Skip to content

Commit 20acfb8

Browse files
ananas-blockSwenSchaeferjohann
authored andcommitted
feat: ctoken pinocchio
feat: add addresses to cpi context, enable spending of created accounts in same ix refactor: cpi context, enable addresses, enable assigned addresses, placeholders for readonly addresses, and accounts,breaking account layout change feat: add cpi context to ctoken ixs feat: update compressed mint, untested refactor: rename TokenContext -> HashCache feat: sha hashing for cmints, start update_metadata feat: add update to mint action feat: mint to decompressed feat: ctoken pinocchio post rebase feat: add addresses to cpi context, enable spending of created accounts in same ix system program update small instruction sdk token 4 cpis works chained token test create mint in cpi context works chaind token mint to works stash multiple ctoken action test implemented not working for address creation fails refactor: cpi context, enable addresses, enable assigned addresses, placeholders for readonly addresses, and accounts,breaking account layout change feat: add cpi context to ctoken ixs fix: chained ctoken actions test fix: cpi context address owner feat: update compressed mint, untested fix tests client test works fixed event parsing in system program, chained test works refactor: rename TokenContext -> HashCache cleanup ix data, rename UpdateCompressedMintInstructionData -> CompressedMintWithContext, UpdateCompressedMintInstructionDataV2 -> UpdateCompressedMintInstructionData feat: sha hashing for cmints, start update_metadata minor CU improvements feat: add zero copy enum support stash mint action feat: add update to mint action stash implemeneted mint actions for existing ixs test: mint actions with token client works without create mint stash cleanup cleanup chained action test passes stash chained test cleanup cleanup errors started refactor create spl mint feat: mint to decompressed update metadata compiles stash stash stash fix: mint hashing feat: format tx logs in light program test fix: logging fix: create spl test_create_compressed_mint_with_token_metadata_sha works fix: mint action program side bugs fix: test test_create_compressed_mint_with_token_metadata_poseidon fix create compressed mint test fix: update mint authority refactor: chained test to pda_ctoken, ctoken_pda comment create_spl_mint dir remove: dead code compressed token program test: decompressed transfer and update latest slot fix: token22 import fix: tests add program id check, cleanups refactor: unify create pda refactor associated token update claude md reactor: close account refactor: create token account refactor: mint_to_action fix: close account fix: mint action test refactor and cleanup create mint action mint action cleanup refactor: update authorities refactor: mint to decompressed refactor: update metadata refactor: update metadata authority cleanup refactor: always check that authority is signer cleanup fix: token sdk tests cherrypicked hasher update: support sha in hasher and lighthasher macro lint remove unused _output_account_info update lightdiscriminator macro wip add compress_pda helper compress_pda compiling decompress_idempotent.rs wip wip decompress batch idempotent wip add compress_pda_new and compress_multiple_pdas_new native program with decompress done compress_dynamic, decompress_dynamic wip adding anchor testprogram uses sdk fix compilation wip experiment with procmacro skip SLOT check at compress_pda_new wip add_compressible_instructions() works for compress, idl gen works add proc macro decompress_multiple_pdas is working as it should fix decompress_idempotent impl rm expanded add remove_data force apps to pass the whole signer_seeds directly add compressible_config draft add create_config_unchecked and checked use config, add unified header struct (just last_written_slot) for now use hascompressioninfo and compressioninfo add config support to compressible macro add expanded.rs cleanup anchor-derived example add support for multiple address_trees per address space add support for multiple address_trees per address space update macro to multiple address_trees add test-sdk-derived program wip cleanup native macro-derive example wip fix compilation config tests working clean up test_config.rs testing add a separate anchor compress_pda_new version so we dont have redundant serde wip wip wip fix decompress_idempotent anchor add test with 2nd account decompress works with multiple different PDAs cleanup, remove anchor helper decompress_multiple_pdas, fix discriminator writes rm examples simplify add compress_multiple_new + test add test add test: compressing multiple accounts_new fix compress_pda and add test added test case: invalid compression cleanup cleanup fmt and lint for anchor-compressible-user program config ix helpers added tests working, added generic create_compress_account_instruction rm warnings added standardized decompress_multiple_accounts_idempotent client rm idl add cu logger util wip add test: decompress with accounts stored in 2 different v2 state trees, added 2nd tree impl. to program-test and cli, added util to xtask clean clean up librs add opt anchor program error conv for errors, fix compression_info usage with single account struct wip clean fmt comments wip sdk-tests working extend and fix sdk-test tests, cleanup csdk, anchor program, update macro clean clean clean data_hasher.rs clean derive program tests, renaming, better simulate_cu err handling renames, remove deadcode remove unused discriminator field from config account move variable length field to end of config account struct simplify anchor/borsh serde imports add DEFAULT_DATA_HASH to constants rename CompressionInfo::new() to CompressionInfo::new_decompressed() xtask, remove helper wip remove redundant owner_program param add compile time size() rename pda_account to solana_account fix doctest output.data correctly clean initconfig, updatteconfig accounts struct rename signer_seeds to solana_accounts__signer_seeds move programs to sdk-test dir move to light-compressible-client lint ci wip wip add check load config add sdk-tests to workspace rename sdk-tests program names fix ci fix asserts in tests fmt update pkg json for sdk-tests debug prints for ci in test_indexer fmt make macro robust, lint anchor-discriminator-compat feature for LightDiscriminator lint add test_discriminator test replace actionlint revert actionlint macro: allow flex imports wip fmt update macro add sha hash function support to LightAccount and LightHasher + tests DataHasher macro: explicit validation for sha fix rebase gmt add compressible macro rebased - fixed macro compressAs trait for compression with custom data add test, fix lint compress_as, flexible Compressible macro auto-derives HasCompressionInfo macro clean remove debug trait bound wip wip add compress_empty_account for native + tests refactor compression config actions to accept rpc trait better upgrade_authority check better error logging add cpda derivation check in prepare_empty_compressed_accounts_on_init js: dedupe in lut creation add PackedAccounts, deriveAddressV2, initializeCompressionConfig helpers add borsh_compat module for validityProof add compressible ts sdk packedaccounts, fix v2 tree getters wip wip wip switch to cpiaccountsSmall wip wip wip wip workaround assign correct hash in client add leafIndex bug reproducer in sdk-token-test pda_ctoken test_indexer, rm debug fix: test_indexer treetype assignment (hotfix) patch compressed accounts with correct leaf_indices in test_indexer clean apply jorrits rc fix add ts packedAccountsSmall, add cpi_inputs helpers for using cpi_context wip wip make csdk use heap alot wip fix new_address_owner assignment array len wip 0x3a99 add fetch_accounts, wip wip bump photon version add clear upd fetch-accounts
1 parent 1eb02d9 commit 20acfb8

