regolith-labs / steel

Solana smart contract framework.
87 stars 14 forks source link

Nostd entrypoint (less CU) #1

Open ebrightfield opened 3 days ago

ebrightfield commented 3 days ago

I haven't tested it much, but someone wrote this awesome solana-nostd-entrypoint crate.

I just played around with a feature-flagged re-export of it in steel, and an example using it here.

Supposedly it uses much less CU than the "vanilla" Solana entrypoint macro (I haven't personally benchmarked it yet). The main difference that it introduces is replacing AccountInfo<'_> with a NoStdAccountInfo, which in turn required minor changes to the loaders (implemented in the commit linked above), and CPIs (not implemented in the commit yet).

In the spirit of optimization, it could be a good choice for steel!

HardhatChad commented 2 days ago

Yes, I have discussed this with Cavey at length. I would like to introduce that here and would approve any PR that does so. As you mentioned, the main complications are just replacing AccountInfo<'_> and using invoke_signed_c for CPIs. When I was working on ORE, the nostd entrypoint crate was brand new (still being written) so I avoided using it at the time. I think to integrate it here, one should add a "nostd" feature flag and optionally reimplement that basic features using the types from the nostd crate.

Jac0xb commented 2 days ago

For what it's worth replacing AccountInfo is not easy since there are many places in the solana program spl token, etc crates that use it. I tried to write a solana program with this entrypoint macro and once you start trying to do instruction building for CPI it becomes a chore.

ebrightfield commented 1 day ago

Yeah the CPI stuff definitely is the biggest challenge here, updating the loaders was a no-brainer, building instructions for CPI is definitely a chore, as illustrated by the example in the nostd-entrypoint repo.

Thinking that an IDL-assisted instruction building interface might be the missing piece here. The .to_info_c() and .to_meta_c() boilerplate can be routinized, as long as the instruction interface is well-defined up-front somewhere.