Skip to content

feat: implement surfnet_writeProgram cheatcode (#319)#396

Merged
lgalabru merged 6 commits intosolana-foundation:mainfrom
29deepanshutyagi:issue-319
Nov 5, 2025
Merged

feat: implement surfnet_writeProgram cheatcode (#319)#396
lgalabru merged 6 commits intosolana-foundation:mainfrom
29deepanshutyagi:issue-319

Conversation

@29deepanshutyagi
Copy link
Contributor

@29deepanshutyagi 29deepanshutyagi commented Nov 1, 2025

✅ Implemented surfnet_writeProgram cheatcode

Hi @lgalabru ,
I’ve completed the implementation for surfnet_writeProgram as described in this issue - #319

🧩 Summary

Added a new RPC method surfnet_writeProgram to support chunked program uploads with offset-based writes.

This allows writing large programs (up to 5 MB per RPC call) directly to program data accounts — without requiring signatures or buffer accounts.

Automatically creates program and program-data accounts if missing, preserves loader metadata, and maintains rent exemption after expansion.

⚙️ Key Features

Write program data in small or large chunks using an offset.

No signature or buffer creation needed — writes directly to account data.

Replicates Solana’s upgradeable loader semantics (Program + ProgramData).

Automatically recalculates rent-exempt lamports on resize.

Fully validated inputs (pubkey, hex data, offsets).

🧪 Tests

Added 17 comprehensive tests, all passing ✅:

Sequential, non-sequential, and overlapping writes

Auto account creation

Invalid input handling

Rent recalculation

Large 1 MB write

Empty and single-byte write

issue #319

image

@29deepanshutyagi
Copy link
Contributor Author

@MicaiahReid , kindly review this pr

@lgalabru
Copy link
Collaborator

lgalabru commented Nov 3, 2025

Thanks @29deepanshutyagi, we'll look into this!

@MicaiahReid
Copy link
Collaborator

This is awesome, thanks @29deepanshutyagi!

I did a minor refactor, but kept nearly all of your logic. I did the following:

  • move logic out of cheatcodes file and into locker.rs (we try to keep the rpc files clean and add all reusable logic to locker). I was able to use all of the code you wrote, it was awesome!
  • added the optional authority field to be able to write the program authority

Copy link
Collaborator

@lgalabru lgalabru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @29deepanshutyagi 🙏

@29deepanshutyagi
Copy link
Contributor Author

29deepanshutyagi commented Nov 5, 2025

Thank you @MicaiahReid and @lgalabru for the quick review and feedback! 🙏

@MicaiahReid - Thanks for taking the time to refactor and improve the code structure. Moving the logic to locker.rs makes total sense for keeping the RPC files clean, and adding the optional authority field is a great enhancement I hadn't considered.

Please Let me know if there's anything else I can help with regarding this issue

@lgalabru lgalabru merged commit 85541cf into solana-foundation:main Nov 5, 2025
3 checks passed
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.

3 participants