Skip to content

refactor: sdk & fix zero copy derive #1647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
light-verifier
light-merkle-tree-metadata
light-zero-copy
light-zero-copy-derive
light-hash-set
light-indexed-merkle-tree
light-batched-merkle-tree
Expand Down
82 changes: 81 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"program-libs/verifier",
"program-libs/merkle-tree-metadata",
"program-libs/zero-copy",
"program-libs/zero-copy-derive",
"program-libs/concurrent-merkle-tree",
"program-libs/hash-set",
"program-libs/indexed-merkle-tree",
Expand Down
4 changes: 1 addition & 3 deletions program-libs/compressed-account/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ pub fn derive_address_legacy(
merkle_tree_pubkey: &Pubkey,
seed: &[u8; 32],
) -> Result<[u8; 32], CompressedAccountError> {
let hash =
hash_to_bn254_field_size_be([merkle_tree_pubkey.to_bytes(), *seed].concat().as_slice());
Ok(hash)
Ok(hash_to_bn254_field_size_be([merkle_tree_pubkey.to_bytes(), *seed].concat().as_slice()))
}

pub fn derive_address(
Expand Down
11 changes: 9 additions & 2 deletions program-libs/compressed-account/src/compressed_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use anchor_lang::{AnchorDeserialize, AnchorSerialize};
#[cfg(not(feature = "anchor"))]
use borsh::{BorshDeserialize as AnchorDeserialize, BorshSerialize as AnchorSerialize};
use light_hasher::{Hasher, Poseidon};
use light_zero_copy::{ZeroCopy, ZeroCopyEq};
use solana_program::pubkey::Pubkey;
use zerocopy::{Immutable, KnownLayout, Unaligned};

use crate::{
address::pack_account,
Expand Down Expand Up @@ -93,7 +95,10 @@ pub struct ReadOnlyCompressedAccount {
pub root_index: u16,
}

#[derive(Debug, PartialEq, Default, Clone, AnchorSerialize, AnchorDeserialize)]
#[repr(C)]
#[derive(
Debug, PartialEq, Default, Clone, Copy, AnchorSerialize, AnchorDeserialize, ZeroCopy, ZeroCopyEq,
)]
pub struct PackedReadOnlyCompressedAccount {
pub account_hash: [u8; 32],
pub merkle_context: PackedMerkleContext,
Expand All @@ -109,7 +114,9 @@ pub struct MerkleContext {
pub tree_type: TreeType,
}

#[derive(Debug, Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Default)]
#[derive(
Debug, Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Default, ZeroCopy, ZeroCopyEq,
)]
pub struct PackedMerkleContext {
pub merkle_tree_pubkey_index: u8,
pub nullifier_queue_pubkey_index: u8,
Expand Down
Loading
Loading