You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This creates a `Bn254Fp2` struct, representing a complex extension field. The `mod_type` must implement `IntMod`.
72
72
73
-
2.**Init**: After calling `complex_declare!`, the `init!` macro will now expand to the appropriate call to `complex_init!`.
73
+
2.**Init**: After calling `complex_declare!`, the [`openvm::init!` macro](./overview.md#automating-the-init-step) will now expand to the appropriate call to `complex_init!`.
Copy file name to clipboardExpand all lines: book/src/custom-extensions/ecc.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,10 +43,10 @@ sw_declare! {
43
43
Each declared curve must specify the `mod_type` (implementing `IntMod`) and a constant `b` for the Weierstrass curve equation \\(y^2 = x^3 + ax + b\\). `a` is optional and defaults to 0 for short Weierstrass curves.
44
44
This creates `Bls12_381G1Affine` and `P256Affine` structs which implement the `Group` and `WeierstrassPoint` traits. The underlying memory layout of the structs uses the memory layout of the `Bls12_381Fp` and `P256Coord` structs, respectively.
45
45
46
-
2.**Init**: Called once, the `init!` macro produces a call to `sw_init!` that enumerates these curves and allows the compiler to produce optimized instructions:
46
+
2.**Init**: Called once, the [`openvm::init!` macro](./overview.md#automating-the-init-step) produces a call to `sw_init!` that enumerates these curves and allows the compiler to produce optimized instructions:
Copy file name to clipboardExpand all lines: book/src/custom-extensions/overview.md
+8-2Lines changed: 8 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,16 +11,22 @@ OpenVM ships with a set of pre-built extensions maintained by the OpenVM team. B
11
11
12
12
## Optimizing Modular Arithmetic
13
13
14
-
Some of these extensions—specifically `algebra`, `ecc`, and `pairing`—perform modular arithmetic, which can be significantly optimized when the modulus is known at compile time. Therefore, these extensions provide a framework to inform the compiler about all the moduli and associated arithmetic structures we intend to use. To achieve this, three steps are involved:
14
+
Some of these extensions—specifically `algebra`, `ecc`, and `pairing`—perform modular arithmetic, which can be significantly optimized when the modulus is known at compile time. Therefore, these extensions provide a framework to inform the compiler about all the moduli and associated arithmetic structures we intend to use. To achieve this, two steps are involved:
15
15
16
16
1.**Declare**: Introduce a modular arithmetic or related structure, along with its modulus and functionality. This can be done in any library or binary file.
17
17
2.**Init**: Performed exactly once in the final binary. It aggregates all previously declared structures, assigns them stable indices, and sets up linkage so that they can be referenced in generated code.
18
-
3.**Setup**: A one-time runtime procedure for security. This ensures that the compiled code matches the virtual machine’s expectations and that each instruction set is tied to the correct modulus or extension.
19
18
20
19
These steps ensure both performance and security: performance because the modulus is known at compile time, and security because runtime checks confirm that the correct structures have been initialized.
21
20
22
21
Our design for the configuration procedure above was inspired by the [EVMMAX proposal](https://github.com/jwasinger/EIPs/blob/evmmax-2/EIPS/eip-6601.md).
23
22
23
+
### Automating the `init!` step
24
+
25
+
The `openvm` crate provides an `init!` macro to automate the **init** step:
26
+
1. Call `openvm::init!()` exactly once in the code of the final program binary.
27
+
2. When [compiling the program](../writing-apps/build.md), `cargo openvm build` will read the [configuration file](#configuration) to automatically generate the correct init code and write it to `<INIT_FILE_NAME>`, which defaults to `openvm_init.rs` in the manifest directory.
28
+
3. The `openvm::init!()` macro will include the `openvm_init.rs` file into the final binary to complete the init process. You can call `openvm::init!(INIT_FILE_NAME)` to include init code from a different file if needed.
29
+
24
30
## Configuration
25
31
26
32
To use these extensions, you must populate an `openvm.toml` in your package root directory (where the `Cargo.toml` file is located).
Copy file name to clipboardExpand all lines: book/src/custom-extensions/pairing.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,3 +19,5 @@ This asserts that \\(e(p_0, q_0) e(p_1, q_1) = 1\\).
19
19
Naturally, this can be extended to more points by adding more elements to the arrays.
20
20
21
21
The pairing extension additionally provides field operations in \\(\mathbb{F_{p^{12}}}\\) for both BN254 and BLS12-381 curves where \\(\mathbb{F}\\) is the coordinate field.
22
+
23
+
See the [pairing guest library](../guest-libs/pairing.md) for usage details.
Copy file name to clipboardExpand all lines: book/src/guest-libs/pairing.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
##Pairing
1
+
#Elliptic Curve Pairing
2
2
3
3
We'll be working with an example using the BLS12-381 elliptic curve. This is in addition to the setup that needs to be done in the [Writing a Program](../writing-apps/write-program.md) section.
Copy file name to clipboardExpand all lines: book/src/writing-apps/write-program.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -126,8 +126,8 @@ See the [overview](./overview.md) on how to build and run the program.
126
126
127
127
## Using crates that depend on `getrandom`
128
128
129
-
OpenVM is compatible with [getrandom](https://crates.io/crates/getrandom)`v0.3`. The `cargo openvm` CLI will always compile with the [custom](https://docs.rs/getrandom/latest/getrandom/#opt-in-backends)`getrandom` backend.
129
+
OpenVM is compatible with [getrandom](https://crates.io/crates/getrandom)`v0.2` and `v0.3`. The `cargo openvm` CLI will always compile with the [custom](https://docs.rs/getrandom/0.3.3/getrandom/#opt-in-backends)`getrandom` backend.
130
130
131
131
By default the `openvm` crate has a default feature `"getrandom-unsupported"` which exports a `__getrandom_v03_custom` function that always returns `Err(Error::UNSUPPORTED)`. This is enabled by default to allow compilation of guest programs that pull in dependencies which require `getrandom` but where the executed code does not actually use `getrandom` functions.
132
132
133
-
To override the default behavior and provide a custom implementation, turn off the `"getrandom-unsupported"` feature in the `openvm` crate and supply your own `__getrandom_v03_custom` function as specified in the [getrandom docs](https://docs.rs/getrandom/latest/getrandom/#custom-backend).
133
+
To override the default behavior and provide a custom implementation, turn off the `"getrandom-unsupported"` feature in the `openvm` crate and supply your own `__getrandom_v03_custom` function as specified in the [getrandom docs](https://docs.rs/getrandom/0.3.3/getrandom/#custom-backend). Similar customization options are available for `getrandom``v0.2`.
0 commit comments