Getting Started with Aleo: Your First Project Guide

Birgitta Arnet
6 min readOct 17, 2023

--

Aleo introduces you to a powerful ecosystem for privacy-focused blockchain development. To kickstart your journey, this guide will walk you through creating, building, and running your inaugural Aleo project. By the end, you’ll have a solid foundation to delve deeper into the exciting world of Aleo development.

Create and Build a New Project

Your Aleo adventure begins by creating a new project using the ‘new’ command. In this guide, we’ll name our project ‘foo’:

snarkvm new foo

Executing this command generates a ‘foo’ directory along with essential project files:

  • README.md: This file serves as a starting point for your project’s README. It provides instructions on compiling and running your Aleo program, making it easier to collaborate with others and share your work.
  • main.aleo: The ‘main.aleo’ file is the heart of your project. Here, you define the core logic of your Aleo program, laying the foundation for your project’s functionality.
  • program.json: This JSON file contains crucial project information, including a development address and its associated private key for the program. These details are essential for interacting with your Aleo project.

The Main Source Code (main.aleo)

Your program’s primary logic resides in the ‘main.aleo’ file. This is where you express your project’s functionality in Aleo’s unique assembly-like programming language. Below is an example of what ‘main.aleo’ might look like:

// The 'foo.aleo' program.
program foo.aleo;

function hello:
input r0 as u32.public;
input r1 as u32.private;
add r0 r1 into r2;
output r2 as u32.private;

Running Your Program

With your project’s foundation laid, you can now run your Aleo program using the ‘snarkvm run’ command. To execute a specific function, provide its name and the required input parameters. In this example, we’re running the ‘hello’ function with ‘2u32’ and ‘3u32’ as input parameters:

snarkvm run hello 2u32 3u32

Upon execution, Aleo will provide feedback on the operation, confirming the successful run of your program. The output includes:

  • Loading the universal setup, a crucial step for Aleo’s execution environment.
  • Constraints for the ‘foo.aleo/hello’ function, providing insights into the number of constraints generated during execution.
  • Program output, which, in this case, is ‘5u32.’ This value represents the result of summing the input values, showcasing the capabilities of your Aleo program.

By following these straightforward steps, you’ve entered the dynamic world of Aleo development. This guide serves as your gateway, equipping you with the fundamental knowledge to create, build, and run Aleo programs. As you explore further, you’ll discover Aleo’s potential for privacy-centric blockchain development. Your journey has only just begun, and the possibilities within the Aleo ecosystem are limitless. Enjoy the ride, explore, and create innovative solutions while prioritizing user privacy and security.

Executing Aleo Programs

After you’ve created and configured your Aleo program, it’s time to put it into action. Executing Aleo programs is made straightforward through the ‘snarkvm execute’ command. This command allows you to specify the function you wish to execute and provide the necessary input parameters. Here’s a step-by-step guide to executing an Aleo program:

Using the command ‘snarkvm execute,’ enter the function name you want to execute, along with the corresponding input parameters. For example, if you want to execute the ‘hello’ function with input parameters ‘2u32’ and ‘3u32,’ the command would look like this:

snarkvm execute hello 2u32 3u32

Analyzing the Output

Upon execution completion, you will receive a detailed output providing insights into the entire process:

  • Loading Universal Setup: The execution process starts by loading a universal setup. This universal setup is a crucial component of Aleo’s operation and plays a foundational role in program execution. If you’re interested in delving deeper into this concept, you can find additional information in the Marlin paper, which offers comprehensive insights into the technology behind Aleo.
  • Constraints: The output will indicate the number of constraints generated for the executed function. In this example, the ‘foo.aleo/hello’ function produced 35 constraints. Constraints are fundamental to the secure and accurate execution of Aleo programs.
  • Output: The result of the execution is presented as ‘5u32.’ This value represents the outcome of the operation, which, in this case, is the sum of the provided input values ‘2u32’ and ‘3u32.’

In addition to these essential details, the output also includes a JSON object that pertains to the execution process. However, the JSON object is typically truncated for the sake of brevity, as Aleo programs can encompass complex operations.

