On-chain programs that hold the stakes and pick the winner for Timba games.
Timba is a platform for multiplayer coinflips and giveaways played on the web or in Telegram. Players stake tokens into a game, the program holds the funds, and a winner is picked from a secret that was committed before anyone joined. Anyone can recompute the winner from public data after the game settles.
| Chain | Implementation | Status | Docs |
|---|---|---|---|
| Solana | Rust, Anchor 1.2, SPL Token | Mainnet, program 32Jr4JnXWvqq9GqPQynkooHsszaucUUvZfNLh2hdX2L5 |
README, deployment |
| EVM | Solidity 0.8.38, UUPS, ERC-20 | Not deployed to a public network yet | README |
Read this before you rely on the contracts:
- The oracle is trusted. It knows each secret before settlement, approves game creation and private entries, and can decline to reveal. Commit-reveal stops the secret from changing after players join, but it does not make games fair against a malicious oracle or block producer. There is no external VRF.
- The contracts are upgradeable. Whoever holds the upgrade authority controls program behavior and the escrowed funds. It is a multisig: a Squads v4 vault on Solana and a Safe on EVM. The Solana program moves to its vault with the v0.3.0 release.
- Token policy is off-chain. The oracle decides which tokens and minimum amounts it will sign for. The Solana program accepts only legacy SPL Token mints, and the EVM contract rejects fee-on-transfer behavior.
- Tests are not an audit. The test suites are extensive, but they are not an independent security audit.
Full details: SECURITY.md, Solana security model, EVM security model.
- Create. The creator picks a token, an amount, player limits and a timeout.
- The Timba oracle generates a random 32-byte secret, and the game stores its SHA-256 hash as a commitment.
- The oracle co-signs creation, so games can only use tokens it has approved.
- Join. Each wallet gets one entry.
- In a coinflip every player stakes the same amount.
- In a giveaway the creator funds the prize and players join for free.
- Settle. A game is ready when it is full, or when it has reached its minimum players and its timeout has passed.
- The oracle then reveals the secret.
- The program checks it against the commitment, computes the winner, pays out and takes the fee.
- Recover. If a game is still below its minimum player count at expiry, players can take their stakes back right away.
- A game that reached its minimum is ready instead.
- If it is never settled, its funds unlock after a recovery buffer, so they cannot be stuck behind the oracle.
| Chain | Formula |
|---|---|
| Solana | sha256(secret || final_slot), read as little-endian u64 values with rejection sampling so every entry is equally likely |
| EVM | Domain-separated Keccak formula over the chain ID, contract address, game ID, secret and last entry block |
- No modulo bias. Both avoid modulo bias.
- No fallback. Both revert rather than fall back to a biased pick.
- Library:
@timbagame/protocolimplements the same calculations. - Web: the verifier at timba.cc/provably-fair.
| Setting | Contract ceiling |
|---|---|
| Game duration | 30 days |
| Oracle buffer | 1 day |
| Fee | 10%, whole percentages |
The live fee and buffer are configured on-chain within these ceilings. Timba currently charges 1%.
- Don't open a public issue for security problems.
- Report privately through this repository's Security tab.
- Never post unrevealed secrets or private keys.
- timbagame/protocol: TypeScript clients, IDLs, ABIs and winner verification
- timbagame/oracle: secrets, game approval and settlement
- timbagame/bot: the Telegram bot
- timba.cc: play on the web and verify games
- @playtimbabot: play in Telegram
Repository layout
solana/ Anchor program, Rust and LiteSVM tests, generated Kit client
evm/ Solidity contract, Foundry tests, deployment scripts, exported ABI
fixtures/ Shared lifecycle and fee cases both implementations must pass
Each project has its own dependencies, pinned toolchain and CI workflow. There is no shared build.
Build and test: Solana
Requires Rust 1.99.1, Solana CLI 4.3.2, Anchor CLI 1.2.0 and Bun 1.4.3.
cd solana
solana-keygen new --no-bip39-passphrase --outfile ~/.config/solana/id.json # skip if you already have one
bun install --frozen-lockfile
anchor build --ignore-keys
anchor test --skip-buildMainnet releases use a verifiable build.
solana/DEPLOYMENT.md explains how to reproduce the deployed executable hash with solana-verify.
Build and test: EVM
Requires Foundry 1.8.4, plus Bun for the smoke test. Dependencies are git submodules.
git submodule update --init --recursive
cd evm
forge build
forge test
bash script/local-smoke.shThe smoke test runs a full coinflip on a local Anvil node.
Shared fixtures
fixtures/lifecycle.csv holds 180 cases covering both game types, player counts, expiry and buffer boundaries, and fee rounding. The Rust, LiteSVM and Foundry suites all run the same file, so both chains follow the same rules.
Coverage gate
Pull requests require 100% first-party executable line coverage for both chains.
- Solana: uses the deployed SBF binary's line inventory and execution traces, supplemented with matching host LLVM hits from direct state tests. This covers defensive state guards that account validation rejects before the deployed handler can reach them. The raw SBF, host and combined reports are retained as CI artifacts.
- EVM: uses Forge LCOV.
Mutation testing
Mutation testing checks that the tests notice when the code changes. It changes a line a little, one change at a time, and runs the tests that reach it. A change no test noticed is a gap, or a change that keeps the same behavior.
- TypeScript scripts: Stryker, on
scripts/*.ts(not the tests). - Solidity: vertigo-rs, on
evm/srcandevm/script, with the Forge tests. It has no releases, so CI pins a commit. It has no line filter either, soscripts/mutants-sol/run.pykeeps only the changes on the lines asked for. - Solana: cargo-mutants, only on
programs/timba/src/state.rs. The program tests need LiteSVM and are slow, so only the host--libandgame_statetests run. A gap there may still be caught by a LiteSVM test.
bun run scripts/mutants.ts ts diff origin/main # TypeScript lines this branch changed
bun run scripts/mutants.ts sol diff origin/main # Solidity lines this branch changed
scripts/mutants-rust.sh diff origin/main # Rust lines this branch changed
bun run scripts/mutants.ts ts part 3 64 # the 4th of 64 equal parts of all TypeScript lines
scripts/mutants-rust.sh shard 3/64 # the 4th of 64 equal parts of all Rust mutantsFor Solidity, set up a virtualenv from scripts/mutants-sol/requirements.txt, run forge build --ast in evm, and point MUTANTS_PYTHON at the virtualenv's Python.
It never blocks a merge. On a pull request, one comment lists the changes no test noticed, from all three languages. Every Saturday a quarter of the 64 parts per language runs, and what lived goes in the open "Missed mutants" issue.