Skip to content

Commit dd5acc0

Browse files
committed
isa: add doc for precompiles
1 parent 791464e commit dd5acc0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

crates/leanIsa/src/precompiles.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
use std::fmt;
22

3+
/// Describes the metadata for a precompiled function available to the zkVM.
34
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
45
pub struct Precompile {
6+
/// The unique identifier for the precompile.
57
pub name: PrecompileName,
8+
/// The number of inputs.
69
pub n_inputs: usize,
10+
/// The number of outputs.
711
pub n_outputs: usize,
812
}
913

14+
/// An enum representing the names of all available precompiles.
1015
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1116
pub enum PrecompileName {
17+
/// The Poseidon2 permutation over 16 field elements.
1218
Poseidon16,
19+
/// The Poseidon2 permutation over 24 field elements.
1320
Poseidon24,
21+
/// The dot product of two vectors of extension field elements.
1422
DotProduct,
23+
/// The evaluation of a multilinear polynomial.
1524
MultilinearEval,
1625
}
1726

1827
impl PrecompileName {
28+
/// Returns the string representation of the precompile name.
1929
#[must_use]
2030
pub const fn as_str(&self) -> &'static str {
2131
match self {
@@ -33,28 +43,33 @@ impl fmt::Display for PrecompileName {
3343
}
3444
}
3545

46+
/// Metadata for the Poseidon2 permutation over 16 elements.
3647
pub const POSEIDON_16: Precompile = Precompile {
3748
name: PrecompileName::Poseidon16,
3849
n_inputs: 2,
3950
n_outputs: 1,
4051
};
4152

53+
/// Metadata for the Poseidon2 permutation over 24 elements.
4254
pub const POSEIDON_24: Precompile = Precompile {
4355
name: PrecompileName::Poseidon24,
4456
n_inputs: 2,
4557
n_outputs: 1,
4658
};
4759

60+
/// Metadata for the dot product precompile.
4861
pub const DOT_PRODUCT: Precompile = Precompile {
4962
name: PrecompileName::DotProduct,
5063
n_inputs: 4,
5164
n_outputs: 0,
5265
};
5366

67+
/// Metadata for the multilinear evaluation precompile.
5468
pub const MULTILINEAR_EVAL: Precompile = Precompile {
5569
name: PrecompileName::MultilinearEval,
5670
n_inputs: 4,
5771
n_outputs: 0,
5872
};
5973

74+
/// An array containing the metadata for all supported precompiles.
6075
pub const PRECOMPILES: [Precompile; 4] = [POSEIDON_16, POSEIDON_24, DOT_PRODUCT, MULTILINEAR_EVAL];

0 commit comments

Comments
 (0)