fix(referrals): don't book referral earnings on zero-revenue subsidized jobs#2
Open
dddabtc wants to merge 1 commit into
Open
fix(referrals): don't book referral earnings on zero-revenue subsidized jobs#2dddabtc wants to merge 1 commit into
dddabtc wants to merge 1 commit into
Conversation
…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.
This was referenced Jul 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In
recordEarning(lib/db.ts):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:
The
UNIQUE(job_id)guard onreferral_earningsalready prevents double-booking; this only removes the zero-revenue case. Stronger sybil linkage (beyond the self-referral check) is worth considering separately.