Skip to content

Commit 4b9d45a

Browse files
Merge branch 'main' into matthias/extract-17
2 parents d4986d9 + 62de573 commit 4b9d45a

File tree

304 files changed

+583
-518
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

304 files changed

+583
-518
lines changed

.github/workflows/ci.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Sanity checks
2+
3+
on:
4+
merge_group:
5+
push:
6+
branches:
7+
- '**'
8+
9+
jobs:
10+
sanity:
11+
name: Sanity check
12+
timeout-minutes: 30
13+
runs-on: ubuntu-24.04
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: dtolnay/rust-toolchain@master
18+
with:
19+
components: rustfmt
20+
# TODO(Matthias): see whether we can keep this in sync with rust-toolchain.toml automatically?
21+
toolchain: nightly-2024-10-03
22+
- name: Cargo cache
23+
uses: actions/cache@v3
24+
with:
25+
# target directories gotten via
26+
# `find . -name target -type d -not -path '*/src/*' -printf '%P\n' | sort`
27+
# We need to exclude `./circ_blocks/src/target` because it just a source directory with an unfortunate name.
28+
path: |
29+
~/.cargo/bin/
30+
~/.cargo/registry/index/
31+
~/.cargo/registry/cache/
32+
~/.cargo/git/db/
33+
circ_blocks/circ_fields/target
34+
circ_blocks/circ_hc/target
35+
circ_blocks/circ_opt/target
36+
circ_blocks/circ_waksman/target
37+
circ_blocks/target
38+
circ_blocks/third_party/ZoKrates/zokrates_parser/target
39+
circ_blocks/third_party/ZoKrates/zokrates_pest_ast/target
40+
circ_blocks/third_party/ZoKrates/zokrates_stdlib/target
41+
ff/ff_derive/target
42+
ff/target
43+
spartan_parallel/target
44+
zok_tests/poseidon_gen/target
45+
key: sanity-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }}
46+
47+
- name: Run sanity check
48+
run: |
49+
set -euxo pipefail
50+
51+
for cargo_toml in $(git ls-files '**/Cargo.toml'); do
52+
(
53+
cd "$(dirname ${cargo_toml})"
54+
cargo fmt --check
55+
cargo check --all-targets
56+
)
57+
done
58+
59+
legacy-scripts:
60+
name: Run legacy scripts
61+
timeout-minutes: 30
62+
runs-on: ubuntu-24.04
63+
64+
steps:
65+
- uses: actions/checkout@v2
66+
- uses: dtolnay/rust-toolchain@master
67+
with:
68+
# TODO(Matthias): see whether we can keep this in sync with rust-toolchain.toml automatically?
69+
toolchain: nightly-2024-10-03
70+
- name: Cargo cache
71+
uses: actions/cache@v3
72+
with:
73+
# target directories gotten via
74+
# `find . -name target -type d -not -path '*/src/*' -printf '%P\n' | sort`
75+
# We need to exclude `./circ_blocks/src/target` because it just a source directory with an unfortunate name.
76+
path: |
77+
~/.cargo/bin/
78+
~/.cargo/registry/index/
79+
~/.cargo/registry/cache/
80+
~/.cargo/git/db/
81+
circ_blocks/circ_fields/target
82+
circ_blocks/circ_hc/target
83+
circ_blocks/circ_opt/target
84+
circ_blocks/circ_waksman/target
85+
circ_blocks/target
86+
circ_blocks/third_party/ZoKrates/zokrates_parser/target
87+
circ_blocks/third_party/ZoKrates/zokrates_pest_ast/target
88+
circ_blocks/third_party/ZoKrates/zokrates_stdlib/target
89+
ff/ff_derive/target
90+
ff/target
91+
spartan_parallel/target
92+
zok_tests/poseidon_gen/target
93+
key: scripts-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }}
94+
95+
- name: Run legacy scripts
96+
run: |
97+
set -euxo pipefail
98+
./setup.sh
99+
# TODO: fix, then enable it.
100+
# ./encode_ceno.sh

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,11 @@ Many flags are WIP. For temporary hacks, alter the code directly and recompile t
4242
#### Working with a different field
4343

4444
#### Verify circuit using `spartan_parallel` (only supported in Curve25519)
45+
46+
# Continuous Integration
47+
48+
At the moment we only have a [simple CI](.github/workflows/) that checks formatting and `cargo check` and runs [setup.sh](setup.sh) and [encode_ceno.sh](encode_ceno.sh).
49+
50+
TODO:
51+
- [ ] run tests in CI, too. (That means we need to fix our tests.)
52+
- [ ] reorganise the code, so that we only need a single `carge check` or `cargo test` instead of having to run that in a dozen different directories.

