fix(stake): remove silent mainnet default in getStakeProgramId for browser bundles - #340
fix(stake): remove silent mainnet default in getStakeProgramId for browser bundles#340Morenikeoa wants to merge 1 commit into
Conversation
…owser bundles getStakeProgramId()'s network-resolution IIFE defaulted to 'mainnet' whenever it ran in a browser bundle with no explicit network argument and no NETWORK/NEXT_PUBLIC_DEFAULT_NETWORK env var set (process.env is empty in browser bundles since env vars aren't inlined into third-party SDK code). This is the exact opposite of the sibling getCurrentNetwork() in program-ids.ts, which was hardened under PERC-697 specifically to remove this same class of silent-mainnet- default bug and now fails open to devnet. Any frontend/wallet-integration code built on this SDK (the natural consumption pattern for a trading SDK) that calls getStakeProgramId() or the PDA helpers that default to it (deriveStakePool, deriveStakeVaultAuth, deriveDepositPda) without an explicit network or programId, in an environment where the bundler didn't inline a NETWORK env var, silently derives mainnet PDAs and targets the mainnet stake program — risking a devnet-testing flow executing against mainnet, or a real deposit/withdraw/stake transaction going to the wrong program. Fix: the browser-context branch now returns 'devnet', matching getCurrentNetwork()'s fail-open-to-devnet policy exactly. Mainnet still requires an explicit `network` argument or env var — this only removes the silent default, it does not change explicit-network behavior. Added a regression test that simulates a browser context (temporary global `window`) with no env vars set and asserts getStakeProgramId() returns the devnet address, not mainnet. Confirmed it fails against the prior code (returns the mainnet address) and passes against this fix. Full suite: 852 passed | 31 skipped (883 total, +1 new test).
|
Warning Review limit reached
More reviews will be available in 51 minutes and 30 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. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ 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 |
Summary
getStakeProgramId()'s network-resolution IIFE defaulted to'mainnet'whenever it ran in a browser bundle with no explicitnetworkargument and noNETWORK/NEXT_PUBLIC_DEFAULT_NETWORKenv var set (process.envis empty in browser bundles since env vars aren't inlined into third-party SDK code). This is the exact opposite of the siblinggetCurrentNetwork()inprogram-ids.ts, which was hardened under PERC-697 specifically to remove this same class of silent-mainnet-default bug and now fails open to devnet.Any frontend/wallet-integration code built on this SDK (the natural consumption pattern for a trading SDK) that calls
getStakeProgramId()or the PDA helpers that default to it (deriveStakePool,deriveStakeVaultAuth,deriveDepositPda) without an explicit network or programId, in an environment where the bundler didn't inline aNETWORKenv var, silently derives mainnet PDAs and targets the mainnet stake program — risking a devnet-testing flow executing against mainnet, or a real deposit/withdraw/stake transaction going to the wrong program.Fix
The browser-context branch now returns
'devnet', matchinggetCurrentNetwork()'s fail-open-to-devnet policy exactly. Mainnet still requires an explicitnetworkargument or env var — this only removes the silent default, it does not change explicit-network behavior.Test plan
window) with no env vars set and assertsgetStakeProgramId()returns the devnet address, not mainnet.