Skip to content

Commit

Permalink
feat: verifier returns all outputs rather than their hash
Browse files Browse the repository at this point in the history
  • Loading branch information
tdelabro committed Jan 9, 2025
1 parent ccd16d3 commit 9407640
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 37 deletions.
11 changes: 6 additions & 5 deletions crates/air/src/layout/dex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ impl LayoutTrait for Layout {
Ok(())
}

fn verify_public_input(public_input: &PublicInput) -> Result<(Felt, Felt), PublicInputError> {
fn verify_public_input(
public_input: &PublicInput,
) -> Result<(Felt, Vec<Felt>), PublicInputError> {
let public_segments = &public_input.segments;

let initial_pc = public_segments
Expand Down Expand Up @@ -405,10 +407,9 @@ impl LayoutTrait for Layout {
let program_hash = pedersen_hash(&hash, &Felt::from(program.len()));

let output_len: usize = (output_stop - output_start).to_bigint().try_into()?;
let output = &memory[memory.len() - output_len * 2..];
let hash = output.iter().skip(1).step_by(2).fold(FELT_0, |acc, e| pedersen_hash(&acc, e));
let output_hash = pedersen_hash(&hash, &Felt::from(output_len));
let output =
memory[memory.len() - output_len * 2..].iter().skip(1).step_by(2).cloned().collect();

Ok((program_hash, output_hash))
Ok((program_hash, output))
}
}
11 changes: 6 additions & 5 deletions crates/air/src/layout/dynamic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,9 @@ impl LayoutTrait for Layout {
Ok(autogenerated::check_asserts(&dynamic_params, stark_domains)?)
}

fn verify_public_input(public_input: &PublicInput) -> Result<(Felt, Felt), PublicInputError> {
fn verify_public_input(
public_input: &PublicInput,
) -> Result<(Felt, Vec<Felt>), PublicInputError> {
let public_segments = &public_input.segments;

let initial_pc = public_segments
Expand Down Expand Up @@ -778,10 +780,9 @@ impl LayoutTrait for Layout {
let program_hash = pedersen_hash(&hash, &felt!(program.len()));

let output_len: usize = (output_stop - output_start).to_bigint().try_into()?;
let output = &memory[memory.len() - output_len * 2..];
let hash = output.iter().skip(1).step_by(2).fold(FELT_0, |acc, e| pedersen_hash(&acc, e));
let output_hash = pedersen_hash(&hash, &felt!(output_len));
let output =
memory[memory.len() - output_len * 2..].iter().skip(1).step_by(2).cloned().collect();

Ok((program_hash, output_hash))
Ok((program_hash, output))
}
}
5 changes: 4 additions & 1 deletion crates/air/src/layout/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{domains::StarkDomains, public_memory::PublicInput};
use alloc::vec::Vec;
use num_bigint::{BigInt, TryFromBigIntError};
use starknet_core::types::NonZeroFelt;
use starknet_crypto::Felt;
Expand Down Expand Up @@ -84,7 +85,9 @@ pub trait LayoutTrait {
witness: crate::trace::Witness,
) -> Result<(), crate::trace::decommit::Error>;

fn verify_public_input(public_input: &PublicInput) -> Result<(Felt, Felt), PublicInputError>;
fn verify_public_input(
public_input: &PublicInput,
) -> Result<(Felt, Vec<Felt>), PublicInputError>;
}

pub trait StaticLayoutTrait {
Expand Down
11 changes: 6 additions & 5 deletions crates/air/src/layout/recursive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ impl LayoutTrait for Layout {
Ok(())
}

fn verify_public_input(public_input: &PublicInput) -> Result<(Felt, Felt), PublicInputError> {
fn verify_public_input(
public_input: &PublicInput,
) -> Result<(Felt, Vec<Felt>), PublicInputError> {
let public_segments = &public_input.segments;

let initial_pc = public_segments
Expand Down Expand Up @@ -405,10 +407,9 @@ impl LayoutTrait for Layout {
let program_hash = pedersen_hash(&hash, &Felt::from(program.len()));

let output_len: usize = (output_stop - output_start).to_bigint().try_into()?;
let output = &memory[memory.len() - output_len * 2..];
let hash = output.iter().skip(1).step_by(2).fold(FELT_0, |acc, e| pedersen_hash(&acc, e));
let output_hash = pedersen_hash(&hash, &Felt::from(output_len));
let output =
memory[memory.len() - output_len * 2..].iter().skip(1).step_by(2).cloned().collect();

Ok((program_hash, output_hash))
Ok((program_hash, output))
}
}
11 changes: 6 additions & 5 deletions crates/air/src/layout/recursive_with_poseidon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,9 @@ impl LayoutTrait for Layout {
Ok(())
}

fn verify_public_input(public_input: &PublicInput) -> Result<(Felt, Felt), PublicInputError> {
fn verify_public_input(
public_input: &PublicInput,
) -> Result<(Felt, Vec<Felt>), PublicInputError> {
let public_segments = &public_input.segments;

let initial_pc = public_segments
Expand Down Expand Up @@ -462,10 +464,9 @@ impl LayoutTrait for Layout {
let program_hash = pedersen_hash(&hash, &Felt::from(program.len()));

let output_len: usize = (output_stop - output_start).to_bigint().try_into()?;
let output = &memory[memory.len() - output_len * 2..];
let hash = output.iter().skip(1).step_by(2).fold(FELT_0, |acc, e| pedersen_hash(&acc, e));
let output_hash = pedersen_hash(&hash, &Felt::from(output_len));
let output =
memory[memory.len() - output_len * 2..].iter().skip(1).step_by(2).cloned().collect();

Ok((program_hash, output_hash))
Ok((program_hash, output))
}
}
11 changes: 6 additions & 5 deletions crates/air/src/layout/small/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ impl LayoutTrait for Layout {
Ok(())
}

fn verify_public_input(public_input: &PublicInput) -> Result<(Felt, Felt), PublicInputError> {
fn verify_public_input(
public_input: &PublicInput,
) -> Result<(Felt, Vec<Felt>), PublicInputError> {
let public_segments = &public_input.segments;

let initial_pc = public_segments
Expand Down Expand Up @@ -405,10 +407,9 @@ impl LayoutTrait for Layout {
let program_hash = pedersen_hash(&hash, &Felt::from(program.len()));

let output_len: usize = (output_stop - output_start).to_bigint().try_into()?;
let output = &memory[memory.len() - output_len * 2..];
let hash = output.iter().skip(1).step_by(2).fold(FELT_0, |acc, e| pedersen_hash(&acc, e));
let output_hash = pedersen_hash(&hash, &Felt::from(output_len));
let output =
memory[memory.len() - output_len * 2..].iter().skip(1).step_by(2).cloned().collect();

Ok((program_hash, output_hash))
Ok((program_hash, output))
}
}
11 changes: 6 additions & 5 deletions crates/air/src/layout/starknet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,9 @@ impl LayoutTrait for Layout {
Ok(())
}

fn verify_public_input(public_input: &PublicInput) -> Result<(Felt, Felt), PublicInputError> {
fn verify_public_input(
public_input: &PublicInput,
) -> Result<(Felt, Vec<Felt>), PublicInputError> {
let public_segments = &public_input.segments;

let initial_pc = public_segments
Expand Down Expand Up @@ -532,10 +534,9 @@ impl LayoutTrait for Layout {
let program_hash = pedersen_hash(&hash, &Felt::from(program.len()));

let output_len: usize = (output_stop - output_start).to_bigint().try_into()?;
let output = &memory[memory.len() - output_len * 2..];
let hash = output.iter().skip(1).step_by(2).fold(FELT_0, |acc, e| pedersen_hash(&acc, e));
let output_hash = pedersen_hash(&hash, &Felt::from(output_len));
let output =
memory[memory.len() - output_len * 2..].iter().skip(1).step_by(2).cloned().collect();

Ok((program_hash, output_hash))
Ok((program_hash, output))
}
}
11 changes: 6 additions & 5 deletions crates/air/src/layout/starknet_with_keccak/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,9 @@ impl LayoutTrait for Layout {
Ok(())
}

fn verify_public_input(public_input: &PublicInput) -> Result<(Felt, Felt), PublicInputError> {
fn verify_public_input(
public_input: &PublicInput,
) -> Result<(Felt, Vec<Felt>), PublicInputError> {
let public_segments = &public_input.segments;

let initial_pc = public_segments
Expand Down Expand Up @@ -581,10 +583,9 @@ impl LayoutTrait for Layout {
let program_hash = pedersen_hash(&hash, &Felt::from(program.len()));

let output_len: usize = (output_stop - output_start).to_bigint().try_into().unwrap();
let output = &memory[memory.len() - output_len * 2..];
let hash = output.iter().skip(1).step_by(2).fold(FELT_0, |acc, e| pedersen_hash(&acc, e));
let output_hash = pedersen_hash(&hash, &Felt::from(output_len));
let output =
memory[memory.len() - output_len * 2..].iter().skip(1).step_by(2).cloned().collect();

Ok((program_hash, output_hash))
Ok((program_hash, output))
}
}
3 changes: 2 additions & 1 deletion crates/stark/src/stark.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
commit::stark_commit, queries::generate_queries, types::StarkProof, verify::stark_verify,
};
use alloc::vec::Vec;
use starknet_crypto::Felt;
use swiftness_air::{
domains::StarkDomains,
Expand All @@ -12,7 +13,7 @@ impl StarkProof {
pub fn verify<Layout: GenericLayoutTrait + LayoutTrait>(
&self,
security_bits: Felt,
) -> Result<(Felt, Felt), Error> {
) -> Result<(Felt, Vec<Felt>), Error> {
let n_original_columns =
Layout::get_num_columns_first(&self.public_input).ok_or(Error::ColumnMissing)?;
let n_interaction_columns =
Expand Down

0 comments on commit 9407640

Please sign in to comment.