circ_blocks/circ_fields/src/ext_field.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl Mul<i64> for FGoldilocksExt2 {
104104

105105
#[inline]
106106
fn mul(self, rhs: i64) -> Self::Output {
107-
&self * &FGoldilocks::from(rhs)
107+
self * FGoldilocks::from(rhs)
108108
}
109109
}
110110
impl MulAssign<&FGoldilocks> for FGoldilocksExt2 {
@@ -315,19 +315,19 @@ impl<'a> Mul<&'a FGoldilocksExt2> for FGoldilocksExt2 {
315315

316316
#[inline]
317317
fn mul(self, rhs: &'a FGoldilocksExt2) -> Self::Output {
318-
mul_internal(&self, &rhs)
318+
mul_internal(&self, rhs)
319319
}
320320
}
321321
impl MulAssign for FGoldilocksExt2 {
322322
#[inline]
323323
fn mul_assign(&mut self, rhs: Self) {
324-
*self = mul_internal(&self, &rhs);
324+
*self = mul_internal(self, &rhs);
325325
}
326326
}
327327
impl<'a> MulAssign<&'a FGoldilocksExt2> for FGoldilocksExt2 {
328328
#[inline]
329329
fn mul_assign(&mut self, rhs: &'a FGoldilocksExt2) {
330-
*self = mul_internal(&self, &rhs);
330+
*self = mul_internal(self, rhs);
331331
}
332332
}
333333

circ_blocks/circ_fields/src/lib.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -499,15 +499,15 @@ impl FullFieldV {
499499
#[inline]
500500
fn pow(&self, u: u64) -> Self {
501501
match self {
502-
FullFieldV::FBls12381(f) => FullFieldV::FBls12381(f.pow_vartime(&[u])),
503-
FullFieldV::FBn254(f) => FullFieldV::FBn254(f.pow_vartime(&[u])),
504-
FullFieldV::FCurve25519(f) => FullFieldV::FCurve25519(f.pow_vartime(&[u])),
502+
FullFieldV::FBls12381(f) => FullFieldV::FBls12381(f.pow_vartime([u])),
503+
FullFieldV::FBn254(f) => FullFieldV::FBn254(f.pow_vartime([u])),
504+
FullFieldV::FCurve25519(f) => FullFieldV::FCurve25519(f.pow_vartime([u])),
505505
FullFieldV::IntField(i) => FullFieldV::IntField(IntField::new(
506506
i.i.clone().pow_mod(&Integer::from(u), i.modulus()).unwrap(),
507507
i.modulus_arc(),
508508
)),
509-
FullFieldV::FGoldilocks(f) => FullFieldV::FGoldilocks(f.pow_vartime(&[u])),
510-
FullFieldV::FGoldilocksExt2(f) => FullFieldV::FGoldilocksExt2(f.pow_vartime(&[u])),
509+
FullFieldV::FGoldilocks(f) => FullFieldV::FGoldilocks(f.pow_vartime([u])),
510+
FullFieldV::FGoldilocksExt2(f) => FullFieldV::FGoldilocksExt2(f.pow_vartime([u])),
511511
}
512512
}
513513

@@ -634,11 +634,11 @@ impl FieldV {
634634
use num_traits::One;
635635
match self.either_ref() {
636636
Ok(InlineFieldV(i, _)) => i == 1,
637-
Err(FullFieldV::FBls12381(pf)) => bool::from(pf.is_one()),
638-
Err(FullFieldV::FBn254(pf)) => bool::from(pf.is_one()),
639-
Err(FullFieldV::FCurve25519(pf)) => bool::from(pf.is_one()),
637+
Err(FullFieldV::FBls12381(pf)) => pf.is_one(),
638+
Err(FullFieldV::FBn254(pf)) => pf.is_one(),
639+
Err(FullFieldV::FCurve25519(pf)) => pf.is_one(),
640640
Err(FullFieldV::IntField(i)) => i.i == 1,
641-
Err(FullFieldV::FGoldilocks(pf)) => bool::from(pf.is_one()),
641+
Err(FullFieldV::FGoldilocks(pf)) => pf.is_one(),
642642
Err(FullFieldV::FGoldilocksExt2(pf)) => pf == &FGoldilocksExt2::one(),
643643
}
644644
}
@@ -922,16 +922,12 @@ impl Neg for FieldV {
922922
fn neg(mut self) -> Self {
923923
if self.is_full() {
924924
match self.full_mut() {
925-
FullFieldV::FBls12381(pf) => Self::from(FullFieldV::FBls12381(pf.clone().neg())),
926-
FullFieldV::FBn254(pf) => Self::from(FullFieldV::FBn254(pf.clone().neg())),
927-
FullFieldV::FCurve25519(pf) => {
928-
Self::from(FullFieldV::FCurve25519(pf.clone().neg()))
929-
}
930-
FullFieldV::FGoldilocks(pf) => {
931-
Self::from(FullFieldV::FGoldilocks(pf.clone().neg()))
932-
}
925+
FullFieldV::FBls12381(pf) => Self::from(FullFieldV::FBls12381((*pf).neg())),
926+
FullFieldV::FBn254(pf) => Self::from(FullFieldV::FBn254((*pf).neg())),
927+
FullFieldV::FCurve25519(pf) => Self::from(FullFieldV::FCurve25519((*pf).neg())),
928+
FullFieldV::FGoldilocks(pf) => Self::from(FullFieldV::FGoldilocks((*pf).neg())),
933929
FullFieldV::FGoldilocksExt2(pf) => {
934-
Self::from(FullFieldV::FGoldilocksExt2(pf.clone().neg()))
930+
Self::from(FullFieldV::FGoldilocksExt2((*pf).neg()))
935931
}
936932
FullFieldV::IntField(i) => Self::from(FullFieldV::IntField(i.clone().neg())),
937933
}

circ_blocks/circ_hc/src/collections/cache.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ pub struct NodeCache<Op, T: Table<Op>, V> {
99
inner: HashMap<T::Weak, V>,
1010
}
1111

12+
impl<Op, T: Table<Op>, V> Default for NodeCache<Op, T, V> {
13+
fn default() -> Self {
14+
Self::new()
15+
}
16+
}
17+
1218
impl<Op, T: Table<Op>, V> NodeCache<Op, T, V> {
1319
/// Create an empty cache.
1420
pub fn new() -> Self {

circ_blocks/circ_hc/src/hashconsing/example_u8.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl crate::Table<u8> for Table {
2727
#[allow(dead_code)]
2828
fn create(op: &u8, children: Vec<Node>) -> Node {
2929
FACTORY.mk(ActualNode {
30-
op: op.clone(),
30+
op: *op,
3131
cs: children,
3232
})
3333
}

circ_blocks/circ_hc/src/hashconsing/template.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl crate::Table<TemplateOp> for Table {
2828
#[allow(dead_code)]
2929
fn create(op: &TemplateOp, children: Vec<Node>) -> Node {
3030
FACTORY.mk(ActualNode {
31-
op: op.clone(),
31+
op: *op,
3232
cs: children,
3333
})
3434
}

circ_blocks/circ_hc/src/raw/example_u8.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl Manager {
111111
// TODO: hash w/o clone.
112112
let raw = NodeData {
113113
cs: children.into(),
114-
op: op.clone(),
114+
op: *op,
115115
};
116116
let id = self.next_id.get();
117117
let ptr = {
@@ -154,10 +154,10 @@ impl Manager {
154154
debug_assert_eq!(unsafe { (*ptr.0).ref_cnt.get() }, 0);
155155
let table_size = self.table.borrow().len();
156156
self.zombies.borrow_mut().insert(ptr);
157-
if !self.in_gc.get() {
158-
if self.zombies.borrow().len() as f64 > GC_IN_DROP_THRESH * table_size as f64 {
159-
self.force_gc();
160-
}
157+
if !self.in_gc.get()
158+
&& self.zombies.borrow().len() as f64 > GC_IN_DROP_THRESH * table_size as f64
159+
{
160+
self.force_gc();
161161
}
162162
}
163163

circ_blocks/circ_hc/src/raw/template.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl Manager {
111111
// TODO: hash w/o clone.
112112
let raw = NodeData {
113113
cs: children.into(),
114-
op: op.clone(),
114+
op: *op,
115115
};
116116
let id = self.next_id.get();
117117
let ptr = {
@@ -154,10 +154,10 @@ impl Manager {
154154
debug_assert_eq!(unsafe { (*ptr.0).ref_cnt.get() }, 0);
155155
let table_size = self.table.borrow().len();
156156
self.zombies.borrow_mut().insert(ptr);
157-
if !self.in_gc.get() {
158-
if self.zombies.borrow().len() as f64 > GC_IN_DROP_THRESH * table_size as f64 {
159-
self.force_gc();
160-
}
157+
if !self.in_gc.get()
158+
&& self.zombies.borrow().len() as f64 > GC_IN_DROP_THRESH * table_size as f64
159+
{
160+
self.force_gc();
161161
}
162162
}
163163

circ_blocks/circ_hc/src/rc/example_u8.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'a> std::fmt::Debug for TableDebug<'a> {
137137
impl std::fmt::Debug for Manager {
138138
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
139139
f.debug_struct("Manager")
140-
.field("table", &TableDebug(&*self.table.borrow()))
140+
.field("table", &TableDebug(&self.table.borrow()))
141141
.field("next_id", &self.next_id.get())
142142
.finish()
143143
}
@@ -157,7 +157,7 @@ impl Manager {
157157
fn create(&self, op: &u8, children: Vec<Node>) -> Node {
158158
let mut table = self.table.borrow_mut();
159159
let data = Rc::new(NodeData {
160-
op: op.clone(),
160+
op: *op,
161161
cs: children.into(),
162162
});
163163

0 commit comments

Comments
 (0)