Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.privora.xyz/llms.txt

Use this file to discover all available pages before exploring further.

The test environment provides utilities for encrypting and submitting test data.

Encrypt and Submit

Submit encrypted values directly to the data store:
// Encrypt and submit u8
let hash = env.encrypt_and_submit_u8(100);

// Encrypt and submit u32
let hash = env.encrypt_and_submit_u32(100000);

// Encrypt and submit u64
let hash = env.encrypt_and_submit_u64(10000000000);
Returns a 32-byte hash that can be used in instructions.

Decrypt and Fetch

Retrieve and decrypt values for verification:
// Fetch and decrypt u8
let value: u8 = env.fetch_and_decrypt_u8(&hash);

// Fetch and decrypt u32
let value: u32 = env.fetch_and_decrypt_u32(&hash);

// Fetch and decrypt u64
let value: u64 = env.fetch_and_decrypt_u64(&hash);

Raw Data Access

For low-level access:
// Submit raw data
let hash = env.submit_data(ciphertext_bytes);

// Get raw data
let data = env.get_data(&hash).unwrap();

Creating EncryptedRef

Create typed references for use in test data structures:
let hash = env.encrypt_and_submit_u8(100);

// Create typed reference
let price_ref: EncryptedRef<u8> = env.encrypted_ref_u8(hash);
let amount_ref: EncryptedRef<u32> = env.encrypted_ref_u32(hash);
let value_ref: EncryptedRef<u64> = env.encrypted_ref_u64(hash);

Data Store Synchronization

Critical for proper test execution:
// Before sending transaction: make data available to program
env.sync_data_store_to_syscalls();

// ... send transaction ...

// After transaction: retrieve program outputs
env.sync_data_store_from_syscalls();

Example: Multiple Values

#[test]
fn test_orderbook_match() {
    let mut env = FheTestEnv::new();
    env.deploy_program(PROGRAM_ID, include_bytes!("../program.so"));

    // Encrypt order data
    let buy_price_hash = env.encrypt_and_submit_u8(100);
    let buy_qty_hash = env.encrypt_and_submit_u8(50);
    let sell_price_hash = env.encrypt_and_submit_u8(95);
    let sell_qty_hash = env.encrypt_and_submit_u8(30);

    // Build instruction with hashes
    let mut data = vec![2u8]; // MatchOrders instruction
    data.extend_from_slice(&buy_price_hash);
    data.extend_from_slice(&buy_qty_hash);
    data.extend_from_slice(&sell_price_hash);
    data.extend_from_slice(&sell_qty_hash);

    // Send transaction and verify...
}

Direct Client Key Access

For advanced testing, access the TFHE keys directly:
// Client key for encryption/decryption
let client_key = &env.client_key;

// Encrypt manually
let encrypted = tfhe::FheUint8::encrypt(100, client_key);
let bytes = bincode::serialize(&encrypted).unwrap();
let hash = env.submit_data(bytes);

// Decrypt manually
let data = env.get_data(&hash).unwrap();
let encrypted: tfhe::FheUint8 = bincode::deserialize(&data).unwrap();
let value: u8 = encrypted.decrypt(client_key);