Skip to content

Commit d6d0fb5

Browse files
committed
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
1 parent 1eb02d9 commit d6d0fb5

File tree

384 files changed

+40110
-1454
lines changed

Some content is hidden

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

384 files changed

+40110
-1454
lines changed

.cargo/config.toml

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

CLAUDE.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
- **Functional test for every usage flow**
13+
- **Failing test for every error condition**
14+
- **Complete output verification** with single `assert_eq!` against expected structs
15+
- **1k iteration randomized tests** for complex functions and ZeroCopy structs
16+
17+
# Debugging with LightProgramTest
18+
19+
## Transaction Log File
20+
21+
The light-program-test library automatically creates detailed transaction logs in:
22+
```
23+
target/light_program_test.log
24+
```
25+
26+
### Features
27+
28+
- **Always enabled**: Logs are written to file regardless of environment variables
29+
- **Clean format**: Plain text without ANSI color codes for easy reading and processing
30+
- **Session-based**: Each test session starts with a timestamp header, transactions append to the same file
31+
- **Comprehensive details**: Includes transaction signatures, fees, compute usage, instruction hierarchies, Light Protocol instruction parsing, and compressed account information
32+
33+
### Configuration
34+
35+
Enhanced logging is enabled by default. To disable:
36+
```rust
37+
let mut config = ProgramTestConfig::default();
38+
config.enhanced_logging.enabled = false;
39+
```
40+
41+
Console output requires `RUST_BACKTRACE` environment variable and can be controlled separately from file logging.
42+
43+
### Log File Location
44+
45+
The log file is automatically placed in the cargo workspace target directory, making it consistent across different test environments and working directories.
46+
47+
# Program Performance
48+
- send bump seeds
49+
- avoid deriving addresses
50+
- avoid vectors stack over heap use ArrayVec
51+
52+
# Program Security
53+
54+
- every input (instruction data and account infos) must be checked
55+
- inclusion of instruction data in an input compressed account data hash counts as checked
56+
57+
### Account checks
58+
- ownership is checked
59+
- cpis should use hardcoded
60+
61+
### Compressed accounts
62+
- the program id is the owner of the compressed account
63+
- data hash must be computed in the owning program
64+
- 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
65+
- input compressed account
66+
- is existing state
67+
- validity is proven by index (zkp is None) or zkp
68+
- no data is sent to the system program
69+
- data hash must be computed in the owning program
70+
- output compressed account
71+
- this is new state, no validity proof
72+
- data hash must be computed in the owning program
73+
- no changes to data after data hash has been computed
74+
- minimize use of instruction data, ie do not send data twice.
75+
1. example, owner pubkey
76+
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.
77+
2. example, values from accounts
78+
79+
-
80+
81+
- 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.
82+
83+
84+
# Zero Copies
85+
- the derive macros ZeroCopy and ZeroCopyMut derive zero copy deserialization methods and should be used in programs
86+
- in client code borsh is preferable
87+
- ZeroCopy is borsh compatible
88+
- 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.

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)