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: 27 additions & 0 deletions .github/workflows/proofs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Proofs

on:
push:
branches: [proofs]
pull_request:
branches: [proofs]

jobs:
format_and_lint_ptoken:
name: Format & Lint p-token
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup
with:
clippy: true
rustfmt: true

- name: Format
run: pnpm p-token:format

- name: Lint
run: pnpm p-token:lint
958 changes: 618 additions & 340 deletions p-token/src/entrypoint-runtime-verification.rs

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion p-token/src/entrypoint.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use {
crate::processor::*,
pinocchio::{
account_info::AccountInfo, no_allocator, nostd_panic_handler, program_entrypoint, program_error::{ProgramError, ToStr}, pubkey::Pubkey, ProgramResult
account_info::AccountInfo,
no_allocator, nostd_panic_handler, program_entrypoint,
program_error::{ProgramError, ToStr},
pubkey::Pubkey,
ProgramResult,
},
pinocchio_token_interface::error::TokenError,
};
Expand Down
2 changes: 1 addition & 1 deletion p-token/src/stubs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ pub unsafe extern "C" fn sol_memcpy_(dst: *mut u8, src: *const u8, n: usize) {
if !dst.is_null() && !src.is_null() && n > 0 {
core::ptr::copy_nonoverlapping(src, dst, n);
}
}
}
22 changes: 19 additions & 3 deletions p-token/tests/approve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,13 @@ async fn _approve_invalid_src() {
);
let result = context.banks_client.process_transaction(tx).await;
let inner_error = result.err().unwrap().unwrap();
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData));
assert_eq!(
inner_error,
solana_transaction_error::TransactionError::InstructionError(
0,
solana_instruction::error::InstructionError::InvalidAccountData
)
);
}

#[tokio::test]
Expand Down Expand Up @@ -202,7 +208,11 @@ async fn approve_frozen() {
&[&context.payer, &freeze_authority],
context.last_blockhash,
);
context.banks_client.process_transaction(freeze_tx).await.unwrap();
context
.banks_client
.process_transaction(freeze_tx)
.await
.unwrap();

// When we approve a delegate.

Expand All @@ -226,5 +236,11 @@ async fn approve_frozen() {
);
let result = context.banks_client.process_transaction(tx).await;
let inner_error = result.err().unwrap().unwrap();
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(17)));
assert_eq!(
inner_error,
solana_transaction_error::TransactionError::InstructionError(
0,
solana_instruction::error::InstructionError::Custom(17)
)
);
}
38 changes: 33 additions & 5 deletions p-token/tests/approve_checked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,13 @@ async fn _approve_checked_invalid_src() {
);
let result = context.banks_client.process_transaction(tx).await;
let inner_error = result.err().unwrap().unwrap();
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData));
assert_eq!(
inner_error,
solana_transaction_error::TransactionError::InstructionError(
0,
solana_instruction::error::InstructionError::InvalidAccountData
)
);
}

#[tokio::test]
Expand Down Expand Up @@ -206,7 +212,11 @@ async fn approve_checked_frozen() {
&[&context.payer, &freeze_authority],
context.last_blockhash,
);
context.banks_client.process_transaction(freeze_tx).await.unwrap();
context
.banks_client
.process_transaction(freeze_tx)
.await
.unwrap();

// When we approve a delegate.

Expand All @@ -232,7 +242,13 @@ async fn approve_checked_frozen() {
);
let result = context.banks_client.process_transaction(tx).await;
let inner_error = result.err().unwrap().unwrap();
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(17)));
assert_eq!(
inner_error,
solana_transaction_error::TransactionError::InstructionError(
0,
solana_instruction::error::InstructionError::Custom(17)
)
);
}

#[tokio::test]
Expand Down Expand Up @@ -297,7 +313,13 @@ async fn approve_checked_mint_mismatch() {
);
let result = context.banks_client.process_transaction(tx).await;
let inner_error = result.err().unwrap().unwrap();
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(3)));
assert_eq!(
inner_error,
solana_transaction_error::TransactionError::InstructionError(
0,
solana_instruction::error::InstructionError::Custom(3)
)
);
}

#[tokio::test]
Expand Down Expand Up @@ -362,5 +384,11 @@ async fn approve_checked_incorrect_decimals() {
);
let result = context.banks_client.process_transaction(tx).await;
let inner_error = result.err().unwrap().unwrap();
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(18)));
assert_eq!(
inner_error,
solana_transaction_error::TransactionError::InstructionError(
0,
solana_instruction::error::InstructionError::Custom(18)
)
);
}
70 changes: 58 additions & 12 deletions p-token/tests/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,15 @@ async fn _burn_invalid_source() {

// When we burn 50 tokens.

let burn_ix =
spl_token::instruction::burn(&spl_token::ID, &Pubkey::new_unique(), &mint, &owner.pubkey(), &[], 50)
.unwrap(); // Invalid sender
let burn_ix = spl_token::instruction::burn(
&spl_token::ID,
&Pubkey::new_unique(),
&mint,
&owner.pubkey(),
&[],
50,
)
.unwrap(); // Invalid sender

let tx = Transaction::new_signed_with_payer(
&[burn_ix],
Expand All @@ -126,7 +132,13 @@ async fn _burn_invalid_source() {
);
let result = context.banks_client.process_transaction(tx).await;
let inner_error = result.err().unwrap().unwrap();
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData));
assert_eq!(
inner_error,
solana_transaction_error::TransactionError::InstructionError(
0,
solana_instruction::error::InstructionError::InvalidAccountData
)
);
}

