Skip to content

Commit 5efeefe

Browse files
committed
feat: hooks, split arkworks backend
1 parent cb4fd4a commit 5efeefe

File tree

14 files changed

+319
-229
lines changed

14 files changed

+319
-229
lines changed

README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ Dory is a transparent polynomial commitment scheme with excellent asymptotic per
3737

3838
### Backend Implementations
3939

40-
- **`backends::arkworks`** - Arkworks backend with BN254 curve (requires `arkworks` feature)
41-
- **`backends::blake2b_transcript`** - Blake2b-based Fiat-Shamir transcript
40+
- **`backends::arkworks`** - Modular Arkworks backend with BN254 curve (requires `arkworks` feature)
41+
- Field wrappers (`ArkFr`)
42+
- Group wrappers (`ArkG1`, `ArkG2`, `ArkGT`)
43+
- Polynomial implementation
44+
- Optimized MSM routines
45+
- Blake2b transcript
46+
- Serialization bridge
4247

4348
## How It Works
4449

@@ -105,6 +110,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
105110
}
106111
```
107112

113+
## Development Setup
114+
115+
After cloning the repository, install Git hooks to ensure code quality:
116+
117+
```bash
118+
./scripts/install-hooks.sh
119+
```
120+
121+
This installs a pre-commit hook that:
122+
- Auto-formats code with `cargo fmt`
123+
- Runs `cargo clippy` in strict mode
124+
108125
## Performance Considerations
109126

110127
This implementation is optimized for performance:
@@ -149,8 +166,14 @@ src/
149166
│ ├── transcript.rs # Fiat-Shamir transcript trait
150167
│ └── serialization.rs # Serialization abstractions
151168
├── backends/
152-
│ ├── arkworks.rs # BN254 implementation
153-
│ └── blake2b_transcript.rs # Blake2b transcript
169+
│ ├── mod.rs # Backend module exports
170+
│ └── arkworks/ # Arkworks BN254 backend
171+
│ ├── mod.rs # Module exports
172+
│ ├── ark_field.rs # Field wrapper (ArkFr)
173+
│ ├── ark_group.rs # Group wrappers (ArkG1, ArkG2, ArkGT)
174+
│ ├── ark_poly.rs # Polynomial implementation
175+
│ ├── ark_serde.rs # Serialization bridge
176+
│ └── blake2b_transcript.rs # Blake2b transcript
154177
├── setup.rs # Transparent setup generation
155178
├── evaluation_proof.rs # Proof creation and verification
156179
├── reduce_and_fold.rs # Inner product protocol
@@ -159,6 +182,7 @@ src/
159182
└── error.rs # Error types
160183
161184
tests/arkworks/
185+
├── mod.rs # Test utilities
162186
├── setup.rs # Setup tests
163187
├── commitment.rs # Commitment tests
164188
├── evaluation.rs # Evaluation tests

hooks/pre-commit

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
# Pre-commit hook for Dory
3+
# Runs cargo fmt (auto-fix) and cargo clippy (strict mode)
4+
5+
set -e
6+
7+
echo "Running pre-commit checks..."
8+
9+
echo " → Running cargo fmt..."
10+
cargo fmt --all
11+
12+
git diff --name-only | grep '\.rs$' | xargs -r git add
13+
14+
echo " → Running cargo clippy (strict mode)..."
15+
if ! cargo clippy -q --message-format=short --all --all-targets --all-features -- -D warnings; then
16+
echo "❌ Clippy failed with warnings or errors. Fix them before committing."
17+
exit 1
18+
fi
19+
20+
echo "✅ All pre-commit checks passed!"
21+
exit 0

scripts/install-hooks.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
# Installation script for Git hooks
3+
4+
set -e
5+
6+
HOOKS_DIR="hooks"
7+
GIT_HOOKS_DIR=".git/hooks"
8+
9+
echo "Installing Git hooks..."
10+
11+
# Check if we're in a git repository
12+
if [ ! -d ".git" ]; then
13+
echo "Error: Not a git repository. Run this script from the repository root."
14+
exit 1
15+
fi
16+
17+
# Check if hooks directory exists
18+
if [ ! -d "$HOOKS_DIR" ]; then
19+
echo "Error: hooks/ directory not found"
20+
exit 1
21+
fi
22+
23+
# Install pre-commit hook
24+
if [ -f "$HOOKS_DIR/pre-commit" ]; then
25+
cp "$HOOKS_DIR/pre-commit" "$GIT_HOOKS_DIR/pre-commit"
26+
chmod +x "$GIT_HOOKS_DIR/pre-commit"
27+
echo "✅ Installed pre-commit hook"
28+
else
29+
echo "⚠️ Warning: hooks/pre-commit not found"
30+
fi
31+
32+
echo "Done! Git hooks are now active."
33+
echo ""
34+
echo "The pre-commit hook will:"
35+
echo " • Auto-format code with cargo fmt"
36+
echo " • Run cargo clippy in strict mode"
37+
echo " • Block commits if clippy warnings exist"

src/backends/arkworks/ark_field.rs

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
use crate::primitives::arithmetic::Field;
2+
use ark_bn254::Fr;
3+
use ark_ff::{Field as ArkField, UniformRand, Zero as ArkZero};
4+
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
5+
use ark_std::ops::{Add, Mul, Neg, Sub};
6+
use rand_core::RngCore;
7+
8+
#[derive(Clone, Copy, PartialEq, Eq, Debug, CanonicalSerialize, CanonicalDeserialize)]
9+
pub struct ArkFr(pub Fr);
10+
11+
impl Field for ArkFr {
12+
fn zero() -> Self {
13+
ArkFr(Fr::from(0u64))
14+
}
15+
16+
fn one() -> Self {
17+
ArkFr(Fr::from(1u64))
18+
}
19+
20+
fn is_zero(&self) -> bool {
21+
ArkZero::is_zero(&self.0)
22+
}
23+
24+
fn add(&self, rhs: &Self) -> Self {
25+
ArkFr(self.0 + rhs.0)
26+
}
27+
28+
fn sub(&self, rhs: &Self) -> Self {
29+
ArkFr(self.0 - rhs.0)
30+
}
31+
32+
fn mul(&self, rhs: &Self) -> Self {
33+
ArkFr(self.0 * rhs.0)
34+
}
35+
36+
fn inv(self) -> Option<Self> {
37+
ArkField::inverse(&self.0).map(ArkFr)
38+
}
39+
40+
fn random<R: RngCore>(rng: &mut R) -> Self {
41+
ArkFr(Fr::rand(rng))
42+
}
43+
44+
fn from_u64(val: u64) -> Self {
45+
ArkFr(Fr::from(val))
46+
}
47+
48+
fn from_i64(val: i64) -> Self {
49+
if val >= 0 {
50+
ArkFr(Fr::from(val as u64))
51+
} else {
52+
ArkFr(-Fr::from((-val) as u64))
53+
}
54+
}
55+
}
56+
57+
impl Add for ArkFr {
58+
type Output = Self;
59+
fn add(self, rhs: Self) -> Self {
60+
ArkFr(self.0 + rhs.0)
61+
}
62+
}
63+
64+
impl Sub for ArkFr {
65+
type Output = Self;
66+
fn sub(self, rhs: Self) -> Self {
67+
ArkFr(self.0 - rhs.0)
68+
}
69+
}
70+
71+
impl Mul for ArkFr {
72+
type Output = Self;
73+
fn mul(self, rhs: Self) -> Self {
74+
ArkFr(self.0 * rhs.0)
75+
}
76+
}
77+
78+
impl Neg for ArkFr {
79+
type Output = Self;
80+
fn neg(self) -> Self {
81+
ArkFr(-self.0)
82+
}
83+
}
84+
85+
impl<'a> Add<&'a ArkFr> for ArkFr {
86+
type Output = ArkFr;
87+
fn add(self, rhs: &'a ArkFr) -> ArkFr {
88+
ArkFr(self.0 + rhs.0)
89+
}
90+
}
91+
92+
impl<'a> Sub<&'a ArkFr> for ArkFr {
93+
type Output = ArkFr;
94+
fn sub(self, rhs: &'a ArkFr) -> ArkFr {
95+
ArkFr(self.0 - rhs.0)
96+
}
97+
}
98+
99+
impl<'a> Mul<&'a ArkFr> for ArkFr {
100+
type Output = ArkFr;
101+
fn mul(self, rhs: &'a ArkFr) -> ArkFr {
102+
ArkFr(self.0 * rhs.0)
103+
}
104+
}

0 commit comments

Comments
 (0)