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
16 changes: 8 additions & 8 deletions Cargo.lock

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

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,18 @@ light-hash-set = { version = "3.0.0", path = "program-libs/hash-set" }
light-indexed-merkle-tree = { version = "3.0.0", path = "program-libs/indexed-merkle-tree" }
light-concurrent-merkle-tree = { version = "3.0.0", path = "program-libs/concurrent-merkle-tree" }
light-sparse-merkle-tree = { version = "0.2.0", path = "sparse-merkle-tree" }
light-client = { path = "sdk-libs/client", version = "0.15.0" }
light-client = { path = "sdk-libs/client", version = "0.16.0" }
light-event = { path = "sdk-libs/event", version = "0.1.0" }
light-hasher = { path = "program-libs/hasher", version = "4.0.0", default-features = false }
light-macros = { path = "program-libs/macros", version = "2.1.0" }
light-merkle-tree-reference = { path = "program-tests/merkle-tree", version = "3.0.1" }
light-heap = { path = "program-libs/heap", version = "2.0.0" }
light-prover-client = { path = "prover/client", version = "3.0.0" }
light-sdk = { path = "sdk-libs/sdk", version = "0.15.0" }
light-sdk-pinocchio = { path = "sdk-libs/sdk-pinocchio", version = "0.13.0" }
light-sdk-macros = { path = "sdk-libs/macros", version = "0.15.0" }
light-sdk-types = { path = "sdk-libs/sdk-types", version = "0.15.0", default-features = false }
light-compressed-account = { path = "program-libs/compressed-account", version = "0.5.0", default-features = false }
light-prover-client = { path = "prover/client", version = "4.0.0" }
light-sdk = { path = "sdk-libs/sdk", version = "0.16.0" }
light-sdk-pinocchio = { path = "sdk-libs/sdk-pinocchio", version = "0.14.0" }
light-sdk-macros = { path = "sdk-libs/macros", version = "0.16.0" }
light-sdk-types = { path = "sdk-libs/sdk-types", version = "0.16.0", default-features = false }
light-compressed-account = { path = "program-libs/compressed-account", version = "0.6.0", default-features = false }
light-compressible = { path = "program-libs/compressible", version = "0.1.0" }
light-ctoken-types = { path = "program-libs/ctoken-types", version = "0.1.0" }
light-account-checks = { path = "program-libs/account-checks", version = "0.4.0", default-features = false }
Expand All @@ -205,7 +205,7 @@ light-registry = { path = "programs/registry", version = "2.0.0", features = [
create-address-test-program = { path = "program-tests/create-address-test-program", version = "1.0.0", features = [
"cpi",
] }
light-program-test = { path = "sdk-libs/program-test", version = "0.15.0" }
light-program-test = { path = "sdk-libs/program-test", version = "0.16.0" }
light-batched-merkle-tree = { path = "program-libs/batched-merkle-tree", version = "0.5.0" }
light-merkle-tree-metadata = { path = "program-libs/merkle-tree-metadata", version = "0.5.0" }
aligned-sized = { path = "program-libs/aligned-sized", version = "1.1.0" }
Expand Down
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lightprotocol/zk-compression-cli",
"version": "0.27.0",
"version": "0.27.1-alpha.2",
"description": "ZK Compression: Secure Scaling on Solana",
"maintainers": [
{
Expand Down
2 changes: 1 addition & 1 deletion js/compressed-token/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lightprotocol/compressed-token",
"version": "0.22.0",
"version": "0.22.1-alpha.2",
"description": "JS client to interact with the compressed-token program",
"sideEffects": false,
"main": "dist/cjs/node/index.cjs",
Expand Down
2 changes: 1 addition & 1 deletion js/stateless.js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lightprotocol/stateless.js",
"version": "0.22.0",
"version": "0.22.1-alpha.1",
"description": "JavaScript API for Light & ZK Compression",
"sideEffects": false,
"main": "dist/cjs/node/index.cjs",
Expand Down
2 changes: 1 addition & 1 deletion program-libs/compressed-account/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "light-compressed-account"
version = "0.5.0"
version = "0.6.0"
description = "Compressed account struct and common utility functions used in Light Protocol."
repository = "https://github.com/Lightprotocol/light-protocol"
license = "Apache-2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,34 @@ impl Default for CompressedProof {
}
}

impl CompressedProof {
/// Convert the proof to a fixed-size byte array [u8; 128]
pub fn to_array(&self) -> [u8; 128] {
let mut result = [0u8; 128];
result[0..32].copy_from_slice(&self.a);
result[32..96].copy_from_slice(&self.b);
result[96..128].copy_from_slice(&self.c);
result
}
}

impl TryFrom<&[u8]> for CompressedProof {
type Error = crate::CompressedAccountError;

fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> {
if bytes.len() < 128 {
return Err(crate::CompressedAccountError::InvalidProofSize(bytes.len()));
}
let mut a = [0u8; 32];
let mut b = [0u8; 64];
let mut c = [0u8; 32];
a.copy_from_slice(&bytes[0..32]);
b.copy_from_slice(&bytes[32..96]);
c.copy_from_slice(&bytes[96..128]);
Ok(Self { a, b, c })
}
}

impl<'a> ZeroCopyAt<'a> for CompressedProof {
type ZeroCopyAt = Ref<&'a [u8], Self>;
fn zero_copy_at(bytes: &'a [u8]) -> Result<(Self::ZeroCopyAt, &'a [u8]), ZeroCopyError> {
Expand All @@ -61,6 +89,12 @@ impl ValidityProof {
pub fn new(proof: Option<CompressedProof>) -> Self {
Self(proof)
}

/// Convert the validity proof to a fixed-size byte array [u8; 128]
/// Returns None if the proof is None
pub fn to_array(&self) -> Option<[u8; 128]> {
self.0.as_ref().map(|proof| proof.to_array())
}
}

impl From<CompressedProof> for ValidityProof {
Expand All @@ -86,6 +120,21 @@ impl From<&Option<CompressedProof>> for ValidityProof {
}
}

impl TryFrom<&[u8]> for ValidityProof {
type Error = crate::CompressedAccountError;

/// Convert bytes to ValidityProof.
/// Empty slice returns None, otherwise attempts to parse as CompressedProof and returns Some.
fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> {
if bytes.is_empty() {
Ok(Self(None))
} else {
let proof = CompressedProof::try_from(bytes)?;
Ok(Self(Some(proof)))
}
}
}

#[allow(clippy::from_over_into)]
impl Into<Option<CompressedProof>> for ValidityProof {
fn into(self) -> Option<CompressedProof> {
Expand Down
3 changes: 3 additions & 0 deletions program-libs/compressed-account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ pub enum CompressedAccountError {
InstructionDataExpectedProof,
#[error("Expected proof for compressed account got None.")]
ZeroCopyExpectedProof,
#[error("Invalid proof size: expected 128 bytes, got {0}")]
InvalidProofSize(usize),
}

// NOTE(vadorovsky): Unfortunately, we need to do it by hand.
Expand Down Expand Up @@ -103,6 +105,7 @@ impl From<CompressedAccountError> for u32 {
CompressedAccountError::ZeroCopyExpectedProof => 12022,
CompressedAccountError::ExpectedDataHash => 12023,
CompressedAccountError::InvalidCpiContext => 12024,
CompressedAccountError::InvalidProofSize(_) => 12025,
CompressedAccountError::HasherError(e) => u32::from(e),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use light_ctoken_types::{
state::CompressedMint,
};
use light_program_profiler::profile;
use light_sdk_pinocchio::ZOutputCompressedAccountWithPackedContextMut;
use light_sdk_pinocchio::instruction::ZOutputCompressedAccountWithPackedContextMut;

use crate::{
mint_action::{
Expand Down
2 changes: 1 addition & 1 deletion prover/client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "light-prover-client"
version = "3.0.0"
version = "4.0.0"
description = "Crate for interacting with Light Protocol circuits"
repository = "https://github.com/Lightprotocol/light-protocol"
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion sdk-libs/client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "light-client"
version = "0.15.0"
version = "0.16.0"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/lightprotocol/light-protocol"
Expand Down
2 changes: 1 addition & 1 deletion sdk-libs/macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "light-sdk-macros"
version = "0.15.0"
version = "0.16.0"
description = "Macros for Programs using the Light SDK for ZK Compression "
repository = "https://github.com/Lightprotocol/light-protocol"
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion sdk-libs/program-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "light-program-test"
version = "0.15.0"
version = "0.16.0"
description = "A fast local test environment for Solana programs using compressed accounts and tokens."
license = "MIT"
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion sdk-libs/sdk-pinocchio/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "light-sdk-pinocchio"
version = "0.13.0"
version = "0.14.0"
description = "Rust SDK for ZK Compression on Solana with Pinocchio features"
repository = "https://github.com/Lightprotocol/light-protocol"
license = "Apache-2.0"
Expand Down
30 changes: 3 additions & 27 deletions sdk-libs/sdk-pinocchio/src/address.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
use pinocchio::{account_info::AccountInfo, pubkey::Pubkey};

// Define data structures needed
#[derive(Clone, Debug, Default)]
pub struct NewAddressParams {
pub seed: [u8; 32],
pub address_queue_pubkey: [u8; 32],
pub address_merkle_tree_pubkey: [u8; 32],
pub address_merkle_tree_root_index: u16,
}

pub fn unpack_new_address_params(
address_params: &crate::NewAddressParamsPacked,
remaining_accounts: &[AccountInfo],
) -> NewAddressParams {
let address_merkle_tree_pubkey =
remaining_accounts[address_params.address_merkle_tree_account_index as usize].key();
let address_queue_pubkey =
remaining_accounts[address_params.address_queue_account_index as usize].key();

NewAddressParams {
seed: address_params.seed,
address_queue_pubkey: *address_queue_pubkey,
address_merkle_tree_pubkey: *address_merkle_tree_pubkey,
address_merkle_tree_root_index: address_params.address_merkle_tree_root_index,
}
}
pub use light_compressed_account::instruction_data::data::NewAddressParamsPacked;
pub use light_sdk_types::address::AddressSeed;
use pinocchio::pubkey::Pubkey;

pub mod v1 {
use light_sdk_types::address::AddressSeed;
Expand Down
25 changes: 25 additions & 0 deletions sdk-libs/sdk-pinocchio/src/cpi/account.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#[cfg(all(not(feature = "std"), feature = "alloc"))]
extern crate alloc;
#[cfg(all(not(feature = "std"), feature = "alloc"))]
use alloc::vec::Vec;
#[cfg(feature = "std")]
use std::vec::Vec;

use pinocchio::instruction::AccountMeta;

/// Trait for types that can provide account information for CPI calls
pub trait CpiAccountsTrait {
/// Convert to a vector of AccountMeta references for instruction
fn to_account_metas(&self) -> crate::error::Result<Vec<AccountMeta<'_>>>;

/// Convert to account infos for invoke
fn to_account_infos_for_invoke(
&self,
) -> crate::error::Result<Vec<&pinocchio::account_info::AccountInfo>>;

/// Get the CPI signer bump
fn bump(&self) -> u8;

/// Get the mode for the instruction (0 for v1, 1 for v2)
fn get_mode(&self) -> u8;
}
22 changes: 22 additions & 0 deletions sdk-libs/sdk-pinocchio/src/cpi/instruction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use light_compressed_account::instruction_data::compressed_proof::ValidityProof;
pub use light_compressed_account::LightInstructionData;

/// Trait for Light CPI instruction types
pub trait LightCpiInstruction: Sized {
fn new_cpi(cpi_signer: light_sdk_types::CpiSigner, proof: ValidityProof) -> Self;

#[cfg(feature = "light-account")]
fn with_light_account<A>(
self,
account: crate::LightAccount<'_, A>,
) -> Result<Self, pinocchio::program_error::ProgramError>
where
A: borsh::BorshSerialize
+ borsh::BorshDeserialize
+ crate::LightDiscriminator
+ light_hasher::DataHasher
+ Default;

fn get_mode(&self) -> u8;
fn get_bump(&self) -> u8;
}
Loading
Loading