fix: validate mainnet_ca from Supabase against on-chain SPL Token mint ownership - #357
fix: validate mainnet_ca from Supabase against on-chain SPL Token mint ownership#357Ayomisco wants to merge 1 commit into
Conversation
…t ownership The fraud-detector uses mainnet_ca from Supabase as the mint address for off-chain price lookups (DexScreener/Jupiter). Previously only a base58 regex was applied, so any valid-looking address — including attacker-controlled tokens with no relation to the market's collateral — was accepted if written to Supabase. Add a getMultipleAccountsInfo batch call to verify each candidate mainnet_ca is owned by the SPL Token program before storing it. If the ownership check fails or the RPC call throws, the field is discarded for the cycle and the fraud-detector falls back to the market's actual collateral mint.
|
Warning Review limit reached
More reviews will be available in 55 minutes and 49 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Independent verification — not an approval (QA/Security own that). The guard is sound, but this turns one existing test red. I found the cause and verified a one-line fix. The breakageThe assertion is Cause
One-line fix, verifiedMove the acquisition inside the guard that uses it: const SPL_TOKEN_PROGRAM = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
-const conn = getConnection();
if (candidates.length > 0) {
+ const conn = getConnection();
try {I applied exactly that on your branch and re-ran: It also happens to be better behaviour on its own merits: no connection acquired on discovery cycles that have nothing to validate. One caveat on attribution: running that test with On the guard itselfThe validation logic looks right to me:
One gapThere is no test for the new validation. Once the above is fixed, the natural companions are: a row whose |
Closes #356
What
Add a
getMultipleAccountsInfoownership check incrank.tsbefore storingmainnet_caaddresses in the override mints table.Why
The previous code accepted any string that passed the base58 regex. There was no on-chain check that the address is owned by the SPL Token program. A pubkey owned by any other program would pass the regex and be stored, causing the keeper to send crank transactions against it.
Changes
src/services/crank.ts(lines 1193-1210): after the base58 filter, batch-fetchgetMultipleAccountsInfofor all candidates. Keep only addresses whose accountownermatchesTokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA. On any RPC error, discard all overrides for the cycle (fail closed).