Skip to content

fix(referrals): don't book referral earnings on zero-revenue subsidized jobs#2

Open
dddabtc wants to merge 1 commit into
leyten:masterfrom
dddabtc:fix/no-referral-on-subsidized-jobs
Open

fix(referrals): don't book referral earnings on zero-revenue subsidized jobs#2
dddabtc wants to merge 1 commit into
leyten:masterfrom
dddabtc:fix/no-referral-on-subsidized-jobs

Conversation

@dddabtc

@dddabtc dddabtc commented Jun 20, 2026

Copy link
Copy Markdown

Problem

In recordEarning (lib/db.ts):

const referralBasisUsd = revenueUsd > 0 ? revenueUsd
  : (data.subsidyKind === 'allowance' ? payoutBaseUsd : 0);

A staker-allowance job has no revenue (the user paid 0; the treasury subsidizes it), yet this still books a 5% referral payout computed on the job's list price. Referral earnings ride the same withdrawable balance as worker pay (getPendingBalance).

The only sybil defense on referrals is the literal self-referral check (referrer === referee). So a referrer can sign up a second account with their own code and have it burn its free daily allowance; each such job books 5% of list price to the referrer — a pure treasury outflow for jobs nobody paid for.

Fix

Only book a referral cut against actual revenue:

const referralBasisUsd = revenueUsd > 0 ? revenueUsd : 0;

The UNIQUE(job_id) guard on referral_earnings already prevents double-booking; this only removes the zero-revenue case. Stronger sybil linkage (beyond the self-referral check) is worth considering separately.

…ed jobs

recordEarning booked a 5% referral payout on staker-allowance jobs using the
job's list price even though those jobs have no revenue (the treasury subsidizes
them). Combined with referrals only being blocked for literal self-referral, a
self-referral ring could mint 5% of the list price out of the treasury for jobs
nobody paid for. Only book referral earnings against actual revenue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants