fix(transfer-sol): require payer signature + checked lamport math by yukikm · Pull Request #532 · solana-developers/program-examples
Pull request overview
This PR hardens the Anchor transfer_sol_with_program example to prevent unauthorized lamport drains by requiring the source (payer) to sign and by using checked lamport arithmetic with explicit error reporting.
Changes:
- Require
payerto be aSigner<'info>(while still enforcingowner = id()). - Add explicit insufficient-funds check plus checked
sub/addfor lamport math, returning custom errors. - Update the Anchor TS test to include
payerAccountas an explicit signer.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| basics/transfer-sol/anchor/programs/transfer-sol/src/lib.rs | Enforces payer signature + checked lamport mutation with custom error codes. |
| basics/transfer-sol/anchor/tests/test.ts | Updates the “Transfer SOL with Program” test to sign with the program-owned payer keypair. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.