febo / pinocchio

Create Solana programs with no dependencies attached
Apache License 2.0
89 stars 18 forks source link

Add `checked_create_program_address` helper #30

Closed febo closed 1 month ago

febo commented 1 month ago

Problem

The current create_program_address helper validates the seeds length before calling the syscall. While in many cases this is useful, since it avoids incurring the costs of the syscall when the seeds are invalid, it consumes additional CUs.

Solution

Add an checked_* variant for the helper, where seeds length are validated before the syscall.

The current create_program_address is modified to not include the validation and therefore has a smaller CU footprint. Seeds are always validated by the syscall, therefore the difference in this case is to avoid consuming CUs for the duplicated validation while incurring the cost of the syscall in case seeds length are invalid.