Overview
Theaccount_decompress syscall restores a compressed account by providing the account’s data and a state proof verifying the data’s authenticity. This allows retrieval of previously compressed account state.
Syscall Code
Code:0x09 (TN_SYSCALL_CODE_ACCOUNT_DECOMPRESS)
C SDK Function
Arguments
Index of the account to decompress. Must be writable in the transaction and currently compressed or non-existent.
Pointer to the account metadata.
Pointer to the account data payload.
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 decompressed successfully
TN_VM_ERR_SYSCALL_INVALID_ACCOUNT_INDEX(-7) - Account index out of boundsTN_VM_ERR_SYSCALL_ACCOUNT_NOT_WRITABLE(-26) - Account not writable in transactionTN_VM_ERR_SYSCALL_ACCOUNT_ALREADY_EXISTS(-14) - Account is already active (not compressed)TN_VM_ERR_SYSCALL_ACCOUNT_IN_COMPRESSION_TIMEOUT(-33) - Account in compression cooldown periodTN_VM_ERR_SYSCALL_INVALID_ACCOUNT_DATA_SIZE(-34) - Invalid account data sizeTN_VM_ERR_SYSCALL_INVALID_ADDRESS(-21) - Invalid virtual address for data or proofTN_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 failedTN_VM_ERR_SYSCALL_INSUFFICIENT_PAGES(-25) - Not enough pages for account data
Resource Consumption
Compute Units
- Base cost:
TN_VM_SYSCALL_BASE_COST(512 units) - Data cost: Additional units equal to account data size in bytes
- Proof cost: Additional units equal to proof size in bytes
- Total formula:
base_cost + data_sz + proof_sz
Memory Pages
- Page allocation: Pages allocated for restored account data
- Data pages: Number of pages based on account data size (page-aligned)
- Metadata pages: Pages for account metadata structure
- Proof verification: Temporary memory usage for proof validation
Side Effects
- Account restoration: Restores account metadata and data from provided input
- Flag clearing: Removes COMPRESSED flag from the account
- Memory allocation: Allocates pages for the account data
Data Format
The account data must be structured as:State Proof Verification
- Proof type: Must be
TN_STATE_PROOF_TYPE_EXISTING - Hash verification: Computed account hash must match the proof
- Block validation: Proof must reference a valid historical block
- State root: Account hash must verify against the block’s state root
Compression Timeout
Accounts have a compression timeout period during which they cannot be decompressed. This prevents rapid compress/decompress cycles.Usage Notes
- Account must be writable in the transaction (signer approval)
- Account data size must match the metadata’s declared data size
- The provided data is validated by computing and verifying its hash
- Account becomes fully active after successful decompression
- Sufficient pages must be available for the account data