File tree

514 files changed

+58173
-2263
lines changed

Some content is hidden

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

514 files changed

+58173
-2263
lines changed

.cargo/config.toml

Lines changed: 0 additions & 40 deletions
This file was deleted.

.github/workflows/ci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ jobs:
1212
shell: bash
1313
- name: Check workflow files
1414
run: ${{ steps.get_actionlint.outputs.executable }} -color
15-
shell: bash
15+
shell: bash

.github/workflows/light-examples-tests.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ on:
44
- main
55
paths:
66
- "examples/**"
7+
- "program-tests/sdk-anchor-test/**"
8+
- "program-tests/sdk-pinocchio-test/**"
79
- "sdk-libs/**"
810
pull_request:
911
branches:
1012
- "*"
1113
paths:
1214
- "examples/**"
15+
- "program-tests/sdk-anchor-test/**"
16+
- "program-tests/sdk-pinocchio-test/**"
1317
- "sdk-libs/**"
1418
types:
1519
- opened
@@ -24,8 +28,8 @@ concurrency:
2428
cancel-in-progress: true
2529

2630
jobs:
27-
system-programs:
28-
name: system-programs
31+
examples-tests:
32+
name: examples-tests
2933
if: github.event.pull_request.draft == false
3034
runs-on: ubuntu-latest
3135
timeout-minutes: 60
@@ -47,8 +51,6 @@ jobs:
4751
strategy:
4852
matrix:
4953
include:
50-
- program: sdk-test-program
51-
sub-tests: '["cargo-test-sbf -p sdk-test"]'
5254
- program: sdk-anchor-test-program
5355
sub-tests: '["cargo-test-sbf -p sdk-anchor-test", "cargo-test-sbf -p sdk-pinocchio-test"]'
5456

