Skip to content

Commit 95ebdc0

Browse files
committed
feat: zero-copy-derive
fix: light-zero-copy tests comment derive mut commented byte len fix: derive macro for non mut pre bytelen refactor: detach bytelen trait stash adding config simple config derive works stash stash new at stash new at Compressed Account stash man InstructionDataInvoke new_zero_copy works stash simple config zero_copy_new tests stash refactor fixed lifetime issue stash instruction data tests work move byte_len to init_mut added randomized tests stash got failing random tests fixed u8 and bool remove bytelen renamed trait fix lint fix tests apply feedback meta_struct use syn to parse options instead of strings primitive types Replace string-based type comparisons with proper syn AST matching replace parse_str with parse_quote replace empty quote with unreachable! add byte len check borsh_vec_u8_as_slice_mut converted unimplemented to panic cleanup redundant as u64 etc fix docs cleanup cleanup commtend code cleanup mut conditionals remove bytelen derive cleanup refactor: replace duplicate code with generate_deserialize_call refactor detecting copy moved to internal refactor: add error handling cleanup cleanup file structure stash wip transform all primitive types to zero copy types simplify analyze_struct_fields fix empty meta struct generation stash zero copy changes unified some with Deserialize::Output unified integer field type enum renam VecNonStaticZeroCopy -> VecDynamicZeroCopy Simplify Option inner type extraction using syn utilities. Add bounds check before writing discriminant byte. improve generate_field_initialization remove debug test Incorrect type conversion from u8 to u32, add note options in arrays are not supported Error context lost in conversion format and add heap allocation check Check the last path segment for accurate type detection fix: test fix: test improve cache robustness fix format renamed Config -> ZeroCopyConfig, impl ZeroCopyMut light compressed account types
1 parent 5fb5198 commit 95ebdc0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+8865
-33
lines changed

.github/workflows/rust.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ jobs:
5353
cargo test -p light-account-checks --all-features
5454
cargo test -p light-verifier --all-features
5555
cargo test -p light-merkle-tree-metadata --all-features
56-
cargo test -p light-zero-copy --features std
56+
cargo test -p light-zero-copy --features "std, mut, derive"
57+
cargo test -p light-zero-copy-derive --features "mut"
5758
cargo test -p light-hash-set --all-features
5859
- name: program-libs-slow
5960
packages: light-bloom-filter light-indexed-merkle-tree light-batched-merkle-tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,5 @@ output1.txt
8686
.zed
8787

8888
**/.claude/**/*
89+
90+
expand.rs

