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
-
Rust Toolchain
-
Nightly Rust (for formatting)
-
Git
Fork and Clone
- Fork the repository on GitHub
-
Clone your fork:
-
Add upstream remote:
Build from Source
Pull Request Process
Branch from Mainnet
Ensure your branch is forked from the currentmainnet branch:
Making Changes
-
Write your code
- Follow the coding conventions (see below)
- Add tests for new functionality
- Update documentation as needed
-
Format your code
-
Run clippy
All clippy warnings must be resolved.
-
Run tests
Commit Your Changes
Create Pull Request
- Go to your fork on GitHub
- Click “New Pull Request”
-
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
-
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:
- 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:
crateimports- Leo crates (
leo_*) - Aleo crates (e.g.,
snarkvm)
- Rust
std - External dependencies
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:Create Collections Just-in-Time
Good:Use Iterators
Avoid intermediate vectors when possible: Good:Bulk Operations
Good:Pass by Value When Consumed
Good:Use Copy-on-Write
For slices that may or may not need extending:Prefer Arrays and Slices
Good:Avoid Unnecessary Clones
Good:Use into_iter() Over iter().cloned()
Good:into_iter() avoids clones.
Reuse Collections
Good:Box Large Enum Variants
Good:Performance
Avoid format!()
Good:Check-Then-Insert Pattern
Good:Use Slice Types in Parameters
Good:Custom PartialEq and Hash
For structs with distinctive fields:Testing
Run Tests
Write Tests
For new features, add tests intests/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 testto 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
- Spans are preserved for error reporting
- NodeIDs are assigned correctly
- Pass ordering is respected
- Generated Aleo instructions are valid
- No unnecessary allocations
- Pre-allocation where size is known
- No unnecessary clones
- Efficient iterators
- 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
AGENTS.md in the repository.
Git Workflow
Commit Messages
Write clear, descriptive commit messages: Good: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 labeledgood 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
Related Resources
GitHub Repository
Leo source code
Discord Community
Join the discussion