Skip to main content

Overview

Thank you for your interest in contributing to Leo! This guide will help you get started with contributing to the Leo programming language and its ecosystem.
The Leo compiler is written in Rust and follows strict coding standards to ensure reliability and security.

Getting Started

Prerequisites

  1. Rust Toolchain
  2. Nightly Rust (for formatting)
  3. Git

Fork and Clone

  1. Fork the repository on GitHub
  2. Clone your fork:
  3. Add upstream remote:

Build from Source

Pull Request Process

Branch from Mainnet

Ensure your branch is forked from the current mainnet branch:

Making Changes

  1. Write your code
    • Follow the coding conventions (see below)
    • Add tests for new functionality
    • Update documentation as needed
  2. Format your code
    Formatting is enforced by a git hook. Commits will fail if code is not properly formatted.
  3. Run clippy
    All clippy warnings must be resolved.
  4. Run tests

Commit Your Changes

Create Pull Request

  1. Go to your fork on GitHub
  2. Click “New Pull Request”
  3. Fill out the PR template:
    • Link related issues using keywords (e.g., “closes #130”)
    • Describe your changes
    • Explain why the changes are needed
    • List any breaking changes
  4. Wait for review
    • Address feedback promptly
    • Keep your branch up to date with mainnet
    • Be patient and respectful

Coding Conventions

Style Guidelines

Comments

Prefer line comments (//) to block comments (/* ... */). Good:
Comment Format:
  • Complete sentences with capitalization and punctuation
  • Single space before and after inline block comments
  • No trailing whitespace

Imports

Imports should be:
  • Stated at the top of the file
  • Ordered alphabetically
  • Split into two sections:
Section 1: First-party imports
  • crate imports
  • Leo crates (leo_*)
  • Aleo crates (e.g., snarkvm)
Section 2: Third-party imports
  • Rust std
  • External dependencies
Example:
cargo fmt will automatically sort imports within each section.

Performance and Memory Guidelines

Leo is a large project. Following these guidelines helps ensure high performance and efficient memory usage.

Memory Handling

Pre-allocate Collections

Good:
Bad:
Pre-allocation reduces system calls and ensures optimal memory usage.

Create Collections Just-in-Time

Good:
Bad:

Use Iterators

Avoid intermediate vectors when possible: Good:
Bad:

Bulk Operations

Good:
Bad:

Pass by Value When Consumed

Good:
Bad:
Pass by value when the function will consume the argument.

Use Copy-on-Write

For slices that may or may not need extending:
This avoids allocation when extension isn’t needed.

Prefer Arrays and Slices

Good:
Bad:
Use arrays when size is known and not too large.

Avoid Unnecessary Clones

Good:
Bad:

Use into_iter() Over iter().cloned()

Good:
Bad:
When you can consume the collection, into_iter() avoids clones.

Reuse Collections

Good:
Bad:

Box Large Enum Variants

Good:
Bad:

Performance

Avoid format!()

Good:
Bad:

Check-Then-Insert Pattern

Good:
Bad:

Use Slice Types in Parameters

Good:
Bad:

Custom PartialEq and Hash

For structs with distinctive fields:
This makes comparisons and hashing much faster.

Testing

Run Tests

Write Tests

For new features, add tests in tests/tests/ with expectations in tests/expectations/:

Test Framework

Leo uses expectation testing:
  • Tests in tests/tests/{category}/
  • Expected outputs in tests/expectations/{category}/
  • Run UPDATE_EXPECT=1 cargo test to update expectations

Validation Checklist

Before submitting your PR, ensure:
  • Code compiles: cargo check --all
  • No clippy warnings: cargo clippy -- -D warnings
  • Code is formatted: cargo +nightly fmt --check
  • All tests pass: cargo test
  • Documentation is updated
  • Commit messages are descriptive
  • PR description is complete

Code Review

Review Checklist

Reviewers will check: Correctness:
  • Logic is sound
  • Edge cases are handled
  • No panics in production code
  • Error handling is appropriate
Compiler-Specific:
  • Spans are preserved for error reporting
  • NodeIDs are assigned correctly
  • Pass ordering is respected
  • Generated Aleo instructions are valid
Performance:
  • No unnecessary allocations
  • Pre-allocation where size is known
  • No unnecessary clones
  • Efficient iterators
Security:
  • Input validation at boundaries
  • No information leakage
  • Fail-closed on uncertainty

Architecture Overview

Leo compilation pipeline:

Key Crates

  • leo-span: Source locations and spans
  • leo-errors: All error types
  • leo-ast: AST node definitions
  • leo-parser-rowan: Lexer and parser
  • leo-parser: Rowan to AST conversion
  • leo-passes: Compiler passes (~25 passes)
  • leo-compiler: Orchestrates compilation
  • leo-package: Project structure
  • leo-fmt: Code formatter
For more details, see AGENTS.md in the repository.

Git Workflow

Commit Messages

Write clear, descriptive commit messages: Good:
Bad:

Squashing Commits

Maintainers may ask you to squash commits:

Keeping Up to Date

Getting Help

Discord

Join the Aleo Discord for:
  • Questions about contributing
  • Discussion of proposed changes
  • Community support

GitHub Discussions

Use GitHub Discussions for:
  • Feature proposals
  • Design discussions
  • General questions

Office Hours

Check the Discord for community office hours and developer meetups.

What to Contribute

Good First Issues

Look for issues labeled good first issue on GitHub:

Ideas

  • Bug fixes
  • Documentation improvements
  • Example programs
  • Test coverage
  • Performance optimizations
  • Error message improvements
  • Developer tooling

What Requires Approval

Before starting work on these, open an issue for discussion:
  • New crates
  • New dependencies
  • New abstractions or traits
  • New error types
  • Breaking changes
  • Major refactors

License

By contributing to Leo, you agree that your contributions will be licensed under the GNU General Public License v3.0.

Code of Conduct

Be respectful, professional, and constructive:
  • Respect differing viewpoints
  • Accept constructive criticism gracefully
  • Focus on what’s best for the community
  • Show empathy towards others

GitHub Repository

Leo source code

Discord Community

Join the discussion
Thank you for contributing to Leo!