Skip to content

Commit 828c4c6

Browse files
committed
first commit
0 parents  commit 828c4c6

29 files changed

+2548
-0
lines changed

.github/workflows/ci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Rust CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
container:
13+
image: nvidia/cuda:12.4.0-devel-ubuntu22.04
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v2
18+
19+
- name: Install dependencies
20+
run: |
21+
apt-get update
22+
apt-get install -y curl wget
23+
24+
- name: Install libclang
25+
run: apt-get install -y libclang-dev
26+
27+
- name: Install protobuf-compiler
28+
run: apt-get install -y protobuf-compiler
29+
30+
- name: Set up Rust
31+
uses: actions-rs/toolchain@v1
32+
with:
33+
toolchain: stable
34+
35+
- name: Set up Rust fmt version
36+
uses: actions-rs/toolchain@v1
37+
with:
38+
toolchain: nightly-2024-02-04-x86_64-unknown-linux-gnu
39+
40+
- name: Install rustfmt
41+
run: rustup component add --toolchain nightly-2024-02-04-x86_64-unknown-linux-gnu rustfmt
42+
43+
- name: Install dependencies
44+
run: rustup target add x86_64-unknown-linux-gnu
45+
46+
- name: Run tests
47+
run: bash ./dev_support/test.sh

.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Generated by Cargo
2+
/target/
3+
/proptest-regressions
4+
target
5+
6+
# Data
7+
ppot2ark/data
8+
amt/pp
9+
params
10+
11+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
12+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
13+
Cargo.lock
14+
15+
# These are backup files generated by rustfmt
16+
**/*.rs.bk
17+
18+
# MSVC Windows builds of rustc generate these, which store debugging information
19+
*.pdb
20+
21+
# Ignore IDE specific files
22+
.idea/
23+
.vscode/
24+
*.swp
25+
*.swo
26+
27+
# Ignore OS specific files
28+
.DS_Store
29+
Thumbs.db
30+
31+
# Ignore any compiled binaries
32+
*.exe
33+
*.dll
34+
*.so
35+
*.dylib
36+
37+
# Ignore any generated documentation
38+
/doc/
39+
40+
# Ignore any environment-specific files
41+
.env

Cargo.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[workspace]
2+
resolver = "2"
3+
4+
members = [
5+
"ppot2ark",
6+
"amt"
7+
]
8+
9+
[workspace.dependencies]
10+
amt = { path = "amt" }
11+
12+
ark-ec = "0.5"
13+
ark-ff = "0.5"
14+
ark-poly = "0.5"
15+
ark-serialize = "0.5"
16+
ark-bls12-381 = "0.5"
17+
ark-bn254 = "0.5"
18+
ark-std = "0.5"
19+
20+
rayon = "1.10"
21+
22+
rand = "0.8"
23+
24+
parking_lot = "0.12"
25+
26+
once_cell = "1.19"
27+
28+
anyhow = "1"
29+
tracing = "0.1.40"
30+
tracing-subscriber = { version = "0.3.11", features = ["env-filter"] }

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Download the trusted setup for BLS12-381 (2^21 powers of tau) from [ZcashFoundation](https://github.com/ZcashFoundation/powersoftau-attestations/tree/master/0087 "Trusted Setup for BLS12-381")
2+
```bash
3+
bash ./dev_support/download_ppot_bls.rs
4+
```
5+
## Build AMT params based on the powers of tau
6+
```bash
7+
bash ./dev_support/build_params_bls.rs $degree
8+
```

amt/Cargo.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[package]
2+
name = "amt"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
ark-ec = { workspace = true }
8+
ark-ff = { workspace = true }
9+
ark-poly = { workspace = true }
10+
ark-serialize = { workspace = true }
11+
ark-bls12-381 = { workspace = true }
12+
ark-bn254 = { workspace = true }
13+
ark-std = { workspace = true }
14+
15+
rayon = { workspace = true, optional = true }
16+
17+
rand = { workspace = true }
18+
19+
once_cell = { workspace = true }
20+
21+
anyhow = { workspace = true }
22+
tracing = { workspace = true }
23+
tracing-subscriber = { workspace = true }
24+
25+
base64 = "0.22"
26+
27+
error-chain = { version = "0.12", default-features = false }
28+
29+
[features]
30+
default = []
31+
parallel = ["ark-poly/parallel", "ark-ec/parallel", "ark-std/parallel", "rayon"]
32+
bn254 = []
33+
bls12-381 = []
34+
35+
[[bin]]
36+
name = "build_params"
37+
test = false
38+
bench = false

amt/src/bin/build_params.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use amt::{AmtParams, CreateMode, PowerTau};
2+
use anyhow::{bail, Result};
3+
use tracing::Level;
4+
5+
fn parse_param() -> Result<(usize, usize, Option<String>)> {
6+
let args: Vec<String> = std::env::args().collect();
7+
8+
if args.len() < 3 {
9+
bail!(
10+
"Usage: {} <amt-depth> <verify-depth> [<power_tau_dir>]",
11+
args[0]
12+
);
13+
}
14+
15+
let path = if args.len() == 4 {
16+
Some(args[3].parse()?)
17+
} else {
18+
None
19+
};
20+
21+
Ok((args[1].parse()?, args[2].parse()?, path))
22+
}
23+
24+
fn main() {
25+
let (depth, verify_depth, ptau_dir) = match parse_param() {
26+
Ok(x) => x,
27+
Err(e) => {
28+
eprintln!("Cannot parse input: {:?}", e);
29+
std::process::exit(1);
30+
}
31+
};
32+
33+
tracing_subscriber::fmt()
34+
.with_max_level(Level::DEBUG)
35+
.with_target(false)
36+
.init();
37+
38+
let create_mode = ptau_dir.is_none();
39+
let dir = ptau_dir.unwrap_or("./params/test".into());
40+
let pp = PowerTau::from_dir(&dir, depth, create_mode);
41+
42+
AmtParams::from_dir_mont(&dir, depth, verify_depth, CreateMode::AmtOnly, Some(&pp));
43+
}

amt/src/ec_algebra.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Re-export all the required components
2+
// in Arkworks's repo (original Zexe).
3+
4+
// Since Zexe's repo doesn't have a
5+
// stable implementation and could be
6+
// refactored in the future,
7+
// we import all the required objects in
8+
// one place and all its usage for this
9+
// repo should import from here.
10+
11+
#[cfg(test)]
12+
pub use ark_ec::VariableBaseMSM;
13+
#[cfg(test)]
14+
pub use ark_ff::{Field, One};
15+
16+
pub use ark_ec::{pairing::Pairing, AffineRepr, CurveGroup};
17+
pub use ark_ff::{utils::k_adicity, BigInt, BigInteger, PrimeField, UniformRand, Zero};
18+
pub use ark_poly::{EvaluationDomain, Radix2EvaluationDomain};
19+
pub use ark_serialize::{CanonicalDeserialize, CanonicalSerialize, Read, Write};
20+
21+
pub type G1<PE> = <PE as ark_ec::pairing::Pairing>::G1;
22+
pub type G1Aff<PE> = <PE as ark_ec::pairing::Pairing>::G1Affine;
23+
pub type G2<PE> = <PE as ark_ec::pairing::Pairing>::G2;
24+
pub type G2Aff<PE> = <PE as ark_ec::pairing::Pairing>::G2Affine;
25+
pub type Fr<PE> = <PE as ark_ec::pairing::Pairing>::ScalarField;
26+
pub type Fq<PE> = <PE as ark_ec::pairing::Pairing>::BaseField;
27+
pub type FrInt<PE> = <Fr<PE> as PrimeField>::BigInt;
28+
pub type FqInt<PE> = <Fq<PE> as PrimeField>::BigInt;
29+
pub type Fq2<PE> = <G2Aff<PE> as AffineRepr>::BaseField;

amt/src/error.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use error_chain::error_chain;
2+
3+
error_chain! {
4+
links {
5+
}
6+
7+
foreign_links {
8+
File(std::io::Error);
9+
Serialize(ark_serialize::SerializationError);
10+
}
11+
12+
errors {
13+
InconsistentLength {
14+
description("In consistent length between expected params and real params")
15+
display("In consistent length between expected params and real params")
16+
}
17+
18+
InconsistentPowersOfTau {
19+
description("In consistent powers of tau")
20+
display("In consistent powers of tau")
21+
}
22+
23+
RareZeroGenerationError {
24+
description("Failed to generate a non-zero scalar after multiple attempts")
25+
display("Failed to generate a non-zero scalar after multiple attempts")
26+
}
27+
}
28+
}

amt/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#[macro_use]
2+
extern crate tracing;
3+
4+
pub mod ec_algebra;
5+
mod error;
6+
mod power_tau;
7+
mod proofs;
8+
mod prove_params;
9+
mod utils;
10+
11+
pub use power_tau::PowerTau;
12+
pub use proofs::AmtProofError;
13+
pub use prove_params::{AmtParams, CreateMode};
14+
pub use utils::ptau_file_name;
15+
16+
#[cfg(not(feature = "bls12-381"))]
17+
pub use prove_params::fast_serde_bn254;
18+
19+
#[cfg(feature = "bls12-381")]
20+
pub use prove_params::fast_serde_bls12_381;

0 commit comments

Comments
 (0)