Record Pointer System

This documentation describes the record pointer system employed by Avail to make referencing records on the Aleo blockchain more efficient.

The Problem

Scanning records, i.e finding tokens / unique tokens you own, is time consuming on Aleo because you have to try and decrypt every record in the blockchain to find which is yours.

For context, Aleo is a sequence of blocks that are created over time that store data like encrypted records that hold the private balances of its users. So inside every block is a sequence of encrypted records.

The Solution

To solve this one can actively scan Aleo for their newly created records and once they are found the owner can store pointers to the records they own. Like this you just scan once and then you know where your records are and can instantly reference them based on what you need.

Record Pointer Data Model

struct AvailRecord<N: Network> {
    pub pointer: Pointer<N>,
    pub metadata: Metadata,
}

struct Pointer<N: Network> {
    pub block_height: u32,
    pub transaction_id: N::TransactionID,
    pub transition_id: N::TransitionID,
    pub function_id: String,
    pub commitment: String,
    pub tag: String,
    pub spent: bool,
}

struct Metadata {
    pub record_type: RecordType,
    pub program_id: String,
}

enum RecordType {
    AleoCredits,
    NFT,
    Contracts,
    Tokens,
    None,
}

The AvailRecord data structure encapsulates the record pointer and metadata that is used to identify what type of record this references. The main components of a Pointer are the block height and the record commitment as this can be used to directly query the record on chain. The tag is used to identify if the record is spent or not and spent is used to keep track of that state.

Storage

Where do you store these record pointers ? The record pointers are encrypted using your viewing key and are stored locally on your device in a database embedded inside your wallet. Like this you have easy access to the records you need, when you need them.

What happens if you lose access to your device or delete the app ?

If you lose access to your wallet then you must go through recovery. Avail offers you the option to backup your encrypted record pointers so that when you recover you get instant access to your records again. If you opt out you will have to scan the whole Aleo blockchain again which can take quite some time to complete.

Last updated