The Role of the Universal Setup:

The mention of a “universal setup” is significant when discussing Aleo’s execution environment. The universal setup serves as a foundational element that facilitates the execution of Aleo programs. Those interested in a more profound understanding of this concept can delve into the Marlin paper, which provides valuable insights into the technology underpinning Aleo’s operations.

Building the Functions

Once the universal setup is successfully loaded, Aleo proceeds to build each function present in your ‘main.aleo’ file. This process generates essential components in the output folder:

  • hello.prover: This file serves as the prover for the ‘hello’ function.
  • hello.verifier: It contains the verifier for the ‘hello’ function, contributing to the secure execution process.
  • main.avm: This file compiles the bytecode of your Aleo program, which is intended to be run by the Aleo Virtual Machine (VM). It essentially encapsulates the functionality of your entire Aleo program.

Although a single ‘.avm’ file is created for the entire program, there are specific provers and verifiers generated for each function. This approach ensures that the execution process remains secure and efficient.

By executing your Aleo program, you embark on the journey of exploring the capabilities of Aleo’s privacy-centric approach to blockchain development. This experience provides valuable insights and serves as a solid foundation for further exploration within the Aleo ecosystem. Enjoy your journey, and embrace the endless possibilities that await you in the realm of Aleo programming.

Understanding the foo Program

In this section, we’ll delve into the structure and components of the ‘foo’ program, which resides within the ‘main.aleo’ file. This program is a representative example of Aleo’s capabilities and provides insights into Aleo instructions. Let’s break down the key elements of this program:

1. Program Declaration

The program begins with the following declaration:

program foo.aleo;

This line signifies the initiation of the ‘foo’ program. The name ‘foo.aleo’ is used to identify this particular program. In Aleo, it’s essential to define the program before proceeding with functions or other program elements.

2. Function Definition

Within the program, you can define functions. In this case, we have a single function named ‘hello’:

function hello:

The ‘function’ keyword signals the start of a function definition, followed by the function’s name. In Aleo, you can define functions as a way to encapsulate specific operations or processes.

3. Input Parameters

Every function in Aleo is composed of three main sections, starting with the input section. Here, we declare the input parameters for the ‘hello’ function:

input r0 as u32.public;
input r1 as u32.private;

In Aleo instructions, data is stored within registers, identified as ‘r0,’ ‘r1,’ and so on. These registers hold data with specific types and visibility options. In this instance, ‘r0’ and ‘r1’ are used to store input values, which are 32-bit unsigned integers (‘u32’). The ‘u32.public’ and ‘u32.private’ designations signify the visibility of these input parameters, with ‘public’ indicating a public input and ‘private’ denoting a private one. Public inputs are openly accessible, while private inputs are secured and only visible to authorized parties.

4. Instructions Section

The core of the ‘hello’ function lies within the instructions section. Here, Aleo instructions are employed to define the operations performed by the function. For instance, the addition operation is defined as follows:

add r0 r1 into r2;

This line specifies the ‘add’ operation, where ‘r0’ and ‘r1’ are the input parameters to be added. The result of this addition operation is stored in ‘r2.’

Aleo instructions are accompanied by input parameters with specific types, and the outcome of the operation is recorded in the register specified by ‘into.

5. Output Section

Lastly, the ‘hello’ function defines its output in the output section:

output r2 as u32.private;

This line designates ‘r2’ as the output register, and the data contained in it is classified as a 32-bit unsigned integer (‘u32’) with private visibility.

In summary, Aleo programs comprise functions and other structures, such as structs, records, and closures. These functions are defined with input and output sections, and they use Aleo instructions to carry out specific operations. Aleo’s use of registers, types, and visibility options ensures a secure and efficient execution environment. The ‘foo’ program serves as an introductory example of Aleo’s programming capabilities, showcasing how functions can be structured, and operations can be executed within Aleo instructions.

In the next article we will discuss such concepts as Types, States, and execution of the first Aleo Program

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response