|
| 1 | +# Changelog |
| 2 | + |
| 3 | +All notable changes to this project will be documented in this file. |
| 4 | + |
| 5 | +## [Unreleased] |
| 6 | + |
| 7 | +### Added |
| 8 | +- **New `cpi_context` module**: Comprehensive 1500+ line CPI (Cross-Program Invocation) context management system enabling advanced multi-program operations with single zero-knowledge proof (d6d0fb5) |
| 9 | +- **Address assignment capability**: Support for spending accounts created within the same instruction via `CpiContextNewAddressParamsAssignedPacked` with `assigned_to_account` and `assigned_account_index` fields (d6d0fb5) |
| 10 | +- **Zero-copy CPI context structure**: `ZCpiContextAccount` with separate fields for different account types: |
| 11 | + - `new_addresses`: `ZeroCopyVecU8<CpiContextNewAddressParamsAssignedPacked>` for newly created addresses |
| 12 | + - `readonly_addresses`: `ZeroCopyVecU8<ZPackedReadOnlyAddress>` for read-only address references |
| 13 | + - `readonly_accounts`: `ZeroCopyVecU8<ZPackedReadOnlyCompressedAccount>` for read-only account references |
| 14 | + - `in_accounts`: `ZeroCopyVecU8<CpiContextInAccount>` for input compressed accounts |
| 15 | + - `out_accounts`: `ZeroCopyVecU8<CpiContextOutAccount>` for output compressed accounts (d6d0fb5) |
| 16 | +- **CPI-specific account structures** distinct from regular instruction data types: |
| 17 | + - `CpiContextInAccount`: Compressed input account format for CPI context (owner, discriminator, data_hash, merkle_context, root_index, lamports, optional address - 80 bytes) vs `ZPackedCompressedAccountWithMerkleContext` used in regular instruction data (includes full compressed account data, variable size) |
| 18 | + - `CpiContextOutAccount`: Compressed output account format for CPI context (owner, discriminator, data_hash, output_merkle_tree_index, lamports, optional address - 82 bytes) vs `ZOutputCompressedAccountWithPackedContext` used in regular instruction data (includes full compressed account data, variable size) |
| 19 | + - **Key difference**: CPI context accounts store only essential fields in fixed-size format for efficient cross-program caching, while regular instruction account types include full variable-length compressed account data (d6d0fb5) |
| 20 | +- **Pinocchio framework integration**: Added `pinocchio-pubkey` dependency for performance optimizations in account operations (d6d0fb5) |
| 21 | +- **Address validation traits**: New `NewAddress` trait implementation for `CpiContextNewAddressParamsAssignedPacked` with seed, queue indices, and assignment validation (d6d0fb5) |
| 22 | + |
| 23 | +### Changed |
| 24 | +- **Breaking: Complete CPI context data structure redesign** |
| 25 | + - **Old**: `CpiContextAccount { fee_payer: Pubkey, associated_merkle_tree: Pubkey, context: Vec<InstructionDataInvokeCpi> }` |
| 26 | + - **New**: `ZCpiContextAccount` with separate typed vectors for different data types and zero-copy memory layout |
| 27 | + - **Migration**: Replace `context` vector access with specific field access (`in_accounts`, `out_accounts`, `new_addresses`, etc.) (d6d0fb5) |
| 28 | +- **Breaking: `LightTransactionContext::set_cpi_context()` method signature change** |
| 29 | + - **Removed parameters**: `outputs_start_offset: usize`, `outputs_end_offset: usize` |
| 30 | + - **Reason**: Offsets now calculated internally from CPI context structure |
| 31 | + - **Migration**: Remove offset parameters from method calls (d6d0fb5) |
| 32 | +- **Breaking: CPI context account layout and serialization format** |
| 33 | + - Account data layout changed from Borsh-serialized struct to zero-copy binary format |
| 34 | + - Clients must update deserialization logic to use new `deserialize_cpi_context_account()` function (d6d0fb5) |
| 35 | +- **CPI context processing workflow**: |
| 36 | + - Enhanced two-phase execution: first invocation caches validated data in CPI context, second invocation combines and executes |
| 37 | + - Improved validation: CPI context association with Merkle tree verified only during execution phase |
| 38 | + - Better fee payer management: fee payer zeroed out when CPI context consumed to prevent reuse (d6d0fb5) |
| 39 | + |
| 40 | +### Performance |
| 41 | +- **Memory optimization**: Zero-copy patterns eliminate memory allocation overhead during CPI context operations, reducing heap usage (d6d0fb5) |
| 42 | +- **Transaction efficiency**: Single zero-knowledge proof for multi-program transactions instead of multiple proofs: |
| 43 | + - **Before**: Each program requires separate proof (128 bytes + ~100,000 CU each) |
| 44 | + - **After**: Single combined proof for all programs (128 bytes + ~100,000 CU total) (d6d0fb5) |
| 45 | +- **Instruction size reduction**: Consolidated instruction data reduces transaction size for complex multi-program operations (d6d0fb5) |
| 46 | +- **Address assignment optimization**: Created accounts can be immediately used as inputs in same instruction, eliminating need for separate transactions (d6d0fb5) |
| 47 | + |
| 48 | +### Internal |
| 49 | +- **Module restructuring**: Moved `process_cpi_context.rs` from `invoke_cpi` to dedicated `cpi_context` module for better organization (d6d0fb5) |
| 50 | +- **Comprehensive instruction data trait**: Implemented `InstructionData` trait for `ZCpiContextAccount` with proper owner, address, and account management (d6d0fb5) |
| 51 | +- **Enhanced validation pipeline**: |
| 52 | + - CPI context association validation with Merkle tree accounts |
| 53 | + - Fee payer consistency checks across invocations |
| 54 | + - Empty context detection and error handling (d6d0fb5) |
| 55 | +- **Improved error context**: Added detailed error messages for CPI context mismatches and validation failures (d6d0fb5) |
| 56 | +- **TODO cleanup**: Identified and documented areas requiring future implementation (clear_cpi_context_account, offset standardization) (41eb6df) |
| 57 | +- **Code documentation**: Added comprehensive comments explaining CPI context usage patterns and examples (51690d7) |
| 58 | + |
| 59 | +### Security |
| 60 | +- **Enhanced signer validation**: CPI context operations validate signers during both caching and execution phases (d6d0fb5) |
| 61 | +- **Context isolation**: CPI context accounts properly isolated and cleared between transactions to prevent state leakage (d6d0fb5) |
| 62 | +- **Fee payer verification**: Strict fee payer matching required between CPI context setup and execution phases (d6d0fb5) |
| 63 | +- **Bounds checking**: Comprehensive validation of account indices, output limits, and address assignment boundaries (d6d0fb5) |
| 64 | +- **State transition atomicity**: Combined instruction data execution ensures all-or-nothing state transitions across programs (d6d0fb5) |
| 65 | + |
| 66 | +### Fixed |
| 67 | +- **CPI context account clearing**: Temporarily disabled problematic account clearing logic requiring reimplementation for new structure (d6d0fb5) |
| 68 | +- **Offset calculation**: Removed manual offset tracking in favor of automated calculation from CPI context structure (41eb6df) |
| 69 | + |
| 70 | +## Migration Guide |
| 71 | + |
| 72 | +### For developers using CPI context: |
| 73 | + |
| 74 | +1. **Update CPI context account access**: |
| 75 | + ```rust |
| 76 | + // Old approach |
| 77 | + let context_data = cpi_context_account.context[0].input_compressed_accounts; |
| 78 | + |
| 79 | + // New approach |
| 80 | + let input_accounts = cpi_context_account.in_accounts; |
| 81 | + let output_accounts = cpi_context_account.out_accounts; |
| 82 | + ``` |
| 83 | + |
| 84 | +2. **Update set_cpi_context calls**: |
| 85 | + ```rust |
| 86 | + // Old signature |
| 87 | + context.set_cpi_context(cpi_context_account, start_offset, end_offset)?; |
| 88 | + |
| 89 | + // New signature |
| 90 | + context.set_cpi_context(cpi_context_account)?; |
| 91 | + ``` |
| 92 | + |
| 93 | +3. **Update account deserialization**: |
| 94 | + - Replace manual Borsh deserialization with `deserialize_cpi_context_account()` |
| 95 | + - Handle new zero-copy data structures appropriately |
| 96 | + |
| 97 | +4. **Review address assignment usage**: |
| 98 | + - Leverage new `assigned_to_account` capability for same-instruction account creation and usage |
| 99 | + - Update address handling to use new structured address parameters |
0 commit comments