Several concepts about Aleo development

Feng
5 min readFeb 15, 2024

--

1.Leo, Programming Language for Zero Knowledge Proofs

Both Leo and its compiled Aleo instruction are part of the Aleo smart contract, as are Solidity and dozens of other chains’ programming languages, all of which are tools for on-chain transactions and dApp development. Nevertheless, Aleo is different in that its programming language is based on zksnark, a solution to Zero Knowledge Proofs. By packaging the “smart contract execution” into a polynomial with homomorphic encryption, the result of this polynomial can be verified to determine whether the transaction is trustworthy or not, so that it can achieve true privacy computing and privacy transactions. The graphic below depicts the exact operating method.

This paradigm of off-chain execution and verification provides the program with an unbounded runtime, but on-chain nodes simply need to verify whether Proof is correct, and the verification time is substantially lower than the execution time, therefore TPS can be significantly increased. At the same time, because there is no such on-chain runtime, the issue of large gas fees is also avoided.

So, how does this relate to developers? This takes us to its downside. We already know that the polynomial created by zksnark is a type of program constraint. As a result, our program must be deterministic for the program constraints to be deterministic for the corresponding polynomials to be generated. Many features of traditional programming languages are difficult to implement, which is why the Aleo team did not choose to include Turing completion. As developers, we need to understand this part of knowledge and have a proper expectation of it.

Another drawback is that off-chain proof generation necessitates higher device performance, therefore low-performance devices like smart phones may be quite sluggish in proof generating. Of course, Aleo has a solution: low-performance devices can generate proofs by delegating Provers, but this comes with a cost: some of your privacy will be sacrificed in return for convenience. With the finalize keyword in Aleo instructions, applications can be partially executed on chain.

Here we assume that you’ve already read the documentation of Aleo instructions. You can see that the min_public function is implemented and the mint_public is overridden with the finalize keyword. simply put, the function overridden with the finalize keyword is executed on chain, while the original function is executed off chain. The original function stores the input in a register of finalize type, and then the value of the finalize register is retrieved for the finalize function when it is executed on chain. It is crucial to note that the finalize register can only accept public data meaning that your input could face potential privacy issues, as previously stated.

2. ZEXE Model

Aleo’s model differs from Ethereum and Bitcoin in that Ethereum employs an account-based approach, whereas Bitcoin uses the UTXO (Unspent Transaction Output) model. Aleo’s ZEXE transaction methodology is similar to Bitcoin in certain ways. In the ZEXE model, there is an important concept called record, which stores smart contract data. In the ZEXE paradigm, each transaction corresponds to at least one record.

This record resembles the UTXO paradigm, in which each transaction consumes old records and generates new ones, and the sum of the user’s existing records indicates the total asset balance. Similar to cash, except records can carry more information.

Each record contains 4 parameters:

· owner, the owner of the record, which is the public key address of the user.

· gates, the number of Aleo held by the record.

· data, the data that exists in the record and belongs to the program’s customizable map storage. Developers can store their own defined data types in this value.

· nonce, the randomness, which is the identifier to prevent double-spending the record.

Below is how Aleo instructions define record:

This way, any input and output records will be added to the associated data map area with the corresponding key-value pair, map<ident,type>. With this feature, we can define our own assets to support various financial applications.

Recently Aleo instructions also introduced a new keyword mapping. This keyword is currently used exclusively for on-chain execution, i.e., it can only be used in functions declared with the finalize keyword as described earlier.

By declaring mapping <key,value>, a new public and global data storage will be created in the memory of the full node. Developers can store their own defined key-value pairs on chain, in which they must be public, and the operating objects of increment and decrement can only be a finalize type register. The current usage scenario for mapping is still unclear and requires more information in the subsequent development.

3. Stack-based Virtual Machine

Most of us might have heard that virtual machines (VM) are divided into two categories, stack-based VM, and register-based VM. The well-known JVM and EVM are both stack-based VM, whereas lua is a register-based VM. The current implementation of Aleo’s snarkVM is similarly a stack-based virtual machine.

The code above represents the snarkVM stack frame data structure. When it runs a program function, it will initialize the program into a new stack frame, which includes the usage of external functions (external stack), all registers necessary for the function (register types, finalize types), and the corresponding proving and verifying keys. Each stack frame will include a number of registers relating to the program you wrote. Following loading, the associated code and external function references will be executed using the stack’s first in first out principle.

Like a Depth First Search (DFS) tree structure, the stack at the root node is our initial program, and the branches that extend down the tree are externally referenced program stacks.

These are three fundamental and crucial concepts concerning the Aleo development phase that are the starting point for developers who wish to build privacy apps based on Aleo, and we hope this article may provide some reference and inspiration to the Aleo developer community.

--

--

Feng
Feng

Written by Feng

A person who enjoys analysis and focuses on privacy!

No responses yet