Private, Verifiable Collateral Layer for Bitcoin DeFi on Starknet
Built for Starknet Re{define} Hackathon 2026 โ Privacy Track + Bitcoin Track
In current DeFi, collateral is completely public:
- โ Anyone can see exactly how much BTC you hold
- โ Your liquidation price is visible โ MEV bots front-run it
- โ Whales become phishing and coercion targets
- โ Institutional players cannot participate without exposing strategy
Result: Bitcoin holders are forced to choose between privacy and DeFi participation.
Shielded Collateral Protocol enables private, verifiable collateral using zero-knowledge proofs natively on Starknet.
| Without Shielded | With Shielded |
|---|---|
Deposit 100 BTC โ everyone sees 100 BTC |
Deposit 100 BTC โ on-chain sees commitment = 0x7f3a... |
| "Prove you have collateral" โ reveal full balance | "Prove collateral > threshold" โ reveal nothing |
| Liquidation is predictable โ MEV attacks | Position private โ no front-running |
| Withdraw: attacker can forge nullifier | Withdraw: requires Poseidon(commitment, secret) โ
|
1. DEPOSIT: amount + secret โ commitment = Poseidon(amount, secret) โ on-chain stores commitment ONLY (no plaintext)
2. PROVE: commitment + proof โ "value > threshold" โ verifiable without learning amount
3. WITHDRAW: provide (amount, secret, nullifier) โ on-chain verifies Poseidon(amount,secret)==commitment
AND Poseidon(commitment,secret)==nullifier โ prevents forgery and double-spend
Privacy Guarantee: The amount is never stored in plaintext โ on-chain or in events. Only the Poseidon commitment is persisted.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ USER INTERFACE โ
โ React + TypeScript + Starknet.js โ
โโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ACCOUNT ABSTRACTION LAYER โ
โ ShieldedAccount โ Session Keys โ Paymaster (gasless) โ
โโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SMART CONTRACTS (Cairo 2.15) โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ CollateralVault.cairo (H-07 hardened) โ โ
โ โ deposit(amount, commitment) โ โ
โ โ prove_collateral(user, threshold, proof) โ bool โ โ
โ โ withdraw(amount, secret, nullifier) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ StubProofVerifier.cairo (MVP) โ โ
โ โ verify_range_proof(commitment, threshold, proof) โ โ
โ โ [Production: full STARK range proof verification] โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ MockLendingProtocol.cairo โ โ
โ โ borrow(amount, threshold) โ uses prove_collateral โ โ
โ โ repay(amount) โ clear debt โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CRYPTOGRAPHIC LAYER โ
โ Poseidon Hash (STARK-native) โ Nullifiers โ Commitments โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
See ARCHITECTURE.md for full diagrams.
commitment = Poseidon(amount.low, amount.high, secret)
Only the depositor knows amount and secret. On-chain only stores commitment โ no plaintext amount ever persisted.
proof: "commitment hides value > threshold"
Any verifier can check the proof without learning the actual amount. MVP uses StubProofVerifier (commitment-existence check); production replaces with RangeProofVerifier via set_verifier().
nullifier = Poseidon(commitment, secret)
Marks withdrawals as used without linking them to the original deposit. Requires knowledge of secret โ making forgery cryptographically infeasible.
| Tool | Version | Install |
|---|---|---|
| Scarb | 2.15+ | scarb.sh |
| Starknet Foundry | 0.56+ | foundry-rs/starknet-foundry |
| Katana | latest | dojoengine.org |
| Node.js | 18+ | nodejs.org |
| pnpm | 10+ | npm i -g pnpm |
git clone https://github.com/deegalabs/shielded-btc-collateral
cd shielded-btc-collateral/contracts
# Build all contracts
scarb build
# Run all 71 tests
snforge test
# โ Tests: 71 passed, 0 failed# Terminal 1: start Katana devnet
katana --accounts 3 --seed 0
# Terminal 2: deploy all 7 contracts
bash scripts/deploy_devnet.sh
# โ scripts/deployment/devnet.json (all addresses)
# โ scripts/deployment/frontend.env.devnet (frontend config)cp scripts/deployment/frontend.env.devnet frontend/.env
cd frontend && pnpm install && pnpm dev
# โ http://localhost:5173
# Connect Argent X wallet (set network to http://localhost:5050)# Full 10-step protocol flow from the command line
cd contracts && npx ts-node ../scripts/demo.ts# Configure environment
cp scripts/.env.example scripts/.env
# Edit: STARKNET_ACCOUNT, STARKNET_PRIVATE_KEY, STARKNET_RPC
# Automated deployment
bash scripts/deploy_sepolia.sh
# โ scripts/deployment/sepolia.json + scripts/deployment/frontend.env.sepoliaSee docs/DEPLOYMENT.md for the full deployment guide.
3-minute walkthrough โ [Recording in progress (deadline: March 9, 2026)]
Topics:
- Problem: BTC privacy gap in DeFi
- Solution: Commitment-based private collateral
- Live: Private deposit โ commitment animation โ borrow โ repay โ withdraw
- Technical: Poseidon on-chain validation, Account Abstraction, session keys
import { hash } from 'starknet';
// Step 1: Generate commitment locally (private โ never sent as plaintext)
const secret = BigInt('0x' + crypto.getRandomValues(new Uint8Array(32)).reduce((s, b) => s + b.toString(16).padStart(2, '0'), ''));
const commitment = hash.computePoseidonHashOnElements([amount_low, amount_high, secret]);
// Step 2: Deposit privately (on-chain sees commitment only)
await vault.invoke("deposit", [amount_u256, commitment]);
// Step 3: Prove collateral to any lending protocol (no amount revealed)
const hasCollateral = await vault.call("prove_collateral", [user, threshold, []]);
// Step 4: Private withdrawal (cryptographic preimage verification on-chain)
const nullifier = hash.computePoseidonHash(commitment, secret);
await vault.invoke("withdraw", [amount_u256, secret, nullifier]);use shielded_collateral::ICollateralVaultDispatcher;
use shielded_collateral::ICollateralVaultDispatcherTrait;
#[external(v0)]
fn borrow(ref self: ContractState, amount: u256, threshold: u256, proof: Span<felt252>) {
let vault = ICollateralVaultDispatcher { contract_address: VAULT_ADDRESS };
// Verify user has sufficient collateral โ without learning the exact amount
let is_valid = vault.prove_collateral(get_caller_address(), threshold, proof);
assert(is_valid, 'Insufficient collateral');
// Proceed with loan...
}| Contract | Address | Explorer |
|---|---|---|
| CollateralVault | TBD โ run deploy_sepolia.sh |
Voyager |
| StubProofVerifier | TBD โ run deploy_sepolia.sh |
Voyager |
| MockWBTC (ERC-20) | TBD โ run deploy_sepolia.sh |
Voyager |
| ShieldedAccount | TBD โ run deploy_sepolia.sh |
Voyager |
| Paymaster | TBD โ run deploy_sepolia.sh |
Voyager |
| MockLendingProtocol | TBD โ run deploy_sepolia.sh |
Voyager |
After running
scripts/deploy_sepolia.sh, addresses are written toscripts/deployment/sepolia.json.
cd contracts
# All 68 tests
snforge test
# With detailed output
snforge test -v
# Specific suite
snforge test test_collateral_vault
snforge test test_integration| Suite | Tests | Coverage |
|---|---|---|
test_collateral_vault |
25+ | Core vault: deposit, prove, withdraw, privacy model |
test_integration |
10+ | Full E2E: lending, repay, withdraw flow |
test_shielded_account |
10+ | AA: deploy, session keys, signature |
test_paymaster |
8+ | Gas sponsorship, collateral eligibility |
test_mock_lending |
8+ | Borrow, repay, collateral checks |
test_session_key |
7+ | Session lifecycle, expiry, revocation |
| Test | Validates |
|---|---|
test_deposit_stores_commitment_only_no_plaintext |
No plaintext amount on-chain after deposit |
test_withdraw_fails_with_wrong_secret |
Preimage check enforced |
test_withdraw_fails_with_wrong_amount |
Amount inflation attack prevented |
test_withdraw_fails_with_forged_nullifier |
Nullifier forgery prevented |
test_privacy_model_commitment_only |
Only commitment accessible externally |
test_prove_collateral_false_after_withdrawal |
Commitment cleared on withdraw |
Whale deposits 100 BTC privately
โ Wants to borrow $50k from zkLend
โ zkLend asks: "Prove collateral > $75k"
โ User proves: โ
(zkLend never learns it's 100 BTC)
โ Loan approved โ position fully private
Trader opens $100k perp position
โ Protocol requires: "margin > $10k"
โ Trader proves margin requirement
โ Trade executes โ total holdings never exposed
User mints $50k stablecoin
โ CDP requires: "BTC collateral > $75k (150%)"
โ User proves threshold
โ Stablecoin minted โ collateral position private
| Feature | Ethereum | Starknet |
|---|---|---|
| Account Abstraction | ERC-4337 (complex) | Native (built-in) |
| Poseidon Hash | ~150k gas | ~15k gas (10x cheaper) |
| STARK Range Proofs | External/expensive | Native, optimized |
| Session Keys | Not native | Native support |
| Gasless Transactions | Relayer workarounds | Native Paymaster |
| Quantum Resistance | โ | โ (STARKs) |
- โ
Core vault logic:
deposit,prove_collateral,withdraw - โ Privacy-preserving commitment storage (no plaintext amounts โ H-07 fix)
- โ Cryptographic withdrawal with preimage + nullifier verification
- โ Nullifier tracking (double-spend prevention + forgery prevention)
- โ WBTC (ERC-20) integration
- โ
Account Abstraction:
ShieldedAccount,SessionKeyManager,Paymaster - โ Mock Lending Protocol integration
- โ 68 passing tests
- โ Sepolia deployment scripts
- โ Frontend with wallet connect + private deposit/withdraw UI
- ๐ Real STARK prover โ Current: stub verifier. Production: full STARK range proof via Cairo circuits + Stone/Stwo prover
- ๐ Mainnet deployment โ Audit completion + liquidity bootstrap
- ๐ Security audits โ Trail of Bits + OpenZeppelin
- ๐ SDK โ
npm install @shielded/sdkfor protocol integrators - ๐ Guardian recovery โ Social recovery for
ShieldedAccount
Note: Hackathon constraints (6 days) require focus on architecture proof and concept validation. The architecture is production-ready; the STARK prover integration requires 4โ6 additional weeks of development. See MVP.md for detailed trade-off analysis.
| Phase | Timeline | Status |
|---|---|---|
| Phase 1: MVP โ Core contracts, AA, stub verifier, frontend, testnet | Hackathon | โ |
| Phase 2: Production โ Real STARK proofs, audits, mainnet | Q2 2026 | ๐ |
| Phase 3: Ecosystem โ zkLend, Nostra, Ekubo integrations | Q3 2026 | ๐ |
| Phase 4: Advanced โ Batch proofs, recursive proofs, cross-chain | Q4 2026 | ๐ |
See ROADMAP.md for detailed breakdown.
Any DeFi protocol can integrate by calling a single function:
ICollateralVaultDispatcher { contract_address: VAULT_ADDRESS }
.prove_collateral(user: ContractAddress, threshold: u256, proof: Span<felt252>) -> boolThe proof parameter allows protocols to pass a STARK range proof generated client-side. For the MVP stub, pass an empty array array![].span().
Integration examples: docs/integration.md
- Poseidon commitments: amount stored as opaque hash โ no plaintext on-chain
- Cryptographic withdrawal: requires knowledge of
secret(preimage proof) - Nullifier integrity:
nullifier = Poseidon(commitment, secret)โ forgery is computationally infeasible - Double-spend prevention: nullifier registry (used nullifiers never reusable)
- Upgradeable verifier:
set_verifier()allows dropping in real STARK prover with zero vault changes - OpenZeppelin components: battle-tested AA primitives
See SECURITY.md for the full audit report including H-07 fix documentation.
| Document | Description |
|---|---|
| ARCHITECTURE.md | System diagrams, component breakdown |
| ROADMAP.md | Development timeline |
| MVP.md | MVP scope, trade-offs, decision log |
| SECURITY.md | Security audit report (v3.0 โ H-07 fix) |
| docs/DEPLOYMENT.md | Sepolia deployment guide |
| docs/zk-proofs.md | ZK proof mechanics explained |
| docs/integration.md | How to integrate as a protocol |
Built with โค๏ธ by DeegaLabs
| Member | Role |
|---|---|
| Daniel Gorgonha | Blockchain Architect, Cairo Developer (2nd place Cronos Hackathon) |
| Dayane Gorgonha | Full-stack Developer, UX/UI, Web3 Integrations |
Blockchain Engineer | Senior Software Engineer
Over 9 years of software development experience, specialized in Blockchain and Web3. Develops smart contracts, decentralized applications, and tokenization systems using Node.js, Python, Rust, and Solidity.
Product Architecture & Philosophical Logic
Works on digital product architecture in the pre-development stage, structuring solutions before they become code. Uses philosophical logic as an analytical method to create resilient architectures.
- ๐ฆ Twitter: @deegalabs
- ๐ฌ Telegram: @danielgorgonha1
- ๐ง Email: contato@deegalabs.com.br
MIT License โ see LICENSE for details.
Built for Starknet Re{define} Hackathon 2026 โ Privacy Track + Bitcoin Track