Skip to content
Draft
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
7 changes: 6 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ jobs:
run: |
cargo build

- name: run tests
- name: run tests (cargo test)
run: |
export PATH="/home/runner/.local/share/solana/install/active_release/bin:$PATH"
cargo test

- name: run tests (cargo test-sbf)
run: |
export PATH="/home/runner/.local/share/solana/install/active_release/bin:$PATH"
cargo test-sbf --features unit_test_config
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pinocchio-associated-token-account = { version = "0.3.0" , optional = true }
solana-address = { version = "2.0", features = ["bytemuck", "decode", "syscalls", "curve25519", "std"] }

# manually resolves the conflict with a pinned version of serde
serde = "=1.0.226"
serde = { version = "=1.0.226", features = ["derive"] }

[dev-dependencies]
assertables = "9.8.2"
Expand Down
5 changes: 4 additions & 1 deletion src/args/delegate.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use borsh::{BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};
use solana_program::pubkey::Pubkey;

#[derive(Default, Debug, BorshSerialize, BorshDeserialize)]
#[derive(
Default, Debug, BorshSerialize, BorshDeserialize, Serialize, Deserialize,
)]
pub struct DelegateArgs {
/// The frequency at which the validator should commit the account data
/// if no commit is triggered by the owning program
Expand Down
48 changes: 48 additions & 0 deletions src/args/delegate_with_actions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use serde::{Deserialize, Serialize};
use solana_program::{instruction::Instruction, pubkey::Pubkey};

use super::DelegateArgs;
use crate::compact;

#[derive(Debug, Serialize, Deserialize)]
pub struct DelegateWithActionsArgs {
/// Standard delegation parameters.
pub delegate: DelegateArgs,

/// Compact post-delegation actions.
pub actions: PostDelegationActions,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PostDelegationActions {
/// Number of signer pubkeys in the `pubkeys` prefix.
/// First `signer_count` entries of `pubkeys` are required signers.
pub signer_count: u8,

/// Shared pubkey table. Account metas and program IDs reference this table by index.
pub pubkeys: Vec<Pubkey>,

/// Instruction payload in compact cleartext or encrypted bytes.
pub instructions: Instructions,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum Instructions {
/// Compact cleartext instructions.
ClearText {
instructions: Vec<compact::Instruction>,
},

/// Encrypted compact instruction bytes.
Encrypted { instructions: Vec<u8> },
}

#[derive(Debug, Serialize, Deserialize)]
pub struct DecryptedInstructions {
/// Sender-provided nonce/salt to randomize ciphertext so identical
/// plaintext does not always map to identical encrypted bytes.
pub random_salt: u64,

/// Decrypted instructions ready for execution.
pub instructions: Vec<Instruction>,
}
2 changes: 2 additions & 0 deletions src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod call_handler;
mod commit_state;
mod delegate;
mod delegate_ephemeral_balance;
mod delegate_with_actions;
mod top_up_ephemeral_balance;
mod types;
mod validator_claim_fees;
Expand All @@ -11,6 +12,7 @@ pub use call_handler::*;
pub use commit_state::*;
pub use delegate::*;
pub use delegate_ephemeral_balance::*;
pub use delegate_with_actions::*;
pub use top_up_ephemeral_balance::*;
pub use types::*;
pub use validator_claim_fees::*;
Expand Down
60 changes: 60 additions & 0 deletions src/compact/account_meta.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use serde::{Deserialize, Serialize};

const ACCOUNT_INDEX_MASK: u8 = 0b0011_1111;
const SIGNER_MASK: u8 = 0b0100_0000;
const WRITABLE_MASK: u8 = 0b1000_0000;

///
/// MAX_PUBKEYS = 64
///
pub const MAX_PUBKEYS: usize = ACCOUNT_INDEX_MASK as usize + 1;

/// Compact account meta packed into one byte.
/// Bits `0..=5` encode the pubkey-table index (`0..MAX_PUBKEYS-1`).
/// Bit `6` is `is_signer`, and bit `7` is `is_writable`.
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub struct AccountMeta(pub u8);

impl AccountMeta {
pub fn new(index: usize, is_signer: bool) -> Self {
Self::try_new(index, is_signer, true).expect("index is out of range")
}
pub fn new_readonly(index: usize, is_signer: bool) -> Self {
Self::try_new(index, is_signer, false).expect("index is out of range")
}

pub fn try_new(
index: usize,
is_signer: bool,
is_writable: bool,
) -> Option<Self> {
if index >= MAX_PUBKEYS {
return None;
}
let mut packed = index as u8;
if is_signer {
packed |= SIGNER_MASK;
}
if is_writable {
packed |= WRITABLE_MASK;
}
Some(Self(packed))
}

pub fn index(self) -> usize {
(self.0 & ACCOUNT_INDEX_MASK) as usize
}

pub fn is_signer(self) -> bool {
(self.0 & SIGNER_MASK) != 0
}

pub fn is_writable(self) -> bool {
(self.0 & WRITABLE_MASK) != 0
}

pub fn set_index(&mut self, new_index: usize) {
*self = Self::try_new(new_index, self.is_signer(), self.is_writable())
.expect("index is out of range");
}
}
10 changes: 10 additions & 0 deletions src/compact/instruction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use serde::{Deserialize, Serialize};

use crate::compact;

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Instruction {
pub program_id: u8,
pub accounts: Vec<compact::AccountMeta>,
pub data: Vec<u8>,
}
5 changes: 5 additions & 0 deletions src/compact/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod account_meta;
mod instruction;

pub use account_meta::*;
pub use instruction::*;
3 changes: 3 additions & 0 deletions src/discriminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ pub enum DlpDiscriminator {

/// See [crate::processor::process_commit_finalize_from_buffer] for docs.
CommitFinalizeFromBuffer = 22,

/// See [crate::processor::process_delegate_with_actions] for docs.
DelegateWithActions = 23,
}

impl DlpDiscriminator {
Expand Down
Loading
Loading