Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] polish declare/init macros (rename and move to one place etc) #1262

Merged
merged 14 commits into from
Jan 23, 2025
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ members = [
"extensions/algebra/circuit",
"extensions/algebra/transpiler",
"extensions/algebra/guest",
"extensions/algebra/moduli-setup",
"extensions/extension-algebra-macros/moduli-macros",
jonathanpwang marked this conversation as resolved.
Show resolved Hide resolved
"extensions/algebra/tests",
"extensions/bigint/circuit",
"extensions/bigint/transpiler",
Expand All @@ -58,7 +58,7 @@ members = [
"extensions/ecc/circuit",
"extensions/ecc/transpiler",
"extensions/ecc/guest",
"extensions/ecc/sw-setup",
"extensions/extension-algebra-macros/sw-macros",
jonathanpwang marked this conversation as resolved.
Show resolved Hide resolved
"extensions/ecc/tests",
"extensions/pairing/circuit",
"extensions/pairing/transpiler",
Expand Down Expand Up @@ -153,12 +153,12 @@ openvm-bigint-guest = { path = "extensions/bigint/guest", default-features = fal
openvm-algebra-circuit = { path = "extensions/algebra/circuit", default-features = false }
openvm-algebra-transpiler = { path = "extensions/algebra/transpiler", default-features = false }
openvm-algebra-guest = { path = "extensions/algebra/guest", default-features = false }
openvm-algebra-moduli-setup = { path = "extensions/algebra/moduli-setup", default-features = false }
openvm-algebra-complex-macros = { path = "extensions/algebra/guest/src/field/complex-macros", default-features = false }
openvm-algebra-moduli-macros = { path = "extensions/extension-algebra-macros/moduli-macros", default-features = false }
openvm-algebra-complex-macros = { path = "extensions/extension-algebra-macros/complex-macros", default-features = false }
openvm-ecc-circuit = { path = "extensions/ecc/circuit", default-features = false }
openvm-ecc-transpiler = { path = "extensions/ecc/transpiler", default-features = false }
openvm-ecc-guest = { path = "extensions/ecc/guest", default-features = false }
openvm-ecc-sw-setup = { path = "extensions/ecc/sw-setup", default-features = false }
openvm-ecc-sw-macros = { path = "extensions/extension-algebra-macros/sw-macros", default-features = false }
openvm-pairing-circuit = { path = "extensions/pairing/circuit", default-features = false }
openvm-pairing-transpiler = { path = "extensions/pairing/transpiler", default-features = false }
openvm-pairing-guest = { path = "extensions/pairing/guest", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/programs/ecrecover/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ use revm_precompile::{

openvm::entry!(main);

openvm_algebra_guest::moduli_setup::moduli_init! {
openvm_algebra_guest::moduli_macros::moduli_init! {
"0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFC2F",
"0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B BFD25E8C D0364141"
}
openvm_ecc_guest::sw_setup::sw_init! {
openvm_ecc_guest::sw_macros::sw_init! {
Secp256k1Point,
}

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/src/bin/ecrecover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn main() -> Result<()> {
let args = BenchmarkCli::parse();

let elf = args.build_bench_program("ecrecover")?;
// TODO: update sw_setup macros and read it from elf.
// TODO: update sw_macros and read it from elf.
let exe = VmExe::from_elf(
elf,
Transpiler::<BabyBear>::default()
Expand Down
2 changes: 1 addition & 1 deletion book/src/custom-extensions/algebra.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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.
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-macros` and `openvm-algebra-complex-macros` crates.

## Available traits and methods

Expand Down
10 changes: 7 additions & 3 deletions docs/repo/layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ Command-line binary to compile, execute, and prove guest programs is in [`cli`](

The toolchain, ISA, and VM are simultaneously extendable. All non-system functionality is implemented via extensions, which may be moved to standalone repositories in the future but are presently in this repository for maintainer convenience.

#### Procedural macros for algebraic structs

- [`openvm-algebra-moduli-macros`](../../extensions/extension-algebra-macros/moduli-macros): Procedural macros for use in guest program to generate modular arithmetic struct with custom intrinsics for compile-time modulus.
- [`openvm-algebra-complex-macros`](../../extensions/extension-algebra-macros/complex-macros): Procedural macros for use in guest program to generate complex field struct with custom intrinsics for compile-time modulus.
- [`openvm-ecc-sw-macros`](../../extensions/extension-algebra-macros/sw-macros): Procedural macros for use in guest program to generate short Weierstrass curve struct with custom intrinsics for compile-time curve.


#### RV32IM

- [`openvm-rv32im-circuit`](../../extensions/rv32im/circuit): Circuit extension for RV32IM instructions and IO instructions.
Expand Down Expand Up @@ -111,16 +118,13 @@ The toolchain, ISA, and VM are simultaneously extendable. All non-system functio
- [`openvm-algebra-circuit`](../../extensions/algebra/circuit): Circuit extension for modular arithmetic for arbitrary compile-time modulus. Supports modular arithmetic and complex field extension operations.
- [`openvm-algebra-transpiler`](../../extensions/algebra/transpiler): Transpiler extension for modular arithmetic for arbitrary compile-time modulus. Supports modular arithmetic and complex field extension operations.
- [`openvm-algebra-guest`](../../extensions/algebra/guest): Guest library with traits for modular arithmetic and complex field extension operations.
- [`openvm-algebra-moduli-setup`](../../extensions/algebra/moduli-setup): Procedural macros for use in guest program to generate modular arithmetic struct with custom intrinsics for compile-time modulus.
- [`openvm-algebra-complex-macros`](../../extensions/algebra/guest/src/field/complex-macros): Procedural macros for use in guest program to generate complex field struct with custom intrinsics for compile-time modulus.
- [`openvm-algebra-tests`](../../extensions/algebra/tests): Integration tests for the algebra extension.

#### Elliptic Curve Cryptography

- [`openvm-ecc-circuit`](../../extensions/ecc/circuit): Circuit extension for Weierstrass elliptic curve operations for arbitrary compile-time curve.
- [`openvm-ecc-transpiler`](../../extensions/ecc/transpiler): Transpiler extension for Weierstrass elliptic curve operations for arbitrary compile-time curve.
- [`openvm-ecc-guest`](../../extensions/ecc/guest): Guest library with traits for elliptic curve cryptography. Includes implementations of ECDSA and multi-scalar multiplication.
- [`openvm-ecc-sw-setup`](../../extensions/ecc/sw-setup): Procedural macros for use in guest program to generate short Weierstrass curve struct with custom intrinsics for compile-time curve.
- [`openvm-ecc-tests`](../../extensions/ecc/tests): Integration tests for the elliptic curve cryptography extension.

#### Elliptic Curve Pairing
Expand Down
2 changes: 1 addition & 1 deletion examples/algebra/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg_attr(not(feature = "std"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

use openvm_algebra_guest::{moduli_setup::*, IntMod};
use openvm_algebra_guest::{moduli_macros::*, IntMod};

openvm::entry!(main);

Expand Down
4 changes: 2 additions & 2 deletions examples/ecc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ use openvm_ecc_guest::{
// ANCHOR_END: imports

// ANCHOR: init
openvm_algebra_guest::moduli_setup::moduli_init! {
openvm_algebra_guest::moduli_macros::moduli_init! {
"0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFC2F",
"0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B BFD25E8C D0364141"
}

openvm_ecc_guest::sw_setup::sw_init! {
openvm_ecc_guest::sw_macros::sw_init! {
Secp256k1Point,
}
// ANCHOR_END: init
Expand Down
2 changes: 1 addition & 1 deletion examples/pairing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ members = []
openvm = { git = "https://github.com/openvm-org/openvm.git" }
openvm-platform = { git = "https://github.com/openvm-org/openvm.git" }
openvm-algebra-guest = { git = "https://github.com/openvm-org/openvm.git" }
openvm-algebra-moduli-setup = { git = "https://github.com/openvm-org/openvm.git" }
openvm-algebra-moduli-macros = { git = "https://github.com/openvm-org/openvm.git" }
openvm-algebra-complex-macros = { git = "https://github.com/openvm-org/openvm.git" }
openvm-ecc-guest = { git = "https://github.com/openvm-org/openvm.git" }
openvm-pairing-guest = { git = "https://github.com/openvm-org/openvm.git", features = ["bls12_381"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/pairing/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use openvm_pairing_guest::{
// ANCHOR_END: imports

// ANCHOR: init
openvm_algebra_moduli_setup::moduli_init! {
openvm_algebra_moduli_macros::moduli_init! {
"0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab",
"0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001"
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/algebra/guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repository.workspace = true
[dependencies]
openvm = { workspace = true }
openvm-platform = { workspace = true }
openvm-algebra-moduli-setup = { workspace = true }
openvm-algebra-moduli-macros = { workspace = true }
openvm-algebra-complex-macros = { workspace = true }
serde = { workspace = true }
serde-big-array = "0.5.1"
Expand Down
2 changes: 1 addition & 1 deletion extensions/algebra/guest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub use field::Field;
#[cfg(not(target_os = "zkvm"))]
use num_bigint::BigUint;
pub use openvm_algebra_complex_macros as complex_macros;
pub use openvm_algebra_moduli_setup as moduli_setup;
pub use openvm_algebra_moduli_macros as moduli_macros;
pub use serde_big_array::BigArray;
use strum_macros::FromRepr;

Expand Down
4 changes: 2 additions & 2 deletions extensions/algebra/tests/programs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ openvm = { path = "../../../../crates/toolchain/openvm" }
openvm-platform = { path = "../../../../crates/toolchain/platform" }

openvm-algebra-guest = { path = "../../guest" }
openvm-algebra-moduli-setup = { path = "../../moduli-setup", default-features = false }
openvm-algebra-complex-macros = { path = "../../guest/src/field/complex-macros", default-features = false }
openvm-algebra-moduli-macros = { path = "../../../extension-algebra-macros/moduli-macros", default-features = false }
openvm-algebra-complex-macros = { path = "../../../extension-algebra-macros/complex-macros", default-features = false }
num-bigint = { version = "0.4", default-features = false }
serde = { version = "1.0", default-features = false, features = [
"alloc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use openvm_algebra_guest::{field::ComplexConjugate, DivAssignUnsafe, DivUnsafe,

openvm::entry!(main);

openvm_algebra_moduli_setup::moduli_declare! {
openvm_algebra_moduli_macros::moduli_declare! {
Secp256k1Coord { modulus = "0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFC2F" }
}
openvm_algebra_moduli_setup::moduli_init!(
openvm_algebra_moduli_macros::moduli_init!(
"0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFC2F"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use openvm_algebra_guest::IntMod;

openvm::entry!(main);

openvm_algebra_moduli_setup::moduli_declare! {
openvm_algebra_moduli_macros::moduli_declare! {
Mod1 { modulus = "998244353" },
Mod2 { modulus = "1000000007" }
}
openvm_algebra_moduli_setup::moduli_init! {
openvm_algebra_moduli_macros::moduli_init! {
"998244353", "1000000007"
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/algebra/tests/programs/examples/little.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use openvm_algebra_guest::{DivUnsafe, IntMod};

openvm::entry!(main);

openvm_algebra_moduli_setup::moduli_declare! {
openvm_algebra_moduli_macros::moduli_declare! {
Secp256k1Coord { modulus = "0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFC2F" }
}

openvm_algebra_moduli_setup::moduli_init!(
openvm_algebra_moduli_macros::moduli_init!(
"0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFC2F"
);

Expand Down
6 changes: 3 additions & 3 deletions extensions/algebra/tests/programs/examples/moduli_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ extern crate alloc;
use openvm_algebra_guest::IntMod;

openvm::entry!(main);
openvm_algebra_moduli_setup::moduli_declare! {
openvm_algebra_moduli_macros::moduli_declare! {
Bls12381 { modulus = "4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787" },
Mod1e18 { modulus = "1000000000000000003" },
}

openvm_algebra_moduli_setup::moduli_declare! {
openvm_algebra_moduli_macros::moduli_declare! {
Mersenne61 { modulus = "0x1fffffffffffffff" },
}

openvm_algebra_moduli_setup::moduli_init! {
openvm_algebra_moduli_macros::moduli_init! {
"4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787",
"1000000000000000003",
"0x1fffffffffffffff",
Expand Down
4 changes: 2 additions & 2 deletions extensions/ecc/guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ k256 = { workspace = true, optional = true }
hex-literal = { workspace = true }
openvm-rv32im-guest = { workspace = true }
openvm-algebra-guest = { workspace = true }
openvm-ecc-sw-setup = { workspace = true }
openvm-algebra-moduli-setup = { workspace = true }
openvm-ecc-sw-macros = { workspace = true }
openvm-algebra-moduli-macros = { workspace = true }

# Used for `halo2curves` feature
# TODO[yj]: Transition to PSE halo2curves
Expand Down
4 changes: 2 additions & 2 deletions extensions/ecc/guest/src/k256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use lazy_static::lazy_static;
#[cfg(not(target_os = "zkvm"))]
use num_bigint::BigUint;
use openvm_algebra_guest::{Field, IntMod};
use openvm_algebra_moduli_setup::moduli_declare;
use openvm_ecc_sw_setup::sw_declare;
use openvm_algebra_moduli_macros::moduli_declare;
use openvm_ecc_sw_macros::sw_declare;

use super::group::{CyclicGroup, Group};
use crate::weierstrass::{CachedMulTable, IntrinsicCurve};
Expand Down
2 changes: 1 addition & 1 deletion extensions/ecc/guest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate alloc;
#[cfg(feature = "halo2curves")]
pub use halo2curves_axiom as halo2curves;
pub use openvm_algebra_guest as algebra;
pub use openvm_ecc_sw_setup as sw_setup;
pub use openvm_ecc_sw_macros as sw_macros;
use strum_macros::FromRepr;

mod affine_point;
Expand Down
4 changes: 2 additions & 2 deletions extensions/ecc/guest/src/p256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ lazy_static! {
));
}

openvm_algebra_moduli_setup::moduli_declare! {
openvm_algebra_moduli_macros::moduli_declare! {
P256Coord { modulus = "0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff" },
P256Scalar { modulus = "0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551" },
}
Expand All @@ -38,7 +38,7 @@ pub const CURVE_B: P256Coord = P256Coord::from_const_bytes(hex!(

pub struct P256;

openvm_ecc_sw_setup::sw_declare! {
openvm_ecc_sw_macros::sw_declare! {
P256Point { mod_type = P256Coord, a = CURVE_A, b = CURVE_B },
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/ecc/tests/programs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ openvm = { path = "../../../../crates/toolchain/openvm" }
openvm-platform = { path = "../../../../crates/toolchain/platform" }

openvm-ecc-guest = { path = "../../guest", default-features = false }
openvm-ecc-sw-setup = { path = "../../../../extensions/ecc/sw-setup", default-features = false }
openvm-ecc-sw-macros = { path = "../../../../extensions/extension-algebra-macros/sw-macros", default-features = false }
openvm-algebra-guest = { path = "../../../algebra/guest", default-features = false }
openvm-algebra-moduli-setup = { path = "../../../algebra/moduli-setup", default-features = false }
openvm-algebra-moduli-macros = { path = "../../../extension-algebra-macros/moduli-macros", default-features = false }
openvm-keccak256-guest = { path = "../../../keccak256/guest", default-features = false }

serde = { version = "1.0", default-features = false, features = [
Expand Down
4 changes: 2 additions & 2 deletions extensions/ecc/tests/programs/examples/decompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use openvm_ecc_guest::{

openvm::entry!(main);

openvm_algebra_moduli_setup::moduli_init! {
openvm_algebra_moduli_macros::moduli_init! {
"0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFC2F",
"0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B BFD25E8C D0364141"
}
openvm_ecc_sw_setup::sw_init! {
openvm_ecc_sw_macros::sw_init! {
Secp256k1Point,
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/ecc/tests/programs/examples/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use openvm_ecc_guest::{
Group,
};

openvm_algebra_moduli_setup::moduli_init! {
openvm_algebra_moduli_macros::moduli_init! {
"0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFC2F",
"0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B BFD25E8C D0364141"
}

openvm_ecc_sw_setup::sw_init! {
openvm_ecc_sw_macros::sw_init! {
Secp256k1Point,
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/ecc/tests/programs/examples/ec_nonzero_a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ use openvm_ecc_guest::{

openvm::entry!(main);

openvm_algebra_moduli_setup::moduli_init! {
openvm_algebra_moduli_macros::moduli_init! {
"0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff",
"0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"
}

openvm_ecc_sw_setup::sw_init! {
openvm_ecc_sw_macros::sw_init! {
P256Point,
}

Expand Down
Loading
Loading