Skip to content

Commit

Permalink
Turn MathJax on, replace $...$ with \\(...\\) (#1067)
Browse files Browse the repository at this point in the history
  • Loading branch information
Golovanov399 authored Dec 16, 2024
1 parent 930dd54 commit c9fc623
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
4 changes: 1 addition & 3 deletions book/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ title = "OpenVM Book"

[output.html]
site-url = "https://book.openvm.dev/"
additional-head = [
"<script async src=\"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js\" id=\"MathJax-script\"></script>"
]
mathjax-support = true
11 changes: 5 additions & 6 deletions book/src/custom-extensions/algebra.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# OpenVM Algebra

The OpenVM Algebra extension provides tools to create and manipulate modular arithmetic structures and their complex extensions. For example, if $p$ is prime, OpenVM Algebra can handle modular arithmetic in $\mathbb{F}_p$​ and its quadratic extension fields $\mathbb{F}_p[x]/(x^2 + 1)$.
The OpenVM Algebra extension provides tools to create and manipulate modular arithmetic structures and their complex extensions. For example, if \\(p\\) is prime, OpenVM Algebra can handle modular arithmetic in \\(\mathbb{F}_p\\)​ and its quadratic extension fields \\(\mathbb{F}_p[x]/(x^2 + 1)\\).

The functional part is provided by the `openvm-algebra-guest` crate, which is a guest library that can be used in any OpenVM program. The macros for creating corresponding structs are in the `openvm-algebra-moduli-setup` and `openvm-algebra-complex-macros` crates.

## Available traits and methods

- `IntMod` trait:
Defines the type `Repr` and constants `MODULUS`, `NUM_LIMBS`, `ZERO`, and `ONE`. It also provides basic methods for constructing a modular arithmetic object and performing arithmetic operations.
- `Repr` typically is `[u8; NUM_LIMBS]`, representing the numbers underlying storage.
- `Repr` typically is `[u8; NUM_LIMBS]`, representing the number's underlying storage.
- `MODULUS` is the compile-time known modulus.
- `ZERO` and `ONE` represent the additive and multiplicative identities, respectively.
- Constructors include `from_repr`, `from_le_bytes`, `from_be_bytes`, `from_u8`, `from_u32`, and `from_u64`.
Expand All @@ -21,7 +21,6 @@ The functional part is provided by the `openvm-algebra-guest` crate, which is a
To [leverage](./overview.md) compile-time known moduli for performance, you declare, initialize, and then set up the arithmetic structures:

1. **Declare**: Use the `moduli_declare!` macro to define a modular arithmetic struct. This can be done multiple times in various crates or modules:

```rust
moduli_declare! {
Bls12_381Fp { modulus = "0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab" },
Expand All @@ -42,7 +41,7 @@ moduli_init! {

This step enumerates the declared moduli (e.g., `0` for the first one, `1` for the second one) and sets up internal linkage so the compiler can generate the appropriate RISC-V instructions associated with each modulus.

3. **Setup**: At runtime, before performing arithmetic, a setup instruction must be sent to ensure security and correctness. For the $i$-th modulus, you call `setup_<i>()` (e.g., `setup_0()` or `setup_1()`). Alternatively, `setup_all_moduli()` can be used to handle all declared moduli.
3. **Setup**: At runtime, before performing arithmetic, a setup instruction must be sent to ensure security and correctness. For the \\(i\\)-th modulus, you call `setup_<i>()` (e.g., `setup_0()` or `setup_1()`). Alternatively, `setup_all_moduli()` can be used to handle all declared moduli.

**Summary**:
- `moduli_declare!`: Declares modular arithmetic structures and can be done multiple times.
Expand All @@ -51,7 +50,7 @@ This step enumerates the declared moduli (e.g., `0` for the first one, `1` for t

## Complex field extension

Complex extensions, such as $\mathbb{F}_p[x]/(x^2 + 1)$, are defined similarly using `complex_declare!` and `complex_init!`:
Complex extensions, such as \\(\mathbb{F}_p[x]/(x^2 + 1)\\), are defined similarly using `complex_declare!` and `complex_init!`:

1. **Declare**:

Expand Down Expand Up @@ -154,4 +153,4 @@ supported_modulus = ["1157920892373161954235709850086879078532699846656405640394
supported_modulus = ["115792089237316195423570985008687907853269984665640564039457584007908834671663"]
```

The `supported_modulus` parameter is a list of moduli that the guest program will use. They must be provided in decimal format in the `.toml` file.
The `supported_modulus` parameter is a list of moduli that the guest program will use. They must be provided in decimal format in the `.toml` file.
2 changes: 1 addition & 1 deletion book/src/custom-extensions/ecc.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ sw_declare! {
}
```

Each declared curve must specify the `mod_type` (implementing `IntMod`) and a constant `b` for the Weierstrass curve equation $y^2 = x^3 + b$.
Each declared curve must specify the `mod_type` (implementing `IntMod`) and a constant `b` for the Weierstrass curve equation \\(y^2 = x^3 + b\\).
This creates `Bls12_381G1Affine` and `Bn254G1Affine` structs which implement the `Group` and `WeierstrassPoint` traits. The underlying memory layout of the structs uses the memory layout of the `Bls12_381Fp` and `Bn254Fp` structs, respectively.

2. **Init**: Called once, it enumerates these curves and allows the compiler to produce optimized instructions:
Expand Down

0 comments on commit c9fc623

Please sign in to comment.