From 3342acfb51c5618f84dcb5ce965031831246e5b7 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Thu, 15 Feb 2024 09:12:54 -0500 Subject: [PATCH 01/30] air: `TraceInfo` no longer uses `TraceLayout` --- air/src/air/boundary/mod.rs | 4 +- air/src/air/mod.rs | 8 +- air/src/air/trace_info.rs | 311 +++++++++++++++++++++++++++++++++--- air/src/proof/context.rs | 93 +++-------- air/src/proof/mod.rs | 23 +-- 5 files changed, 316 insertions(+), 123 deletions(-) diff --git a/air/src/air/boundary/mod.rs b/air/src/air/boundary/mod.rs index d0b9156c9..877ae0e1a 100644 --- a/air/src/air/boundary/mod.rs +++ b/air/src/air/boundary/mod.rs @@ -83,8 +83,8 @@ impl BoundaryConstraints { ); let trace_length = context.trace_info.length(); - let main_trace_width = context.trace_info.layout().main_trace_width(); - let aux_trace_width = context.trace_info.layout().aux_trace_width(); + let main_trace_width = context.trace_info.main_trace_width(); + let aux_trace_width = context.trace_info.aux_trace_width(); // make sure the assertions are valid in the context of their respective trace segments; // also, sort the assertions in the deterministic order so that changing the order of diff --git a/air/src/air/mod.rs b/air/src/air/mod.rs index 6c5857af8..0d8bbe2f2 100644 --- a/air/src/air/mod.rs +++ b/air/src/air/mod.rs @@ -390,12 +390,6 @@ pub trait Air: Send + Sync { self.context().trace_info.length() } - /// Returns a description of how execution trace columns are arranged into segments for - /// an instance of a computation described by this AIR. - fn trace_layout(&self) -> &TraceLayout { - self.context().trace_info.layout() - } - /// Returns degree of trace polynomials for an instance of the computation described by /// this AIR. /// @@ -477,7 +471,7 @@ pub trait Air: Send + Sync { R: RandomCoin, { let num_elements = - self.trace_info().layout().get_aux_segment_rand_elements(aux_segment_idx); + self.trace_info().get_aux_segment_rand_elements(aux_segment_idx); let mut result = Vec::with_capacity(num_elements); for _ in 0..num_elements { result.push(public_coin.draw()?); diff --git a/air/src/air/trace_info.rs b/air/src/air/trace_info.rs index 9e5d40011..814fec5af 100644 --- a/air/src/air/trace_info.rs +++ b/air/src/air/trace_info.rs @@ -25,9 +25,12 @@ const NUM_AUX_SEGMENTS: usize = 1; /// size. #[derive(Debug, Clone, Eq, PartialEq)] pub struct TraceInfo { - layout: TraceLayout, - length: usize, - meta: Vec, + main_segment_width: usize, + aux_segment_widths: [usize; NUM_AUX_SEGMENTS], + aux_segment_rands: [usize; NUM_AUX_SEGMENTS], + num_aux_segments: usize, + trace_length: usize, + trace_meta: Vec, } impl TraceInfo { @@ -66,8 +69,7 @@ impl TraceInfo { /// * Length of `meta` is greater than 65535; pub fn with_meta(width: usize, length: usize, meta: Vec) -> Self { assert!(width > 0, "trace width must be greater than 0"); - let layout = TraceLayout::new(width, [0], [0]); - Self::new_multi_segment(layout, length, meta) + Self::new_multi_segment(width, [0], [0], length, meta) } /// Creates a new [TraceInfo] from the specified trace segment widths, length, and metadata. @@ -77,62 +79,300 @@ impl TraceInfo { /// * The width of the first trace segment is zero. /// * Total width of all trace segments is greater than 255. /// * Trace length is smaller than 8 or is not a power of two. - pub fn new_multi_segment(layout: TraceLayout, length: usize, meta: Vec) -> Self { + pub fn new_multi_segment( + main_segment_width: usize, + aux_segment_widths: [usize; NUM_AUX_SEGMENTS], + aux_segment_rands: [usize; NUM_AUX_SEGMENTS], + trace_length: usize, + trace_meta: Vec, + ) -> Self { assert!( - length >= Self::MIN_TRACE_LENGTH, + trace_length >= Self::MIN_TRACE_LENGTH, "trace length must be at least {}, but was {}", Self::MIN_TRACE_LENGTH, - length + trace_length ); assert!( - length.is_power_of_two(), - "trace length must be a power of two, but was {length}" + trace_length.is_power_of_two(), + "trace length must be a power of two, but was {trace_length}" ); assert!( - meta.len() <= Self::MAX_META_LENGTH, + trace_meta.len() <= Self::MAX_META_LENGTH, "number of metadata bytes cannot be greater than {}, but was {}", Self::MAX_META_LENGTH, - meta.len() + trace_meta.len() + ); + + // validate trace segment widths + assert!(main_segment_width > 0, "main trace segment must consist of at least one column"); + let full_width = main_segment_width + aux_segment_widths.iter().sum::(); + assert!( + full_width <= TraceInfo::MAX_TRACE_WIDTH, + "total number of columns in the trace cannot be greater than {}, but was {}", + TraceInfo::MAX_TRACE_WIDTH, + full_width ); + + // validate number of random elements required by each segment + let mut was_zero_width = false; + let mut num_aux_segments = 0; + for (&width, &num_rand_elements) in aux_segment_widths.iter().zip(aux_segment_rands.iter()) + { + if width != 0 { + assert!( + !was_zero_width, + "a non-empty trace segment cannot follow an empty segment" + ); + assert!( + num_rand_elements > 0, + "number of random elements for a non-empty trace segment must be greater than zero" + ); + num_aux_segments += 1; + } else { + assert!( + num_rand_elements == 0, + "number of random elements for an empty trace segment must be zero" + ); + was_zero_width = true; + } + assert!( + num_rand_elements <= TraceInfo::MAX_RAND_SEGMENT_ELEMENTS, + "number of random elements required by a segment cannot exceed {}, but was {}", + TraceInfo::MAX_RAND_SEGMENT_ELEMENTS, + num_rand_elements + ); + } + TraceInfo { - layout, - length, - meta, + main_segment_width, + aux_segment_widths, + aux_segment_rands, + num_aux_segments, + trace_length, + trace_meta, } } // PUBLIC ACCESSORS // -------------------------------------------------------------------------------------------- - /// Returns a description of how execution trace columns are arranged into segments. - /// - /// Currently, an execution trace can consist of at most two segments. - pub fn layout(&self) -> &TraceLayout { - &self.layout - } - /// Returns the total number of columns in an execution trace. /// /// This is guaranteed to be between 1 and 255. pub fn width(&self) -> usize { - self.layout.main_trace_width() + self.layout().aux_trace_width() + self.main_segment_width + self.aux_segment_widths[0] } /// Returns execution trace length. /// /// The length is guaranteed to be a power of two. pub fn length(&self) -> usize { - self.length + self.trace_length } /// Returns execution trace metadata. pub fn meta(&self) -> &[u8] { - &self.meta + &self.trace_meta } /// Returns true if an execution trace contains more than one segment. pub fn is_multi_segment(&self) -> bool { - self.layout.num_aux_segments > 0 + self.num_aux_segments > 0 + } + + /// Returns the number of columns in the main segment of an execution trace. + /// + /// This is guaranteed to be between 1 and 255. + pub fn main_trace_width(&self) -> usize { + self.main_segment_width + } + + /// Returns the number of columns in all auxiliary segments of an execution trace. + pub fn aux_trace_width(&self) -> usize { + self.aux_segment_widths.iter().sum() + } + + /// Returns the total number of segments in an execution trace. + pub fn num_segments(&self) -> usize { + self.num_aux_segments + 1 + } + + /// Returns the number of auxiliary trace segments in an execution trace. + pub fn num_aux_segments(&self) -> usize { + self.num_aux_segments + } + + /// Returns the number of columns in the auxiliary trace segment at the specified index. + pub fn get_aux_segment_width(&self, segment_idx: usize) -> usize { + assert!( + segment_idx < self.num_aux_segments, + "attempted to access segment index {segment_idx}, but there are only {} segments", + self.num_aux_segments + ); + + self.aux_segment_widths[segment_idx] + } + + /// Returns the number of random elements required by the auxiliary trace segment at the + /// specified index. + pub fn get_aux_segment_rand_elements(&self, segment_idx: usize) -> usize { + // TODO: panic if segment_idx is not within num_aux_segments + self.aux_segment_rands[segment_idx] + } +} + +impl ToElements for TraceInfo { + fn to_elements(&self) -> Vec { + let mut result = Vec::new(); + + // main segment width, number of auxiliary segments, and parameters of the first auxiliary + // segment (if present) go into the first field element; we assume that each parameter can + // be encoded in 8 bits (which is enforced by the constructor) + let mut buf = self.main_segment_width as u32; + buf = (buf << 8) | self.num_aux_segments as u32; + if self.num_aux_segments == 1 { + buf = (buf << 8) | self.aux_segment_widths[0] as u32; + buf = (buf << 8) | self.aux_segment_rands[0] as u32; + } + result.push(E::from(buf)); + + // parameters of all subsequent auxiliary segments go into additional elements + for i in 1..self.num_aux_segments { + buf = self.aux_segment_widths[i] as u32; + buf = (buf << 8) | self.aux_segment_rands[i] as u32; + result.push(E::from(buf)); + } + + result.push(E::from(self.trace_length as u32)); + + // convert trace metadata to elements; this is done by breaking trace metadata into chunks + // of bytes which are slightly smaller than the number of bytes needed to encode a field + // element, and then converting these chunks into field elements. + if !self.trace_meta.is_empty() { + for chunk in self.trace_meta.chunks(E::ELEMENT_BYTES - 1) { + result.push(bytes_to_element(chunk)); + } + } + + result + } +} + +impl Serializable for TraceInfo { + /// Serializes `self` and writes the resulting bytes into the `target`. + fn write_into(&self, target: &mut W) { + // store segments + target.write_u8(self.main_segment_width as u8); + for &w in self.aux_segment_widths.iter() { + debug_assert!(w <= u8::MAX as usize, "aux segment width does not fit into u8 value"); + target.write_u8(w as u8); + } + for &rc in self.aux_segment_rands.iter() { + debug_assert!( + rc <= u8::MAX as usize, + "aux segment random element count does not fit into u8 value" + ); + target.write_u8(rc as u8); + } + + // store trace length as power of two + target.write_u8(self.trace_length.ilog2() as u8); + + // store trace meta + target.write_u16(self.trace_meta.len() as u16); + target.write_bytes(&self.trace_meta); + } +} + +impl Deserializable for TraceInfo { + /// Reads [TraceLayout] from the specified `source` and returns the result. + /// + /// # Errors + /// Returns an error of a valid [TraceLayout] struct could not be read from the specified + /// `source`. + fn read_from(source: &mut R) -> Result { + let main_segment_width = source.read_u8()? as usize; + if main_segment_width == 0 { + return Err(DeserializationError::InvalidValue( + "main trace segment width must be greater than zero".to_string(), + )); + } + + // read and validate auxiliary trace segment widths + let mut was_zero_width = false; + let mut aux_segment_widths = [0; NUM_AUX_SEGMENTS]; + for width in aux_segment_widths.iter_mut() { + *width = source.read_u8()? as usize; + if *width != 0 { + if was_zero_width { + return Err(DeserializationError::InvalidValue( + "a non-empty trace segment cannot follow an empty segment".to_string(), + )); + } + } else { + was_zero_width = true; + } + } + + let full_trace_width = main_segment_width + aux_segment_widths.iter().sum::(); + if full_trace_width >= TraceInfo::MAX_TRACE_WIDTH { + return Err(DeserializationError::InvalidValue(format!( + "full trace width cannot be greater than {}, but was {}", + TraceInfo::MAX_TRACE_WIDTH, + full_trace_width + ))); + } + + // read and validate number of random elements for each auxiliary trace segment + let mut aux_segment_rands = [0; NUM_AUX_SEGMENTS]; + for (num_rand_elements, &width) in + aux_segment_rands.iter_mut().zip(aux_segment_widths.iter()) + { + *num_rand_elements = source.read_u8()? as usize; + if width == 0 && *num_rand_elements != 0 { + return Err(DeserializationError::InvalidValue( + "an empty trace segment cannot require random elements".to_string(), + )); + } else if width != 0 && *num_rand_elements == 0 { + return Err(DeserializationError::InvalidValue( + "a non-empty trace segment must require at least one random element" + .to_string(), + )); + } else if *num_rand_elements > TraceInfo::MAX_RAND_SEGMENT_ELEMENTS { + return Err(DeserializationError::InvalidValue(format!( + "number of random elements required by a segment cannot exceed {}, but was {}", + TraceInfo::MAX_RAND_SEGMENT_ELEMENTS, + *num_rand_elements + ))); + } + } + + // read and validate trace length (which was stored as a power of two) + let trace_length = source.read_u8()?; + if trace_length < TraceInfo::MIN_TRACE_LENGTH.ilog2() as u8 { + return Err(DeserializationError::InvalidValue(format!( + "trace length cannot be smaller than 2^{}, but was 2^{}", + TraceInfo::MIN_TRACE_LENGTH.ilog2(), + trace_length + ))); + } + let trace_length = 2_usize.pow(trace_length as u32); + + // read trace metadata + let num_meta_bytes = source.read_u16()? as usize; + let trace_meta = if num_meta_bytes != 0 { + source.read_vec(num_meta_bytes)? + } else { + vec![] + }; + + Ok(Self::new_multi_segment( + main_segment_width, + aux_segment_widths, + aux_segment_rands, + trace_length, + trace_meta, + )) } } @@ -375,6 +615,25 @@ impl Deserializable for TraceLayout { } } +// TODO: MERGE WITH `air::proof::context::bytes_to_elements` + +/// Converts a slice of bytes into a field element. +/// +/// Assumes that the length of `bytes` is smaller than the number of bytes needed to encode an +/// element. +#[allow(clippy::let_and_return)] +fn bytes_to_element(bytes: &[u8]) -> B { + debug_assert!(bytes.len() < B::ELEMENT_BYTES); + + let mut buf = bytes.to_vec(); + buf.resize(B::ELEMENT_BYTES, 0); + let element = match B::try_from(buf.as_slice()) { + Ok(element) => element, + Err(_) => panic!("element deserialization failed"), + }; + element +} + // TESTS // ================================================================================================ diff --git a/air/src/proof/context.rs b/air/src/proof/context.rs index a6e4bf0af..b74c494c6 100644 --- a/air/src/proof/context.rs +++ b/air/src/proof/context.rs @@ -3,7 +3,7 @@ // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. -use crate::{ProofOptions, TraceInfo, TraceLayout}; +use crate::{ProofOptions, TraceInfo}; use math::{StarkField, ToElements}; use utils::{ collections::Vec, string::ToString, ByteReader, ByteWriter, Deserializable, @@ -15,9 +15,7 @@ use utils::{ /// Basic metadata about a specific execution of a computation. #[derive(Debug, Clone, Eq, PartialEq)] pub struct Context { - trace_layout: TraceLayout, - trace_length: usize, - trace_meta: Vec, + trace_info: TraceInfo, field_modulus_bytes: Vec, options: ProofOptions, } @@ -31,7 +29,7 @@ impl Context { /// # Panics /// Panics if either trace length or the LDE domain size implied by the trace length and the /// blowup factor is greater then [u32::MAX]. - pub fn new(trace_info: &TraceInfo, options: ProofOptions) -> Self { + pub fn new(trace_info: TraceInfo, options: ProofOptions) -> Self { // TODO: return errors instead of panicking? let trace_length = trace_info.length(); @@ -41,9 +39,7 @@ impl Context { assert!(lde_domain_size <= u32::MAX as usize, "LDE domain size too big"); Context { - trace_layout: trace_info.layout().clone(), - trace_length, - trace_meta: trace_info.meta().to_vec(), + trace_info, field_modulus_bytes: B::get_modulus_le_bytes(), options, } @@ -52,29 +48,14 @@ impl Context { // PUBLIC ACCESSORS // -------------------------------------------------------------------------------------------- - /// Returns a layout describing how columns of the execution trace described by this context - /// are arranged into segments. - pub fn trace_layout(&self) -> &TraceLayout { - &self.trace_layout - } - - /// Returns execution trace length of the computation described by this context. - pub fn trace_length(&self) -> usize { - self.trace_length - } - /// Returns execution trace info for the computation described by this context. - pub fn get_trace_info(&self) -> TraceInfo { - TraceInfo::new_multi_segment( - self.trace_layout.clone(), - self.trace_length(), - self.trace_meta.clone(), - ) + pub fn get_trace_info(&self) -> &TraceInfo { + &self.trace_info } /// Returns the size of the LDE domain for the computation described by this context. pub fn lde_domain_size(&self) -> usize { - self.trace_length() * self.options.blowup_factor() + self.trace_info.length() * self.options.blowup_factor() } /// Returns modulus of the field for the computation described by this context. @@ -119,7 +100,7 @@ impl ToElements for Context { /// - trace metadata [0 or more elements]. fn to_elements(&self) -> Vec { // convert trace layout - let mut result = self.trace_layout.to_elements(); + let mut result = self.trace_info.to_elements(); // convert field modulus bytes into 2 elements let num_modulus_bytes = self.field_modulus_bytes.len(); @@ -127,18 +108,8 @@ impl ToElements for Context { result.push(bytes_to_element(m1)); result.push(bytes_to_element(m2)); - // convert proof options and trace length to elements + // convert proof options to elements result.append(&mut self.options.to_elements()); - result.push(E::from(self.trace_length as u32)); - - // convert trace metadata to elements; this is done by breaking trace metadata into chunks - // of bytes which are slightly smaller than the number of bytes needed to encode a field - // element, and then converting these chunks into field elements. - if !self.trace_meta.is_empty() { - for chunk in self.trace_meta.chunks(E::ELEMENT_BYTES - 1) { - result.push(bytes_to_element(chunk)); - } - } result } @@ -150,10 +121,7 @@ impl ToElements for Context { impl Serializable for Context { /// Serializes `self` and writes the resulting bytes into the `target`. fn write_into(&self, target: &mut W) { - self.trace_layout.write_into(target); - target.write_u8(self.trace_length.ilog2() as u8); // store as power of two - target.write_u16(self.trace_meta.len() as u16); - target.write_bytes(&self.trace_meta); + self.trace_info.write_into(target); assert!(self.field_modulus_bytes.len() < u8::MAX as usize); target.write_u8(self.field_modulus_bytes.len() as u8); target.write_bytes(&self.field_modulus_bytes); @@ -167,27 +135,8 @@ impl Deserializable for Context { /// # Errors /// Returns an error of a valid Context struct could not be read from the specified `source`. fn read_from(source: &mut R) -> Result { - // read and validate trace layout info - let trace_layout = TraceLayout::read_from(source)?; - - // read and validate trace length (which was stored as a power of two) - let trace_length = source.read_u8()?; - if trace_length < TraceInfo::MIN_TRACE_LENGTH.ilog2() as u8 { - return Err(DeserializationError::InvalidValue(format!( - "trace length cannot be smaller than 2^{}, but was 2^{}", - TraceInfo::MIN_TRACE_LENGTH.ilog2(), - trace_length - ))); - } - let trace_length = 2_usize.pow(trace_length as u32); - - // read trace metadata - let num_meta_bytes = source.read_u16()? as usize; - let trace_meta = if num_meta_bytes != 0 { - source.read_vec(num_meta_bytes)? - } else { - vec![] - }; + // read and validate trace info + let trace_info = TraceInfo::read_from(source)?; // read and validate field modulus bytes let num_modulus_bytes = source.read_u8()? as usize; @@ -202,9 +151,7 @@ impl Deserializable for Context { let options = ProofOptions::read_from(source)?; Ok(Context { - trace_layout, - trace_length, - trace_meta, + trace_info, field_modulus_bytes, options, }) @@ -237,7 +184,7 @@ fn bytes_to_element(bytes: &[u8]) -> B { #[cfg(test)] mod tests { use super::{Context, ProofOptions, ToElements, TraceInfo}; - use crate::{FieldExtension, TraceLayout}; + use crate::FieldExtension; use math::fields::f64::BaseElement; #[test] @@ -283,10 +230,14 @@ mod tests { fri_folding_factor as usize, fri_remainder_max_degree as usize, ); - let layout = - TraceLayout::new(main_width as usize, [aux_width as usize], [aux_rands as usize]); - let trace_info = TraceInfo::new_multi_segment(layout, trace_length, vec![]); - let context = Context::new::(&trace_info, options); + let trace_info = TraceInfo::new_multi_segment( + main_width as usize, + [aux_width as usize], + [aux_rands as usize], + trace_length, + vec![], + ); + let context = Context::new::(trace_info, options); assert_eq!(expected, context.to_elements()); } } diff --git a/air/src/proof/mod.rs b/air/src/proof/mod.rs index 6a7a3b3a2..d305782bb 100644 --- a/air/src/proof/mod.rs +++ b/air/src/proof/mod.rs @@ -5,7 +5,7 @@ //! Contains STARK proof struct and associated components. -use crate::{ProofOptions, TraceInfo, TraceLayout}; +use crate::{ProofOptions, TraceInfo}; use core::cmp; use crypto::Hasher; use fri::FriProof; @@ -81,19 +81,8 @@ impl StarkProof { self.context.options() } - /// Returns a layout describing how columns of the execution trace described by this context - /// are arranged into segments. - pub fn trace_layout(&self) -> &TraceLayout { - self.context.trace_layout() - } - - /// Returns trace length for the computation described by this proof. - pub fn trace_length(&self) -> usize { - self.context.trace_length() - } - /// Returns trace info for the computation described by this proof. - pub fn get_trace_info(&self) -> TraceInfo { + pub fn get_trace_info(&self) -> &TraceInfo { self.context.get_trace_info() } @@ -115,14 +104,14 @@ impl StarkProof { get_conjectured_security( self.context.options(), self.context.num_modulus_bits(), - self.trace_length(), + self.get_trace_info().length(), H::COLLISION_RESISTANCE, ) } else { get_proven_security( self.context.options(), self.context.num_modulus_bits(), - self.trace_length(), + self.get_trace_info().length(), H::COLLISION_RESISTANCE, ) } @@ -153,7 +142,7 @@ impl StarkProof { Self { context: Context::new::( - &TraceInfo::new(1, 8), + TraceInfo::new(1, 8), ProofOptions::new(1, 2, 2, FieldExtension::None, 8, 1), ), num_unique_queries: 0, @@ -195,7 +184,7 @@ impl Deserializable for StarkProof { let context = Context::read_from(source)?; let num_unique_queries = source.read_u8()?; let commitments = Commitments::read_from(source)?; - let num_trace_segments = context.trace_layout().num_segments(); + let num_trace_segments = context.get_trace_info().num_segments(); let mut trace_queries = Vec::with_capacity(num_trace_segments); for _ in 0..num_trace_segments { trace_queries.push(Queries::read_from(source)?); From 23bdeb2b451eb6e8f10b636d554a6974aa7de56b Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Thu, 15 Feb 2024 09:45:38 -0500 Subject: [PATCH 02/30] prover: propagate `TraceInfo` changes --- README.md | 2 +- examples/src/fibonacci/fib2/mod.rs | 2 +- examples/src/fibonacci/fib2/prover.rs | 4 +- examples/src/fibonacci/fib8/mod.rs | 2 +- examples/src/fibonacci/fib8/prover.rs | 2 +- examples/src/fibonacci/fib_small/mod.rs | 2 +- examples/src/fibonacci/fib_small/prover.rs | 4 +- examples/src/fibonacci/mulfib2/mod.rs | 2 +- examples/src/fibonacci/mulfib2/prover.rs | 2 +- examples/src/fibonacci/mulfib8/mod.rs | 2 +- examples/src/fibonacci/mulfib8/prover.rs | 2 +- examples/src/lamport/aggregate/mod.rs | 2 +- examples/src/lamport/aggregate/prover.rs | 2 +- examples/src/lamport/threshold/mod.rs | 2 +- examples/src/lamport/threshold/prover.rs | 2 +- examples/src/merkle/mod.rs | 2 +- examples/src/merkle/prover.rs | 4 +- examples/src/rescue/mod.rs | 2 +- examples/src/rescue/prover.rs | 4 +- examples/src/rescue_raps/mod.rs | 2 +- examples/src/rescue_raps/prover.rs | 2 +- examples/src/utils/mod.rs | 2 +- examples/src/vdf/exempt/mod.rs | 2 +- examples/src/vdf/exempt/prover.rs | 2 +- examples/src/vdf/regular/mod.rs | 2 +- examples/src/vdf/regular/prover.rs | 2 +- prover/src/channel.rs | 2 +- prover/src/constraints/evaluator/default.rs | 6 +- prover/src/lib.rs | 6 +- prover/src/trace/mod.rs | 53 +++--------- prover/src/trace/tests.rs | 4 +- prover/src/trace/trace_lde/default/mod.rs | 8 +- prover/src/trace/trace_lde/mod.rs | 4 +- prover/src/trace/trace_table.rs | 96 +++++---------------- verifier/src/channel.rs | 14 +-- verifier/src/lib.rs | 2 +- winterfell/src/lib.rs | 4 +- 37 files changed, 91 insertions(+), 168 deletions(-) diff --git a/README.md b/README.md index ffc1c5d9d..5994dc547 100644 --- a/README.md +++ b/README.md @@ -269,7 +269,7 @@ impl Prover for WorkProver { // Our public inputs consist of the first and last value in the execution trace. fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { - let last_step = trace.length() - 1; + let last_step = trace.get_info().length() - 1; PublicInputs { start: trace.get(0, 0), result: trace.get(0, last_step), diff --git a/examples/src/fibonacci/fib2/mod.rs b/examples/src/fibonacci/fib2/mod.rs index c97ef8fde..badbba85a 100644 --- a/examples/src/fibonacci/fib2/mod.rs +++ b/examples/src/fibonacci/fib2/mod.rs @@ -101,7 +101,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(self.sequence_length); - tracing::Span::current().record("steps", trace.length()); + tracing::Span::current().record("steps", trace.get_info().length()); trace }); diff --git a/examples/src/fibonacci/fib2/prover.rs b/examples/src/fibonacci/fib2/prover.rs index 83e089efb..cfcb748d4 100644 --- a/examples/src/fibonacci/fib2/prover.rs +++ b/examples/src/fibonacci/fib2/prover.rs @@ -34,7 +34,7 @@ impl FibProver { pub fn build_trace(&self, sequence_length: usize) -> TraceTable { assert!(sequence_length.is_power_of_two(), "sequence length must be a power of 2"); - let mut trace = TraceTable::new(TRACE_WIDTH, sequence_length / 2); + let mut trace = TraceTable::new_empty(TRACE_WIDTH, sequence_length / 2); trace.fill( |state| { state[0] = BaseElement::ONE; @@ -64,7 +64,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { - let last_step = trace.length() - 1; + let last_step = trace.get_info().length() - 1; trace.get(1, last_step) } diff --git a/examples/src/fibonacci/fib8/mod.rs b/examples/src/fibonacci/fib8/mod.rs index 866c4a084..c5f28a776 100644 --- a/examples/src/fibonacci/fib8/mod.rs +++ b/examples/src/fibonacci/fib8/mod.rs @@ -101,7 +101,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(self.sequence_length); - tracing::Span::current().record("steps", trace.length()); + tracing::Span::current().record("steps", trace.get_info().length()); trace }); diff --git a/examples/src/fibonacci/fib8/prover.rs b/examples/src/fibonacci/fib8/prover.rs index 026bef3db..99134bc99 100644 --- a/examples/src/fibonacci/fib8/prover.rs +++ b/examples/src/fibonacci/fib8/prover.rs @@ -79,7 +79,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { - let last_step = trace.length() - 1; + let last_step = trace.get_info().length() - 1; trace.get(1, last_step) } diff --git a/examples/src/fibonacci/fib_small/mod.rs b/examples/src/fibonacci/fib_small/mod.rs index 5b149a42f..2e32f3d65 100644 --- a/examples/src/fibonacci/fib_small/mod.rs +++ b/examples/src/fibonacci/fib_small/mod.rs @@ -116,7 +116,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(self.sequence_length); - tracing::Span::current().record("steps", trace.length()); + tracing::Span::current().record("steps", trace.get_info().length()); trace }); diff --git a/examples/src/fibonacci/fib_small/prover.rs b/examples/src/fibonacci/fib_small/prover.rs index af0a6b40d..d701c5c30 100644 --- a/examples/src/fibonacci/fib_small/prover.rs +++ b/examples/src/fibonacci/fib_small/prover.rs @@ -33,7 +33,7 @@ impl FibSmallProver { pub fn build_trace(&self, sequence_length: usize) -> TraceTable { assert!(sequence_length.is_power_of_two(), "sequence length must be a power of 2"); - let mut trace = TraceTable::new(TRACE_WIDTH, sequence_length / 2); + let mut trace = TraceTable::new_empty(TRACE_WIDTH, sequence_length / 2); trace.fill( |state| { state[0] = BaseElement::ONE; @@ -63,7 +63,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { - let last_step = trace.length() - 1; + let last_step = trace.get_info().length() - 1; trace.get(1, last_step) } diff --git a/examples/src/fibonacci/mulfib2/mod.rs b/examples/src/fibonacci/mulfib2/mod.rs index 8abf025dc..0d203cb7a 100644 --- a/examples/src/fibonacci/mulfib2/mod.rs +++ b/examples/src/fibonacci/mulfib2/mod.rs @@ -101,7 +101,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(sequence_length); - tracing::Span::current().record("steps", trace.length()); + tracing::Span::current().record("steps", trace.get_info().length()); trace }); diff --git a/examples/src/fibonacci/mulfib2/prover.rs b/examples/src/fibonacci/mulfib2/prover.rs index b68e18cd7..ced46c76e 100644 --- a/examples/src/fibonacci/mulfib2/prover.rs +++ b/examples/src/fibonacci/mulfib2/prover.rs @@ -60,7 +60,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { - let last_step = trace.length() - 1; + let last_step = trace.get_info().length() - 1; trace.get(0, last_step) } diff --git a/examples/src/fibonacci/mulfib8/mod.rs b/examples/src/fibonacci/mulfib8/mod.rs index b9763761a..ccbb8a12c 100644 --- a/examples/src/fibonacci/mulfib8/mod.rs +++ b/examples/src/fibonacci/mulfib8/mod.rs @@ -102,7 +102,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(sequence_length); - tracing::Span::current().record("steps", trace.length()); + tracing::Span::current().record("steps", trace.get_info().length()); trace }); diff --git a/examples/src/fibonacci/mulfib8/prover.rs b/examples/src/fibonacci/mulfib8/prover.rs index 744e71f91..558f547a6 100644 --- a/examples/src/fibonacci/mulfib8/prover.rs +++ b/examples/src/fibonacci/mulfib8/prover.rs @@ -72,7 +72,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { - let last_step = trace.length() - 1; + let last_step = trace.get_info().length() - 1; trace.get(6, last_step) } diff --git a/examples/src/lamport/aggregate/mod.rs b/examples/src/lamport/aggregate/mod.rs index 765c4896d..b898ba9db 100644 --- a/examples/src/lamport/aggregate/mod.rs +++ b/examples/src/lamport/aggregate/mod.rs @@ -127,7 +127,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(&self.messages, &self.signatures); - tracing::Span::current().record("steps", trace.length()); + tracing::Span::current().record("steps", trace.get_info().length()); trace }); diff --git a/examples/src/lamport/aggregate/prover.rs b/examples/src/lamport/aggregate/prover.rs index ac5dea2fa..d997b953f 100644 --- a/examples/src/lamport/aggregate/prover.rs +++ b/examples/src/lamport/aggregate/prover.rs @@ -72,7 +72,7 @@ impl LamportAggregateProver { ) -> TraceTable { // allocate memory to hold the trace table let trace_length = SIG_CYCLE_LENGTH * messages.len(); - let mut trace = TraceTable::new(TRACE_WIDTH, trace_length); + let mut trace = TraceTable::new_empty(TRACE_WIDTH, trace_length); let powers_of_two = get_power_series(TWO, 128); diff --git a/examples/src/lamport/threshold/mod.rs b/examples/src/lamport/threshold/mod.rs index 092433f07..06b4ebe3e 100644 --- a/examples/src/lamport/threshold/mod.rs +++ b/examples/src/lamport/threshold/mod.rs @@ -133,7 +133,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(&self.pub_key, self.message, &self.signatures); - tracing::Span::current().record("steps", trace.length()); + tracing::Span::current().record("steps", trace.get_info().length()); trace }); diff --git a/examples/src/lamport/threshold/prover.rs b/examples/src/lamport/threshold/prover.rs index 4cd26ef14..0a72d1891 100644 --- a/examples/src/lamport/threshold/prover.rs +++ b/examples/src/lamport/threshold/prover.rs @@ -83,7 +83,7 @@ impl LamportThresholdProver { // allocate memory to hold the trace table let num_cycles = pub_key.num_keys().next_power_of_two(); let trace_length = SIG_CYCLE_LENGTH * num_cycles; - let mut trace = TraceTable::new(TRACE_WIDTH, trace_length); + let mut trace = TraceTable::new_empty(TRACE_WIDTH, trace_length); let powers_of_two = get_power_series(TWO, 128); diff --git a/examples/src/merkle/mod.rs b/examples/src/merkle/mod.rs index d99d0dd78..dcee6180f 100644 --- a/examples/src/merkle/mod.rs +++ b/examples/src/merkle/mod.rs @@ -121,7 +121,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(self.value, &self.path, self.index); - tracing::Span::current().record("steps", trace.length()); + tracing::Span::current().record("steps", trace.get_info().length()); trace }); diff --git a/examples/src/merkle/prover.rs b/examples/src/merkle/prover.rs index d4dae42d2..0a91bb32c 100644 --- a/examples/src/merkle/prover.rs +++ b/examples/src/merkle/prover.rs @@ -38,7 +38,7 @@ impl MerkleProver { ) -> TraceTable { // allocate memory to hold the trace table let trace_length = branch.len() * HASH_CYCLE_LEN; - let mut trace = TraceTable::new(TRACE_WIDTH, trace_length); + let mut trace = TraceTable::new_empty(TRACE_WIDTH, trace_length); // skip the first node of the branch because it will be computed in the trace as hash(value) let branch = &branch[1..]; @@ -113,7 +113,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { - let last_step = trace.length() - 1; + let last_step = trace.get_info().length() - 1; PublicInputs { tree_root: [trace.get(0, last_step), trace.get(1, last_step)], } diff --git a/examples/src/rescue/mod.rs b/examples/src/rescue/mod.rs index 9f79fec96..4f18ab6d3 100644 --- a/examples/src/rescue/mod.rs +++ b/examples/src/rescue/mod.rs @@ -106,7 +106,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(self.seed, self.chain_length); - tracing::Span::current().record("steps", trace.length()); + tracing::Span::current().record("steps", trace.get_info().length()); trace }); diff --git a/examples/src/rescue/prover.rs b/examples/src/rescue/prover.rs index 4d2599062..fe452cda4 100644 --- a/examples/src/rescue/prover.rs +++ b/examples/src/rescue/prover.rs @@ -36,7 +36,7 @@ impl RescueProver { ) -> TraceTable { // allocate memory to hold the trace table let trace_length = iterations * CYCLE_LENGTH; - let mut trace = TraceTable::new(4, trace_length); + let mut trace = TraceTable::new_empty(4, trace_length); trace.fill( |state| { @@ -79,7 +79,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { - let last_step = trace.length() - 1; + let last_step = trace.get_info().length() - 1; PublicInputs { seed: [trace.get(0, 0), trace.get(1, 0)], result: [trace.get(0, last_step), trace.get(1, last_step)], diff --git a/examples/src/rescue_raps/mod.rs b/examples/src/rescue_raps/mod.rs index 33828eca1..d18b3ac29 100644 --- a/examples/src/rescue_raps/mod.rs +++ b/examples/src/rescue_raps/mod.rs @@ -119,7 +119,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(&self.seeds, &self.permuted_seeds, self.result); - tracing::Span::current().record("steps", trace.length()); + tracing::Span::current().record("steps", trace.get_info().length()); trace }); diff --git a/examples/src/rescue_raps/prover.rs b/examples/src/rescue_raps/prover.rs index 021f02319..bb3eb175b 100644 --- a/examples/src/rescue_raps/prover.rs +++ b/examples/src/rescue_raps/prover.rs @@ -107,7 +107,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { - let last_step = trace.length() - 1; + let last_step = trace.get_info().length() - 1; PublicInputs { result: [ [trace.get(0, last_step), trace.get(1, last_step)], diff --git a/examples/src/utils/mod.rs b/examples/src/utils/mod.rs index 3fecfa6e9..6e2bb2702 100644 --- a/examples/src/utils/mod.rs +++ b/examples/src/utils/mod.rs @@ -67,7 +67,7 @@ pub fn print_trace( let trace_width = trace.width(); let mut state = vec![E::ZERO; trace_width]; - for i in 0..trace.length() { + for i in 0..trace.get_info().length() { if (i.wrapping_sub(offset)) % multiples_of != 0 { continue; } diff --git a/examples/src/vdf/exempt/mod.rs b/examples/src/vdf/exempt/mod.rs index 66bef4f22..f1f1b6379 100644 --- a/examples/src/vdf/exempt/mod.rs +++ b/examples/src/vdf/exempt/mod.rs @@ -97,7 +97,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = VdfProver::::build_trace(self.seed, self.num_steps + 1); - tracing::Span::current().record("steps", trace.length()); + tracing::Span::current().record("steps", trace.get_info().length()); trace }); diff --git a/examples/src/vdf/exempt/prover.rs b/examples/src/vdf/exempt/prover.rs index 9a83ff501..2e1ec1f3e 100644 --- a/examples/src/vdf/exempt/prover.rs +++ b/examples/src/vdf/exempt/prover.rs @@ -62,7 +62,7 @@ where fn get_pub_inputs(&self, trace: &Self::Trace) -> VdfInputs { // the result is read from the second to last step because the last last step contains // garbage - let second_to_last_step = trace.length() - 2; + let second_to_last_step = trace.get_info().length() - 2; VdfInputs { seed: trace.get(0, 0), result: trace.get(0, second_to_last_step), diff --git a/examples/src/vdf/regular/mod.rs b/examples/src/vdf/regular/mod.rs index 8b8ffb08c..76a4b3c04 100644 --- a/examples/src/vdf/regular/mod.rs +++ b/examples/src/vdf/regular/mod.rs @@ -94,7 +94,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = VdfProver::::build_trace(self.seed, self.num_steps); - tracing::Span::current().record("steps", trace.length()); + tracing::Span::current().record("steps", trace.get_info().length()); trace }); diff --git a/examples/src/vdf/regular/prover.rs b/examples/src/vdf/regular/prover.rs index e899ec3be..60e9eef9d 100644 --- a/examples/src/vdf/regular/prover.rs +++ b/examples/src/vdf/regular/prover.rs @@ -57,7 +57,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> VdfInputs { - let last_step = trace.length() - 1; + let last_step = trace.get_info().length() - 1; VdfInputs { seed: trace.get(0, 0), result: trace.get(0, last_step), diff --git a/prover/src/channel.rs b/prover/src/channel.rs index dd411f5bc..ef5c0fa25 100644 --- a/prover/src/channel.rs +++ b/prover/src/channel.rs @@ -49,7 +49,7 @@ where // -------------------------------------------------------------------------------------------- /// Creates a new prover channel for the specified `air` and public inputs. pub fn new(air: &'a A, mut pub_inputs_elements: Vec) -> Self { - let context = Context::new::(air.trace_info(), air.options().clone()); + let context = Context::new::(air.trace_info().clone(), air.options().clone()); // build a seed for the public coin; the initial seed is a hash of the proof context and // the public inputs, but as the protocol progresses, the coin will be reseeded with the diff --git a/prover/src/constraints/evaluator/default.rs b/prover/src/constraints/evaluator/default.rs index ea47b1a52..ff0ec0d5f 100644 --- a/prover/src/constraints/evaluator/default.rs +++ b/prover/src/constraints/evaluator/default.rs @@ -161,7 +161,7 @@ where fragment: &mut EvaluationTableFragment, ) { // initialize buffers to hold trace values and evaluation results at each step; - let mut main_frame = EvaluationFrame::new(trace.trace_layout().main_trace_width()); + let mut main_frame = EvaluationFrame::new(trace.trace_info().main_trace_width()); let mut evaluations = vec![E::ZERO; fragment.num_columns()]; let mut t_evaluations = vec![E::BaseField::ZERO; self.num_main_transition_constraints()]; @@ -212,8 +212,8 @@ where fragment: &mut EvaluationTableFragment, ) { // initialize buffers to hold trace values and evaluation results at each step - let mut main_frame = EvaluationFrame::new(trace.trace_layout().main_trace_width()); - let mut aux_frame = EvaluationFrame::new(trace.trace_layout().aux_trace_width()); + let mut main_frame = EvaluationFrame::new(trace.trace_info().main_trace_width()); + let mut aux_frame = EvaluationFrame::new(trace.trace_info().aux_trace_width()); let mut tm_evaluations = vec![E::BaseField::ZERO; self.num_main_transition_constraints()]; let mut ta_evaluations = vec![E::ZERO; self.num_aux_transition_constraints()]; let mut evaluations = vec![E::ZERO; fragment.num_columns()]; diff --git a/prover/src/lib.rs b/prover/src/lib.rs index 230835c65..f2163045d 100644 --- a/prover/src/lib.rs +++ b/prover/src/lib.rs @@ -241,7 +241,7 @@ pub trait Prover { // create an instance of AIR for the provided parameters. this takes a generic description // of the computation (provided via AIR type), and creates a description of a specific // execution of the computation for the provided public inputs. - let air = Self::Air::new(trace.get_info(), pub_inputs, self.options().clone()); + let air = Self::Air::new(trace.get_info().clone(), pub_inputs, self.options().clone()); // create a channel which is used to simulate interaction between the prover and the // verifier; the channel will be used to commit to values and to draw randomness that @@ -283,8 +283,8 @@ pub trait Prover { // commitment and trace polynomial table structs let mut aux_trace_segments = Vec::new(); let mut aux_trace_rand_elements = AuxTraceRandElements::new(); - for i in 0..trace.layout().num_aux_segments() { - let num_columns = trace.layout().get_aux_segment_width(i); + for i in 0..trace.get_info().num_aux_segments() { + let num_columns = trace.get_info().get_aux_segment_width(i); let (aux_segment, rand_elements) = { let _ = info_span!("build_aux_trace_segment", num_columns).entered(); diff --git a/prover/src/trace/mod.rs b/prover/src/trace/mod.rs index df835697f..f47c80936 100644 --- a/prover/src/trace/mod.rs +++ b/prover/src/trace/mod.rs @@ -4,7 +4,7 @@ // LICENSE file in the root directory of this source tree. use super::{matrix::MultiColumnIter, ColMatrix}; -use air::{Air, AuxTraceRandElements, EvaluationFrame, TraceInfo, TraceLayout}; +use air::{Air, AuxTraceRandElements, EvaluationFrame, TraceInfo}; use math::{polynom, FieldElement, StarkField}; mod trace_lde; @@ -43,15 +43,8 @@ pub trait Trace: Sized { // REQUIRED METHODS // -------------------------------------------------------------------------------------------- - - /// Returns a description of how columns of this trace are arranged into trace segments. - fn layout(&self) -> &TraceLayout; - - /// Returns the number of rows in this trace. - fn length(&self) -> usize; - - /// Returns metadata associated with this trace. - fn meta(&self) -> &[u8]; + /// Returns trace info for this trace. + fn get_info(&self) -> &TraceInfo; /// Returns a reference to a [Matrix] describing the main segment of this trace. fn main_segment(&self) -> &ColMatrix; @@ -72,24 +65,6 @@ pub trait Trace: Sized { /// Reads an evaluation frame from the main trace segment at the specified row. fn read_main_frame(&self, row_idx: usize, frame: &mut EvaluationFrame); - // PROVIDED METHODS - // -------------------------------------------------------------------------------------------- - - /// Returns trace info for this trace. - fn get_info(&self) -> TraceInfo { - TraceInfo::new_multi_segment(self.layout().clone(), self.length(), self.meta().to_vec()) - } - - /// Returns the number of columns in the main segment of this trace. - fn main_trace_width(&self) -> usize { - self.layout().main_trace_width() - } - - /// Returns the number of columns in all auxiliary trace segments. - fn aux_trace_width(&self) -> usize { - self.layout().aux_trace_width() - } - // VALIDATION // -------------------------------------------------------------------------------------------- /// Checks if this trace is valid against the specified AIR, and panics if not. @@ -106,18 +81,18 @@ pub trait Trace: Sized { { // make sure the width align; if they don't something went terribly wrong assert_eq!( - self.main_trace_width(), - air.trace_layout().main_trace_width(), + self.get_info().main_trace_width(), + air.trace_info().main_trace_width(), "inconsistent trace width: expected {}, but was {}", - self.main_trace_width(), - air.trace_layout().main_trace_width(), + self.get_info().main_trace_width(), + air.trace_info().main_trace_width(), ); // --- 1. make sure the assertions are valid ---------------------------------------------- // first, check assertions against the main segment of the execution trace for assertion in air.get_assertions() { - assertion.apply(self.length(), |step, value| { + assertion.apply(self.get_info().length(), |step, value| { assert!( value == self.main_segment().get(assertion.column(), step), "trace does not satisfy assertion main_trace({}, {}) == {}", @@ -134,8 +109,8 @@ pub trait Trace: Sized { // column index in the context of this segment let mut column_idx = assertion.column(); let mut segment_idx = 0; - for i in 0..self.layout().num_aux_segments() { - let segment_width = self.layout().get_aux_segment_width(i); + for i in 0..self.get_info().num_aux_segments() { + let segment_width = self.get_info().get_aux_segment_width(i); if column_idx < segment_width { segment_idx = i; break; @@ -144,7 +119,7 @@ pub trait Trace: Sized { } // get the matrix and verify the assertion against it - assertion.apply(self.length(), |step, value| { + assertion.apply(self.get_info().length(), |step, value| { assert!( value == aux_segments[segment_idx].get(column_idx, step), "trace does not satisfy assertion aux_trace({}, {}) == {}", @@ -164,9 +139,9 @@ pub trait Trace: Sized { // initialize buffers to hold evaluation frames and results of constraint evaluations let mut x = Self::BaseField::ONE; - let mut main_frame = EvaluationFrame::new(self.main_trace_width()); + let mut main_frame = EvaluationFrame::new(self.get_info().main_trace_width()); let mut aux_frame = if air.trace_info().is_multi_segment() { - Some(EvaluationFrame::::new(self.aux_trace_width())) + Some(EvaluationFrame::::new(self.get_info().aux_trace_width())) } else { None }; @@ -176,7 +151,7 @@ pub trait Trace: Sized { // we check transition constraints on all steps except the last k steps, where k is the // number of steps exempt from transition constraints (guaranteed to be at least 1) - for step in 0..self.length() - air.context().num_transition_exemptions() { + for step in 0..self.get_info().length() - air.context().num_transition_exemptions() { // build periodic values for (p, v) in periodic_values_polys.iter().zip(periodic_values.iter_mut()) { let num_cycles = air.trace_length() / p.len(); diff --git a/prover/src/trace/tests.rs b/prover/src/trace/tests.rs index 29460705b..757904208 100644 --- a/prover/src/trace/tests.rs +++ b/prover/src/trace/tests.rs @@ -12,8 +12,8 @@ fn new_trace_table() { let trace_length = 8; let trace = build_fib_trace(trace_length * 2); - assert_eq!(2, trace.main_trace_width()); - assert_eq!(8, trace.length()); + assert_eq!(2, trace.get_info().main_trace_width()); + assert_eq!(8, trace.get_info().length()); let expected: Vec = vec![1u32, 2, 5, 13, 34, 89, 233, 610] .into_iter() diff --git a/prover/src/trace/trace_lde/default/mod.rs b/prover/src/trace/trace_lde/default/mod.rs index e742d2dfb..6fdba625d 100644 --- a/prover/src/trace/trace_lde/default/mod.rs +++ b/prover/src/trace/trace_lde/default/mod.rs @@ -5,7 +5,7 @@ use super::{ ColMatrix, ElementHasher, EvaluationFrame, FieldElement, Hasher, Queries, StarkDomain, - TraceInfo, TraceLayout, TraceLde, TracePolyTable, Vec, + TraceInfo, TraceLde, TracePolyTable, Vec, }; use crate::{RowMatrix, DEFAULT_SEGMENT_WIDTH}; use crypto::MerkleTree; @@ -127,7 +127,7 @@ where // check errors assert!( - self.aux_segment_ldes.len() < self.trace_info.layout().num_aux_segments(), + self.aux_segment_ldes.len() < self.trace_info.num_aux_segments(), "the specified number of auxiliary segments has already been added" ); assert_eq!( @@ -203,8 +203,8 @@ where } /// Returns the trace layout of the execution trace. - fn trace_layout(&self) -> &TraceLayout { - self.trace_info.layout() + fn trace_info(&self) -> &TraceInfo { + &self.trace_info } } diff --git a/prover/src/trace/trace_lde/mod.rs b/prover/src/trace/trace_lde/mod.rs index 6228e5473..c54c947c0 100644 --- a/prover/src/trace/trace_lde/mod.rs +++ b/prover/src/trace/trace_lde/mod.rs @@ -5,7 +5,7 @@ use super::{ColMatrix, EvaluationFrame, FieldElement, TracePolyTable}; use crate::StarkDomain; -use air::{proof::Queries, TraceInfo, TraceLayout}; +use air::{proof::Queries, TraceInfo}; use crypto::{ElementHasher, Hasher}; use utils::collections::Vec; @@ -67,5 +67,5 @@ pub trait TraceLde: Sync { fn blowup(&self) -> usize; /// Returns the trace layout of the execution trace. - fn trace_layout(&self) -> &TraceLayout; + fn trace_info(&self) -> &TraceInfo; } diff --git a/prover/src/trace/trace_table.rs b/prover/src/trace/trace_table.rs index 097e908a6..c5b3f8858 100644 --- a/prover/src/trace/trace_table.rs +++ b/prover/src/trace/trace_table.rs @@ -4,7 +4,7 @@ // LICENSE file in the root directory of this source tree. use super::{ColMatrix, Trace}; -use air::{EvaluationFrame, TraceInfo, TraceLayout}; +use air::{EvaluationFrame, TraceInfo}; use math::{FieldElement, StarkField}; use utils::{collections::Vec, uninit_vector}; @@ -61,9 +61,8 @@ const MIN_FRAGMENT_LENGTH: usize = 2; /// semantics of the [TraceTable::fill()] method. #[derive(Debug, Clone)] pub struct TraceTable { - layout: TraceLayout, + info: TraceInfo, trace: ColMatrix, - meta: Vec, } impl TraceTable { @@ -80,8 +79,8 @@ impl TraceTable { /// * `width` is zero or greater than 255. /// * `length` is smaller than 8, greater than biggest multiplicative subgroup in the field /// `B`, or is not a power of two. - pub fn new(width: usize, length: usize) -> Self { - Self::with_meta(width, length, vec![]) + pub fn new_empty(width: usize, length: usize) -> Self { + Self::new_empty_with_meta(width, length, vec![]) } /// Creates a new execution trace of the specified width and length, and with the specified @@ -96,39 +95,20 @@ impl TraceTable { /// * `length` is smaller than 8, greater than the biggest multiplicative subgroup in the /// field `B`, or is not a power of two. /// * Length of `meta` is greater than 65535; - pub fn with_meta(width: usize, length: usize, meta: Vec) -> Self { - assert!(width > 0, "execution trace must consist of at least one column"); - assert!( - width <= TraceInfo::MAX_TRACE_WIDTH, - "execution trace width cannot be greater than {}, but was {}", - TraceInfo::MAX_TRACE_WIDTH, - width - ); - assert!( - length >= TraceInfo::MIN_TRACE_LENGTH, - "execution trace must be at least {} steps long, but was {}", - TraceInfo::MIN_TRACE_LENGTH, - length - ); - assert!(length.is_power_of_two(), "execution trace length must be a power of 2"); + pub fn new_empty_with_meta(width: usize, length: usize, meta: Vec) -> Self { + let info = TraceInfo::with_meta(width, length, meta); assert!( length.ilog2() <= B::TWO_ADICITY, "execution trace length cannot exceed 2^{} steps, but was 2^{}", B::TWO_ADICITY, length.ilog2() ); - assert!( - meta.len() <= TraceInfo::MAX_META_LENGTH, - "number of metadata bytes cannot be greater than {}, but was {}", - TraceInfo::MAX_META_LENGTH, - meta.len() - ); let columns = unsafe { (0..width).map(|_| uninit_vector(length)).collect() }; + Self { - layout: TraceLayout::new(width, [0], [0]), + info, trace: ColMatrix::new(columns), - meta, } } @@ -142,34 +122,24 @@ impl TraceTable { /// * Number of elements is not identical for all columns. pub fn init(columns: Vec>) -> Self { assert!(!columns.is_empty(), "execution trace must consist of at least one column"); - assert!( - columns.len() <= TraceInfo::MAX_TRACE_WIDTH, - "execution trace width cannot be greater than {}, but was {}", - TraceInfo::MAX_TRACE_WIDTH, - columns.len() - ); + let trace_length = columns[0].len(); - assert!( - trace_length >= TraceInfo::MIN_TRACE_LENGTH, - "execution trace must be at least {} steps long, but was {}", - TraceInfo::MIN_TRACE_LENGTH, - trace_length - ); - assert!(trace_length.is_power_of_two(), "execution trace length must be a power of 2"); + let info = TraceInfo::with_meta(columns.len(), trace_length, Vec::new()); + assert!( trace_length.ilog2() <= B::TWO_ADICITY, "execution trace length cannot exceed 2^{} steps, but was 2^{}", B::TWO_ADICITY, trace_length.ilog2() ); + for column in columns.iter().skip(1) { assert_eq!(column.len(), trace_length, "all columns traces must have the same length"); } Self { - layout: TraceLayout::new(columns.len(), [0], [0]), + info, trace: ColMatrix::new(columns), - meta: vec![], } } @@ -187,20 +157,6 @@ impl TraceTable { self.trace.set(column, step, value) } - /// Updates metadata for this execution trace to the specified vector of bytes. - /// - /// # Panics - /// Panics if the length of `meta` is greater than 65535; - pub fn set_meta(&mut self, meta: Vec) { - assert!( - meta.len() <= TraceInfo::MAX_META_LENGTH, - "number of metadata bytes cannot be greater than {}, but was {}", - TraceInfo::MAX_META_LENGTH, - meta.len() - ); - self.meta = meta - } - /// Fill all rows in the execution trace. /// /// The rows are filled by executing the provided closures as follows: @@ -217,11 +173,11 @@ impl TraceTable { I: FnOnce(&mut [B]), U: FnMut(usize, &mut [B]), { - let mut state = vec![B::ZERO; self.main_trace_width()]; + let mut state = vec![B::ZERO; self.info.main_trace_width()]; init(&mut state); self.update_row(0, &state); - for i in 0..self.length() - 1 { + for i in 0..self.info.length() - 1 { update(i, &mut state); self.update_row(i + 1, &state); } @@ -272,13 +228,13 @@ impl TraceTable { "fragment length must be at least {MIN_FRAGMENT_LENGTH}, but was {fragment_length}" ); assert!( - fragment_length <= self.length(), + fragment_length <= self.info.length(), "length of a fragment cannot exceed {}, but was {}", - self.length(), + self.info.length(), fragment_length ); assert!(fragment_length.is_power_of_two(), "fragment length must be a power of 2"); - let num_fragments = self.length() / fragment_length; + let num_fragments = self.info.length() / fragment_length; let mut fragment_data = (0..num_fragments).map(|_| Vec::new()).collect::>(); self.trace.columns_mut().for_each(|column| { @@ -303,7 +259,7 @@ impl TraceTable { /// Returns the number of columns in this execution trace. pub fn width(&self) -> usize { - self.main_trace_width() + self.info.main_trace_width() } /// Returns the entire trace column at the specified index. @@ -328,20 +284,12 @@ impl TraceTable { impl Trace for TraceTable { type BaseField = B; - fn layout(&self) -> &TraceLayout { - &self.layout - } - - fn length(&self) -> usize { - self.trace.num_rows() - } - - fn meta(&self) -> &[u8] { - &self.meta + fn get_info(&self) -> &TraceInfo { + &self.info } fn read_main_frame(&self, row_idx: usize, frame: &mut EvaluationFrame) { - let next_row_idx = (row_idx + 1) % self.length(); + let next_row_idx = (row_idx + 1) % self.info.length(); self.trace.read_row_into(row_idx, frame.current_mut()); self.trace.read_row_into(next_row_idx, frame.next_mut()); } diff --git a/verifier/src/channel.rs b/verifier/src/channel.rs index 99120b4b5..448b9bdff 100644 --- a/verifier/src/channel.rs +++ b/verifier/src/channel.rs @@ -66,9 +66,9 @@ impl> VerifierChanne } let constraint_frame_width = air.context().num_constraint_composition_columns(); - let num_trace_segments = air.trace_layout().num_segments(); - let main_trace_width = air.trace_layout().main_trace_width(); - let aux_trace_width = air.trace_layout().aux_trace_width(); + let num_trace_segments = air.trace_info().num_segments(); + let main_trace_width = air.trace_info().main_trace_width(); + let aux_trace_width = air.trace_info().aux_trace_width(); let lde_domain_size = air.lde_domain_size(); let fri_options = air.options().to_fri_options(); @@ -248,15 +248,15 @@ impl> TraceQueries Result { assert_eq!( queries.len(), - air.trace_layout().num_segments(), + air.trace_info().num_segments(), "expected {} trace segment queries, but received {}", - air.trace_layout().num_segments(), + air.trace_info().num_segments(), queries.len() ); // parse main trace segment queries; parsing also validates that hashes of each table row // form the leaves of Merkle authentication paths in the proofs - let main_segment_width = air.trace_layout().main_trace_width(); + let main_segment_width = air.trace_info().main_trace_width(); let main_segment_queries = queries.remove(0); let (main_segment_query_proofs, main_segment_states) = main_segment_queries .parse::(air.lde_domain_size(), num_queries, main_segment_width) @@ -275,7 +275,7 @@ impl> TraceQueries(air.lde_domain_size(), num_queries, segment_width) .map_err(|err| { diff --git a/verifier/src/lib.rs b/verifier/src/lib.rs index 31f3df284..510eee1c0 100644 --- a/verifier/src/lib.rs +++ b/verifier/src/lib.rs @@ -103,7 +103,7 @@ where public_coin_seed.append(&mut pub_inputs.to_elements()); // create AIR instance for the computation specified in the proof - let air = AIR::new(proof.get_trace_info(), pub_inputs, proof.options().clone()); + let air = AIR::new(proof.get_trace_info().clone(), pub_inputs, proof.options().clone()); // figure out which version of the generic proof verification procedure to run. this is a sort // of static dispatch for selecting two generic parameter: extension field and hash function. diff --git a/winterfell/src/lib.rs b/winterfell/src/lib.rs index 19394c18b..12c4b8c13 100644 --- a/winterfell/src/lib.rs +++ b/winterfell/src/lib.rs @@ -349,7 +349,7 @@ //! //! // Our public inputs consist of the first and last value in the execution trace. //! fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { -//! let last_step = trace.length() - 1; +//! let last_step = trace.get_info().length() - 1; //! PublicInputs { //! start: trace.get(0, 0), //! result: trace.get(0, last_step), @@ -488,7 +488,7 @@ //! # DefaultConstraintEvaluator<'a, Self::Air, E>; //! # //! # fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { -//! # let last_step = trace.length() - 1; +//! # let last_step = trace.get_info().length() - 1; //! # PublicInputs { //! # start: trace.get(0, 0), //! # result: trace.get(0, last_step), From ebb1ced4805d06a04d2d241c38339ce2167e1b2c Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Thu, 15 Feb 2024 09:53:58 -0500 Subject: [PATCH 03/30] examples: propagate change --- air/src/air/mod.rs | 3 +- .../src/rescue_raps/custom_trace_table.rs | 32 +++++++------------ 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/air/src/air/mod.rs b/air/src/air/mod.rs index 0d8bbe2f2..98753dec3 100644 --- a/air/src/air/mod.rs +++ b/air/src/air/mod.rs @@ -470,8 +470,7 @@ pub trait Air: Send + Sync { E: FieldElement, R: RandomCoin, { - let num_elements = - self.trace_info().get_aux_segment_rand_elements(aux_segment_idx); + let num_elements = self.trace_info().get_aux_segment_rand_elements(aux_segment_idx); let mut result = Vec::with_capacity(num_elements); for _ in 0..num_elements { result.push(public_coin.draw()?); diff --git a/examples/src/rescue_raps/custom_trace_table.rs b/examples/src/rescue_raps/custom_trace_table.rs index ec0f65c2b..bc96123db 100644 --- a/examples/src/rescue_raps/custom_trace_table.rs +++ b/examples/src/rescue_raps/custom_trace_table.rs @@ -7,7 +7,7 @@ use core_utils::{collections::Vec, uninit_vector}; use winterfell::{ math::{FieldElement, StarkField}, matrix::ColMatrix, - EvaluationFrame, Trace, TraceInfo, TraceLayout, + EvaluationFrame, Trace, TraceInfo, }; // RAP TRACE TABLE @@ -29,9 +29,8 @@ use winterfell::{ /// This function work just like [RapTraceTable::new()] function, but also takes a metadata /// parameter which can be an arbitrary sequence of bytes up to 64KB in size. pub struct RapTraceTable { - layout: TraceLayout, + info: TraceInfo, trace: ColMatrix, - meta: Vec, } impl RapTraceTable { @@ -94,9 +93,8 @@ impl RapTraceTable { let columns = unsafe { (0..width).map(|_| uninit_vector(length)).collect() }; Self { - layout: TraceLayout::new(width, [3], [3]), + info: TraceInfo::new_multi_segment(width, [3], [3], length, meta), trace: ColMatrix::new(columns), - meta, } } @@ -119,11 +117,11 @@ impl RapTraceTable { I: Fn(&mut [B]), U: Fn(usize, &mut [B]), { - let mut state = vec![B::ZERO; self.main_trace_width()]; + let mut state = vec![B::ZERO; self.info.main_trace_width()]; init(&mut state); self.update_row(0, &state); - for i in 0..self.length() - 1 { + for i in 0..self.info.length() - 1 { update(i, &mut state); self.update_row(i + 1, &state); } @@ -139,7 +137,7 @@ impl RapTraceTable { /// Returns the number of columns in this execution trace. pub fn width(&self) -> usize { - self.main_trace_width() + self.info.main_trace_width() } /// Returns value of the cell in the specified column at the specified row of this trace. @@ -159,20 +157,12 @@ impl RapTraceTable { impl Trace for RapTraceTable { type BaseField = B; - fn layout(&self) -> &TraceLayout { - &self.layout - } - - fn length(&self) -> usize { - self.trace.num_rows() - } - - fn meta(&self) -> &[u8] { - &self.meta + fn get_info(&self) -> &TraceInfo { + &self.info } fn read_main_frame(&self, row_idx: usize, frame: &mut EvaluationFrame) { - let next_row_idx = (row_idx + 1) % self.length(); + let next_row_idx = (row_idx + 1) % self.info.length(); self.trace.read_row_into(row_idx, frame.current_mut()); self.trace.read_row_into(next_row_idx, frame.next_mut()); } @@ -197,7 +187,7 @@ impl Trace for RapTraceTable { let mut current_row = unsafe { uninit_vector(self.width()) }; let mut next_row = unsafe { uninit_vector(self.width()) }; self.read_row_into(0, &mut current_row); - let mut aux_columns = vec![vec![E::ZERO; self.length()]; self.aux_trace_width()]; + let mut aux_columns = vec![vec![E::ZERO; self.info.length()]; self.info.aux_trace_width()]; // Columns storing the copied values for the permutation argument are not necessary, but // help understanding the construction of RAPs and are kept for illustrative purposes. @@ -209,7 +199,7 @@ impl Trace for RapTraceTable { // Permutation argument column aux_columns[2][0] = E::ONE; - for index in 1..self.length() { + for index in 1..self.info.length() { // At every last step before a new hash iteration, // copy the permuted values into the auxiliary columns if (index % super::CYCLE_LENGTH) == super::NUM_HASH_ROUNDS { From 606a0fff1e709874e167849ad59fc31ba820dab0 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Thu, 15 Feb 2024 10:00:49 -0500 Subject: [PATCH 04/30] fix context serialization test --- air/src/proof/context.rs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/air/src/proof/context.rs b/air/src/proof/context.rs index b74c494c6..21702f8c2 100644 --- a/air/src/proof/context.rs +++ b/air/src/proof/context.rs @@ -197,7 +197,6 @@ mod tests { let num_queries = 30; let main_width = 20; - let num_aux_segments = 1; let aux_width = 9; let aux_rands = 12; let trace_length = 4096; @@ -209,18 +208,27 @@ mod tests { 0, ]); - let layout_info = u32::from_le_bytes([aux_rands, aux_width, num_aux_segments, main_width]); - - let expected = vec![ - BaseElement::from(layout_info), - BaseElement::from(1_u32), // lower bits of field modulus - BaseElement::from(u32::MAX), // upper bits of field modulus - BaseElement::from(ext_fri), - BaseElement::from(grinding_factor), - BaseElement::from(blowup_factor as u32), - BaseElement::from(num_queries as u32), - BaseElement::from(trace_length as u32), - ]; + let expected = { + let trace_info = TraceInfo::new_multi_segment( + main_width, + [aux_width], + [aux_rands], + trace_length, + Vec::new(), + ); + + let mut expected = trace_info.to_elements(); + expected.extend(vec![ + BaseElement::from(1_u32), // lower bits of field modulus + BaseElement::from(u32::MAX), // upper bits of field modulus + BaseElement::from(ext_fri), + BaseElement::from(grinding_factor), + BaseElement::from(blowup_factor as u32), + BaseElement::from(num_queries as u32), + ]); + + expected + }; let options = ProofOptions::new( num_queries, From 1076a7d911a3d896bf4b84f2eadad80726bf4d70 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Thu, 15 Feb 2024 10:00:59 -0500 Subject: [PATCH 05/30] revert `TraceTable` name changes --- examples/src/fibonacci/fib2/prover.rs | 2 +- examples/src/fibonacci/fib_small/prover.rs | 2 +- examples/src/lamport/aggregate/prover.rs | 2 +- examples/src/lamport/threshold/prover.rs | 2 +- examples/src/merkle/prover.rs | 2 +- examples/src/rescue/prover.rs | 2 +- prover/src/trace/trace_table.rs | 6 +++--- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/src/fibonacci/fib2/prover.rs b/examples/src/fibonacci/fib2/prover.rs index cfcb748d4..09de4ed40 100644 --- a/examples/src/fibonacci/fib2/prover.rs +++ b/examples/src/fibonacci/fib2/prover.rs @@ -34,7 +34,7 @@ impl FibProver { pub fn build_trace(&self, sequence_length: usize) -> TraceTable { assert!(sequence_length.is_power_of_two(), "sequence length must be a power of 2"); - let mut trace = TraceTable::new_empty(TRACE_WIDTH, sequence_length / 2); + let mut trace = TraceTable::new(TRACE_WIDTH, sequence_length / 2); trace.fill( |state| { state[0] = BaseElement::ONE; diff --git a/examples/src/fibonacci/fib_small/prover.rs b/examples/src/fibonacci/fib_small/prover.rs index d701c5c30..d7f3df788 100644 --- a/examples/src/fibonacci/fib_small/prover.rs +++ b/examples/src/fibonacci/fib_small/prover.rs @@ -33,7 +33,7 @@ impl FibSmallProver { pub fn build_trace(&self, sequence_length: usize) -> TraceTable { assert!(sequence_length.is_power_of_two(), "sequence length must be a power of 2"); - let mut trace = TraceTable::new_empty(TRACE_WIDTH, sequence_length / 2); + let mut trace = TraceTable::new(TRACE_WIDTH, sequence_length / 2); trace.fill( |state| { state[0] = BaseElement::ONE; diff --git a/examples/src/lamport/aggregate/prover.rs b/examples/src/lamport/aggregate/prover.rs index d997b953f..ac5dea2fa 100644 --- a/examples/src/lamport/aggregate/prover.rs +++ b/examples/src/lamport/aggregate/prover.rs @@ -72,7 +72,7 @@ impl LamportAggregateProver { ) -> TraceTable { // allocate memory to hold the trace table let trace_length = SIG_CYCLE_LENGTH * messages.len(); - let mut trace = TraceTable::new_empty(TRACE_WIDTH, trace_length); + let mut trace = TraceTable::new(TRACE_WIDTH, trace_length); let powers_of_two = get_power_series(TWO, 128); diff --git a/examples/src/lamport/threshold/prover.rs b/examples/src/lamport/threshold/prover.rs index 0a72d1891..4cd26ef14 100644 --- a/examples/src/lamport/threshold/prover.rs +++ b/examples/src/lamport/threshold/prover.rs @@ -83,7 +83,7 @@ impl LamportThresholdProver { // allocate memory to hold the trace table let num_cycles = pub_key.num_keys().next_power_of_two(); let trace_length = SIG_CYCLE_LENGTH * num_cycles; - let mut trace = TraceTable::new_empty(TRACE_WIDTH, trace_length); + let mut trace = TraceTable::new(TRACE_WIDTH, trace_length); let powers_of_two = get_power_series(TWO, 128); diff --git a/examples/src/merkle/prover.rs b/examples/src/merkle/prover.rs index 0a91bb32c..86c4a3c40 100644 --- a/examples/src/merkle/prover.rs +++ b/examples/src/merkle/prover.rs @@ -38,7 +38,7 @@ impl MerkleProver { ) -> TraceTable { // allocate memory to hold the trace table let trace_length = branch.len() * HASH_CYCLE_LEN; - let mut trace = TraceTable::new_empty(TRACE_WIDTH, trace_length); + let mut trace = TraceTable::new(TRACE_WIDTH, trace_length); // skip the first node of the branch because it will be computed in the trace as hash(value) let branch = &branch[1..]; diff --git a/examples/src/rescue/prover.rs b/examples/src/rescue/prover.rs index fe452cda4..32f03077a 100644 --- a/examples/src/rescue/prover.rs +++ b/examples/src/rescue/prover.rs @@ -36,7 +36,7 @@ impl RescueProver { ) -> TraceTable { // allocate memory to hold the trace table let trace_length = iterations * CYCLE_LENGTH; - let mut trace = TraceTable::new_empty(4, trace_length); + let mut trace = TraceTable::new(4, trace_length); trace.fill( |state| { diff --git a/prover/src/trace/trace_table.rs b/prover/src/trace/trace_table.rs index c5b3f8858..050367088 100644 --- a/prover/src/trace/trace_table.rs +++ b/prover/src/trace/trace_table.rs @@ -79,8 +79,8 @@ impl TraceTable { /// * `width` is zero or greater than 255. /// * `length` is smaller than 8, greater than biggest multiplicative subgroup in the field /// `B`, or is not a power of two. - pub fn new_empty(width: usize, length: usize) -> Self { - Self::new_empty_with_meta(width, length, vec![]) + pub fn new(width: usize, length: usize) -> Self { + Self::with_meta(width, length, vec![]) } /// Creates a new execution trace of the specified width and length, and with the specified @@ -95,7 +95,7 @@ impl TraceTable { /// * `length` is smaller than 8, greater than the biggest multiplicative subgroup in the /// field `B`, or is not a power of two. /// * Length of `meta` is greater than 65535; - pub fn new_empty_with_meta(width: usize, length: usize, meta: Vec) -> Self { + pub fn with_meta(width: usize, length: usize, meta: Vec) -> Self { let info = TraceInfo::with_meta(width, length, meta); assert!( length.ilog2() <= B::TWO_ADICITY, From 44da0d4e581fdb40de69bd646f14e9683e399261 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Thu, 15 Feb 2024 10:39:58 -0500 Subject: [PATCH 06/30] test: `TraceInfo::to_elements()` --- air/src/air/trace_info.rs | 45 ++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/air/src/air/trace_info.rs b/air/src/air/trace_info.rs index 814fec5af..e1cebad45 100644 --- a/air/src/air/trace_info.rs +++ b/air/src/air/trace_info.rs @@ -639,32 +639,53 @@ fn bytes_to_element(bytes: &[u8]) -> B { #[cfg(test)] mod tests { - use super::{ToElements, TraceLayout}; - use math::fields::f64::BaseElement; + use super::{ToElements, TraceInfo}; + use math::{fields::f64::BaseElement, FieldElement}; #[test] - fn trace_layout_to_elements() { + fn trace_info_to_elements() { // --- test trace with only main segment ------------------------------ let main_width = 20; + let trace_length = 64_u32; let num_aux_segments = 0; - let expected = u32::from_le_bytes([num_aux_segments, main_width as u8, 0, 0]); - let expected = vec![BaseElement::from(expected)]; + let expected = { + let first_ele = u32::from_le_bytes([num_aux_segments, main_width as u8, 0, 0]); - let layout = TraceLayout::new(main_width, [0], [0]); - assert_eq!(expected, layout.to_elements()); + vec![BaseElement::from(first_ele), BaseElement::from(trace_length)] + }; + + let info = TraceInfo::new(main_width, trace_length as usize); + assert_eq!(expected, info.to_elements()); // --- test trace with one auxiliary segment -------------------------- let main_width = 20; + let trace_length = 64_u32; let num_aux_segments = 1; let aux_width = 9; let aux_rands = 12; + let trace_meta = vec![1_u8, 2, 3, 4]; + + let expected = { + let first_ele = + u32::from_le_bytes([aux_rands as u8, aux_width, num_aux_segments, main_width]); + + // `trace_meta` is 4 bytes, so fits into a single element + let mut meta_bytes = trace_meta.clone(); + meta_bytes.resize(BaseElement::ELEMENT_BYTES, 0); + let meta_ele = BaseElement::try_from(meta_bytes.as_slice()).unwrap(); - let expected = u32::from_le_bytes([aux_rands, aux_width, num_aux_segments, main_width]); - let expected = vec![BaseElement::from(expected)]; + vec![BaseElement::from(first_ele), BaseElement::from(trace_length), meta_ele] + }; + + let info = TraceInfo::new_multi_segment( + main_width as usize, + [aux_width as usize], + [aux_rands as usize], + trace_length as usize, + trace_meta, + ); - let layout = - TraceLayout::new(main_width as usize, [aux_width as usize], [aux_rands as usize]); - assert_eq!(expected, layout.to_elements()); + assert_eq!(expected, info.to_elements()); } } From 520bb9bb4be13c410aaeb48131ce0d054c92635f Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Thu, 15 Feb 2024 10:41:14 -0500 Subject: [PATCH 07/30] remove `TraceLayout` --- air/src/air/mod.rs | 2 +- air/src/air/trace_info.rs | 239 -------------------------------------- air/src/lib.rs | 4 +- prover/src/lib.rs | 2 +- winterfell/src/lib.rs | 4 +- 5 files changed, 6 insertions(+), 245 deletions(-) diff --git a/air/src/air/mod.rs b/air/src/air/mod.rs index 98753dec3..f9a33565e 100644 --- a/air/src/air/mod.rs +++ b/air/src/air/mod.rs @@ -9,7 +9,7 @@ use math::{fft, ExtensibleField, ExtensionOf, FieldElement, StarkField, ToElemen use utils::collections::{BTreeMap, Vec}; mod trace_info; -pub use trace_info::{TraceInfo, TraceLayout}; +pub use trace_info::TraceInfo; mod context; pub use context::AirContext; diff --git a/air/src/air/trace_info.rs b/air/src/air/trace_info.rs index e1cebad45..e53556cd7 100644 --- a/air/src/air/trace_info.rs +++ b/air/src/air/trace_info.rs @@ -376,245 +376,6 @@ impl Deserializable for TraceInfo { } } -// TRACE LAYOUT -// ================================================================================================ - -/// Layout of columns within an execution trace. -/// -/// A layout describes how columns of a trace are arranged into segments. All execution traces must -/// have a non-zero main segment, and may have additional auxiliary trace segments. Currently, the -/// number of auxiliary trace segments is limited to one. -/// -/// Additionally, a layout contains information on how many random elements are required to build a -/// given auxiliary trace segment. This information is used to construct -/// [AuxTraceRandElements](crate::AuxTraceRandElements) struct which is passed in as one of the -/// parameters to [Air::evaluate_aux_transition()](crate::Air::evaluate_aux_transition()) and -/// [Air::get_aux_assertions()](crate::Air::get_aux_assertions()) methods. -/// -/// The number of random elements may be different from the number of columns in a given auxiliary -/// segment. For example, an auxiliary segment may contain just one column, but may require many -/// random elements. -#[derive(Debug, Clone, Eq, PartialEq)] -pub struct TraceLayout { - main_segment_width: usize, - aux_segment_widths: [usize; NUM_AUX_SEGMENTS], - aux_segment_rands: [usize; NUM_AUX_SEGMENTS], - num_aux_segments: usize, -} - -impl TraceLayout { - // CONSTRUCTOR - // -------------------------------------------------------------------------------------------- - /// Returns a new [TraceLayout] instantiated with the provided info. - /// - /// # Panics - /// Panics if: - /// * Width of the main trace segment is set to zero. - /// * Sum of all segment widths exceeds 255. - /// * A zero entry in auxiliary segment width array is followed by a non-zero entry. - /// * Number of random elements for an auxiliary trace segment of non-zero width is set to zero. - /// * Number of random elements for an auxiliary trace segment of zero width is set to non-zero. - /// * Number of random elements for any auxiliary trace segment is greater than 255. - pub fn new( - main_width: usize, - aux_widths: [usize; NUM_AUX_SEGMENTS], - aux_rands: [usize; NUM_AUX_SEGMENTS], - ) -> Self { - // validate trace segment widths - assert!(main_width > 0, "main trace segment must consist of at least one column"); - let full_width = main_width + aux_widths.iter().sum::(); - assert!( - full_width <= TraceInfo::MAX_TRACE_WIDTH, - "total number of columns in the trace cannot be greater than {}, but was {}", - TraceInfo::MAX_TRACE_WIDTH, - full_width - ); - - // validate number of random elements required by each segment - let mut was_zero_width = false; - let mut num_aux_segments = 0; - for (&width, &num_rand_elements) in aux_widths.iter().zip(aux_rands.iter()) { - if width != 0 { - assert!( - !was_zero_width, - "a non-empty trace segment cannot follow an empty segment" - ); - assert!( - num_rand_elements > 0, - "number of random elements for a non-empty trace segment must be greater than zero" - ); - num_aux_segments += 1; - } else { - assert!( - num_rand_elements == 0, - "number of random elements for an empty trace segment must be zero" - ); - was_zero_width = true; - } - assert!( - num_rand_elements <= TraceInfo::MAX_RAND_SEGMENT_ELEMENTS, - "number of random elements required by a segment cannot exceed {}, but was {}", - TraceInfo::MAX_RAND_SEGMENT_ELEMENTS, - num_rand_elements - ); - } - - Self { - main_segment_width: main_width, - aux_segment_widths: aux_widths, - aux_segment_rands: aux_rands, - num_aux_segments, - } - } - - // PUBLIC ACCESSORS - // -------------------------------------------------------------------------------------------- - - /// Returns the number of columns in the main segment of an execution trace. - /// - /// This is guaranteed to be between 1 and 255. - pub fn main_trace_width(&self) -> usize { - self.main_segment_width - } - - /// Returns the number of columns in all auxiliary segments of an execution trace. - pub fn aux_trace_width(&self) -> usize { - self.aux_segment_widths.iter().sum() - } - - /// Returns the total number of segments in an execution trace. - pub fn num_segments(&self) -> usize { - self.num_aux_segments + 1 - } - - /// Returns the number of auxiliary trace segments in an execution trace. - pub fn num_aux_segments(&self) -> usize { - self.num_aux_segments - } - - /// Returns the number of columns in the auxiliary trace segment at the specified index. - pub fn get_aux_segment_width(&self, segment_idx: usize) -> usize { - // TODO: panic if segment_idx is not within num_aux_segments - self.aux_segment_widths[segment_idx] - } - - /// Returns the number of random elements required by the auxiliary trace segment at the - /// specified index. - pub fn get_aux_segment_rand_elements(&self, segment_idx: usize) -> usize { - // TODO: panic if segment_idx is not within num_aux_segments - self.aux_segment_rands[segment_idx] - } -} - -impl ToElements for TraceLayout { - fn to_elements(&self) -> Vec { - let mut result = Vec::new(); - - // main segment width, number of auxiliary segments, and parameters of the first auxiliary - // segment (if present) go into the first field element; we assume that each parameter can - // be encoded in 8 bits (which is enforced by the constructor) - let mut buf = self.main_segment_width as u32; - buf = (buf << 8) | self.num_aux_segments as u32; - if self.num_aux_segments == 1 { - buf = (buf << 8) | self.aux_segment_widths[0] as u32; - buf = (buf << 8) | self.aux_segment_rands[0] as u32; - } - result.push(E::from(buf)); - - // parameters of all subsequent auxiliary segments go into additional elements - for i in 1..self.num_aux_segments { - buf = self.aux_segment_widths[i] as u32; - buf = (buf << 8) | self.aux_segment_rands[i] as u32; - result.push(E::from(buf)); - } - - result - } -} - -impl Serializable for TraceLayout { - /// Serializes `self` and writes the resulting bytes into the `target`. - fn write_into(&self, target: &mut W) { - target.write_u8(self.main_segment_width as u8); - for &w in self.aux_segment_widths.iter() { - debug_assert!(w <= u8::MAX as usize, "aux segment width does not fit into u8 value"); - target.write_u8(w as u8); - } - for &rc in self.aux_segment_rands.iter() { - debug_assert!( - rc <= u8::MAX as usize, - "aux segment random element count does not fit into u8 value" - ); - target.write_u8(rc as u8); - } - } -} - -impl Deserializable for TraceLayout { - /// Reads [TraceLayout] from the specified `source` and returns the result. - /// - /// # Errors - /// Returns an error of a valid [TraceLayout] struct could not be read from the specified - /// `source`. - fn read_from(source: &mut R) -> Result { - let main_width = source.read_u8()? as usize; - if main_width == 0 { - return Err(DeserializationError::InvalidValue( - "main trace segment width must be greater than zero".to_string(), - )); - } - - // read and validate auxiliary trace segment widths - let mut was_zero_width = false; - let mut aux_widths = [0; NUM_AUX_SEGMENTS]; - for width in aux_widths.iter_mut() { - *width = source.read_u8()? as usize; - if *width != 0 { - if was_zero_width { - return Err(DeserializationError::InvalidValue( - "a non-empty trace segment cannot follow an empty segment".to_string(), - )); - } - } else { - was_zero_width = true; - } - } - - let full_trace_width = main_width + aux_widths.iter().sum::(); - if full_trace_width >= TraceInfo::MAX_TRACE_WIDTH { - return Err(DeserializationError::InvalidValue(format!( - "full trace width cannot be greater than {}, but was {}", - TraceInfo::MAX_TRACE_WIDTH, - full_trace_width - ))); - } - - // read and validate number of random elements for each auxiliary trace segment - let mut aux_rands = [0; NUM_AUX_SEGMENTS]; - for (num_rand_elements, &width) in aux_rands.iter_mut().zip(aux_widths.iter()) { - *num_rand_elements = source.read_u8()? as usize; - if width == 0 && *num_rand_elements != 0 { - return Err(DeserializationError::InvalidValue( - "an empty trace segment cannot require random elements".to_string(), - )); - } else if width != 0 && *num_rand_elements == 0 { - return Err(DeserializationError::InvalidValue( - "a non-empty trace segment must require at least one random element" - .to_string(), - )); - } else if *num_rand_elements > TraceInfo::MAX_RAND_SEGMENT_ELEMENTS { - return Err(DeserializationError::InvalidValue(format!( - "number of random elements required by a segment cannot exceed {}, but was {}", - TraceInfo::MAX_RAND_SEGMENT_ELEMENTS, - *num_rand_elements - ))); - } - } - - Ok(TraceLayout::new(main_width, aux_widths, aux_rands)) - } -} - // TODO: MERGE WITH `air::proof::context::bytes_to_elements` /// Converts a slice of bytes into a field element. diff --git a/air/src/lib.rs b/air/src/lib.rs index 149a0915b..41c70e04f 100644 --- a/air/src/lib.rs +++ b/air/src/lib.rs @@ -45,6 +45,6 @@ mod air; pub use air::{ Air, AirContext, Assertion, AuxTraceRandElements, BoundaryConstraint, BoundaryConstraintGroup, BoundaryConstraints, ConstraintCompositionCoefficients, ConstraintDivisor, - DeepCompositionCoefficients, EvaluationFrame, TraceInfo, TraceLayout, - TransitionConstraintDegree, TransitionConstraints, + DeepCompositionCoefficients, EvaluationFrame, TraceInfo, TransitionConstraintDegree, + TransitionConstraints, }; diff --git a/prover/src/lib.rs b/prover/src/lib.rs index f2163045d..b4db51038 100644 --- a/prover/src/lib.rs +++ b/prover/src/lib.rs @@ -47,7 +47,7 @@ pub use air::{ proof, proof::StarkProof, Air, AirContext, Assertion, AuxTraceRandElements, BoundaryConstraint, BoundaryConstraintGroup, ConstraintCompositionCoefficients, ConstraintDivisor, DeepCompositionCoefficients, EvaluationFrame, FieldExtension, ProofOptions, TraceInfo, - TraceLayout, TransitionConstraintDegree, + TransitionConstraintDegree, }; use tracing::{event, info_span, Level}; pub use utils::{ diff --git a/winterfell/src/lib.rs b/winterfell/src/lib.rs index 12c4b8c13..88f679461 100644 --- a/winterfell/src/lib.rs +++ b/winterfell/src/lib.rs @@ -586,7 +586,7 @@ pub use prover::{ ConstraintCompositionCoefficients, ConstraintDivisor, ConstraintEvaluator, DeepCompositionCoefficients, DefaultConstraintEvaluator, DefaultTraceLde, Deserializable, DeserializationError, EvaluationFrame, FieldExtension, ProofOptions, Prover, ProverError, - Serializable, SliceReader, StarkDomain, StarkProof, Trace, TraceInfo, TraceLayout, TraceLde, - TracePolyTable, TraceTable, TraceTableFragment, TransitionConstraintDegree, + Serializable, SliceReader, StarkDomain, StarkProof, Trace, TraceInfo, TraceLde, TracePolyTable, + TraceTable, TraceTableFragment, TransitionConstraintDegree, }; pub use verifier::{verify, AcceptableOptions, VerifierError}; From 6bc46ba21b53eb190407816cd69f87279c1c558f Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Thu, 15 Feb 2024 10:41:29 -0500 Subject: [PATCH 08/30] clippy --- prover/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prover/src/lib.rs b/prover/src/lib.rs index b4db51038..392987702 100644 --- a/prover/src/lib.rs +++ b/prover/src/lib.rs @@ -266,7 +266,7 @@ pub trait Prover { // extend the main execution trace and build a Merkle tree from the extended trace let span = info_span!("commit_to_main_trace_segment").entered(); let (trace_lde, trace_polys) = - self.new_trace_lde(&trace.get_info(), trace.main_segment(), &domain); + self.new_trace_lde(trace.get_info(), trace.main_segment(), &domain); // get the commitment to the main trace segment LDE let main_trace_root = trace_lde.get_main_trace_commitment(); From 0d41ad8ee076b5cffa2807b1bf35d6f786a429c7 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Thu, 15 Feb 2024 10:44:51 -0500 Subject: [PATCH 09/30] fix comment --- air/src/proof/context.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/air/src/proof/context.rs b/air/src/proof/context.rs index 21702f8c2..e9b88a892 100644 --- a/air/src/proof/context.rs +++ b/air/src/proof/context.rs @@ -90,14 +90,12 @@ impl ToElements for Context { /// Converts this [Context] into a vector of field elements. /// /// The elements are laid out as follows: - /// - trace layout info [1 or more elements]. + /// - trace info [1 or more elements]. /// - field modulus bytes [2 field elements]. /// - field extension and FRI parameters [1 element]. /// - grinding factor [1 element]. /// - blowup factor [1 element]. /// - number of queries [1 element]. - /// - trace length [1 element]. - /// - trace metadata [0 or more elements]. fn to_elements(&self) -> Vec { // convert trace layout let mut result = self.trace_info.to_elements(); From c7d888d651a8b9f001417d774d64ee47d8c9c97e Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Thu, 15 Feb 2024 11:00:51 -0500 Subject: [PATCH 10/30] bytes_to_element_with_padding --- air/src/air/trace_info.rs | 23 ++--------------------- air/src/proof/context.rs | 26 +++----------------------- math/src/lib.rs | 3 ++- math/src/utils/mod.rs | 21 ++++++++++++++++++++- 4 files changed, 27 insertions(+), 46 deletions(-) diff --git a/air/src/air/trace_info.rs b/air/src/air/trace_info.rs index e53556cd7..420cdcc82 100644 --- a/air/src/air/trace_info.rs +++ b/air/src/air/trace_info.rs @@ -3,7 +3,7 @@ // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. -use math::{StarkField, ToElements}; +use math::{bytes_to_element_with_padding, StarkField, ToElements}; use utils::{ collections::Vec, string::ToString, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable, @@ -250,7 +250,7 @@ impl ToElements for TraceInfo { // element, and then converting these chunks into field elements. if !self.trace_meta.is_empty() { for chunk in self.trace_meta.chunks(E::ELEMENT_BYTES - 1) { - result.push(bytes_to_element(chunk)); + result.push(bytes_to_element_with_padding(chunk.to_vec())); } } @@ -376,25 +376,6 @@ impl Deserializable for TraceInfo { } } -// TODO: MERGE WITH `air::proof::context::bytes_to_elements` - -/// Converts a slice of bytes into a field element. -/// -/// Assumes that the length of `bytes` is smaller than the number of bytes needed to encode an -/// element. -#[allow(clippy::let_and_return)] -fn bytes_to_element(bytes: &[u8]) -> B { - debug_assert!(bytes.len() < B::ELEMENT_BYTES); - - let mut buf = bytes.to_vec(); - buf.resize(B::ELEMENT_BYTES, 0); - let element = match B::try_from(buf.as_slice()) { - Ok(element) => element, - Err(_) => panic!("element deserialization failed"), - }; - element -} - // TESTS // ================================================================================================ diff --git a/air/src/proof/context.rs b/air/src/proof/context.rs index e9b88a892..cd122d1dd 100644 --- a/air/src/proof/context.rs +++ b/air/src/proof/context.rs @@ -4,7 +4,7 @@ // LICENSE file in the root directory of this source tree. use crate::{ProofOptions, TraceInfo}; -use math::{StarkField, ToElements}; +use math::{bytes_to_element_with_padding, StarkField, ToElements}; use utils::{ collections::Vec, string::ToString, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable, @@ -103,8 +103,8 @@ impl ToElements for Context { // convert field modulus bytes into 2 elements let num_modulus_bytes = self.field_modulus_bytes.len(); let (m1, m2) = self.field_modulus_bytes.split_at(num_modulus_bytes / 2); - result.push(bytes_to_element(m1)); - result.push(bytes_to_element(m2)); + result.push(bytes_to_element_with_padding(m1.to_vec())); + result.push(bytes_to_element_with_padding(m2.to_vec())); // convert proof options to elements result.append(&mut self.options.to_elements()); @@ -156,26 +156,6 @@ impl Deserializable for Context { } } -// HELPER FUNCTIONS -// ================================================================================================ - -/// Converts a slice of bytes into a field element. -/// -/// Assumes that the length of `bytes` is smaller than the number of bytes needed to encode an -/// element. -#[allow(clippy::let_and_return)] -fn bytes_to_element(bytes: &[u8]) -> B { - debug_assert!(bytes.len() < B::ELEMENT_BYTES); - - let mut buf = bytes.to_vec(); - buf.resize(B::ELEMENT_BYTES, 0); - let element = match B::try_from(buf.as_slice()) { - Ok(element) => element, - Err(_) => panic!("element deserialization failed"), - }; - element -} - // TESTS // ================================================================================================ diff --git a/math/src/lib.rs b/math/src/lib.rs index 3d35c1c39..260dba73a 100644 --- a/math/src/lib.rs +++ b/math/src/lib.rs @@ -113,5 +113,6 @@ pub mod fields { mod utils; pub use crate::utils::{ - add_in_place, batch_inversion, get_power_series, get_power_series_with_offset, log2, mul_acc, + add_in_place, batch_inversion, bytes_to_element_with_padding, get_power_series, + get_power_series_with_offset, log2, mul_acc, }; diff --git a/math/src/utils/mod.rs b/math/src/utils/mod.rs index fab0512dd..e02fe7c41 100644 --- a/math/src/utils/mod.rs +++ b/math/src/utils/mod.rs @@ -3,7 +3,7 @@ // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. -use crate::{field::FieldElement, ExtensionOf}; +use crate::{field::FieldElement, ExtensionOf, StarkField}; use utils::{batch_iter_mut, collections::Vec, iter_mut, uninit_vector}; #[cfg(feature = "concurrent")] @@ -199,6 +199,25 @@ pub fn log2(n: usize) -> u32 { n.trailing_zeros() } +// CONVERSION FUNCTIONS +// ================================================================================================ + +/// Converts a slice of bytes into a field element. Pads the slice if it is smaller than the number +/// of bytes needed to represent an element. +/// +/// # Panics +/// Panics if the length of `bytes` is smaller than the number of bytes needed to encode an element. +pub fn bytes_to_element_with_padding(mut bytes: Vec) -> B { + assert!(bytes.len() < B::ELEMENT_BYTES); + + bytes.resize(B::ELEMENT_BYTES, 0); + + match B::try_from(bytes.as_slice()) { + Ok(element) => element, + Err(_) => panic!("element deserialization failed"), + } +} + // HELPER FUNCTIONS // ------------------------------------------------------------------------------------------------ From 564da7c2f990cd35e5e0e88569af00f338b6bc9c Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Thu, 15 Feb 2024 11:14:19 -0500 Subject: [PATCH 11/30] use `vec![]` instead of `Vec::new()` --- air/src/proof/context.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/air/src/proof/context.rs b/air/src/proof/context.rs index cd122d1dd..e7536ac9a 100644 --- a/air/src/proof/context.rs +++ b/air/src/proof/context.rs @@ -192,7 +192,7 @@ mod tests { [aux_width], [aux_rands], trace_length, - Vec::new(), + vec![], ); let mut expected = trace_info.to_elements(); From 3e0122cd13e479f72dc822f0606e96b74207514a Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Tue, 20 Feb 2024 07:58:09 -0500 Subject: [PATCH 12/30] docstring: `TraceInfo::new_multi_segment` --- air/src/air/trace_info.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/air/src/air/trace_info.rs b/air/src/air/trace_info.rs index 420cdcc82..f2d038bf0 100644 --- a/air/src/air/trace_info.rs +++ b/air/src/air/trace_info.rs @@ -72,13 +72,17 @@ impl TraceInfo { Self::new_multi_segment(width, [0], [0], length, meta) } - /// Creates a new [TraceInfo] from the specified trace segment widths, length, and metadata. + /// Creates a new [TraceInfo] with main and auxiliary segments. /// /// # Panics /// Panics if: /// * The width of the first trace segment is zero. /// * Total width of all trace segments is greater than 255. /// * Trace length is smaller than 8 or is not a power of two. + /// * A zero entry in auxiliary segment width array is followed by a non-zero entry. + /// * Number of random elements for an auxiliary trace segment of non-zero width is set to zero. + /// * Number of random elements for an auxiliary trace segment of zero width is set to non-zero. + /// * Number of random elements for any auxiliary trace segment is greater than 255. pub fn new_multi_segment( main_segment_width: usize, aux_segment_widths: [usize; NUM_AUX_SEGMENTS], From c31d18c17162d79ed759c90f487544303e78bce4 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Tue, 20 Feb 2024 07:59:41 -0500 Subject: [PATCH 13/30] `get_trace_info()` -> `trace_info()` --- air/src/proof/context.rs | 2 +- air/src/proof/mod.rs | 10 +++++----- verifier/src/lib.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/air/src/proof/context.rs b/air/src/proof/context.rs index e7536ac9a..6edc2d1df 100644 --- a/air/src/proof/context.rs +++ b/air/src/proof/context.rs @@ -49,7 +49,7 @@ impl Context { // -------------------------------------------------------------------------------------------- /// Returns execution trace info for the computation described by this context. - pub fn get_trace_info(&self) -> &TraceInfo { + pub fn trace_info(&self) -> &TraceInfo { &self.trace_info } diff --git a/air/src/proof/mod.rs b/air/src/proof/mod.rs index d305782bb..a6989a78f 100644 --- a/air/src/proof/mod.rs +++ b/air/src/proof/mod.rs @@ -82,8 +82,8 @@ impl StarkProof { } /// Returns trace info for the computation described by this proof. - pub fn get_trace_info(&self) -> &TraceInfo { - self.context.get_trace_info() + pub fn trace_info(&self) -> &TraceInfo { + self.context.trace_info() } /// Returns the size of the LDE domain for the computation described by this proof. @@ -104,14 +104,14 @@ impl StarkProof { get_conjectured_security( self.context.options(), self.context.num_modulus_bits(), - self.get_trace_info().length(), + self.trace_info().length(), H::COLLISION_RESISTANCE, ) } else { get_proven_security( self.context.options(), self.context.num_modulus_bits(), - self.get_trace_info().length(), + self.trace_info().length(), H::COLLISION_RESISTANCE, ) } @@ -184,7 +184,7 @@ impl Deserializable for StarkProof { let context = Context::read_from(source)?; let num_unique_queries = source.read_u8()?; let commitments = Commitments::read_from(source)?; - let num_trace_segments = context.get_trace_info().num_segments(); + let num_trace_segments = context.trace_info().num_segments(); let mut trace_queries = Vec::with_capacity(num_trace_segments); for _ in 0..num_trace_segments { trace_queries.push(Queries::read_from(source)?); diff --git a/verifier/src/lib.rs b/verifier/src/lib.rs index 510eee1c0..2bbf0de6a 100644 --- a/verifier/src/lib.rs +++ b/verifier/src/lib.rs @@ -103,7 +103,7 @@ where public_coin_seed.append(&mut pub_inputs.to_elements()); // create AIR instance for the computation specified in the proof - let air = AIR::new(proof.get_trace_info().clone(), pub_inputs, proof.options().clone()); + let air = AIR::new(proof.trace_info().clone(), pub_inputs, proof.options().clone()); // figure out which version of the generic proof verification procedure to run. this is a sort // of static dispatch for selecting two generic parameter: extension field and hash function. From a0fdbfc14ae1d69d62ccc38ea3440e4e49c7a6db Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Tue, 20 Feb 2024 08:00:24 -0500 Subject: [PATCH 14/30] Rename Trace::get_info --- examples/src/fibonacci/fib2/mod.rs | 2 +- examples/src/fibonacci/fib2/prover.rs | 2 +- examples/src/fibonacci/fib8/mod.rs | 2 +- examples/src/fibonacci/fib8/prover.rs | 2 +- examples/src/fibonacci/fib_small/mod.rs | 2 +- examples/src/fibonacci/fib_small/prover.rs | 2 +- examples/src/fibonacci/mulfib2/mod.rs | 2 +- examples/src/fibonacci/mulfib2/prover.rs | 2 +- examples/src/fibonacci/mulfib8/mod.rs | 2 +- examples/src/fibonacci/mulfib8/prover.rs | 2 +- examples/src/lamport/aggregate/mod.rs | 2 +- examples/src/lamport/threshold/mod.rs | 2 +- examples/src/merkle/mod.rs | 2 +- examples/src/merkle/prover.rs | 2 +- examples/src/rescue/mod.rs | 2 +- examples/src/rescue/prover.rs | 2 +- .../src/rescue_raps/custom_trace_table.rs | 2 +- examples/src/rescue_raps/mod.rs | 2 +- examples/src/rescue_raps/prover.rs | 2 +- examples/src/utils/mod.rs | 2 +- examples/src/vdf/exempt/mod.rs | 2 +- examples/src/vdf/exempt/prover.rs | 2 +- examples/src/vdf/regular/mod.rs | 2 +- examples/src/vdf/regular/prover.rs | 2 +- prover/src/lib.rs | 8 ++++---- prover/src/trace/mod.rs | 20 +++++++++---------- prover/src/trace/tests.rs | 4 ++-- prover/src/trace/trace_lde/default/tests.rs | 4 ++-- prover/src/trace/trace_table.rs | 2 +- 29 files changed, 43 insertions(+), 43 deletions(-) diff --git a/examples/src/fibonacci/fib2/mod.rs b/examples/src/fibonacci/fib2/mod.rs index badbba85a..46e3ff7ff 100644 --- a/examples/src/fibonacci/fib2/mod.rs +++ b/examples/src/fibonacci/fib2/mod.rs @@ -101,7 +101,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(self.sequence_length); - tracing::Span::current().record("steps", trace.get_info().length()); + tracing::Span::current().record("steps", trace.info().length()); trace }); diff --git a/examples/src/fibonacci/fib2/prover.rs b/examples/src/fibonacci/fib2/prover.rs index 09de4ed40..bb818de30 100644 --- a/examples/src/fibonacci/fib2/prover.rs +++ b/examples/src/fibonacci/fib2/prover.rs @@ -64,7 +64,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { - let last_step = trace.get_info().length() - 1; + let last_step = trace.info().length() - 1; trace.get(1, last_step) } diff --git a/examples/src/fibonacci/fib8/mod.rs b/examples/src/fibonacci/fib8/mod.rs index c5f28a776..74b17f59f 100644 --- a/examples/src/fibonacci/fib8/mod.rs +++ b/examples/src/fibonacci/fib8/mod.rs @@ -101,7 +101,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(self.sequence_length); - tracing::Span::current().record("steps", trace.get_info().length()); + tracing::Span::current().record("steps", trace.info().length()); trace }); diff --git a/examples/src/fibonacci/fib8/prover.rs b/examples/src/fibonacci/fib8/prover.rs index 99134bc99..dd65ecd45 100644 --- a/examples/src/fibonacci/fib8/prover.rs +++ b/examples/src/fibonacci/fib8/prover.rs @@ -79,7 +79,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { - let last_step = trace.get_info().length() - 1; + let last_step = trace.info().length() - 1; trace.get(1, last_step) } diff --git a/examples/src/fibonacci/fib_small/mod.rs b/examples/src/fibonacci/fib_small/mod.rs index 2e32f3d65..c6a37b1cf 100644 --- a/examples/src/fibonacci/fib_small/mod.rs +++ b/examples/src/fibonacci/fib_small/mod.rs @@ -116,7 +116,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(self.sequence_length); - tracing::Span::current().record("steps", trace.get_info().length()); + tracing::Span::current().record("steps", trace.info().length()); trace }); diff --git a/examples/src/fibonacci/fib_small/prover.rs b/examples/src/fibonacci/fib_small/prover.rs index d7f3df788..489aa5e3d 100644 --- a/examples/src/fibonacci/fib_small/prover.rs +++ b/examples/src/fibonacci/fib_small/prover.rs @@ -63,7 +63,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { - let last_step = trace.get_info().length() - 1; + let last_step = trace.info().length() - 1; trace.get(1, last_step) } diff --git a/examples/src/fibonacci/mulfib2/mod.rs b/examples/src/fibonacci/mulfib2/mod.rs index 0d203cb7a..2c02ea047 100644 --- a/examples/src/fibonacci/mulfib2/mod.rs +++ b/examples/src/fibonacci/mulfib2/mod.rs @@ -101,7 +101,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(sequence_length); - tracing::Span::current().record("steps", trace.get_info().length()); + tracing::Span::current().record("steps", trace.info().length()); trace }); diff --git a/examples/src/fibonacci/mulfib2/prover.rs b/examples/src/fibonacci/mulfib2/prover.rs index ced46c76e..cc4023623 100644 --- a/examples/src/fibonacci/mulfib2/prover.rs +++ b/examples/src/fibonacci/mulfib2/prover.rs @@ -60,7 +60,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { - let last_step = trace.get_info().length() - 1; + let last_step = trace.info().length() - 1; trace.get(0, last_step) } diff --git a/examples/src/fibonacci/mulfib8/mod.rs b/examples/src/fibonacci/mulfib8/mod.rs index ccbb8a12c..19b5ae2fe 100644 --- a/examples/src/fibonacci/mulfib8/mod.rs +++ b/examples/src/fibonacci/mulfib8/mod.rs @@ -102,7 +102,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(sequence_length); - tracing::Span::current().record("steps", trace.get_info().length()); + tracing::Span::current().record("steps", trace.info().length()); trace }); diff --git a/examples/src/fibonacci/mulfib8/prover.rs b/examples/src/fibonacci/mulfib8/prover.rs index 558f547a6..a3d322ce9 100644 --- a/examples/src/fibonacci/mulfib8/prover.rs +++ b/examples/src/fibonacci/mulfib8/prover.rs @@ -72,7 +72,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { - let last_step = trace.get_info().length() - 1; + let last_step = trace.info().length() - 1; trace.get(6, last_step) } diff --git a/examples/src/lamport/aggregate/mod.rs b/examples/src/lamport/aggregate/mod.rs index b898ba9db..b8029274a 100644 --- a/examples/src/lamport/aggregate/mod.rs +++ b/examples/src/lamport/aggregate/mod.rs @@ -127,7 +127,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(&self.messages, &self.signatures); - tracing::Span::current().record("steps", trace.get_info().length()); + tracing::Span::current().record("steps", trace.info().length()); trace }); diff --git a/examples/src/lamport/threshold/mod.rs b/examples/src/lamport/threshold/mod.rs index 06b4ebe3e..974629af2 100644 --- a/examples/src/lamport/threshold/mod.rs +++ b/examples/src/lamport/threshold/mod.rs @@ -133,7 +133,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(&self.pub_key, self.message, &self.signatures); - tracing::Span::current().record("steps", trace.get_info().length()); + tracing::Span::current().record("steps", trace.info().length()); trace }); diff --git a/examples/src/merkle/mod.rs b/examples/src/merkle/mod.rs index dcee6180f..0b6149a8f 100644 --- a/examples/src/merkle/mod.rs +++ b/examples/src/merkle/mod.rs @@ -121,7 +121,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(self.value, &self.path, self.index); - tracing::Span::current().record("steps", trace.get_info().length()); + tracing::Span::current().record("steps", trace.info().length()); trace }); diff --git a/examples/src/merkle/prover.rs b/examples/src/merkle/prover.rs index 86c4a3c40..619c9f9d8 100644 --- a/examples/src/merkle/prover.rs +++ b/examples/src/merkle/prover.rs @@ -113,7 +113,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { - let last_step = trace.get_info().length() - 1; + let last_step = trace.info().length() - 1; PublicInputs { tree_root: [trace.get(0, last_step), trace.get(1, last_step)], } diff --git a/examples/src/rescue/mod.rs b/examples/src/rescue/mod.rs index 4f18ab6d3..fe7af67f2 100644 --- a/examples/src/rescue/mod.rs +++ b/examples/src/rescue/mod.rs @@ -106,7 +106,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(self.seed, self.chain_length); - tracing::Span::current().record("steps", trace.get_info().length()); + tracing::Span::current().record("steps", trace.info().length()); trace }); diff --git a/examples/src/rescue/prover.rs b/examples/src/rescue/prover.rs index 32f03077a..b04ee28bf 100644 --- a/examples/src/rescue/prover.rs +++ b/examples/src/rescue/prover.rs @@ -79,7 +79,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { - let last_step = trace.get_info().length() - 1; + let last_step = trace.info().length() - 1; PublicInputs { seed: [trace.get(0, 0), trace.get(1, 0)], result: [trace.get(0, last_step), trace.get(1, last_step)], diff --git a/examples/src/rescue_raps/custom_trace_table.rs b/examples/src/rescue_raps/custom_trace_table.rs index bc96123db..1a3680880 100644 --- a/examples/src/rescue_raps/custom_trace_table.rs +++ b/examples/src/rescue_raps/custom_trace_table.rs @@ -157,7 +157,7 @@ impl RapTraceTable { impl Trace for RapTraceTable { type BaseField = B; - fn get_info(&self) -> &TraceInfo { + fn info(&self) -> &TraceInfo { &self.info } diff --git a/examples/src/rescue_raps/mod.rs b/examples/src/rescue_raps/mod.rs index d18b3ac29..e41a65c7a 100644 --- a/examples/src/rescue_raps/mod.rs +++ b/examples/src/rescue_raps/mod.rs @@ -119,7 +119,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(&self.seeds, &self.permuted_seeds, self.result); - tracing::Span::current().record("steps", trace.get_info().length()); + tracing::Span::current().record("steps", trace.info().length()); trace }); diff --git a/examples/src/rescue_raps/prover.rs b/examples/src/rescue_raps/prover.rs index bb3eb175b..b32196668 100644 --- a/examples/src/rescue_raps/prover.rs +++ b/examples/src/rescue_raps/prover.rs @@ -107,7 +107,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { - let last_step = trace.get_info().length() - 1; + let last_step = trace.info().length() - 1; PublicInputs { result: [ [trace.get(0, last_step), trace.get(1, last_step)], diff --git a/examples/src/utils/mod.rs b/examples/src/utils/mod.rs index 6e2bb2702..a3d9283ee 100644 --- a/examples/src/utils/mod.rs +++ b/examples/src/utils/mod.rs @@ -67,7 +67,7 @@ pub fn print_trace( let trace_width = trace.width(); let mut state = vec![E::ZERO; trace_width]; - for i in 0..trace.get_info().length() { + for i in 0..trace.info().length() { if (i.wrapping_sub(offset)) % multiples_of != 0 { continue; } diff --git a/examples/src/vdf/exempt/mod.rs b/examples/src/vdf/exempt/mod.rs index f1f1b6379..3b847d81e 100644 --- a/examples/src/vdf/exempt/mod.rs +++ b/examples/src/vdf/exempt/mod.rs @@ -97,7 +97,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = VdfProver::::build_trace(self.seed, self.num_steps + 1); - tracing::Span::current().record("steps", trace.get_info().length()); + tracing::Span::current().record("steps", trace.info().length()); trace }); diff --git a/examples/src/vdf/exempt/prover.rs b/examples/src/vdf/exempt/prover.rs index 2e1ec1f3e..2c1e81278 100644 --- a/examples/src/vdf/exempt/prover.rs +++ b/examples/src/vdf/exempt/prover.rs @@ -62,7 +62,7 @@ where fn get_pub_inputs(&self, trace: &Self::Trace) -> VdfInputs { // the result is read from the second to last step because the last last step contains // garbage - let second_to_last_step = trace.get_info().length() - 2; + let second_to_last_step = trace.info().length() - 2; VdfInputs { seed: trace.get(0, 0), result: trace.get(0, second_to_last_step), diff --git a/examples/src/vdf/regular/mod.rs b/examples/src/vdf/regular/mod.rs index 76a4b3c04..4402dca22 100644 --- a/examples/src/vdf/regular/mod.rs +++ b/examples/src/vdf/regular/mod.rs @@ -94,7 +94,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = VdfProver::::build_trace(self.seed, self.num_steps); - tracing::Span::current().record("steps", trace.get_info().length()); + tracing::Span::current().record("steps", trace.info().length()); trace }); diff --git a/examples/src/vdf/regular/prover.rs b/examples/src/vdf/regular/prover.rs index 60e9eef9d..f794c620b 100644 --- a/examples/src/vdf/regular/prover.rs +++ b/examples/src/vdf/regular/prover.rs @@ -57,7 +57,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> VdfInputs { - let last_step = trace.get_info().length() - 1; + let last_step = trace.info().length() - 1; VdfInputs { seed: trace.get(0, 0), result: trace.get(0, last_step), diff --git a/prover/src/lib.rs b/prover/src/lib.rs index 392987702..db98871b2 100644 --- a/prover/src/lib.rs +++ b/prover/src/lib.rs @@ -241,7 +241,7 @@ pub trait Prover { // create an instance of AIR for the provided parameters. this takes a generic description // of the computation (provided via AIR type), and creates a description of a specific // execution of the computation for the provided public inputs. - let air = Self::Air::new(trace.get_info().clone(), pub_inputs, self.options().clone()); + let air = Self::Air::new(trace.info().clone(), pub_inputs, self.options().clone()); // create a channel which is used to simulate interaction between the prover and the // verifier; the channel will be used to commit to values and to draw randomness that @@ -266,7 +266,7 @@ pub trait Prover { // extend the main execution trace and build a Merkle tree from the extended trace let span = info_span!("commit_to_main_trace_segment").entered(); let (trace_lde, trace_polys) = - self.new_trace_lde(trace.get_info(), trace.main_segment(), &domain); + self.new_trace_lde(trace.info(), trace.main_segment(), &domain); // get the commitment to the main trace segment LDE let main_trace_root = trace_lde.get_main_trace_commitment(); @@ -283,8 +283,8 @@ pub trait Prover { // commitment and trace polynomial table structs let mut aux_trace_segments = Vec::new(); let mut aux_trace_rand_elements = AuxTraceRandElements::new(); - for i in 0..trace.get_info().num_aux_segments() { - let num_columns = trace.get_info().get_aux_segment_width(i); + for i in 0..trace.info().num_aux_segments() { + let num_columns = trace.info().get_aux_segment_width(i); let (aux_segment, rand_elements) = { let _ = info_span!("build_aux_trace_segment", num_columns).entered(); diff --git a/prover/src/trace/mod.rs b/prover/src/trace/mod.rs index f47c80936..a463afeec 100644 --- a/prover/src/trace/mod.rs +++ b/prover/src/trace/mod.rs @@ -44,7 +44,7 @@ pub trait Trace: Sized { // REQUIRED METHODS // -------------------------------------------------------------------------------------------- /// Returns trace info for this trace. - fn get_info(&self) -> &TraceInfo; + fn info(&self) -> &TraceInfo; /// Returns a reference to a [Matrix] describing the main segment of this trace. fn main_segment(&self) -> &ColMatrix; @@ -81,10 +81,10 @@ pub trait Trace: Sized { { // make sure the width align; if they don't something went terribly wrong assert_eq!( - self.get_info().main_trace_width(), + self.info().main_trace_width(), air.trace_info().main_trace_width(), "inconsistent trace width: expected {}, but was {}", - self.get_info().main_trace_width(), + self.info().main_trace_width(), air.trace_info().main_trace_width(), ); @@ -92,7 +92,7 @@ pub trait Trace: Sized { // first, check assertions against the main segment of the execution trace for assertion in air.get_assertions() { - assertion.apply(self.get_info().length(), |step, value| { + assertion.apply(self.info().length(), |step, value| { assert!( value == self.main_segment().get(assertion.column(), step), "trace does not satisfy assertion main_trace({}, {}) == {}", @@ -109,8 +109,8 @@ pub trait Trace: Sized { // column index in the context of this segment let mut column_idx = assertion.column(); let mut segment_idx = 0; - for i in 0..self.get_info().num_aux_segments() { - let segment_width = self.get_info().get_aux_segment_width(i); + for i in 0..self.info().num_aux_segments() { + let segment_width = self.info().get_aux_segment_width(i); if column_idx < segment_width { segment_idx = i; break; @@ -119,7 +119,7 @@ pub trait Trace: Sized { } // get the matrix and verify the assertion against it - assertion.apply(self.get_info().length(), |step, value| { + assertion.apply(self.info().length(), |step, value| { assert!( value == aux_segments[segment_idx].get(column_idx, step), "trace does not satisfy assertion aux_trace({}, {}) == {}", @@ -139,9 +139,9 @@ pub trait Trace: Sized { // initialize buffers to hold evaluation frames and results of constraint evaluations let mut x = Self::BaseField::ONE; - let mut main_frame = EvaluationFrame::new(self.get_info().main_trace_width()); + let mut main_frame = EvaluationFrame::new(self.info().main_trace_width()); let mut aux_frame = if air.trace_info().is_multi_segment() { - Some(EvaluationFrame::::new(self.get_info().aux_trace_width())) + Some(EvaluationFrame::::new(self.info().aux_trace_width())) } else { None }; @@ -151,7 +151,7 @@ pub trait Trace: Sized { // we check transition constraints on all steps except the last k steps, where k is the // number of steps exempt from transition constraints (guaranteed to be at least 1) - for step in 0..self.get_info().length() - air.context().num_transition_exemptions() { + for step in 0..self.info().length() - air.context().num_transition_exemptions() { // build periodic values for (p, v) in periodic_values_polys.iter().zip(periodic_values.iter_mut()) { let num_cycles = air.trace_length() / p.len(); diff --git a/prover/src/trace/tests.rs b/prover/src/trace/tests.rs index 757904208..9102aaac2 100644 --- a/prover/src/trace/tests.rs +++ b/prover/src/trace/tests.rs @@ -12,8 +12,8 @@ fn new_trace_table() { let trace_length = 8; let trace = build_fib_trace(trace_length * 2); - assert_eq!(2, trace.get_info().main_trace_width()); - assert_eq!(8, trace.get_info().length()); + assert_eq!(2, trace.info().main_trace_width()); + assert_eq!(8, trace.info().length()); let expected: Vec = vec![1u32, 2, 5, 13, 34, 89, 233, 610] .into_iter() diff --git a/prover/src/trace/trace_lde/default/tests.rs b/prover/src/trace/trace_lde/default/tests.rs index 57044dc8d..53d143758 100644 --- a/prover/src/trace/trace_lde/default/tests.rs +++ b/prover/src/trace/trace_lde/default/tests.rs @@ -26,7 +26,7 @@ fn extend_trace_table() { // build the trace polynomials, extended trace, and commitment using the default TraceLde impl let (trace_lde, trace_polys) = DefaultTraceLde::::new( - &trace.get_info(), + &trace.info(), trace.main_segment(), &domain, ); @@ -76,7 +76,7 @@ fn commit_trace_table() { // build the trace polynomials, extended trace, and commitment using the default TraceLde impl let (trace_lde, _) = DefaultTraceLde::::new( - &trace.get_info(), + &trace.info(), trace.main_segment(), &domain, ); diff --git a/prover/src/trace/trace_table.rs b/prover/src/trace/trace_table.rs index 050367088..5438efeb5 100644 --- a/prover/src/trace/trace_table.rs +++ b/prover/src/trace/trace_table.rs @@ -284,7 +284,7 @@ impl TraceTable { impl Trace for TraceTable { type BaseField = B; - fn get_info(&self) -> &TraceInfo { + fn info(&self) -> &TraceInfo { &self.info } From b27664befb920de77089a93e7b74a4d033e55ae9 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Tue, 20 Feb 2024 08:01:01 -0500 Subject: [PATCH 15/30] fmt --- prover/src/trace/trace_lde/default/tests.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/prover/src/trace/trace_lde/default/tests.rs b/prover/src/trace/trace_lde/default/tests.rs index 53d143758..6cc53b421 100644 --- a/prover/src/trace/trace_lde/default/tests.rs +++ b/prover/src/trace/trace_lde/default/tests.rs @@ -25,11 +25,8 @@ fn extend_trace_table() { let domain = StarkDomain::new(&air); // build the trace polynomials, extended trace, and commitment using the default TraceLde impl - let (trace_lde, trace_polys) = DefaultTraceLde::::new( - &trace.info(), - trace.main_segment(), - &domain, - ); + let (trace_lde, trace_polys) = + DefaultTraceLde::::new(&trace.info(), trace.main_segment(), &domain); // check the width and length of the extended trace assert_eq!(2, trace_lde.main_segment_width()); @@ -75,11 +72,8 @@ fn commit_trace_table() { let domain = StarkDomain::new(&air); // build the trace polynomials, extended trace, and commitment using the default TraceLde impl - let (trace_lde, _) = DefaultTraceLde::::new( - &trace.info(), - trace.main_segment(), - &domain, - ); + let (trace_lde, _) = + DefaultTraceLde::::new(&trace.info(), trace.main_segment(), &domain); // build Merkle tree from trace rows let mut hashed_states = Vec::new(); From d85700a14d16d93664ecb8f1d43722051d3ae6e9 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Tue, 20 Feb 2024 08:03:43 -0500 Subject: [PATCH 16/30] Reintroduce `Trace::length` --- prover/src/trace/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/prover/src/trace/mod.rs b/prover/src/trace/mod.rs index a463afeec..1d1ee63bb 100644 --- a/prover/src/trace/mod.rs +++ b/prover/src/trace/mod.rs @@ -65,8 +65,14 @@ pub trait Trace: Sized { /// Reads an evaluation frame from the main trace segment at the specified row. fn read_main_frame(&self, row_idx: usize, frame: &mut EvaluationFrame); - // VALIDATION + // PROVIDED METHODS // -------------------------------------------------------------------------------------------- + + /// Returns the number of rows in this trace. + fn length(&self) -> usize { + self.info().length() + } + /// Checks if this trace is valid against the specified AIR, and panics if not. /// /// NOTE: this is a very expensive operation and is intended for use only in debug mode. From eef2453dd4423e942b182f08a9dc279bc73d7eaf Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Tue, 20 Feb 2024 08:04:37 -0500 Subject: [PATCH 17/30] Fix docstrings --- README.md | 2 +- winterfell/src/lib.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5994dc547..137e9ad8a 100644 --- a/README.md +++ b/README.md @@ -269,7 +269,7 @@ impl Prover for WorkProver { // Our public inputs consist of the first and last value in the execution trace. fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { - let last_step = trace.get_info().length() - 1; + let last_step = trace.info().length() - 1; PublicInputs { start: trace.get(0, 0), result: trace.get(0, last_step), diff --git a/winterfell/src/lib.rs b/winterfell/src/lib.rs index 88f679461..4740984dd 100644 --- a/winterfell/src/lib.rs +++ b/winterfell/src/lib.rs @@ -349,7 +349,7 @@ //! //! // Our public inputs consist of the first and last value in the execution trace. //! fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { -//! let last_step = trace.get_info().length() - 1; +//! let last_step = trace.info().length() - 1; //! PublicInputs { //! start: trace.get(0, 0), //! result: trace.get(0, last_step), @@ -488,7 +488,7 @@ //! # DefaultConstraintEvaluator<'a, Self::Air, E>; //! # //! # fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { -//! # let last_step = trace.get_info().length() - 1; +//! # let last_step = trace.info().length() - 1; //! # PublicInputs { //! # start: trace.get(0, 0), //! # result: trace.get(0, last_step), From f854979c6c4d5d2251e384b27d91c20811668bea Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Tue, 20 Feb 2024 08:06:30 -0500 Subject: [PATCH 18/30] Use `Trace::length()` --- README.md | 2 +- examples/src/fibonacci/fib2/mod.rs | 2 +- examples/src/fibonacci/fib2/prover.rs | 2 +- examples/src/fibonacci/fib8/mod.rs | 2 +- examples/src/fibonacci/fib8/prover.rs | 2 +- examples/src/fibonacci/fib_small/mod.rs | 2 +- examples/src/fibonacci/fib_small/prover.rs | 2 +- examples/src/fibonacci/mulfib2/mod.rs | 2 +- examples/src/fibonacci/mulfib2/prover.rs | 2 +- examples/src/fibonacci/mulfib8/mod.rs | 2 +- examples/src/fibonacci/mulfib8/prover.rs | 2 +- examples/src/lamport/aggregate/mod.rs | 2 +- examples/src/lamport/threshold/mod.rs | 2 +- examples/src/merkle/mod.rs | 2 +- examples/src/merkle/prover.rs | 2 +- examples/src/rescue/mod.rs | 2 +- examples/src/rescue/prover.rs | 2 +- examples/src/rescue_raps/mod.rs | 2 +- examples/src/rescue_raps/prover.rs | 2 +- examples/src/utils/mod.rs | 2 +- examples/src/vdf/exempt/mod.rs | 2 +- examples/src/vdf/exempt/prover.rs | 2 +- examples/src/vdf/regular/mod.rs | 2 +- examples/src/vdf/regular/prover.rs | 2 +- prover/src/trace/mod.rs | 6 +++--- prover/src/trace/tests.rs | 2 +- winterfell/src/lib.rs | 4 ++-- 27 files changed, 30 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 137e9ad8a..ffc1c5d9d 100644 --- a/README.md +++ b/README.md @@ -269,7 +269,7 @@ impl Prover for WorkProver { // Our public inputs consist of the first and last value in the execution trace. fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { - let last_step = trace.info().length() - 1; + let last_step = trace.length() - 1; PublicInputs { start: trace.get(0, 0), result: trace.get(0, last_step), diff --git a/examples/src/fibonacci/fib2/mod.rs b/examples/src/fibonacci/fib2/mod.rs index 46e3ff7ff..c97ef8fde 100644 --- a/examples/src/fibonacci/fib2/mod.rs +++ b/examples/src/fibonacci/fib2/mod.rs @@ -101,7 +101,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(self.sequence_length); - tracing::Span::current().record("steps", trace.info().length()); + tracing::Span::current().record("steps", trace.length()); trace }); diff --git a/examples/src/fibonacci/fib2/prover.rs b/examples/src/fibonacci/fib2/prover.rs index bb818de30..83e089efb 100644 --- a/examples/src/fibonacci/fib2/prover.rs +++ b/examples/src/fibonacci/fib2/prover.rs @@ -64,7 +64,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { - let last_step = trace.info().length() - 1; + let last_step = trace.length() - 1; trace.get(1, last_step) } diff --git a/examples/src/fibonacci/fib8/mod.rs b/examples/src/fibonacci/fib8/mod.rs index 74b17f59f..866c4a084 100644 --- a/examples/src/fibonacci/fib8/mod.rs +++ b/examples/src/fibonacci/fib8/mod.rs @@ -101,7 +101,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(self.sequence_length); - tracing::Span::current().record("steps", trace.info().length()); + tracing::Span::current().record("steps", trace.length()); trace }); diff --git a/examples/src/fibonacci/fib8/prover.rs b/examples/src/fibonacci/fib8/prover.rs index dd65ecd45..026bef3db 100644 --- a/examples/src/fibonacci/fib8/prover.rs +++ b/examples/src/fibonacci/fib8/prover.rs @@ -79,7 +79,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { - let last_step = trace.info().length() - 1; + let last_step = trace.length() - 1; trace.get(1, last_step) } diff --git a/examples/src/fibonacci/fib_small/mod.rs b/examples/src/fibonacci/fib_small/mod.rs index c6a37b1cf..5b149a42f 100644 --- a/examples/src/fibonacci/fib_small/mod.rs +++ b/examples/src/fibonacci/fib_small/mod.rs @@ -116,7 +116,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(self.sequence_length); - tracing::Span::current().record("steps", trace.info().length()); + tracing::Span::current().record("steps", trace.length()); trace }); diff --git a/examples/src/fibonacci/fib_small/prover.rs b/examples/src/fibonacci/fib_small/prover.rs index 489aa5e3d..af0a6b40d 100644 --- a/examples/src/fibonacci/fib_small/prover.rs +++ b/examples/src/fibonacci/fib_small/prover.rs @@ -63,7 +63,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { - let last_step = trace.info().length() - 1; + let last_step = trace.length() - 1; trace.get(1, last_step) } diff --git a/examples/src/fibonacci/mulfib2/mod.rs b/examples/src/fibonacci/mulfib2/mod.rs index 2c02ea047..8abf025dc 100644 --- a/examples/src/fibonacci/mulfib2/mod.rs +++ b/examples/src/fibonacci/mulfib2/mod.rs @@ -101,7 +101,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(sequence_length); - tracing::Span::current().record("steps", trace.info().length()); + tracing::Span::current().record("steps", trace.length()); trace }); diff --git a/examples/src/fibonacci/mulfib2/prover.rs b/examples/src/fibonacci/mulfib2/prover.rs index cc4023623..b68e18cd7 100644 --- a/examples/src/fibonacci/mulfib2/prover.rs +++ b/examples/src/fibonacci/mulfib2/prover.rs @@ -60,7 +60,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { - let last_step = trace.info().length() - 1; + let last_step = trace.length() - 1; trace.get(0, last_step) } diff --git a/examples/src/fibonacci/mulfib8/mod.rs b/examples/src/fibonacci/mulfib8/mod.rs index 19b5ae2fe..b9763761a 100644 --- a/examples/src/fibonacci/mulfib8/mod.rs +++ b/examples/src/fibonacci/mulfib8/mod.rs @@ -102,7 +102,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(sequence_length); - tracing::Span::current().record("steps", trace.info().length()); + tracing::Span::current().record("steps", trace.length()); trace }); diff --git a/examples/src/fibonacci/mulfib8/prover.rs b/examples/src/fibonacci/mulfib8/prover.rs index a3d322ce9..744e71f91 100644 --- a/examples/src/fibonacci/mulfib8/prover.rs +++ b/examples/src/fibonacci/mulfib8/prover.rs @@ -72,7 +72,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { - let last_step = trace.info().length() - 1; + let last_step = trace.length() - 1; trace.get(6, last_step) } diff --git a/examples/src/lamport/aggregate/mod.rs b/examples/src/lamport/aggregate/mod.rs index b8029274a..765c4896d 100644 --- a/examples/src/lamport/aggregate/mod.rs +++ b/examples/src/lamport/aggregate/mod.rs @@ -127,7 +127,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(&self.messages, &self.signatures); - tracing::Span::current().record("steps", trace.info().length()); + tracing::Span::current().record("steps", trace.length()); trace }); diff --git a/examples/src/lamport/threshold/mod.rs b/examples/src/lamport/threshold/mod.rs index 974629af2..092433f07 100644 --- a/examples/src/lamport/threshold/mod.rs +++ b/examples/src/lamport/threshold/mod.rs @@ -133,7 +133,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(&self.pub_key, self.message, &self.signatures); - tracing::Span::current().record("steps", trace.info().length()); + tracing::Span::current().record("steps", trace.length()); trace }); diff --git a/examples/src/merkle/mod.rs b/examples/src/merkle/mod.rs index 0b6149a8f..d99d0dd78 100644 --- a/examples/src/merkle/mod.rs +++ b/examples/src/merkle/mod.rs @@ -121,7 +121,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(self.value, &self.path, self.index); - tracing::Span::current().record("steps", trace.info().length()); + tracing::Span::current().record("steps", trace.length()); trace }); diff --git a/examples/src/merkle/prover.rs b/examples/src/merkle/prover.rs index 619c9f9d8..d4dae42d2 100644 --- a/examples/src/merkle/prover.rs +++ b/examples/src/merkle/prover.rs @@ -113,7 +113,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { - let last_step = trace.info().length() - 1; + let last_step = trace.length() - 1; PublicInputs { tree_root: [trace.get(0, last_step), trace.get(1, last_step)], } diff --git a/examples/src/rescue/mod.rs b/examples/src/rescue/mod.rs index fe7af67f2..9f79fec96 100644 --- a/examples/src/rescue/mod.rs +++ b/examples/src/rescue/mod.rs @@ -106,7 +106,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(self.seed, self.chain_length); - tracing::Span::current().record("steps", trace.info().length()); + tracing::Span::current().record("steps", trace.length()); trace }); diff --git a/examples/src/rescue/prover.rs b/examples/src/rescue/prover.rs index b04ee28bf..4d2599062 100644 --- a/examples/src/rescue/prover.rs +++ b/examples/src/rescue/prover.rs @@ -79,7 +79,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { - let last_step = trace.info().length() - 1; + let last_step = trace.length() - 1; PublicInputs { seed: [trace.get(0, 0), trace.get(1, 0)], result: [trace.get(0, last_step), trace.get(1, last_step)], diff --git a/examples/src/rescue_raps/mod.rs b/examples/src/rescue_raps/mod.rs index e41a65c7a..33828eca1 100644 --- a/examples/src/rescue_raps/mod.rs +++ b/examples/src/rescue_raps/mod.rs @@ -119,7 +119,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = prover.build_trace(&self.seeds, &self.permuted_seeds, self.result); - tracing::Span::current().record("steps", trace.info().length()); + tracing::Span::current().record("steps", trace.length()); trace }); diff --git a/examples/src/rescue_raps/prover.rs b/examples/src/rescue_raps/prover.rs index b32196668..021f02319 100644 --- a/examples/src/rescue_raps/prover.rs +++ b/examples/src/rescue_raps/prover.rs @@ -107,7 +107,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { - let last_step = trace.info().length() - 1; + let last_step = trace.length() - 1; PublicInputs { result: [ [trace.get(0, last_step), trace.get(1, last_step)], diff --git a/examples/src/utils/mod.rs b/examples/src/utils/mod.rs index a3d9283ee..3fecfa6e9 100644 --- a/examples/src/utils/mod.rs +++ b/examples/src/utils/mod.rs @@ -67,7 +67,7 @@ pub fn print_trace( let trace_width = trace.width(); let mut state = vec![E::ZERO; trace_width]; - for i in 0..trace.info().length() { + for i in 0..trace.length() { if (i.wrapping_sub(offset)) % multiples_of != 0 { continue; } diff --git a/examples/src/vdf/exempt/mod.rs b/examples/src/vdf/exempt/mod.rs index 3b847d81e..66bef4f22 100644 --- a/examples/src/vdf/exempt/mod.rs +++ b/examples/src/vdf/exempt/mod.rs @@ -97,7 +97,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = VdfProver::::build_trace(self.seed, self.num_steps + 1); - tracing::Span::current().record("steps", trace.info().length()); + tracing::Span::current().record("steps", trace.length()); trace }); diff --git a/examples/src/vdf/exempt/prover.rs b/examples/src/vdf/exempt/prover.rs index 2c1e81278..9a83ff501 100644 --- a/examples/src/vdf/exempt/prover.rs +++ b/examples/src/vdf/exempt/prover.rs @@ -62,7 +62,7 @@ where fn get_pub_inputs(&self, trace: &Self::Trace) -> VdfInputs { // the result is read from the second to last step because the last last step contains // garbage - let second_to_last_step = trace.info().length() - 2; + let second_to_last_step = trace.length() - 2; VdfInputs { seed: trace.get(0, 0), result: trace.get(0, second_to_last_step), diff --git a/examples/src/vdf/regular/mod.rs b/examples/src/vdf/regular/mod.rs index 4402dca22..8b8ffb08c 100644 --- a/examples/src/vdf/regular/mod.rs +++ b/examples/src/vdf/regular/mod.rs @@ -94,7 +94,7 @@ where info_span!("generate_execution_trace", num_cols = TRACE_WIDTH, steps = field::Empty) .in_scope(|| { let trace = VdfProver::::build_trace(self.seed, self.num_steps); - tracing::Span::current().record("steps", trace.info().length()); + tracing::Span::current().record("steps", trace.length()); trace }); diff --git a/examples/src/vdf/regular/prover.rs b/examples/src/vdf/regular/prover.rs index f794c620b..e899ec3be 100644 --- a/examples/src/vdf/regular/prover.rs +++ b/examples/src/vdf/regular/prover.rs @@ -57,7 +57,7 @@ where DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> VdfInputs { - let last_step = trace.info().length() - 1; + let last_step = trace.length() - 1; VdfInputs { seed: trace.get(0, 0), result: trace.get(0, last_step), diff --git a/prover/src/trace/mod.rs b/prover/src/trace/mod.rs index 1d1ee63bb..511e8fa0b 100644 --- a/prover/src/trace/mod.rs +++ b/prover/src/trace/mod.rs @@ -98,7 +98,7 @@ pub trait Trace: Sized { // first, check assertions against the main segment of the execution trace for assertion in air.get_assertions() { - assertion.apply(self.info().length(), |step, value| { + assertion.apply(self.length(), |step, value| { assert!( value == self.main_segment().get(assertion.column(), step), "trace does not satisfy assertion main_trace({}, {}) == {}", @@ -125,7 +125,7 @@ pub trait Trace: Sized { } // get the matrix and verify the assertion against it - assertion.apply(self.info().length(), |step, value| { + assertion.apply(self.length(), |step, value| { assert!( value == aux_segments[segment_idx].get(column_idx, step), "trace does not satisfy assertion aux_trace({}, {}) == {}", @@ -157,7 +157,7 @@ pub trait Trace: Sized { // we check transition constraints on all steps except the last k steps, where k is the // number of steps exempt from transition constraints (guaranteed to be at least 1) - for step in 0..self.info().length() - air.context().num_transition_exemptions() { + for step in 0..self.length() - air.context().num_transition_exemptions() { // build periodic values for (p, v) in periodic_values_polys.iter().zip(periodic_values.iter_mut()) { let num_cycles = air.trace_length() / p.len(); diff --git a/prover/src/trace/tests.rs b/prover/src/trace/tests.rs index 9102aaac2..71665f592 100644 --- a/prover/src/trace/tests.rs +++ b/prover/src/trace/tests.rs @@ -13,7 +13,7 @@ fn new_trace_table() { let trace = build_fib_trace(trace_length * 2); assert_eq!(2, trace.info().main_trace_width()); - assert_eq!(8, trace.info().length()); + assert_eq!(8, trace.length()); let expected: Vec = vec![1u32, 2, 5, 13, 34, 89, 233, 610] .into_iter() diff --git a/winterfell/src/lib.rs b/winterfell/src/lib.rs index 4740984dd..804e3db25 100644 --- a/winterfell/src/lib.rs +++ b/winterfell/src/lib.rs @@ -349,7 +349,7 @@ //! //! // Our public inputs consist of the first and last value in the execution trace. //! fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { -//! let last_step = trace.info().length() - 1; +//! let last_step = trace.length() - 1; //! PublicInputs { //! start: trace.get(0, 0), //! result: trace.get(0, last_step), @@ -488,7 +488,7 @@ //! # DefaultConstraintEvaluator<'a, Self::Air, E>; //! # //! # fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { -//! # let last_step = trace.info().length() - 1; +//! # let last_step = trace.length() - 1; //! # PublicInputs { //! # start: trace.get(0, 0), //! # result: trace.get(0, last_step), From 9cdd508e66e77930adac4b4096b9f050a346a355 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Tue, 20 Feb 2024 08:14:28 -0500 Subject: [PATCH 19/30] Reintroduce `Trace::{main,aux}_trace_width()` --- prover/src/trace/mod.rs | 18 ++++++++++++++---- prover/src/trace/tests.rs | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/prover/src/trace/mod.rs b/prover/src/trace/mod.rs index 511e8fa0b..8c0ab411c 100644 --- a/prover/src/trace/mod.rs +++ b/prover/src/trace/mod.rs @@ -73,6 +73,16 @@ pub trait Trace: Sized { self.info().length() } + /// Returns the number of columns in the main segment of this trace. + fn main_trace_width(&self) -> usize { + self.info().main_trace_width() + } + + /// Returns the number of columns in all auxiliary trace segments. + fn aux_trace_width(&self) -> usize { + self.info().aux_trace_width() + } + /// Checks if this trace is valid against the specified AIR, and panics if not. /// /// NOTE: this is a very expensive operation and is intended for use only in debug mode. @@ -87,10 +97,10 @@ pub trait Trace: Sized { { // make sure the width align; if they don't something went terribly wrong assert_eq!( - self.info().main_trace_width(), + self.main_trace_width(), air.trace_info().main_trace_width(), "inconsistent trace width: expected {}, but was {}", - self.info().main_trace_width(), + self.main_trace_width(), air.trace_info().main_trace_width(), ); @@ -145,9 +155,9 @@ pub trait Trace: Sized { // initialize buffers to hold evaluation frames and results of constraint evaluations let mut x = Self::BaseField::ONE; - let mut main_frame = EvaluationFrame::new(self.info().main_trace_width()); + let mut main_frame = EvaluationFrame::new(self.main_trace_width()); let mut aux_frame = if air.trace_info().is_multi_segment() { - Some(EvaluationFrame::::new(self.info().aux_trace_width())) + Some(EvaluationFrame::::new(self.aux_trace_width())) } else { None }; diff --git a/prover/src/trace/tests.rs b/prover/src/trace/tests.rs index 71665f592..29460705b 100644 --- a/prover/src/trace/tests.rs +++ b/prover/src/trace/tests.rs @@ -12,7 +12,7 @@ fn new_trace_table() { let trace_length = 8; let trace = build_fib_trace(trace_length * 2); - assert_eq!(2, trace.info().main_trace_width()); + assert_eq!(2, trace.main_trace_width()); assert_eq!(8, trace.length()); let expected: Vec = vec![1u32, 2, 5, 13, 34, 89, 233, 610] From 9d3296fd2c3ea999c3b51a3665a5d6bc2b732270 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Tue, 20 Feb 2024 08:22:22 -0500 Subject: [PATCH 20/30] update docstrings --- prover/src/trace/trace_lde/default/mod.rs | 2 +- prover/src/trace/trace_lde/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/prover/src/trace/trace_lde/default/mod.rs b/prover/src/trace/trace_lde/default/mod.rs index 6fdba625d..d6a160ff6 100644 --- a/prover/src/trace/trace_lde/default/mod.rs +++ b/prover/src/trace/trace_lde/default/mod.rs @@ -202,7 +202,7 @@ where self.blowup } - /// Returns the trace layout of the execution trace. + /// Returns the trace info of the execution trace. fn trace_info(&self) -> &TraceInfo { &self.trace_info } diff --git a/prover/src/trace/trace_lde/mod.rs b/prover/src/trace/trace_lde/mod.rs index c54c947c0..0a552178a 100644 --- a/prover/src/trace/trace_lde/mod.rs +++ b/prover/src/trace/trace_lde/mod.rs @@ -66,6 +66,6 @@ pub trait TraceLde: Sync { /// Returns blowup factor which was used to extend original execution trace into trace LDE. fn blowup(&self) -> usize; - /// Returns the trace layout of the execution trace. + /// Returns the trace info of the execution trace. fn trace_info(&self) -> &TraceInfo; } From 81cde9d625028f61864e3668ff45c6e8fbda7056 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Tue, 20 Feb 2024 08:27:37 -0500 Subject: [PATCH 21/30] reorg `StarkField` methods --- math/src/field/traits.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/math/src/field/traits.rs b/math/src/field/traits.rs index e6dd22094..bc0393c52 100644 --- a/math/src/field/traits.rs +++ b/math/src/field/traits.rs @@ -230,6 +230,9 @@ pub trait FieldElement: /// the modulus of the field should be a prime number of the form `k` * 2^`n` + 1 (a Proth prime), /// where `n` is relatively large (e.g., greater than 32). pub trait StarkField: FieldElement { + // CONSTANTS + // ============================================================================================= + /// Prime modulus of the field. Must be of the form `k` * 2^`n` + 1 (a Proth prime). /// This ensures that the field has high 2-adicity. const MODULUS: Self::PositiveInteger; @@ -247,6 +250,18 @@ pub trait StarkField: FieldElement { /// computed as Self::GENERATOR^`k`. const TWO_ADIC_ROOT_OF_UNITY: Self; + // REQUIRED METHODS + // ============================================================================================= + + /// Returns byte representation of the field modulus in little-endian byte order. + fn get_modulus_le_bytes() -> Vec; + + /// Returns a canonical integer representation of this field element. + fn as_int(&self) -> Self::PositiveInteger; + + // PROVIDED METHODS + // ============================================================================================= + /// Returns the root of unity of order 2^`n`. /// /// # Panics @@ -258,11 +273,6 @@ pub trait StarkField: FieldElement { Self::TWO_ADIC_ROOT_OF_UNITY.exp(power) } - /// Returns byte representation of the field modulus in little-endian byte order. - fn get_modulus_le_bytes() -> Vec; - - /// Returns a canonical integer representation of this field element. - fn as_int(&self) -> Self::PositiveInteger; } // EXTENSIBLE FIELD From 8359b0025a87985eefa81923967869f86d0f1638 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Tue, 20 Feb 2024 08:30:00 -0500 Subject: [PATCH 22/30] Introduce `StarkField::from_byte_vec_with_padding` --- math/src/field/traits.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/math/src/field/traits.rs b/math/src/field/traits.rs index bc0393c52..dcd3c3140 100644 --- a/math/src/field/traits.rs +++ b/math/src/field/traits.rs @@ -273,6 +273,21 @@ pub trait StarkField: FieldElement { Self::TWO_ADIC_ROOT_OF_UNITY.exp(power) } + /// Converts a slice of bytes into a field element. Pads the slice if it is smaller than the number + /// of bytes needed to represent an element. + /// + /// # Panics + /// Panics if the length of `bytes` is smaller than the number of bytes needed to encode an element. + fn from_byte_vec_with_padding(mut bytes: Vec) -> Self { + assert!(bytes.len() < Self::ELEMENT_BYTES); + + bytes.resize(Self::ELEMENT_BYTES, 0); + + match Self::try_from(bytes.as_slice()) { + Ok(element) => element, + Err(_) => panic!("element deserialization failed"), + } + } } // EXTENSIBLE FIELD From 44b4961d1bd620fb61c9c6a295c8088f02f86725 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Tue, 20 Feb 2024 08:31:24 -0500 Subject: [PATCH 23/30] Use `StarkField::from_byte_vec_with_padding` --- air/src/air/trace_info.rs | 4 ++-- air/src/proof/context.rs | 6 +++--- math/src/lib.rs | 3 +-- math/src/utils/mod.rs | 21 +-------------------- 4 files changed, 7 insertions(+), 27 deletions(-) diff --git a/air/src/air/trace_info.rs b/air/src/air/trace_info.rs index f2d038bf0..85f6453bf 100644 --- a/air/src/air/trace_info.rs +++ b/air/src/air/trace_info.rs @@ -3,7 +3,7 @@ // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. -use math::{bytes_to_element_with_padding, StarkField, ToElements}; +use math::{StarkField, ToElements}; use utils::{ collections::Vec, string::ToString, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable, @@ -254,7 +254,7 @@ impl ToElements for TraceInfo { // element, and then converting these chunks into field elements. if !self.trace_meta.is_empty() { for chunk in self.trace_meta.chunks(E::ELEMENT_BYTES - 1) { - result.push(bytes_to_element_with_padding(chunk.to_vec())); + result.push(E::from_byte_vec_with_padding(chunk.to_vec())); } } diff --git a/air/src/proof/context.rs b/air/src/proof/context.rs index 6edc2d1df..f34c45274 100644 --- a/air/src/proof/context.rs +++ b/air/src/proof/context.rs @@ -4,7 +4,7 @@ // LICENSE file in the root directory of this source tree. use crate::{ProofOptions, TraceInfo}; -use math::{bytes_to_element_with_padding, StarkField, ToElements}; +use math::{StarkField, ToElements}; use utils::{ collections::Vec, string::ToString, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable, @@ -103,8 +103,8 @@ impl ToElements for Context { // convert field modulus bytes into 2 elements let num_modulus_bytes = self.field_modulus_bytes.len(); let (m1, m2) = self.field_modulus_bytes.split_at(num_modulus_bytes / 2); - result.push(bytes_to_element_with_padding(m1.to_vec())); - result.push(bytes_to_element_with_padding(m2.to_vec())); + result.push(E::from_byte_vec_with_padding(m1.to_vec())); + result.push(E::from_byte_vec_with_padding(m2.to_vec())); // convert proof options to elements result.append(&mut self.options.to_elements()); diff --git a/math/src/lib.rs b/math/src/lib.rs index 260dba73a..3d35c1c39 100644 --- a/math/src/lib.rs +++ b/math/src/lib.rs @@ -113,6 +113,5 @@ pub mod fields { mod utils; pub use crate::utils::{ - add_in_place, batch_inversion, bytes_to_element_with_padding, get_power_series, - get_power_series_with_offset, log2, mul_acc, + add_in_place, batch_inversion, get_power_series, get_power_series_with_offset, log2, mul_acc, }; diff --git a/math/src/utils/mod.rs b/math/src/utils/mod.rs index e02fe7c41..fab0512dd 100644 --- a/math/src/utils/mod.rs +++ b/math/src/utils/mod.rs @@ -3,7 +3,7 @@ // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. -use crate::{field::FieldElement, ExtensionOf, StarkField}; +use crate::{field::FieldElement, ExtensionOf}; use utils::{batch_iter_mut, collections::Vec, iter_mut, uninit_vector}; #[cfg(feature = "concurrent")] @@ -199,25 +199,6 @@ pub fn log2(n: usize) -> u32 { n.trailing_zeros() } -// CONVERSION FUNCTIONS -// ================================================================================================ - -/// Converts a slice of bytes into a field element. Pads the slice if it is smaller than the number -/// of bytes needed to represent an element. -/// -/// # Panics -/// Panics if the length of `bytes` is smaller than the number of bytes needed to encode an element. -pub fn bytes_to_element_with_padding(mut bytes: Vec) -> B { - assert!(bytes.len() < B::ELEMENT_BYTES); - - bytes.resize(B::ELEMENT_BYTES, 0); - - match B::try_from(bytes.as_slice()) { - Ok(element) => element, - Err(_) => panic!("element deserialization failed"), - } -} - // HELPER FUNCTIONS // ------------------------------------------------------------------------------------------------ From 2ac004ca4acec2deb0cd8f9ea25f9c1ce4b64f8a Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Wed, 21 Feb 2024 08:47:48 -0500 Subject: [PATCH 24/30] docstring --- math/src/field/traits.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/math/src/field/traits.rs b/math/src/field/traits.rs index dcd3c3140..5f61755ab 100644 --- a/math/src/field/traits.rs +++ b/math/src/field/traits.rs @@ -277,7 +277,9 @@ pub trait StarkField: FieldElement { /// of bytes needed to represent an element. /// /// # Panics - /// Panics if the length of `bytes` is smaller than the number of bytes needed to encode an element. + /// Panics if + /// - the length of `bytes` is greater than the number of bytes needed to encode an element. + /// - the value of the bytes is not a valid field element after padding fn from_byte_vec_with_padding(mut bytes: Vec) -> Self { assert!(bytes.len() < Self::ELEMENT_BYTES); From 0f189b2653522773e73a39c047ce19fea41207b2 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Wed, 21 Feb 2024 08:49:36 -0500 Subject: [PATCH 25/30] docstring fix --- air/src/proof/context.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/air/src/proof/context.rs b/air/src/proof/context.rs index f34c45274..e3fdaacdc 100644 --- a/air/src/proof/context.rs +++ b/air/src/proof/context.rs @@ -90,7 +90,7 @@ impl ToElements for Context { /// Converts this [Context] into a vector of field elements. /// /// The elements are laid out as follows: - /// - trace info [1 or more elements]. + /// - trace info [2 or more elements]. /// - field modulus bytes [2 field elements]. /// - field extension and FRI parameters [1 element]. /// - grinding factor [1 element]. From 8acf5c8e96bd5ebbf63b94abf895051f5363650a Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Wed, 21 Feb 2024 08:50:42 -0500 Subject: [PATCH 26/30] fix internal section separator --- math/src/field/traits.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/math/src/field/traits.rs b/math/src/field/traits.rs index 5f61755ab..672aeb1c4 100644 --- a/math/src/field/traits.rs +++ b/math/src/field/traits.rs @@ -231,7 +231,7 @@ pub trait FieldElement: /// where `n` is relatively large (e.g., greater than 32). pub trait StarkField: FieldElement { // CONSTANTS - // ============================================================================================= + //---------------------------------------------------------------------------------------------- /// Prime modulus of the field. Must be of the form `k` * 2^`n` + 1 (a Proth prime). /// This ensures that the field has high 2-adicity. @@ -251,7 +251,7 @@ pub trait StarkField: FieldElement { const TWO_ADIC_ROOT_OF_UNITY: Self; // REQUIRED METHODS - // ============================================================================================= + //---------------------------------------------------------------------------------------------- /// Returns byte representation of the field modulus in little-endian byte order. fn get_modulus_le_bytes() -> Vec; @@ -260,7 +260,7 @@ pub trait StarkField: FieldElement { fn as_int(&self) -> Self::PositiveInteger; // PROVIDED METHODS - // ============================================================================================= + //---------------------------------------------------------------------------------------------- /// Returns the root of unity of order 2^`n`. /// From b4286653ef2a1e9a28a2694a5d6c5207f29de84d Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Wed, 21 Feb 2024 09:04:57 -0500 Subject: [PATCH 27/30] add comment --- air/src/air/trace_info.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/air/src/air/trace_info.rs b/air/src/air/trace_info.rs index 85f6453bf..4facbef73 100644 --- a/air/src/air/trace_info.rs +++ b/air/src/air/trace_info.rs @@ -247,6 +247,7 @@ impl ToElements for TraceInfo { result.push(E::from(buf)); } + // We assume here that the trace length is never greater than 2^32. result.push(E::from(self.trace_length as u32)); // convert trace metadata to elements; this is done by breaking trace metadata into chunks From e7d2511343581c1c04c2a995b128adb61c833ea7 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Wed, 21 Feb 2024 14:02:59 -0500 Subject: [PATCH 28/30] Change `from_bytes_with_padding` signature --- air/src/air/trace_info.rs | 2 +- air/src/proof/context.rs | 4 ++-- math/src/field/traits.rs | 13 ++++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/air/src/air/trace_info.rs b/air/src/air/trace_info.rs index 4facbef73..45ef6ba88 100644 --- a/air/src/air/trace_info.rs +++ b/air/src/air/trace_info.rs @@ -255,7 +255,7 @@ impl ToElements for TraceInfo { // element, and then converting these chunks into field elements. if !self.trace_meta.is_empty() { for chunk in self.trace_meta.chunks(E::ELEMENT_BYTES - 1) { - result.push(E::from_byte_vec_with_padding(chunk.to_vec())); + result.push(E::from_byte_vec_with_padding(chunk)); } } diff --git a/air/src/proof/context.rs b/air/src/proof/context.rs index e3fdaacdc..4f6d8209c 100644 --- a/air/src/proof/context.rs +++ b/air/src/proof/context.rs @@ -103,8 +103,8 @@ impl ToElements for Context { // convert field modulus bytes into 2 elements let num_modulus_bytes = self.field_modulus_bytes.len(); let (m1, m2) = self.field_modulus_bytes.split_at(num_modulus_bytes / 2); - result.push(E::from_byte_vec_with_padding(m1.to_vec())); - result.push(E::from_byte_vec_with_padding(m2.to_vec())); + result.push(E::from_byte_vec_with_padding(m1)); + result.push(E::from_byte_vec_with_padding(m2)); // convert proof options to elements result.append(&mut self.options.to_elements()); diff --git a/math/src/field/traits.rs b/math/src/field/traits.rs index 672aeb1c4..f202554ed 100644 --- a/math/src/field/traits.rs +++ b/math/src/field/traits.rs @@ -277,18 +277,21 @@ pub trait StarkField: FieldElement { /// of bytes needed to represent an element. /// /// # Panics - /// Panics if + /// Panics if /// - the length of `bytes` is greater than the number of bytes needed to encode an element. /// - the value of the bytes is not a valid field element after padding - fn from_byte_vec_with_padding(mut bytes: Vec) -> Self { + fn from_byte_vec_with_padding(bytes: &[u8]) -> Self { assert!(bytes.len() < Self::ELEMENT_BYTES); - bytes.resize(Self::ELEMENT_BYTES, 0); + let mut buf = bytes.to_vec(); + buf.resize(Self::ELEMENT_BYTES, 0); - match Self::try_from(bytes.as_slice()) { + let element = match Self::try_from(buf.as_slice()) { Ok(element) => element, Err(_) => panic!("element deserialization failed"), - } + }; + + element } } From 35742d60f0205c848e7d360348e449b9f76c12e8 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Wed, 21 Feb 2024 16:45:04 -0500 Subject: [PATCH 29/30] rename fn --- air/src/air/trace_info.rs | 2 +- air/src/proof/context.rs | 4 ++-- math/src/field/traits.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/air/src/air/trace_info.rs b/air/src/air/trace_info.rs index ba4b0d0c7..d433f3114 100644 --- a/air/src/air/trace_info.rs +++ b/air/src/air/trace_info.rs @@ -255,7 +255,7 @@ impl ToElements for TraceInfo { // element, and then converting these chunks into field elements. if !self.trace_meta.is_empty() { for chunk in self.trace_meta.chunks(E::ELEMENT_BYTES - 1) { - result.push(E::from_byte_vec_with_padding(chunk)); + result.push(E::from_byte_with_padding(chunk)); } } diff --git a/air/src/proof/context.rs b/air/src/proof/context.rs index 01f226e4f..6c0f7829f 100644 --- a/air/src/proof/context.rs +++ b/air/src/proof/context.rs @@ -103,8 +103,8 @@ impl ToElements for Context { // convert field modulus bytes into 2 elements let num_modulus_bytes = self.field_modulus_bytes.len(); let (m1, m2) = self.field_modulus_bytes.split_at(num_modulus_bytes / 2); - result.push(E::from_byte_vec_with_padding(m1)); - result.push(E::from_byte_vec_with_padding(m2)); + result.push(E::from_byte_with_padding(m1)); + result.push(E::from_byte_with_padding(m2)); // convert proof options to elements result.append(&mut self.options.to_elements()); diff --git a/math/src/field/traits.rs b/math/src/field/traits.rs index 898c3d6ee..826b90bf4 100644 --- a/math/src/field/traits.rs +++ b/math/src/field/traits.rs @@ -279,7 +279,7 @@ pub trait StarkField: FieldElement { /// Panics if /// - the length of `bytes` is greater than the number of bytes needed to encode an element. /// - the value of the bytes is not a valid field element after padding - fn from_byte_vec_with_padding(bytes: &[u8]) -> Self { + fn from_byte_with_padding(bytes: &[u8]) -> Self { assert!(bytes.len() < Self::ELEMENT_BYTES); let mut buf = bytes.to_vec(); From 5f945a582b9f5163be11a77ca63f16c481a09fe9 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Wed, 21 Feb 2024 16:45:33 -0500 Subject: [PATCH 30/30] fix typo --- air/src/air/trace_info.rs | 2 +- air/src/proof/context.rs | 4 ++-- math/src/field/traits.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/air/src/air/trace_info.rs b/air/src/air/trace_info.rs index d433f3114..6dde88af9 100644 --- a/air/src/air/trace_info.rs +++ b/air/src/air/trace_info.rs @@ -255,7 +255,7 @@ impl ToElements for TraceInfo { // element, and then converting these chunks into field elements. if !self.trace_meta.is_empty() { for chunk in self.trace_meta.chunks(E::ELEMENT_BYTES - 1) { - result.push(E::from_byte_with_padding(chunk)); + result.push(E::from_bytes_with_padding(chunk)); } } diff --git a/air/src/proof/context.rs b/air/src/proof/context.rs index 6c0f7829f..92b28ff65 100644 --- a/air/src/proof/context.rs +++ b/air/src/proof/context.rs @@ -103,8 +103,8 @@ impl ToElements for Context { // convert field modulus bytes into 2 elements let num_modulus_bytes = self.field_modulus_bytes.len(); let (m1, m2) = self.field_modulus_bytes.split_at(num_modulus_bytes / 2); - result.push(E::from_byte_with_padding(m1)); - result.push(E::from_byte_with_padding(m2)); + result.push(E::from_bytes_with_padding(m1)); + result.push(E::from_bytes_with_padding(m2)); // convert proof options to elements result.append(&mut self.options.to_elements()); diff --git a/math/src/field/traits.rs b/math/src/field/traits.rs index 826b90bf4..842f4fe2e 100644 --- a/math/src/field/traits.rs +++ b/math/src/field/traits.rs @@ -279,7 +279,7 @@ pub trait StarkField: FieldElement { /// Panics if /// - the length of `bytes` is greater than the number of bytes needed to encode an element. /// - the value of the bytes is not a valid field element after padding - fn from_byte_with_padding(bytes: &[u8]) -> Self { + fn from_bytes_with_padding(bytes: &[u8]) -> Self { assert!(bytes.len() < Self::ELEMENT_BYTES); let mut buf = bytes.to_vec();