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

Add range_check example #768

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
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
148 changes: 148 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ rayon = { version = "1.10.0", optional = true }
serde = { version = "1.0", features = ["derive"] }

[dev-dependencies]
proptest = "1.0"
aligned = "0.4.2"
test-log = { version = "0.2.15", features = ["trace"] }
tracing-subscriber = "0.3.18"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc e1bb1f72c891764d16309d8fc8cfd7a23f6d31324a661979c6c684a2cc29724c # shrinks to invalid_value = 32768
1 change: 1 addition & 0 deletions crates/prover/src/examples/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod fibonacci;
pub mod poseidon;
pub mod range_check;
pub mod wide_fibonacci;
pub mod xor;
118 changes: 118 additions & 0 deletions crates/prover/src/examples/range_check/air.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
use super::component::{RangeCheckComponent, RangeCheckInput, RangeCheckTraceGenerator};
use crate::core::air::{Air, AirProver, Component, ComponentProver};
use crate::core::backend::CpuBackend;
use crate::core::channel::Blake2sChannel;
use crate::core::fields::m31::BaseField;
use crate::core::poly::circle::CircleEvaluation;
use crate::core::poly::BitReversedOrder;
use crate::core::prover::VerificationError;
use crate::core::{ColumnVec, InteractionElements, LookupValues};
use crate::trace_generation::registry::ComponentGenerationRegistry;
use crate::trace_generation::{AirTraceGenerator, AirTraceVerifier, ComponentTraceGenerator};

pub struct RangeCheckAirGenerator {
pub registry: ComponentGenerationRegistry,
}

impl RangeCheckAirGenerator {
pub fn new(inputs: &RangeCheckInput) -> Self {
let mut component_generator = RangeCheckTraceGenerator::new();
component_generator.add_inputs(inputs);
let mut registry = ComponentGenerationRegistry::default();
registry.register("range_check", component_generator);
Self { registry }
}
}

impl AirTraceVerifier for RangeCheckAirGenerator {
fn interaction_elements(&self, _channel: &mut Blake2sChannel) -> InteractionElements {
InteractionElements::default()
}
}

impl AirTraceGenerator<CpuBackend> for RangeCheckAirGenerator {
fn write_trace(&mut self) -> Vec<CircleEvaluation<CpuBackend, BaseField, BitReversedOrder>> {
RangeCheckTraceGenerator::write_trace("range_check", &mut self.registry)
}

fn interact(
&self,
_trace: &ColumnVec<CircleEvaluation<CpuBackend, BaseField, BitReversedOrder>>,
_elements: &InteractionElements,
) -> Vec<CircleEvaluation<CpuBackend, BaseField, BitReversedOrder>> {
vec![]
}

fn to_air_prover(&self) -> impl AirProver<CpuBackend> {
let component_generator = self
.registry
.get_generator::<RangeCheckTraceGenerator>("range_check");
RangeCheckAir {
component: component_generator.component(),
}
}

fn composition_log_degree_bound(&self) -> u32 {
let component_generator = self
.registry
.get_generator::<RangeCheckTraceGenerator>("range_check");
assert!(
component_generator.inputs_set(),
"range_check input not set."
);
component_generator
.component()
.max_constraint_log_degree_bound()
}
}

#[derive(Clone)]
pub struct RangeCheckAir {
pub component: RangeCheckComponent,
}

impl RangeCheckAir {
pub fn new(component: RangeCheckComponent) -> Self {
Self { component }
}
}

impl Air for RangeCheckAir {
fn components(&self) -> Vec<&dyn Component> {
vec![&self.component]
}

fn verify_lookups(&self, _lookup_values: &LookupValues) -> Result<(), VerificationError> {
Ok(())
}
}

impl AirTraceVerifier for RangeCheckAir {
fn interaction_elements(&self, _channel: &mut Blake2sChannel) -> InteractionElements {
InteractionElements::default()
}
}

impl AirTraceGenerator<CpuBackend> for RangeCheckAir {
fn interact(
&self,
_trace: &ColumnVec<CircleEvaluation<CpuBackend, BaseField, BitReversedOrder>>,
_elements: &InteractionElements,
) -> Vec<CircleEvaluation<CpuBackend, BaseField, BitReversedOrder>> {
vec![]
}

fn to_air_prover(&self) -> impl AirProver<CpuBackend> {
self.clone()
}

fn composition_log_degree_bound(&self) -> u32 {
self.component.max_constraint_log_degree_bound()
}
}

impl AirProver<CpuBackend> for RangeCheckAir {
fn prover_components(&self) -> Vec<&dyn ComponentProver<CpuBackend>> {
vec![&self.component]
}
}
Loading