.github/workflows/sdk-tests.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
paths:
6+
- "sdk-tests/**"
7+
- "sdk-libs/**"
8+
- "program-libs/**"
9+
- ".github/workflows/sdk-tests.yml"
10+
pull_request:
11+
branches:
12+
- "*"
13+
paths:
14+
- "sdk-tests/**"
15+
- "sdk-libs/**"
16+
- "program-libs/**"
17+
- ".github/workflows/sdk-tests.yml"
18+
types:
19+
- opened
20+
- synchronize
21+
- reopened
22+
- ready_for_review
23+
24+
name: sdk-tests
25+
26+
concurrency:
27+
group: ${{ github.workflow }}-${{ github.ref }}
28+
cancel-in-progress: true
29+
30+
jobs:
31+
sdk-tests:
32+
name: sdk-tests
33+
if: github.event.pull_request.draft == false
34+
runs-on: warp-ubuntu-latest-x64-4x
35+
timeout-minutes: 60
36+
37+
services:
38+
redis:
39+
image: redis:8.0.1
40+
ports:
41+
- 6379:6379
42+
options: >-
43+
--health-cmd "redis-cli ping"
44+
--health-interval 10s
45+
--health-timeout 5s
46+
--health-retries 5
47+
48+
env:
49+
REDIS_URL: redis://localhost:6379
50+
RUST_MIN_STACK: 8388608
51+
52+
steps:
53+
- name: Checkout sources
54+
uses: actions/checkout@v4
55+
56+
- name: Setup and build
57+
uses: ./.github/actions/setup-and-build
58+
with:
59+
skip-components: "redis"
60+
61+
- name: Build CLI
62+
run: |
63+
source ./scripts/devenv.sh
64+
npx nx build @lightprotocol/zk-compression-cli
65+
66+
- name: Build core programs
67+
run: |
68+
source ./scripts/devenv.sh
69+
npx nx build @lightprotocol/programs
70+
71+
- name: Build and test all sdk-tests programs
72+
run: |
73+
source ./scripts/devenv.sh
74+
# Increase stack size for SBF compilation to avoid regex_automata stack overflow
75+
export RUST_MIN_STACK=16777216
76+
# Remove -D warnings flag for SBF compilation to avoid compilation issues
77+
export RUSTFLAGS=""
78+
79+
echo "Building and testing all sdk-tests programs sequentially..."
80+
# Build and test each program one by one to ensure .so files exist
81+
82+
echo "Building and testing native-compressible"
83+
cargo-test-sbf -p native-compressible
84+
85+
echo "Building and testing anchor-compressible"
86+
cargo-test-sbf -p anchor-compressible
87+
88+
echo "Building and testing anchor-compressible-derived"
89+
cargo-test-sbf -p anchor-compressible-derived

