Skip to content

Commit

Permalink
TraceGenerator trait (#663)
Browse files Browse the repository at this point in the history
<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/starkware-libs/stwo/663)
<!-- Reviewable:end -->
  • Loading branch information
shaharsamocha7 authored Jun 20, 2024
2 parents a150b8f + 814052c commit 6e7af35
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
7 changes: 7 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 @@ -10,6 +10,7 @@ blake2.workspace = true
blake3.workspace = true
bytemuck = { workspace = true, features = ["derive"] }
cfg-if = "1.0.0"
downcast-rs = "1.2"
educe.workspace = true
hex.workspace = true
itertools.workspace = true
Expand Down
1 change: 1 addition & 0 deletions crates/prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ pub mod core;
pub mod examples;
pub mod hash_functions;
pub mod math;
pub mod trace_generation;
36 changes: 36 additions & 0 deletions crates/prover/src/trace_generation/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use std::collections::HashMap;

use downcast_rs::{impl_downcast, Downcast};

use crate::core::backend::Backend;
use crate::core::fields::m31::BaseField;
use crate::core::poly::circle::CircleEvaluation;
use crate::core::poly::BitReversedOrder;
use crate::core::ColumnVec;

pub trait ComponentGen: Downcast {}
impl_downcast!(ComponentGen);

pub struct ComponentRegistry {
_components: HashMap<String, Box<dyn ComponentGen>>,
}

// A trait to generate a a trace.
// Generates the trace given a list of inputs collects inputs for subcomponents.
pub trait TraceGenerator<B: Backend> {
type ComponentInputs;

/// Add inputs for the trace generation of the component.
/// This function should be called from the caller components before calling `write_trace` of
/// this component.
fn add_inputs(&mut self, inputs: &Self::ComponentInputs);

/// Allocates and returns the trace of the component and updates the
/// subcomponents with the corresponding inputs.
/// Should be called only after all the inputs are available.
// TODO(ShaharS): change `component_id` to a struct that contains the id and the component name.
fn write_trace(
component_id: &str,
registry: &mut ComponentRegistry,
) -> ColumnVec<CircleEvaluation<B, BaseField, BitReversedOrder>>;
}

0 comments on commit 6e7af35

Please sign in to comment.