Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[workspace]
members = [
".",
"ff_codegen",
"ff_derive",
]

[package]
name = "ff"
version = "0.12.0"
Expand All @@ -18,7 +25,7 @@ bitvec = { version = "1", default-features = false, optional = true }
byteorder = { version = "1", default-features = false, optional = true }
ff_derive = { version = "0.12", path = "ff_derive", optional = true }
rand_core = { version = "0.6", default-features = false }
subtle = { version = "2.2.1", default-features = false, features = ["i128"] }
subtle = { version = ">=2.6.0", default-features = false, features = ["i128"] }

[dev-dependencies]
rand = "0.8"
Expand Down
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ ff = { version = "0.12", features = ["derive"] }
And then use the macro like so:

```rust
#[macro_use]
extern crate ff;
use ff::PrimeField;

#[derive(PrimeField)]
#[PrimeFieldModulus = "52435875175126190479447740508185965837690552500527637822603658699938581184513"]
Expand All @@ -50,6 +49,39 @@ struct Fp([u64; 4]);

And that's it! `Fp` now implements `Field` and `PrimeField`.

### `build.rs`
Using the `derive(PrimeField)` functionality can slow down compile times. As an alternative, the
`ff` library's code generation functionality can be invoked via a build script.

First, add the dependencies:
```toml
[dependencies]
ff = { version = "0.12", features = ["derive"] }

[build-dependencies]
ff_codegen = "0.12"
```

Then write the `build.rs` file:
```rust
fn main() {
let path = std::path::Path::new(&std::env::var("OUT_DIR").unwrap()).join("codegen.rs");
std::fs::write(&path, ff_codegen::PrimeFieldCodegen {
ident: "Fp",
is_pub: false,
modulus: "52435875175126190479447740508185965837690552500527637822603658699938581184513",
generator: "7",
endianness: ff_codegen::ReprEndianness::Little,
}.to_string()).unwrap();
println!("cargo:rerun-if-changed=build.rs");
}
```

And, finally, in the module you want to include the code in:
```rust
include!(concat!(env!("OUT_DIR"), "/codegen.rs"));
```

## Minimum Supported Rust Version

Requires Rust **1.56** or higher.
Expand Down
30 changes: 30 additions & 0 deletions ff_codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "ff_codegen"
version = "0.12.0"
authors = [
"Sean Bowe <[email protected]>",
"Jack Grigg <[email protected]>",
]
description = "Code generator library used to build custom prime field implementations"
documentation = "https://docs.rs/ff-common/"
homepage = "https://github.com/zkcrypto/ff"
license = "MIT/Apache-2.0"
repository = "https://github.com/zkcrypto/ff"
edition = "2021"

[features]
# enabled when generating bitvec code utilizing the version of ff's bitvec
bits = []

[dependencies]
addchain = "0.2"
num-bigint = "0.3"
num-traits = "0.2"
num-integer = "0.1"
proc-macro2 = "1"
quote = "1"
syn = { version = "1", features = ["full"] }
cfg-if = "1"

[badges]
maintenance = { status = "passively-maintained" }
Loading