#[tokio::test]
Expand Down Expand Up @@ -182,7 +194,11 @@ async fn burn_frozen_source() {
&[&context.payer, &freeze_authority],
context.last_blockhash,
);
context.banks_client.process_transaction(freeze_tx).await.unwrap();
context
.banks_client
.process_transaction(freeze_tx)
.await
.unwrap();

// When we burn 50 tokens.

Expand All @@ -198,7 +214,13 @@ async fn burn_frozen_source() {
);
let result = context.banks_client.process_transaction(tx).await;
let inner_error = result.err().unwrap().unwrap();
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(17)));
assert_eq!(
inner_error,
solana_transaction_error::TransactionError::InstructionError(
0,
solana_instruction::error::InstructionError::Custom(17)
)
);
}

#[tokio::test]
Expand Down Expand Up @@ -230,7 +252,13 @@ async fn burn_native() {
);
let result = context.banks_client.process_transaction(tx).await;
let inner_error = result.err().unwrap().unwrap();
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(10)));
assert_eq!(
inner_error,
solana_transaction_error::TransactionError::InstructionError(
0,
solana_instruction::error::InstructionError::Custom(10)
)
);
}

#[tokio::test]
Expand Down Expand Up @@ -285,7 +313,13 @@ async fn burn_excessive_amount() {
);
let result = context.banks_client.process_transaction(tx).await;
let inner_error = result.err().unwrap().unwrap();
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(1)));
assert_eq!(
inner_error,
solana_transaction_error::TransactionError::InstructionError(
0,
solana_instruction::error::InstructionError::Custom(1)
)
);
}

#[tokio::test]
Expand Down Expand Up @@ -330,9 +364,15 @@ async fn burn_different_mint() {

// When we burn 50 tokens.

let burn_ix =
spl_token::instruction::burn(&spl_token::ID, &account, &native_mint, &owner.pubkey(), &[], 50)
.unwrap();
let burn_ix = spl_token::instruction::burn(
&spl_token::ID,
&account,
&native_mint,
&owner.pubkey(),
&[],
50,
)
.unwrap();

let tx = Transaction::new_signed_with_payer(
&[burn_ix],
Expand All @@ -342,5 +382,11 @@ async fn burn_different_mint() {
);
let result = context.banks_client.process_transaction(tx).await;
let inner_error = result.err().unwrap().unwrap();
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(3)));
assert_eq!(
inner_error,
solana_transaction_error::TransactionError::InstructionError(
0,
solana_instruction::error::InstructionError::Custom(3)
)
);
}
54 changes: 47 additions & 7 deletions p-token/tests/burn_checked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ async fn _burn_checked_invalid_source() {
);
let result = context.banks_client.process_transaction(tx).await;
let inner_error = result.err().unwrap().unwrap();
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData));
assert_eq!(
inner_error,
solana_transaction_error::TransactionError::InstructionError(
0,
solana_instruction::error::InstructionError::InvalidAccountData
)
);
}

#[tokio::test]
Expand Down Expand Up @@ -196,7 +202,11 @@ async fn burn_checked_frozen_source() {
&[&context.payer, &freeze_authority],
context.last_blockhash,
);
context.banks_client.process_transaction(freeze_tx).await.unwrap();
context
.banks_client
.process_transaction(freeze_tx)
.await
.unwrap();

// When we burn 50 tokens.

Expand All @@ -219,7 +229,13 @@ async fn burn_checked_frozen_source() {
);
let result = context.banks_client.process_transaction(tx).await;
let inner_error = result.err().unwrap().unwrap();
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(17)));
assert_eq!(
inner_error,
solana_transaction_error::TransactionError::InstructionError(
0,
solana_instruction::error::InstructionError::Custom(17)
)
);
}

#[tokio::test]
Expand Down Expand Up @@ -258,7 +274,13 @@ async fn burn_checked_native() {
);
let result = context.banks_client.process_transaction(tx).await;
let inner_error = result.err().unwrap().unwrap();
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(10)));
assert_eq!(
inner_error,
solana_transaction_error::TransactionError::InstructionError(
0,
solana_instruction::error::InstructionError::Custom(10)
)
);
}

#[tokio::test]
Expand Down Expand Up @@ -320,7 +342,13 @@ async fn burn_checked_excessive_amount() {
);
let result = context.banks_client.process_transaction(tx).await;
let inner_error = result.err().unwrap().unwrap();
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(1)));
assert_eq!(
inner_error,
solana_transaction_error::TransactionError::InstructionError(
0,
solana_instruction::error::InstructionError::Custom(1)
)
);
}

#[tokio::test]
Expand Down Expand Up @@ -384,7 +412,13 @@ async fn burn_checked_different_mint() {
);
let result = context.banks_client.process_transaction(tx).await;
let inner_error = result.err().unwrap().unwrap();
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(3)));
assert_eq!(
inner_error,
solana_transaction_error::TransactionError::InstructionError(
0,
solana_instruction::error::InstructionError::Custom(3)
)
);
}

#[tokio::test]
Expand Down Expand Up @@ -446,5 +480,11 @@ async fn burn_checked_incorrect_decimals() {
);
let result = context.banks_client.process_transaction(tx).await;
let inner_error = result.err().unwrap().unwrap();
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(18)));
assert_eq!(
inner_error,
solana_transaction_error::TransactionError::InstructionError(
0,
solana_instruction::error::InstructionError::Custom(18)
)
);
}
Loading