Overview
Theaccount_compress syscall compresses an account by setting the COMPRESSED flag and providing a state proof. This allows the account data to be stored more efficiently while maintaining verifiability.
Syscall Code
Code:0x08 (TN_SYSCALL_CODE_ACCOUNT_COMPRESS)
C SDK Function
Arguments
Index of the account to compress. Must be writable in the transaction.
Pointer to the state proof data.
Size of the state proof data in bytes.
Return Value
Returns a syscall result code:TN_VM_SYSCALL_SUCCESS(0) - Account compressed successfully0(special case) - Ephemeral account deleted instead of compressed
TN_VM_ERR_SYSCALL_INVALID_ACCOUNT_INDEX(-7) - Account index out of boundsTN_VM_ERR_SYSCALL_ACCOUNT_DOES_NOT_EXIST(-8) - Account does not existTN_VM_ERR_SYSCALL_ACCOUNT_NOT_WRITABLE(-26) - Account not writable in transactionTN_VM_ERR_SYSCALL_TXN_HAS_COMPRESSED_ACCOUNT(-36) - Transaction already has a compressed accountTN_VM_ERR_SYSCALL_INVALID_PROOF_LEN(-31) - Proof size mismatchTN_VM_ERR_SYSCALL_INVALID_PROOF_SLOT(-32) - Proof references invalid block slotTN_VM_ERR_SYSCALL_INVALID_STATE_PROOF(-22) - State proof verification failed
Resource Consumption
Compute Units
- Base cost:
TN_VM_SYSCALL_BASE_COST(512 units) - Proof cost: Additional units equal to proof size in bytes
- Data cost: Additional units equal to account data size in bytes
- Metadata cost: Additional units equal to
sizeof(tn_account_meta_t) - Total formula:
base_cost + proof_sz + account_data_sz + sizeof(tn_account_meta_t)
Memory Pages
- Page usage: No immediate page deallocation (compression is logical)
- Proof storage: Temporary memory for proof verification
- Metadata impact: Account metadata becomes writable if not already
Side Effects
- Account state: Sets COMPRESSED flag and updates state counter
- Transaction state: Records compression proof for transaction
- Special handling: Ephemeral and deleted accounts are deleted instead
Special Cases
- Ephemeral Accounts
- Deleted Accounts
- New Accounts
Ephemeral accounts are simply deleted when “compressed” - they cannot be truly compressed since they don’t persist beyond the transaction.
State Proof Requirements
- New accounts: Must use
TN_STATE_PROOF_TYPE_CREATIONproof type - Existing accounts: Must use
TN_STATE_PROOF_TYPE_EXISTINGproof type - Proof verification: Must reference valid block slot and verify against state root
- Account hash: Proof must match the computed hash of the account’s current state
Transaction Limitations
- Only one account can be compressed per transaction
- The transaction records the compression proof and account details
- Compression state is tracked to prevent multiple compressions
Usage Notes
- Account must be writable in the transaction (signer approval)
- State proof ensures the account state is correctly recorded
- Compressed accounts can later be decompressed with valid proofs
- The account’s state counter is updated to the proof block’s counter