Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ a little-endian u64 in instruction data.
| Zig | 38 |
| C | 104 |
| Assembly | 30 |
| Rust (pinocchio) | 32 |
| Rust (pinocchio) | 28 |

This one starts to get interesting since it requires parsing the instruction
input. Since the assembly version knows exactly where to find everything, it can
be hyper-optimized. The pinocchio version performs very closely to the assembly
be hyper-optimized. The pinocchio version performs better than the assembly
implementation!

### CPI
Expand All @@ -188,7 +188,7 @@ address and `invoke_signed` to CPI to the system program.
| Rust | 3698 | 1198 |
| Zig | 2809 | 309 |
| C | 3122 | 622 |
| Rust (pinocchio) | 2816 | 316 |
| Rust (pinocchio) | 2802 | 302 |

Note: `create_program_address` consumes 1500 CUs, and `invoke` consumes 1000, so
we can subtract 2500 CUs from each program to see the actual cost of the program
Expand Down
4 changes: 2 additions & 2 deletions cpi/pinocchio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "1.0.0"
edition = "2021"

[dependencies]
pinocchio = "0.6"
pinocchio-system = "0.2"
pinocchio = "0.9.1"
pinocchio-system = "0.3.0"

[lib]
crate-type = ["cdylib", "lib"]
14 changes: 9 additions & 5 deletions cpi/pinocchio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
#![deny(missing_docs)]

use pinocchio::{
instruction::{Account, AccountMeta, Instruction},
instruction::{Account, AccountMeta, Instruction, Signer},
lazy_entrypoint::InstructionContext,
program::invoke_signed_unchecked,
program_error::ProgramError,
pubkey::create_program_address,
signer, ProgramResult,
seeds, ProgramResult,
};

// Since this is a single instruction program, we use the "lazy" variation
// of the entrypoint.
pinocchio::lazy_entrypoint!(process_instruction);
pinocchio::lazy_program_entrypoint!(process_instruction);

/// Amount of bytes of account data to allocate
pub const SIZE: usize = 42;
Expand All @@ -31,7 +31,8 @@ fn process_instruction(mut context: InstructionContext) -> ProgramResult {

// Again, don't need to check that all accounts have been consumed, we know
// we have exactly 2 accounts.
let (instruction_data, program_id) = unsafe { context.instruction_data_unchecked() };
let instruction_data = unsafe { context.instruction_data_unchecked() };
let program_id = unsafe { context.program_id_unchecked() };

let expected_allocated_key =
create_program_address(&[b"You pass butter", &[instruction_data[0]]], program_id)?;
Expand All @@ -57,7 +58,10 @@ fn process_instruction(mut context: InstructionContext) -> ProgramResult {
invoke_signed_unchecked(
&instruction,
&[Account::from(&allocated_info)],
&[signer!(b"You pass butter", &[instruction_data[0]])],
&[Signer::from(&seeds!(
b"You pass butter",
&[instruction_data[0]]
))],
)
};

Expand Down
2 changes: 1 addition & 1 deletion transfer-lamports/pinocchio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
no-entrypoint = []

[dependencies]
pinocchio = "0.6"
pinocchio = "0.9.1"

[lib]
crate-type = ["cdylib", "lib"]
4 changes: 2 additions & 2 deletions transfer-lamports/pinocchio/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use pinocchio::{

// Since this is a single instruction program, we use the "lazy" variation
// of the entrypoint.
pinocchio::lazy_entrypoint!(process_instruction);
pinocchio::lazy_program_entrypoint!(process_instruction);

#[inline]
fn process_instruction(mut context: InstructionContext) -> ProgramResult {
Expand Down Expand Up @@ -38,7 +38,7 @@ fn process_instruction(mut context: InstructionContext) -> ProgramResult {
// accounts are different, so we can safely ignore the case when the account is
// duplicated.
if let MaybeAccount::Account(destination_info) = context.next_account_unchecked() {
let (instruction_data, _) = context.instruction_data_unchecked();
let instruction_data = context.instruction_data_unchecked();
let transfer_amount = u64::from_le_bytes(instruction_data.try_into().unwrap());
// withdraw five lamports
*source_info.borrow_mut_lamports_unchecked() -= transfer_amount;
Expand Down