Skip to main content

leo_std/
lib.rs

1// Copyright (C) 2019-2026 Provable Inc.
2// This file is part of the Leo library.
3
4// The Leo library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The Leo library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
16
17//! Embedded source for the Leo standard library.
18//!
19//! Compiler and tooling crates depend on this to inject `std` into every
20//! Leo build without requiring users to declare it in `program.json`.
21
22/// The Leo identifier under which the standard library is exposed
23/// (`std::foo(...)`).
24pub const LIBRARY_NAME: &str = "std";
25
26const LIB_LEO: &str = include_str!("leo/lib.leo");
27const DUMMY_LEO: &str = include_str!("leo/dummy.leo");
28
29const HASH_BHP256_LEO: &str = include_str!("leo/hash/bhp256.leo");
30const HASH_BHP512_LEO: &str = include_str!("leo/hash/bhp512.leo");
31const HASH_BHP768_LEO: &str = include_str!("leo/hash/bhp768.leo");
32const HASH_BHP1024_LEO: &str = include_str!("leo/hash/bhp1024.leo");
33const HASH_KECCAK256_LEO: &str = include_str!("leo/hash/keccak256.leo");
34const HASH_KECCAK384_LEO: &str = include_str!("leo/hash/keccak384.leo");
35const HASH_KECCAK512_LEO: &str = include_str!("leo/hash/keccak512.leo");
36const HASH_PEDERSEN64_LEO: &str = include_str!("leo/hash/pedersen64.leo");
37const HASH_PEDERSEN128_LEO: &str = include_str!("leo/hash/pedersen128.leo");
38const HASH_POSEIDON2_LEO: &str = include_str!("leo/hash/poseidon2.leo");
39const HASH_POSEIDON4_LEO: &str = include_str!("leo/hash/poseidon4.leo");
40const HASH_POSEIDON8_LEO: &str = include_str!("leo/hash/poseidon8.leo");
41const HASH_SHA3_256_LEO: &str = include_str!("leo/hash/sha3_256.leo");
42const HASH_SHA3_384_LEO: &str = include_str!("leo/hash/sha3_384.leo");
43const HASH_SHA3_512_LEO: &str = include_str!("leo/hash/sha3_512.leo");
44
45const COMMIT_BHP256_LEO: &str = include_str!("leo/commit/bhp256.leo");
46const COMMIT_BHP512_LEO: &str = include_str!("leo/commit/bhp512.leo");
47const COMMIT_BHP768_LEO: &str = include_str!("leo/commit/bhp768.leo");
48const COMMIT_BHP1024_LEO: &str = include_str!("leo/commit/bhp1024.leo");
49const COMMIT_PEDERSEN64_LEO: &str = include_str!("leo/commit/pedersen64.leo");
50const COMMIT_PEDERSEN128_LEO: &str = include_str!("leo/commit/pedersen128.leo");
51
52const RAND_LEO: &str = include_str!("leo/rand.leo");
53const SIG_LEO: &str = include_str!("leo/sig.leo");
54const SERIALIZE_LEO: &str = include_str!("leo/serialize.leo");
55const GRP_LEO: &str = include_str!("leo/grp.leo");
56const CTX_LEO: &str = include_str!("leo/ctx.leo");
57const PROG_LEO: &str = include_str!("leo/prog.leo");
58
59/// Entry source of the standard library (contents of `lib.leo`).
60pub fn entry_source() -> &'static str {
61    LIB_LEO
62}
63
64/// Submodule sources, returned as `(virtual_path, source)` pairs.
65///
66/// The first element of each tuple is a label used in span/error reporting AND
67/// drives the module key: `hash/bhp256.leo` → module `std::hash::bhp256`. Use
68/// forward slashes for nested paths.
69pub fn modules() -> &'static [(&'static str, &'static str)] {
70    &[
71        ("dummy.leo", DUMMY_LEO),
72        ("hash/bhp256.leo", HASH_BHP256_LEO),
73        ("hash/bhp512.leo", HASH_BHP512_LEO),
74        ("hash/bhp768.leo", HASH_BHP768_LEO),
75        ("hash/bhp1024.leo", HASH_BHP1024_LEO),
76        ("hash/keccak256.leo", HASH_KECCAK256_LEO),
77        ("hash/keccak384.leo", HASH_KECCAK384_LEO),
78        ("hash/keccak512.leo", HASH_KECCAK512_LEO),
79        ("hash/pedersen64.leo", HASH_PEDERSEN64_LEO),
80        ("hash/pedersen128.leo", HASH_PEDERSEN128_LEO),
81        ("hash/poseidon2.leo", HASH_POSEIDON2_LEO),
82        ("hash/poseidon4.leo", HASH_POSEIDON4_LEO),
83        ("hash/poseidon8.leo", HASH_POSEIDON8_LEO),
84        ("hash/sha3_256.leo", HASH_SHA3_256_LEO),
85        ("hash/sha3_384.leo", HASH_SHA3_384_LEO),
86        ("hash/sha3_512.leo", HASH_SHA3_512_LEO),
87        ("commit/bhp256.leo", COMMIT_BHP256_LEO),
88        ("commit/bhp512.leo", COMMIT_BHP512_LEO),
89        ("commit/bhp768.leo", COMMIT_BHP768_LEO),
90        ("commit/bhp1024.leo", COMMIT_BHP1024_LEO),
91        ("commit/pedersen64.leo", COMMIT_PEDERSEN64_LEO),
92        ("commit/pedersen128.leo", COMMIT_PEDERSEN128_LEO),
93        ("rand.leo", RAND_LEO),
94        ("sig.leo", SIG_LEO),
95        ("serialize.leo", SERIALIZE_LEO),
96        ("grp.leo", GRP_LEO),
97        ("ctx.leo", CTX_LEO),
98        ("prog.leo", PROG_LEO),
99    ]
100}
101
102/// The Leo identifier under which the standard library is exposed.
103pub fn library_name() -> &'static str {
104    LIBRARY_NAME
105}