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

Generic Layout Trait #11

Merged
merged 1 commit into from
Jul 13, 2024
Merged
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ repository = "https://github.com/iosis-tech/cairovm-verifier"
version = "0.0.1"

[workspace.dependencies]
bail-out = "0.2.0"
serde = { version = "1.0", features = ["derive"] }
serde_with = "2.3.2"
sha3 = "0.10.8"
Expand Down
1 change: 1 addition & 0 deletions crates/air/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repository.workspace = true
version.workspace = true

[dependencies]
bail-out.workspace = true
serde.workspace = true
serde_with.workspace = true
starknet-crypto.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions crates/air/src/fixtures/commitment.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::{config, interaction_elements, unsent_commitment};
use crate::trace::Commitment;
use crate::{layout::recursive::global_values::InteractionElements, trace::Commitment};
use cairovm_verifier_commitment::{table, vector};
use starknet_crypto::Felt;

pub fn get() -> Commitment {
pub fn get() -> Commitment<InteractionElements> {
let unsent_commitment = unsent_commitment::get();
let traces_config = config::get();

Expand Down
73 changes: 73 additions & 0 deletions crates/air/src/layout/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,74 @@
use crate::{domains::StarkDomains, public_memory::PublicInput};
use cairovm_verifier_transcript::transcript::Transcript;
use starknet_crypto::Felt;

pub mod recursive;

pub trait LayoutTrait {
type InteractionElements;
fn eval_composition_polynomial(
interaction_elements: &Self::InteractionElements,
public_input: &PublicInput,
mask_values: &[Felt],
constraint_coefficients: &[Felt],
point: &Felt,
trace_domain_size: &Felt,
trace_generator: &Felt,
) -> Result<Felt, CompositionPolyEvalError>;

fn eval_oods_polynomial(
column_values: &[Felt],
oods_values: &[Felt],
constraint_coefficients: &[Felt],
point: &Felt,
oods_point: &Felt,
trace_generator: &Felt,
) -> Felt;

fn validate(
public_input: &PublicInput,
stark_domains: &StarkDomains,
) -> Result<(), PublicInputValidateError>;

fn traces_commit(
transcript: &mut Transcript,
unsent_commitment: &crate::trace::UnsentCommitment,
config: crate::trace::config::Config,
) -> crate::trace::Commitment<Self::InteractionElements>;

fn traces_decommit(
queries: &[Felt],
commitment: crate::trace::Commitment<Self::InteractionElements>,
decommitment: crate::trace::Decommitment,
witness: crate::trace::Witness,
) -> Result<(), crate::trace::decommit::Error>;
}

use thiserror::Error;

#[derive(Error, Debug)]
pub enum CompositionPolyEvalError {
#[error("segment not present {segment}")]
SegmentMissing { segment: usize },
}

#[derive(Error, Debug)]
pub enum PublicInputValidateError {
#[error("max steps exceeded")]
MaxSteps,

#[error("trace length invalid")]
TraceLengthInvalid,

#[error("segment not present {segment}")]
SegmentMissing { segment: usize },

#[error("layout code invalid")]
LayoutCodeInvalid,

#[error("range_check invalid")]
RangeCheckInvalid,

#[error("invalid number of builtin uses")]
UsesInvalid,
}
12 changes: 6 additions & 6 deletions crates/air/src/layout/recursive/autogenerated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use starknet_crypto::Felt;
pub fn eval_composition_polynomial_inner(
mask_values: &[Felt],
constraint_coefficients: &[Felt],
point: Felt,
trace_generator: Felt,
global_values: GlobalValues,
point: &Felt,
trace_generator: &Felt,
global_values: &GlobalValues,
) -> Felt {
// Compute powers.
let pow0 = point.pow_felt(
Expand Down Expand Up @@ -866,9 +866,9 @@ pub fn eval_oods_polynomial_inner(
column_values: &[Felt],
oods_values: &[Felt],
constraint_coefficients: &[Felt],
point: Felt,
oods_point: Felt,
trace_generator: Felt,
point: &Felt,
oods_point: &Felt,
trace_generator: &Felt,
) -> Felt {
// Compute powers.
let pow0 = trace_generator.pow(0_u128);
Expand Down
14 changes: 14 additions & 0 deletions crates/air/src/layout/recursive/global_values.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cairovm_verifier_transcript::transcript::Transcript;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use starknet_core::serde::unsigned_field_element::UfeHex;
Expand Down Expand Up @@ -92,3 +93,16 @@ pub struct InteractionElements {
#[serde_as(as = "UfeHex")]
pub diluted_check_interaction_alpha: Felt,
}

impl InteractionElements {
pub fn new(transcript: &mut Transcript) -> Self {
Self {
memory_multi_column_perm_perm_interaction_elm: transcript.random_felt_to_prover(),
memory_multi_column_perm_hash_interaction_elm0: transcript.random_felt_to_prover(),
range_check16_perm_interaction_elm: transcript.random_felt_to_prover(),
diluted_check_permutation_interaction_elm: transcript.random_felt_to_prover(),
diluted_check_interaction_z: transcript.random_felt_to_prover(),
diluted_check_interaction_alpha: transcript.random_felt_to_prover(),
}
}
}
Loading
Loading