The best way to get to know Leo is by writing some code. We will fly through a high level overview of a Leo file. To gain a deeper understanding of the Leo language, continue to the next page.
Square Example: Let's prove that we know the square of a number.
Leo supports boolean, unsigned integer, signed integer, field, group, and address data types. Data types in Leo
must be explicitly stated
let a: u32 = 5;
Collections of data types can be created in the form of static arrays and tuples.
square function is called by
main with private inputs
b which are both unsigned
A naive way to test
square would be to execute
leo run several times on different inputs and check the output of the program each time.
Luckily, we can write unit tests in Leo using the
@test syntax and run them using
test_square we can sanity check our code without having to load in private inputs from a file every time.
Want to upgrade your unit test into an integration test?
In Leo you can provide arguments that load different sets of private inputs to make your test suite even more robust.
The last line of
test_square uses the console function
This function along with
console.error provide developers with tools that are run without
affecting the underlying constraint system.
Circuits in leo are similar to structures in other object-oriented languages. They provide a composite data type that can store any value and provide functions for instantiation and computation.
new function is static and can be called without instantiating the circuit.
self keywords to access circuit member variables and functions.
Imports fetch other circuits and functions and bring them into the current file scope.
Leo supports imports for dependencies that are declared locally or in an imported package.
Importing packages can be accomplished using the
leo add command in the CLI.
This completes the flying tour!
To learn more about how to use the Leo Language, start here
To learn more about how to use the Leo CLI, start here