Audience: on-call operators for the backend (API, oracle worker, indexer worker) and the
coin-flip/random-generatorcontracts on testnet. Scope: the six incidents below. For exploit triage and severity classification see EXPLOIT_RESPONSE_RUNBOOK.md; for how the backend is hosted see deploy-backend.md. Last verified: testnet, against the contracts in this repository (contracts/coin-flip,contracts/random-generator), stellar CLI 25.1.0.
| Placeholder | Where it comes from |
|---|---|
$API |
Deployed API base URL, e.g. https://<your-render-service>.onrender.com/api (see deploy-backend.md) |
$NETWORK |
testnet |
$ADMIN |
stellar keys address admin (the identity in scripts/setup-testnet.sh) |
$ORACLE |
stellar keys address oracle |
$COIN_FLIP_ID, $RNG_ID |
jq -r '.contracts.coinFlip' deployments/testnet.json, jq -r '.contracts.randomGenerator' deployments/testnet.json |
$STROOPS |
Integer token amounts, 7 decimals: 1 XLM = 10000000 |
All stellar contract invoke commands are copied from
scripts/deploy-contracts.sh and the contracts' own #[contractimpl]
functions.
curl -sS -o /dev/null -w '%{http_code}\n' "$API/health" # liveness: 200
curl -sS "$API/health/deep" | jq # 200 only when everything is healthy/health/deep returns 200 with status: "healthy" when
dependencies.db, dependencies.redis, dependencies.stellar, soroban
and both contracts.coinFlip / contracts.randomGenerator are healthy, and
503 (status: "degraded" or "unhealthy") otherwise. It never caches
(Cache-Control: no-store).
Useful reads that almost every incident needs:
# Seed commitment queue depth (random-generator)
stellar contract invoke --id "$RNG_ID" --source "$ADMIN" --network "$NETWORK" -- get_commitment_queue_len
# Is coin-flip paused? (is_paused -> true | false)
stellar contract invoke --id "$COIN_FLIP_ID" --source "$ADMIN" --network "$NETWORK" -- is_paused
# One round: resolved / refunded / payout (get_game --game_id <u64>)
stellar contract invoke --id "$COIN_FLIP_ID" --source "$ADMIN" --network "$NETWORK" -- get_game --game_id <GAME_ID>
# Oracle fee balance (Horizon); fund with: stellar keys fund oracle --network "$NETWORK"
curl -sS "https://horizon-testnet.stellar.org/accounts/$ORACLE" | jq '.balances[].balance'Worker logs:
docker compose logs -f backend # local / compose
# Render: Dashboard → <service> → Logs (both workers log from the same process)Workers are enabled with ORACLE_ENABLED=true and INDEXER_ENABLED=true;
both read SOROBAN_RPC_URL from the backend environment and store their
event cursor in the worker_cursors table (name = 'oracle' | 'indexer').
Symptoms
- Rounds stay
pending:get_game --game_id <id>showsresolved: falselong after the bet, orGET $API/games/recentshows onlypendingrows. get_commitment_queue_lenis0(or falling belowORACLE_MIN_QUEUE, default20) —request_randomthen fails withNoCommitmentAvailableand new bets are rejected.- Backend logs show
oracle workererrors, or no oracle log lines at all.
Steps
curl -sS "$API/health/deep" | jq '{status, soroban, contracts}'— ifsorobanis unhealthy, go to incident 6 first (the worker cannot poll events without RPC).- Check the queue and the stuck round (commands above). Queue
0with a stuck round = oracle not running or not funded. - Confirm the worker is on: the process env must contain
ORACLE_ENABLED=true,ORACLE_SECRET_KEY,RANDOM_GENERATOR_CONTRACT_ID,COIN_FLIP_CONTRACT_ID. - Restart the service (Render: Restart; local:
docker compose restart backend). The worker resumes from its saved cursor — it does not replay or skip events. - Check the oracle account can still pay fees:
curl -sS "https://horizon-testnet.stellar.org/accounts/$ORACLE" | jq '.balances[].balance'. Below ~1 XLM:stellar keys fund oracle --network testnet(testnet friendbot) and restart again. - If the queue is empty it refills automatically on the next poll
(
ORACLE_MIN_QUEUEcommitments are generated andcommit_seedsis called). To refill by hand:
stellar contract invoke --id "$RNG_ID" --source oracle --network "$NETWORK" \
-- commit_seeds --oracle "$ORACLE" \
--commitments '["<sha256-of-seed-1>", "<sha256-of-seed-2>", "<sha256-of-seed-3>"]'Resolved when
get_commitment_queue_len≥ORACLE_MIN_QUEUE;- the stuck round returns
resolved: truefromget_game, and appears inGET $API/games/recent; /health/deepis200 healthy.
Symptoms: the oracle secret (ORACLE_SECRET_KEY) leaked — a commit, a
log line, an exposed .env, a former contractor's laptop.
What a compromised oracle key can and cannot do
- It cannot change the outcome of a round whose commitment is already in
the queue:
fulfill_randomrejects any seed wheresha256(server_seed) != pending.commitment(SeedCommitmentMismatch), and without the original preimage the attacker cannot fulfil those rounds at all. - It can stall rounds (never reveal → players refund via
cancel_stale_bet), fill the queue with seeds it knows, and refuse to cooperate. Treat it as an incident, not a catastrophe, but rotate it.
The hard fact: random-generator has no oracle rotation function.
init(env, admin, oracle) runs once (AlreadyInitialized), and
DataKey::Oracle has no setter; coin-flip stores its rng_contract the
same way in init. Rotating the on-chain oracle address therefore means
redeploying the stack (the commands are scripts/deploy-contracts.sh's).
Steps
- Stop new bets immediately:
stellar contract invoke --id "$COIN_FLIP_ID" --source "$ADMIN" --network "$NETWORK" \
-- set_paused --admin "$ADMIN" --paused true
stellar contract invoke --id "$COIN_FLIP_ID" --source "$ADMIN" --network "$NETWORK" -- is_paused # true- Generate and fund the replacement identity:
stellar keys generate oracle_v2 --fund --network testnet
stellar keys address oracle_v2 # becomes the new $ORACLE- Redeploy with the new oracle wired in (copy of
scripts/deploy-contracts.sh, run from the repo root):
ADMIN_ADDR=$(stellar keys address admin)
ORACLE_ADDR=$(stellar keys address oracle_v2)
RNG_ID=$(stellar contract deploy --wasm contracts/target/wasm32v1-none/release/stellarcade_random_generator.wasm --source admin --network testnet)
stellar contract invoke --id "$RNG_ID" --source admin --network testnet -- init --admin "$ADMIN_ADDR" --oracle "$ORACLE_ADDR"
COIN_FLIP_ID=$(stellar contract deploy --wasm contracts/target/wasm32v1-none/release/stellarcade_coin_flip.wasm --source admin --network testnet)
stellar contract invoke --id "$RNG_ID" --source admin --network testnet -- authorize --admin "$ADMIN_ADDR" --caller "$COIN_FLIP_ID"
stellar contract invoke --id "$COIN_FLIP_ID" --source admin --network testnet -- init \
--admin "$ADMIN_ADDR" --rng_contract "$RNG_ID" \
--token CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC \
--min_wager 10000000 --max_wager 1000000000 --house_edge_bps 250- Re-commit a seed batch before reopening (queue must be non-empty or every bet fails), then fund the house:
stellar contract invoke --id "$RNG_ID" --source oracle_v2 --network testnet \
-- commit_seeds --oracle "$ORACLE_ADDR" \
--commitments '["<sha256-of-seed-1>", "<sha256-of-seed-2>", "<sha256-of-seed-3>"]'
stellar contract invoke --id "$COIN_FLIP_ID" --source admin --network testnet \
-- fund_house --admin "$ADMIN_ADDR" --amount 10000000000- Update the backend secrets (platform secret store, never committed):
ORACLE_SECRET_KEY=$(stellar keys secret oracle_v2),RANDOM_GENERATOR_CONTRACT_ID=$RNG_ID,COIN_FLIP_ID/COIN_FLIP_CONTRACT_ID=$COIN_FLIP_ID, and the same IDs in the web app (NEXT_PUBLIC_*). Restart. - Unpause:
stellar contract invoke --id "$COIN_FLIP_ID" --source "$ADMIN" --network "$NETWORK" \
-- set_paused --admin "$ADMIN" --paused falseResolved when: is_paused → false, get_commitment_queue_len > 0,
GET $API/health/deep is healthy with the new contract IDs, and a test
round resolves end to end. Old contract IDs stay paused; rounds already
placed there follow the refund path (incident 4).
Symptoms: place_bet fails with Error(Contract, #13)
(InsufficientHouseLiquidity) — the contract requires
balance + wager ≥ (total active wager + wager) × (2 − house_edge) — or
withdraw_house fails with the same error.
Steps
# What the house holds, and what it already owes unresolved rounds
stellar contract invoke --id "$COIN_FLIP_ID" --source "$ADMIN" --network "$NETWORK" -- house_balance
stellar contract invoke --id "$COIN_FLIP_ID" --source "$ADMIN" --network "$NETWORK" -- house_exposure_snapshot
# Top up (amount in stroops; 100 XLM = 1000000000)
stellar contract invoke --id "$COIN_FLIP_ID" --source "$ADMIN" --network "$NETWORK" \
-- fund_house --admin "$ADMIN" --amount 1000000000fund_house transfers from the admin account, so the admin must hold at
least that much XLM. Never use withdraw_house to "fix" a low bankroll; it
is refused while balance − amount < max_payout_liability.
Resolved when: house_balance covers house_exposure_snapshot's
max_payout_liability plus headroom, and a 1-XLM test bet is accepted.
Symptoms: a reproducible fault in payouts, resolution or refunds.
Steps
- Pause new bets (players can still refund and rounds already placed can
still resolve —
set_pausedonly blocksplace_bet):
stellar contract invoke --id "$COIN_FLIP_ID" --source "$ADMIN" --network "$NETWORK" \
-- set_paused --admin "$ADMIN" --paused true- Tell affected players the refund path, in exactly these terms:
- the round is refunded only if the oracle never fulfils it — once
get_resultsucceeds,cancel_stale_betreturnsRefundNotYetAvailable (#14)and the round must settle normally; - after
RefundTimeoutLedgersledgers (17,280 ≈ 24 h at ~5 s/ledger) fromplaced_at_ledger, the player calls:
- the round is refunded only if the oracle never fulfils it — once
stellar contract invoke --id "$COIN_FLIP_ID" --source <player_identity> --network "$NETWORK" \
-- cancel_stale_bet --player <PLAYER_ADDRESS> --game_id <GAME_ID>A refunded game can never be resolved (resolve_bet returns
GameRefunded (#15)), so nobody can be paid twice.
3. Fix, rebuild (cargo build -p stellarcade-coin-flip --target wasm32v1-none --release --locked), redeploy, re-init, re-fund
(incident 2, step 3 is the full sequence), update contract IDs in
backend + web env, then unpause the new deployment.
Resolved when: is_paused → false on the healthy deployment,
/health/deep healthy with the new ID, and one full round (bet → resolve)
succeeds.
Symptoms: GET $API/games/recent, history or leaderboards miss on-chain
rounds; logs show getEvents failing with a cursor/startLedger error.
Facts: the indexer resumes from worker_cursors.name = 'indexer' and
polls bet_placed / bet_resolved. If that cursor is older than the RPC
provider's event retention, polling fails and there is no automatic
recovery in the backend yet — the steps below are the manual recovery.
Steps
docker compose exec db psql -U stellarcade -d stellarcade \
-c "SELECT name, cursor, updated_at FROM worker_cursors;"- If the cursor is stale (or
updated_atis old), delete it and start from a recent ledger:
docker compose exec db psql -U stellarcade -d stellarcade \
-c "DELETE FROM worker_cursors WHERE name = 'indexer';"- Set
INDEXER_START_LEDGERto the current ledger minus a small margin (the value is printed by/health/deep→soroban.latencyMscontext, orstellar ledger --network testnet) and restart the backend. - Rounds whose
bet_placedhappened before the new start ledger are backfilled: when theirbet_resolvedevent arrives and no row exists, the worker simulatesget_gameand inserts the row. Rounds still pending at that point appear as soon as they resolve — they are not lost. - The same recovery applies to the oracle worker with
worker_cursors.name = 'oracle'andORACLE_START_LEDGER.
Resolved when: the worker_cursors.updated_at timestamp advances every
poll, and the previously missing round is present:
curl -sS "$API/games/recent?pageSize=20" | jq '.items[] | {chain_game_id, status, result}'Symptoms: /health/deep reports soroban.status = "unhealthy"; both
workers log getEvents / simulation failures; /verify and the play panel
cannot read contracts.
Steps
- Confirm it is the provider, not the contracts:
curl -sS https://soroban-testnet.stellar.org -X POST -H 'content-type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"getHealth"}' - Switch the backend to a standby endpoint — set
SOROBAN_RPC_URLin the platform secret store (it is read inbackend/src/config/stellar.js) and restart. Testnet default:https://soroban-testnet.stellar.org. - If the public web app also fails to read contracts, update
NEXT_PUBLIC_SOROBAN_RPC_URL(and redeploy the frontend).
Resolved when: /health/deep → soroban.status = "healthy", worker logs
resume advancing worker_cursors.updated_at, and get_commitment_queue_len
answers.
From contracts/coin-flip/src/lib.rs (line numbers on main):
| Function | Signature |
|---|---|
set_paused |
pub fn set_paused(env: Env, admin: Address, paused: bool) -> Result<(), Error> (lib.rs:761) |
is_paused |
pub fn is_paused(env: Env) -> Result<bool, Error> (lib.rs:809) |
fund_house |
pub fn fund_house(env: Env, admin: Address, amount: i128) -> Result<(), Error> (lib.rs:684) |
withdraw_house |
pub fn withdraw_house(env: Env, admin: Address, amount: i128) -> Result<(), Error> (lib.rs:700) |
house_balance |
pub fn house_balance(env: Env) -> Result<i128, Error> (lib.rs:728) |
house_exposure_snapshot |
pub fn house_exposure_snapshot(env: Env) -> Result<HouseExposureSnapshot, Error> (lib.rs:643) |
set_wager_limits |
pub fn set_wager_limits(env: Env, admin: Address, min_wager: i128, max_wager: i128) -> Result<(), Error> (lib.rs:735) |
cancel_stale_bet |
pub fn cancel_stale_bet(env: Env, player: Address, game_id: u64) -> Result<(), Error> (lib.rs:519) |
resolve_bet |
pub fn resolve_bet(env: Env, game_id: u64) -> Result<(), Error> (lib.rs:419) |
get_game |
pub fn get_game(env: Env, game_id: u64) -> Result<Game, Error> (lib.rs:590) |
place_bet |
pub fn place_bet(env: Env, player: Address, side: u32, wager: i128, game_id: u64) -> Result<(), Error> (lib.rs:305) |
From contracts/random-generator/src/lib.rs:
| Function | Signature |
|---|---|
init |
pub fn init(env: Env, admin: Address, oracle: Address) -> Result<(), Error> (lib.rs:253) — one-time; no setter for oracle exists |
authorize / revoke |
pub fn authorize(env: Env, admin: Address, caller: Address) -> Result<(), Error> (lib.rs:271 / lib.rs:287) |
commit_seeds |
pub fn commit_seeds(env: Env, oracle: Address, commitments: Vec<BytesN<32>>) -> Result<u32, Error> (lib.rs:304) |
fulfill_random |
pub fn fulfill_random(env: Env, oracle: Address, request_id: u64, server_seed: BytesN<32>) -> Result<(), Error> (lib.rs:471) |
get_commitment_queue_len |
pub fn get_commitment_queue_len(env: Env) -> u32 (lib.rs:341) |
get_result |
pub fn get_result(env: Env, request_id: u64) -> Result<FulfilledEntry, Error> (lib.rs:625) |
get_config |
pub fn get_config(env: Env) -> Result<GeneratorConfig, Error> (lib.rs:689) |
Backend API used here: GET /api/health, GET /api/health/deep
(backend/src/routes/health.routes.js), GET /api/games/recent
(backend/src/routes/games.routes.js).
Executed against a stack built from this tree
(cargo build -p stellarcade-random-generator -p stellarcade-coin-flip --target wasm32v1-none --release --locked), stellar CLI 25.1.0, network testnet,
admin GBQDK5VERHW2SHGD4FQKG7C5JMZ77NYPL5IXEIDJC3EWKPC5NGCEBQRO:
$RNG_ID=CDET7LAKBJ452RPSNC2NP7RUFRGS4BGXXGBWYGVGBFANN3H7NF7V5VFZ$COIN_FLIP_ID=CAA7MSM77YCU73NSBR46CIS26LSJT6RTBT476BEZ67BL5GUIFIQXLVBQ
Pause (set_paused --paused true):
$ stellar contract invoke --id "$COIN_FLIP_ID" --source admin --network testnet -- is_paused
false
$ stellar contract invoke --id "$COIN_FLIP_ID" --source admin --network testnet -- set_paused --admin "$ADMIN" --paused true
ℹ️ Signing transaction: a45dd1b0caf3e61eb102473be09cdeac17e9166bbf7c100fbe1627d268038a7d
📅 CAA7MSM77YCU73NSBR46CIS26LSJT6RTBT476BEZ67BL5GUIFIQXLVBQ - Success - Event: [{"symbol":"contract_paused"},{"address":"GBQDK5VERHW2SHGD4FQKG7C5JMZ77NYPL5IXEIDJC3EWKPC5NGCEBQRO"}] = {"map":[{"key":{"symbol":"paused"},"val":{"bool":true}}]}
$ stellar contract invoke --id "$COIN_FLIP_ID" --source admin --network testnet -- is_paused
true
Unpause (set_paused --paused false):
$ stellar contract invoke --id "$COIN_FLIP_ID" --source admin --network testnet -- set_paused --admin "$ADMIN" --paused false
ℹ️ Signing transaction: 23770a59ca08953c4c73dca277dc7582da4ab589e7af194a632b4c342a9cc5fe
📅 CAA7MSM77YCU73NSBR46CIS26LSJT6RTBT476BEZ67BL5GUIFIQXLVBQ - Success - Event: [{"symbol":"contract_paused"},{"address":"GBQDK5VERHW2SHGD4FQKG7C5JMZ77NYPL5IXEIDJC3EWKPC5NGCEBQRO"}] = {"map":[{"key":{"symbol":"paused"},"val":{"bool":false}}]}
$ stellar contract invoke --id "$COIN_FLIP_ID" --source admin --network testnet -- is_paused
false
fund_house (100 XLM at init, then a 10 XLM top-up):
$ stellar contract invoke --id "$COIN_FLIP_ID" --source admin --network testnet -- fund_house --admin "$ADMIN" --amount 100000000
ℹ️ Signing transaction: d759597b60ef83dddc0332bffec18b9407fc4fc3127ea639ad9ee22576dca4e3
📅 CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC - Success - Event: [{"symbol":"transfer"},{"address":"GBQDK5VERHW2SHGD4FQKG7C5JMZ77NYPL5IXEIDJC3EWKPC5NGCEBQRO"},{"address":"CAA7MSM77YCU73NSBR46CIS26LSJT6RTBT476BEZ67BL5GUIFIQXLVBQ"},{"string":"native"}] = {"i128":"100000000"}
📅 CAA7MSM77YCU73NSBR46CIS26LSJT6RTBT476BEZ67BL5GUIFIQXLVBQ - Success - Event: [{"symbol":"house_funded"},{"address":"GBQDK5VERHW2SHGD4FQKG7C5JMZ77NYPL5IXEIDJC3EWKPC5NGCEBQRO"}] = {"map":[{"key":{"symbol":"amount"},"val":{"i128":"100000000"}}]}
$ stellar contract invoke --id "$COIN_FLIP_ID" --source admin --network testnet -- house_balance
"1100000000"
$ stellar contract invoke --id "$COIN_FLIP_ID" --source admin --network testnet -- house_exposure_snapshot
{"active_game_count":0,"max_payout_liability":"0","total_wagered":"0"}
A non-admin cannot pause (sanity check of require_admin):
$ stellar contract invoke --id "$COIN_FLIP_ID" --source alice --network testnet -- set_paused --admin "$(stellar keys address alice)" --paused true
0: [Diagnostic Event] contract:CAA7MSM77YCU73NSBR46CIS26LSJT6RTBT476BEZ67BL5GUIFIQXLVBQ, topics:[error, Error(Contract, #3)], data:...
$ stellar contract invoke --id "$COIN_FLIP_ID" --source alice --network testnet -- is_paused
false
Error(Contract, #3) is NotAuthorized; the contract stayed unpaused.