CLAUDE.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Testing
2+
3+
This repository uses a comprehensive two-tier testing strategy:
4+
5+
- **[Unit Testing Guide](./UNIT_TESTING.md)** - For testing individual functions in isolation using mock account infos. Tests are located in `tests/` directories within each crate.
6+
7+
- **[Integration Testing Guide](./INTEGRATION_TESTING.md)** - For testing complete program workflows using full SVM simulation. Tests are located in the `program-tests/` directory.
8+
9+
## Key Testing Requirements
10+
11+
All tests must follow these mandatory requirements:
12+
13+
- **Functional test for every usage flow**
14+
- **Failing test for every error condition**
15+
- **Complete output verification** with single `assert_eq!` against expected structs
16+
- **1k iteration randomized tests** for complex functions and ZeroCopy structs
17+
18+
# Debugging with LightProgramTest
19+
20+
## Transaction Log File
21+
22+
The light-program-test library automatically creates detailed transaction logs in:
23+
24+
```
25+
target/light_program_test.log
26+
```
27+
28+
### Features
29+
30+
- **Always enabled**: Logs are written to file regardless of environment variables
31+
- **Clean format**: Plain text without ANSI color codes for easy reading and processing
32+
- **Session-based**: Each test session starts with a timestamp header, transactions append to the same file
33+
- **Comprehensive details**: Includes transaction signatures, fees, compute usage, instruction hierarchies, Light Protocol instruction parsing, and compressed account information
34+
35+
### Configuration
36+
37+
Enhanced logging is enabled by default. To disable:
38+
39+
```rust
40+
let mut config = ProgramTestConfig::default();
41+
config.enhanced_logging.enabled = false;
42+
```
43+
44+
Console output requires `RUST_BACKTRACE` environment variable and can be controlled separately from file logging.
45+
46+
### Log File Location
47+
48+
The log file is automatically placed in the cargo workspace target directory, making it consistent across different test environments and working directories.
49+
50+
# Program Performance
51+
52+
- send bump seeds
53+
- avoid deriving addresses
54+
- avoid vectors stack over heap use ArrayVec
55+
56+
# Program Security
57+
58+
- every input (instruction data and account infos) must be checked
59+
- inclusion of instruction data in an input compressed account data hash counts as checked
60+
61+
### Account checks
62+
63+
- ownership is checked
64+
- cpis should use hardcoded
65+
66+
### Compressed accounts
67+
68+
- the program id is the owner of the compressed account
69+
- data hash must be computed in the owning program
70+
- all data that is in an input compressed account is checked implicitly by inclusion in the data hash, the data hash is part of the compressed account hash that is in the Merkle tree or queue which we prove inclusion in by zkp or index
71+
- input compressed account
72+
- is existing state
73+
- validity is proven by index (zkp is None) or zkp
74+
- no data is sent to the system program
75+
- data hash must be computed in the owning program
76+
- output compressed account
77+
- this is new state, no validity proof
78+
- data hash must be computed in the owning program
79+
- no changes to data after data hash has been computed
80+
- minimize use of instruction data, ie do not send data twice.
81+
82+
1. example, owner pubkey
83+
if a compressed account has an owner pubkey field which should be a tx signer, send it as signer account info, set it in the custom program, and do not sending it as instruction data. No comparison in the program is required.
84+
2. example, values from accounts
85+
86+
- a compressed account the state update is atomic through the cpi to the light system program, writes to the cpi context can produce non atomic transactions if solana accounts are involved and instantly updated for compressed accounts atomicity still applies, in case that a written cpi context account is not executed the state update is never actually applied only prepared.
87+
88+
# Zero Copies
89+
90+
- the derive macros ZeroCopy and ZeroCopyMut derive zero copy deserialization methods and should be used in programs
91+
- in client code borsh is preferable
92+
- ZeroCopy is borsh compatible
93+
- # Z and Z\*Mut structs are derived by the ZeroCopy and ZeroCopyMut macros and cannot be searched with grep or rg, search for the non prefixed struct instead the zero copy struct has the same structure with zero copy types.
94+
- a compressed account the state update is atomic through the cpi to the light system program, writes to the cpi context can produce non atomic transactions if solana accounts are involved and instantly updated for compressed accounts atomicity still applies, in case that a written cpi context account is not executed the state update is never actually applied only prepared.
95+
> > > > > > > eeb1ded20 (feat: ctoken pinocchio)

COMMON_ERRORS.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
1. │ ERROR: Not enough accounts. Requested 'burn change account owner' at index 3 but only 0 accounts available. programs/compressed-token/program/src/mint_action/burn.rs:142:41
2+
- means that packed accounts doesn't contain enough accounts
3+
-
4+
2. `NotEnoughSigners`
5+
- `create_and_send_transaction(&[instruction], &payer.pubkey(), &signers)`
6+
- needs more signers
7+
- signers must be unique you must not pass the same twice it will result in an error
8+
3. `CompressedAccountError::ZeroCopyExpectedAddress => 12017`
9+
- when setting output compressed accounts in a zero copy we expect an address to be provided the address is allocated as Some by the ZeroCopyConfig but None is provided
10+
- any error that contains Expected and is an CompressedAccountError means this for the specied compressed account field
11+
4. `Signer/Program cannot write into an account it doesn't own.`
12+
```mode Small
13+
│ Signer/Program cannot write into an account it doesn't own. Write access check failed, compressed account owner [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] != invoking_program_id [9, 21, 163, 87, 35, 121, 78, 143, 182, 93, 7, 91, 107, 114, 105, 156, 56, 221, 2, 229, 148, 139, 117, 176, 229, 160, 65, 142, 128, 151, 91, 68].
14+
│ Program SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7 consumed 17422 of 1186879 compute units
15+
│ Program SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7 failed: custom program error: 0x177d
16+
│ Program cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m consumed 230543 of 1400000 compute units
17+
│ Program cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m failed: custom program error: 0x177d
18+
```
19+
- the compressed output account owner is not set
20+
5. ` Program SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7 failed: custom program error: 0x179a`
21+
-
22+
- the index for a state Merkle tree in the packed accounts is wrong

0 commit comments

Comments
 (0)