Cargo.lock

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ members = [
1313
"program-libs/hash-set",
1414
"program-libs/indexed-merkle-tree",
1515
"program-libs/indexed-array",
16+
"program-libs/zero-copy-derive",
1617
"programs/account-compression",
1718
"programs/system",
1819
"programs/compressed-token",
@@ -167,6 +168,7 @@ light-compressed-account = { path = "program-libs/compressed-account", version =
167168
light-account-checks = { path = "program-libs/account-checks", version = "0.3.0" }
168169
light-verifier = { path = "program-libs/verifier", version = "2.1.0" }
169170
light-zero-copy = { path = "program-libs/zero-copy", version = "0.2.0" }
171+
light-zero-copy-derive = { path = "program-libs/zero-copy-derive", version = "0.1.0" }
170172
photon-api = { path = "sdk-libs/photon-api", version = "0.51.0" }
171173
forester-utils = { path = "forester-utils", version = "2.0.0" }
172174
account-compression = { path = "programs/account-compression", version = "2.0.0", features = [

program-libs/compressed-account/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ new-unique = ["dep:solana-pubkey"]
1818
thiserror = { workspace = true }
1919
zerocopy = { workspace = true, features = ["derive"] }
2020
light-hasher = { workspace = true }
21-
light-zero-copy = { workspace = true, features = ["std"] }
21+
light-zero-copy = { workspace = true, features = ["std", "mut", "derive"] }
2222
light-macros = { workspace = true }
2323
pinocchio = { workspace = true, optional = true }
2424
solana-program-error = { workspace = true, optional = true }

program-libs/compressed-account/src/compressed_account.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::collections::HashMap;
22

33
use light_hasher::{Hasher, Poseidon};
4+
use light_zero_copy::ZeroCopyMut;
45

56
use crate::{
67
address::pack_account,
@@ -11,7 +12,7 @@ use crate::{
1112
AnchorDeserialize, AnchorSerialize, CompressedAccountError, Pubkey, TreeType,
1213
};
1314

14-
#[derive(Debug, PartialEq, Default, Clone, AnchorSerialize, AnchorDeserialize)]
15+
#[derive(Debug, PartialEq, Default, Clone, AnchorSerialize, AnchorDeserialize, ZeroCopyMut)]
1516
pub struct PackedCompressedAccountWithMerkleContext {
1617
pub compressed_account: CompressedAccount,
1718
pub merkle_context: PackedMerkleContext,
@@ -149,7 +150,9 @@ pub struct MerkleContext {
149150
pub tree_type: TreeType,
150151
}
151152

152-
#[derive(Debug, Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Default)]
153+
#[derive(
154+
Debug, Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Default, ZeroCopyMut,
155+
)]
153156
pub struct PackedMerkleContext {
154157
pub merkle_tree_pubkey_index: u8,
155158
pub queue_pubkey_index: u8,
@@ -217,7 +220,7 @@ pub fn pack_merkle_context(
217220
.collect::<Vec<_>>()
218221
}
219222

220-
#[derive(Debug, PartialEq, Default, Clone, AnchorSerialize, AnchorDeserialize)]
223+
#[derive(Debug, PartialEq, Default, Clone, AnchorSerialize, AnchorDeserialize, ZeroCopyMut)]
221224
pub struct CompressedAccount {
222225
pub owner: Pubkey,
223226
pub lamports: u64,
@@ -234,7 +237,7 @@ pub struct InCompressedAccount {
234237
pub address: Option<[u8; 32]>,
235238
}
236239

237-
#[derive(Debug, PartialEq, Default, Clone, AnchorSerialize, AnchorDeserialize)]
240+
#[derive(Debug, PartialEq, Default, Clone, AnchorSerialize, AnchorDeserialize, ZeroCopyMut)]
238241
pub struct CompressedAccountData {
239242
pub discriminator: [u8; 8],
240243
pub data: Vec<u8>,

program-libs/compressed-account/src/instruction_data/compressed_proof.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use light_zero_copy::{borsh::Deserialize, errors::ZeroCopyError};
1+
use light_zero_copy::{borsh::Deserialize, errors::ZeroCopyError, ZeroCopyMut};
22
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout, Ref, Unaligned};
33

44
use crate::{AnchorDeserialize, AnchorSerialize};
@@ -17,6 +17,7 @@ use crate::{AnchorDeserialize, AnchorSerialize};
1717
FromBytes,
1818
IntoBytes,
1919
Unaligned,
20+
ZeroCopyMut,
2021
)]
2122
pub struct CompressedProof {
2223
pub a: [u8; 32],

program-libs/compressed-account/src/instruction_data/cpi_context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
use light_zero_copy::ZeroCopyMut;
2+
13
use crate::{AnchorDeserialize, AnchorSerialize};
24

3-
#[derive(AnchorSerialize, AnchorDeserialize, Debug, Clone, Copy, PartialEq, Eq, Default)]
5+
#[derive(
6+
AnchorSerialize, AnchorDeserialize, Debug, Clone, Copy, PartialEq, Eq, Default, ZeroCopyMut,
7+
)]
48
pub struct CompressedCpiContext {
59
/// Is set by the program that is invoking the CPI to signal that is should
610
/// set the cpi context.

program-libs/compressed-account/src/instruction_data/data.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::collections::HashMap;
22

3+
use light_zero_copy::ZeroCopyMut;
4+
35
use crate::{
46
compressed_account::{CompressedAccount, PackedCompressedAccountWithMerkleContext},
57
instruction_data::compressed_proof::CompressedProof,
@@ -24,13 +26,15 @@ pub struct OutputCompressedAccountWithContext {
2426
pub merkle_tree: Pubkey,
2527
}
2628

27-
#[derive(Debug, PartialEq, Default, Clone, AnchorDeserialize, AnchorSerialize)]
29+
#[derive(Debug, PartialEq, Default, Clone, AnchorDeserialize, AnchorSerialize, ZeroCopyMut)]
2830
pub struct OutputCompressedAccountWithPackedContext {
2931
pub compressed_account: CompressedAccount,
3032
pub merkle_tree_index: u8,
3133
}
3234

33-
#[derive(Debug, PartialEq, Default, Clone, Copy, AnchorDeserialize, AnchorSerialize)]
35+
#[derive(
36+
Debug, PartialEq, Default, Clone, Copy, AnchorDeserialize, AnchorSerialize, ZeroCopyMut,
37+
)]
3438
pub struct NewAddressParamsPacked {
3539
pub seed: [u8; 32],
3640
pub address_queue_account_index: u8,

program-libs/compressed-account/src/instruction_data/invoke_cpi.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use light_zero_copy::ZeroCopyMut;
2+
13
use super::{
24
cpi_context::CompressedCpiContext,
35
data::{NewAddressParamsPacked, OutputCompressedAccountWithPackedContext},
@@ -8,7 +10,7 @@ use crate::{
810
};
911

1012
#[repr(C)]
11-
#[derive(Debug, PartialEq, Default, Clone, AnchorDeserialize, AnchorSerialize)]
13+
#[derive(Debug, PartialEq, Default, Clone, AnchorDeserialize, AnchorSerialize, ZeroCopyMut)]
1214
pub struct InstructionDataInvokeCpi {
1315
pub proof: Option<CompressedProof>,
1416
pub new_address_params: Vec<NewAddressParamsPacked>,

0 commit comments

Comments
 (0)