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

Thv/degree lowering hardening #325

Merged
merged 37 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
20fd0ea
refactor: Factor out loop body
Sword-Smith Sep 12, 2024
86cf962
bench: Add benchmark for degree lowering times
Sword-Smith Sep 12, 2024
763cf3f
test: Add test for deterministic degree lowering
Sword-Smith Sep 12, 2024
83d184e
test: Catch changes in constraint evaluators
Sword-Smith Sep 12, 2024
9834bda
test: Verify node-picking for degree lowering is deterministic
Sword-Smith Sep 12, 2024
759ebad
refactor: Rename function to reflect what happens inside
aszepieniec Sep 16, 2024
eabac9f
refactor: Rename function to concise descriptor
aszepieniec Sep 16, 2024
883a172
test: Add proptest for `apply_substitution`
aszepieniec Sep 16, 2024
3649789
ci: Skip degree-lowering benchmark in nextest run
aszepieniec Sep 19, 2024
f8154fa
deps: Synchronize dependency invocation
aszepieniec Sep 19, 2024
84b2ea9
style: Inline benchmarked functions' output into `black_box`
aszepieniec Sep 19, 2024
055e891
style: Use if-else for bool
aszepieniec Sep 19, 2024
aa84d29
fix: Use type aliases to kill boilerplate
aszepieniec Sep 19, 2024
e00014d
fix(test): Remove false assertion when counting nodes
Sword-Smith Sep 18, 2024
4ee2cbb
ci: Skip degree-lowering benchmark in nextest CI run
aszepieniec Sep 19, 2024
1f077a9
fix: Set hardcoded value right
aszepieniec Sep 19, 2024
1dcadf8
test: Reduce seed length from 256 to 64 bits
aszepieniec Sep 21, 2024
db295aa
style: Un-merge imports
aszepieniec Sep 21, 2024
603740d
refactor: Rename `redirect_pointers` to `redirect_all_references_to_n…
aszepieniec Sep 21, 2024
920c97d
style: Make doc string fit line width
aszepieniec Sep 21, 2024
8ee206e
docs: Correct grammatical error
aszepieniec Sep 21, 2024
7d914de
refactor: Simplify, return early, factor out
aszepieniec Sep 21, 2024
acc09d5
style: Drop unnecessaries
aszepieniec Sep 21, 2024
14a0572
style: Disambiguate with new types
aszepieniec Sep 21, 2024
2718b14
style: Use helper function `num_nodes`
aszepieniec Sep 23, 2024
28beaa9
style: Simplify selection of suitable node id
aszepieniec Sep 23, 2024
2d87fb7
style: Use `panic!` instead of `unreachable!`
aszepieniec Sep 23, 2024
396f38f
style: Simplify extension of input
aszepieniec Sep 23, 2024
d69ceba
style: Touch up comments
aszepieniec Sep 23, 2024
5cdf137
style: Split iter-map into smaller steps
aszepieniec Sep 23, 2024
2c4db3c
style: Use idiomatic `not().then_some()`
aszepieniec Sep 23, 2024
0d012de
refactor: Factor out common patterns
aszepieniec Sep 23, 2024
99424f9
style: Drop superfluous verbs from docstrings
aszepieniec Sep 23, 2024
94c7593
fix: Fix copy-paste error in docstring
aszepieniec Sep 23, 2024
532bbb7
refactor: Simplify interface to arbitrary circuit
aszepieniec Sep 23, 2024
821d6e0
fix: Match for specific node type
aszepieniec Sep 23, 2024
8634d45
style: Apply cosmetic changes
jan-ferdinand Sep 25, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: taiki-e/install-action@nextest

- name: Collect coverage data
run: cargo llvm-cov nextest --all-targets --lcov --output-path lcov.info
run: cargo llvm-cov nextest --lcov --output-path lcov.info

- name: Upload coverage to coveralls.io
uses: coverallsapp/github-action@v2
Expand Down
17 changes: 15 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,21 @@ jobs:
- name: Run clippy
run: cargo clippy --all-targets -- -D warnings

- name: Run tests
run: cargo nextest run --no-fail-fast --all-targets
- name: Test triton-isa
run: cargo nextest run -p triton-isa --no-fail-fast --all-targets

- name: Test triton-constraint-circuit
run: cargo nextest run -p triton-constraint-circuit --no-fail-fast --all-targets

- name: Test triton-air
run: cargo nextest run -p triton-air --no-fail-fast --all-targets

- name: Test triton-constraint-builder
# without --all-targets because the divan benchmark doesn't play ball with nextest
run: cargo nextest run -p triton-constraint-builder --no-fail-fast

- name: Test triton-vm
run: cargo nextest run -p triton-vm --no-fail-fast --all-targets

# doctests are special [^1] but this step does not incur a performance penalty [^2]
#
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ test-strategy = "0.4.0"
thiserror = "1.0"
twenty-first = "0.42.0-alpha.9"
unicode-width = "0.1"
divan = "0.1.14"

[workspace.lints.rust]
let_underscore_drop = "warn"
Expand Down
2 changes: 1 addition & 1 deletion triton-air/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Triton VM AIR

This crate is part of the [Triton VM](https://triton-vm.org) ecosystem. It contains the definition
of the AIR constraints, which are part of the STARK proving system.
of the AIR constraints, which are part of the STARK proving system, before degree lowering.
5 changes: 5 additions & 0 deletions triton-constraint-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ twenty-first.workspace = true
proptest.workspace = true
proptest-arbitrary-interop.workspace = true
test-strategy.workspace = true
divan.workspace = true

[lints]
workspace = true

[[bench]]
name = "degree_lowering"
harness = false
91 changes: 91 additions & 0 deletions triton-constraint-builder/benches/degree_lowering.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
use constraint_circuit::ConstraintCircuitMonad;
use divan::black_box;
use triton_constraint_builder::Constraints;

fn main() {
divan::main();
}

#[divan::bench(sample_count = 10)]
fn assemble_constraints() {
black_box(Constraints::all());
}

#[divan::bench(sample_count = 10)]
fn initial_constraints(bencher: divan::Bencher) {
bencher
.with_inputs(|| {
let degree_lowering_info = Constraints::default_degree_lowering_info();
let constraints = Constraints::initial_constraints();
(degree_lowering_info, constraints)
})
.bench_values(|(degree_lowering_info, mut constraints)| {
black_box(ConstraintCircuitMonad::lower_to_degree(
&mut constraints,
degree_lowering_info,
));
});
}

#[divan::bench(sample_count = 10)]
fn consistency_constraints(bencher: divan::Bencher) {
bencher
.with_inputs(|| {
let degree_lowering_info = Constraints::default_degree_lowering_info();
let constraints = Constraints::consistency_constraints();
(degree_lowering_info, constraints)
})
.bench_values(|(degree_lowering_info, mut constraints)| {
black_box(ConstraintCircuitMonad::lower_to_degree(
&mut constraints,
degree_lowering_info,
));
});
}

#[divan::bench(sample_count = 1)]
fn transition_constraints(bencher: divan::Bencher) {
bencher
.with_inputs(|| {
let degree_lowering_info = Constraints::default_degree_lowering_info();
let constraints = Constraints::transition_constraints();
(degree_lowering_info, constraints)
})
.bench_values(|(degree_lowering_info, mut constraints)| {
black_box(ConstraintCircuitMonad::lower_to_degree(
&mut constraints,
degree_lowering_info,
));
});
}

#[divan::bench(sample_count = 10)]
fn terminal_constraints(bencher: divan::Bencher) {
bencher
.with_inputs(|| {
let degree_lowering_info = Constraints::default_degree_lowering_info();
let constraints = Constraints::terminal_constraints();
(degree_lowering_info, constraints)
})
.bench_values(|(degree_lowering_info, mut constraints)| {
black_box(ConstraintCircuitMonad::lower_to_degree(
&mut constraints,
degree_lowering_info,
));
});
}

#[divan::bench(sample_count = 1)]
fn degree_lower_all(bencher: divan::Bencher) {
bencher
.with_inputs(|| {
let constraints = Constraints::all();
let degree_lowering_info = Constraints::default_degree_lowering_info();
(degree_lowering_info, constraints)
})
.bench_values(|(degree_lowering_info, mut constraints)| {
black_box(
constraints.lower_to_target_degree_through_substitutions(degree_lowering_info),
);
});
}
11 changes: 11 additions & 0 deletions triton-constraint-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ impl Constraints {
}
}

// Implementing Default for DegreeLoweringInfo is impossible because the
// constants are defined in crate `air` but struct `DegreeLoweringInfo` is
// defined in crate `triton-constraint-circuit`. Cfr. orphan rule.
pub fn default_degree_lowering_info() -> DegreeLoweringInfo {
constraint_circuit::DegreeLoweringInfo {
target_degree: air::TARGET_DEGREE,
num_main_cols: air::table::NUM_MAIN_COLUMNS,
num_aux_cols: air::table::NUM_AUX_COLUMNS,
}
}

pub fn initial_constraints() -> Vec<ConstraintCircuitMonad<SingleRowIndicator>> {
let circuit_builder = ConstraintCircuitBuilder::new();
vec![
Expand Down
Loading