3

I ask this because I noticed even the no-op instruction uses a some compute units (I assume for loading the program and stuff like this) and it made me wonder. Is there a lower bound? Is it zero?

2 Answers 2

5

Depends on how deep you want to go. I won't be able to give an exact number, but hopefully a picture can be painted here. Theoretically the very minimum would be 1 CU (to my knowledge every transaction has to actually do something), but in reality most transactions will use at least 1 syscall. For example "sol_log" uses about 100 CUs in an assembly program. A standard entrypoint in a program (using C or Rust) will normally log a fair bit of compute usage as well.

A good representation of this would be the sbpf-inline-asm example from Dean Little. He uses some basic asm instructions + the sol_log syscall. This logs at 104 CUs iirc (most from the logging), and to date it's probably the smallest program I've ever seen by that metric.

EDIT: I linked the wrong repo. The correct one I was referring to is this

3
  • This is helpful, thank you! I'm asking mostly from a theoretical standpoint (partially to help me answer solana.stackexchange.com/questions/14701/…), so the program can be completely useless as long as the transaction would pass onchain. Judging from the asm example, the minimum would be 1 CU by just doing a mov for example correct?
    – McBain
    Commented Jun 12 at 20:22
  • @Ahri custom entrypoint (similar to link above) -> single operation -> exit would use about 1 CU. This is also assuming no instruction data provided (not sure if loading that into memory would add more CUs)
    – Joey Meere
    Commented Jun 13 at 13:33
  • Got it, thank you!
    – McBain
    Commented Jun 13 at 18:46
4

If your program just calls exit, then it's possible for the program to only take 1 CU. Currently, there's no CU cost to instruction data, loading account data, or taking write locks, but that might change in the future.

Here's that example:

#[no_mangle]
pub extern "C" fn entrypoint(_: *mut u8) -> () {
}
#[no_mangle]
fn custom_panic(_info: &core::panic::PanicInfo<'_>) {}
solana_program::custom_heap_default!();

If you dump the program, then you'll see the singular call to exit:

$ ~/.local/share/solana/install/active_release/bin/sdk/sbf/scripts/dump.sh target/deploy/program.so out.txt
$ cat out.txt
... loads of other stuff ...
Disassembly of section .text

0000000000000120 <entrypoint>
      36        95 00 00 00 00 00 00 00 exit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.