From bdcaf3954711cc7b2653dc4796a3e6059756796b Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 2 Dec 2024 15:31:31 -0500 Subject: [PATCH 01/64] new values! macro + tests --- macros/src/lib.rs | 135 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 2 deletions(-) diff --git a/macros/src/lib.rs b/macros/src/lib.rs index ede1ec17..d4a9cf10 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -2,9 +2,8 @@ use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; use quote::{quote, format_ident, ToTokens}; use syn::{ - parse2, parse::{Parse, ParseStream}, - Ident, Generics, FieldsNamed, Result, Field, Token, + parse2, Field, FieldsNamed, Generics, Ident, Result, Token, }; #[proc_macro] @@ -232,6 +231,74 @@ fn calculate_field_size_literal(field_type: &syn::Type) -> Result { } } +#[proc_macro] +pub fn values(input: TokenStream) -> TokenStream { + match values_impl(input.into()) { + Ok(tokens) => tokens.into(), + Err(e) => e.to_compile_error().into(), + } +} + +fn values_impl(input: TokenStream2) -> Result { + let parsed_input: ParsedValuesInput = parse2(input)?; + + let struct_name = parsed_input.struct_name; + let generic_param = parsed_input.generic_param; + + // Generate the struct and implementation + let result = quote! { + pub struct #struct_name<#generic_param> { + pub buffer: Vec<#generic_param>, + pub x: usize, + } + + impl<#generic_param: Clone> #struct_name<#generic_param> { + pub fn new(x: usize) -> Self { + #struct_name { + buffer: Vec::new(), + x, + } + } + + pub fn set_value(&mut self, value: #generic_param) { + self.buffer.resize(self.x, value); + } + + pub fn set_values(&mut self, values: Vec<#generic_param>) { + assert_eq!( + values.len(), + self.x, + "Number of values must match the size parameter `x`." + ); + self.buffer = values; + } + + pub fn get_buffer(&self) -> &[#generic_param] { + &self.buffer + } + } + }; + + Ok(result) +} + +struct ParsedValuesInput { + pub struct_name: Ident, + pub generic_param: Ident, +} + +impl Parse for ParsedValuesInput { + fn parse(input: ParseStream) -> Result { + let struct_name: Ident = input.parse()?; + input.parse::()?; + let generic_param: Ident = input.parse()?; + input.parse::]>()?; + input.parse::()?; // Expect a semicolon to terminate the macro input + + Ok(ParsedValuesInput { struct_name, generic_param }) + } +} + #[test] fn test_trace_macro_generates_default_row_struct() { let input = quote! { @@ -549,3 +616,67 @@ fn test_empty_array() { let size = calculate_field_size_literal(&ty).unwrap(); assert_eq!(size, 0); } + +#[test] +fn test_parsed_values_basic() { + let input = quote! { + U8AirAirValuesVals; + }; + + let parsed: ParsedValuesInput = syn::parse2(input).unwrap(); + + assert_eq!(parsed.struct_name, "U8AirAirValuesVals"); + assert_eq!(parsed.generic_param, "F"); +} + +#[test] +fn test_parsed_values_complex_name() { + let input = quote! { + FibonacciSquareValues; + }; + + let parsed: ParsedValuesInput = syn::parse2(input).unwrap(); + + assert_eq!(parsed.struct_name, "FibonacciSquareValues"); + assert_eq!(parsed.generic_param, "F"); +} + +#[test] +#[should_panic(expected = "expected `;`")] +fn test_parsed_values_missing_semicolon() { + let input = quote! { + U8AirAirValuesVals + }; + + let _parsed: ParsedValuesInput = syn::parse2(input).unwrap(); +} + +#[test] +#[should_panic(expected = "expected `<`")] +fn test_parsed_values_missing_generic_param() { + let input = quote! { + U8AirAirValuesVals; + }; + + let _parsed: ParsedValuesInput = syn::parse2(input).unwrap(); +} + +#[test] +#[should_panic(expected = "expected `;`")] +fn test_parsed_values_invalid_syntax() { + let input = quote! { + U8AirAirValuesVals < F > extra; + }; + + let _parsed: ParsedValuesInput = syn::parse2(input).unwrap(); +} + +#[test] +#[should_panic(expected = "expected `>`")] +fn test_parsed_values_multiple_generics() { + let input = quote! { + U8AirAirValuesVals; + }; + + let _parsed: ParsedValuesInput = syn::parse2(input).unwrap(); +} From 4a3623c853925d21db057657e590213d311fc329 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 3 Dec 2024 15:04:58 -0500 Subject: [PATCH 02/64] upgrade parsing --- macros/src/lib.rs | 71 ++++------------------------------------------- 1 file changed, 6 insertions(+), 65 deletions(-) diff --git a/macros/src/lib.rs b/macros/src/lib.rs index d4a9cf10..a0a68fd0 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -2,6 +2,7 @@ use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; use quote::{quote, format_ident, ToTokens}; use syn::{ + LitInt, parse::{Parse, ParseStream}, parse2, Field, FieldsNamed, Generics, Ident, Result, Token, }; @@ -244,6 +245,7 @@ fn values_impl(input: TokenStream2) -> Result { let struct_name = parsed_input.struct_name; let generic_param = parsed_input.generic_param; + let dimensions = parsed_input.dimensions; // Generate the struct and implementation let result = quote! { @@ -285,6 +287,7 @@ fn values_impl(input: TokenStream2) -> Result { struct ParsedValuesInput { pub struct_name: Ident, pub generic_param: Ident, + pub dimensions: usize, } impl Parse for ParsedValuesInput { @@ -292,10 +295,12 @@ impl Parse for ParsedValuesInput { let struct_name: Ident = input.parse()?; input.parse::()?; let generic_param: Ident = input.parse()?; + input.parse::()?; + let dimensions: LitInt = input.parse()?; input.parse::]>()?; input.parse::()?; // Expect a semicolon to terminate the macro input - Ok(ParsedValuesInput { struct_name, generic_param }) + Ok(ParsedValuesInput { struct_name, generic_param, dimensions: dimensions.base10_parse()? }) } } @@ -616,67 +621,3 @@ fn test_empty_array() { let size = calculate_field_size_literal(&ty).unwrap(); assert_eq!(size, 0); } - -#[test] -fn test_parsed_values_basic() { - let input = quote! { - U8AirAirValuesVals; - }; - - let parsed: ParsedValuesInput = syn::parse2(input).unwrap(); - - assert_eq!(parsed.struct_name, "U8AirAirValuesVals"); - assert_eq!(parsed.generic_param, "F"); -} - -#[test] -fn test_parsed_values_complex_name() { - let input = quote! { - FibonacciSquareValues; - }; - - let parsed: ParsedValuesInput = syn::parse2(input).unwrap(); - - assert_eq!(parsed.struct_name, "FibonacciSquareValues"); - assert_eq!(parsed.generic_param, "F"); -} - -#[test] -#[should_panic(expected = "expected `;`")] -fn test_parsed_values_missing_semicolon() { - let input = quote! { - U8AirAirValuesVals - }; - - let _parsed: ParsedValuesInput = syn::parse2(input).unwrap(); -} - -#[test] -#[should_panic(expected = "expected `<`")] -fn test_parsed_values_missing_generic_param() { - let input = quote! { - U8AirAirValuesVals; - }; - - let _parsed: ParsedValuesInput = syn::parse2(input).unwrap(); -} - -#[test] -#[should_panic(expected = "expected `;`")] -fn test_parsed_values_invalid_syntax() { - let input = quote! { - U8AirAirValuesVals < F > extra; - }; - - let _parsed: ParsedValuesInput = syn::parse2(input).unwrap(); -} - -#[test] -#[should_panic(expected = "expected `>`")] -fn test_parsed_values_multiple_generics() { - let input = quote! { - U8AirAirValuesVals; - }; - - let _parsed: ParsedValuesInput = syn::parse2(input).unwrap(); -} From db76716f5da68ff83fd3e6629fc5f18173a09c13 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 3 Dec 2024 15:05:16 -0500 Subject: [PATCH 03/64] WIP From c909bac811390b638476c14015cb7effc725f063 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 4 Dec 2024 11:36:00 -0500 Subject: [PATCH 04/64] also parse fields --- macros/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/macros/src/lib.rs b/macros/src/lib.rs index a0a68fd0..67796ca1 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -246,6 +246,7 @@ fn values_impl(input: TokenStream2) -> Result { let struct_name = parsed_input.struct_name; let generic_param = parsed_input.generic_param; let dimensions = parsed_input.dimensions; + let fields = parsed_input.fields; // Generate the struct and implementation let result = quote! { @@ -288,6 +289,7 @@ struct ParsedValuesInput { pub struct_name: Ident, pub generic_param: Ident, pub dimensions: usize, + pub fields: FieldsNamed, } impl Parse for ParsedValuesInput { @@ -299,8 +301,8 @@ impl Parse for ParsedValuesInput { let dimensions: LitInt = input.parse()?; input.parse::]>()?; input.parse::()?; // Expect a semicolon to terminate the macro input - - Ok(ParsedValuesInput { struct_name, generic_param, dimensions: dimensions.base10_parse()? }) + let fields: FieldsNamed = input.parse()?; + Ok(ParsedValuesInput { struct_name, generic_param, dimensions: dimensions.base10_parse()?, fields }) } } From 1dfbf6a76a8dde910dde980ea46acba0042b18df Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 4 Dec 2024 12:09:30 -0500 Subject: [PATCH 05/64] fix parsing --- macros/src/lib.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 67796ca1..6a043e0e 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -300,12 +300,22 @@ impl Parse for ParsedValuesInput { input.parse::()?; let dimensions: LitInt = input.parse()?; input.parse::]>()?; - input.parse::()?; // Expect a semicolon to terminate the macro input let fields: FieldsNamed = input.parse()?; Ok(ParsedValuesInput { struct_name, generic_param, dimensions: dimensions.base10_parse()?, fields }) } } +#[test] +fn test_parse_values_01() { + let input = quote! { + Values { a: F, b: F } + }; + let parsed: ParsedValuesInput = parse2(input).unwrap(); + assert_eq!(parsed.struct_name, "Values"); + assert_eq!(parsed.generic_param, "F"); + assert_eq!(parsed.dimensions, 3); +} + #[test] fn test_trace_macro_generates_default_row_struct() { let input = quote! { From d8773b7b7893186efd5f849c842a66cfcf608dcd Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 4 Dec 2024 12:12:52 -0500 Subject: [PATCH 06/64] add more tests --- macros/src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 6a043e0e..fbeb8007 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -316,6 +316,28 @@ fn test_parse_values_01() { assert_eq!(parsed.dimensions, 3); } +#[test] +fn test_parse_values_02() { + let input = quote! { + Something { a: G } + }; + let parsed: ParsedValuesInput = parse2(input).unwrap(); + assert_eq!(parsed.struct_name, "Something"); + assert_eq!(parsed.generic_param, "G"); + assert_eq!(parsed.dimensions, 2); +} + +#[test] +fn test_parse_values_03() { + let input = quote! { + Something { a: G, b: [G; 4] } + }; + let parsed: ParsedValuesInput = parse2(input).unwrap(); + assert_eq!(parsed.struct_name, "Something"); + assert_eq!(parsed.generic_param, "G"); + assert_eq!(parsed.dimensions, 189_432); +} + #[test] fn test_trace_macro_generates_default_row_struct() { let input = quote! { From 041c7ab252ce17b7efe97e03ee21cc07ce590ec7 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 4 Dec 2024 13:43:07 -0500 Subject: [PATCH 07/64] num_rows --- macros/src/lib.rs | 269 +++++----------------------------------------- 1 file changed, 29 insertions(+), 240 deletions(-) diff --git a/macros/src/lib.rs b/macros/src/lib.rs index fbeb8007..a36a063e 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -2,9 +2,8 @@ use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; use quote::{quote, format_ident, ToTokens}; use syn::{ - LitInt, parse::{Parse, ParseStream}, - parse2, Field, FieldsNamed, Generics, Ident, Result, Token, + parse2, Field, FieldsNamed, Generics, Ident, LitInt, LitStr, Result, Token, }; #[proc_macro] @@ -22,6 +21,8 @@ fn trace_impl(input: TokenStream2) -> Result { let trace_struct_name = parsed_input.struct_name; let generics = parsed_input.generics.params; let fields = parsed_input.fields; + let num_rows = parsed_input.num_rows; + let commit_id = parsed_input.commit_id; // Calculate ROW_SIZE based on the field types let row_size = fields @@ -64,11 +65,15 @@ fn trace_impl(input: TokenStream2) -> Result { pub struct #trace_struct_name<'a, #generics> { pub buffer: Option>, pub slice_trace: &'a mut [#row_struct_name<#generics>], - num_rows: usize, + pub num_rows: usize, + pub commit_id: Option<&'a str>, } impl<'a, #generics: Default + Clone + Copy> #trace_struct_name<'a, #generics> { - pub fn new(num_rows: usize) -> Self { + const NUM_ROWS: usize = #num_rows; + + pub fn new() -> Self { + let num_rows = Self::NUM_ROWS; assert!(num_rows >= 2); assert!(num_rows & (num_rows - 1) == 0); @@ -84,6 +89,7 @@ fn trace_impl(input: TokenStream2) -> Result { buffer: Some(buffer), slice_trace, num_rows, + commit_id: #commit_id } } @@ -191,6 +197,8 @@ struct ParsedTraceInput { struct_name: Ident, generics: Generics, fields: FieldsNamed, + num_rows: LitInt, + commit_id: Option, } impl Parse for ParsedTraceInput { @@ -212,7 +220,16 @@ impl Parse for ParsedTraceInput { let generics: Generics = input.parse()?; let fields: FieldsNamed = input.parse()?; - Ok(ParsedTraceInput { row_struct_name, struct_name, generics, fields }) + input.parse::()?; + let num_rows = input.parse::()?; + let commit_id: Option = if lookahead.peek(Token![,]) { + input.parse::()?; + Some(input.parse()?) + } else { + None + }; + + Ok(ParsedTraceInput { row_struct_name, struct_name, generics, fields, num_rows, commit_id }) } } @@ -341,275 +358,47 @@ fn test_parse_values_03() { #[test] fn test_trace_macro_generates_default_row_struct() { let input = quote! { - Simple { a: F, b: F } + Simple { a: F, b: F }, 2 }; - let _expected = quote! { - #[repr(C)] - #[derive(Debug, Clone, Copy, Default)] - pub struct SimpleRow { - pub a: F, - pub b: F, - } - impl SimpleRow { - pub const ROW_SIZE: usize = 2usize; - } - pub struct Simple<'a, F> { - pub buffer: Option>, - pub slice_trace: &'a mut [SimpleRow], - num_rows: usize, - } - impl<'a, F: Default + Clone + Copy> Simple<'a, F> { - pub fn new(num_rows: usize) -> Self { - assert!(num_rows >= 2); - assert!(num_rows & (num_rows - 1) == 0); - let buffer = vec![F::default(); num_rows * SimpleRow::::ROW_SIZE]; - let slice_trace = unsafe { - std::slice::from_raw_parts_mut( - buffer.as_ptr() as *mut SimpleRow, - num_rows, - ) - }; - Simple { - buffer: Some(buffer), - slice_trace, - num_rows, - } - } - pub fn map_buffer( - external_buffer: &'a mut [F], - num_rows: usize, - offset: usize, - ) -> Result> { - assert!(num_rows >= 2); - assert!(num_rows & (num_rows - 1) == 0); - let start = offset; - let end = start + num_rows * SimpleRow::::ROW_SIZE; - if end > external_buffer.len() { - return Err("Buffer is too small to fit the trace".into()); - } - let slice_trace = unsafe { - std::slice::from_raw_parts_mut( - external_buffer[start..end].as_ptr() as *mut SimpleRow, - num_rows, - ) - }; - Ok(Simple { - buffer: None, - slice_trace, - num_rows, - }) - } - pub fn from_row_vec( - external_buffer: Vec>, - ) -> Result> { - let num_rows = external_buffer.len().next_power_of_two(); - assert!(num_rows >= 2); - assert!(num_rows & (num_rows - 1) == 0); - let slice_trace = unsafe { - let ptr = external_buffer.as_ptr() as *mut SimpleRow; - std::slice::from_raw_parts_mut( - ptr, - num_rows, - ) - }; - let buffer_f = unsafe { - Vec::from_raw_parts( - external_buffer.as_ptr() as *mut F, - num_rows * SimpleRow::::ROW_SIZE, - num_rows * SimpleRow::::ROW_SIZE, - ) - }; - std::mem::forget(external_buffer); - Ok(Simple { - buffer: Some(buffer_f), - slice_trace, - num_rows, - }) - } - pub fn num_rows(&self) -> usize { - self.num_rows - } - } - impl<'a, F> std::ops::Index for Simple<'a, F> { - type Output = SimpleRow; - fn index(&self, index: usize) -> &Self::Output { - &self.slice_trace[index] - } - } - impl<'a, F> std::ops::IndexMut for Simple<'a, F> { - fn index_mut(&mut self, index: usize) -> &mut Self::Output { - &mut self.slice_trace[index] - } - } - impl<'a, F: Send> common::trace::Trace for Simple<'a, F> { - fn num_rows(&self) -> usize { - self.num_rows - } - fn get_buffer_ptr(&mut self) -> *mut u8 { - let buffer = self.buffer.as_mut().expect("Buffer is not available"); - buffer.as_mut_ptr() as *mut u8 - } - } - - - }; let _generated = trace_impl(input).unwrap(); - // assert_eq!(generated.to_string(), expected.into_token_stream().to_string()); } #[test] fn test_trace_macro_with_explicit_row_struct_name() { let input = quote! { - SimpleRow, Simple { a: F, b: F } - }; - - let _expected = quote! { - #[repr(C)] - #[derive(Debug, Clone, Copy, Default)] - pub struct SimpleRow { - pub a: F, - pub b: F, - } - - impl SimpleRow { - pub const ROW_SIZE: usize = 2usize; - } - - pub struct Simple<'a, F> { - pub buffer: Option>, - pub slice_trace: &'a mut [SimpleRow], - num_rows: usize, - } - - impl<'a, F: Default + Clone + Copy> Simple<'a, F> { - pub fn new(num_rows: usize) -> Self { - assert!(num_rows >= 2); - assert!(num_rows & (num_rows - 1) == 0); - let buffer = vec![F::default(); num_rows * SimpleRow::::ROW_SIZE]; - let slice_trace = unsafe { - std::slice::from_raw_parts_mut( - buffer.as_ptr() as *mut SimpleRow, - num_rows, - ) - }; - Simple { - buffer: Some(buffer), - slice_trace, - num_rows, - } - } - - pub fn map_buffer( - external_buffer: &'a mut [F], - num_rows: usize, - offset: usize, - ) -> Result> { - assert!(num_rows >= 2); - assert!(num_rows & (num_rows - 1) == 0); - let start = offset; - let end = start + num_rows * SimpleRow::::ROW_SIZE; - if end > external_buffer.len() { - return Err("Buffer is too small to fit the trace".into()); - } - let slice_trace = unsafe { - std::slice::from_raw_parts_mut( - external_buffer[start..end].as_ptr() as *mut SimpleRow, - num_rows, - ) - }; - Ok(Simple { - buffer: None, - slice_trace, - num_rows, - }) - } - - pub fn from_row_vec( - external_buffer: Vec>, - ) -> Result> { - let num_rows = external_buffer.len().next_power_of_two(); - assert!(num_rows >= 2); - assert!(num_rows & (num_rows - 1) == 0); - let slice_trace = unsafe { - let ptr = external_buffer.as_ptr() as *mut SimpleRow; - std::slice::from_raw_parts_mut( - ptr, - num_rows, - ) - }; - let buffer_f = unsafe { - Vec::from_raw_parts( - external_buffer.as_ptr() as *mut F, - num_rows * SimpleRow::::ROW_SIZE, num_rows * SimpleRow::::ROW_SIZE, - ) - }; - std::mem::forget(external_buffer); - Ok(Simple { - buffer: Some(buffer_f), - slice_trace, num_rows, - }) - } - - pub fn num_rows(&self) -> usize { - self.num_rows - } - } - - impl<'a, F> std::ops::Index for Simple<'a, F> { - type Output = SimpleRow; - - fn index(&self, index: usize) -> &Self::Output { - &self.slice_trace[index] - } - } - - impl<'a, F> std::ops::IndexMut for Simple<'a, F> { - fn index_mut(&mut self, index: usize) -> &mut Self::Output { - &mut self.slice_trace[index] - } - } - - impl<'a, F: Send> common::trace::Trace for Simple<'a, F> { - fn num_rows(&self) -> usize { - self.num_rows - } - - fn get_buffer_ptr(&mut self) -> *mut u8 { - let buffer = self.buffer.as_mut().expect("Buffer is not available"); - buffer.as_mut_ptr() as *mut u8 - } - } + SimpleRow, Simple { a: F, b: F }, 4 }; let _generated = trace_impl(input).unwrap(); - // assert_eq!(generated.to_string(), expected.into_token_stream().to_string()); } #[test] fn test_parsing_01() { let input = quote! { - TraceRow, MyTrace { a: F, b: F } + TraceRow, MyTrace { a: F, b: F }, 34 }; let parsed: ParsedTraceInput = parse2(input).unwrap(); assert_eq!(parsed.row_struct_name, "TraceRow"); assert_eq!(parsed.struct_name, "MyTrace"); + assert_eq!(parsed.num_rows.base10_parse::().unwrap(), 34); } #[test] fn test_parsing_02() { let input = quote! { - SimpleRow, Simple { a: F } + SimpleRow, Simple { a: F }, 127_456 }; let parsed: ParsedTraceInput = parse2(input).unwrap(); assert_eq!(parsed.row_struct_name, "SimpleRow"); assert_eq!(parsed.struct_name, "Simple"); + assert_eq!(parsed.num_rows.base10_parse::().unwrap(), 127_456); } #[test] fn test_parsing_03() { let input = quote! { - Simple { a: F } + Simple { a: F }, 2 }; let parsed: ParsedTraceInput = parse2(input).unwrap(); assert_eq!(parsed.row_struct_name, "SimpleRow"); From ea9c695daba529640797d64915db48793bf519ac Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 4 Dec 2024 13:49:58 -0500 Subject: [PATCH 08/64] commit_id --- macros/src/lib.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/macros/src/lib.rs b/macros/src/lib.rs index a36a063e..618519fa 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -66,7 +66,7 @@ fn trace_impl(input: TokenStream2) -> Result { pub buffer: Option>, pub slice_trace: &'a mut [#row_struct_name<#generics>], pub num_rows: usize, - pub commit_id: Option<&'a str>, + pub commit_id: Option, } impl<'a, #generics: Default + Clone + Copy> #trace_struct_name<'a, #generics> { @@ -198,7 +198,7 @@ struct ParsedTraceInput { generics: Generics, fields: FieldsNamed, num_rows: LitInt, - commit_id: Option, + commit_id: Option, } impl Parse for ParsedTraceInput { @@ -222,7 +222,7 @@ impl Parse for ParsedTraceInput { input.parse::()?; let num_rows = input.parse::()?; - let commit_id: Option = if lookahead.peek(Token![,]) { + let commit_id: Option = if input.peek(Token![,]) { input.parse::()?; Some(input.parse()?) } else { @@ -358,7 +358,7 @@ fn test_parse_values_03() { #[test] fn test_trace_macro_generates_default_row_struct() { let input = quote! { - Simple { a: F, b: F }, 2 + Simple { a: F, b: F }, 2, 788 }; let _generated = trace_impl(input).unwrap(); @@ -376,12 +376,13 @@ fn test_trace_macro_with_explicit_row_struct_name() { #[test] fn test_parsing_01() { let input = quote! { - TraceRow, MyTrace { a: F, b: F }, 34 + TraceRow, MyTrace { a: F, b: F }, 34, 38 }; let parsed: ParsedTraceInput = parse2(input).unwrap(); assert_eq!(parsed.row_struct_name, "TraceRow"); assert_eq!(parsed.struct_name, "MyTrace"); assert_eq!(parsed.num_rows.base10_parse::().unwrap(), 34); + assert_eq!(parsed.commit_id.unwrap().base10_parse::().unwrap(), 38); } #[test] From e704e3e8c6913eaf14aded63c0f27091971db2c4 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 4 Dec 2024 14:31:51 -0500 Subject: [PATCH 09/64] working.....? --- macros/src/lib.rs | 61 +++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 618519fa..1d16b84b 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -3,7 +3,7 @@ use proc_macro2::TokenStream as TokenStream2; use quote::{quote, format_ident, ToTokens}; use syn::{ parse::{Parse, ParseStream}, - parse2, Field, FieldsNamed, Generics, Ident, LitInt, LitStr, Result, Token, + parse2, Field, FieldsNamed, Generics, Ident, LitInt, Result, Token, }; #[proc_macro] @@ -265,41 +265,46 @@ fn values_impl(input: TokenStream2) -> Result { let dimensions = parsed_input.dimensions; let fields = parsed_input.fields; - // Generate the struct and implementation - let result = quote! { - pub struct #struct_name<#generic_param> { - pub buffer: Vec<#generic_param>, - pub x: usize, - } + // Calculate ROW_SIZE based on the field types + let row_size = fields + .named + .iter() + .map(|field| calculate_field_size_literal(&field.ty)) + .collect::>>()? + .into_iter() + .sum::() + * dimensions; - impl<#generic_param: Clone> #struct_name<#generic_param> { - pub fn new(x: usize) -> Self { - #struct_name { - buffer: Vec::new(), - x, - } - } + // Generate row struct + let field_definitions = fields.named.iter().map(|field| { + let Field { ident, ty, .. } = field; + quote! { pub #ident: #ty, } + }); - pub fn set_value(&mut self, value: #generic_param) { - self.buffer.resize(self.x, value); - } + let row_struct = quote! { + #[repr(C)] + #[derive(Debug, Clone, Copy, Default)] + pub struct #struct_name<#generic_param> { + #(#field_definitions)* + } - pub fn set_values(&mut self, values: Vec<#generic_param>) { - assert_eq!( - values.len(), - self.x, - "Number of values must match the size parameter `x`." - ); - self.buffer = values; - } + impl<#generic_param: Copy> #struct_name<#generic_param> { + pub const ROW_SIZE: usize = #row_size; - pub fn get_buffer(&self) -> &[#generic_param] { - &self.buffer + pub fn as_slice(&self) -> &[#generic_param] { + unsafe { + std::slice::from_raw_parts( + self as *const #struct_name<#generic_param> as *const #generic_param, + #row_size, + ) + } } } }; - Ok(result) + Ok(quote! { + #row_struct + }) } struct ParsedValuesInput { From 806cae4c70754dc0dd492b7bb3c750e3d3b3c86b Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Thu, 5 Dec 2024 08:50:15 +0000 Subject: [PATCH 10/64] Simplifying macro and commenting commit_id --- .../src/pil_helpers/traces.rs | 16 +-- macros/src/lib.rs | 124 +++++------------- 2 files changed, 44 insertions(+), 96 deletions(-) diff --git a/examples/fibonacci-square/src/pil_helpers/traces.rs b/examples/fibonacci-square/src/pil_helpers/traces.rs index 920d9f9f..3dea50ba 100644 --- a/examples/fibonacci-square/src/pil_helpers/traces.rs +++ b/examples/fibonacci-square/src/pil_helpers/traces.rs @@ -3,18 +3,18 @@ use proofman_common as common; pub use proofman_macros::trace; -trace!(FibonacciSquareRow, FibonacciSquareTrace { +trace!(FibonacciSquareTrace { a: F, b: F, -}); +}, 1024); -trace!(ModuleRow, ModuleTrace { +trace!(ModuleTrace { x: F, q: F, x_mod: F, -}); +}, 1024); -trace!(U8AirRow, U8AirTrace { +trace!(U8AirTrace { mul: F, -}); +}, 256); -trace!(FibonacciSquareRomRow, FibonacciSquareRomTrace { +trace!(FibonacciSquareRomTrace { line: F, flags: F, -}); +}, 1024); diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 1d16b84b..498841d7 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -22,7 +22,7 @@ fn trace_impl(input: TokenStream2) -> Result { let generics = parsed_input.generics.params; let fields = parsed_input.fields; let num_rows = parsed_input.num_rows; - let commit_id = parsed_input.commit_id; + // let commit_id = parsed_input.commit_id; // Calculate ROW_SIZE based on the field types let row_size = fields @@ -62,14 +62,13 @@ fn trace_impl(input: TokenStream2) -> Result { // Generate trace struct let trace_struct = quote! { - pub struct #trace_struct_name<'a, #generics> { - pub buffer: Option>, - pub slice_trace: &'a mut [#row_struct_name<#generics>], + pub struct #trace_struct_name<#generics> { + pub buffer: Vec<#row_struct_name<#generics>>, pub num_rows: usize, - pub commit_id: Option, + // pub commit_id: Option, } - impl<'a, #generics: Default + Clone + Copy> #trace_struct_name<'a, #generics> { + impl<#generics: Default + Clone + Copy> #trace_struct_name<#generics> { const NUM_ROWS: usize = #num_rows; pub fn new() -> Self { @@ -77,81 +76,31 @@ fn trace_impl(input: TokenStream2) -> Result { assert!(num_rows >= 2); assert!(num_rows & (num_rows - 1) == 0); - let buffer = vec![#generics::default(); num_rows * #row_struct_name::<#generics>::ROW_SIZE]; - let slice_trace = unsafe { - std::slice::from_raw_parts_mut( - buffer.as_ptr() as *mut #row_struct_name<#generics>, - num_rows, - ) - }; + let mut buff_uninit: Vec>> = Vec::with_capacity(num_rows); + unsafe { + buff_uninit.set_len(num_rows); + } + let buffer: Vec<#row_struct_name<#generics>> = unsafe { std::mem::transmute(buff_uninit) }; #trace_struct_name { - buffer: Some(buffer), - slice_trace, + buffer, num_rows, - commit_id: #commit_id + // commit_id: #commit_id } } - pub fn map_buffer( - external_buffer: &'a mut [#generics], - num_rows: usize, - offset: usize, - ) -> Result> { + pub fn new_zeroes() -> Self { + let num_rows = Self::NUM_ROWS; assert!(num_rows >= 2); assert!(num_rows & (num_rows - 1) == 0); - let start = offset; - let end = start + num_rows * #row_struct_name::<#generics>::ROW_SIZE; - - if end > external_buffer.len() { - return Err("Buffer is too small to fit the trace".into()); - } - - let slice_trace = unsafe { - std::slice::from_raw_parts_mut( - external_buffer[start..end].as_ptr() as *mut #row_struct_name<#generics>, - num_rows, - ) - }; - - Ok(#trace_struct_name { - buffer: None, - slice_trace, + let buffer = vec![#row_struct_name::<#generics>::default(); num_rows]; + + #trace_struct_name { + buffer, num_rows, - }) - } - - pub fn from_row_vec( - external_buffer: Vec<#row_struct_name<#generics>>, - ) -> Result> { - let mut num_f = external_buffer.len() * #row_struct_name::<#generics>::ROW_SIZE; - - let slice_trace = unsafe { - let ptr = external_buffer.as_ptr() as *mut #row_struct_name<#generics>; - std::slice::from_raw_parts_mut( - ptr, - external_buffer.len(), - ) - }; - - let buffer_f = unsafe { - let mut vec = Vec::from_raw_parts( - external_buffer.as_ptr() as *mut #generics, - num_f, - num_f, - ); - vec.resize(num_f, #generics::default()); - vec - }; - - std::mem::forget(external_buffer); - - Ok(#trace_struct_name { - buffer: Some(buffer_f), - slice_trace, - num_rows: num_f / #row_struct_name::<#generics>::ROW_SIZE, - }) + // commit_id: #commit_id + } } pub fn num_rows(&self) -> usize { @@ -159,28 +108,27 @@ fn trace_impl(input: TokenStream2) -> Result { } } - impl<'a, #generics> std::ops::Index for #trace_struct_name<'a, #generics> { + impl<#generics> std::ops::Index for #trace_struct_name<#generics> { type Output = #row_struct_name<#generics>; fn index(&self, index: usize) -> &Self::Output { - &self.slice_trace[index] + &self.buffer[index] } } - impl<'a, #generics> std::ops::IndexMut for #trace_struct_name<'a, #generics> { + impl<#generics> std::ops::IndexMut for #trace_struct_name<#generics> { fn index_mut(&mut self, index: usize) -> &mut Self::Output { - &mut self.slice_trace[index] + &mut self.buffer[index] } } - impl<'a, #generics: Send> common::trace::Trace for #trace_struct_name<'a, #generics> { + impl<#generics: Send> common::trace::Trace for #trace_struct_name<#generics> { fn num_rows(&self) -> usize { self.num_rows } fn get_buffer_ptr(&mut self) -> *mut u8 { - let buffer = self.buffer.as_mut().expect("Buffer is not available"); - buffer.as_mut_ptr() as *mut u8 + self.buffer.as_mut_ptr() as *mut u8 } } }; @@ -198,7 +146,7 @@ struct ParsedTraceInput { generics: Generics, fields: FieldsNamed, num_rows: LitInt, - commit_id: Option, + // commit_id: Option, } impl Parse for ParsedTraceInput { @@ -222,14 +170,14 @@ impl Parse for ParsedTraceInput { input.parse::()?; let num_rows = input.parse::()?; - let commit_id: Option = if input.peek(Token![,]) { - input.parse::()?; - Some(input.parse()?) - } else { - None - }; - - Ok(ParsedTraceInput { row_struct_name, struct_name, generics, fields, num_rows, commit_id }) + // let commit_id: Option = if input.peek(Token![,]) { + // input.parse::()?; + // Some(input.parse()?) + // } else { + // None + // }; + + Ok(ParsedTraceInput { row_struct_name, struct_name, generics, fields, num_rows /*, commit_id */ }) } } @@ -387,7 +335,7 @@ fn test_parsing_01() { assert_eq!(parsed.row_struct_name, "TraceRow"); assert_eq!(parsed.struct_name, "MyTrace"); assert_eq!(parsed.num_rows.base10_parse::().unwrap(), 34); - assert_eq!(parsed.commit_id.unwrap().base10_parse::().unwrap(), 38); + //assert_eq!(parsed.commit_id.unwrap().base10_parse::().unwrap(), 38); } #[test] From aabbb66730c54e069f67b05cb84e248361ca8062 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Wed, 4 Dec 2024 15:21:12 +0000 Subject: [PATCH 11/64] Renaming, improving logs, cleaning --- .github/workflows/ci.yaml | 2 +- Cargo.lock | 147 +++++++++--------- common/src/air_instance.rs | 68 +++++--- common/src/buffer_allocator.rs | 14 -- common/src/custom_commits.rs | 24 ++- common/src/execution_ctx.rs | 17 +- common/src/lib.rs | 2 - common/src/proof_ctx.rs | 4 +- common/src/prover.rs | 22 ++- common/src/setup.rs | 8 +- examples/fibonacci-square/src/fibonacci.rs | 34 ++-- examples/fibonacci-square/src/module.rs | 2 +- hints/Cargo.toml | 1 + hints/src/hints.rs | 102 ++++++------ macros/src/lib.rs | 26 ++++ .../test/simple/rs/src/simple_left.rs | 2 +- .../test/simple/rs/src/simple_right.rs | 2 +- .../test/std/connection/rs/src/connection1.rs | 4 +- .../test/std/connection/rs/src/connection2.rs | 4 +- .../std/connection/rs/src/connection_new.rs | 4 +- .../test/std/lookup/rs/src/lookup0.rs | 2 +- .../test/std/lookup/rs/src/lookup1.rs | 2 +- .../test/std/lookup/rs/src/lookup2_12.rs | 2 +- .../test/std/lookup/rs/src/lookup2_13.rs | 2 +- .../test/std/lookup/rs/src/lookup2_15.rs | 2 +- .../test/std/lookup/rs/src/lookup3.rs | 2 +- .../std/permutation/rs/src/permutation1_6.rs | 2 +- .../std/permutation/rs/src/permutation1_7.rs | 2 +- .../std/permutation/rs/src/permutation1_8.rs | 2 +- .../std/permutation/rs/src/permutation2.rs | 2 +- .../range_check/rs/src/multi_range_check1.rs | 4 +- .../range_check/rs/src/multi_range_check2.rs | 4 +- .../std/range_check/rs/src/range_check1.rs | 4 +- .../std/range_check/rs/src/range_check2.rs | 4 +- .../std/range_check/rs/src/range_check3.rs | 4 +- .../std/range_check/rs/src/range_check4.rs | 4 +- .../rs/src/range_check_dynamic1.rs | 4 +- .../rs/src/range_check_dynamic2.rs | 4 +- .../std/range_check/rs/src/range_check_mix.rs | 4 +- pil2-stark/lib/include/starks_lib.h | 17 +- pil2-stark/src/api/starks_api.cpp | 46 ++---- pil2-stark/src/api/starks_api.hpp | 17 +- pil2-stark/src/starkpil/exec_file.hpp | 14 +- pil2-stark/src/starkpil/expressions_avx.hpp | 7 +- .../src/starkpil/expressions_avx512.hpp | 7 +- pil2-stark/src/starkpil/expressions_pack.hpp | 7 +- pil2-stark/src/starkpil/final_snark_proof.hpp | 4 +- .../src/starkpil/gen_recursive_proof.hpp | 24 +-- .../src/starkpil/global_constraints.hpp | 72 +++++---- pil2-stark/src/starkpil/hints.hpp | 92 +++++------ pil2-stark/src/starkpil/stark_info.cpp | 3 +- pil2-stark/src/starkpil/stark_info.hpp | 2 - pil2-stark/src/starkpil/starks.cpp | 36 ++--- pil2-stark/src/starkpil/starks.hpp | 8 +- pil2-stark/src/starkpil/steps.hpp | 5 +- .../src/starkpil/verify_constraints.hpp | 7 +- proofman/src/constraints.rs | 57 +++++-- proofman/src/global_constraints.rs | 27 ++-- proofman/src/proofman.rs | 11 +- proofman/src/recursion.rs | 18 +-- provers/stark/src/stark_prover.rs | 80 ++++------ provers/starks-lib-c/bindings_starks.rs | 127 ++++----------- provers/starks-lib-c/src/ffi_starks.rs | 89 +++-------- 63 files changed, 609 insertions(+), 713 deletions(-) delete mode 100644 common/src/buffer_allocator.rs diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6ff32625..f6e9c17f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -260,7 +260,7 @@ jobs: uses: actions/checkout@v4 with: repository: 0xPolygonHermez/pil2-proofman-js - ref: feature/setup + ref: 0.0.16 path: pil2-proofman-js - name: Install pil2-proofman-js dependencies diff --git a/Cargo.lock b/Cargo.lock index 0768b511..1e62d32a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.15" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" dependencies = [ "anstyle", "anstyle-parse", @@ -28,43 +28,43 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.8" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" [[package]] name = "anstyle-parse" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.4" +version = "3.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" dependencies = [ "anstyle", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "anyhow" -version = "1.0.91" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c042108f3ed77fd83760a5fd79b53be043192bb3b9dba91d8c574c0ada7850c8" +checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7" [[package]] name = "autocfg" @@ -119,15 +119,15 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" +checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" [[package]] name = "cc" -version = "1.1.31" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f" +checksum = "f34d93e62b03caf570cccc334cbc6c2fceca82f39211051345108adcba3eebdc" dependencies = [ "shlex", ] @@ -160,9 +160,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.20" +version = "4.5.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" +checksum = "69371e34337c4c984bbe322360c2547210bf632eb2814bbe78a6e87a2935bd2b" dependencies = [ "clap_builder", "clap_derive", @@ -170,9 +170,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.20" +version = "4.5.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" +checksum = "6e24c1b4099818523236a8ca881d2b45db98dadfb4625cf6608c12069fcbbde1" dependencies = [ "anstream", "anstyle", @@ -194,15 +194,15 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" [[package]] name = "colorchoice" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" [[package]] name = "colored" @@ -306,19 +306,19 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.9" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "fastrand" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" +checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" [[package]] name = "fibonacci-square" @@ -395,9 +395,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "indexmap" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" dependencies = [ "equivalent", "hashbrown", @@ -429,9 +429,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.11" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" [[package]] name = "lazy_static" @@ -447,9 +447,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.161" +version = "0.2.167" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" +checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" [[package]] name = "libffi" @@ -472,9 +472,9 @@ dependencies = [ [[package]] name = "libloading" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", "windows-targets 0.52.6", @@ -749,9 +749,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" [[package]] name = "pkg-config" @@ -770,9 +770,9 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.2.24" +version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "910d41a655dac3b764f1ade94821093d3610248694320cd072303a8eedcf221d" +checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" dependencies = [ "proc-macro2", "syn", @@ -780,9 +780,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.89" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -850,6 +850,7 @@ dependencies = [ name = "proofman-hints" version = "0.1.0" dependencies = [ + "log", "p3-field", "proofman-common", "proofman-starks-lib-c", @@ -993,9 +994,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", @@ -1005,9 +1006,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -1028,9 +1029,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" -version = "0.38.37" +version = "0.38.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" dependencies = [ "bitflags", "errno", @@ -1047,18 +1048,18 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "serde" -version = "1.0.213" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ea7893ff5e2466df8d720bb615088341b295f849602c6956047f8f80f0e9bc1" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.213" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e85ad2009c50b58e87caa8cd6dac16bdf511bbfb7af6c33df902396aa480fa5" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", @@ -1067,9 +1068,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.132" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" dependencies = [ "itoa", "memchr", @@ -1126,9 +1127,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.82" +version = "2.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021" +checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" dependencies = [ "proc-macro2", "quote", @@ -1151,9 +1152,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.13.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" +checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" dependencies = [ "cfg-if", "fastrand", @@ -1164,18 +1165,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.65" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.65" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", @@ -1194,9 +1195,9 @@ dependencies = [ [[package]] name = "tracing" -version = "0.1.40" +version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" dependencies = [ "pin-project-lite", "tracing-attributes", @@ -1205,9 +1206,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.27" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2", "quote", @@ -1216,9 +1217,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.32" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" dependencies = [ "once_cell", ] @@ -1242,9 +1243,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "unicode-segmentation" diff --git a/common/src/air_instance.rs b/common/src/air_instance.rs index 78156027..5aa00b50 100644 --- a/common/src/air_instance.rs +++ b/common/src/air_instance.rs @@ -1,16 +1,15 @@ -use std::mem::MaybeUninit; -use std::ptr; use std::{collections::HashMap, os::raw::c_void, sync::Arc}; use std::path::PathBuf; use p3_field::Field; -use proofman_starks_lib_c::{get_custom_commit_map_ids_c, get_map_totaln_custom_commits_c}; +use proofman_starks_lib_c::get_custom_commit_map_ids_c; +use proofman_util::create_buffer_fast; use crate::{SetupCtx, StarkInfo}; #[repr(C)] pub struct StepsParams { + pub witness: *mut c_void, pub trace: *mut c_void, - pub pols: *mut c_void, pub public_inputs: *mut c_void, pub challenges: *mut c_void, pub airgroup_values: *mut c_void, @@ -20,6 +19,7 @@ pub struct StepsParams { pub p_const_pols: *mut c_void, pub p_const_tree: *mut c_void, pub custom_commits: [*mut c_void; 10], + pub custom_commits_extended: [*mut c_void; 10], } impl From<&StepsParams> for *mut c_void { @@ -68,9 +68,10 @@ pub struct AirInstance { pub air_instance_id: Option, pub idx: Option, pub global_idx: Option, - pub trace: Vec, - pub buffer: Option>>, + pub witness: Vec, + pub trace: Option>, pub custom_commits: Vec>, + pub custom_commits_extended: Vec>, pub airgroup_values: Vec, pub airvalues: Vec, pub evals: Vec, @@ -87,7 +88,7 @@ impl AirInstance { airgroup_id: usize, air_id: usize, air_segment_id: Option, - trace: Vec, + witness: Vec, ) -> Self { let ps = setup_ctx.get_setup(airgroup_id, air_id); @@ -95,9 +96,20 @@ impl AirInstance { let custom_commits_calculated = vec![HashMap::new(); n_custom_commits]; let mut custom_commits = Vec::new(); - - for _ in 0..n_custom_commits { - custom_commits.push(CustomCommitsInfo::default()); + let mut custom_commits_extended = Vec::new(); + + for i in 0..n_custom_commits { + let n_cols = + *ps.stark_info.map_sections_n.get(&(ps.stark_info.custom_commits[i].name.clone() + "0")).unwrap() + as usize; + custom_commits.push(CustomCommitsInfo::new( + create_buffer_fast((1 << ps.stark_info.stark_struct.n_bits) * n_cols), + PathBuf::new(), + )); + custom_commits_extended.push(CustomCommitsInfo::new( + create_buffer_fast((1 << ps.stark_info.stark_struct.n_bits_ext) * n_cols), + PathBuf::new(), + )); } AirInstance { @@ -107,9 +119,10 @@ impl AirInstance { air_instance_id: None, idx: None, global_idx: None, - trace, - buffer: None, + witness, + trace: None, custom_commits, + custom_commits_extended, airgroup_values: vec![F::zero(); ps.stark_info.airgroupvalues_map.as_ref().unwrap().len() * 3], airvalues: vec![F::zero(); ps.stark_info.airvalues_map.as_ref().unwrap().len() * 3], evals: vec![F::zero(); ps.stark_info.ev_map.len() * 3], @@ -121,18 +134,18 @@ impl AirInstance { } } - pub fn get_trace_ptr(&self) -> *mut u8 { - self.trace.as_ptr() as *mut u8 + pub fn get_witness_ptr(&self) -> *mut u8 { + self.witness.as_ptr() as *mut u8 } - pub fn set_buffer(&mut self, buffer: Vec>) { - self.buffer = Some(buffer); + pub fn set_trace(&mut self, trace: Vec) { + self.trace = Some(trace); } - pub fn get_buffer_ptr(&self) -> *mut u8 { - match &self.buffer { - Some(buffer) => buffer.as_ptr() as *mut u8, - None => std::ptr::null_mut(), // Return null if `buffer` is `None` + pub fn get_trace_ptr(&self) -> *mut u8 { + match &self.trace { + Some(trace) => trace.as_ptr() as *mut u8, + None => std::ptr::null_mut(), // Return null if `trace` is `None` } } @@ -144,13 +157,18 @@ impl AirInstance { ptrs } + pub fn get_custom_commits_extended_ptr(&self) -> [*mut c_void; 10] { + let mut ptrs = [std::ptr::null_mut(); 10]; + for (i, custom_commit) in self.custom_commits_extended.iter().enumerate() { + ptrs[i] = custom_commit.buffer.as_ptr() as *mut c_void; + } + ptrs + } + pub fn set_custom_commit_cached_file(&mut self, setup_ctx: &SetupCtx, commit_id: u64, cached_file: PathBuf) { let ps = setup_ctx.get_setup(self.airgroup_id, self.air_id); - let buffer_size = get_map_totaln_custom_commits_c(ps.p_setup.p_stark_info, commit_id); - let buffer = vec![F::zero(); buffer_size as usize]; - - self.custom_commits[commit_id as usize] = CustomCommitsInfo::new(buffer, cached_file); + self.custom_commits[commit_id as usize].cached_file = cached_file; let ids = get_custom_commit_map_ids_c(ps.p_setup.p_stark_info, commit_id, 0); for idx in ids { @@ -159,7 +177,7 @@ impl AirInstance { } pub fn set_custom_commit_id_buffer(&mut self, setup_ctx: &SetupCtx, buffer: Vec, commit_id: u64) { - self.custom_commits[commit_id as usize] = CustomCommitsInfo::new(buffer, PathBuf::new()); + self.custom_commits[commit_id as usize].buffer = buffer; let ps = setup_ctx.get_setup(self.airgroup_id, self.air_id); diff --git a/common/src/buffer_allocator.rs b/common/src/buffer_allocator.rs deleted file mode 100644 index 46c31a83..00000000 --- a/common/src/buffer_allocator.rs +++ /dev/null @@ -1,14 +0,0 @@ -use std::error::Error; - -use crate::SetupCtx; - -pub trait BufferAllocator: Send + Sync { - // Returns the size of the buffer and the offsets for each stage - fn get_buffer_info_custom_commit( - &self, - sctx: &SetupCtx, - airgroup_id: usize, - air_id: usize, - custom_commit_name: &str, - ) -> Result<(u64, Vec, u64), Box>; -} diff --git a/common/src/custom_commits.rs b/common/src/custom_commits.rs index 1a2f2646..dba9d09c 100644 --- a/common/src/custom_commits.rs +++ b/common/src/custom_commits.rs @@ -5,7 +5,7 @@ use std::collections::HashMap; use std::os::raw::c_void; use std::path::PathBuf; -use crate::Setup; +use crate::{Setup, SetupCtx}; pub fn parse_cached_buffers(s: &str) -> Result, String> { let json_data: Value = serde_json::from_str(s).map_err(|e| format!("Invalid JSON: {}", e))?; @@ -26,12 +26,32 @@ pub fn parse_cached_buffers(s: &str) -> Result, String> Ok(map) } -pub fn get_custom_commit_trace(commit_id: u64, step: u64, setup: &Setup, buffer: Vec, buffer_str: &str) { +pub fn get_custom_commit_id(sctx: &SetupCtx, airgroup_id: usize, air_id: usize, name: &str) -> u64 { + let ps = sctx.get_setup(airgroup_id, air_id); + let commit_id = match ps.stark_info.custom_commits.iter().position(|custom_commit| custom_commit.name == name) { + Some(commit_id) => commit_id as u64, + None => { + eprintln!("Custom commit '{}' not found in custom commits.", name); + std::process::exit(1); + } + }; + commit_id +} + +pub fn get_custom_commit_trace( + commit_id: u64, + step: u64, + setup: &Setup, + buffer: Vec, + buffer_ext: Vec, + buffer_str: &str, +) { extend_and_merkelize_custom_commit_c( starks_new_c((&setup.p_setup).into(), std::ptr::null_mut()), commit_id, step, buffer.as_ptr() as *mut c_void, + buffer_ext.as_ptr() as *mut c_void, fri_proof_new_c((&setup.p_setup).into()), std::ptr::null_mut(), buffer_str, diff --git a/common/src/execution_ctx.rs b/common/src/execution_ctx.rs index 85b2e559..eb198be3 100644 --- a/common/src/execution_ctx.rs +++ b/common/src/execution_ctx.rs @@ -1,5 +1,5 @@ -use std::{path::PathBuf, sync::Arc}; -use crate::{BufferAllocator, DistributionCtx, StdMode, VerboseMode}; +use std::path::PathBuf; +use crate::{DistributionCtx, StdMode, VerboseMode}; use std::sync::RwLock; use std::collections::HashMap; #[allow(dead_code)] @@ -9,7 +9,6 @@ pub struct ExecutionCtx { pub cached_buffers_path: Option>, /// If true, the plugin must generate the public outputs pub public_output: bool, - pub buffer_allocator: Arc, pub verbose_mode: VerboseMode, pub dctx: RwLock, pub std_mode: StdMode, @@ -25,7 +24,6 @@ pub struct ExecutionCtxBuilder { rom_path: Option, cached_buffers_path: Option>, public_output: bool, - buffer_allocator: Option>, verbose_mode: VerboseMode, std_mode: StdMode, } @@ -42,7 +40,6 @@ impl ExecutionCtxBuilder { rom_path: None, cached_buffers_path: None, public_output: true, - buffer_allocator: None, verbose_mode: VerboseMode::Info, std_mode: StdMode::default(), } @@ -58,11 +55,6 @@ impl ExecutionCtxBuilder { self } - pub fn with_buffer_allocator(mut self, buffer_allocator: Arc) -> Self { - self.buffer_allocator = Some(buffer_allocator); - self - } - pub fn with_verbose_mode(mut self, verbose_mode: VerboseMode) -> Self { self.verbose_mode = verbose_mode; self @@ -74,15 +66,10 @@ impl ExecutionCtxBuilder { } pub fn build(self) -> ExecutionCtx { - if self.buffer_allocator.is_none() { - panic!("Buffer allocator is required"); - } - ExecutionCtx { rom_path: self.rom_path, cached_buffers_path: self.cached_buffers_path, public_output: self.public_output, - buffer_allocator: self.buffer_allocator.unwrap(), verbose_mode: self.verbose_mode, dctx: RwLock::new(DistributionCtx::new()), std_mode: self.std_mode, diff --git a/common/src/lib.rs b/common/src/lib.rs index 5b10c1fe..16a82623 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -1,6 +1,5 @@ mod air_instance; mod air_instances_repository; -mod buffer_allocator; mod verbose_mode; mod execution_ctx; mod distribution_ctx; @@ -18,7 +17,6 @@ pub mod stark_info; pub use air_instance::*; pub use air_instances_repository::*; -pub use buffer_allocator::*; use proofman_starks_lib_c::set_log_level_c; pub use verbose_mode::*; pub use execution_ctx::*; diff --git a/common/src/proof_ctx.rs b/common/src/proof_ctx.rs index 73047d42..e5d5c84b 100644 --- a/common/src/proof_ctx.rs +++ b/common/src/proof_ctx.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use std::{mem::MaybeUninit, sync::RwLock}; +use std::sync::RwLock; use std::path::PathBuf; use p3_field::Field; @@ -48,7 +48,7 @@ impl Default for Challenges { } pub struct BuffHelper { - pub buff_helper: RwLock>>, + pub buff_helper: RwLock>, } impl Default for BuffHelper { diff --git a/common/src/prover.rs b/common/src/prover.rs index 10f09a17..dcf14e56 100644 --- a/common/src/prover.rs +++ b/common/src/prover.rs @@ -1,5 +1,4 @@ use std::os::raw::c_void; -use std::os::raw::c_char; use std::sync::Arc; use p3_field::Field; @@ -45,7 +44,8 @@ pub struct ConstraintInfo { pub id: u64, pub stage: u64, pub im_pol: bool, - pub line: *const c_char, + pub line: *mut u8, + pub line_size: u64, pub n_rows: u64, pub rows: [ConstraintRowInfo; 10usize], } @@ -57,6 +57,24 @@ pub struct ConstraintsResults { pub constraints_info: *mut ConstraintInfo, } +#[derive(Debug, Clone, Copy)] +#[repr(C)] +pub struct GlobalConstraintInfo { + pub id: u64, + pub dim: u64, + pub valid: bool, + pub value: [u64; 3usize], + pub line: *mut u8, + pub line_size: u64, +} + +#[derive(Debug, Clone, Copy)] +#[repr(C)] +pub struct GlobalConstraintsResults { + pub n_constraints: u64, + pub constraints_info: *mut GlobalConstraintInfo, +} + pub trait Prover { fn build(&mut self, proof_ctx: Arc>); fn free(&mut self); diff --git a/common/src/setup.rs b/common/src/setup.rs index 4b119061..f433d189 100644 --- a/common/src/setup.rs +++ b/common/src/setup.rs @@ -1,4 +1,3 @@ -use std::mem::MaybeUninit; use std::os::raw::c_void; use std::path::PathBuf; use std::sync::RwLock; @@ -8,6 +7,7 @@ use proofman_starks_lib_c::{ load_const_tree_c, load_const_pols_c, calculate_const_tree_c, stark_info_free_c, expressions_bin_free_c, prover_helpers_free_c, }; +use proofman_util::create_buffer_fast; use crate::GlobalInfo; use crate::ProofType; @@ -32,7 +32,7 @@ impl From<&SetupC> for *mut c_void { #[derive(Debug)] pub struct Pols { - pub values: RwLock>>, + pub values: RwLock>, } impl Default for Pols { @@ -113,7 +113,7 @@ impl Setup { let p_stark_info = self.p_setup.p_stark_info; let const_size = get_const_size_c(p_stark_info) as usize; - let const_pols: Vec> = Vec::with_capacity(const_size); + let const_pols: Vec = create_buffer_fast(const_size); let p_const_pols_address = const_pols.as_ptr() as *mut c_void; load_const_pols_c(p_const_pols_address, const_pols_path.as_str(), const_size as u64); @@ -136,7 +136,7 @@ impl Setup { let const_tree_size = get_const_tree_size_c(p_stark_info) as usize; - let const_tree: Vec> = Vec::with_capacity(const_tree_size); + let const_tree: Vec = create_buffer_fast(const_tree_size); let p_const_tree_address = const_tree.as_ptr() as *mut c_void; if PathBuf::from(&const_pols_tree_path).exists() { diff --git a/examples/fibonacci-square/src/fibonacci.rs b/examples/fibonacci-square/src/fibonacci.rs index 1331d2c5..1b24c536 100644 --- a/examples/fibonacci-square/src/fibonacci.rs +++ b/examples/fibonacci-square/src/fibonacci.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{get_custom_commit_id, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use proofman::{WitnessManager, WitnessComponent}; use p3_field::PrimeField; @@ -46,7 +46,7 @@ impl FibonacciSquare { let mut b = pctx.get_public_value("in2"); let num_rows = pctx.global_info.airs[airgroup_id][air_id].num_rows; - let mut trace = FibonacciSquareTrace::new(num_rows); + let mut trace = FibonacciSquareTrace::new_zeroes(num_rows); trace[0].a = F::from_canonical_u64(a); trace[0].b = F::from_canonical_u64(b); @@ -60,20 +60,12 @@ impl FibonacciSquare { trace[i].b = F::from_canonical_u64(b); } - let (buffer_size_rom, offsets_rom, commit_id) = ectx.buffer_allocator.as_ref().get_buffer_info_custom_commit( - &sctx, - FIBONACCI_SQUARE_AIRGROUP_ID, - FIBONACCI_SQUARE_AIR_IDS[0], - "rom", - )?; + let mut trace_rom = FibonacciSquareRomTrace::new_zeroes(num_rows); + let commit_id = get_custom_commit_id(&sctx, FIBONACCI_SQUARE_AIRGROUP_ID, FIBONACCI_SQUARE_AIR_IDS[0], "rom"); - let mut buffer_rom = vec![F::zero(); buffer_size_rom as usize]; - - let mut trace_custom_commits = - FibonacciSquareRomTrace::map_buffer(&mut buffer_rom, num_rows, offsets_rom[0] as usize)?; for i in 0..num_rows { - trace_custom_commits[i].line = F::from_canonical_u64(3 + i as u64); - trace_custom_commits[i].flags = F::from_canonical_u64(2 + i as u64); + trace_rom[i].line = F::from_canonical_u64(3 + i as u64); + trace_rom[i].flags = F::from_canonical_u64(2 + i as u64); } pctx.set_public_value_by_name(b, "out", None); @@ -81,13 +73,6 @@ impl FibonacciSquare { pctx.set_proof_value("value1", F::from_canonical_u64(5)); pctx.set_proof_value("value2", F::from_canonical_u64(125)); - // Not needed, for debugging! - // let mut result = F::zero(); - // for (i, _) in buffer.iter().enumerate() { - // result += buffer[i] * F::from_canonical_u64(i as u64); - // } - // log::info!("Result Fibonacci buffer: {:?}", result); - let mut air_instance = AirInstance::new( sctx.clone(), FIBONACCI_SQUARE_AIRGROUP_ID, @@ -98,10 +83,9 @@ impl FibonacciSquare { air_instance.set_airvalue("FibonacciSquare.fibo1", Some(vec![0]), F::from_canonical_u64(1)); air_instance.set_airvalue("FibonacciSquare.fibo1", Some(vec![1]), F::from_canonical_u64(2)); air_instance.set_airvalue_ext("FibonacciSquare.fibo3", None, vec![F::from_canonical_u64(5); 3]); - match ectx.cached_buffers_path.as_ref().and_then(|cached_buffers| cached_buffers.get("rom").cloned()) { - Some(buffer_path) => air_instance.set_custom_commit_cached_file(&sctx, commit_id, buffer_path), - None => air_instance.set_custom_commit_id_buffer(&sctx, buffer_rom, commit_id), - } + + air_instance.set_custom_commit_id_buffer(&sctx, trace_rom.buffer.unwrap(), commit_id); + let (is_myne, gid) = ectx.dctx.write().unwrap().add_instance(FIBONACCI_SQUARE_AIRGROUP_ID, FIBONACCI_SQUARE_AIR_IDS[0], 1); if is_myne { diff --git a/examples/fibonacci-square/src/module.rs b/examples/fibonacci-square/src/module.rs index 6b5e2e03..d58abe4a 100644 --- a/examples/fibonacci-square/src/module.rs +++ b/examples/fibonacci-square/src/module.rs @@ -47,7 +47,7 @@ impl Module let module = pctx.get_public_value("mod"); let num_rows = pctx.global_info.airs[FIBONACCI_SQUARE_AIRGROUP_ID][MODULE_AIR_IDS[0]].num_rows; - let mut trace = ModuleTrace::new(num_rows); + let mut trace = ModuleTrace::new_zeroes(num_rows); //range_check(colu: mod - x_mod, min: 1, max: 2**8-1); let range = self.std_lib.get_range(BigInt::from(1), BigInt::from((1 << 8) - 1), None); diff --git a/hints/Cargo.toml b/hints/Cargo.toml index cef188a7..10a208e7 100644 --- a/hints/Cargo.toml +++ b/hints/Cargo.toml @@ -7,3 +7,4 @@ edition = "2021" proofman-starks-lib-c = { path = "../provers/starks-lib-c" } proofman-common = { path = "../common" } p3-field.workspace = true +log.workspace = true \ No newline at end of file diff --git a/hints/src/hints.rs b/hints/src/hints.rs index faf73d60..f7d0a9ac 100644 --- a/hints/src/hints.rs +++ b/hints/src/hints.rs @@ -1,6 +1,6 @@ use proofman_starks_lib_c::{ - acc_hint_field_c, acc_mul_hint_fields_c, get_hint_field_c, get_hint_ids_by_name_c, mul_hint_fields_c, - print_expression_c, print_row_c, set_hint_field_c, VecU64Result, + acc_hint_field_c, acc_mul_hint_fields_c, get_hint_field_c, get_hint_ids_by_name_c, mul_hint_fields_c, print_row_c, + set_hint_field_c, VecU64Result, }; use std::collections::HashMap; @@ -34,6 +34,8 @@ pub struct HintFieldInfo { string_value: *mut u8, pub matrix_size: u64, pub pos: *mut u64, + expression_line: *mut u8, + expression_line_size: u64, } #[repr(C)] @@ -687,8 +689,8 @@ pub fn mul_hint_fields( let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; let steps_params = StepsParams { + witness: air_instance.get_witness_ptr() as *mut c_void, trace: air_instance.get_trace_ptr() as *mut c_void, - pols: air_instance.get_buffer_ptr() as *mut c_void, public_inputs: public_inputs_ptr, challenges: challenges_ptr, airgroup_values: air_instance.airgroup_values.as_ptr() as *mut c_void, @@ -698,6 +700,7 @@ pub fn mul_hint_fields( p_const_pols: const_pols_ptr, p_const_tree: const_tree_ptr, custom_commits: air_instance.get_custom_commits_ptr(), + custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; mul_hint_fields_c( @@ -732,8 +735,8 @@ pub fn acc_hint_field( let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; let steps_params = StepsParams { + witness: air_instance.get_witness_ptr() as *mut c_void, trace: air_instance.get_trace_ptr() as *mut c_void, - pols: air_instance.get_buffer_ptr() as *mut c_void, public_inputs: public_inputs_ptr, challenges: challenges_ptr, airgroup_values: air_instance.airgroup_values.as_ptr() as *mut c_void, @@ -743,6 +746,7 @@ pub fn acc_hint_field( p_const_pols: const_pols_ptr, p_const_tree: const_tree_ptr, custom_commits: air_instance.get_custom_commits_ptr(), + custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; let raw_ptr = acc_hint_field_c( @@ -785,8 +789,8 @@ pub fn acc_mul_hint_fields( let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; let steps_params = StepsParams { + witness: air_instance.get_witness_ptr() as *mut c_void, trace: air_instance.get_trace_ptr() as *mut c_void, - pols: air_instance.get_buffer_ptr() as *mut c_void, public_inputs: public_inputs_ptr, challenges: challenges_ptr, airgroup_values: air_instance.airgroup_values.as_ptr() as *mut c_void, @@ -796,6 +800,7 @@ pub fn acc_mul_hint_fields( p_const_pols: const_pols_ptr, p_const_tree: const_tree_ptr, custom_commits: air_instance.get_custom_commits_ptr(), + custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; let raw_ptr = acc_mul_hint_fields_c( @@ -835,8 +840,8 @@ pub fn get_hint_field( let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; let steps_params = StepsParams { + witness: air_instance.get_witness_ptr() as *mut c_void, trace: air_instance.get_trace_ptr() as *mut c_void, - pols: air_instance.get_buffer_ptr() as *mut c_void, public_inputs: public_inputs_ptr, challenges: challenges_ptr, airgroup_values: air_instance.airgroup_values.as_ptr() as *mut c_void, @@ -846,6 +851,7 @@ pub fn get_hint_field( p_const_pols: const_pols_ptr, p_const_tree: const_tree_ptr, custom_commits: air_instance.get_custom_commits_ptr(), + custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; let raw_ptr = get_hint_field_c( @@ -862,6 +868,11 @@ pub fn get_hint_field( if value.matrix_size != 0 { panic!("get_hint_field can only be called with single expressions, but {} is an array", hint_field_name); } + if options.print_expression { + let str_slice = std::slice::from_raw_parts(value.expression_line, value.expression_line_size as usize); + let str_line = std::str::from_utf8(str_slice).unwrap(); + log::info!("HintsInf: {}", str_line); + } HintCol::from_hint_field(value) } } @@ -883,8 +894,8 @@ pub fn get_hint_field_a( let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; let steps_params = StepsParams { + witness: air_instance.get_witness_ptr() as *mut c_void, trace: air_instance.get_trace_ptr() as *mut c_void, - pols: air_instance.get_buffer_ptr() as *mut c_void, public_inputs: public_inputs_ptr, challenges: challenges_ptr, airgroup_values: air_instance.airgroup_values.as_ptr() as *mut c_void, @@ -894,6 +905,7 @@ pub fn get_hint_field_a( p_const_pols: const_pols_ptr, p_const_tree: const_tree_ptr, custom_commits: air_instance.get_custom_commits_ptr(), + custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; let raw_ptr = get_hint_field_c( @@ -912,6 +924,11 @@ pub fn get_hint_field_a( if v == 0 && h.matrix_size != 1 { panic!("get_hint_field_m can only be called with an array of expressions!"); } + if options.print_expression { + let str_slice = std::slice::from_raw_parts(h.expression_line, h.expression_line_size as usize); + let str_line = std::str::from_utf8(str_slice).unwrap(); + log::info!("HintsInf: {}", str_line); + } let hint_value = HintCol::from_hint_field(h); hint_field_values.push(hint_value); } @@ -937,8 +954,8 @@ pub fn get_hint_field_m( let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; let steps_params = StepsParams { + witness: air_instance.get_witness_ptr() as *mut c_void, trace: air_instance.get_trace_ptr() as *mut c_void, - pols: air_instance.get_buffer_ptr() as *mut c_void, public_inputs: public_inputs_ptr, challenges: challenges_ptr, airgroup_values: air_instance.airgroup_values.as_ptr() as *mut c_void, @@ -948,6 +965,7 @@ pub fn get_hint_field_m( p_const_pols: const_pols_ptr, p_const_tree: const_tree_ptr, custom_commits: air_instance.get_custom_commits_ptr(), + custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; let raw_ptr = get_hint_field_c( @@ -972,6 +990,11 @@ pub fn get_hint_field_m( for p in 0..h.matrix_size { pos.push(h.pos.wrapping_add(p as usize) as u64); } + if options.print_expression { + let str_slice = std::slice::from_raw_parts(h.expression_line, h.expression_line_size as usize); + let str_line = std::str::from_utf8(str_slice).unwrap(); + log::info!("HintsInf: {}", str_line); + } hint_field_values.insert(pos, hint_value); } @@ -1004,6 +1027,11 @@ pub fn get_hint_field_constant( unsafe { let hint_field_values = &*(raw_ptr as *mut HintFieldInfoValues); let value = &*(hint_field_values.hint_field_values.add(0)); + if options.print_expression { + let str_slice = std::slice::from_raw_parts(value.expression_line, value.expression_line_size as usize); + let str_line = std::str::from_utf8(str_slice).unwrap(); + log::info!("HintsInf: {}", str_line); + } if value.matrix_size != 0 { panic!("get_hint_field can only be called with single expressions, but {} is an array", hint_field_name); } @@ -1041,6 +1069,11 @@ pub fn get_hint_field_constant_a( if v == 0 && h.matrix_size != 1 { panic!("get_hint_field_m can only be called with an array of expressions!"); } + if options.print_expression { + let str_slice = std::slice::from_raw_parts(h.expression_line, h.expression_line_size as usize); + let str_line = std::str::from_utf8(str_slice).unwrap(); + log::info!("HintsInf: {}", str_line); + } let hint_value = HintCol::from_hint_field(h); hint_field_values.push(hint_value); } @@ -1083,6 +1116,11 @@ pub fn get_hint_field_constant_m( hint_field_name ); } + if options.print_expression { + let str_slice = std::slice::from_raw_parts(h.expression_line, h.expression_line_size as usize); + let str_line = std::str::from_utf8(str_slice).unwrap(); + log::info!("HintsInf: {}", str_line); + } let hint_value = HintCol::from_hint_field(h); let mut pos = Vec::new(); for p in 0..h.matrix_size { @@ -1103,8 +1141,8 @@ pub fn set_hint_field( values: &HintFieldValue, ) { let steps_params = StepsParams { + witness: air_instance.get_witness_ptr() as *mut c_void, trace: air_instance.get_trace_ptr() as *mut c_void, - pols: air_instance.get_buffer_ptr() as *mut c_void, public_inputs: std::ptr::null_mut(), challenges: std::ptr::null_mut(), airgroup_values: std::ptr::null_mut(), @@ -1114,6 +1152,7 @@ pub fn set_hint_field( p_const_pols: std::ptr::null_mut(), p_const_tree: std::ptr::null_mut(), custom_commits: [std::ptr::null_mut(); 10], + custom_commits_extended: [std::ptr::null_mut(); 10], }; let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); @@ -1137,8 +1176,8 @@ pub fn set_hint_field_val( value: HintFieldOutput, ) { let steps_params = StepsParams { + witness: std::ptr::null_mut(), trace: std::ptr::null_mut(), - pols: std::ptr::null_mut(), public_inputs: std::ptr::null_mut(), challenges: std::ptr::null_mut(), airgroup_values: air_instance.airgroup_values.as_mut_ptr() as *mut c_void, @@ -1148,6 +1187,7 @@ pub fn set_hint_field_val( p_const_pols: std::ptr::null_mut(), p_const_tree: std::ptr::null_mut(), custom_commits: [std::ptr::null_mut(); 10], + custom_commits_extended: [std::ptr::null_mut(); 10], }; let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); @@ -1172,50 +1212,12 @@ pub fn set_hint_field_val( air_instance.set_airgroupvalue_calculated(id as usize); } -pub fn print_expression( - setup_ctx: &SetupCtx, - air_instance: &mut AirInstance, - expr: &HintFieldValue, - first_print_value: u64, - last_print_value: u64, -) { - let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); - - match expr { - HintFieldValue::Column(vec) => { - print_expression_c( - (&setup.p_setup).into(), - vec.as_ptr() as *mut c_void, - 1, - first_print_value, - last_print_value, - ); - } - HintFieldValue::ColumnExtended(vec) => { - print_expression_c( - (&setup.p_setup).into(), - vec.as_ptr() as *mut c_void, - 3, - first_print_value, - last_print_value, - ); - } - HintFieldValue::Field(val) => { - println!("Field value: {:?}", val); - } - HintFieldValue::FieldExtended(val) => { - println!("FieldExtended values: {:?}", val); - } - HintFieldValue::String(_str) => panic!(), - } -} - pub fn print_row(setup_ctx: &SetupCtx, air_instance: &AirInstance, stage: u64, row: u64) { let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); let buffer = match stage == 1 { - true => air_instance.get_trace_ptr() as *mut c_void, - false => air_instance.get_buffer_ptr() as *mut c_void, + true => air_instance.get_witness_ptr() as *mut c_void, + false => air_instance.get_trace_ptr() as *mut c_void, }; print_row_c((&setup.p_setup).into(), buffer, stage, row); diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 498841d7..f90a0900 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -81,6 +81,32 @@ fn trace_impl(input: TokenStream2) -> Result { buff_uninit.set_len(num_rows); } let buffer: Vec<#row_struct_name<#generics>> = unsafe { std::mem::transmute(buff_uninit) }; + let slice_trace = unsafe { + std::slice::from_raw_parts_mut( + buffer.as_ptr() as *mut #row_struct_name<#generics>, + num_rows, + ) + }; + + #trace_struct_name { + buffer: Some(buffer), + slice_trace, + num_rows, + } + } + + pub fn new_zeroes(num_rows: usize) -> Self { + assert!(num_rows >= 2); + assert!(num_rows & (num_rows - 1) == 0); + + let buffer = vec![#generics::default(); num_rows * #row_struct_name::<#generics>::ROW_SIZE]; + let slice_trace = unsafe { + std::slice::from_raw_parts_mut( + buffer.as_ptr() as *mut #row_struct_name<#generics>, + num_rows, + ) + }; +>>>>>>> adba4fd1 (Renaming, improving logs, cleaning) #trace_struct_name { buffer, diff --git a/pil2-components/test/simple/rs/src/simple_left.rs b/pil2-components/test/simple/rs/src/simple_left.rs index ba705325..389fd881 100644 --- a/pil2-components/test/simple/rs/src/simple_left.rs +++ b/pil2-components/test/simple/rs/src/simple_left.rs @@ -69,7 +69,7 @@ where ); if stage == 1 { - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(airgroup_id, air_id).num_rows(); // I cannot, programatically, link the permutation trace with its air_id diff --git a/pil2-components/test/simple/rs/src/simple_right.rs b/pil2-components/test/simple/rs/src/simple_right.rs index 327f050a..83bcd8ad 100644 --- a/pil2-components/test/simple/rs/src/simple_right.rs +++ b/pil2-components/test/simple/rs/src/simple_right.rs @@ -66,7 +66,7 @@ where ); if stage == 1 { - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(airgroup_id, air_id).num_rows(); // I cannot, programatically, link the permutation trace with its air_id diff --git a/pil2-components/test/std/connection/rs/src/connection1.rs b/pil2-components/test/std/connection/rs/src/connection1.rs index 3bfa98a3..a7005a89 100644 --- a/pil2-components/test/std/connection/rs/src/connection1.rs +++ b/pil2-components/test/std/connection/rs/src/connection1.rs @@ -29,7 +29,7 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { // For simplicity, add a single instance of each air let num_rows = pctx.global_info.airs[CONNECTION_AIRGROUP_ID][CONNECTION_1_AIR_IDS[0]].num_rows; - let trace = Connection1Trace::new(num_rows); + let trace = Connection1Trace::new_zeroes(num_rows); let air_instance = AirInstance::new( sctx.clone(), @@ -72,7 +72,7 @@ where ); if stage == 1 { - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(CONNECTION_AIRGROUP_ID, CONNECTION_1_AIR_IDS[0]).num_rows(); let mut trace = Connection1Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); diff --git a/pil2-components/test/std/connection/rs/src/connection2.rs b/pil2-components/test/std/connection/rs/src/connection2.rs index 6db92acb..ae8323d3 100644 --- a/pil2-components/test/std/connection/rs/src/connection2.rs +++ b/pil2-components/test/std/connection/rs/src/connection2.rs @@ -28,7 +28,7 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let num_rows = pctx.global_info.airs[CONNECTION_AIRGROUP_ID][CONNECTION_2_AIR_IDS[0]].num_rows; - let trace = Connection2Trace::new(num_rows); + let trace = Connection2Trace::new_zeroes(num_rows); let air_instance = AirInstance::new( sctx.clone(), @@ -71,7 +71,7 @@ where ); if stage == 1 { - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(CONNECTION_AIRGROUP_ID, CONNECTION_2_AIR_IDS[0]).num_rows(); let mut trace = Connection2Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); diff --git a/pil2-components/test/std/connection/rs/src/connection_new.rs b/pil2-components/test/std/connection/rs/src/connection_new.rs index 418e42c4..1dccfdf4 100644 --- a/pil2-components/test/std/connection/rs/src/connection_new.rs +++ b/pil2-components/test/std/connection/rs/src/connection_new.rs @@ -28,7 +28,7 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let num_rows = pctx.global_info.airs[CONNECTION_AIRGROUP_ID][CONNECTION_NEW_AIR_IDS[0]].num_rows; - let trace = ConnectionNewTrace::new(num_rows); + let trace = ConnectionNewTrace::new_zeroes(num_rows); let air_instance = AirInstance::new( sctx.clone(), @@ -71,7 +71,7 @@ where ); if stage == 1 { - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(CONNECTION_AIRGROUP_ID, CONNECTION_NEW_AIR_IDS[0]).num_rows(); let mut trace = ConnectionNewTrace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); diff --git a/pil2-components/test/std/lookup/rs/src/lookup0.rs b/pil2-components/test/std/lookup/rs/src/lookup0.rs index dfc622fd..bd5e726c 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup0.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup0.rs @@ -66,7 +66,7 @@ where ); if stage == 1 { - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_0_AIR_IDS[0]).num_rows(); let mut trace = Lookup0Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); diff --git a/pil2-components/test/std/lookup/rs/src/lookup1.rs b/pil2-components/test/std/lookup/rs/src/lookup1.rs index da0ea753..47e69321 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup1.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup1.rs @@ -66,7 +66,7 @@ where ); if stage == 1 { - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_1_AIR_IDS[0]).num_rows(); let mut trace = Lookup1Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs index 156f6423..aaba64b0 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs @@ -66,7 +66,7 @@ where ); if stage == 1 { - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_2_12_AIR_IDS[0]).num_rows(); let mut trace = Lookup2_12Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs index 225de754..23fd207b 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs @@ -66,7 +66,7 @@ where ); if stage == 1 { - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_2_13_AIR_IDS[0]).num_rows(); let mut trace = Lookup2_13Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs index 09779c27..d1dfb65b 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs @@ -66,7 +66,7 @@ where ); if stage == 1 { - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_2_15_AIR_IDS[0]).num_rows(); let mut trace = Lookup2_15Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); diff --git a/pil2-components/test/std/lookup/rs/src/lookup3.rs b/pil2-components/test/std/lookup/rs/src/lookup3.rs index 70f23056..8dd4e20d 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup3.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup3.rs @@ -58,7 +58,7 @@ impl WitnessComponent for Lookup3 { ); if stage == 1 { - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_3_AIR_IDS[0]).num_rows(); let mut trace = Lookup3Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs index 374c9a6a..fbab5f9e 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs @@ -89,7 +89,7 @@ where ); if stage == 1 { - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(air_instance.airgroup_id, air_instance.air_id).num_rows(); // I cannot, programatically, link the permutation trace with its air_id diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs index 7c503c1a..d1c9cbf3 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs @@ -74,7 +74,7 @@ where ); if stage == 1 { - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(airgroup_id, air_id).num_rows(); // I cannot, programatically, link the permutation trace with its air_id diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs index 409f0f84..6de958cf 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs @@ -74,7 +74,7 @@ where ); if stage == 1 { - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(airgroup_id, air_id).num_rows(); // I cannot, programatically, link the permutation trace with its air_id diff --git a/pil2-components/test/std/permutation/rs/src/permutation2.rs b/pil2-components/test/std/permutation/rs/src/permutation2.rs index f627101f..a7eefcb7 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation2.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation2.rs @@ -65,7 +65,7 @@ impl WitnessComponent for Permutation2 { ); if stage == 1 { - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(airgroup_id, air_id).num_rows(); let mut trace = Permutation2_6Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs index 7cb59b88..bd5dd707 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs @@ -37,7 +37,7 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let num_rows = pctx.global_info.airs[MULTI_RANGE_CHECK_1_AIRGROUP_ID][MULTI_RANGE_CHECK_1_AIR_IDS[0]].num_rows; - let trace = MultiRangeCheck1Trace::new(num_rows); + let trace = MultiRangeCheck1Trace::new_zeroes(num_rows); let air_instance = AirInstance::new( sctx.clone(), @@ -75,7 +75,7 @@ where let air_instances_vec = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap(); let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(MULTI_RANGE_CHECK_1_AIRGROUP_ID, MULTI_RANGE_CHECK_1_AIR_IDS[0]).num_rows(); let mut trace = MultiRangeCheck1Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs index 6ab0e9ec..7b44680d 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs @@ -37,7 +37,7 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let num_rows = pctx.global_info.airs[MULTI_RANGE_CHECK_2_AIRGROUP_ID][MULTI_RANGE_CHECK_2_AIR_IDS[0]].num_rows; - let trace = MultiRangeCheck2Trace::new(num_rows); + let trace = MultiRangeCheck2Trace::new_zeroes(num_rows); let air_instance = AirInstance::new( sctx.clone(), @@ -74,7 +74,7 @@ where let proof_ctx = pctx.clone(); let air_instances_vec = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap(); let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(MULTI_RANGE_CHECK_2_AIRGROUP_ID, MULTI_RANGE_CHECK_2_AIR_IDS[0]).num_rows(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check1.rs b/pil2-components/test/std/range_check/rs/src/range_check1.rs index a6192526..492c95d3 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check1.rs @@ -33,7 +33,7 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let num_rows = pctx.global_info.airs[RANGE_CHECK_1_AIRGROUP_ID][RANGE_CHECK_1_AIR_IDS[0]].num_rows; - let trace = RangeCheck1Trace::new(num_rows); + let trace = RangeCheck1Trace::new_zeroes(num_rows); let air_instance = AirInstance::new( sctx.clone(), @@ -69,7 +69,7 @@ where if stage == 1 { let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(RANGE_CHECK_1_AIRGROUP_ID, RANGE_CHECK_1_AIR_IDS[0]).num_rows(); let mut trace = RangeCheck1Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check2.rs b/pil2-components/test/std/range_check/rs/src/range_check2.rs index abecaee0..fbe7159a 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check2.rs @@ -33,7 +33,7 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let num_rows = pctx.global_info.airs[RANGE_CHECK_2_AIRGROUP_ID][RANGE_CHECK_2_AIR_IDS[0]].num_rows; - let trace = RangeCheck2Trace::new(num_rows); + let trace = RangeCheck2Trace::new_zeroes(num_rows); let air_instance = AirInstance::new( sctx.clone(), @@ -69,7 +69,7 @@ where if stage == 1 { let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(RANGE_CHECK_2_AIRGROUP_ID, RANGE_CHECK_2_AIR_IDS[0]).num_rows(); let mut trace = RangeCheck2Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check3.rs b/pil2-components/test/std/range_check/rs/src/range_check3.rs index 7e046a92..27fe7107 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check3.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check3.rs @@ -33,7 +33,7 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let num_rows = pctx.global_info.airs[RANGE_CHECK_3_AIRGROUP_ID][RANGE_CHECK_3_AIR_IDS[0]].num_rows; - let trace = RangeCheck3Trace::new(num_rows); + let trace = RangeCheck3Trace::new_zeroes(num_rows); let air_instance = AirInstance::new( sctx.clone(), @@ -70,7 +70,7 @@ where let proof_ctx = pctx.clone(); let air_instances_vec = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap(); let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(RANGE_CHECK_3_AIRGROUP_ID, RANGE_CHECK_3_AIR_IDS[0]).num_rows(); let mut trace = RangeCheck3Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check4.rs b/pil2-components/test/std/range_check/rs/src/range_check4.rs index 90fe9e1c..306e90cd 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check4.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check4.rs @@ -34,7 +34,7 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let num_rows = pctx.global_info.airs[RANGE_CHECK_4_AIRGROUP_ID][RANGE_CHECK_4_AIR_IDS[0]].num_rows; - let trace = RangeCheck4Trace::new(num_rows); + let trace = RangeCheck4Trace::new_zeroes(num_rows); let air_instance = AirInstance::new( sctx.clone(), @@ -71,7 +71,7 @@ where let proof_ctx = pctx.clone(); let air_instances_vec = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap(); let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(RANGE_CHECK_4_AIRGROUP_ID, RANGE_CHECK_4_AIR_IDS[0]).num_rows(); let mut trace = RangeCheck4Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs index 020360dd..fdb59854 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs @@ -38,7 +38,7 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let num_rows = pctx.global_info.airs[RANGE_CHECK_DYNAMIC_1_AIRGROUP_ID][RANGE_CHECK_DYNAMIC_1_AIR_IDS[0]].num_rows; - let trace = RangeCheckDynamic1Trace::new(num_rows); + let trace = RangeCheckDynamic1Trace::new_zeroes(num_rows); let air_instance = AirInstance::new( sctx.clone(), @@ -78,7 +78,7 @@ where let proof_ctx = pctx.clone(); let air_instances_vec = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap(); let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(RANGE_CHECK_DYNAMIC_1_AIRGROUP_ID, RANGE_CHECK_DYNAMIC_1_AIR_IDS[0]).num_rows(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs index f13575aa..df3b6208 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs @@ -39,7 +39,7 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let num_rows = pctx.global_info.airs[RANGE_CHECK_DYNAMIC_2_AIRGROUP_ID][RANGE_CHECK_DYNAMIC_2_AIR_IDS[0]].num_rows; - let trace = RangeCheckDynamic2Trace::new(num_rows); + let trace = RangeCheckDynamic2Trace::new_zeroes(num_rows); let air_instance = AirInstance::new( sctx.clone(), @@ -79,7 +79,7 @@ where let proof_ctx = pctx.clone(); let air_instances_vec = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap(); let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(RANGE_CHECK_DYNAMIC_2_AIRGROUP_ID, RANGE_CHECK_DYNAMIC_2_AIR_IDS[0]).num_rows(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs index 197568bc..c07841bb 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs @@ -38,7 +38,7 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let num_rows = pctx.global_info.airs[RANGE_CHECK_MIX_AIRGROUP_ID][RANGE_CHECK_MIX_AIR_IDS[0]].num_rows; - let trace = RangeCheckMixTrace::new(num_rows); + let trace = RangeCheckMixTrace::new_zeroes(num_rows); let air_instance = AirInstance::new( sctx.clone(), @@ -75,7 +75,7 @@ where let proof_ctx = pctx.clone(); let air_instances_vec = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap(); let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let buffer = &mut air_instance.trace; + let buffer = &mut air_instance.witness; let num_rows = pctx.pilout.get_air(RANGE_CHECK_MIX_AIRGROUP_ID, RANGE_CHECK_MIX_AIR_IDS[0]).num_rows(); let mut trace = RangeCheckMixTrace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); diff --git a/pil2-stark/lib/include/starks_lib.h b/pil2-stark/lib/include/starks_lib.h index 33762bf8..11480875 100644 --- a/pil2-stark/lib/include/starks_lib.h +++ b/pil2-stark/lib/include/starks_lib.h @@ -26,8 +26,6 @@ // ======================================================================================== void *stark_info_new(char* filename); uint64_t get_map_total_n(void *pStarkInfo); - uint64_t get_map_total_n_custom_commits(void *pStarkInfo, uint64_t commit_id); - uint64_t get_map_offsets(void *pStarkInfo, char *stage, bool flag); void *get_custom_commit_map_ids(void *pStarkInfo, uint64_t commit_id, uint64_t stage); void stark_info_free(void *pStarkInfo); @@ -72,10 +70,10 @@ void calculate_quotient_polynomial(void *pStarks, void* stepsParams); void calculate_impols_expressions(void *pStarks, uint64_t step, void* stepsParams); - void extend_and_merkelize_custom_commit(void *pStarks, uint64_t commitId, uint64_t step, void *buffer, void *pProof, void *pBuffHelper, char *treeFile); - void load_custom_commit(void *pStarks, uint64_t commitId, uint64_t step, void *buffer, void *pProof, char *treeFile); + void extend_and_merkelize_custom_commit(void *pStarks, uint64_t commitId, uint64_t step, void *buffer, void *bufferExt, void *pProof, void *pBuffHelper, char *treeFile); + void load_custom_commit(void *pStarks, uint64_t commitId, uint64_t step, void *buffer, void *bufferExt, void *pProof, char *treeFile); - void commit_stage(void *pStarks, uint32_t elementType, uint64_t step, void *trace, void *buffer, void *pProof, void *pBuffHelper); + void commit_stage(void *pStarks, uint32_t elementType, uint64_t step, void *witness, void *buffer, void *pProof, void *pBuffHelper); void compute_lev(void *pStarks, void *xiChallenge, void* LEv); void compute_evals(void *pStarks, void *params, void *LEv, void *pProof); @@ -112,18 +110,17 @@ // Global constraints // ================================================================================= - bool verify_global_constraints(void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues); + void *verify_global_constraints(void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues); void *get_hint_field_global_constraints(void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues, uint64_t hintId, char *hintFieldName, bool print_expression); uint64_t set_hint_field_global_constraints(void* p_globalinfo_bin, void *proofValues, void *values, uint64_t hintId, char *hintFieldName); // Debug functions // ================================================================================= void print_row(void *pSetupCtx, void *buffer, uint64_t stage, uint64_t row); - void print_expression(void *pSetupCtx, void* pol, uint64_t dim, uint64_t first_value, uint64_t last_value); // Recursive proof // ================================================================================= - void *gen_recursive_proof(void *pSetupCtx, char* globalInfoFile, uint64_t airgroupId, void* pAddress, void *pConstPols, void *pConstTree, void* pPublicInputs, char *proof_file, bool vadcop); + void *gen_recursive_proof(void *pSetupCtx, char* globalInfoFile, uint64_t airgroupId, void* witness, void *pConstPols, void *pConstTree, void* pPublicInputs, char *proof_file, bool vadcop); void *get_zkin_ptr(char *zkin_file); void *add_recursive2_verkey(void *pZkin, char* recursive2VerKeyFilename); void *join_zkin_recursive2(char* globalInfoFile, uint64_t airgroupId, void* pPublics, void* pChallenges, void *zkin1, void *zkin2, void *starkInfoRecursive2); @@ -133,11 +130,11 @@ void *get_zkin_proof(char* zkin); void zkin_proof_free(void *pZkinProof); void serialized_proof_free(char *zkinCStr); - void get_committed_pols(void *pWitness, char* execFile, void *pAddress, void* pPublics, uint64_t sizeWitness, uint64_t N, uint64_t nPublics, uint64_t offsetCm1, uint64_t nCols); + void get_committed_pols(void *circomWitness, char* execFile, void *witness, void* pPublics, uint64_t sizeWitness, uint64_t N, uint64_t nPublics, uint64_t nCols); // Final proof // ================================================================================= - void gen_final_snark_proof(void *pWitnessFinal, char* zkeyFile, char* outputDir); + void gen_final_snark_proof(void *circomWitnessFinal, char* zkeyFile, char* outputDir); // Util calls // ================================================================================= diff --git a/pil2-stark/src/api/starks_api.cpp b/pil2-stark/src/api/starks_api.cpp index fdf69768..374fe6bc 100644 --- a/pil2-stark/src/api/starks_api.cpp +++ b/pil2-stark/src/api/starks_api.cpp @@ -161,11 +161,6 @@ uint64_t get_map_total_n(void *pStarkInfo) return ((StarkInfo *)pStarkInfo)->mapTotalN; } -uint64_t get_map_total_n_custom_commits(void *pStarkInfo, uint64_t commit_id) { - auto starkInfo = *(StarkInfo *)pStarkInfo; - return starkInfo.mapTotalNcustomCommits[starkInfo.customCommits[commit_id].name]; -} - void *get_custom_commit_map_ids(void *pStarkInfo, uint64_t commit_id, uint64_t stage) { auto starkInfo = *(StarkInfo *)pStarkInfo; VecU64Result customCommitIds; @@ -180,12 +175,6 @@ void *get_custom_commit_map_ids(void *pStarkInfo, uint64_t commit_id, uint64_t s return new VecU64Result(customCommitIds); } -uint64_t get_map_offsets(void *pStarkInfo, char *stage, bool flag) -{ - auto starkInfo = (StarkInfo *)pStarkInfo; - return starkInfo->mapOffsets[std::make_pair(stage, flag)]; -} - void stark_info_free(void *pStarkInfo) { auto starkInfo = (StarkInfo *)pStarkInfo; @@ -333,25 +322,25 @@ void calculate_impols_expressions(void *pStarks, uint64_t step, void* stepsParam starks->calculateImPolsExpressions(step, *(StepsParams *)stepsParams); } -void extend_and_merkelize_custom_commit(void *pStarks, uint64_t commitId, uint64_t step, void *buffer, void *pProof, void *pBuffHelper, char *bufferFile) +void extend_and_merkelize_custom_commit(void *pStarks, uint64_t commitId, uint64_t step, void *buffer, void* bufferExt, void *pProof, void *pBuffHelper, char *bufferFile) { Starks *starks = (Starks *)pStarks; - starks->extendAndMerkelizeCustomCommit(commitId, step, (Goldilocks::Element *)buffer, *(FRIProof *)pProof, (Goldilocks::Element *)pBuffHelper, string(bufferFile)); + starks->extendAndMerkelizeCustomCommit(commitId, step, (Goldilocks::Element *)buffer, (Goldilocks::Element *)bufferExt, *(FRIProof *)pProof, (Goldilocks::Element *)pBuffHelper, string(bufferFile)); } -void load_custom_commit(void *pStarks, uint64_t commitId, uint64_t step, void *buffer, void *pProof, char *bufferFile) +void load_custom_commit(void *pStarks, uint64_t commitId, uint64_t step, void *buffer, void *bufferExt, void *pProof, char *bufferFile) { Starks *starks = (Starks *)pStarks; - starks->loadCustomCommit(commitId, step, (Goldilocks::Element *)buffer, *(FRIProof *)pProof, string(bufferFile)); + starks->loadCustomCommit(commitId, step, (Goldilocks::Element *)buffer, (Goldilocks::Element *)bufferExt, *(FRIProof *)pProof, string(bufferFile)); } -void commit_stage(void *pStarks, uint32_t elementType, uint64_t step, void *trace, void *buffer, void *pProof, void *pBuffHelper) { +void commit_stage(void *pStarks, uint32_t elementType, uint64_t step, void *witness, void *buffer, void *pProof, void *pBuffHelper) { // type == 1 => Goldilocks // type == 2 => BN128 switch (elementType) { case 1: - ((Starks *)pStarks)->commitStage(step, (Goldilocks::Element *)trace, (Goldilocks::Element *)buffer, *(FRIProof *)pProof, (Goldilocks::Element *)pBuffHelper); + ((Starks *)pStarks)->commitStage(step, (Goldilocks::Element *)witness, (Goldilocks::Element *)buffer, *(FRIProof *)pProof, (Goldilocks::Element *)pBuffHelper); break; default: cerr << "Invalid elementType: " << elementType << endl; @@ -503,8 +492,9 @@ void *verify_constraints(void *pSetupCtx, void* stepsParams) // Global Constraints // ================================================================================= -bool verify_global_constraints(void* p_globalinfo_bin, void *publics, void *challenges, void *proofValues, void **airgroupValues) { - return verifyGlobalConstraints(*(ExpressionsBin*)p_globalinfo_bin, (Goldilocks::Element *)publics, (Goldilocks::Element *)challenges, (Goldilocks::Element *)proofValues, (Goldilocks::Element **)airgroupValues); +void *verify_global_constraints(void* p_globalinfo_bin, void *publics, void *challenges, void *proofValues, void **airgroupValues) { + GlobalConstraintsResults *constraintsInfo = verifyGlobalConstraints(*(ExpressionsBin*)p_globalinfo_bin, (Goldilocks::Element *)publics, (Goldilocks::Element *)challenges, (Goldilocks::Element *)proofValues, (Goldilocks::Element **)airgroupValues); + return constraintsInfo; } void *get_hint_field_global_constraints(void* p_globalinfo_bin, void *publics, void *challenges, void *proofValues, void **airgroupValues, uint64_t hintId, char *hintFieldName, bool print_expression) @@ -521,25 +511,21 @@ uint64_t set_hint_field_global_constraints(void* p_globalinfo_bin, void *proofVa // Debug functions // ================================================================================= -void print_expression(void *pSetupCtx, void* pol, uint64_t dim, uint64_t first_value, uint64_t last_value) { - printExpression((Goldilocks::Element *)pol, dim, first_value, last_value); -} - void print_row(void *pSetupCtx, void *buffer, uint64_t stage, uint64_t row) { printRow(*(SetupCtx *)pSetupCtx, (Goldilocks::Element *)buffer, stage, row); } // Recursive proof // ================================================================================= -void *gen_recursive_proof(void *pSetupCtx, char* globalInfoFile, uint64_t airgroupId, void* pAddress, void *pConstPols, void *pConstTree, void* pPublicInputs, char* proof_file, bool vadcop) { +void *gen_recursive_proof(void *pSetupCtx, char* globalInfoFile, uint64_t airgroupId, void* witness, void *pConstPols, void *pConstTree, void* pPublicInputs, char* proof_file, bool vadcop) { json globalInfo; file2json(globalInfoFile, globalInfo); auto setup = *(SetupCtx *)pSetupCtx; if(setup.starkInfo.starkStruct.verificationHashType == "GL") { - return genRecursiveProof(*(SetupCtx *)pSetupCtx, globalInfo, airgroupId, (Goldilocks::Element *)pAddress, (Goldilocks::Element *)pConstPols, (Goldilocks::Element *)pConstTree, (Goldilocks::Element *)pPublicInputs, string(proof_file), vadcop); + return genRecursiveProof(*(SetupCtx *)pSetupCtx, globalInfo, airgroupId, (Goldilocks::Element *)witness, (Goldilocks::Element *)pConstPols, (Goldilocks::Element *)pConstTree, (Goldilocks::Element *)pPublicInputs, string(proof_file), vadcop); } else { - return genRecursiveProof(*(SetupCtx *)pSetupCtx, globalInfo, airgroupId, (Goldilocks::Element *)pAddress, (Goldilocks::Element *)pConstPols, (Goldilocks::Element *)pConstTree, (Goldilocks::Element *)pPublicInputs, string(proof_file), false); + return genRecursiveProof(*(SetupCtx *)pSetupCtx, globalInfo, airgroupId, (Goldilocks::Element *)witness, (Goldilocks::Element *)pConstPols, (Goldilocks::Element *)pConstTree, (Goldilocks::Element *)pPublicInputs, string(proof_file), false); } } @@ -625,12 +611,12 @@ void serialized_proof_free(char *zkinCStr) { delete[] zkinCStr; } -void get_committed_pols(void *pWitness, char* execFile, void *pAddress, void* pPublics, uint64_t sizeWitness, uint64_t N, uint64_t nPublics, uint64_t offsetCm1, uint64_t nCommitedPols) { - getCommitedPols((Goldilocks::Element *)pWitness, string(execFile), (Goldilocks::Element *)pAddress, (Goldilocks::Element *)pPublics, sizeWitness, N, nPublics, offsetCm1, nCommitedPols); +void get_committed_pols(void *circomWitness, char* execFile, void *witness, void* pPublics, uint64_t sizeWitness, uint64_t N, uint64_t nPublics, uint64_t nCommitedPols) { + getCommitedPols((Goldilocks::Element *)circomWitness, string(execFile), (Goldilocks::Element *)witness, (Goldilocks::Element *)pPublics, sizeWitness, N, nPublics, nCommitedPols); } -void gen_final_snark_proof(void *pWitnessFinal, char* zkeyFile, char* outputDir) { - genFinalSnarkProof(pWitnessFinal, string(zkeyFile), string(outputDir)); +void gen_final_snark_proof(void *circomWitnessFinal, char* zkeyFile, char* outputDir) { + genFinalSnarkProof(circomWitnessFinal, string(zkeyFile), string(outputDir)); } void setLogLevel(uint64_t level) { diff --git a/pil2-stark/src/api/starks_api.hpp b/pil2-stark/src/api/starks_api.hpp index 33762bf8..11480875 100644 --- a/pil2-stark/src/api/starks_api.hpp +++ b/pil2-stark/src/api/starks_api.hpp @@ -26,8 +26,6 @@ // ======================================================================================== void *stark_info_new(char* filename); uint64_t get_map_total_n(void *pStarkInfo); - uint64_t get_map_total_n_custom_commits(void *pStarkInfo, uint64_t commit_id); - uint64_t get_map_offsets(void *pStarkInfo, char *stage, bool flag); void *get_custom_commit_map_ids(void *pStarkInfo, uint64_t commit_id, uint64_t stage); void stark_info_free(void *pStarkInfo); @@ -72,10 +70,10 @@ void calculate_quotient_polynomial(void *pStarks, void* stepsParams); void calculate_impols_expressions(void *pStarks, uint64_t step, void* stepsParams); - void extend_and_merkelize_custom_commit(void *pStarks, uint64_t commitId, uint64_t step, void *buffer, void *pProof, void *pBuffHelper, char *treeFile); - void load_custom_commit(void *pStarks, uint64_t commitId, uint64_t step, void *buffer, void *pProof, char *treeFile); + void extend_and_merkelize_custom_commit(void *pStarks, uint64_t commitId, uint64_t step, void *buffer, void *bufferExt, void *pProof, void *pBuffHelper, char *treeFile); + void load_custom_commit(void *pStarks, uint64_t commitId, uint64_t step, void *buffer, void *bufferExt, void *pProof, char *treeFile); - void commit_stage(void *pStarks, uint32_t elementType, uint64_t step, void *trace, void *buffer, void *pProof, void *pBuffHelper); + void commit_stage(void *pStarks, uint32_t elementType, uint64_t step, void *witness, void *buffer, void *pProof, void *pBuffHelper); void compute_lev(void *pStarks, void *xiChallenge, void* LEv); void compute_evals(void *pStarks, void *params, void *LEv, void *pProof); @@ -112,18 +110,17 @@ // Global constraints // ================================================================================= - bool verify_global_constraints(void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues); + void *verify_global_constraints(void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues); void *get_hint_field_global_constraints(void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues, uint64_t hintId, char *hintFieldName, bool print_expression); uint64_t set_hint_field_global_constraints(void* p_globalinfo_bin, void *proofValues, void *values, uint64_t hintId, char *hintFieldName); // Debug functions // ================================================================================= void print_row(void *pSetupCtx, void *buffer, uint64_t stage, uint64_t row); - void print_expression(void *pSetupCtx, void* pol, uint64_t dim, uint64_t first_value, uint64_t last_value); // Recursive proof // ================================================================================= - void *gen_recursive_proof(void *pSetupCtx, char* globalInfoFile, uint64_t airgroupId, void* pAddress, void *pConstPols, void *pConstTree, void* pPublicInputs, char *proof_file, bool vadcop); + void *gen_recursive_proof(void *pSetupCtx, char* globalInfoFile, uint64_t airgroupId, void* witness, void *pConstPols, void *pConstTree, void* pPublicInputs, char *proof_file, bool vadcop); void *get_zkin_ptr(char *zkin_file); void *add_recursive2_verkey(void *pZkin, char* recursive2VerKeyFilename); void *join_zkin_recursive2(char* globalInfoFile, uint64_t airgroupId, void* pPublics, void* pChallenges, void *zkin1, void *zkin2, void *starkInfoRecursive2); @@ -133,11 +130,11 @@ void *get_zkin_proof(char* zkin); void zkin_proof_free(void *pZkinProof); void serialized_proof_free(char *zkinCStr); - void get_committed_pols(void *pWitness, char* execFile, void *pAddress, void* pPublics, uint64_t sizeWitness, uint64_t N, uint64_t nPublics, uint64_t offsetCm1, uint64_t nCols); + void get_committed_pols(void *circomWitness, char* execFile, void *witness, void* pPublics, uint64_t sizeWitness, uint64_t N, uint64_t nPublics, uint64_t nCols); // Final proof // ================================================================================= - void gen_final_snark_proof(void *pWitnessFinal, char* zkeyFile, char* outputDir); + void gen_final_snark_proof(void *circomWitnessFinal, char* zkeyFile, char* outputDir); // Util calls // ================================================================================= diff --git a/pil2-stark/src/starkpil/exec_file.hpp b/pil2-stark/src/starkpil/exec_file.hpp index bddc1714..f9aeda08 100644 --- a/pil2-stark/src/starkpil/exec_file.hpp +++ b/pil2-stark/src/starkpil/exec_file.hpp @@ -13,8 +13,8 @@ #include "commit_pols_starks.hpp" -void getCommitedPols(Goldilocks::Element *pWitness, std::string execFile, Goldilocks::Element *pAddress, Goldilocks::Element* publics, uint64_t sizeWitness, uint64_t N, uint64_t nPublics, uint64_t offsetCm1, uint64_t nCommitedPols) { - CommitPolsStarks commitPols((uint8_t *)pAddress + offsetCm1 * sizeof(Goldilocks::Element), N, nCommitedPols); +void getCommitedPols(Goldilocks::Element *circomWitness, std::string execFile, Goldilocks::Element *witness, Goldilocks::Element* publics, uint64_t sizeWitness, uint64_t N, uint64_t nPublics, uint64_t nCommitedPols) { + CommitPolsStarks commitPols((uint8_t *)witness, N, nCommitedPols); uint64_t nAdds; uint64_t nSMap; @@ -31,7 +31,7 @@ void getCommitedPols(Goldilocks::Element *pWitness, std::string execFile, Goldil uint64_t *p_sMap = &p_data[2 + nAdds * 4]; for(uint64_t i = 0; i < nPublics; ++i) { - publics[i] = pWitness[1 + i]; + publics[i] = circomWitness[1 + i]; } // #pragma omp parallel for @@ -39,16 +39,16 @@ void getCommitedPols(Goldilocks::Element *pWitness, std::string execFile, Goldil uint64_t idx_1 = p_adds[i * 4]; uint64_t idx_2 = p_adds[i * 4 + 1]; - Goldilocks::Element c = pWitness[idx_1] * Goldilocks::fromU64(p_adds[i * 4 + 2]); - Goldilocks::Element d = pWitness[idx_2] * Goldilocks::fromU64(p_adds[i * 4 + 3]); - pWitness[sizeWitness + i] = c + d; + Goldilocks::Element c = circomWitness[idx_1] * Goldilocks::fromU64(p_adds[i * 4 + 2]); + Goldilocks::Element d = circomWitness[idx_2] * Goldilocks::fromU64(p_adds[i * 4 + 3]); + circomWitness[sizeWitness + i] = c + d; } // #pragma omp parallel for for (uint i = 0; i < N; i++) { for (uint j = 0; j < nCommitedPols; j++) { if (i < nSMap && p_sMap[nCommitedPols * i + j] != 0) { - commitPols.Compressor.a[j][i] = pWitness[p_sMap[nCommitedPols * i + j]]; + commitPols.Compressor.a[j][i] = circomWitness[p_sMap[nCommitedPols * i + j]]; } else { commitPols.Compressor.a[j][i] = Goldilocks::zero(); } diff --git a/pil2-stark/src/starkpil/expressions_avx.hpp b/pil2-stark/src/starkpil/expressions_avx.hpp index aff04d99..0834c013 100644 --- a/pil2-stark/src/starkpil/expressions_avx.hpp +++ b/pil2-stark/src/starkpil/expressions_avx.hpp @@ -125,9 +125,9 @@ class ExpressionsAvx : public ExpressionsCtx { for(uint64_t j = 0; j < nrowsPack; ++j) { uint64_t l = (row + j + nextStrides[o]) % domainSize; if(stage == 1 && !domainExtended) { - bufferT[nrowsPack*o + j] = params.trace[l * nColsStages[stage] + stagePos + d]; + bufferT[nrowsPack*o + j] = params.witness[l * nColsStages[stage] + stagePos + d]; } else { - bufferT[nrowsPack*o + j] = params.pols[offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; + bufferT[nrowsPack*o + j] = params.trace[offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; } } @@ -137,6 +137,7 @@ class ExpressionsAvx : public ExpressionsCtx { } for(uint64_t i = 0; i < setupCtx.starkInfo.customCommits.size(); ++i) { + Goldilocks::Element *customCommits = domainExtended ? params.pCustomCommitsExtended[i] : params.pCustomCommits[i]; for(uint64_t j = 0; j < setupCtx.starkInfo.customCommits[i].stageWidths[0]; ++j) { if(!customCommitsUsed[i][j]) continue; PolMap polInfo = setupCtx.starkInfo.customCommitsMap[i][j]; @@ -146,7 +147,7 @@ class ExpressionsAvx : public ExpressionsCtx { for(uint64_t o = 0; o < nOpenings; ++o) { for(uint64_t j = 0; j < nrowsPack; ++j) { uint64_t l = (row + j + nextStrides[o]) % domainSize; - bufferT[nrowsPack*o + j] = params.customCommits[i][offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; + bufferT[nrowsPack*o + j] = customCommits[offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; } Goldilocks::load_avx(bufferT_[nColsStagesAcc[ns*o + stage] + (stagePos + d)], &bufferT[nrowsPack*o]); } diff --git a/pil2-stark/src/starkpil/expressions_avx512.hpp b/pil2-stark/src/starkpil/expressions_avx512.hpp index 4cd3490e..0340550b 100644 --- a/pil2-stark/src/starkpil/expressions_avx512.hpp +++ b/pil2-stark/src/starkpil/expressions_avx512.hpp @@ -125,9 +125,9 @@ class ExpressionsAvx512 : public ExpressionsCtx { for(uint64_t j = 0; j < nrowsPack; ++j) { uint64_t l = (row + j + nextStrides[o]) % domainSize; if(stage == 1 && !domainExtended) { - bufferT[nrowsPack*o + j] = params.trace[l * nColsStages[stage] + stagePos + d]; + bufferT[nrowsPack*o + j] = params.witness[l * nColsStages[stage] + stagePos + d]; } else { - bufferT[nrowsPack*o + j] = params.pols[offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; + bufferT[nrowsPack*o + j] = params.trace[offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; } } Goldilocks::load_avx512(bufferT_[nColsStagesAcc[ns*o + stage] + (stagePos + d)], &bufferT[nrowsPack*o]); @@ -136,6 +136,7 @@ class ExpressionsAvx512 : public ExpressionsCtx { } for(uint64_t i = 0; i < setupCtx.starkInfo.customCommits.size(); ++i) { + Goldilocks::Element *customCommits = domainExtended ? params.pCustomCommitsExtended[i] : params.pCustomCommits[i]; for(uint64_t j = 0; j < setupCtx.starkInfo.customCommits[i].stageWidths[0]; ++j) { if(!customCommitsUsed[i][j]) continue; PolMap polInfo = setupCtx.starkInfo.customCommitsMap[i][j]; @@ -145,7 +146,7 @@ class ExpressionsAvx512 : public ExpressionsCtx { for(uint64_t o = 0; o < nOpenings; ++o) { for(uint64_t j = 0; j < nrowsPack; ++j) { uint64_t l = (row + j + nextStrides[o]) % domainSize; - bufferT[nrowsPack*o + j] = params.customCommits[i][offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; + bufferT[nrowsPack*o + j] = customCommits[offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; } Goldilocks::load_avx(bufferT_[nColsStagesAcc[ns*o + stage] + (stagePos + d)], &bufferT[nrowsPack*o]); } diff --git a/pil2-stark/src/starkpil/expressions_pack.hpp b/pil2-stark/src/starkpil/expressions_pack.hpp index a50ea0ad..d4a589d8 100644 --- a/pil2-stark/src/starkpil/expressions_pack.hpp +++ b/pil2-stark/src/starkpil/expressions_pack.hpp @@ -120,9 +120,9 @@ class ExpressionsPack : public ExpressionsCtx { for(uint64_t j = 0; j < nrowsPack; ++j) { uint64_t l = (row + j + nextStrides[o]) % domainSize; if(stage == 1 && !domainExtended) { - bufferT_[(nColsStagesAcc[ns*o + stage] + (stagePos + d))*nrowsPack + j] = params.trace[l * nColsStages[stage] + stagePos + d]; + bufferT_[(nColsStagesAcc[ns*o + stage] + (stagePos + d))*nrowsPack + j] = params.witness[l * nColsStages[stage] + stagePos + d]; } else { - bufferT_[(nColsStagesAcc[ns*o + stage] + (stagePos + d))*nrowsPack + j] = params.pols[offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; + bufferT_[(nColsStagesAcc[ns*o + stage] + (stagePos + d))*nrowsPack + j] = params.trace[offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; } } } @@ -130,6 +130,7 @@ class ExpressionsPack : public ExpressionsCtx { } for(uint64_t i = 0; i < setupCtx.starkInfo.customCommits.size(); ++i) { + Goldilocks::Element *customCommits = domainExtended ? params.pCustomCommitsExtended[i] : params.pCustomCommits[i]; for(uint64_t j = 0; j < setupCtx.starkInfo.customCommits[i].stageWidths[0]; ++j) { if(!customCommitsUsed[i][j]) continue; PolMap polInfo = setupCtx.starkInfo.customCommitsMap[i][j]; @@ -139,7 +140,7 @@ class ExpressionsPack : public ExpressionsCtx { for(uint64_t o = 0; o < nOpenings; ++o) { for(uint64_t j = 0; j < nrowsPack; ++j) { uint64_t l = (row + j + nextStrides[o]) % domainSize; - bufferT_[(nColsStagesAcc[ns*o + stage] + (stagePos + d))*nrowsPack + j] = params.customCommits[i][offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; + bufferT_[(nColsStagesAcc[ns*o + stage] + (stagePos + d))*nrowsPack + j] = customCommits[offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; } } } diff --git a/pil2-stark/src/starkpil/final_snark_proof.hpp b/pil2-stark/src/starkpil/final_snark_proof.hpp index afdbe3ce..f8e136ce 100644 --- a/pil2-stark/src/starkpil/final_snark_proof.hpp +++ b/pil2-stark/src/starkpil/final_snark_proof.hpp @@ -4,10 +4,10 @@ #include "utils.hpp" #include "alt_bn128.hpp" -void genFinalSnarkProof(void *pWitnessFinal, std::string zkeyFile, std::string outputDir) { +void genFinalSnarkProof(void *circomWitnessFinal, std::string zkeyFile, std::string outputDir) { TimerStart(PROVER_FINAL_SNARK_PROOF); - AltBn128::FrElement *witnessFinal = (AltBn128::FrElement *)pWitnessFinal; + AltBn128::FrElement *witnessFinal = (AltBn128::FrElement *)circomWitnessFinal; // Save public file json publicJson; AltBn128::FrElement aux; diff --git a/pil2-stark/src/starkpil/gen_recursive_proof.hpp b/pil2-stark/src/starkpil/gen_recursive_proof.hpp index 653c7fcf..9463c11c 100644 --- a/pil2-stark/src/starkpil/gen_recursive_proof.hpp +++ b/pil2-stark/src/starkpil/gen_recursive_proof.hpp @@ -1,7 +1,7 @@ #include "starks.hpp" template -void *genRecursiveProof(SetupCtx& setupCtx, json& globalInfo, uint64_t airgroupId, Goldilocks::Element *pAddress, Goldilocks::Element *pConstPols, Goldilocks::Element *pConstTree, Goldilocks::Element *publicInputs, std::string proofFile, bool vadcop) { +void *genRecursiveProof(SetupCtx& setupCtx, json& globalInfo, uint64_t airgroupId, Goldilocks::Element *witness, Goldilocks::Element *pConstPols, Goldilocks::Element *pConstTree, Goldilocks::Element *publicInputs, std::string proofFile, bool vadcop) { TimerStart(STARK_PROOF); FRIProof proof(setupCtx.starkInfo); @@ -10,7 +10,7 @@ void *genRecursiveProof(SetupCtx& setupCtx, json& globalInfo, uint64_t airgroupI Starks starks(setupCtx, pConstTree); - Goldilocks::Element *pols = new Goldilocks::Element[setupCtx.starkInfo.mapTotalN]; + Goldilocks::Element *trace = new Goldilocks::Element[setupCtx.starkInfo.mapTotalN]; #ifdef __AVX512__ ExpressionsAvx512 expressionsCtx(setupCtx); @@ -29,8 +29,8 @@ void *genRecursiveProof(SetupCtx& setupCtx, json& globalInfo, uint64_t airgroupI vector airgroupValuesCalculated(setupCtx.starkInfo.airgroupValuesMap.size(), false); StepsParams params = { - trace: pAddress, - pols : pols, + witness, + trace, publicInputs : publicInputs, challenges : challenges, airgroupValues : nullptr, @@ -67,7 +67,7 @@ void *genRecursiveProof(SetupCtx& setupCtx, json& globalInfo, uint64_t airgroupI } } TimerStart(STARK_COMMIT_STAGE_1); - starks.commitStage(1, params.trace, params.pols, proof); + starks.commitStage(1, params.witness, params.trace, proof); TimerStopAndLog(STARK_COMMIT_STAGE_1); starks.addTranscript(transcript, &proof.proof.roots[0][0], nFieldElements); @@ -101,7 +101,7 @@ void *genRecursiveProof(SetupCtx& setupCtx, json& globalInfo, uint64_t airgroupI } Polinomial gprodTransposedPol; - setupCtx.starkInfo.getPolynomial(gprodTransposedPol, params.pols, "cm", setupCtx.starkInfo.cmPolsMap[gprodFieldId], false); + setupCtx.starkInfo.getPolynomial(gprodTransposedPol, params.trace, "cm", setupCtx.starkInfo.cmPolsMap[gprodFieldId], false); #pragma omp parallel for for(uint64_t j = 0; j < N; ++j) { std::memcpy(gprodTransposedPol[j], &gprod[j*FIELD_EXTENSION], FIELD_EXTENSION * sizeof(Goldilocks::Element)); @@ -115,7 +115,7 @@ void *genRecursiveProof(SetupCtx& setupCtx, json& globalInfo, uint64_t airgroupI TimerStopAndLog(CALCULATE_IM_POLS); TimerStart(STARK_COMMIT_STAGE_2); - starks.commitStage(2, nullptr, params.pols, proof); + starks.commitStage(2, nullptr, params.trace, proof); TimerStopAndLog(STARK_COMMIT_STAGE_2); starks.addTranscript(transcript, &proof.proof.roots[1][0], nFieldElements); @@ -130,10 +130,10 @@ void *genRecursiveProof(SetupCtx& setupCtx, json& globalInfo, uint64_t airgroupI } } - expressionsCtx.calculateExpression(params, ¶ms.pols[setupCtx.starkInfo.mapOffsets[std::make_pair("q", true)]], setupCtx.starkInfo.cExpId); + expressionsCtx.calculateExpression(params, ¶ms.trace[setupCtx.starkInfo.mapOffsets[std::make_pair("q", true)]], setupCtx.starkInfo.cExpId); TimerStart(STARK_COMMIT_QUOTIENT_POLYNOMIAL); - starks.commitStage(setupCtx.starkInfo.nStages + 1, nullptr, params.pols, proof); + starks.commitStage(setupCtx.starkInfo.nStages + 1, nullptr, params.trace, proof); TimerStopAndLog(STARK_COMMIT_QUOTIENT_POLYNOMIAL); starks.addTranscript(transcript, &proof.proof.roots[setupCtx.starkInfo.nStages][0], nFieldElements); TimerStopAndLog(STARK_STEP_Q); @@ -150,7 +150,7 @@ void *genRecursiveProof(SetupCtx& setupCtx, json& globalInfo, uint64_t airgroupI } Goldilocks::Element *xiChallenge = &challenges[xiChallengeIndex * FIELD_EXTENSION]; - Goldilocks::Element* LEv = ¶ms.pols[setupCtx.starkInfo.mapOffsets[make_pair("LEv", true)]]; + Goldilocks::Element* LEv = ¶ms.trace[setupCtx.starkInfo.mapOffsets[make_pair("LEv", true)]]; starks.computeLEv(xiChallenge, LEv); starks.computeEvals(params ,LEv, proof); @@ -179,13 +179,13 @@ void *genRecursiveProof(SetupCtx& setupCtx, json& globalInfo, uint64_t airgroupI TimerStart(STARK_STEP_FRI); TimerStart(COMPUTE_FRI_POLYNOMIAL); - params.xDivXSub = ¶ms.pols[setupCtx.starkInfo.mapOffsets[std::make_pair("xDivXSubXi", true)]]; + params.xDivXSub = ¶ms.trace[setupCtx.starkInfo.mapOffsets[std::make_pair("xDivXSubXi", true)]]; starks.calculateXDivXSub(xiChallenge, params.xDivXSub); starks.calculateFRIPolynomial(params); TimerStopAndLog(COMPUTE_FRI_POLYNOMIAL); Goldilocks::Element challenge[FIELD_EXTENSION]; - Goldilocks::Element *friPol = ¶ms.pols[setupCtx.starkInfo.mapOffsets[std::make_pair("f", true)]]; + Goldilocks::Element *friPol = ¶ms.trace[setupCtx.starkInfo.mapOffsets[std::make_pair("f", true)]]; TimerStart(STARK_FRI_FOLDING); uint64_t nBitsExt = setupCtx.starkInfo.starkStruct.steps[0].nBits; diff --git a/pil2-stark/src/starkpil/global_constraints.hpp b/pil2-stark/src/starkpil/global_constraints.hpp index 65812dd8..5da82d87 100644 --- a/pil2-stark/src/starkpil/global_constraints.hpp +++ b/pil2-stark/src/starkpil/global_constraints.hpp @@ -1,11 +1,24 @@ #ifndef GLOBAL_CONSTRAINTS_HPP #define GLOBAL_CONSTRAINTS_HPP -#include "timer.hpp" #include "goldilocks_base_field.hpp" #include using json = nlohmann::json; +struct GlobalConstraintInfo { + uint64_t id; + uint64_t dim; + bool valid; + uint64_t value[3]; + uint8_t* line; + uint64_t line_size; +}; + +struct GlobalConstraintsResults { + uint64_t nConstraints; + GlobalConstraintInfo* constraintInfo; +}; + void calculateGlobalExpression(Goldilocks::Element* dest, Goldilocks::Element* publics, Goldilocks::Element* challenges, Goldilocks::Element* proofValues, Goldilocks::Element** airgroupValues, ParserArgs &parserArgs, ParserParams &parserParams) { uint8_t* ops = &parserArgs.ops[parserParams.opsOffset]; @@ -209,55 +222,52 @@ void calculateGlobalExpression(Goldilocks::Element* dest, Goldilocks::Element* p } -bool verifyGlobalConstraint(Goldilocks::Element* publics, Goldilocks::Element* challenges, Goldilocks::Element* proofValues, Goldilocks::Element** airgroupValues, ParserArgs &parserArgs, ParserParams &parserParams) { +GlobalConstraintInfo verifyGlobalConstraint(uint64_t constraintId, Goldilocks::Element* publics, Goldilocks::Element* challenges, Goldilocks::Element* proofValues, Goldilocks::Element** airgroupValues, ParserArgs &parserArgs, ParserParams &parserParams) { + + GlobalConstraintInfo constraintInfo; + constraintInfo.id = constraintId; + constraintInfo.valid = true; + constraintInfo.line = new uint8_t[parserParams.line.size()]; + constraintInfo.line_size = parserParams.line.size(); + std::memcpy(constraintInfo.line, parserParams.line.data(), parserParams.line.size()); Goldilocks::Element dest[parserParams.destDim]; calculateGlobalExpression(dest, publics, challenges, proofValues, airgroupValues, parserArgs, parserParams); - bool isValidConstraint = true; if(parserParams.destDim == 1) { - if(!Goldilocks::isZero(dest[0])) { - cout << "Global constraint check failed with value: " << Goldilocks::toString(dest[0]) << endl; - isValidConstraint = false; - } + constraintInfo.dim = parserParams.destDim; + constraintInfo.value[0] = Goldilocks::toU64(dest[0]); + constraintInfo.value[1] = 0; + constraintInfo.value[2] = 0; + if(constraintInfo.value[0] != 0) constraintInfo.valid = false; } else { - for(uint64_t i = 0; i < FIELD_EXTENSION; ++i) { - if(!Goldilocks::isZero(dest[i])) { - cout << "Global constraint check failed with value: [" << Goldilocks::toString(dest[0]) << ", " << Goldilocks::toString(dest[1]) << ", " << Goldilocks::toString(dest[2]) << "]" << endl; - isValidConstraint = false; - break; - } - } + constraintInfo.dim = parserParams.destDim; + constraintInfo.value[0] = Goldilocks::toU64(dest[0]); + constraintInfo.value[1] = Goldilocks::toU64(dest[1]); + constraintInfo.value[2] = Goldilocks::toU64(dest[2]); + if(constraintInfo.value[0] != 0 || constraintInfo.value[1] != 0 || constraintInfo.value[2] != 0) constraintInfo.valid = false; } - if(isValidConstraint) { - TimerLog(VALID_CONSTRAINT); - return true; - } else { - TimerLog(INVALID_CONSTRAINT); - return false; - } + return constraintInfo; } -bool verifyGlobalConstraints(ExpressionsBin &globalConstraintsBin, Goldilocks::Element* publicInputs, Goldilocks::Element* challenges, Goldilocks::Element* proofValues, Goldilocks::Element** airgroupValues) +GlobalConstraintsResults * verifyGlobalConstraints(ExpressionsBin &globalConstraintsBin, Goldilocks::Element* publicInputs, Goldilocks::Element* challenges, Goldilocks::Element* proofValues, Goldilocks::Element** airgroupValues) { std::vector globalConstraintsInfo = globalConstraintsBin.constraintsInfoDebug; - bool validGlobalConstraints = true; + GlobalConstraintsResults *constraintsInfo = new GlobalConstraintsResults(); + constraintsInfo->nConstraints = globalConstraintsInfo.size(); + constraintsInfo->constraintInfo = new GlobalConstraintInfo[constraintsInfo->nConstraints]; + for(uint64_t i = 0; i < globalConstraintsInfo.size(); ++i) { - TimerLog(CHECKING_CONSTRAINT); - cout << "--------------------------------------------------------" << endl; - cout << globalConstraintsInfo[i].line << endl; - cout << "--------------------------------------------------------" << endl; - if(!verifyGlobalConstraint(publicInputs, challenges, proofValues, airgroupValues, globalConstraintsBin.expressionsBinArgsConstraints, globalConstraintsInfo[i])) { - validGlobalConstraints = false; - }; + auto constraintInfo = verifyGlobalConstraint(i, publicInputs, challenges, proofValues, airgroupValues, globalConstraintsBin.expressionsBinArgsConstraints, globalConstraintsInfo[i]); + constraintsInfo->constraintInfo[i] = constraintInfo; } - return validGlobalConstraints; + return constraintsInfo; } diff --git a/pil2-stark/src/starkpil/hints.hpp b/pil2-stark/src/starkpil/hints.hpp index 78f695d7..9e241a1c 100644 --- a/pil2-stark/src/starkpil/hints.hpp +++ b/pil2-stark/src/starkpil/hints.hpp @@ -16,6 +16,8 @@ struct HintFieldInfo { uint8_t* stringValue; uint64_t matrix_size; uint64_t* pos; + uint8_t* expression_line; + uint64_t expression_line_size; }; struct HintFieldValues { @@ -67,18 +69,6 @@ void setPolynomial(SetupCtx& setupCtx, Goldilocks::Element *buffer, Goldilocks:: } } -void printExpression(Goldilocks::Element* pol, uint64_t dim, uint64_t firstPrintValue = 0, uint64_t lastPrintValue = 0) { - cout << "-------------------------------------------------" << endl; - for(uint64_t i = firstPrintValue; i < lastPrintValue; ++i) { - if(dim == 3) { - cout << "Value at " << i << " is: " << " [" << Goldilocks::toString(pol[i*FIELD_EXTENSION]) << ", " << Goldilocks::toString(pol[i*FIELD_EXTENSION + 1]) << ", " << Goldilocks::toString(pol[i*FIELD_EXTENSION + 2]) << " ]" << endl; - } else { - cout << "Value at " << i << " is: " << Goldilocks::toString(pol[i]) << endl; - } - } - cout << "-------------------------------------------------" << endl; -} - void printRow(SetupCtx& setupCtx, Goldilocks::Element* buffer, uint64_t stage, uint64_t row) { Goldilocks::Element *pol = &buffer[setupCtx.starkInfo.mapOffsets[std::make_pair("cm" + to_string(stage), false)] + setupCtx.starkInfo.mapSectionsN["cm" + to_string(stage)] * row]; cout << "Values at row " << row << " = {" << endl; @@ -112,69 +102,63 @@ void printRow(SetupCtx& setupCtx, Goldilocks::Element* buffer, uint64_t stage, u cout << "}" << endl; } -void printExpressionDebug(SetupCtx& setupCtx, uint64_t hintId, std::string hintFieldName, HintFieldValue hintFieldVal) { - cout << "--------------------------------------------------------" << endl; - cout << "Hint name " << hintFieldName << " for hint id " << hintId << " is "; +std::string getExpressionDebug(SetupCtx& setupCtx, uint64_t hintId, std::string hintFieldName, HintFieldValue hintFieldVal) { + std::string debug = "Hint name " + hintFieldName + " for hint id " + to_string(hintId) + " is "; if(hintFieldVal.operand == opType::cm) { - cout << "witness col " << setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].name; + debug += "witness col " + setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].name; if(setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].lengths.size() > 0) { - cout << "["; + debug += "["; for(uint64_t i = 0; i < setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].lengths.size(); ++i) { - cout << setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].lengths[i]; - if(i != setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].lengths.size() - 1) cout << ", "; + debug += to_string(setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].lengths[i]); + if(i != setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].lengths.size() - 1) debug += ", "; } - cout << "]"; + debug += "]"; } - cout << endl; } else if(hintFieldVal.operand == opType::custom) { - cout << "custom col " << setupCtx.starkInfo.customCommitsMap[hintFieldVal.commitId][hintFieldVal.id].name; + debug += "custom col " + setupCtx.starkInfo.customCommitsMap[hintFieldVal.commitId][hintFieldVal.id].name; if(setupCtx.starkInfo.customCommitsMap[hintFieldVal.commitId][hintFieldVal.id].lengths.size() > 0) { - cout << "["; + debug += "["; for(uint64_t i = 0; i < setupCtx.starkInfo.customCommitsMap[hintFieldVal.commitId][hintFieldVal.id].lengths.size(); ++i) { - cout << setupCtx.starkInfo.customCommitsMap[hintFieldVal.commitId][hintFieldVal.id].lengths[i]; - if(i != setupCtx.starkInfo.customCommitsMap[hintFieldVal.commitId][hintFieldVal.id].lengths.size() - 1) cout << ", "; + debug += to_string(setupCtx.starkInfo.customCommitsMap[hintFieldVal.commitId][hintFieldVal.id].lengths[i]); + if(i != setupCtx.starkInfo.customCommitsMap[hintFieldVal.commitId][hintFieldVal.id].lengths.size() - 1) debug += ", "; } - cout << "]"; + debug += "]"; } - cout << endl; } else if(hintFieldVal.operand == opType::const_) { - cout << "fixed col" << setupCtx.starkInfo.constPolsMap[hintFieldVal.id].name; + debug += "fixed col" + setupCtx.starkInfo.constPolsMap[hintFieldVal.id].name; if(setupCtx.starkInfo.constPolsMap[hintFieldVal.id].lengths.size() > 0) { - cout << "["; + debug += "["; for(uint64_t i = 0; i < setupCtx.starkInfo.constPolsMap[hintFieldVal.id].lengths.size(); ++i) { - cout << setupCtx.starkInfo.constPolsMap[hintFieldVal.id].lengths[i]; - if(i != setupCtx.starkInfo.constPolsMap[hintFieldVal.id].lengths.size() - 1) cout << ", "; + debug += to_string(setupCtx.starkInfo.constPolsMap[hintFieldVal.id].lengths[i]); + if(i != setupCtx.starkInfo.constPolsMap[hintFieldVal.id].lengths.size() - 1) debug += ", "; } - cout << "]"; + debug += "]"; } - cout << endl; } else if (hintFieldVal.operand == opType::tmp) { - cout << "the expression with id: "; + debug += "the expression with id: "; if(setupCtx.expressionsBin.expressionsInfo[hintFieldVal.id].line != "") { - cout << " " << setupCtx.expressionsBin.expressionsInfo[hintFieldVal.id].line << endl; + debug += " " + setupCtx.expressionsBin.expressionsInfo[hintFieldVal.id].line; } - cout << endl; } else if (hintFieldVal.operand == opType::public_) { - cout << "public input " << setupCtx.starkInfo.publicsMap[hintFieldVal.id].name << endl; + debug += "public input " + setupCtx.starkInfo.publicsMap[hintFieldVal.id].name; } else if (hintFieldVal.operand == opType::number) { - cout << "number " << hintFieldVal.value << endl; + debug += "number " + to_string(hintFieldVal.value); } else if (hintFieldVal.operand == opType::airgroupvalue) { - cout << "airgroupValue " << setupCtx.starkInfo.airgroupValuesMap[hintFieldVal.id].name << endl; + debug += "airgroupValue " + setupCtx.starkInfo.airgroupValuesMap[hintFieldVal.id].name; } else if (hintFieldVal.operand == opType::airvalue) { - cout << "airgroupValue " << setupCtx.starkInfo.airValuesMap[hintFieldVal.id].name << endl; + debug += "airValue " + setupCtx.starkInfo.airValuesMap[hintFieldVal.id].name; } else if (hintFieldVal.operand == opType::challenge) { - cout << "challenge " << setupCtx.starkInfo.challengesMap[hintFieldVal.id].name << endl; + debug += "challenge " + setupCtx.starkInfo.challengesMap[hintFieldVal.id].name; } else if (hintFieldVal.operand == opType::string_) { - cout << "string " << hintFieldVal.stringValue << endl; + debug += "string " + hintFieldVal.stringValue; } else { zklog.error("Unknown HintFieldType"); exitProcess(); exit(-1); } - cout << "--------------------------------------------------------" << endl; - + return debug; } HintFieldValues getHintField( @@ -221,7 +205,10 @@ HintFieldValues getHintField( HintFieldInfo hintFieldInfo; if(hintOptions.print_expression) { - printExpressionDebug(setupCtx, hintId, hintFieldName, hintFieldVal); + std::string expression_line = getExpressionDebug(setupCtx, hintId, hintFieldName, hintFieldVal); + hintFieldInfo.expression_line = new uint8_t[expression_line.size()]; + std::memcpy(hintFieldInfo.expression_line, expression_line.data(), expression_line.size()); + hintFieldInfo.expression_line_size = expression_line.size(); } if(hintFieldVal.operand == opType::cm) { uint64_t dim = setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].dim; @@ -230,8 +217,8 @@ HintFieldValues getHintField( hintFieldInfo.fieldType = dim == 1 ? HintFieldType::Column : HintFieldType::ColumnExtended; hintFieldInfo.offset = dim; if(!hintOptions.dest) { - Goldilocks::Element *pols = setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].stage == 1 ? params.trace : params.pols; - getPolynomial(setupCtx, pols, hintFieldInfo.values, setupCtx.starkInfo.cmPolsMap[hintFieldVal.id], hintFieldVal.rowOffsetIndex, "cm"); + Goldilocks::Element *pAddress = setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].stage == 1 ? params.witness : params.trace; + getPolynomial(setupCtx, pAddress, hintFieldInfo.values, setupCtx.starkInfo.cmPolsMap[hintFieldVal.id], hintFieldVal.rowOffsetIndex, "cm"); if(hintOptions.inverse) { zklog.error("Inverse not supported still for polynomials"); exitProcess(); @@ -245,7 +232,7 @@ HintFieldValues getHintField( hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; hintFieldInfo.fieldType = dim == 1 ? HintFieldType::Column : HintFieldType::ColumnExtended; hintFieldInfo.offset = dim; - getPolynomial(setupCtx, params.customCommits[hintFieldVal.commitId], hintFieldInfo.values, setupCtx.starkInfo.customCommitsMap[hintFieldVal.commitId][hintFieldVal.id], hintFieldVal.rowOffsetIndex, "custom"); + getPolynomial(setupCtx, params.pCustomCommits[hintFieldVal.commitId], hintFieldInfo.values, setupCtx.starkInfo.customCommitsMap[hintFieldVal.commitId][hintFieldVal.id], hintFieldVal.rowOffsetIndex, "custom"); if(hintOptions.inverse) { zklog.error("Inverse not supported still for polynomials"); exitProcess(); @@ -377,8 +364,8 @@ uint64_t setHintField(SetupCtx& setupCtx, StepsParams& params, Goldilocks::Eleme auto hintFieldVal = hintField->values[0]; if(hintFieldVal.operand == opType::cm) { - Goldilocks::Element *pols = setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].stage > 1 ? params.pols : params.trace; - setPolynomial(setupCtx, pols, values, hintFieldVal.id); + Goldilocks::Element *pAddress = setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].stage > 1 ? params.trace : params.witness; + setPolynomial(setupCtx, pAddress, values, hintFieldVal.id); } else if(hintFieldVal.operand == opType::airgroupvalue) { if(setupCtx.starkInfo.airgroupValuesMap[hintFieldVal.id].stage > 1) { std::memcpy(¶ms.airgroupValues[FIELD_EXTENSION*hintFieldVal.id], values, FIELD_EXTENSION * sizeof(Goldilocks::Element)); @@ -419,7 +406,8 @@ void opHintFields(SetupCtx& setupCtx, StepsParams& params, Goldilocks::Element* } if(hintFieldOptions[i].print_expression) { - printExpressionDebug(setupCtx, hintId, hintFieldNames[i], hintFieldVal); + std::string expression_line = getExpressionDebug(setupCtx, hintId, hintFieldNames[i], hintFieldVal); + cout << expression_line << endl; } if(hintFieldVal.operand == opType::cm) { destStruct.addCmPol(setupCtx.starkInfo.cmPolsMap[hintFieldVal.id], hintFieldVal.rowOffsetIndex, hintFieldOptions[i].inverse); @@ -464,7 +452,7 @@ uint64_t multiplyHintFields(SetupCtx& setupCtx, StepsParams ¶ms, uint64_t hi HintFieldValue hintFieldDestVal = hintFieldDest->values[0]; uint64_t offset = setupCtx.starkInfo.mapSectionsN["cm" + to_string(setupCtx.starkInfo.cmPolsMap[hintFieldDestVal.id].stage)]; - Goldilocks::Element *buff = ¶ms.pols[setupCtx.starkInfo.mapOffsets[std::make_pair("cm" + to_string(setupCtx.starkInfo.cmPolsMap[hintFieldDestVal.id].stage), false)] + setupCtx.starkInfo.cmPolsMap[hintFieldDestVal.id].stagePos]; + Goldilocks::Element *buff = ¶ms.trace[setupCtx.starkInfo.mapOffsets[std::make_pair("cm" + to_string(setupCtx.starkInfo.cmPolsMap[hintFieldDestVal.id].stage), false)] + setupCtx.starkInfo.cmPolsMap[hintFieldDestVal.id].stagePos]; opHintFields(setupCtx, params, buff, offset, hintId, {hintFieldName1, hintFieldName2}, {hintOptions1, hintOptions2}); diff --git a/pil2-stark/src/starkpil/stark_info.cpp b/pil2-stark/src/starkpil/stark_info.cpp index 9d89c013..c766e3f7 100644 --- a/pil2-stark/src/starkpil/stark_info.cpp +++ b/pil2-stark/src/starkpil/stark_info.cpp @@ -232,8 +232,7 @@ void StarkInfo::setMapOffsets() { // Set offsets for custom commits for(uint64_t i = 0; i < customCommits.size(); ++i) { mapOffsets[std::make_pair(customCommits[i].name + "0", false)] = 0; - mapOffsets[std::make_pair(customCommits[i].name + "0", true)] = N * mapSectionsN[customCommits[i].name + "0"]; - mapTotalNcustomCommits[customCommits[i].name] = (N + NExtended) * mapSectionsN[customCommits[i].name + "0"]; + mapOffsets[std::make_pair(customCommits[i].name + "0", true)] = 0; } mapTotalN = 0; diff --git a/pil2-stark/src/starkpil/stark_info.hpp b/pil2-stark/src/starkpil/stark_info.hpp index 30e4feff..8f294746 100644 --- a/pil2-stark/src/starkpil/stark_info.hpp +++ b/pil2-stark/src/starkpil/stark_info.hpp @@ -154,8 +154,6 @@ class StarkInfo std::map, uint64_t> mapOffsets; uint64_t mapTotalN; - - std::map mapTotalNcustomCommits; /* Constructor */ StarkInfo(string file); diff --git a/pil2-stark/src/starkpil/starks.cpp b/pil2-stark/src/starkpil/starks.cpp index 9ab164e0..4a1687d2 100644 --- a/pil2-stark/src/starkpil/starks.cpp +++ b/pil2-stark/src/starkpil/starks.cpp @@ -4,15 +4,15 @@ #include "exit_process.hpp" template -void Starks::extendAndMerkelizeCustomCommit(uint64_t commitId, uint64_t step, Goldilocks::Element *buffer, FRIProof &proof, Goldilocks::Element *pBuffHelper, string bufferFile) +void Starks::extendAndMerkelizeCustomCommit(uint64_t commitId, uint64_t step, Goldilocks::Element *buffer, Goldilocks::Element *bufferExt, FRIProof &proof, Goldilocks::Element *pBuffHelper, string bufferFile) { uint64_t N = 1 << setupCtx.starkInfo.starkStruct.nBits; uint64_t NExtended = 1 << setupCtx.starkInfo.starkStruct.nBitsExt; std::string section = setupCtx.starkInfo.customCommits[commitId].name + to_string(step); uint64_t nCols = setupCtx.starkInfo.mapSectionsN[section]; - Goldilocks::Element *pBuff = &buffer[setupCtx.starkInfo.mapOffsets[make_pair(section, false)]]; - Goldilocks::Element *pBuffExtended = &buffer[setupCtx.starkInfo.mapOffsets[make_pair(section, true)]]; + Goldilocks::Element *pBuff = buffer; + Goldilocks::Element *pBuffExtended = bufferExt; NTT_Goldilocks ntt(N); if(pBuffHelper != nullptr) { @@ -36,15 +36,15 @@ void Starks::extendAndMerkelizeCustomCommit(uint64_t commitId, uint } template -void Starks::loadCustomCommit(uint64_t commitId, uint64_t step, Goldilocks::Element *buffer, FRIProof &proof, string bufferFile) +void Starks::loadCustomCommit(uint64_t commitId, uint64_t step, Goldilocks::Element *buffer, Goldilocks::Element *bufferExt, FRIProof &proof, string bufferFile) { uint64_t N = 1 << setupCtx.starkInfo.starkStruct.nBits; uint64_t NExtended = 1 << setupCtx.starkInfo.starkStruct.nBitsExt; std::string section = setupCtx.starkInfo.customCommits[commitId].name + to_string(step); uint64_t nCols = setupCtx.starkInfo.mapSectionsN[section]; - Goldilocks::Element *pBuff = &buffer[setupCtx.starkInfo.mapOffsets[make_pair(section, false)]]; - Goldilocks::Element *pBuffExtended = &buffer[setupCtx.starkInfo.mapOffsets[make_pair(section, true)]]; + Goldilocks::Element *pBuff = buffer; + Goldilocks::Element *pBuffExtended = bufferExt; uint64_t pos = setupCtx.starkInfo.nStages + 2 + commitId; @@ -59,7 +59,7 @@ void Starks::loadCustomCommit(uint64_t commitId, uint64_t step, Gol } template -void Starks::extendAndMerkelize(uint64_t step, Goldilocks::Element *trace, Goldilocks::Element *buffer, FRIProof &proof, Goldilocks::Element *pBuffHelper) +void Starks::extendAndMerkelize(uint64_t step, Goldilocks::Element *witness, Goldilocks::Element *buffer, FRIProof &proof, Goldilocks::Element *pBuffHelper) { uint64_t N = 1 << setupCtx.starkInfo.starkStruct.nBits; uint64_t NExtended = 1 << setupCtx.starkInfo.starkStruct.nBitsExt; @@ -67,7 +67,7 @@ void Starks::extendAndMerkelize(uint64_t step, Goldilocks::Element std::string section = "cm" + to_string(step); uint64_t nCols = setupCtx.starkInfo.mapSectionsN["cm" + to_string(step)]; - Goldilocks::Element *pBuff = step == 1 ? trace : &buffer[setupCtx.starkInfo.mapOffsets[make_pair(section, false)]]; + Goldilocks::Element *pBuff = step == 1 ? witness : &buffer[setupCtx.starkInfo.mapOffsets[make_pair(section, false)]]; Goldilocks::Element *pBuffExtended = &buffer[setupCtx.starkInfo.mapOffsets[make_pair(section, true)]]; NTT_Goldilocks ntt(N); @@ -83,16 +83,16 @@ void Starks::extendAndMerkelize(uint64_t step, Goldilocks::Element } template -void Starks::commitStage(uint64_t step, Goldilocks::Element *trace, Goldilocks::Element *buffer, FRIProof &proof, Goldilocks::Element* pBuffHelper) +void Starks::commitStage(uint64_t step, Goldilocks::Element *witness, Goldilocks::Element *trace, FRIProof &proof, Goldilocks::Element* pBuffHelper) { if (step <= setupCtx.starkInfo.nStages) { - extendAndMerkelize(step, trace, buffer, proof, pBuffHelper); + extendAndMerkelize(step, witness, trace, proof, pBuffHelper); } else { - computeQ(step, buffer, proof, pBuffHelper); + computeQ(step, trace, proof, pBuffHelper); } } @@ -244,7 +244,7 @@ void Starks::evmap(StepsParams& params, Goldilocks::Element *LEv) int num_threads = omp_get_max_threads(); int size_thread = size_eval * FIELD_EXTENSION; - Goldilocks::Element *evals_acc = ¶ms.pols[setupCtx.starkInfo.mapOffsets[std::make_pair("evals", true)]]; + Goldilocks::Element *evals_acc = ¶ms.trace[setupCtx.starkInfo.mapOffsets[std::make_pair("evals", true)]]; memset(&evals_acc[0], 0, num_threads * size_thread * sizeof(Goldilocks::Element)); Polinomial *ordPols = new Polinomial[size_eval]; @@ -253,9 +253,9 @@ void Starks::evmap(StepsParams& params, Goldilocks::Element *LEv) { EvMap ev = setupCtx.starkInfo.evMap[i]; string type = ev.type == EvMap::eType::cm ? "cm" : ev.type == EvMap::eType::custom ? "custom" : "fixed"; - Goldilocks::Element *pols = type == "cm" ? params.pols : type == "custom" ? params.customCommits[ev.commitId] : ¶ms.pConstPolsExtendedTreeAddress[2]; + Goldilocks::Element *pAddress = type == "cm" ? params.trace : type == "custom" ? params.pCustomCommitsExtended[ev.commitId] : ¶ms.pConstPolsExtendedTreeAddress[2]; PolMap polInfo = type == "cm" ? setupCtx.starkInfo.cmPolsMap[ev.id] : type == "custom" ? setupCtx.starkInfo.customCommitsMap[ev.commitId][ev.id] : setupCtx.starkInfo.constPolsMap[ev.id]; - setupCtx.starkInfo.getPolynomial(ordPols[i], pols, type, polInfo, true); + setupCtx.starkInfo.getPolynomial(ordPols[i], pAddress, type, polInfo, true); } #pragma omp parallel @@ -341,8 +341,8 @@ void Starks::calculateImPolsExpressions(uint64_t step, StepsParams std::vector dests; for(uint64_t i = 0; i < setupCtx.starkInfo.cmPolsMap.size(); i++) { if(setupCtx.starkInfo.cmPolsMap[i].imPol && setupCtx.starkInfo.cmPolsMap[i].stage == step) { - Goldilocks::Element* pols = setupCtx.starkInfo.cmPolsMap[i].stage == 1 ? params.trace : params.pols; - Dest destStruct(&pols[setupCtx.starkInfo.mapOffsets[std::make_pair("cm" + to_string(step), false)] + setupCtx.starkInfo.cmPolsMap[i].stagePos], setupCtx.starkInfo.mapSectionsN["cm" + to_string(step)]); + Goldilocks::Element* pAddress = setupCtx.starkInfo.cmPolsMap[i].stage == 1 ? params.witness : params.trace; + Dest destStruct(&pAddress[setupCtx.starkInfo.mapOffsets[std::make_pair("cm" + to_string(step), false)] + setupCtx.starkInfo.cmPolsMap[i].stagePos], setupCtx.starkInfo.mapSectionsN["cm" + to_string(step)]); destStruct.addParams(setupCtx.expressionsBin.expressionsInfo[setupCtx.starkInfo.cmPolsMap[i].expId], false); dests.push_back(destStruct); @@ -371,7 +371,7 @@ void Starks::calculateQuotientPolynomial(StepsParams ¶ms) { #else ExpressionsPack expressionsCtx(setupCtx); #endif - expressionsCtx.calculateExpression(params, ¶ms.pols[setupCtx.starkInfo.mapOffsets[std::make_pair("q", true)]], setupCtx.starkInfo.cExpId); + expressionsCtx.calculateExpression(params, ¶ms.trace[setupCtx.starkInfo.mapOffsets[std::make_pair("q", true)]], setupCtx.starkInfo.cExpId); } template @@ -383,5 +383,5 @@ void Starks::calculateFRIPolynomial(StepsParams ¶ms) { #else ExpressionsPack expressionsCtx(setupCtx); #endif - expressionsCtx.calculateExpression(params, ¶ms.pols[setupCtx.starkInfo.mapOffsets[std::make_pair("f", true)]], setupCtx.starkInfo.friExpId); + expressionsCtx.calculateExpression(params, ¶ms.trace[setupCtx.starkInfo.mapOffsets[std::make_pair("f", true)]], setupCtx.starkInfo.friExpId); } \ No newline at end of file diff --git a/pil2-stark/src/starkpil/starks.hpp b/pil2-stark/src/starkpil/starks.hpp index 4bd8ea0a..ef4a8232 100644 --- a/pil2-stark/src/starkpil/starks.hpp +++ b/pil2-stark/src/starkpil/starks.hpp @@ -73,11 +73,11 @@ class Starks delete[] treesFRI; }; - void extendAndMerkelizeCustomCommit(uint64_t commitId, uint64_t step, Goldilocks::Element *buffer, FRIProof &proof, Goldilocks::Element *pBuffHelper, string bufferFile); - void loadCustomCommit(uint64_t commitId, uint64_t step, Goldilocks::Element *buffer, FRIProof &proof, string bufferFile); - void extendAndMerkelize(uint64_t step, Goldilocks::Element *trace, Goldilocks::Element *buffer, FRIProof &proof, Goldilocks::Element* pBuffHelper = nullptr); + void extendAndMerkelizeCustomCommit(uint64_t commitId, uint64_t step, Goldilocks::Element *buffer, Goldilocks::Element *bufferExt, FRIProof &proof, Goldilocks::Element *pBuffHelper, string bufferFile); + void loadCustomCommit(uint64_t commitId, uint64_t step, Goldilocks::Element *buffer, Goldilocks::Element *bufferExt, FRIProof &proof, string bufferFile); + void extendAndMerkelize(uint64_t step, Goldilocks::Element *witness, Goldilocks::Element *buffer, FRIProof &proof, Goldilocks::Element* pBuffHelper = nullptr); - void commitStage(uint64_t step, Goldilocks::Element *trace, Goldilocks::Element *buffer, FRIProof &proof, Goldilocks::Element* pBuffHelper = nullptr); + void commitStage(uint64_t step, Goldilocks::Element *witness, Goldilocks::Element *buffer, FRIProof &proof, Goldilocks::Element* pBuffHelper = nullptr); void computeQ(uint64_t step, Goldilocks::Element *buffer, FRIProof &proof, Goldilocks::Element* pBuffHelper = nullptr); void calculateImPolsExpressions(uint64_t step, StepsParams& params); diff --git a/pil2-stark/src/starkpil/steps.hpp b/pil2-stark/src/starkpil/steps.hpp index 4d0e3d06..9211e5f3 100644 --- a/pil2-stark/src/starkpil/steps.hpp +++ b/pil2-stark/src/starkpil/steps.hpp @@ -5,8 +5,8 @@ struct StepsParams { + Goldilocks::Element *witness; Goldilocks::Element *trace; - Goldilocks::Element *pols; Goldilocks::Element *publicInputs; Goldilocks::Element *challenges; Goldilocks::Element *airgroupValues; @@ -15,7 +15,8 @@ struct StepsParams Goldilocks::Element *xDivXSub; Goldilocks::Element *pConstPolsAddress; Goldilocks::Element *pConstPolsExtendedTreeAddress; - Goldilocks::Element *customCommits[10]; + Goldilocks::Element *pCustomCommits[10]; + Goldilocks::Element *pCustomCommitsExtended[10]; }; #endif \ No newline at end of file diff --git a/pil2-stark/src/starkpil/verify_constraints.hpp b/pil2-stark/src/starkpil/verify_constraints.hpp index 78a6e84e..efa631c1 100644 --- a/pil2-stark/src/starkpil/verify_constraints.hpp +++ b/pil2-stark/src/starkpil/verify_constraints.hpp @@ -10,7 +10,8 @@ struct ConstraintInfo { uint64_t id; uint64_t stage; bool imPol; - const char* line; + uint8_t* line; + uint64_t line_size; uint64_t nrows; ConstraintRowInfo rows[10]; }; @@ -56,7 +57,9 @@ ConstraintInfo verifyConstraint(SetupCtx& setupCtx, Goldilocks::Element* dest, u constraintInfo.id = constraintId; constraintInfo.stage = setupCtx.expressionsBin.constraintsInfoDebug[constraintId].stage; constraintInfo.imPol = setupCtx.expressionsBin.constraintsInfoDebug[constraintId].imPol; - constraintInfo.line = setupCtx.expressionsBin.constraintsInfoDebug[constraintId].line.c_str(); + constraintInfo.line = new uint8_t[setupCtx.expressionsBin.constraintsInfoDebug[constraintId].line.size()]; + constraintInfo.line_size = setupCtx.expressionsBin.constraintsInfoDebug[constraintId].line.size(); + std::memcpy(constraintInfo.line, setupCtx.expressionsBin.constraintsInfoDebug[constraintId].line.data(), setupCtx.expressionsBin.constraintsInfoDebug[constraintId].line.size()); constraintInfo.nrows = 0; uint64_t N = (1 << setupCtx.starkInfo.starkStruct.nBits); diff --git a/proofman/src/constraints.rs b/proofman/src/constraints.rs index e346670b..3766632d 100644 --- a/proofman/src/constraints.rs +++ b/proofman/src/constraints.rs @@ -1,5 +1,5 @@ use p3_field::Field; -use std::{cmp, ffi::CStr}; +use std::cmp; use std::sync::Arc; @@ -41,7 +41,8 @@ pub fn verify_constraints_proof( air_name, ); for constraint in &constraints[air_instance_index] { - let line_str = unsafe { CStr::from_ptr(constraint.line) }; + let str_slice = unsafe { std::slice::from_raw_parts(constraint.line, constraint.line_size as usize) }; + let line_str = std::str::from_utf8(str_slice).unwrap(); let valid = if constraint.n_rows > 0 { format!("has {} invalid rows", constraint.n_rows).bright_red() } else { @@ -49,29 +50,29 @@ pub fn verify_constraints_proof( }; if constraint.im_pol { log::trace!( - "{}: ··· Intermediate polynomial (stage {}) {} -> {:?}", + "{}: ··· Intermediate polynomial (stage {}) {} -> {}", MY_NAME, constraint.stage, valid, - line_str.to_str().unwrap() + line_str ); } else if constraint.n_rows == 0 { log::debug!( - "{}: · Constraint #{} (stage {}) {} -> {:?}", + "{}: · Constraint #{} (stage {}) {} -> {}", MY_NAME, constraint.id, constraint.stage, valid, - line_str.to_str().unwrap() + line_str ); } else { log::info!( - "{}: · Constraint #{} (stage {}) {} -> {:?}", + "{}: · Constraint #{} (stage {}) {} -> {}", MY_NAME, constraint.id, constraint.stage, valid, - line_str.to_str().unwrap() + line_str ); } if constraint.n_rows > 0 { @@ -123,11 +124,45 @@ pub fn verify_constraints_proof( } } - log::info!("{}: <-- Checking constraints", MY_NAME); + let global_constraints = verify_global_constraints_proof(pctx.clone(), sctx.clone()); + let mut valid_global_constraints = true; + for constraint in &global_constraints { + let str_slice = unsafe { std::slice::from_raw_parts(constraint.line, constraint.line_size as usize) }; + let line_str = std::str::from_utf8(str_slice).unwrap(); - let global_constraints_verified = verify_global_constraints_proof(pctx.clone(), sctx.clone()); + let valid = if !constraint.valid { "is invalid".bright_red() } else { "is valid".bright_green() }; + if constraint.valid { + log::debug!("{}: · Global Constraint #{} {} -> {}", MY_NAME, constraint.id, valid, line_str); + } else { + log::info!("{}: · Global Constraint #{} {} -> {}", MY_NAME, constraint.id, valid, line_str); + } + if !constraint.valid { + valid_global_constraints = false; + if constraint.dim == 1 { + log::info!("{}: ··· \u{2717} Failed with value: {}", MY_NAME, constraint.value[0]); + } else { + log::info!( + "{}: ··· \u{2717} Failed with value: [{}, {}, {}]", + MY_NAME, + constraint.value[0], + constraint.value[1], + constraint.value[2] + ); + } + } + } + + if valid_global_constraints { + log::info!( + "{}: ··· {}", + MY_NAME, + "\u{2713} All global constraints were successfully verified".bright_green().bold() + ); + } else { + log::info!("{}: ··· {}", MY_NAME, "\u{2717} Not all global constraints were verified".bright_red().bold()); + } - if valid_constraints && global_constraints_verified { + if valid_constraints && valid_global_constraints { log::info!("{}: ··· {}", MY_NAME, "\u{2713} All constraints were verified".bright_green().bold()); Ok(()) } else { diff --git a/proofman/src/global_constraints.rs b/proofman/src/global_constraints.rs index 97f7d918..4b6c3053 100644 --- a/proofman/src/global_constraints.rs +++ b/proofman/src/global_constraints.rs @@ -6,9 +6,7 @@ use proofman_starks_lib_c::{ use std::{collections::HashMap, sync::Arc}; -use proofman_common::{ExtensionField, ProofCtx, SetupCtx}; - -use colored::*; +use proofman_common::{GlobalConstraintInfo, GlobalConstraintsResults, ExtensionField, ProofCtx, SetupCtx}; use std::os::raw::c_void; @@ -58,7 +56,10 @@ pub fn aggregate_airgroupvals(pctx: Arc>) -> Vec> { airgroupvalues } -pub fn verify_global_constraints_proof(pctx: Arc>, sctx: Arc) -> bool { +pub fn verify_global_constraints_proof( + pctx: Arc>, + sctx: Arc, +) -> Vec { const MY_NAME: &str = "GlCstVfy"; log::info!("{}: --> Checking global constraints", MY_NAME); @@ -79,7 +80,7 @@ pub fn verify_global_constraints_proof(pctx: Arc>, sctx: A .map(|inner_vec| inner_vec.as_mut_ptr()) // Get a raw pointer to each inner Vec .collect(); - let global_constraints_verified = verify_global_constraints_c( + let raw_ptr = verify_global_constraints_c( sctx.get_global_bin(), public_inputs, challenges, @@ -87,19 +88,11 @@ pub fn verify_global_constraints_proof(pctx: Arc>, sctx: A airgroup_values_ptrs.as_mut_ptr() as *mut *mut c_void, ); - log::info!("{}: <-- Checking global constraints", MY_NAME); - - if global_constraints_verified { - log::info!( - "{}: ··· {}", - MY_NAME, - "\u{2713} All global constraints were successfully verified".bright_green().bold() - ); - } else { - log::info!("{}: ··· {}", MY_NAME, "\u{2717} Not all global constraints were verified".bright_red().bold()); + unsafe { + let constraints_result = Box::from_raw(raw_ptr as *mut GlobalConstraintsResults); + std::slice::from_raw_parts(constraints_result.constraints_info, constraints_result.n_constraints as usize) } - - global_constraints_verified + .to_vec() } pub fn get_hint_field_gc( diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index 1de1aa8a..7aa0ba73 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -1,12 +1,11 @@ use libloading::{Library, Symbol}; use log::{info, trace}; use p3_field::Field; -use stark::{StarkBufferAllocator, StarkProver}; +use stark::StarkProver; use proofman_starks_lib_c::{save_challenges_c, save_proof_values_c, save_publics_c}; use core::panic; use std::fs; use std::error::Error; -use std::mem::MaybeUninit; use colored::*; @@ -25,7 +24,9 @@ use proofman_common::{ExecutionCtx, ProofCtx, ProofOptions, ProofType, Prover, S use std::os::raw::c_void; -use proofman_util::{timer_start_debug, timer_start_info, timer_stop_and_log_debug, timer_stop_and_log_info}; +use proofman_util::{ + create_buffer_fast, timer_start_debug, timer_start_info, timer_stop_and_log_debug, timer_stop_and_log_info, +}; pub struct ProofMan { _phantom: std::marker::PhantomData, @@ -56,11 +57,9 @@ impl ProofMan { &output_dir_path, options.verify_constraints, )?; - let buffer_allocator: Arc = Arc::new(StarkBufferAllocator::new(proving_key_path.clone())); let ectx = ExecutionCtx::builder() .with_rom_path(rom_path.clone()) .with_cached_buffers_path(cached_buffers_paths.clone()) - .with_buffer_allocator(buffer_allocator) .with_verbose_mode(options.verbose_mode) .with_std_mode(options.std_mode) .build(); @@ -330,7 +329,7 @@ impl ProofMan { } } - let buff_helper: Vec> = Vec::with_capacity(buff_helper_size); + let buff_helper: Vec = create_buffer_fast(buff_helper_size); *pctx.buff_helper.buff_helper.write().unwrap() = buff_helper; timer_stop_and_log_debug!(INITIALIZE_PROVERS); diff --git a/proofman/src/recursion.rs b/proofman/src/recursion.rs index a4b59cfe..a823109e 100644 --- a/proofman/src/recursion.rs +++ b/proofman/src/recursion.rs @@ -4,7 +4,6 @@ use std::ffi::CString; use std::fs::File; use std::sync::Arc; use proofman_starks_lib_c::*; -use std::mem::MaybeUninit; use std::path::{Path, PathBuf}; use std::io::Read; @@ -12,14 +11,14 @@ use proofman_common::{ExecutionCtx, ProofCtx, ProofType, Setup, SetupCtx, Setups use std::os::raw::{c_void, c_char}; -use proofman_util::{timer_start_trace, timer_stop_and_log_trace}; +use proofman_util::{create_buffer_fast, timer_start_trace, timer_stop_and_log_trace}; type GetWitnessFunc = unsafe extern "C" fn(zkin: *mut c_void, dat_file: *const c_char, witness: *mut c_void, n_mutexes: u64); type GetSizeWitnessFunc = unsafe extern "C" fn() -> u64; -type GenWitnessResult = Result<(Vec>, Vec>), Box>; +type GenWitnessResult = Result<(Vec, Vec), Box>; pub fn generate_vadcop_recursive1_proof( pctx: &ProofCtx, @@ -469,7 +468,7 @@ pub fn generate_fflonk_snark_proof( let get_size_witness: Symbol = library.get(b"getSizeWitness\0")?; let size_witness = get_size_witness(); - let witness: Vec> = Vec::with_capacity((size_witness * 32) as usize); + let witness: Vec = create_buffer_fast((size_witness * 32) as usize); let witness_ptr = witness.as_ptr() as *mut c_void; let get_witness: Symbol = library.get(b"getWitness\0")?; @@ -502,17 +501,13 @@ fn generate_witness( // Load the symbol (function) from the library timer_start_trace!(CALCULATE_WITNESS); - let p_stark_info = setup.p_setup.p_stark_info; - let n = 1 << (setup.stark_info.stark_struct.n_bits); - let buffer: Vec> = Vec::with_capacity(n_cols * n); + let buffer: Vec = create_buffer_fast(n_cols * n); let p_address = buffer.as_ptr() as *mut c_void; - let offset_cm1 = get_map_offsets_c(p_stark_info, "cm1", false); - let n_publics = setup.stark_info.n_publics as usize; - let publics: Vec> = Vec::with_capacity(n_publics); + let publics: Vec = create_buffer_fast(n_publics); let p_publics = publics.as_ptr() as *mut c_void; let rust_lib_filename = setup_path.display().to_string() + ".so"; @@ -542,7 +537,7 @@ fn generate_witness( file.read_exact(&mut n_adds)?; let n_adds = u64::from_le_bytes(n_adds); - let witness: Vec> = Vec::with_capacity((size_witness + n_adds) as usize); + let witness: Vec = create_buffer_fast((size_witness + n_adds) as usize); let witness_ptr = witness.as_ptr() as *mut c_void; let get_witness: Symbol = library.get(b"getWitness\0")?; @@ -559,7 +554,6 @@ fn generate_witness( size_witness, n as u64, n_publics as u64, - offset_cm1, n_cols as u64, ); } diff --git a/provers/stark/src/stark_prover.rs b/provers/stark/src/stark_prover.rs index b5fd9b78..a33d8147 100644 --- a/provers/stark/src/stark_prover.rs +++ b/provers/stark/src/stark_prover.rs @@ -1,19 +1,17 @@ use core::panic; -use std::error::Error; use std::fs::File; use std::io::Read; -use std::path::PathBuf; use std::any::type_name; use std::sync::Arc; use proofman_common::{ - BufferAllocator, ConstraintInfo, ConstraintsResults, ProofCtx, ProofType, Prover, ProverInfo, ProverStatus, - StepsParams, SetupCtx, StarkInfo, + ConstraintInfo, ConstraintsResults, ProofCtx, ProofType, Prover, ProverInfo, ProverStatus, StepsParams, SetupCtx, + StarkInfo, }; use log::{debug, trace}; use transcript::FFITranscript; -use proofman_util::{timer_start_trace, timer_stop_and_log_trace}; +use proofman_util::{create_buffer_fast, timer_start_trace, timer_stop_and_log_trace}; use proofman_starks_lib_c::*; use p3_goldilocks::Goldilocks; use p3_field::AbstractField; @@ -94,8 +92,8 @@ impl Prover for StarkProver { fn build(&mut self, proof_ctx: Arc>) { let air_instance = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap()[self.prover_idx]; - let buffer = Vec::with_capacity(get_map_totaln_c(self.p_stark_info) as usize); - air_instance.set_buffer(buffer); + let trace = create_buffer_fast(get_map_totaln_c(self.p_stark_info) as usize); + air_instance.set_trace(trace); //initialize the common challenges if have not been initialized by another prover let challenges = @@ -136,11 +134,10 @@ impl Prover for StarkProver { let challenges_guard = proof_ctx.challenges.challenges.read().unwrap(); let const_pols_ptr = (*setup.const_pols.values.read().unwrap()).as_ptr() as *mut c_void; - let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; let steps_params = StepsParams { + witness: air_instance.get_witness_ptr() as *mut c_void, trace: air_instance.get_trace_ptr() as *mut c_void, - pols: air_instance.get_buffer_ptr() as *mut c_void, public_inputs: (*public_inputs_guard).as_ptr() as *mut c_void, challenges: (*challenges_guard).as_ptr() as *mut c_void, airgroup_values: air_instance.airgroup_values.as_ptr() as *mut c_void, @@ -148,8 +145,9 @@ impl Prover for StarkProver { evals: air_instance.evals.as_ptr() as *mut c_void, xdivxsub: std::ptr::null_mut(), p_const_pols: const_pols_ptr, - p_const_tree: const_tree_ptr, + p_const_tree: std::ptr::null_mut(), custom_commits: air_instance.get_custom_commits_ptr(), + custom_commits_extended: [std::ptr::null_mut(); 10], }; let raw_ptr = verify_constraints_c((&setup.p_setup).into(), (&steps_params).into()); @@ -175,8 +173,8 @@ impl Prover for StarkProver { let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; let steps_params = StepsParams { + witness: air_instance.get_witness_ptr() as *mut c_void, trace: air_instance.get_trace_ptr() as *mut c_void, - pols: air_instance.get_buffer_ptr() as *mut c_void, public_inputs: (*public_inputs_guard).as_ptr() as *mut c_void, challenges: (*challenges_guard).as_ptr() as *mut c_void, airgroup_values: air_instance.airgroup_values.as_ptr() as *mut c_void, @@ -186,6 +184,7 @@ impl Prover for StarkProver { p_const_pols: const_pols_ptr, p_const_tree: const_tree_ptr, custom_commits: air_instance.get_custom_commits_ptr(), + custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; if stage_id as usize <= proof_ctx.global_info.n_challenges.len() { @@ -312,15 +311,16 @@ impl Prover for StarkProver { timer_start_trace!(STARK_COMMIT_STAGE_, stage_id); - let trace = match stage_id == 1 { - true => air_instance.get_trace_ptr() as *mut c_void, + let witness = match stage_id == 1 { + true => air_instance.get_witness_ptr() as *mut c_void, false => std::ptr::null_mut(), }; - let buffer = air_instance.get_buffer_ptr() as *mut c_void; + let trace = air_instance.get_trace_ptr() as *mut c_void; let element_type = if type_name::() == type_name::() { 1 } else { 0 }; - commit_stage_c(p_stark, element_type, stage_id as u64, trace, buffer, p_proof, buff_helper); + commit_stage_c(p_stark, element_type, stage_id as u64, witness, trace, p_proof, buff_helper); + timer_stop_and_log_trace!(STARK_COMMIT_STAGE_, stage_id); } else { let n_custom_commits = self.stark_info.custom_commits.len(); @@ -338,6 +338,7 @@ impl Prover for StarkProver { commit_id as u64, stage_id as u64, air_instance.custom_commits[commit_id].buffer.as_ptr() as *mut c_void, + air_instance.custom_commits_extended[commit_id].buffer.as_ptr() as *mut c_void, p_proof, buff_helper, "", @@ -348,6 +349,7 @@ impl Prover for StarkProver { commit_id as u64, stage_id as u64, air_instance.custom_commits[commit_id].buffer.as_ptr() as *mut c_void, + air_instance.custom_commits_extended[commit_id].buffer.as_ptr() as *mut c_void, p_proof, air_instance.custom_commits[commit_id].cached_file.to_str().unwrap(), ); @@ -549,7 +551,6 @@ impl Prover for StarkProver { let mut root = vec![F::zero(); self.n_field_elements]; treesGL_get_root_c(p_stark, stage - 1, root.as_mut_ptr() as *mut c_void); - trace!( "{}: ··· MerkleTree root for stage {} of instance {} of {} is: {:?}", Self::MY_NAME, @@ -611,7 +612,7 @@ impl Prover for StarkProver { fri_proof_get_tree_root_c(p_proof, value.as_mut_ptr() as *mut c_void, step_index as u64); } else { let air_instance = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap()[self.prover_idx]; - let buffer = air_instance.get_buffer_ptr() as *mut c_void; + let buffer = air_instance.get_trace_ptr() as *mut c_void; let n_hash = (1 << (steps[n_steps].n_bits)) * Self::FIELD_EXTENSION as u64; let fri_pol = get_fri_pol_c(self.p_stark_info, buffer); @@ -743,8 +744,8 @@ impl StarkProver { let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; let steps_params = StepsParams { - trace: std::ptr::null_mut(), - pols: air_instance.get_buffer_ptr() as *mut c_void, + witness: std::ptr::null_mut(), + trace: air_instance.get_trace_ptr() as *mut c_void, public_inputs: std::ptr::null_mut(), challenges: std::ptr::null_mut(), airgroup_values: std::ptr::null_mut(), @@ -754,6 +755,7 @@ impl StarkProver { p_const_pols: std::ptr::null_mut(), p_const_tree: const_tree_ptr, custom_commits: air_instance.get_custom_commits_ptr(), + custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; compute_evals_c(p_stark, (&steps_params).into(), buff_helper, p_proof); @@ -776,8 +778,8 @@ impl StarkProver { let p_stark = self.p_stark; let steps_params = StepsParams { - trace: std::ptr::null_mut(), - pols: air_instance.get_buffer_ptr() as *mut c_void, + witness: std::ptr::null_mut(), + trace: air_instance.get_trace_ptr() as *mut c_void, public_inputs: (*public_inputs_guard).as_ptr() as *mut c_void, challenges: (*challenges_guard).as_ptr() as *mut c_void, airgroup_values: air_instance.airgroup_values.as_ptr() as *mut c_void, @@ -787,6 +789,7 @@ impl StarkProver { p_const_pols: const_pols_ptr, p_const_tree: const_tree_ptr, custom_commits: air_instance.get_custom_commits_ptr(), + custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; calculate_fri_polynomial_c(p_stark, (&steps_params).into()); @@ -811,7 +814,7 @@ impl StarkProver { } let air_instance = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap()[self.prover_idx]; - let buffer = air_instance.get_buffer_ptr() as *mut c_void; + let buffer = air_instance.get_trace_ptr() as *mut c_void; let fri_pol = get_fri_pol_c(self.p_stark_info, buffer); @@ -871,7 +874,7 @@ impl StarkProver { ); let air_instance = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap()[self.prover_idx]; - let buffer = air_instance.get_buffer_ptr() as *mut c_void; + let buffer = air_instance.get_trace_ptr() as *mut c_void; let fri_pol = get_fri_pol_c(self.p_stark_info, buffer); @@ -895,34 +898,3 @@ impl StarkProver { ); } } - -pub struct StarkBufferAllocator { - pub proving_key_path: PathBuf, -} - -impl StarkBufferAllocator { - pub fn new(proving_key_path: PathBuf) -> Self { - Self { proving_key_path } - } -} - -impl BufferAllocator for StarkBufferAllocator { - fn get_buffer_info_custom_commit( - &self, - sctx: &SetupCtx, - airgroup_id: usize, - air_id: usize, - name: &str, - ) -> Result<(u64, Vec, u64), Box> { - let ps = sctx.get_setup(airgroup_id, air_id); - - let commit_id = match ps.stark_info.custom_commits.iter().position(|custom_commit| custom_commit.name == name) { - Some(commit_id) => commit_id as u64, - None => { - eprintln!("Custom commit '{}' not found in custom commits.", name); - std::process::exit(1); - } - }; - Ok((get_map_totaln_custom_commits_c(ps.p_setup.p_stark_info, commit_id), vec![0], commit_id)) - } -} diff --git a/provers/starks-lib-c/bindings_starks.rs b/provers/starks-lib-c/bindings_starks.rs index 9b9aac11..16e203e9 100644 --- a/provers/starks-lib-c/bindings_starks.rs +++ b/provers/starks-lib-c/bindings_starks.rs @@ -43,10 +43,7 @@ extern "C" { } extern "C" { #[link_name = "\u{1}_Z23fri_proof_set_airvaluesPvS_"] - pub fn fri_proof_set_airvalues( - pFriProof: *mut ::std::os::raw::c_void, - airValues: *mut ::std::os::raw::c_void, - ); + pub fn fri_proof_set_airvalues(pFriProof: *mut ::std::os::raw::c_void, airValues: *mut ::std::os::raw::c_void); } extern "C" { #[link_name = "\u{1}_Z23fri_proof_get_zkinproofmPvS_S_S_PcS0_"] @@ -83,21 +80,6 @@ extern "C" { #[link_name = "\u{1}_Z15get_map_total_nPv"] pub fn get_map_total_n(pStarkInfo: *mut ::std::os::raw::c_void) -> u64; } -extern "C" { - #[link_name = "\u{1}_Z30get_map_total_n_custom_commitsPvm"] - pub fn get_map_total_n_custom_commits( - pStarkInfo: *mut ::std::os::raw::c_void, - commit_id: u64, - ) -> u64; -} -extern "C" { - #[link_name = "\u{1}_Z15get_map_offsetsPvPcb"] - pub fn get_map_offsets( - pStarkInfo: *mut ::std::os::raw::c_void, - stage: *mut ::std::os::raw::c_char, - flag: bool, - ) -> u64; -} extern "C" { #[link_name = "\u{1}_Z25get_custom_commit_map_idsPvmm"] pub fn get_custom_commit_map_ids( @@ -112,9 +94,7 @@ extern "C" { } extern "C" { #[link_name = "\u{1}_Z18prover_helpers_newPv"] - pub fn prover_helpers_new( - pStarkInfo: *mut ::std::os::raw::c_void, - ) -> *mut ::std::os::raw::c_void; + pub fn prover_helpers_new(pStarkInfo: *mut ::std::os::raw::c_void) -> *mut ::std::os::raw::c_void; } extern "C" { #[link_name = "\u{1}_Z19prover_helpers_freePv"] @@ -155,10 +135,7 @@ extern "C" { } extern "C" { #[link_name = "\u{1}_Z19expressions_bin_newPcb"] - pub fn expressions_bin_new( - filename: *mut ::std::os::raw::c_char, - global: bool, - ) -> *mut ::std::os::raw::c_void; + pub fn expressions_bin_new(filename: *mut ::std::os::raw::c_char, global: bool) -> *mut ::std::os::raw::c_void; } extern "C" { #[link_name = "\u{1}_Z20expressions_bin_freePv"] @@ -237,19 +214,11 @@ extern "C" { } extern "C" { #[link_name = "\u{1}_Z16treesGL_get_rootPvmS_"] - pub fn treesGL_get_root( - pStarks: *mut ::std::os::raw::c_void, - index: u64, - root: *mut ::std::os::raw::c_void, - ); + pub fn treesGL_get_root(pStarks: *mut ::std::os::raw::c_void, index: u64, root: *mut ::std::os::raw::c_void); } extern "C" { #[link_name = "\u{1}_Z16treesGL_set_rootPvmS_"] - pub fn treesGL_set_root( - pStarks: *mut ::std::os::raw::c_void, - index: u64, - pProof: *mut ::std::os::raw::c_void, - ); + pub fn treesGL_set_root(pStarks: *mut ::std::os::raw::c_void, index: u64, pProof: *mut ::std::os::raw::c_void); } extern "C" { #[link_name = "\u{1}_Z18calculate_xdivxsubPvS_S_"] @@ -268,10 +237,7 @@ extern "C" { } extern "C" { #[link_name = "\u{1}_Z24calculate_fri_polynomialPvS_"] - pub fn calculate_fri_polynomial( - pStarks: *mut ::std::os::raw::c_void, - stepsParams: *mut ::std::os::raw::c_void, - ); + pub fn calculate_fri_polynomial(pStarks: *mut ::std::os::raw::c_void, stepsParams: *mut ::std::os::raw::c_void); } extern "C" { #[link_name = "\u{1}_Z29calculate_quotient_polynomialPvS_"] @@ -289,24 +255,26 @@ extern "C" { ); } extern "C" { - #[link_name = "\u{1}_Z34extend_and_merkelize_custom_commitPvmmS_S_S_Pc"] + #[link_name = "\u{1}_Z34extend_and_merkelize_custom_commitPvmmS_S_S_S_Pc"] pub fn extend_and_merkelize_custom_commit( pStarks: *mut ::std::os::raw::c_void, commitId: u64, step: u64, buffer: *mut ::std::os::raw::c_void, + bufferExt: *mut ::std::os::raw::c_void, pProof: *mut ::std::os::raw::c_void, pBuffHelper: *mut ::std::os::raw::c_void, treeFile: *mut ::std::os::raw::c_char, ); } extern "C" { - #[link_name = "\u{1}_Z18load_custom_commitPvmmS_S_Pc"] + #[link_name = "\u{1}_Z18load_custom_commitPvmmS_S_S_Pc"] pub fn load_custom_commit( pStarks: *mut ::std::os::raw::c_void, commitId: u64, step: u64, buffer: *mut ::std::os::raw::c_void, + bufferExt: *mut ::std::os::raw::c_void, pProof: *mut ::std::os::raw::c_void, treeFile: *mut ::std::os::raw::c_char, ); @@ -317,7 +285,7 @@ extern "C" { pStarks: *mut ::std::os::raw::c_void, elementType: u32, step: u64, - trace: *mut ::std::os::raw::c_void, + witness: *mut ::std::os::raw::c_void, buffer: *mut ::std::os::raw::c_void, pProof: *mut ::std::os::raw::c_void, pBuffHelper: *mut ::std::os::raw::c_void, @@ -351,12 +319,7 @@ extern "C" { } extern "C" { #[link_name = "\u{1}_Z15merkle_tree_newmmmb"] - pub fn merkle_tree_new( - height: u64, - width: u64, - arity: u64, - custom: bool, - ) -> *mut ::std::os::raw::c_void; + pub fn merkle_tree_new(height: u64, width: u64, arity: u64, custom: bool) -> *mut ::std::os::raw::c_void; } extern "C" { #[link_name = "\u{1}_Z16merkle_tree_freePv"] @@ -407,27 +370,15 @@ extern "C" { } extern "C" { #[link_name = "\u{1}_Z17set_fri_final_polPvS_m"] - pub fn set_fri_final_pol( - pProof: *mut ::std::os::raw::c_void, - buffer: *mut ::std::os::raw::c_void, - nBits: u64, - ); + pub fn set_fri_final_pol(pProof: *mut ::std::os::raw::c_void, buffer: *mut ::std::os::raw::c_void, nBits: u64); } extern "C" { #[link_name = "\u{1}_Z14transcript_newjmb"] - pub fn transcript_new( - elementType: u32, - arity: u64, - custom: bool, - ) -> *mut ::std::os::raw::c_void; + pub fn transcript_new(elementType: u32, arity: u64, custom: bool) -> *mut ::std::os::raw::c_void; } extern "C" { #[link_name = "\u{1}_Z14transcript_addPvS_m"] - pub fn transcript_add( - pTranscript: *mut ::std::os::raw::c_void, - pInput: *mut ::std::os::raw::c_void, - size: u64, - ); + pub fn transcript_add(pTranscript: *mut ::std::os::raw::c_void, pInput: *mut ::std::os::raw::c_void, size: u64); } extern "C" { #[link_name = "\u{1}_Z25transcript_add_polinomialPvS_"] @@ -450,12 +401,7 @@ extern "C" { } extern "C" { #[link_name = "\u{1}_Z16get_permutationsPvPmmm"] - pub fn get_permutations( - pTranscript: *mut ::std::os::raw::c_void, - res: *mut u64, - n: u64, - nBits: u64, - ); + pub fn get_permutations(pTranscript: *mut ::std::os::raw::c_void, res: *mut u64, n: u64, nBits: u64); } extern "C" { #[link_name = "\u{1}_Z18verify_constraintsPvS_"] @@ -472,7 +418,7 @@ extern "C" { challenges: *mut ::std::os::raw::c_void, proofValues: *mut ::std::os::raw::c_void, airgroupValues: *mut *mut ::std::os::raw::c_void, - ) -> bool; + ) -> *mut ::std::os::raw::c_void; } extern "C" { #[link_name = "\u{1}_Z33get_hint_field_global_constraintsPvS_S_S_PS_mPcb"] @@ -499,22 +445,7 @@ extern "C" { } extern "C" { #[link_name = "\u{1}_Z9print_rowPvS_mm"] - pub fn print_row( - pSetupCtx: *mut ::std::os::raw::c_void, - buffer: *mut ::std::os::raw::c_void, - stage: u64, - row: u64, - ); -} -extern "C" { - #[link_name = "\u{1}_Z16print_expressionPvS_mmm"] - pub fn print_expression( - pSetupCtx: *mut ::std::os::raw::c_void, - pol: *mut ::std::os::raw::c_void, - dim: u64, - first_value: u64, - last_value: u64, - ); + pub fn print_row(pSetupCtx: *mut ::std::os::raw::c_void, buffer: *mut ::std::os::raw::c_void, stage: u64, row: u64); } extern "C" { #[link_name = "\u{1}_Z19gen_recursive_proofPvPcmS_S_S_S_S0_b"] @@ -522,7 +453,7 @@ extern "C" { pSetupCtx: *mut ::std::os::raw::c_void, globalInfoFile: *mut ::std::os::raw::c_char, airgroupId: u64, - pAddress: *mut ::std::os::raw::c_void, + witness: *mut ::std::os::raw::c_void, pConstPols: *mut ::std::os::raw::c_void, pConstTree: *mut ::std::os::raw::c_void, pPublicInputs: *mut ::std::os::raw::c_void, @@ -566,16 +497,11 @@ extern "C" { } extern "C" { #[link_name = "\u{1}_Z20get_serialized_proofPvPm"] - pub fn get_serialized_proof( - zkin: *mut ::std::os::raw::c_void, - size: *mut u64, - ) -> *mut ::std::os::raw::c_char; + pub fn get_serialized_proof(zkin: *mut ::std::os::raw::c_void, size: *mut u64) -> *mut ::std::os::raw::c_char; } extern "C" { #[link_name = "\u{1}_Z22deserialize_zkin_proofPc"] - pub fn deserialize_zkin_proof( - serialized_proof: *mut ::std::os::raw::c_char, - ) -> *mut ::std::os::raw::c_void; + pub fn deserialize_zkin_proof(serialized_proof: *mut ::std::os::raw::c_char) -> *mut ::std::os::raw::c_void; } extern "C" { #[link_name = "\u{1}_Z14get_zkin_proofPc"] @@ -590,23 +516,22 @@ extern "C" { pub fn serialized_proof_free(zkinCStr: *mut ::std::os::raw::c_char); } extern "C" { - #[link_name = "\u{1}_Z18get_committed_polsPvPcS_S_mmmmm"] + #[link_name = "\u{1}_Z18get_committed_polsPvPcS_S_mmmm"] pub fn get_committed_pols( - pWitness: *mut ::std::os::raw::c_void, + circomWitness: *mut ::std::os::raw::c_void, execFile: *mut ::std::os::raw::c_char, - pAddress: *mut ::std::os::raw::c_void, + witness: *mut ::std::os::raw::c_void, pPublics: *mut ::std::os::raw::c_void, sizeWitness: u64, N: u64, nPublics: u64, - offsetCm1: u64, nCols: u64, ); } extern "C" { #[link_name = "\u{1}_Z21gen_final_snark_proofPvPcS0_"] pub fn gen_final_snark_proof( - pWitnessFinal: *mut ::std::os::raw::c_void, + circomWitnessFinal: *mut ::std::os::raw::c_void, zkeyFile: *mut ::std::os::raw::c_char, outputDir: *mut ::std::os::raw::c_char, ); @@ -614,4 +539,4 @@ extern "C" { extern "C" { #[link_name = "\u{1}_Z11setLogLevelm"] pub fn setLogLevel(level: u64); -} +} \ No newline at end of file diff --git a/provers/starks-lib-c/src/ffi_starks.rs b/provers/starks-lib-c/src/ffi_starks.rs index 2564db59..6d156f44 100644 --- a/provers/starks-lib-c/src/ffi_starks.rs +++ b/provers/starks-lib-c/src/ffi_starks.rs @@ -127,11 +127,6 @@ pub fn get_map_totaln_c(p_stark_info: *mut c_void) -> u64 { unsafe { get_map_total_n(p_stark_info) } } -#[cfg(not(feature = "no_lib_link"))] -pub fn get_map_totaln_custom_commits_c(p_stark_info: *mut c_void, commit_id: u64) -> u64 { - unsafe { get_map_total_n_custom_commits(p_stark_info, commit_id) } -} - #[cfg(not(feature = "no_lib_link"))] pub fn get_custom_commit_map_ids_c(p_stark_info: *mut c_void, commit_id: u64, stage: u64) -> Vec { unsafe { @@ -147,12 +142,6 @@ pub fn get_custom_commit_map_ids_c(p_stark_info: *mut c_void, commit_id: u64, st } } -#[cfg(not(feature = "no_lib_link"))] -pub fn get_map_offsets_c(pStarkInfo: *mut c_void, stage: &str, flag: bool) -> u64 { - let stage = CString::new(stage).unwrap(); - unsafe { get_map_offsets(pStarkInfo, stage.as_ptr() as *mut std::os::raw::c_char, flag) } -} - #[cfg(not(feature = "no_lib_link"))] pub fn stark_info_free_c(p_stark_info: *mut c_void) { unsafe { @@ -439,11 +428,13 @@ pub fn calculate_impols_expressions_c(p_starks: *mut c_void, step: u64, p_steps_ } #[cfg(not(feature = "no_lib_link"))] +#[allow(clippy::too_many_arguments)] pub fn extend_and_merkelize_custom_commit_c( p_starks: *mut c_void, commit_id: u64, step: u64, buffer: *mut c_void, + buffer_ext: *mut c_void, p_proof: *mut c_void, p_buff_helper: *mut c_void, buffer_file: &str, @@ -455,6 +446,7 @@ pub fn extend_and_merkelize_custom_commit_c( commit_id, step, buffer, + buffer_ext, p_proof, p_buff_helper, buffer_file_name.as_ptr() as *mut std::os::raw::c_char, @@ -468,6 +460,7 @@ pub fn load_custom_commit_c( commit_id: u64, step: u64, buffer: *mut c_void, + buffer_ext: *mut c_void, p_proof: *mut c_void, buffer_file: &str, ) { @@ -478,6 +471,7 @@ pub fn load_custom_commit_c( commit_id, step, buffer, + buffer_ext, p_proof, buffer_file_name.as_ptr() as *mut std::os::raw::c_char, ); @@ -489,13 +483,13 @@ pub fn commit_stage_c( p_starks: *mut c_void, element_type: u32, step: u64, - trace: *mut c_void, + witness: *mut c_void, buffer: *mut c_void, p_proof: *mut c_void, p_buff_helper: *mut c_void, ) { unsafe { - commit_stage(p_starks, element_type, step, trace, buffer, p_proof, p_buff_helper); + commit_stage(p_starks, element_type, step, witness, buffer, p_proof, p_buff_helper); } } @@ -634,7 +628,7 @@ pub fn verify_global_constraints_c( challenges: *mut c_void, proof_values: *mut c_void, airgroupvalues: *mut *mut c_void, -) -> bool { +) -> *mut c_void { unsafe { verify_global_constraints(p_global_constraints_bin, publics, challenges, proof_values, airgroupvalues) } } @@ -685,19 +679,6 @@ pub fn set_hint_field_global_constraints_c( } } -#[cfg(not(feature = "no_lib_link"))] -pub fn print_expression_c( - p_setup_ctx: *mut c_void, - pol: *mut c_void, - dim: u64, - first_print_value: u64, - last_print_value: u64, -) { - unsafe { - print_expression(p_setup_ctx, pol, dim, first_print_value, last_print_value); - } -} - #[cfg(not(feature = "no_lib_link"))] pub fn print_row_c(p_setup_ctx: *mut c_void, buffer: *mut c_void, stage: u64, row: u64) { unsafe { @@ -843,30 +824,29 @@ pub fn serialized_proof_free_c(zkin_cstr: *mut std::os::raw::c_char) { #[cfg(not(feature = "no_lib_link"))] #[allow(clippy::too_many_arguments)] pub fn get_committed_pols_c( - pWitness: *mut ::std::os::raw::c_void, + circomWitness: *mut ::std::os::raw::c_void, execFile: *mut ::std::os::raw::c_char, - pAddress: *mut ::std::os::raw::c_void, + witness: *mut ::std::os::raw::c_void, pPublics: *mut ::std::os::raw::c_void, sizeWitness: u64, N: u64, nPublics: u64, - offsetCm1: u64, nCols: u64, ) { unsafe { - get_committed_pols(pWitness, execFile, pAddress, pPublics, sizeWitness, N, nPublics, offsetCm1, nCols); + get_committed_pols(circomWitness, execFile, witness, pPublics, sizeWitness, N, nPublics, nCols); } } #[cfg(not(feature = "no_lib_link"))] -pub fn gen_final_snark_proof_c(pWitnessFinal: *mut ::std::os::raw::c_void, zkeyFile: &str, outputDir: &str) { +pub fn gen_final_snark_proof_c(circomWitnessFinal: *mut ::std::os::raw::c_void, zkeyFile: &str, outputDir: &str) { let zkey_file_name = CString::new(zkeyFile).unwrap(); let zkey_file_ptr = zkey_file_name.as_ptr() as *mut std::os::raw::c_char; let output_dir_name = CString::new(outputDir).unwrap(); let output_dir_ptr = output_dir_name.as_ptr() as *mut std::os::raw::c_char; unsafe { - gen_final_snark_proof(pWitnessFinal, zkey_file_ptr, output_dir_ptr); + gen_final_snark_proof(circomWitnessFinal, zkey_file_ptr, output_dir_ptr); } } @@ -965,16 +945,6 @@ pub fn get_map_totaln_c(_p_stark_info: *mut c_void) -> u64 { 100000000 } -#[cfg(feature = "no_lib_link")] -pub fn get_map_totaln_custom_commits_c(_p_stark_info: *mut c_void, _commit_id: u64) -> u64 { - trace!( - "{}: ··· {}", - "ffi ", - "get_map_totaln_custom_commits: This is a mock call because there is no linked library" - ); - 100000000 -} - #[cfg(feature = "no_lib_link")] pub fn get_custom_commit_id_c(_p_stark_info: *mut c_void, _name: &str) -> u64 { trace!("{}: ··· {}", "ffi ", "get_custom_commit_id: This is a mock call because there is no linked library"); @@ -991,12 +961,6 @@ pub fn get_custom_commit_map_ids_c(_p_stark_info: *mut c_void, _commit_id: u64, Vec::new() } -#[cfg(feature = "no_lib_link")] -pub fn get_map_offsets_c(_p_stark_info: *mut c_void, _stage: &str, _flag: bool) -> u64 { - trace!("{}: ··· {}", "ffi ", "get_map_offsets: This is a mock call because there is no linked library"); - 0 -} - #[cfg(feature = "no_lib_link")] pub fn stark_info_free_c(_p_stark_info: *mut c_void) { trace!("{}: ··· {}", "ffi ", "starkinfo_free: This is a mock call because there is no linked library"); @@ -1181,11 +1145,13 @@ pub fn calculate_impols_expressions_c(_p_starks: *mut c_void, _step: u64, _p_ste } #[cfg(feature = "no_lib_link")] +#[allow(clippy::too_many_arguments)] pub fn extend_and_merkelize_custom_commit_c( _p_starks: *mut c_void, _commit_id: u64, _step: u64, _buffer: *mut c_void, + _buffer_ext: *mut c_void, _p_proof: *mut c_void, _p_buff_helper: *mut c_void, _tree_file: &str, @@ -1203,6 +1169,7 @@ pub fn load_custom_commit_c( _commit_id: u64, _step: u64, _buffer: *mut c_void, + _buffer_ext: *mut c_void, _p_proof: *mut c_void, _tree_file: &str, ) { @@ -1214,7 +1181,7 @@ pub fn commit_stage_c( _p_starks: *mut c_void, _element_type: u32, _step: u64, - _trace: *mut c_void, + _witness: *mut c_void, _buffer: *mut c_void, _p_proof: *mut c_void, _p_buff_helper: *mut c_void, @@ -1348,13 +1315,13 @@ pub fn verify_global_constraints_c( _challenges: *mut c_void, _proof_values: *mut c_void, _airgroupvalues: *mut *mut c_void, -) -> bool { +) -> *mut c_void { trace!( "{}: ··· {}", "ffi ", "verify_global_constraints: This is a mock call because there is no linked library" ); - true + std::ptr::null_mut() } #[cfg(feature = "no_lib_link")] @@ -1393,17 +1360,6 @@ pub fn set_hint_field_global_constraints_c( 100000 } -#[cfg(feature = "no_lib_link")] -pub fn print_expression_c( - _p_setup_ctx: *mut c_void, - _pol: *mut c_void, - _dim: u64, - _first_print_value: u64, - _last_print_value: u64, -) { - trace!("{}: ··· {}", "ffi ", "print_expression: This is a mock call because there is no linked library"); -} - #[cfg(feature = "no_lib_link")] pub fn print_row_c(_p_setup_ctx: *mut c_void, _buffer: *mut c_void, _stage: u64, _row: u64) { trace!("{}: ··· {}", "ffi ", "print_row: This is a mock call because there is no linked library"); @@ -1496,21 +1452,20 @@ pub fn serialized_proof_free_c(_zkin_cstr: *mut std::os::raw::c_char) { #[cfg(feature = "no_lib_link")] #[allow(clippy::too_many_arguments)] pub fn get_committed_pols_c( - _pWitness: *mut ::std::os::raw::c_void, + _circomWitness: *mut ::std::os::raw::c_void, _execFile: *mut ::std::os::raw::c_char, - _pAddress: *mut ::std::os::raw::c_void, + _witness: *mut ::std::os::raw::c_void, _pPublics: *mut ::std::os::raw::c_void, _sizeWitness: u64, _N: u64, _nPublics: u64, - _offsetCm1: u64, _nCols: u64, ) { trace!("{}: ··· {}", "ffi ", "get_committed_pols: This is a mock call because there is no linked library"); } #[cfg(feature = "no_lib_link")] -pub fn gen_final_snark_proof_c(_pWitnessFinal: *mut ::std::os::raw::c_void, _zkeyFile: &str, _outputDir: &str) { +pub fn gen_final_snark_proof_c(_circomWitnessFinal: *mut ::std::os::raw::c_void, _zkeyFile: &str, _outputDir: &str) { trace!("{}: ··· {}", "ffi ", "gen_final_snark_proof: This is a mock call because there is no linked library"); } From 2a7073d5da22902f1f4a3fffc650b0989c59580e Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Wed, 4 Dec 2024 17:49:01 +0000 Subject: [PATCH 12/64] Removing map_buffer from tests --- .../test/simple/rs/src/simple_left.rs | 84 +++---- .../test/simple/rs/src/simple_right.rs | 58 ++--- .../test/std/connection/rs/src/connection1.rs | 49 ++-- .../test/std/connection/rs/src/connection2.rs | 52 ++-- .../std/connection/rs/src/connection_new.rs | 237 +++++++++--------- .../test/std/lookup/rs/src/lookup0.rs | 75 +++--- .../test/std/lookup/rs/src/lookup1.rs | 71 +++--- .../test/std/lookup/rs/src/lookup2_12.rs | 95 ++++--- .../test/std/lookup/rs/src/lookup2_13.rs | 94 ++++--- .../test/std/lookup/rs/src/lookup2_15.rs | 94 ++++--- .../test/std/lookup/rs/src/lookup3.rs | 77 +++--- .../std/permutation/rs/src/permutation1_6.rs | 150 ++++++----- .../std/permutation/rs/src/permutation1_7.rs | 114 ++++----- .../std/permutation/rs/src/permutation1_8.rs | 113 ++++----- .../std/permutation/rs/src/permutation2.rs | 64 ++--- .../range_check/rs/src/multi_range_check1.rs | 148 ++++++----- .../range_check/rs/src/multi_range_check2.rs | 112 ++++----- .../std/range_check/rs/src/range_check1.rs | 103 ++++---- .../std/range_check/rs/src/range_check2.rs | 55 ++-- .../std/range_check/rs/src/range_check3.rs | 51 ++-- .../std/range_check/rs/src/range_check4.rs | 145 ++++++----- .../rs/src/range_check_dynamic1.rs | 104 ++++---- .../rs/src/range_check_dynamic2.rs | 128 +++++----- .../std/range_check/rs/src/range_check_mix.rs | 205 ++++++++------- 24 files changed, 1149 insertions(+), 1329 deletions(-) diff --git a/pil2-components/test/simple/rs/src/simple_left.rs b/pil2-components/test/simple/rs/src/simple_left.rs index 389fd881..34939e5c 100644 --- a/pil2-components/test/simple/rs/src/simple_left.rs +++ b/pil2-components/test/simple/rs/src/simple_left.rs @@ -27,8 +27,39 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); + let num_rows = pctx.global_info.airs[SIMPLE_AIRGROUP_ID][SIMPLE_LEFT_AIR_IDS[0]].num_rows; - let trace = SimpleLeftTrace::new(num_rows); + let air = pctx.pilout.get_air(SIMPLE_AIRGROUP_ID, SIMPLE_LEFT_AIR_IDS[0]); + let mut trace = SimpleLeftTrace::new(num_rows); + + log::debug!( + "{}: ··· Computing witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + + // Assumes + for i in 0..num_rows { + trace[i].a = F::from_canonical_usize(i); + trace[i].b = F::from_canonical_usize(i); + + trace[i].e = F::from_canonical_u8(200); + trace[i].f = F::from_canonical_u8(201); + + trace[i].g = F::from_canonical_usize(i); + trace[i].h = F::from_canonical_usize(num_rows - i - 1); + } + + let mut indices: Vec = (0..num_rows).collect(); + indices.shuffle(&mut rng); + + // Proves + for i in 0..num_rows { + // We take a random permutation of the indices to show that the permutation check is passing + trace[i].c = trace[indices[i]].a; + trace[i].d = trace[indices[i]].b; + } let air_instance = AirInstance::new(sctx.clone(), SIMPLE_AIRGROUP_ID, SIMPLE_LEFT_AIR_IDS[0], None, trace.buffer.unwrap()); @@ -46,56 +77,11 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, - pctx: Arc>, + _stage: u32, + _air_instance_id: Option, + _pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - - let airgroup_id = air_instance.airgroup_id; - let air_id = air_instance.air_id; - let air = pctx.pilout.get_air(airgroup_id, air_id); - - log::debug!( - "{}: ··· Computing witness computation for AIR '{}' at stage {}", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - stage - ); - - if stage == 1 { - let buffer = &mut air_instance.witness; - let num_rows = pctx.pilout.get_air(airgroup_id, air_id).num_rows(); - - // I cannot, programatically, link the permutation trace with its air_id - let mut trace = SimpleLeftTrace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - // Assumes - for i in 0..num_rows { - trace[i].a = F::from_canonical_usize(i); - trace[i].b = F::from_canonical_usize(i); - - trace[i].e = F::from_canonical_u8(200); - trace[i].f = F::from_canonical_u8(201); - - trace[i].g = F::from_canonical_usize(i); - trace[i].h = F::from_canonical_usize(num_rows - i - 1); - } - - let mut indices: Vec = (0..num_rows).collect(); - indices.shuffle(&mut rng); - - // Proves - for i in 0..num_rows { - // We take a random permutation of the indices to show that the permutation check is passing - trace[i].c = trace[indices[i]].a; - trace[i].d = trace[indices[i]].b; - } - } } } diff --git a/pil2-components/test/simple/rs/src/simple_right.rs b/pil2-components/test/simple/rs/src/simple_right.rs index 83bcd8ad..d7b2fdab 100644 --- a/pil2-components/test/simple/rs/src/simple_right.rs +++ b/pil2-components/test/simple/rs/src/simple_right.rs @@ -28,7 +28,25 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let num_rows = pctx.global_info.airs[SIMPLE_AIRGROUP_ID][SIMPLE_RIGHT_AIR_IDS[0]].num_rows; - let trace = SimpleRightTrace::new(num_rows); + let air = pctx.pilout.get_air(SIMPLE_AIRGROUP_ID, SIMPLE_RIGHT_AIR_IDS[0]); + let mut trace = SimpleRightTrace::new(num_rows); + + log::debug!( + "{}: ··· Computing witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + + // Proves + for i in 0..num_rows { + trace[i].a = F::from_canonical_u8(200); + trace[i].b = F::from_canonical_u8(201); + + trace[i].c = F::from_canonical_usize(i); + trace[i].d = F::from_canonical_usize(num_rows - i - 1); + + trace[i].mul = F::from_canonical_usize(1); + } let air_instance = AirInstance::new(sctx.clone(), SIMPLE_AIRGROUP_ID, SIMPLE_RIGHT_AIR_IDS[0], None, trace.buffer.unwrap()); @@ -45,43 +63,11 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, - pctx: Arc>, + _stage: u32, + _air_instance_id: Option, + _pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - - let airgroup_id = air_instance.airgroup_id; - let air_id = air_instance.air_id; - let air = pctx.pilout.get_air(airgroup_id, air_id); - - log::debug!( - "{}: ··· Computing witness computation for AIR '{}' at stage {}", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - stage - ); - - if stage == 1 { - let buffer = &mut air_instance.witness; - let num_rows = pctx.pilout.get_air(airgroup_id, air_id).num_rows(); - - // I cannot, programatically, link the permutation trace with its air_id - let mut trace = SimpleRightTrace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - // Proves - for i in 0..num_rows { - trace[i].a = F::from_canonical_u8(200); - trace[i].b = F::from_canonical_u8(201); - - trace[i].c = F::from_canonical_usize(i); - trace[i].d = F::from_canonical_usize(num_rows - i - 1); - - trace[i].mul = F::from_canonical_usize(1); - } - } } } diff --git a/pil2-components/test/std/connection/rs/src/connection1.rs b/pil2-components/test/std/connection/rs/src/connection1.rs index a7005a89..901ad33e 100644 --- a/pil2-components/test/std/connection/rs/src/connection1.rs +++ b/pil2-components/test/std/connection/rs/src/connection1.rs @@ -27,9 +27,25 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); + // For simplicity, add a single instance of each air let num_rows = pctx.global_info.airs[CONNECTION_AIRGROUP_ID][CONNECTION_1_AIR_IDS[0]].num_rows; - let trace = Connection1Trace::new_zeroes(num_rows); + let air = pctx.pilout.get_air(CONNECTION_AIRGROUP_ID, CONNECTION_1_AIR_IDS[0]); + + let mut trace = Connection1Trace::new_zeroes(num_rows); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + + for i in 0..num_rows { + trace[i].a = rng.gen(); + trace[i].b = rng.gen(); + trace[i].c = rng.gen(); + } let air_instance = AirInstance::new( sctx.clone(), @@ -52,36 +68,11 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, - pctx: Arc>, + _stage: u32, + _air_instance_id: Option, + _pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let air = pctx.pilout.get_air(air_instance.airgroup_id, air_instance.air_id); - - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage {}", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - stage - ); - - if stage == 1 { - let buffer = &mut air_instance.witness; - - let num_rows = pctx.pilout.get_air(CONNECTION_AIRGROUP_ID, CONNECTION_1_AIR_IDS[0]).num_rows(); - let mut trace = Connection1Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - for i in 0..num_rows { - trace[i].a = rng.gen(); - trace[i].b = rng.gen(); - trace[i].c = rng.gen(); - } - } } } diff --git a/pil2-components/test/std/connection/rs/src/connection2.rs b/pil2-components/test/std/connection/rs/src/connection2.rs index ae8323d3..30192ed0 100644 --- a/pil2-components/test/std/connection/rs/src/connection2.rs +++ b/pil2-components/test/std/connection/rs/src/connection2.rs @@ -27,8 +27,25 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); + let num_rows = pctx.global_info.airs[CONNECTION_AIRGROUP_ID][CONNECTION_2_AIR_IDS[0]].num_rows; - let trace = Connection2Trace::new_zeroes(num_rows); + let air = pctx.pilout.get_air(CONNECTION_AIRGROUP_ID, CONNECTION_2_AIR_IDS[0]); + let mut trace = Connection2Trace::new_zeroes(num_rows); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + + for i in 0..num_rows { + trace[i].a = rng.gen(); + trace[i].b = rng.gen(); + trace[i].c = rng.gen(); + } + + trace[0].a = trace[1].a; let air_instance = AirInstance::new( sctx.clone(), @@ -51,38 +68,11 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, - pctx: Arc>, + _stage: u32, + _air_instance_id: Option, + _pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let air = pctx.pilout.get_air(air_instance.airgroup_id, air_instance.air_id); - - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage {}", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - stage - ); - - if stage == 1 { - let buffer = &mut air_instance.witness; - - let num_rows = pctx.pilout.get_air(CONNECTION_AIRGROUP_ID, CONNECTION_2_AIR_IDS[0]).num_rows(); - let mut trace = Connection2Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - for i in 0..num_rows { - trace[i].a = rng.gen(); - trace[i].b = rng.gen(); - trace[i].c = rng.gen(); - } - - trace[0].a = trace[1].a; - } } } diff --git a/pil2-components/test/std/connection/rs/src/connection_new.rs b/pil2-components/test/std/connection/rs/src/connection_new.rs index 1dccfdf4..004743b8 100644 --- a/pil2-components/test/std/connection/rs/src/connection_new.rs +++ b/pil2-components/test/std/connection/rs/src/connection_new.rs @@ -27,8 +27,117 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); let num_rows = pctx.global_info.airs[CONNECTION_AIRGROUP_ID][CONNECTION_NEW_AIR_IDS[0]].num_rows; - let trace = ConnectionNewTrace::new_zeroes(num_rows); + let mut trace = ConnectionNewTrace::new_zeroes(num_rows); + + let air = pctx.pilout.get_air(CONNECTION_AIRGROUP_ID, CONNECTION_NEW_AIR_IDS[0]); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + + let mut frame = [0; 6]; + let mut conn_len = [0; 6]; + for i in 0..num_rows { + // Start connection + trace[i].a[0] = rng.gen(); + trace[i].b[0] = rng.gen(); + trace[i].c[0] = rng.gen(); + + // Start connection + trace[i].a[1] = rng.gen(); + trace[i].b[1] = rng.gen(); + trace[i].c[1] = rng.gen(); + if i == 3 + frame[1] { + trace[i - 1].c[1] = trace[i].c[1]; + frame[1] += num_rows / 2; + } + + // TODO: Finish! + // // Start connection + // trace[i].a[2] = rng.gen(); + // trace[i].b[2] = rng.gen(); + // trace[i].c[2] = rng.gen(); + // if i == 3 + frame[2] { + // trace[i - 1].c[2] = trace[i].c[2]; + + // trace[0 + frame[2]].c[2] = trace[i].b[2]; + // trace[1 + frame[2]].a[2] = trace[i].b[2]; + // conn_len[2] += 2; + // } + + // if i == 3 + frame[2] { + // trace[i - 1].c[2] = trace[i].c[2]; + + // trace[0 + frame[2]].c[2] = trace[i].b[2]; + // trace[1 + frame[2]].a[2] = trace[i].b[2]; + // conn_len[2] += 2; + // } + + // if conn_len[2] == 3 { + // frame[2] += num_rows / 4; + // conn_len[2] = 0; + // } + + // Start connection + trace[i].a[3] = rng.gen(); + trace[i].b[3] = rng.gen(); + trace[i].c[3] = rng.gen(); + if i == 2 + frame[3] { + trace[i - 1].c[3] = trace[i].a[3]; + frame[3] += num_rows / 2; + } + + if i == 3 { + trace[i - 3].c[3] = trace[i].b[3]; + trace[i - 2].a[3] = trace[i - 3].c[3]; + } + + // Start connection + trace[i].a[4] = rng.gen(); + trace[i].b[4] = rng.gen(); + trace[i].c[4] = rng.gen(); + + if i == 2 + frame[4] { + trace[i - 1].d[4] = trace[i - 1].b[4]; + trace[i - 1].a[4] = trace[i].c[4]; + conn_len[4] += 1; + } + + if i == 3 + frame[4] { + trace[i - 1].b[4] = trace[i].a[4]; + trace[i].c[4] = trace[i - 1].b[4]; + conn_len[4] += 1; + } + + if conn_len[4] == 2 { + frame[4] += num_rows / 2; + conn_len[4] = 0; + } + + // Start connection + trace[i].a[5] = rng.gen(); + trace[i].b[5] = rng.gen(); + trace[i].c[5] = rng.gen(); + if i == 3 + frame[5] { + trace[i - 1].d[5] = trace[i].d[5]; + trace[i - 3].b[5] = trace[i].d[5]; + conn_len[5] += 2; + } + + if i == 8 { + trace[5].b[5] = trace[i].c[5]; + trace[1].a[5] = trace[i].c[5]; + } + + if conn_len[5] == 2 { + frame[5] += num_rows / 2; + conn_len[5] = 0; + } + } let air_instance = AirInstance::new( sctx.clone(), @@ -37,6 +146,7 @@ where None, trace.buffer.unwrap(), ); + let (is_myne, gid) = ectx.dctx.write().unwrap().add_instance(CONNECTION_AIRGROUP_ID, CONNECTION_NEW_AIR_IDS[0], 1); if is_myne { @@ -51,130 +161,11 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, - pctx: Arc>, + _stage: u32, + _air_instance_id: Option, + _pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let air = pctx.pilout.get_air(air_instance.airgroup_id, air_instance.air_id); - - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage {}", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - stage - ); - - if stage == 1 { - let buffer = &mut air_instance.witness; - - let num_rows = pctx.pilout.get_air(CONNECTION_AIRGROUP_ID, CONNECTION_NEW_AIR_IDS[0]).num_rows(); - let mut trace = ConnectionNewTrace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - let mut frame = [0; 6]; - let mut conn_len = [0; 6]; - for i in 0..num_rows { - // Start connection - trace[i].a[0] = rng.gen(); - trace[i].b[0] = rng.gen(); - trace[i].c[0] = rng.gen(); - - // Start connection - trace[i].a[1] = rng.gen(); - trace[i].b[1] = rng.gen(); - trace[i].c[1] = rng.gen(); - if i == 3 + frame[1] { - trace[i - 1].c[1] = trace[i].c[1]; - frame[1] += num_rows / 2; - } - - // TODO: Finish! - // // Start connection - // trace[i].a[2] = rng.gen(); - // trace[i].b[2] = rng.gen(); - // trace[i].c[2] = rng.gen(); - // if i == 3 + frame[2] { - // trace[i - 1].c[2] = trace[i].c[2]; - - // trace[0 + frame[2]].c[2] = trace[i].b[2]; - // trace[1 + frame[2]].a[2] = trace[i].b[2]; - // conn_len[2] += 2; - // } - - // if i == 3 + frame[2] { - // trace[i - 1].c[2] = trace[i].c[2]; - - // trace[0 + frame[2]].c[2] = trace[i].b[2]; - // trace[1 + frame[2]].a[2] = trace[i].b[2]; - // conn_len[2] += 2; - // } - - // if conn_len[2] == 3 { - // frame[2] += num_rows / 4; - // conn_len[2] = 0; - // } - - // Start connection - trace[i].a[3] = rng.gen(); - trace[i].b[3] = rng.gen(); - trace[i].c[3] = rng.gen(); - if i == 2 + frame[3] { - trace[i - 1].c[3] = trace[i].a[3]; - frame[3] += num_rows / 2; - } - - if i == 3 { - trace[i - 3].c[3] = trace[i].b[3]; - trace[i - 2].a[3] = trace[i - 3].c[3]; - } - - // Start connection - trace[i].a[4] = rng.gen(); - trace[i].b[4] = rng.gen(); - trace[i].c[4] = rng.gen(); - - if i == 2 + frame[4] { - trace[i - 1].d[4] = trace[i - 1].b[4]; - trace[i - 1].a[4] = trace[i].c[4]; - conn_len[4] += 1; - } - - if i == 3 + frame[4] { - trace[i - 1].b[4] = trace[i].a[4]; - trace[i].c[4] = trace[i - 1].b[4]; - conn_len[4] += 1; - } - - if conn_len[4] == 2 { - frame[4] += num_rows / 2; - conn_len[4] = 0; - } - - // Start connection - trace[i].a[5] = rng.gen(); - trace[i].b[5] = rng.gen(); - trace[i].c[5] = rng.gen(); - if i == 3 + frame[5] { - trace[i - 1].d[5] = trace[i].d[5]; - trace[i - 3].b[5] = trace[i].d[5]; - conn_len[5] += 2; - } - - if i == 8 { - trace[5].b[5] = trace[i].c[5]; - trace[1].a[5] = trace[i].c[5]; - } - - if conn_len[5] == 2 { - frame[5] += num_rows / 2; - conn_len[5] = 0; - } - } - } } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup0.rs b/pil2-components/test/std/lookup/rs/src/lookup0.rs index bd5e726c..fb71a2fe 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup0.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup0.rs @@ -27,8 +27,37 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); + let num_rows = pctx.global_info.airs[LOOKUP_AIRGROUP_ID][LOOKUP_0_AIR_IDS[0]].num_rows; - let trace = Lookup0Trace::new(num_rows); + let air = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_0_AIR_IDS[0]); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + + let mut trace = Lookup0Trace::new(num_rows); + + let num_lookups = trace[0].sel.len(); + + for j in 0..num_lookups { + for i in 0..num_rows { + // Assumes + trace[i].f[2 * j] = rng.gen(); + trace[i].f[2 * j + 1] = rng.gen(); + let selected = rng.gen_bool(0.5); + trace[i].sel[j] = F::from_bool(selected); + + // Proves + trace[i].t[2 * j] = trace[i].f[2 * j]; + trace[i].t[2 * j + 1] = trace[i].f[2 * j + 1]; + if selected { + trace[i].mul[j] = F::one(); + } + } + } let air_instance = AirInstance::new(sctx.clone(), LOOKUP_AIRGROUP_ID, LOOKUP_0_AIR_IDS[0], None, trace.buffer.unwrap()); @@ -46,49 +75,11 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, - pctx: Arc>, + _stage: u32, + _air_instance_id: Option, + _pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let air = pctx.pilout.get_air(air_instance.airgroup_id, air_instance.air_id); - - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage {}", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - stage - ); - - if stage == 1 { - let buffer = &mut air_instance.witness; - - let num_rows = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_0_AIR_IDS[0]).num_rows(); - let mut trace = Lookup0Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - let num_lookups = trace[0].sel.len(); - - for j in 0..num_lookups { - for i in 0..num_rows { - // Assumes - trace[i].f[2 * j] = rng.gen(); - trace[i].f[2 * j + 1] = rng.gen(); - let selected = rng.gen_bool(0.5); - trace[i].sel[j] = F::from_bool(selected); - - // Proves - trace[i].t[2 * j] = trace[i].f[2 * j]; - trace[i].t[2 * j + 1] = trace[i].f[2 * j + 1]; - if selected { - trace[i].mul[j] = F::one(); - } - } - } - } } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup1.rs b/pil2-components/test/std/lookup/rs/src/lookup1.rs index 47e69321..47dbd960 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup1.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup1.rs @@ -27,8 +27,35 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); + let num_rows = pctx.global_info.airs[LOOKUP_AIRGROUP_ID][LOOKUP_1_AIR_IDS[0]].num_rows; - let trace = Lookup1Trace::new(num_rows); + let air = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_1_AIR_IDS[0]); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + + let mut trace = Lookup1Trace::new(num_rows); + + let num_lookups = trace[0].sel.len(); + + for i in 0..num_rows { + let val = rng.gen(); + let mut n_sel = 0; + for j in 0..num_lookups { + trace[i].f[j] = val; + let selected = rng.gen_bool(0.5); + trace[i].sel[j] = F::from_bool(selected); + if selected { + n_sel += 1; + } + } + trace[i].t = val; + trace[i].mul = F::from_canonical_usize(n_sel); + } let air_instance = AirInstance::new(sctx.clone(), LOOKUP_AIRGROUP_ID, LOOKUP_1_AIR_IDS[0], None, trace.buffer.unwrap()); @@ -46,47 +73,11 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, - pctx: Arc>, + _stage: u32, + _air_instance_id: Option, + _pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let air = pctx.pilout.get_air(air_instance.airgroup_id, air_instance.air_id); - - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage {}", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - stage - ); - - if stage == 1 { - let buffer = &mut air_instance.witness; - - let num_rows = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_1_AIR_IDS[0]).num_rows(); - let mut trace = Lookup1Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - let num_lookups = trace[0].sel.len(); - - for i in 0..num_rows { - let val = rng.gen(); - let mut n_sel = 0; - for j in 0..num_lookups { - trace[i].f[j] = val; - let selected = rng.gen_bool(0.5); - trace[i].sel[j] = F::from_bool(selected); - if selected { - n_sel += 1; - } - } - trace[i].t = val; - trace[i].mul = F::from_canonical_usize(n_sel); - } - } } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs index aaba64b0..fd4a4a63 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs @@ -27,8 +27,47 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); + let num_rows = pctx.global_info.airs[LOOKUP_AIRGROUP_ID][LOOKUP_2_12_AIR_IDS[0]].num_rows; - let trace = Lookup2_12Trace::new(num_rows); + let air = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_2_12_AIR_IDS[0]); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + + let mut trace = Lookup2_12Trace::new(num_rows); + + // TODO: Add the ability to send inputs to lookup3 + // and consequently add random selectors + + for i in 0..num_rows { + // Inner lookups + trace[i].a1 = rng.gen(); + trace[i].b1 = rng.gen(); + trace[i].c1 = trace[i].a1; + trace[i].d1 = trace[i].b1; + + trace[i].a3 = rng.gen(); + trace[i].b3 = rng.gen(); + trace[i].c2 = trace[i].a3; + trace[i].d2 = trace[i].b3; + let selected = rng.gen_bool(0.5); + trace[i].sel1 = F::from_bool(selected); + if selected { + trace[i].mul = trace[i].sel1; + } + + // Outer lookups + trace[i].a2 = F::from_canonical_usize(i); + trace[i].b2 = F::from_canonical_usize(i); + + trace[i].a4 = F::from_canonical_usize(i); + trace[i].b4 = F::from_canonical_usize(i); + trace[i].sel2 = F::from_bool(true); + } let air_instance = AirInstance::new(sctx.clone(), LOOKUP_AIRGROUP_ID, LOOKUP_2_12_AIR_IDS[0], None, trace.buffer.unwrap()); @@ -46,59 +85,11 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, - pctx: Arc>, + _stage: u32, + _air_instance_id: Option, + _pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let air = pctx.pilout.get_air(air_instance.airgroup_id, air_instance.air_id); - - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage {}", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - stage - ); - - if stage == 1 { - let buffer = &mut air_instance.witness; - - let num_rows = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_2_12_AIR_IDS[0]).num_rows(); - let mut trace = Lookup2_12Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - // TODO: Add the ability to send inputs to lookup3 - // and consequently add random selectors - - for i in 0..num_rows { - // Inner lookups - trace[i].a1 = rng.gen(); - trace[i].b1 = rng.gen(); - trace[i].c1 = trace[i].a1; - trace[i].d1 = trace[i].b1; - - trace[i].a3 = rng.gen(); - trace[i].b3 = rng.gen(); - trace[i].c2 = trace[i].a3; - trace[i].d2 = trace[i].b3; - let selected = rng.gen_bool(0.5); - trace[i].sel1 = F::from_bool(selected); - if selected { - trace[i].mul = trace[i].sel1; - } - - // Outer lookups - trace[i].a2 = F::from_canonical_usize(i); - trace[i].b2 = F::from_canonical_usize(i); - - trace[i].a4 = F::from_canonical_usize(i); - trace[i].b4 = F::from_canonical_usize(i); - trace[i].sel2 = F::from_bool(true); - } - } } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs index 23fd207b..1c7de046 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs @@ -27,8 +27,46 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); + let num_rows = pctx.global_info.airs[LOOKUP_AIRGROUP_ID][LOOKUP_2_13_AIR_IDS[0]].num_rows; - let trace = Lookup2_13Trace::new(num_rows); + let air = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_2_13_AIR_IDS[0]); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + let mut trace = Lookup2_13Trace::new(num_rows); + + // TODO: Add the ability to send inputs to lookup3 + // and consequently add random selectors + + for i in 0..num_rows { + // Inner lookups + trace[i].a1 = rng.gen(); + trace[i].b1 = rng.gen(); + trace[i].c1 = trace[i].a1; + trace[i].d1 = trace[i].b1; + + trace[i].a3 = rng.gen(); + trace[i].b3 = rng.gen(); + trace[i].c2 = trace[i].a3; + trace[i].d2 = trace[i].b3; + let selected = rng.gen_bool(0.5); + trace[i].sel1 = F::from_bool(selected); + if selected { + trace[i].mul = trace[i].sel1; + } + + // Outer lookups + trace[i].a2 = F::from_canonical_usize(i); + trace[i].b2 = F::from_canonical_usize(i); + + trace[i].a4 = F::from_canonical_usize(i); + trace[i].b4 = F::from_canonical_usize(i); + trace[i].sel2 = F::from_bool(true); + } let air_instance = AirInstance::new(sctx.clone(), LOOKUP_AIRGROUP_ID, LOOKUP_2_13_AIR_IDS[0], None, trace.buffer.unwrap()); @@ -46,59 +84,11 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, - pctx: Arc>, + _stage: u32, + _air_instance_id: Option, + _pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let air = pctx.pilout.get_air(air_instance.airgroup_id, air_instance.air_id); - - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage {}", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - stage - ); - - if stage == 1 { - let buffer = &mut air_instance.witness; - - let num_rows = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_2_13_AIR_IDS[0]).num_rows(); - let mut trace = Lookup2_13Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - // TODO: Add the ability to send inputs to lookup3 - // and consequently add random selectors - - for i in 0..num_rows { - // Inner lookups - trace[i].a1 = rng.gen(); - trace[i].b1 = rng.gen(); - trace[i].c1 = trace[i].a1; - trace[i].d1 = trace[i].b1; - - trace[i].a3 = rng.gen(); - trace[i].b3 = rng.gen(); - trace[i].c2 = trace[i].a3; - trace[i].d2 = trace[i].b3; - let selected = rng.gen_bool(0.5); - trace[i].sel1 = F::from_bool(selected); - if selected { - trace[i].mul = trace[i].sel1; - } - - // Outer lookups - trace[i].a2 = F::from_canonical_usize(i); - trace[i].b2 = F::from_canonical_usize(i); - - trace[i].a4 = F::from_canonical_usize(i); - trace[i].b4 = F::from_canonical_usize(i); - trace[i].sel2 = F::from_bool(true); - } - } } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs index d1dfb65b..12d1ff6d 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs @@ -27,8 +27,46 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); let num_rows = pctx.global_info.airs[LOOKUP_AIRGROUP_ID][LOOKUP_2_15_AIR_IDS[0]].num_rows; - let trace = Lookup2_15Trace::new(num_rows); + let air = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_2_15_AIR_IDS[0]); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + + let mut trace = Lookup2_15Trace::new(num_rows); + + // TODO: Add the ability to send inputs to lookup3 + // and consequently add random selectors + + for i in 0..num_rows { + // Inner lookups + trace[i].a1 = rng.gen(); + trace[i].b1 = rng.gen(); + trace[i].c1 = trace[i].a1; + trace[i].d1 = trace[i].b1; + + trace[i].a3 = rng.gen(); + trace[i].b3 = rng.gen(); + trace[i].c2 = trace[i].a3; + trace[i].d2 = trace[i].b3; + let selected = rng.gen_bool(0.5); + trace[i].sel1 = F::from_bool(selected); + if selected { + trace[i].mul = trace[i].sel1; + } + + // Outer lookups + trace[i].a2 = F::from_canonical_usize(i % (1 << 14)); + trace[i].b2 = F::from_canonical_usize(i % (1 << 14)); + + trace[i].a4 = F::from_canonical_usize(i % (1 << 14)); + trace[i].b4 = F::from_canonical_usize(i % (1 << 14)); + trace[i].sel2 = F::from_bool(true); + } let air_instance = AirInstance::new(sctx.clone(), LOOKUP_AIRGROUP_ID, LOOKUP_2_15_AIR_IDS[0], None, trace.buffer.unwrap()); @@ -46,59 +84,11 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, - pctx: Arc>, + _stage: u32, + _air_instance_id: Option, + _pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let air = pctx.pilout.get_air(air_instance.airgroup_id, air_instance.air_id); - - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage {}", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - stage - ); - - if stage == 1 { - let buffer = &mut air_instance.witness; - - let num_rows = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_2_15_AIR_IDS[0]).num_rows(); - let mut trace = Lookup2_15Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - // TODO: Add the ability to send inputs to lookup3 - // and consequently add random selectors - - for i in 0..num_rows { - // Inner lookups - trace[i].a1 = rng.gen(); - trace[i].b1 = rng.gen(); - trace[i].c1 = trace[i].a1; - trace[i].d1 = trace[i].b1; - - trace[i].a3 = rng.gen(); - trace[i].b3 = rng.gen(); - trace[i].c2 = trace[i].a3; - trace[i].d2 = trace[i].b3; - let selected = rng.gen_bool(0.5); - trace[i].sel1 = F::from_bool(selected); - if selected { - trace[i].mul = trace[i].sel1; - } - - // Outer lookups - trace[i].a2 = F::from_canonical_usize(i % (1 << 14)); - trace[i].b2 = F::from_canonical_usize(i % (1 << 14)); - - trace[i].a4 = F::from_canonical_usize(i % (1 << 14)); - trace[i].b4 = F::from_canonical_usize(i % (1 << 14)); - trace[i].sel2 = F::from_bool(true); - } - } } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup3.rs b/pil2-components/test/std/lookup/rs/src/lookup3.rs index 8dd4e20d..c97b543c 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup3.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup3.rs @@ -25,7 +25,37 @@ impl Lookup3 { pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { // For simplicity, add a single instance of each air let num_rows = pctx.global_info.airs[LOOKUP_AIRGROUP_ID][LOOKUP_3_AIR_IDS[0]].num_rows; - let trace = Lookup3Trace::new(num_rows); + let air = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_3_AIR_IDS[0]); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + + let mut trace = Lookup3Trace::new(num_rows); + + for i in 0..num_rows { + trace[i].c1 = F::from_canonical_usize(i); + trace[i].d1 = F::from_canonical_usize(i); + if i < (1 << 12) { + trace[i].mul1 = F::from_canonical_usize(4); + } else if i < (1 << 13) { + trace[i].mul1 = F::from_canonical_usize(3); + } else { + trace[i].mul1 = F::from_canonical_usize(2); + } + + trace[i].c2 = F::from_canonical_usize(i); + trace[i].d2 = F::from_canonical_usize(i); + if i < (1 << 12) { + trace[i].mul2 = F::from_canonical_usize(4); + } else if i < (1 << 13) { + trace[i].mul2 = F::from_canonical_usize(3); + } else { + trace[i].mul2 = F::from_canonical_usize(2); + } + } let air_instance = AirInstance::new(sctx.clone(), LOOKUP_AIRGROUP_ID, LOOKUP_3_AIR_IDS[0], None, trace.buffer.unwrap()); @@ -40,50 +70,11 @@ impl Lookup3 { impl WitnessComponent for Lookup3 { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, - pctx: Arc>, + _stage: u32, + _air_instance_id: Option, + _pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let air = pctx.pilout.get_air(air_instance.airgroup_id, air_instance.air_id); - - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage {}", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - stage - ); - - if stage == 1 { - let buffer = &mut air_instance.witness; - - let num_rows = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_3_AIR_IDS[0]).num_rows(); - let mut trace = Lookup3Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - for i in 0..num_rows { - trace[i].c1 = F::from_canonical_usize(i); - trace[i].d1 = F::from_canonical_usize(i); - if i < (1 << 12) { - trace[i].mul1 = F::from_canonical_usize(4); - } else if i < (1 << 13) { - trace[i].mul1 = F::from_canonical_usize(3); - } else { - trace[i].mul1 = F::from_canonical_usize(2); - } - - trace[i].c2 = F::from_canonical_usize(i); - trace[i].d2 = F::from_canonical_usize(i); - if i < (1 << 12) { - trace[i].mul2 = F::from_canonical_usize(4); - } else if i < (1 << 13) { - trace[i].mul2 = F::from_canonical_usize(3); - } else { - trace[i].mul2 = F::from_canonical_usize(2); - } - } - } } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs index fbab5f9e..631b3dfd 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs @@ -27,8 +27,53 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); let num_rows = pctx.global_info.airs[PERMUTATION_AIRGROUP_ID][PERMUTATION_1_6_AIR_IDS[0]].num_rows; - let trace = Permutation1_6Trace::new(num_rows); + let air = pctx.pilout.get_air(PERMUTATION_AIRGROUP_ID, PERMUTATION_1_6_AIR_IDS[0]); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + + let mut trace = Permutation1_6Trace::new(num_rows); + + // TODO: Add the ability to send inputs to permutation2 + // and consequently add random selectors + + // Assumes + for i in 0..num_rows { + trace[i].a1 = rng.gen(); + trace[i].b1 = rng.gen(); + + trace[i].a2 = F::from_canonical_u8(200); + trace[i].b2 = F::from_canonical_u8(201); + + trace[i].a3 = rng.gen(); + trace[i].b3 = rng.gen(); + + trace[i].a4 = F::from_canonical_u8(100); + trace[i].b4 = F::from_canonical_u8(101); + + trace[i].sel1 = F::from_bool(rng.gen_bool(0.5)); + trace[i].sel3 = F::one(); + } + + let mut indices: Vec = (0..num_rows).collect(); + indices.shuffle(&mut rng); + + // Proves + for i in 0..num_rows { + // We take a random permutation of the indices to show that the permutation check is passing + trace[i].c1 = trace[indices[i]].a1; + trace[i].d1 = trace[indices[i]].b1; + + trace[i].c2 = trace[indices[i]].a3; + trace[i].d2 = trace[indices[i]].b3; + + trace[i].sel2 = trace[indices[i]].sel1; + } let air_instance = AirInstance::new( sctx.clone(), @@ -43,7 +88,43 @@ where pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); } - let trace2 = Permutation1_6Trace::new(num_rows); + let mut trace2 = Permutation1_6Trace::new(num_rows); + + // TODO: Add the ability to send inputs to permutation2 + // and consequently add random selectors + + // Assumes + for i in 0..num_rows { + trace2[i].a1 = rng.gen(); + trace2[i].b1 = rng.gen(); + + trace2[i].a2 = F::from_canonical_u8(200); + trace2[i].b2 = F::from_canonical_u8(201); + + trace2[i].a3 = rng.gen(); + trace2[i].b3 = rng.gen(); + + trace2[i].a4 = F::from_canonical_u8(100); + trace2[i].b4 = F::from_canonical_u8(101); + + trace2[i].sel1 = F::from_bool(rng.gen_bool(0.5)); + trace2[i].sel3 = F::one(); + } + + let mut indices2: Vec = (0..num_rows).collect(); + indices2.shuffle(&mut rng); + + // Proves + for i in 0..num_rows { + // We take a random permutation of the indices to show that the permutation check is passing + trace2[i].c1 = trace2[indices2[i]].a1; + trace2[i].d1 = trace2[indices2[i]].b1; + + trace2[i].c2 = trace2[indices2[i]].a3; + trace2[i].d2 = trace2[indices2[i]].b3; + + trace2[i].sel2 = trace2[indices2[i]].sel1; + } let air_instance = AirInstance::new( sctx.clone(), @@ -66,70 +147,11 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, - pctx: Arc>, + _stage: u32, + _air_instance_id: Option, + _pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - - let airgroup_id = air_instance.airgroup_id; - let air_id = air_instance.air_id; - let air = pctx.pilout.get_air(airgroup_id, air_id); - - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage {}", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - stage - ); - - if stage == 1 { - let buffer = &mut air_instance.witness; - let num_rows = pctx.pilout.get_air(air_instance.airgroup_id, air_instance.air_id).num_rows(); - - // I cannot, programatically, link the permutation trace with its air_id - let mut trace = Permutation1_6Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - // TODO: Add the ability to send inputs to permutation2 - // and consequently add random selectors - - // Assumes - for i in 0..num_rows { - trace[i].a1 = rng.gen(); - trace[i].b1 = rng.gen(); - - trace[i].a2 = F::from_canonical_u8(200); - trace[i].b2 = F::from_canonical_u8(201); - - trace[i].a3 = rng.gen(); - trace[i].b3 = rng.gen(); - - trace[i].a4 = F::from_canonical_u8(100); - trace[i].b4 = F::from_canonical_u8(101); - - trace[i].sel1 = F::from_bool(rng.gen_bool(0.5)); - trace[i].sel3 = F::one(); - } - - let mut indices: Vec = (0..num_rows).collect(); - indices.shuffle(&mut rng); - - // Proves - for i in 0..num_rows { - // We take a random permutation of the indices to show that the permutation check is passing - trace[i].c1 = trace[indices[i]].a1; - trace[i].d1 = trace[indices[i]].b1; - - trace[i].c2 = trace[indices[i]].a3; - trace[i].d2 = trace[indices[i]].b3; - - trace[i].sel2 = trace[indices[i]].sel1; - } - } } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs index d1c9cbf3..fe87d9ee 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs @@ -27,8 +27,54 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); let num_rows = pctx.global_info.airs[PERMUTATION_AIRGROUP_ID][PERMUTATION_1_7_AIR_IDS[0]].num_rows; - let trace = Permutation1_7Trace::new(num_rows); + let air = pctx.pilout.get_air(PERMUTATION_AIRGROUP_ID, PERMUTATION_1_7_AIR_IDS[0]); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + + let mut trace = Permutation1_7Trace::new(num_rows); + + // TODO: Add the ability to send inputs to permutation2 + // and consequently add random selectors + + // Assumes + for i in 0..num_rows { + trace[i].a1 = rng.gen(); + trace[i].b1 = rng.gen(); + + trace[i].a2 = F::from_canonical_u8(200); + trace[i].b2 = F::from_canonical_u8(201); + + trace[i].a3 = rng.gen(); + trace[i].b3 = rng.gen(); + + trace[i].a4 = F::from_canonical_u8(100); + trace[i].b4 = F::from_canonical_u8(101); + + trace[i].sel1 = F::one(); + trace[i].sel3 = F::one(); // F::from_canonical_u8(rng.gen_range(0..=1)); + } + + // TODO: Add the permutation of indexes + + // Proves + for i in 0..num_rows { + let index = num_rows - i - 1; + // let mut index = rng.gen_range(0..num_rows); + trace[i].c1 = trace[index].a1; + trace[i].d1 = trace[index].b1; + + // index = rng.gen_range(0..num_rows); + trace[i].c2 = trace[index].a3; + trace[i].d2 = trace[index].b3; + + trace[i].sel2 = trace[i].sel1; + } let air_instance = AirInstance::new( sctx.clone(), @@ -51,71 +97,11 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, - pctx: Arc>, + _stage: u32, + _air_instance_id: Option, + _pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - - let airgroup_id = air_instance.airgroup_id; - let air_id = air_instance.air_id; - let air = pctx.pilout.get_air(airgroup_id, air_id); - - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage {}", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - stage - ); - - if stage == 1 { - let buffer = &mut air_instance.witness; - let num_rows = pctx.pilout.get_air(airgroup_id, air_id).num_rows(); - - // I cannot, programatically, link the permutation trace with its air_id - let mut trace = Permutation1_7Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - // TODO: Add the ability to send inputs to permutation2 - // and consequently add random selectors - - // Assumes - for i in 0..num_rows { - trace[i].a1 = rng.gen(); - trace[i].b1 = rng.gen(); - - trace[i].a2 = F::from_canonical_u8(200); - trace[i].b2 = F::from_canonical_u8(201); - - trace[i].a3 = rng.gen(); - trace[i].b3 = rng.gen(); - - trace[i].a4 = F::from_canonical_u8(100); - trace[i].b4 = F::from_canonical_u8(101); - - trace[i].sel1 = F::one(); - trace[i].sel3 = F::one(); // F::from_canonical_u8(rng.gen_range(0..=1)); - } - - // TODO: Add the permutation of indexes - - // Proves - for i in 0..num_rows { - let index = num_rows - i - 1; - // let mut index = rng.gen_range(0..num_rows); - trace[i].c1 = trace[index].a1; - trace[i].d1 = trace[index].b1; - - // index = rng.gen_range(0..num_rows); - trace[i].c2 = trace[index].a3; - trace[i].d2 = trace[index].b3; - - trace[i].sel2 = trace[i].sel1; - } - } } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs index 6de958cf..e2b50133 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs @@ -27,8 +27,53 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); let num_rows = pctx.global_info.airs[PERMUTATION_AIRGROUP_ID][PERMUTATION_1_8_AIR_IDS[0]].num_rows; - let trace = Permutation1_8Trace::new(num_rows); + let air = pctx.pilout.get_air(PERMUTATION_AIRGROUP_ID, PERMUTATION_1_8_AIR_IDS[0]); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + let mut trace = Permutation1_8Trace::new(num_rows); + + // TODO: Add the ability to send inputs to permutation2 + // and consequently add random selectors + + // Assumes + for i in 0..num_rows { + trace[i].a1 = rng.gen(); + trace[i].b1 = rng.gen(); + + trace[i].a2 = F::from_canonical_u8(200); + trace[i].b2 = F::from_canonical_u8(201); + + trace[i].a3 = rng.gen(); + trace[i].b3 = rng.gen(); + + trace[i].a4 = F::from_canonical_u8(100); + trace[i].b4 = F::from_canonical_u8(101); + + trace[i].sel1 = F::one(); + trace[i].sel3 = F::one(); // F::from_canonical_u8(rng.gen_range(0..=1)); + } + + // TODO: Add the permutation of indexes + + // Proves + for i in 0..num_rows { + let index = num_rows - i - 1; + // let mut index = rng.gen_range(0..num_rows); + trace[i].c1 = trace[index].a1; + trace[i].d1 = trace[index].b1; + + // index = rng.gen_range(0..num_rows); + trace[i].c2 = trace[index].a3; + trace[i].d2 = trace[index].b3; + + trace[i].sel2 = trace[i].sel1; + } let air_instance = AirInstance::new( sctx.clone(), @@ -51,71 +96,11 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, - pctx: Arc>, + _stage: u32, + _air_instance_id: Option, + _pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - - let airgroup_id = air_instance.airgroup_id; - let air_id = air_instance.air_id; - let air = pctx.pilout.get_air(airgroup_id, air_id); - - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage {}", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - stage - ); - - if stage == 1 { - let buffer = &mut air_instance.witness; - let num_rows = pctx.pilout.get_air(airgroup_id, air_id).num_rows(); - - // I cannot, programatically, link the permutation trace with its air_id - let mut trace = Permutation1_8Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - // TODO: Add the ability to send inputs to permutation2 - // and consequently add random selectors - - // Assumes - for i in 0..num_rows { - trace[i].a1 = rng.gen(); - trace[i].b1 = rng.gen(); - - trace[i].a2 = F::from_canonical_u8(200); - trace[i].b2 = F::from_canonical_u8(201); - - trace[i].a3 = rng.gen(); - trace[i].b3 = rng.gen(); - - trace[i].a4 = F::from_canonical_u8(100); - trace[i].b4 = F::from_canonical_u8(101); - - trace[i].sel1 = F::one(); - trace[i].sel3 = F::one(); // F::from_canonical_u8(rng.gen_range(0..=1)); - } - - // TODO: Add the permutation of indexes - - // Proves - for i in 0..num_rows { - let index = num_rows - i - 1; - // let mut index = rng.gen_range(0..num_rows); - trace[i].c1 = trace[index].a1; - trace[i].d1 = trace[index].b1; - - // index = rng.gen_range(0..num_rows); - trace[i].c2 = trace[index].a3; - trace[i].d2 = trace[index].b3; - - trace[i].sel2 = trace[i].sel1; - } - } } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation2.rs b/pil2-components/test/std/permutation/rs/src/permutation2.rs index a7eefcb7..2414d826 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation2.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation2.rs @@ -24,7 +24,29 @@ impl Permutation2 { pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let num_rows = pctx.global_info.airs[PERMUTATION_AIRGROUP_ID][PERMUTATION_2_6_AIR_IDS[0]].num_rows; - let trace = Permutation2_6Trace::new(num_rows); + let air = pctx.pilout.get_air(PERMUTATION_AIRGROUP_ID, PERMUTATION_2_6_AIR_IDS[0]); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + + let mut trace = Permutation2_6Trace::new(num_rows); + + // Note: Here it is assumed that num_rows of permutation2 is equal to + // the sum of num_rows of each variant of permutation1. + // Ohterwise, the permutation check cannot be satisfied. + // Proves + for i in 0..num_rows { + trace[i].c1 = F::from_canonical_u8(200); + trace[i].d1 = F::from_canonical_u8(201); + + trace[i].c2 = F::from_canonical_u8(100); + trace[i].d2 = F::from_canonical_u8(101); + + trace[i].sel = F::from_bool(true); + } let air_instance = AirInstance::new( sctx.clone(), @@ -44,45 +66,11 @@ impl Permutation2 { impl WitnessComponent for Permutation2 { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, - pctx: Arc>, + _stage: u32, + _air_instance_id: Option, + _pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - - let airgroup_id = air_instance.airgroup_id; - let air_id = air_instance.air_id; - let air = pctx.pilout.get_air(airgroup_id, air_id); - - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage {}", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - stage - ); - - if stage == 1 { - let buffer = &mut air_instance.witness; - - let num_rows = pctx.pilout.get_air(airgroup_id, air_id).num_rows(); - let mut trace = Permutation2_6Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - // Note: Here it is assumed that num_rows of permutation2 is equal to - // the sum of num_rows of each variant of permutation1. - // Ohterwise, the permutation check cannot be satisfied. - // Proves - for i in 0..num_rows { - trace[i].c1 = F::from_canonical_u8(200); - trace[i].d1 = F::from_canonical_u8(201); - - trace[i].c2 = F::from_canonical_u8(100); - trace[i].d2 = F::from_canonical_u8(101); - - trace[i].sel = F::from_bool(true); - } - } } } diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs index bd5dd707..2de61e24 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs @@ -36,8 +36,76 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); let num_rows = pctx.global_info.airs[MULTI_RANGE_CHECK_1_AIRGROUP_ID][MULTI_RANGE_CHECK_1_AIR_IDS[0]].num_rows; - let trace = MultiRangeCheck1Trace::new_zeroes(num_rows); + let air = pctx.pilout.get_air(MULTI_RANGE_CHECK_1_AIRGROUP_ID, MULTI_RANGE_CHECK_1_AIR_IDS[0]); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + + let mut trace = MultiRangeCheck1Trace::new_zeroes(num_rows); + + let range1 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 7) - 1), Some(false)); + let range2 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(false)); + let range3 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 6) - 1), Some(false)); + let range4 = self.std_lib.get_range(BigInt::from(1 << 5), BigInt::from((1 << 8) - 1), Some(false)); + let range5 = self.std_lib.get_range(BigInt::from(1 << 8), BigInt::from((1 << 9) - 1), Some(false)); + + for i in 0..num_rows { + let selected1 = rng.gen_bool(0.5); + let range_selector1 = rng.gen_bool(0.5); + trace[i].sel[0] = F::from_bool(selected1); + trace[i].range_sel[0] = F::from_bool(range_selector1); + + let selected2 = rng.gen_bool(0.5); + let range_selector2 = rng.gen_bool(0.5); + trace[i].sel[1] = F::from_bool(selected2); + trace[i].range_sel[1] = F::from_bool(range_selector2); + + let selected3 = rng.gen_bool(0.5); + let range_selector3 = rng.gen_bool(0.5); + trace[i].sel[2] = F::from_bool(selected3); + trace[i].range_sel[2] = F::from_bool(range_selector3); + + if selected1 { + if range_selector1 { + trace[i].a[0] = F::from_canonical_u16(rng.gen_range(0..=(1 << 7) - 1)); + + self.std_lib.range_check(trace[i].a[0], F::one(), range1); + } else { + trace[i].a[0] = F::from_canonical_u16(rng.gen_range(0..=(1 << 8) - 1)); + + self.std_lib.range_check(trace[i].a[0], F::one(), range2); + } + } + + if selected2 { + if range_selector2 { + trace[i].a[1] = F::from_canonical_u16(rng.gen_range(0..=(1 << 7) - 1)); + + self.std_lib.range_check(trace[i].a[1], F::one(), range1); + } else { + trace[i].a[1] = F::from_canonical_u16(rng.gen_range(0..=(1 << 6) - 1)); + + self.std_lib.range_check(trace[i].a[1], F::one(), range3); + } + } + + if selected3 { + if range_selector3 { + trace[i].a[2] = F::from_canonical_u16(rng.gen_range((1 << 5)..=(1 << 8) - 1)); + + self.std_lib.range_check(trace[i].a[2], F::one(), range4); + } else { + trace[i].a[2] = F::from_canonical_u16(rng.gen_range((1 << 8)..=(1 << 9) - 1)); + + self.std_lib.range_check(trace[i].a[2], F::one(), range5); + } + } + } let air_instance = AirInstance::new( sctx.clone(), @@ -60,86 +128,12 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, + _stage: u32, + _air_instance_id: Option, pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - log::debug!("{}: ··· Witness computation for AIR '{}' at stage {}", Self::MY_NAME, "MultiRangeCheck1", stage); - - if stage == 1 { - let proof_ctx = pctx.clone(); - let air_instances_vec = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - - let buffer = &mut air_instance.witness; - let num_rows = - pctx.pilout.get_air(MULTI_RANGE_CHECK_1_AIRGROUP_ID, MULTI_RANGE_CHECK_1_AIR_IDS[0]).num_rows(); - let mut trace = MultiRangeCheck1Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - let range1 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 7) - 1), Some(false)); - let range2 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(false)); - let range3 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 6) - 1), Some(false)); - let range4 = self.std_lib.get_range(BigInt::from(1 << 5), BigInt::from((1 << 8) - 1), Some(false)); - let range5 = self.std_lib.get_range(BigInt::from(1 << 8), BigInt::from((1 << 9) - 1), Some(false)); - - for i in 0..num_rows { - let selected1 = rng.gen_bool(0.5); - let range_selector1 = rng.gen_bool(0.5); - trace[i].sel[0] = F::from_bool(selected1); - trace[i].range_sel[0] = F::from_bool(range_selector1); - - let selected2 = rng.gen_bool(0.5); - let range_selector2 = rng.gen_bool(0.5); - trace[i].sel[1] = F::from_bool(selected2); - trace[i].range_sel[1] = F::from_bool(range_selector2); - - let selected3 = rng.gen_bool(0.5); - let range_selector3 = rng.gen_bool(0.5); - trace[i].sel[2] = F::from_bool(selected3); - trace[i].range_sel[2] = F::from_bool(range_selector3); - - if selected1 { - if range_selector1 { - trace[i].a[0] = F::from_canonical_u16(rng.gen_range(0..=(1 << 7) - 1)); - - self.std_lib.range_check(trace[i].a[0], F::one(), range1); - } else { - trace[i].a[0] = F::from_canonical_u16(rng.gen_range(0..=(1 << 8) - 1)); - - self.std_lib.range_check(trace[i].a[0], F::one(), range2); - } - } - - if selected2 { - if range_selector2 { - trace[i].a[1] = F::from_canonical_u16(rng.gen_range(0..=(1 << 7) - 1)); - - self.std_lib.range_check(trace[i].a[1], F::one(), range1); - } else { - trace[i].a[1] = F::from_canonical_u16(rng.gen_range(0..=(1 << 6) - 1)); - - self.std_lib.range_check(trace[i].a[1], F::one(), range3); - } - } - - if selected3 { - if range_selector3 { - trace[i].a[2] = F::from_canonical_u16(rng.gen_range((1 << 5)..=(1 << 8) - 1)); - - self.std_lib.range_check(trace[i].a[2], F::one(), range4); - } else { - trace[i].a[2] = F::from_canonical_u16(rng.gen_range((1 << 8)..=(1 << 9) - 1)); - - self.std_lib.range_check(trace[i].a[2], F::one(), range5); - } - } - } - } - self.std_lib.unregister_predecessor(pctx, None); } } diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs index 7b44680d..9411c919 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs @@ -36,8 +36,58 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); let num_rows = pctx.global_info.airs[MULTI_RANGE_CHECK_2_AIRGROUP_ID][MULTI_RANGE_CHECK_2_AIR_IDS[0]].num_rows; - let trace = MultiRangeCheck2Trace::new_zeroes(num_rows); + let air = pctx.pilout.get_air(MULTI_RANGE_CHECK_2_AIRGROUP_ID, MULTI_RANGE_CHECK_2_AIR_IDS[0]); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + + let mut trace = MultiRangeCheck2Trace::new_zeroes(num_rows); + + let range1 = self.std_lib.get_range(BigInt::from(1 << 5), BigInt::from((1 << 8) - 1), Some(false)); + let range2 = self.std_lib.get_range(BigInt::from(1 << 8), BigInt::from((1 << 9) - 1), Some(false)); + let range3 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 7) - 1), Some(false)); + let range4 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 4) - 1), Some(false)); + + for i in 0..num_rows { + let selected1 = rng.gen_bool(0.5); + let range_selector1 = rng.gen_bool(0.5); + trace[i].sel[0] = F::from_bool(selected1); + trace[i].range_sel[0] = F::from_bool(range_selector1); + + let selected2 = rng.gen_bool(0.5); + let range_selector2 = rng.gen_bool(0.5); + trace[i].sel[1] = F::from_bool(selected2); + trace[i].range_sel[1] = F::from_bool(range_selector2); + + if selected1 { + if range_selector1 { + trace[i].a[0] = F::from_canonical_u16(rng.gen_range((1 << 5)..=(1 << 8) - 1)); + + self.std_lib.range_check(trace[i].a[0], F::one(), range1); + } else { + trace[i].a[0] = F::from_canonical_u16(rng.gen_range((1 << 8)..=(1 << 9) - 1)); + + self.std_lib.range_check(trace[i].a[0], F::one(), range2); + } + } + + if selected2 { + if range_selector2 { + trace[i].a[1] = F::from_canonical_u16(rng.gen_range(0..=(1 << 7) - 1)); + + self.std_lib.range_check(trace[i].a[1], F::one(), range3); + } else { + trace[i].a[1] = F::from_canonical_u16(rng.gen_range(0..=(1 << 4) - 1)); + + self.std_lib.range_check(trace[i].a[1], F::one(), range4); + } + } + } let air_instance = AirInstance::new( sctx.clone(), @@ -60,68 +110,12 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, + _stage: u32, + _air_instance_id: Option, pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - log::debug!("{}: ··· Witness computation for AIR '{}' at stage {}", Self::MY_NAME, "MultiRangeCheck2", stage); - - if stage == 1 { - let proof_ctx = pctx.clone(); - let air_instances_vec = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let buffer = &mut air_instance.witness; - - let num_rows = - pctx.pilout.get_air(MULTI_RANGE_CHECK_2_AIRGROUP_ID, MULTI_RANGE_CHECK_2_AIR_IDS[0]).num_rows(); - let mut trace = MultiRangeCheck2Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - let range1 = self.std_lib.get_range(BigInt::from(1 << 5), BigInt::from((1 << 8) - 1), Some(false)); - let range2 = self.std_lib.get_range(BigInt::from(1 << 8), BigInt::from((1 << 9) - 1), Some(false)); - let range3 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 7) - 1), Some(false)); - let range4 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 4) - 1), Some(false)); - - for i in 0..num_rows { - let selected1 = rng.gen_bool(0.5); - let range_selector1 = rng.gen_bool(0.5); - trace[i].sel[0] = F::from_bool(selected1); - trace[i].range_sel[0] = F::from_bool(range_selector1); - - let selected2 = rng.gen_bool(0.5); - let range_selector2 = rng.gen_bool(0.5); - trace[i].sel[1] = F::from_bool(selected2); - trace[i].range_sel[1] = F::from_bool(range_selector2); - - if selected1 { - if range_selector1 { - trace[i].a[0] = F::from_canonical_u16(rng.gen_range((1 << 5)..=(1 << 8) - 1)); - - self.std_lib.range_check(trace[i].a[0], F::one(), range1); - } else { - trace[i].a[0] = F::from_canonical_u16(rng.gen_range((1 << 8)..=(1 << 9) - 1)); - - self.std_lib.range_check(trace[i].a[0], F::one(), range2); - } - } - - if selected2 { - if range_selector2 { - trace[i].a[1] = F::from_canonical_u16(rng.gen_range(0..=(1 << 7) - 1)); - - self.std_lib.range_check(trace[i].a[1], F::one(), range3); - } else { - trace[i].a[1] = F::from_canonical_u16(rng.gen_range(0..=(1 << 4) - 1)); - - self.std_lib.range_check(trace[i].a[1], F::one(), range4); - } - } - } - } - self.std_lib.unregister_predecessor(pctx, None); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check1.rs b/pil2-components/test/std/range_check/rs/src/range_check1.rs index 492c95d3..1bfd9f58 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check1.rs @@ -32,8 +32,54 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); let num_rows = pctx.global_info.airs[RANGE_CHECK_1_AIRGROUP_ID][RANGE_CHECK_1_AIR_IDS[0]].num_rows; - let trace = RangeCheck1Trace::new_zeroes(num_rows); + let air = pctx.pilout.get_air(RANGE_CHECK_1_AIRGROUP_ID, RANGE_CHECK_1_AIR_IDS[0]); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + let mut trace = RangeCheck1Trace::new_zeroes(num_rows); + + let range1 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(false)); + let range2 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 4) - 1), Some(false)); + let range3 = self.std_lib.get_range(BigInt::from(60), BigInt::from((1 << 16) - 1), Some(false)); + let range4 = self.std_lib.get_range(BigInt::from(8228), BigInt::from(17400), Some(false)); + + for i in 0..num_rows { + let selected1 = rng.gen_bool(0.5); + trace[i].sel1 = F::from_bool(selected1); + + let selected2 = rng.gen_bool(0.5); + trace[i].sel2 = F::from_bool(selected2); + + let selected3 = rng.gen_bool(0.5); + trace[i].sel3 = F::from_bool(selected3); + + if selected1 { + trace[i].a1 = F::from_canonical_u16(rng.gen_range(0..=(1 << 8) - 1)); + trace[i].a3 = F::from_canonical_u32(rng.gen_range(60..=(1 << 16) - 1)); + + self.std_lib.range_check(trace[i].a1, F::one(), range1); + self.std_lib.range_check(trace[i].a3, F::one(), range3); + } + + if selected2 { + trace[i].a2 = F::from_canonical_u8(rng.gen_range(0..=(1 << 4) - 1)); + trace[i].a4 = F::from_canonical_u16(rng.gen_range(8228..=17400)); + + self.std_lib.range_check(trace[i].a2, F::one(), range2); + self.std_lib.range_check(trace[i].a4, F::one(), range4); + } + + if selected3 { + trace[i].a5 = F::from_canonical_u16(rng.gen_range(0..=(1 << 8) - 1)); + + self.std_lib.range_check(trace[i].a5, F::one(), range1); + } + } let air_instance = AirInstance::new( sctx.clone(), @@ -56,63 +102,12 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, + _stage: u32, + _air_instance_id: Option, pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - log::debug!("{}: ··· Witness computation for AIR '{}' at stage {}", Self::MY_NAME, "RangeCheck1", stage); - - if stage == 1 { - let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let buffer = &mut air_instance.witness; - let num_rows = pctx.pilout.get_air(RANGE_CHECK_1_AIRGROUP_ID, RANGE_CHECK_1_AIR_IDS[0]).num_rows(); - - let mut trace = RangeCheck1Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - let range1 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(false)); - let range2 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 4) - 1), Some(false)); - let range3 = self.std_lib.get_range(BigInt::from(60), BigInt::from((1 << 16) - 1), Some(false)); - let range4 = self.std_lib.get_range(BigInt::from(8228), BigInt::from(17400), Some(false)); - - for i in 0..num_rows { - let selected1 = rng.gen_bool(0.5); - trace[i].sel1 = F::from_bool(selected1); - - let selected2 = rng.gen_bool(0.5); - trace[i].sel2 = F::from_bool(selected2); - - let selected3 = rng.gen_bool(0.5); - trace[i].sel3 = F::from_bool(selected3); - - if selected1 { - trace[i].a1 = F::from_canonical_u16(rng.gen_range(0..=(1 << 8) - 1)); - trace[i].a3 = F::from_canonical_u32(rng.gen_range(60..=(1 << 16) - 1)); - - self.std_lib.range_check(trace[i].a1, F::one(), range1); - self.std_lib.range_check(trace[i].a3, F::one(), range3); - } - - if selected2 { - trace[i].a2 = F::from_canonical_u8(rng.gen_range(0..=(1 << 4) - 1)); - trace[i].a4 = F::from_canonical_u16(rng.gen_range(8228..=17400)); - - self.std_lib.range_check(trace[i].a2, F::one(), range2); - self.std_lib.range_check(trace[i].a4, F::one(), range4); - } - - if selected3 { - trace[i].a5 = F::from_canonical_u16(rng.gen_range(0..=(1 << 8) - 1)); - - self.std_lib.range_check(trace[i].a5, F::one(), range1); - } - } - } - self.std_lib.unregister_predecessor(pctx, None); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check2.rs b/pil2-components/test/std/range_check/rs/src/range_check2.rs index fbe7159a..a405fbf2 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check2.rs @@ -32,8 +32,30 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); let num_rows = pctx.global_info.airs[RANGE_CHECK_2_AIRGROUP_ID][RANGE_CHECK_2_AIR_IDS[0]].num_rows; - let trace = RangeCheck2Trace::new_zeroes(num_rows); + let air = pctx.pilout.get_air(RANGE_CHECK_2_AIRGROUP_ID, RANGE_CHECK_2_AIR_IDS[0]); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + let mut trace = RangeCheck2Trace::new_zeroes(num_rows); + + let range1 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(false)); + let range2 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 9) - 1), Some(false)); + let range3 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 10) - 1), Some(false)); + + for i in 0..num_rows { + trace[i].b1 = F::from_canonical_u16(rng.gen_range(0..=(1 << 8) - 1)); + trace[i].b2 = F::from_canonical_u16(rng.gen_range(0..=(1 << 9) - 1)); + trace[i].b3 = F::from_canonical_u16(rng.gen_range(0..=(1 << 10) - 1)); + + self.std_lib.range_check(trace[i].b1, F::one(), range1); + self.std_lib.range_check(trace[i].b2, F::one(), range2); + self.std_lib.range_check(trace[i].b3, F::one(), range3); + } let air_instance = AirInstance::new( sctx.clone(), @@ -56,39 +78,12 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, + _stage: u32, + _air_instance_id: Option, pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - log::debug!("{}: ··· Witness computation for AIR '{}' at stage {}", Self::MY_NAME, "RangeCheck2", stage); - - if stage == 1 { - let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let buffer = &mut air_instance.witness; - let num_rows = pctx.pilout.get_air(RANGE_CHECK_2_AIRGROUP_ID, RANGE_CHECK_2_AIR_IDS[0]).num_rows(); - - let mut trace = RangeCheck2Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - let range1 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(false)); - let range2 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 9) - 1), Some(false)); - let range3 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 10) - 1), Some(false)); - - for i in 0..num_rows { - trace[i].b1 = F::from_canonical_u16(rng.gen_range(0..=(1 << 8) - 1)); - trace[i].b2 = F::from_canonical_u16(rng.gen_range(0..=(1 << 9) - 1)); - trace[i].b3 = F::from_canonical_u16(rng.gen_range(0..=(1 << 10) - 1)); - - self.std_lib.range_check(trace[i].b1, F::one(), range1); - self.std_lib.range_check(trace[i].b2, F::one(), range2); - self.std_lib.range_check(trace[i].b3, F::one(), range3); - } - } - self.std_lib.unregister_predecessor(pctx, None); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check3.rs b/pil2-components/test/std/range_check/rs/src/range_check3.rs index 27fe7107..4eb0f168 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check3.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check3.rs @@ -32,8 +32,28 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); let num_rows = pctx.global_info.airs[RANGE_CHECK_3_AIRGROUP_ID][RANGE_CHECK_3_AIR_IDS[0]].num_rows; - let trace = RangeCheck3Trace::new_zeroes(num_rows); + let air = pctx.pilout.get_air(RANGE_CHECK_3_AIRGROUP_ID, RANGE_CHECK_3_AIR_IDS[0]); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + + let mut trace = RangeCheck3Trace::new_zeroes(num_rows); + + let range1 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 4) - 1), Some(false)); + let range2 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(false)); + + for i in 0..num_rows { + trace[i].c1 = F::from_canonical_u16(rng.gen_range(0..=(1 << 4) - 1)); + trace[i].c2 = F::from_canonical_u16(rng.gen_range(0..=(1 << 8) - 1)); + + self.std_lib.range_check(trace[i].c1, F::one(), range1); + self.std_lib.range_check(trace[i].c2, F::one(), range2); + } let air_instance = AirInstance::new( sctx.clone(), @@ -56,37 +76,12 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, + _stage: u32, + _air_instance_id: Option, pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - log::debug!("{}: ··· Witness computation for AIR '{}' at stage {}", Self::MY_NAME, "RangeCheck3", stage); - - if stage == 1 { - let proof_ctx = pctx.clone(); - let air_instances_vec = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let buffer = &mut air_instance.witness; - - let num_rows = pctx.pilout.get_air(RANGE_CHECK_3_AIRGROUP_ID, RANGE_CHECK_3_AIR_IDS[0]).num_rows(); - let mut trace = RangeCheck3Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - let range1 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 4) - 1), Some(false)); - let range2 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(false)); - - for i in 0..num_rows { - trace[i].c1 = F::from_canonical_u16(rng.gen_range(0..=(1 << 4) - 1)); - trace[i].c2 = F::from_canonical_u16(rng.gen_range(0..=(1 << 8) - 1)); - - self.std_lib.range_check(trace[i].c1, F::one(), range1); - self.std_lib.range_check(trace[i].c2, F::one(), range2); - } - } - self.std_lib.unregister_predecessor(pctx, None); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check4.rs b/pil2-components/test/std/range_check/rs/src/range_check4.rs index 306e90cd..973e43ed 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check4.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check4.rs @@ -33,8 +33,75 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); let num_rows = pctx.global_info.airs[RANGE_CHECK_4_AIRGROUP_ID][RANGE_CHECK_4_AIR_IDS[0]].num_rows; - let trace = RangeCheck4Trace::new_zeroes(num_rows); + let air = pctx.pilout.get_air(RANGE_CHECK_4_AIRGROUP_ID, RANGE_CHECK_4_AIR_IDS[0]); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + + let mut trace = RangeCheck4Trace::new_zeroes(num_rows); + + let range1 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 16) - 1), Some(true)); + let range2 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(true)); + let range3 = self.std_lib.get_range(BigInt::from(50), BigInt::from((1 << 7) - 1), Some(true)); + let range4 = self.std_lib.get_range(BigInt::from(127), BigInt::from(1 << 8), Some(true)); + let range5 = self.std_lib.get_range(BigInt::from(1), BigInt::from((1 << 16) + 1), Some(true)); + let range6 = self.std_lib.get_range(BigInt::from(127), BigInt::from(1 << 16), Some(true)); + let range7 = self.std_lib.get_range(BigInt::from(-1), BigInt::from(1 << 3), Some(true)); + let range8 = self.std_lib.get_range(BigInt::from(-(1 << 7) + 1), BigInt::from(-50), Some(true)); + let range9 = self.std_lib.get_range(BigInt::from(-(1 << 8) + 1), BigInt::from(-127), Some(true)); + + for i in 0..num_rows { + let selected1 = rng.gen_bool(0.5); + trace[i].sel1 = F::from_bool(selected1); + + // selected1 and selected2 have to be disjoint for the range check to pass + let selected2 = if selected1 { false } else { rng.gen_bool(0.5) }; + trace[i].sel2 = F::from_bool(selected2); + + if selected1 { + trace[i].a1 = F::from_canonical_u32(rng.gen_range(0..=(1 << 16) - 1)); + trace[i].a5 = F::from_canonical_u32(rng.gen_range(127..=(1 << 16))); + let mut a6_val: i128 = rng.gen_range(-1..=2i128.pow(3)); + if a6_val < 0 { + a6_val += F::order().to_i128().unwrap(); + } + trace[i].a6 = F::from_canonical_u64(a6_val as u64); + + self.std_lib.range_check(trace[i].a1, F::one(), range1); + self.std_lib.range_check(trace[i].a5, F::one(), range6); + self.std_lib.range_check(trace[i].a6, F::one(), range7); + } + if selected2 { + trace[i].a1 = F::from_canonical_u16(rng.gen_range(0..=(1 << 8) - 1)); + trace[i].a2 = F::from_canonical_u8(rng.gen_range(50..=(1 << 7) - 1)); + trace[i].a3 = F::from_canonical_u16(rng.gen_range(127..=(1 << 8))); + trace[i].a4 = F::from_canonical_u32(rng.gen_range(1..=(1 << 16) + 1)); + + self.std_lib.range_check(trace[i].a1, F::one(), range2); + self.std_lib.range_check(trace[i].a2, F::one(), range3); + self.std_lib.range_check(trace[i].a3, F::one(), range4); + self.std_lib.range_check(trace[i].a4, F::one(), range5); + } + + let mut a7_val: i128 = rng.gen_range(-(2i128.pow(7)) + 1..=-50); + if a7_val < 0 { + a7_val += F::order().to_i128().unwrap(); + } + trace[i].a7 = F::from_canonical_u64(a7_val as u64); + self.std_lib.range_check(trace[i].a7, F::one(), range8); + + let mut a8_val: i128 = rng.gen_range(-(2i128.pow(8)) + 1..=-127); + if a8_val < 0 { + a8_val += F::order().to_i128().unwrap(); + } + trace[i].a8 = F::from_canonical_u64(a8_val as u64); + self.std_lib.range_check(trace[i].a8, F::one(), range9); + } let air_instance = AirInstance::new( sctx.clone(), @@ -57,84 +124,12 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, + _stage: u32, + _air_instance_id: Option, pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - log::debug!("{}: ··· Witness computation for AIR '{}' at stage {}", Self::MY_NAME, "RangeCheck4", stage); - - if stage == 1 { - let proof_ctx = pctx.clone(); - let air_instances_vec = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let buffer = &mut air_instance.witness; - - let num_rows = pctx.pilout.get_air(RANGE_CHECK_4_AIRGROUP_ID, RANGE_CHECK_4_AIR_IDS[0]).num_rows(); - let mut trace = RangeCheck4Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - let range1 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 16) - 1), Some(true)); - let range2 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(true)); - let range3 = self.std_lib.get_range(BigInt::from(50), BigInt::from((1 << 7) - 1), Some(true)); - let range4 = self.std_lib.get_range(BigInt::from(127), BigInt::from(1 << 8), Some(true)); - let range5 = self.std_lib.get_range(BigInt::from(1), BigInt::from((1 << 16) + 1), Some(true)); - let range6 = self.std_lib.get_range(BigInt::from(127), BigInt::from(1 << 16), Some(true)); - let range7 = self.std_lib.get_range(BigInt::from(-1), BigInt::from(1 << 3), Some(true)); - let range8 = self.std_lib.get_range(BigInt::from(-(1 << 7) + 1), BigInt::from(-50), Some(true)); - let range9 = self.std_lib.get_range(BigInt::from(-(1 << 8) + 1), BigInt::from(-127), Some(true)); - - for i in 0..num_rows { - let selected1 = rng.gen_bool(0.5); - trace[i].sel1 = F::from_bool(selected1); - - // selected1 and selected2 have to be disjoint for the range check to pass - let selected2 = if selected1 { false } else { rng.gen_bool(0.5) }; - trace[i].sel2 = F::from_bool(selected2); - - if selected1 { - trace[i].a1 = F::from_canonical_u32(rng.gen_range(0..=(1 << 16) - 1)); - trace[i].a5 = F::from_canonical_u32(rng.gen_range(127..=(1 << 16))); - let mut a6_val: i128 = rng.gen_range(-1..=2i128.pow(3)); - if a6_val < 0 { - a6_val += F::order().to_i128().unwrap(); - } - trace[i].a6 = F::from_canonical_u64(a6_val as u64); - - self.std_lib.range_check(trace[i].a1, F::one(), range1); - self.std_lib.range_check(trace[i].a5, F::one(), range6); - self.std_lib.range_check(trace[i].a6, F::one(), range7); - } - if selected2 { - trace[i].a1 = F::from_canonical_u16(rng.gen_range(0..=(1 << 8) - 1)); - trace[i].a2 = F::from_canonical_u8(rng.gen_range(50..=(1 << 7) - 1)); - trace[i].a3 = F::from_canonical_u16(rng.gen_range(127..=(1 << 8))); - trace[i].a4 = F::from_canonical_u32(rng.gen_range(1..=(1 << 16) + 1)); - - self.std_lib.range_check(trace[i].a1, F::one(), range2); - self.std_lib.range_check(trace[i].a2, F::one(), range3); - self.std_lib.range_check(trace[i].a3, F::one(), range4); - self.std_lib.range_check(trace[i].a4, F::one(), range5); - } - - let mut a7_val: i128 = rng.gen_range(-(2i128.pow(7)) + 1..=-50); - if a7_val < 0 { - a7_val += F::order().to_i128().unwrap(); - } - trace[i].a7 = F::from_canonical_u64(a7_val as u64); - self.std_lib.range_check(trace[i].a7, F::one(), range8); - - let mut a8_val: i128 = rng.gen_range(-(2i128.pow(8)) + 1..=-127); - if a8_val < 0 { - a8_val += F::order().to_i128().unwrap(); - } - trace[i].a8 = F::from_canonical_u64(a8_val as u64); - self.std_lib.range_check(trace[i].a8, F::one(), range9); - } - } - self.std_lib.unregister_predecessor(pctx, None); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs index fdb59854..8751d7cd 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs @@ -36,9 +36,55 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); let num_rows = pctx.global_info.airs[RANGE_CHECK_DYNAMIC_1_AIRGROUP_ID][RANGE_CHECK_DYNAMIC_1_AIR_IDS[0]].num_rows; - let trace = RangeCheckDynamic1Trace::new_zeroes(num_rows); + let air = pctx.pilout.get_air(RANGE_CHECK_DYNAMIC_1_AIRGROUP_ID, RANGE_CHECK_DYNAMIC_1_AIR_IDS[0]); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + + let mut trace = RangeCheckDynamic1Trace::new_zeroes(num_rows); + + let range7 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 7) - 1), Some(false)); + let range8 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(false)); + let range16 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 16) - 1), Some(false)); + let range17 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 17) - 1), Some(false)); + + for i in 0..num_rows { + let range = rng.gen_range(0..=3); + + match range { + 0 => { + trace[i].sel_7 = F::one(); + trace[i].colu = F::from_canonical_u16(rng.gen_range(0..=(1 << 7) - 1)); + + self.std_lib.range_check(trace[i].colu, F::one(), range7); + } + 1 => { + trace[i].sel_8 = F::one(); + trace[i].colu = F::from_canonical_u16(rng.gen_range(0..=(1 << 8) - 1)); + + self.std_lib.range_check(trace[i].colu, F::one(), range8); + } + 2 => { + trace[i].sel_16 = F::one(); + trace[i].colu = F::from_canonical_u32(rng.gen_range(0..=(1 << 16) - 1)); + + self.std_lib.range_check(trace[i].colu, F::one(), range16); + } + 3 => { + trace[i].sel_17 = F::one(); + trace[i].colu = F::from_canonical_u32(rng.gen_range(0..=(1 << 17) - 1)); + + self.std_lib.range_check(trace[i].colu, F::one(), range17); + } + _ => panic!("Invalid range"), + } + } let air_instance = AirInstance::new( sctx.clone(), @@ -64,64 +110,12 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, + _stage: u32, + _air_instance_id: Option, pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - log::debug!("{}: ··· Witness computation for AIR '{}' at stage {}", Self::MY_NAME, "RangeCheckDynamic1", stage); - - if stage == 1 { - let proof_ctx = pctx.clone(); - let air_instances_vec = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let buffer = &mut air_instance.witness; - - let num_rows = - pctx.pilout.get_air(RANGE_CHECK_DYNAMIC_1_AIRGROUP_ID, RANGE_CHECK_DYNAMIC_1_AIR_IDS[0]).num_rows(); - let mut trace = RangeCheckDynamic1Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - let range7 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 7) - 1), Some(false)); - let range8 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(false)); - let range16 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 16) - 1), Some(false)); - let range17 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 17) - 1), Some(false)); - - for i in 0..num_rows { - let range = rng.gen_range(0..=3); - - match range { - 0 => { - trace[i].sel_7 = F::one(); - trace[i].colu = F::from_canonical_u16(rng.gen_range(0..=(1 << 7) - 1)); - - self.std_lib.range_check(trace[i].colu, F::one(), range7); - } - 1 => { - trace[i].sel_8 = F::one(); - trace[i].colu = F::from_canonical_u16(rng.gen_range(0..=(1 << 8) - 1)); - - self.std_lib.range_check(trace[i].colu, F::one(), range8); - } - 2 => { - trace[i].sel_16 = F::one(); - trace[i].colu = F::from_canonical_u32(rng.gen_range(0..=(1 << 16) - 1)); - - self.std_lib.range_check(trace[i].colu, F::one(), range16); - } - 3 => { - trace[i].sel_17 = F::one(); - trace[i].colu = F::from_canonical_u32(rng.gen_range(0..=(1 << 17) - 1)); - - self.std_lib.range_check(trace[i].colu, F::one(), range17); - } - _ => panic!("Invalid range"), - } - } - } - self.std_lib.unregister_predecessor(pctx, None); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs index df3b6208..c43fa932 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs @@ -37,9 +37,67 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); let num_rows = pctx.global_info.airs[RANGE_CHECK_DYNAMIC_2_AIRGROUP_ID][RANGE_CHECK_DYNAMIC_2_AIR_IDS[0]].num_rows; - let trace = RangeCheckDynamic2Trace::new_zeroes(num_rows); + let air = pctx.pilout.get_air(RANGE_CHECK_DYNAMIC_2_AIRGROUP_ID, RANGE_CHECK_DYNAMIC_2_AIR_IDS[0]); + + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), + ); + + let mut trace = RangeCheckDynamic2Trace::new_zeroes(num_rows); + + let range1 = self.std_lib.get_range(BigInt::from(5225), BigInt::from(29023), Some(false)); + let range2 = self.std_lib.get_range(BigInt::from(-8719), BigInt::from(-7269), Some(false)); + let range3 = self.std_lib.get_range(BigInt::from(-10), BigInt::from(10), Some(false)); + let range4 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(false)); + let range5 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 7) - 1), Some(false)); + + for i in 0..num_rows { + let range = rng.gen_range(0..=4); + + match range { + 0 => { + trace[i].sel_1 = F::one(); + trace[i].colu = F::from_canonical_u16(rng.gen_range(5225..=29023)); + + self.std_lib.range_check(trace[i].colu, F::one(), range1); + } + 1 => { + trace[i].sel_2 = F::one(); + let colu_val = rng.gen_range(-8719..=-7269) + F::order().to_i128().unwrap(); + trace[i].colu = F::from_canonical_u64(colu_val as u64); + + self.std_lib.range_check(trace[i].colu, F::one(), range2); + } + 2 => { + trace[i].sel_3 = F::one(); + let mut colu_val: i128 = rng.gen_range(-10..=10); + if colu_val < 0 { + colu_val += F::order().to_i128().unwrap(); + } + trace[i].colu = F::from_canonical_u64(colu_val as u64); + + self.std_lib.range_check(trace[i].colu, F::one(), range3); + } + 3 => { + trace[i].sel_4 = F::one(); + trace[i].colu = F::from_canonical_u32(rng.gen_range(0..=(1 << 8) - 1)); + + self.std_lib.range_check(trace[i].colu, F::one(), range4); + } + 4 => { + trace[i].sel_5 = F::one(); + trace[i].colu = F::from_canonical_u32(rng.gen_range(0..=(1 << 7) - 1)); + + self.std_lib.range_check(trace[i].colu, F::one(), range5); + } + _ => panic!("Invalid range"), + } + } let air_instance = AirInstance::new( sctx.clone(), @@ -65,76 +123,12 @@ where { fn calculate_witness( &self, - stage: u32, - air_instance_id: Option, + _stage: u32, + _air_instance_id: Option, pctx: Arc>, _ectx: Arc, _sctx: Arc, ) { - let mut rng = rand::thread_rng(); - - log::debug!("{}: ··· Witness computation for AIR '{}' at stage {}", Self::MY_NAME, "RangeCheckDynamic2", stage); - - if stage == 1 { - let proof_ctx = pctx.clone(); - let air_instances_vec = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let buffer = &mut air_instance.witness; - - let num_rows = - pctx.pilout.get_air(RANGE_CHECK_DYNAMIC_2_AIRGROUP_ID, RANGE_CHECK_DYNAMIC_2_AIR_IDS[0]).num_rows(); - let mut trace = RangeCheckDynamic2Trace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); - - let range1 = self.std_lib.get_range(BigInt::from(5225), BigInt::from(29023), Some(false)); - let range2 = self.std_lib.get_range(BigInt::from(-8719), BigInt::from(-7269), Some(false)); - let range3 = self.std_lib.get_range(BigInt::from(-10), BigInt::from(10), Some(false)); - let range4 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(false)); - let range5 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 7) - 1), Some(false)); - - for i in 0..num_rows { - let range = rng.gen_range(0..=4); - - match range { - 0 => { - trace[i].sel_1 = F::one(); - trace[i].colu = F::from_canonical_u16(rng.gen_range(5225..=29023)); - - self.std_lib.range_check(trace[i].colu, F::one(), range1); - } - 1 => { - trace[i].sel_2 = F::one(); - let colu_val = rng.gen_range(-8719..=-7269) + F::order().to_i128().unwrap(); - trace[i].colu = F::from_canonical_u64(colu_val as u64); - - self.std_lib.range_check(trace[i].colu, F::one(), range2); - } - 2 => { - trace[i].sel_3 = F::one(); - let mut colu_val: i128 = rng.gen_range(-10..=10); - if colu_val < 0 { - colu_val += F::order().to_i128().unwrap(); - } - trace[i].colu = F::from_canonical_u64(colu_val as u64); - - self.std_lib.range_check(trace[i].colu, F::one(), range3); - } - 3 => { - trace[i].sel_4 = F::one(); - trace[i].colu = F::from_canonical_u32(rng.gen_range(0..=(1 << 8) - 1)); - - self.std_lib.range_check(trace[i].colu, F::one(), range4); - } - 4 => { - trace[i].sel_5 = F::one(); - trace[i].colu = F::from_canonical_u32(rng.gen_range(0..=(1 << 7) - 1)); - - self.std_lib.range_check(trace[i].colu, F::one(), range5); - } - _ => panic!("Invalid range"), - } - } - } - self.std_lib.unregister_predecessor(pctx, None); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs index c07841bb..62be39e8 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs @@ -37,140 +37,135 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + let mut rng = rand::thread_rng(); let num_rows = pctx.global_info.airs[RANGE_CHECK_MIX_AIRGROUP_ID][RANGE_CHECK_MIX_AIR_IDS[0]].num_rows; - let trace = RangeCheckMixTrace::new_zeroes(num_rows); + let air = pctx.pilout.get_air(RANGE_CHECK_MIX_AIRGROUP_ID, RANGE_CHECK_MIX_AIR_IDS[0]); - let air_instance = AirInstance::new( - sctx.clone(), - RANGE_CHECK_MIX_AIRGROUP_ID, - RANGE_CHECK_MIX_AIR_IDS[0], - None, - trace.buffer.unwrap(), + log::debug!( + "{}: ··· Witness computation for AIR '{}' at stage 1", + Self::MY_NAME, + air.name().unwrap_or("unknown"), ); - let (is_myne, gid) = - ectx.dctx.write().unwrap().add_instance(RANGE_CHECK_MIX_AIRGROUP_ID, RANGE_CHECK_MIX_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } - } -} -impl WitnessComponent for RangeCheckMix -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - stage: u32, - air_instance_id: Option, - pctx: Arc>, - _ectx: Arc, - _sctx: Arc, - ) { - let mut rng = rand::thread_rng(); + let mut trace = RangeCheckMixTrace::new_zeroes(num_rows); - log::debug!("{}: ··· Witness computation for AIR '{}' at stage {}", Self::MY_NAME, "RangeCheckMix", stage); + let range1 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), None); + let range2 = self.std_lib.get_range(BigInt::from(50), BigInt::from((1 << 7) - 1), None); + let range3 = self.std_lib.get_range(BigInt::from(-1), BigInt::from(1 << 3), None); + let range4 = self.std_lib.get_range(BigInt::from(-(1 << 7) + 1), BigInt::from(-50), None); - if stage == 1 { - let proof_ctx = pctx.clone(); - let air_instances_vec = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap(); - let air_instance = &mut air_instances_vec[air_instance_id.unwrap()]; - let buffer = &mut air_instance.witness; + let range5 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 7) - 1), Some(false)); + let range6 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 4) - 1), Some(false)); + let range7 = self.std_lib.get_range(BigInt::from(1 << 5), BigInt::from((1 << 8) - 1), Some(false)); + let range8 = self.std_lib.get_range(BigInt::from(1 << 8), BigInt::from((1 << 9) - 1), Some(false)); - let num_rows = pctx.pilout.get_air(RANGE_CHECK_MIX_AIRGROUP_ID, RANGE_CHECK_MIX_AIR_IDS[0]).num_rows(); - let mut trace = RangeCheckMixTrace::map_buffer(buffer.as_mut_slice(), num_rows, 0).unwrap(); + let range9 = self.std_lib.get_range(BigInt::from(5225), BigInt::from(29023), Some(false)); + // let range10 = self.std_lib.get_range(BigInt::from(-8719), BigInt::from(-7269), Some(false)); + let range11 = self.std_lib.get_range(BigInt::from(-10), BigInt::from(10), Some(false)); - let range1 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), None); - let range2 = self.std_lib.get_range(BigInt::from(50), BigInt::from((1 << 7) - 1), None); - let range3 = self.std_lib.get_range(BigInt::from(-1), BigInt::from(1 << 3), None); - let range4 = self.std_lib.get_range(BigInt::from(-(1 << 7) + 1), BigInt::from(-50), None); + for i in 0..num_rows { + // First interface + trace[i].a[0] = F::from_canonical_u16(rng.gen_range(0..=(1 << 8) - 1)); + self.std_lib.range_check(trace[i].a[0], F::one(), range1); - let range5 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 7) - 1), Some(false)); - let range6 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 4) - 1), Some(false)); - let range7 = self.std_lib.get_range(BigInt::from(1 << 5), BigInt::from((1 << 8) - 1), Some(false)); - let range8 = self.std_lib.get_range(BigInt::from(1 << 8), BigInt::from((1 << 9) - 1), Some(false)); + trace[i].a[1] = F::from_canonical_u8(rng.gen_range(50..=(1 << 7) - 1)); + self.std_lib.range_check(trace[i].a[1], F::one(), range2); - let range9 = self.std_lib.get_range(BigInt::from(5225), BigInt::from(29023), Some(false)); - // let range10 = self.std_lib.get_range(BigInt::from(-8719), BigInt::from(-7269), Some(false)); - let range11 = self.std_lib.get_range(BigInt::from(-10), BigInt::from(10), Some(false)); + let mut a2_val: i128 = rng.gen_range(-1..=2i128.pow(3)); + if a2_val < 0 { + a2_val += F::order().to_i128().unwrap(); + } + trace[i].a[2] = F::from_canonical_u64(a2_val as u64); + self.std_lib.range_check(trace[i].a[2], F::one(), range3); - for i in 0..num_rows { - // First interface - trace[i].a[0] = F::from_canonical_u16(rng.gen_range(0..=(1 << 8) - 1)); - self.std_lib.range_check(trace[i].a[0], F::one(), range1); + let a3_val = rng.gen_range(-(2i128.pow(7)) + 1..=-50) + F::order().to_i128().unwrap(); + trace[i].a[3] = F::from_canonical_u64(a3_val as u64); + self.std_lib.range_check(trace[i].a[3], F::one(), range4); - trace[i].a[1] = F::from_canonical_u8(rng.gen_range(50..=(1 << 7) - 1)); - self.std_lib.range_check(trace[i].a[1], F::one(), range2); + // Second interface + let range_selector1 = rng.gen_bool(0.5); + trace[i].range_sel[0] = F::from_bool(range_selector1); - let mut a2_val: i128 = rng.gen_range(-1..=2i128.pow(3)); - if a2_val < 0 { - a2_val += F::order().to_i128().unwrap(); - } - trace[i].a[2] = F::from_canonical_u64(a2_val as u64); - self.std_lib.range_check(trace[i].a[2], F::one(), range3); + let range_selector2 = rng.gen_bool(0.5); + trace[i].range_sel[1] = F::from_bool(range_selector2); - let a3_val = rng.gen_range(-(2i128.pow(7)) + 1..=-50) + F::order().to_i128().unwrap(); - trace[i].a[3] = F::from_canonical_u64(a3_val as u64); - self.std_lib.range_check(trace[i].a[3], F::one(), range4); + if range_selector1 { + trace[i].b[0] = F::from_canonical_u16(rng.gen_range(0..=(1 << 7) - 1)); - // Second interface - let range_selector1 = rng.gen_bool(0.5); - trace[i].range_sel[0] = F::from_bool(range_selector1); + self.std_lib.range_check(trace[i].b[0], F::one(), range5); + } else { + trace[i].b[0] = F::from_canonical_u16(rng.gen_range(0..=(1 << 4) - 1)); - let range_selector2 = rng.gen_bool(0.5); - trace[i].range_sel[1] = F::from_bool(range_selector2); + self.std_lib.range_check(trace[i].b[0], F::one(), range6); + } - if range_selector1 { - trace[i].b[0] = F::from_canonical_u16(rng.gen_range(0..=(1 << 7) - 1)); + if range_selector2 { + trace[i].b[1] = F::from_canonical_u16(rng.gen_range((1 << 5)..=(1 << 8) - 1)); - self.std_lib.range_check(trace[i].b[0], F::one(), range5); - } else { - trace[i].b[0] = F::from_canonical_u16(rng.gen_range(0..=(1 << 4) - 1)); + self.std_lib.range_check(trace[i].b[1], F::one(), range7); + } else { + trace[i].b[1] = F::from_canonical_u16(rng.gen_range((1 << 8)..=(1 << 9) - 1)); - self.std_lib.range_check(trace[i].b[0], F::one(), range6); - } + self.std_lib.range_check(trace[i].b[1], F::one(), range8); + } - if range_selector2 { - trace[i].b[1] = F::from_canonical_u16(rng.gen_range((1 << 5)..=(1 << 8) - 1)); + // Third interface + let range = rng.gen_range(0..=2); - self.std_lib.range_check(trace[i].b[1], F::one(), range7); - } else { - trace[i].b[1] = F::from_canonical_u16(rng.gen_range((1 << 8)..=(1 << 9) - 1)); + match range { + 0 => { + trace[i].range_sel[2] = F::one(); + trace[i].c[0] = F::from_canonical_u32(rng.gen_range(5225..=29023)); - self.std_lib.range_check(trace[i].b[1], F::one(), range8); + self.std_lib.range_check(trace[i].c[0], F::one(), range9); } - - // Third interface - let range = rng.gen_range(0..=2); - - match range { - 0 => { - trace[i].range_sel[2] = F::one(); - trace[i].c[0] = F::from_canonical_u32(rng.gen_range(5225..=29023)); - - self.std_lib.range_check(trace[i].c[0], F::one(), range9); + 1 => { + trace[i].range_sel[3] = F::one(); + let mut colu_val: i128 = rng.gen_range(-10..=10); + if colu_val < 0 { + colu_val += F::order().to_i128().unwrap(); } - 1 => { - trace[i].range_sel[3] = F::one(); - let mut colu_val: i128 = rng.gen_range(-10..=10); - if colu_val < 0 { - colu_val += F::order().to_i128().unwrap(); - } - trace[i].c[0] = F::from_canonical_u64(colu_val as u64); - - self.std_lib.range_check(trace[i].c[0], F::one(), range11); - } - 2 => { - trace[i].range_sel[4] = F::one(); - trace[i].c[0] = F::from_canonical_u32(rng.gen_range(0..=(1 << 7) - 1)); + trace[i].c[0] = F::from_canonical_u64(colu_val as u64); - self.std_lib.range_check(trace[i].c[0], F::one(), range5); - } - _ => panic!("Invalid range"), + self.std_lib.range_check(trace[i].c[0], F::one(), range11); } + 2 => { + trace[i].range_sel[4] = F::one(); + trace[i].c[0] = F::from_canonical_u32(rng.gen_range(0..=(1 << 7) - 1)); + + self.std_lib.range_check(trace[i].c[0], F::one(), range5); + } + _ => panic!("Invalid range"), } } + let air_instance = AirInstance::new( + sctx.clone(), + RANGE_CHECK_MIX_AIRGROUP_ID, + RANGE_CHECK_MIX_AIR_IDS[0], + None, + trace.buffer.unwrap(), + ); + let (is_myne, gid) = + ectx.dctx.write().unwrap().add_instance(RANGE_CHECK_MIX_AIRGROUP_ID, RANGE_CHECK_MIX_AIR_IDS[0], 1); + if is_myne { + pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); + } + } +} + +impl WitnessComponent for RangeCheckMix +where + Standard: Distribution, +{ + fn calculate_witness( + &self, + _stage: u32, + _air_instance_id: Option, + pctx: Arc>, + _ectx: Arc, + _sctx: Arc, + ) { self.std_lib.unregister_predecessor(pctx, None); } } From 7f04e6d2cadd21ff475b112b199e4eac482588d0 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Thu, 5 Dec 2024 11:43:11 +0000 Subject: [PATCH 13/64] Working on AirInstance improvements --- Cargo.toml | 10 +- book/quickstart.md | 2 +- cli/assets/templates/pil_helpers_mod.rs.tt | 2 - cli/assets/templates/pil_helpers_pilout.rs.tt | 27 ---- cli/assets/templates/pil_helpers_trace.rs.tt | 31 ++++- cli/src/commands/pil_helpers.rs | 9 +- common/src/air_instance.rs | 29 +++- common/src/lib.rs | 2 - common/src/lib_pilout.rs | 124 ------------------ common/src/proof_ctx.rs | 6 +- common/src/setup_ctx.rs | 4 + common/src/trace.rs | 7 +- examples/fibonacci-square/pil/fibonaccisq.pil | 2 +- examples/fibonacci-square/pil/module.pil | 10 +- examples/fibonacci-square/src/fibonacci.rs | 35 ++--- .../fibonacci-square/src/fibonacci_lib.rs | 10 +- examples/fibonacci-square/src/module.rs | 21 +-- .../fibonacci-square/src/pil_helpers/mod.rs | 2 - .../src/pil_helpers/pilout.rs | 33 ----- .../src/pil_helpers/traces.rs | 31 ++++- .../fibonacci-square/src/publics_info.json | 2 +- macros/src/lib.rs | 91 ++++++++----- pil2-components/lib/std/rs/src/decider.rs | 4 +- .../rs/src/range_check/specified_ranges.rs | 8 +- .../std/rs/src/range_check/std_range_check.rs | 33 ++--- .../lib/std/rs/src/range_check/u16air.rs | 8 +- .../lib/std/rs/src/range_check/u8air.rs | 8 +- pil2-components/lib/std/rs/src/std_prod.rs | 37 +++--- pil2-components/lib/std/rs/src/std_sum.rs | 44 +++---- .../test/simple/rs/src/pil_helpers/mod.rs | 2 - .../test/simple/rs/src/pil_helpers/pilout.rs | 30 ----- .../test/simple/rs/src/pil_helpers/traces.rs | 21 ++- .../test/simple/rs/src/simple_left.rs | 19 +-- .../test/simple/rs/src/simple_lib.rs | 8 +- .../test/simple/rs/src/simple_right.rs | 18 +-- .../test/std/connection/rs/src/connection1.rs | 26 +--- .../test/std/connection/rs/src/connection2.rs | 24 +--- .../std/connection/rs/src/connection_lib.rs | 8 +- .../std/connection/rs/src/connection_new.rs | 26 +--- .../std/connection/rs/src/pil_helpers/mod.rs | 2 - .../connection/rs/src/pil_helpers/pilout.rs | 33 ----- .../connection/rs/src/pil_helpers/traces.rs | 27 +++- .../test/std/lookup/rs/src/lookup0.rs | 20 +-- .../test/std/lookup/rs/src/lookup1.rs | 20 +-- .../test/std/lookup/rs/src/lookup2_12.rs | 20 +-- .../test/std/lookup/rs/src/lookup2_13.rs | 21 +-- .../test/std/lookup/rs/src/lookup2_15.rs | 19 +-- .../test/std/lookup/rs/src/lookup3.rs | 20 +-- .../test/std/lookup/rs/src/lookup_lib.rs | 8 +- .../test/std/lookup/rs/src/pil_helpers/mod.rs | 2 - .../std/lookup/rs/src/pil_helpers/pilout.rs | 42 ------ .../std/lookup/rs/src/pil_helpers/traces.rs | 45 +++++-- .../std/permutation/rs/src/permutation1_6.rs | 75 +---------- .../std/permutation/rs/src/permutation1_7.rs | 25 +--- .../std/permutation/rs/src/permutation1_8.rs | 24 +--- .../std/permutation/rs/src/permutation2.rs | 25 +--- .../std/permutation/rs/src/permutation_lib.rs | 8 +- .../std/permutation/rs/src/pil_helpers/mod.rs | 2 - .../permutation/rs/src/pil_helpers/pilout.rs | 36 ----- .../permutation/rs/src/pil_helpers/traces.rs | 33 +++-- .../range_check/rs/src/multi_range_check1.rs | 24 +--- .../range_check/rs/src/multi_range_check2.rs | 24 +--- .../std/range_check/rs/src/pil_helpers/mod.rs | 2 - .../range_check/rs/src/pil_helpers/pilout.rs | 110 ---------------- .../range_check/rs/src/pil_helpers/traces.rs | 101 ++++++++++---- .../std/range_check/rs/src/range_check1.rs | 25 +--- .../std/range_check/rs/src/range_check2.rs | 24 +--- .../std/range_check/rs/src/range_check3.rs | 24 +--- .../std/range_check/rs/src/range_check4.rs | 24 +--- .../rs/src/range_check_dynamic1.rs | 30 +---- .../rs/src/range_check_dynamic2.rs | 30 +---- .../std/range_check/rs/src/range_check_lib.rs | 8 +- .../std/range_check/rs/src/range_check_mix.rs | 24 +--- proofman/src/proofman.rs | 2 +- proofman/src/witness_library.rs | 4 +- 75 files changed, 531 insertions(+), 1246 deletions(-) delete mode 100644 cli/assets/templates/pil_helpers_pilout.rs.tt delete mode 100644 common/src/lib_pilout.rs delete mode 100644 examples/fibonacci-square/src/pil_helpers/pilout.rs delete mode 100644 pil2-components/test/simple/rs/src/pil_helpers/pilout.rs delete mode 100644 pil2-components/test/std/connection/rs/src/pil_helpers/pilout.rs delete mode 100644 pil2-components/test/std/lookup/rs/src/pil_helpers/pilout.rs delete mode 100644 pil2-components/test/std/permutation/rs/src/pil_helpers/pilout.rs delete mode 100644 pil2-components/test/std/range_check/rs/src/pil_helpers/pilout.rs diff --git a/Cargo.toml b/Cargo.toml index 3c798dc6..02a3dd7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,11 +11,11 @@ members = [ "transcript", "util", "pil2-components/lib/std/rs", - #"pil2-components/test/std/range_check/rs", - #"pil2-components/test/std/lookup/rs", - #"pil2-components/test/std/connection/rs", - #"pil2-components/test/std/permutation/rs", - #"pil2-components/test/simple/rs", + # "pil2-components/test/std/range_check/rs", + # "pil2-components/test/std/lookup/rs", + # "pil2-components/test/std/connection/rs", + # "pil2-components/test/std/permutation/rs", + # "pil2-components/test/simple/rs", # whoever re-enables this, it has to work out of # the box with `cargo check --workspace` or CI will # break and dev experience will be bad since repo diff --git a/book/quickstart.md b/book/quickstart.md index fafadee5..d4c04404 100644 --- a/book/quickstart.md +++ b/book/quickstart.md @@ -127,7 +127,7 @@ impl Executor for FibonacciExecutor { let num_rows = proof_ctx.pilout.air_groups[airgroup_id].airs[air_id].num_rows.unwrap() as usize; trace!(Fibonacci { a: Goldilocks, b: Goldilocks }); - let mut fib = Fibonacci::new(num_rows); + let mut fib = Fibonacci::new(); fib.a[0] = Goldilocks::one(); fib.b[0] = Goldilocks::one(); diff --git a/cli/assets/templates/pil_helpers_mod.rs.tt b/cli/assets/templates/pil_helpers_mod.rs.tt index 8273843a..9daf0c06 100644 --- a/cli/assets/templates/pil_helpers_mod.rs.tt +++ b/cli/assets/templates/pil_helpers_mod.rs.tt @@ -1,7 +1,5 @@ // WARNING: This file has been autogenerated from the PILOUT file. // Manual modifications are not recommended and may be overwritten. -mod pilout; mod traces; -pub use pilout::*; pub use traces::*; diff --git a/cli/assets/templates/pil_helpers_pilout.rs.tt b/cli/assets/templates/pil_helpers_pilout.rs.tt deleted file mode 100644 index fb85c143..00000000 --- a/cli/assets/templates/pil_helpers_pilout.rs.tt +++ /dev/null @@ -1,27 +0,0 @@ -// WARNING: This file has been autogenerated from the PILOUT file. -// Manual modifications are not recommended and may be overwritten. -use proofman_common::WitnessPilout; - -pub const PILOUT_HASH: &[u8] = b"{ project_name }-hash"; - -//AIRGROUP CONSTANTS -{{ for constant in constant_airgroups }} -pub const { constant.0 }_AIRGROUP_ID: usize = { constant.1 }; -{{ endfor }} -//AIR CONSTANTS -{{ for constant in constant_airs }} -pub const { constant.0 }_AIR_IDS: &[usize] = &[{ constant.3 }]; -{{ endfor }} -pub struct Pilout; - -impl Pilout \{ - pub fn pilout() -> WitnessPilout \{ - let mut pilout = WitnessPilout::new("{ project_name }", { num_stages }, PILOUT_HASH.to_vec()); -{{ for air_group in air_groups }} - let air_group = pilout.add_air_group(Some("{ air_group.name }")); -{{ for air in air_group.airs }} - air_group.add_air(Some("{ air.name }"), { air.num_rows });{{ endfor }} -{{ endfor }} - pilout - } -} diff --git a/cli/assets/templates/pil_helpers_trace.rs.tt b/cli/assets/templates/pil_helpers_trace.rs.tt index 709e0ebe..3b0d39cd 100644 --- a/cli/assets/templates/pil_helpers_trace.rs.tt +++ b/cli/assets/templates/pil_helpers_trace.rs.tt @@ -2,12 +2,35 @@ // Manual modifications are not recommended and may be overwritten. use proofman_common as common; pub use proofman_macros::trace; +pub use proofman_macros::values; + +pub const PILOUT_HASH: &[u8] = b"{ project_name }-hash"; + +//AIRGROUP CONSTANTS +{{ for constant in constant_airgroups }} +pub const { constant.0 }_AIRGROUP_ID: usize = { constant.1 }; +{{ endfor }} +//AIR CONSTANTS +{{ for constant in constant_airs }} +pub const { constant.0 }_AIR_IDS: &[usize] = &[{ constant.3 }]; +{{ endfor }} + +{{ for public_values in publics }} +values!({ project_name }PublicValues \{ +{{ for column in public_values.values }} { column.name }: { column.type },{{ endfor }} +}); +{{ endfor }} +{{ for proof_vals in proof_values }} +values!({ project_name }ProofValues \{ +{{ for column in proof_vals.values }} { column.name }: { column.type },{{ endfor }} +}); +{{ endfor }} {{ for air_group in air_groups }}{{ for air in air_group.airs }} -trace!({ air.name }Row, { air.name }Trace \{ +trace!({ air.name }Trace \{ {{ for column in air.columns }} { column.name }: { column.type },{{ endfor }} -}); +}, { air_group.airgroup_id }, { air.id }, { air.num_rows } ); {{ endfor }}{{ endfor }}{{ for air_group in air_groups }}{{ for air in air_group.airs }}{{ for custom_commit in air.custom_columns }} -trace!({ air.name }{custom_commit.name}Row, { air.name }{custom_commit.name}Trace \{ +trace!({ air.name }{custom_commit.name}Trace \{ {{ for column in custom_commit.custom_columns }} { column.name }: { column.type },{{ endfor }} -}); +}, { air_group.airgroup_id }, { air.id }, { air.num_rows } ); {{ endfor }}{{ endfor }}{{ endfor }} \ No newline at end of file diff --git a/cli/src/commands/pil_helpers.rs b/cli/src/commands/pil_helpers.rs index 5e0fd0d6..f9e933b5 100644 --- a/cli/src/commands/pil_helpers.rs +++ b/cli/src/commands/pil_helpers.rs @@ -65,6 +65,7 @@ struct ValuesCtx { #[derive(Debug, Serialize)] struct CustomCommitsCtx { name: String, + commit_id: usize, custom_columns: Vec, } #[derive(Debug, Serialize)] @@ -191,8 +192,10 @@ impl PilHelpersCmd { air.custom_columns = pilout.air_groups[airgroup_id].airs[air_id] .custom_commits .iter() - .map(|commit| CustomCommitsCtx { + .enumerate() + .map(|(index, commit)| CustomCommitsCtx { name: commit.name.clone().unwrap().to_case(Case::Pascal), + commit_id: index, custom_columns: Vec::new(), }) .collect(); @@ -261,7 +264,6 @@ impl PilHelpersCmd { let mut tt = TinyTemplate::new(); tt.add_template("mod.rs", MOD_RS)?; - tt.add_template("pilout.rs", include_str!("../../assets/templates/pil_helpers_pilout.rs.tt"))?; tt.add_template("traces.rs", include_str!("../../assets/templates/pil_helpers_trace.rs.tt"))?; // Write the files @@ -269,9 +271,6 @@ impl PilHelpersCmd { // Write mod.rs fs::write(pil_helpers_path.join("mod.rs"), MOD_RS)?; - // Write pilout.rs - fs::write(pil_helpers_path.join("pilout.rs"), tt.render("pilout.rs", &context)?)?; - // Write traces.rs fs::write(pil_helpers_path.join("traces.rs"), tt.render("traces.rs", &context)?)?; diff --git a/common/src/air_instance.rs b/common/src/air_instance.rs index 5aa00b50..1ee101a5 100644 --- a/common/src/air_instance.rs +++ b/common/src/air_instance.rs @@ -4,7 +4,7 @@ use p3_field::Field; use proofman_starks_lib_c::get_custom_commit_map_ids_c; use proofman_util::create_buffer_fast; -use crate::{SetupCtx, StarkInfo}; +use crate::{trace::Trace, ProofCtx, ExecutionCtx, SetupCtx, StarkInfo}; #[repr(C)] pub struct StepsParams { @@ -31,8 +31,8 @@ impl From<&StepsParams> for *mut c_void { impl Default for StepsParams { fn default() -> Self { StepsParams { + witness: ptr::null_mut(), trace: ptr::null_mut(), - pols: ptr::null_mut(), public_inputs: ptr::null_mut(), challenges: ptr::null_mut(), airgroup_values: ptr::null_mut(), @@ -61,6 +61,7 @@ impl CustomCommitsInfo { /// Air instance context for managing air instances (traces) #[allow(dead_code)] #[repr(C)] +#[derive(Clone)] pub struct AirInstance { pub airgroup_id: usize, pub air_id: usize, @@ -85,9 +86,9 @@ pub struct AirInstance { impl AirInstance { pub fn new( setup_ctx: Arc, + air_segment_id: Option, airgroup_id: usize, air_id: usize, - air_segment_id: Option, witness: Vec, ) -> Self { let ps = setup_ctx.get_setup(airgroup_id, air_id); @@ -134,6 +135,28 @@ impl AirInstance { } } + pub fn from_trace( + proof_ctx: Arc>, + execution_ctx: Arc, + setup_ctx: Arc, + air_segment_id: Option, + trace: &mut dyn Trace, + ) -> Self { + let airgroup_id = trace.airgroup_id(); + let air_id = trace.air_id(); + let witness = trace.detach_buffer(); + + let air_instance = AirInstance::new(setup_ctx, air_segment_id, airgroup_id, air_id, witness); + + let (is_mine, gid) = + execution_ctx.dctx.write().unwrap().add_instance(air_instance.airgroup_id, air_instance.air_id, 1); + if is_mine { + proof_ctx.air_instance_repo.add_air_instance(air_instance.clone(), Some(gid)); + } + + air_instance + } + pub fn get_witness_ptr(&self) -> *mut u8 { self.witness.as_ptr() as *mut u8 } diff --git a/common/src/lib.rs b/common/src/lib.rs index 16a82623..26378a65 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -3,7 +3,6 @@ mod air_instances_repository; mod verbose_mode; mod execution_ctx; mod distribution_ctx; -mod lib_pilout; mod proof_ctx; mod prover; mod extended_field; @@ -21,7 +20,6 @@ use proofman_starks_lib_c::set_log_level_c; pub use verbose_mode::*; pub use execution_ctx::*; pub use distribution_ctx::*; -pub use lib_pilout::*; pub use proof_ctx::*; pub use prover::*; pub use extended_field::*; diff --git a/common/src/lib_pilout.rs b/common/src/lib_pilout.rs deleted file mode 100644 index 45943344..00000000 --- a/common/src/lib_pilout.rs +++ /dev/null @@ -1,124 +0,0 @@ -#[derive(Debug)] -pub struct WitnessPilout { - name: String, - hash: Vec, - num_stages: u32, - air_groups: Vec, -} - -impl WitnessPilout { - pub fn new(name: &str, num_stages: u32, hash: Vec) -> Self { - WitnessPilout { name: name.to_string(), num_stages, air_groups: Vec::new(), hash } - } - - pub fn add_air_group(&mut self, air_group_name: Option<&str>) -> &mut AirGroup { - let airgroup_id = self.air_groups.len(); - let air_group = AirGroup::new(airgroup_id, air_group_name); - self.air_groups.push(air_group); - &mut self.air_groups[airgroup_id] - } - - pub fn find_air(&self, airgroup_name: &str, air_name: &str) -> Option<&Air> { - for airgroup in &self.air_groups { - if let Some(name) = &airgroup.name { - if name == airgroup_name { - for air in &airgroup.airs { - if let Some(name) = &air.name { - if name == air_name { - return Some(air); - } - } - } - } - } - } - None - } - - pub fn get_air_group(&self, airgroup_id: usize) -> &AirGroup { - &self.air_groups[airgroup_id] - } - - pub fn get_air(&self, airgroup_id: usize, air_id: usize) -> &Air { - &self.air_groups[airgroup_id].airs[air_id] - } - - pub fn name(&self) -> &str { - &self.name - } - - pub fn hash(&self) -> &[u8] { - &self.hash - } - - pub fn num_stages(&self) -> u32 { - self.num_stages - } - - pub fn air_groups(&self) -> &[AirGroup] { - &self.air_groups - } -} - -#[derive(Debug)] -pub struct AirGroup { - airgroup_id: usize, - name: Option, - airs: Vec, -} - -impl AirGroup { - pub fn new(airgroup_id: usize, name: Option<&str>) -> Self { - AirGroup { airgroup_id, name: name.map(|s| s.to_string()), airs: Vec::new() } - } - - pub fn add_air(&mut self, air_name: Option<&str>, num_rows: usize) -> &Air { - let air_id = self.airs.len(); - let air = Air::new(self.airgroup_id, air_id, air_name, num_rows); - self.airs.push(air); - &self.airs[air_id] - } - - pub fn airgroup_id(&self) -> usize { - self.airgroup_id - } - - pub fn name(&self) -> Option<&str> { - self.name.as_deref() - } - - pub fn airs(&self) -> &[Air] { - &self.airs - } -} - -#[derive(Debug)] -pub struct Air { - pub airgroup_id: usize, - pub air_id: usize, - pub name: Option, - /// log2(n), where n is the number of rows - num_rows: usize, -} - -impl Air { - pub fn new(airgroup_id: usize, air_id: usize, name: Option<&str>, num_rows: usize) -> Self { - Air { airgroup_id, air_id, name: name.map(|s| s.to_string()), num_rows } - } - - pub fn airgroup_id(&self) -> usize { - self.airgroup_id - } - - pub fn air_id(&self) -> usize { - self.air_id - } - - pub fn name(&self) -> Option<&str> { - self.name.as_deref() - } - - pub fn num_rows(&self) -> usize { - self.num_rows - } -} diff --git a/common/src/proof_ctx.rs b/common/src/proof_ctx.rs index e5d5c84b..0560cb06 100644 --- a/common/src/proof_ctx.rs +++ b/common/src/proof_ctx.rs @@ -4,7 +4,7 @@ use std::path::PathBuf; use p3_field::Field; -use crate::{AirInstancesRepository, GlobalInfo, StdMode, VerboseMode, WitnessPilout}; +use crate::{AirInstancesRepository, GlobalInfo, StdMode, VerboseMode}; pub struct PublicInputs { pub inputs: RwLock>, @@ -79,7 +79,6 @@ impl ProofOptions { #[allow(dead_code)] pub struct ProofCtx { - pub pilout: WitnessPilout, pub public_inputs: PublicInputs, pub proof_values: ProofValues, pub challenges: Challenges, @@ -91,7 +90,7 @@ pub struct ProofCtx { impl ProofCtx { const MY_NAME: &'static str = "ProofCtx"; - pub fn create_ctx(pilout: WitnessPilout, proving_key_path: PathBuf) -> Self { + pub fn create_ctx(proving_key_path: PathBuf) -> Self { log::info!("{}: Creating proof context", Self::MY_NAME); let global_info: GlobalInfo = GlobalInfo::new(&proving_key_path); @@ -102,7 +101,6 @@ impl ProofCtx { }; let n_publics = global_info.n_publics; Self { - pilout, global_info, public_inputs: PublicInputs::new(n_publics), proof_values, diff --git a/common/src/setup_ctx.rs b/common/src/setup_ctx.rs index 7db99ccb..16fc6110 100644 --- a/common/src/setup_ctx.rs +++ b/common/src/setup_ctx.rs @@ -153,6 +153,10 @@ impl SetupCtx { } } + pub fn get_setups_list(&self) -> Vec<(usize, usize)> { + self.setup_repository.setups.keys().cloned().collect() + } + pub fn get_global_bin(&self) -> *mut c_void { self.setup_repository.global_bin.unwrap() } diff --git a/common/src/trace.rs b/common/src/trace.rs index 1ca6e89a..c57ebdea 100644 --- a/common/src/trace.rs +++ b/common/src/trace.rs @@ -1,5 +1,10 @@ -pub trait Trace: Send { +use p3_field::Field; + +pub trait Trace: Send { fn num_rows(&self) -> usize; + fn airgroup_id(&self) -> usize; + fn air_id(&self) -> usize; + fn detach_buffer(&mut self) -> Vec; fn get_buffer_ptr(&mut self) -> *mut u8; } diff --git a/examples/fibonacci-square/pil/fibonaccisq.pil b/examples/fibonacci-square/pil/fibonaccisq.pil index bceefe6b..781cd13d 100644 --- a/examples/fibonacci-square/pil/fibonaccisq.pil +++ b/examples/fibonacci-square/pil/fibonaccisq.pil @@ -11,7 +11,7 @@ proofval value2; private function checkProofValues() { - mod * value1 - value2 === 0; + module * value1 - value2 === 0; std_alpha - std_alpha === 0; } diff --git a/examples/fibonacci-square/pil/module.pil b/examples/fibonacci-square/pil/module.pil index b4de0c2d..31ec3986 100644 --- a/examples/fibonacci-square/pil/module.pil +++ b/examples/fibonacci-square/pil/module.pil @@ -2,18 +2,18 @@ require "std_range_check.pil"; const int MODULE_ID = 1; -public mod; +public module; airtemplate Module(const int N = 2**8) { col fixed LN = [0...,1]; col witness x, q, x_mod; - x === q * mod + x_mod; + x === q * module + x_mod; - // Ensure that 0 <= x_mod < mod < PRIME <--> 0 < mod - x_mod <--> mod - x_mod <= mod - range_check(mod - x_mod, 1, 2**8-1); - // NOTE: The 2**8-1 is used for simplicity. Moreover, for the shake of security, mod should be limited to 2**8-1 by the verifier + // Ensure that 0 <= x_mod < module < PRIME <--> 0 < module - x_mod <--> module - x_mod <= module + range_check(module - x_mod, 1, 2**8-1); + // NOTE: The 2**8-1 is used for simplicity. Moreover, for the shake of security, module should be limited to 2**8-1 by the verifier permutation_proves(MODULE_ID, [x, x_mod], 1 - LN); } \ No newline at end of file diff --git a/examples/fibonacci-square/src/fibonacci.rs b/examples/fibonacci-square/src/fibonacci.rs index 1b24c536..8711b142 100644 --- a/examples/fibonacci-square/src/fibonacci.rs +++ b/examples/fibonacci-square/src/fibonacci.rs @@ -23,35 +23,29 @@ impl FibonacciSquare { } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { - // TODO: We should create the instance here and fill the trace in calculate witness!!! - if let Err(e) = - Self::calculate_trace(self, FIBONACCI_SQUARE_AIRGROUP_ID, FIBONACCI_SQUARE_AIR_IDS[0], pctx, ectx, sctx) - { + if let Err(e) = Self::calculate_trace(self, pctx, ectx, sctx) { panic!("Failed to calculate fibonacci: {:?}", e); } } fn calculate_trace( &self, - airgroup_id: usize, - air_id: usize, pctx: Arc>, ectx: Arc, sctx: Arc, ) -> Result> { log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); - let module = pctx.get_public_value("mod"); + let module = pctx.get_public_value("module"); let mut a = pctx.get_public_value("in1"); let mut b = pctx.get_public_value("in2"); - let num_rows = pctx.global_info.airs[airgroup_id][air_id].num_rows; - let mut trace = FibonacciSquareTrace::new_zeroes(num_rows); + let mut trace = FibonacciSquareTrace::new_zeroes(); trace[0].a = F::from_canonical_u64(a); trace[0].b = F::from_canonical_u64(b); - for i in 1..num_rows { + for i in 1..trace.num_rows() { let tmp = b; let result = self.module.calculate_module(a.pow(2) + b.pow(2), module); (a, b) = (tmp, result); @@ -60,10 +54,10 @@ impl FibonacciSquare { trace[i].b = F::from_canonical_u64(b); } - let mut trace_rom = FibonacciSquareRomTrace::new_zeroes(num_rows); + let mut trace_rom = FibonacciSquareRomTrace::new_zeroes(); let commit_id = get_custom_commit_id(&sctx, FIBONACCI_SQUARE_AIRGROUP_ID, FIBONACCI_SQUARE_AIR_IDS[0], "rom"); - for i in 0..num_rows { + for i in 0..trace.num_rows() { trace_rom[i].line = F::from_canonical_u64(3 + i as u64); trace_rom[i].flags = F::from_canonical_u64(2 + i as u64); } @@ -73,24 +67,13 @@ impl FibonacciSquare { pctx.set_proof_value("value1", F::from_canonical_u64(5)); pctx.set_proof_value("value2", F::from_canonical_u64(125)); - let mut air_instance = AirInstance::new( - sctx.clone(), - FIBONACCI_SQUARE_AIRGROUP_ID, - FIBONACCI_SQUARE_AIR_IDS[0], - Some(0), - trace.buffer.unwrap(), - ); + let mut air_instance = AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), Some(0), &mut trace); + air_instance.set_airvalue("FibonacciSquare.fibo1", Some(vec![0]), F::from_canonical_u64(1)); air_instance.set_airvalue("FibonacciSquare.fibo1", Some(vec![1]), F::from_canonical_u64(2)); air_instance.set_airvalue_ext("FibonacciSquare.fibo3", None, vec![F::from_canonical_u64(5); 3]); - air_instance.set_custom_commit_id_buffer(&sctx, trace_rom.buffer.unwrap(), commit_id); - - let (is_myne, gid) = - ectx.dctx.write().unwrap().add_instance(FIBONACCI_SQUARE_AIRGROUP_ID, FIBONACCI_SQUARE_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + air_instance.set_custom_commit_id_buffer(&sctx, trace_rom.detach_buffer(), commit_id); Ok(b) } diff --git a/examples/fibonacci-square/src/fibonacci_lib.rs b/examples/fibonacci-square/src/fibonacci_lib.rs index 3804edb6..f210712a 100644 --- a/examples/fibonacci-square/src/fibonacci_lib.rs +++ b/examples/fibonacci-square/src/fibonacci_lib.rs @@ -1,7 +1,7 @@ use std::io::Read; use std::{fs::File, sync::Arc}; -use proofman_common::{initialize_logger, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode, WitnessPilout}; +use proofman_common::{initialize_logger, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode}; use proofman::{WitnessLibrary, WitnessManager}; use pil_std_lib::Std; use p3_field::PrimeField; @@ -11,7 +11,7 @@ use std::error::Error; use std::path::PathBuf; use crate::FibonacciSquarePublics; -use crate::{FibonacciSquare, Pilout, Module}; +use crate::{FibonacciSquare, Module}; pub struct FibonacciWitness { public_inputs_path: Option, @@ -57,7 +57,7 @@ impl WitnessLibrary for FibonacciWitness { FibonacciSquarePublics::default() }; - pctx.set_public_value_by_name(public_inputs.module, "mod", None); + pctx.set_public_value_by_name(public_inputs.module, "module", None); pctx.set_public_value_by_name(public_inputs.a, "in1", None); pctx.set_public_value_by_name(public_inputs.b, "in2", None); @@ -76,10 +76,6 @@ impl WitnessLibrary for FibonacciWitness { fn calculate_witness(&mut self, stage: u32, pctx: Arc>, ectx: Arc, sctx: Arc) { self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, ectx, sctx); } - - fn pilout(&self) -> WitnessPilout { - Pilout::pilout() - } } #[no_mangle] diff --git a/examples/fibonacci-square/src/module.rs b/examples/fibonacci-square/src/module.rs index d58abe4a..b31e71a9 100644 --- a/examples/fibonacci-square/src/module.rs +++ b/examples/fibonacci-square/src/module.rs @@ -44,10 +44,9 @@ impl Module fn calculate_trace(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); - let module = pctx.get_public_value("mod"); + let module = pctx.get_public_value("module"); - let num_rows = pctx.global_info.airs[FIBONACCI_SQUARE_AIRGROUP_ID][MODULE_AIR_IDS[0]].num_rows; - let mut trace = ModuleTrace::new_zeroes(num_rows); + let mut trace = ModuleTrace::new_zeroes(); //range_check(colu: mod - x_mod, min: 1, max: 2**8-1); let range = self.std_lib.get_range(BigInt::from(1), BigInt::from((1 << 8) - 1), None); @@ -68,23 +67,11 @@ impl Module } // Trivial range check for the remaining rows - for _ in inputs.len()..num_rows { + for _ in inputs.len()..trace.num_rows() { self.std_lib.range_check(F::from_canonical_u64(module), F::one(), range); } - let air_instance = AirInstance::new( - sctx.clone(), - FIBONACCI_SQUARE_AIRGROUP_ID, - MODULE_AIR_IDS[0], - Some(0), - trace.buffer.unwrap(), - ); - - let (is_myne, gid) = - ectx.dctx.write().unwrap().add_instance(FIBONACCI_SQUARE_AIRGROUP_ID, MODULE_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), Some(0), &mut trace); self.std_lib.unregister_predecessor(pctx, None); } diff --git a/examples/fibonacci-square/src/pil_helpers/mod.rs b/examples/fibonacci-square/src/pil_helpers/mod.rs index 8273843a..9daf0c06 100644 --- a/examples/fibonacci-square/src/pil_helpers/mod.rs +++ b/examples/fibonacci-square/src/pil_helpers/mod.rs @@ -1,7 +1,5 @@ // WARNING: This file has been autogenerated from the PILOUT file. // Manual modifications are not recommended and may be overwritten. -mod pilout; mod traces; -pub use pilout::*; pub use traces::*; diff --git a/examples/fibonacci-square/src/pil_helpers/pilout.rs b/examples/fibonacci-square/src/pil_helpers/pilout.rs deleted file mode 100644 index 9ed22685..00000000 --- a/examples/fibonacci-square/src/pil_helpers/pilout.rs +++ /dev/null @@ -1,33 +0,0 @@ -// WARNING: This file has been autogenerated from the PILOUT file. -// Manual modifications are not recommended and may be overwritten. -use proofman_common::WitnessPilout; - -pub const PILOUT_HASH: &[u8] = b"Build-hash"; - -//AIRGROUP CONSTANTS - -pub const FIBONACCI_SQUARE_AIRGROUP_ID: usize = 0; - -//AIR CONSTANTS - -pub const FIBONACCI_SQUARE_AIR_IDS: &[usize] = &[0]; - -pub const MODULE_AIR_IDS: &[usize] = &[1]; - -pub const U_8_AIR_AIR_IDS: &[usize] = &[2]; - -pub struct Pilout; - -impl Pilout { - pub fn pilout() -> WitnessPilout { - let mut pilout = WitnessPilout::new("Build", 2, PILOUT_HASH.to_vec()); - - let air_group = pilout.add_air_group(Some("FibonacciSquare")); - - air_group.add_air(Some("FibonacciSquare"), 1024); - air_group.add_air(Some("Module"), 1024); - air_group.add_air(Some("U8Air"), 256); - - pilout - } -} diff --git a/examples/fibonacci-square/src/pil_helpers/traces.rs b/examples/fibonacci-square/src/pil_helpers/traces.rs index 3dea50ba..2224dd0b 100644 --- a/examples/fibonacci-square/src/pil_helpers/traces.rs +++ b/examples/fibonacci-square/src/pil_helpers/traces.rs @@ -2,19 +2,42 @@ // Manual modifications are not recommended and may be overwritten. use proofman_common as common; pub use proofman_macros::trace; +pub use proofman_macros::values; + +pub const PILOUT_HASH: &[u8] = b"Build-hash"; + +//AIRGROUP CONSTANTS + +pub const FIBONACCI_SQUARE_AIRGROUP_ID: usize = 0; + +//AIR CONSTANTS + +pub const FIBONACCI_SQUARE_AIR_IDS: &[usize] = &[0]; + +pub const MODULE_AIR_IDS: &[usize] = &[1]; + +pub const U_8_AIR_AIR_IDS: &[usize] = &[2]; + +values!(BuildPublicValues { + module: F, in1: F, in2: F, out: F, rom_root: [F; 4], +}); + +values!(BuildProofValues { + value1: F, value2: F, +}); trace!(FibonacciSquareTrace { a: F, b: F, -}, 1024); +}, 0, 0, 1024 ); trace!(ModuleTrace { x: F, q: F, x_mod: F, -}, 1024); +}, 0, 1, 1024 ); trace!(U8AirTrace { mul: F, -}, 256); +}, 0, 2, 256 ); trace!(FibonacciSquareRomTrace { line: F, flags: F, -}, 1024); +}, 0, 0, 1024 ); diff --git a/examples/fibonacci-square/src/publics_info.json b/examples/fibonacci-square/src/publics_info.json index 381d3491..4534ac9a 100644 --- a/examples/fibonacci-square/src/publics_info.json +++ b/examples/fibonacci-square/src/publics_info.json @@ -1,7 +1,7 @@ { "nPublics": 8, "definitions": [ - { "name": "mod", "initialPos": 0, "chunks": [1, 64] }, + { "name": "module", "initialPos": 0, "chunks": [1, 64] }, { "name": "in1", "initialPos": 1, "chunks": [1, 64] }, { "name": "in2", "initialPos": 2, "chunks": [1, 64] }, { "name": "out", "initialPos": 3, "chunks": [1, 64] }, diff --git a/macros/src/lib.rs b/macros/src/lib.rs index f90a0900..4814850a 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -21,6 +21,8 @@ fn trace_impl(input: TokenStream2) -> Result { let trace_struct_name = parsed_input.struct_name; let generics = parsed_input.generics.params; let fields = parsed_input.fields; + let airgroup_id = parsed_input.airgroup_id; + let air_id = parsed_input.air_id; let num_rows = parsed_input.num_rows; // let commit_id = parsed_input.commit_id; @@ -65,11 +67,15 @@ fn trace_impl(input: TokenStream2) -> Result { pub struct #trace_struct_name<#generics> { pub buffer: Vec<#row_struct_name<#generics>>, pub num_rows: usize, + pub airgroup_id: usize, + pub air_id: usize, // pub commit_id: Option, } impl<#generics: Default + Clone + Copy> #trace_struct_name<#generics> { const NUM_ROWS: usize = #num_rows; + const AIRGROUP_ID: usize = #airgroup_id; + const AIR_ID: usize = #air_id; pub fn new() -> Self { let num_rows = Self::NUM_ROWS; @@ -81,37 +87,12 @@ fn trace_impl(input: TokenStream2) -> Result { buff_uninit.set_len(num_rows); } let buffer: Vec<#row_struct_name<#generics>> = unsafe { std::mem::transmute(buff_uninit) }; - let slice_trace = unsafe { - std::slice::from_raw_parts_mut( - buffer.as_ptr() as *mut #row_struct_name<#generics>, - num_rows, - ) - }; - - #trace_struct_name { - buffer: Some(buffer), - slice_trace, - num_rows, - } - } - - pub fn new_zeroes(num_rows: usize) -> Self { - assert!(num_rows >= 2); - assert!(num_rows & (num_rows - 1) == 0); - - let buffer = vec![#generics::default(); num_rows * #row_struct_name::<#generics>::ROW_SIZE]; - let slice_trace = unsafe { - std::slice::from_raw_parts_mut( - buffer.as_ptr() as *mut #row_struct_name<#generics>, - num_rows, - ) - }; ->>>>>>> adba4fd1 (Renaming, improving logs, cleaning) #trace_struct_name { buffer, num_rows, - // commit_id: #commit_id + airgroup_id: Self::AIRGROUP_ID, + air_id: Self::AIR_ID, } } @@ -121,17 +102,32 @@ fn trace_impl(input: TokenStream2) -> Result { assert!(num_rows & (num_rows - 1) == 0); let buffer = vec![#row_struct_name::<#generics>::default(); num_rows]; - + #trace_struct_name { buffer, num_rows, - // commit_id: #commit_id + airgroup_id: Self::AIRGROUP_ID, + air_id: Self::AIR_ID, } } pub fn num_rows(&self) -> usize { self.num_rows } + + pub fn airgroup_id(&self) -> usize { + self.airgroup_id + } + + pub fn air_id(&self) -> usize { + self.air_id + } + + pub fn detach_buffer(&mut self) -> Vec<#generics> { + let buffer = std::mem::take(&mut self.buffer); + let buffer: Vec<#generics> = unsafe { std::mem::transmute(buffer) }; + buffer + } } impl<#generics> std::ops::Index for #trace_struct_name<#generics> { @@ -148,11 +144,25 @@ fn trace_impl(input: TokenStream2) -> Result { } } - impl<#generics: Send> common::trace::Trace for #trace_struct_name<#generics> { + impl<#generics: Send + p3_field::Field> common::trace::Trace<#generics> for #trace_struct_name<#generics> { fn num_rows(&self) -> usize { self.num_rows } + fn airgroup_id(&self) -> usize { + self.airgroup_id + } + + fn air_id(&self) -> usize { + self.air_id + } + + fn detach_buffer(&mut self) -> Vec<#generics> { + let buffer = std::mem::take(&mut self.buffer); + let buffer: Vec<#generics> = unsafe { std::mem::transmute(buffer) }; + buffer + } + fn get_buffer_ptr(&mut self) -> *mut u8 { self.buffer.as_mut_ptr() as *mut u8 } @@ -171,6 +181,8 @@ struct ParsedTraceInput { struct_name: Ident, generics: Generics, fields: FieldsNamed, + airgroup_id: LitInt, + air_id: LitInt, num_rows: LitInt, // commit_id: Option, } @@ -194,8 +206,15 @@ impl Parse for ParsedTraceInput { let generics: Generics = input.parse()?; let fields: FieldsNamed = input.parse()?; + input.parse::()?; + let airgroup_id = input.parse::()?; + + input.parse::()?; + let air_id = input.parse::()?; + input.parse::()?; let num_rows = input.parse::()?; + // let commit_id: Option = if input.peek(Token![,]) { // input.parse::()?; // Some(input.parse()?) @@ -203,7 +222,15 @@ impl Parse for ParsedTraceInput { // None // }; - Ok(ParsedTraceInput { row_struct_name, struct_name, generics, fields, num_rows /*, commit_id */ }) + Ok(ParsedTraceInput { + row_struct_name, + struct_name, + generics, + fields, + airgroup_id, + air_id, + num_rows, /*, commit_id */ + }) } } @@ -264,7 +291,7 @@ fn values_impl(input: TokenStream2) -> Result { impl<#generic_param: Copy> #struct_name<#generic_param> { pub const ROW_SIZE: usize = #row_size; - + pub fn as_slice(&self) -> &[#generic_param] { unsafe { std::slice::from_raw_parts( diff --git a/pil2-components/lib/std/rs/src/decider.rs b/pil2-components/lib/std/rs/src/decider.rs index 7b5bd441..0dbadaf8 100644 --- a/pil2-components/lib/std/rs/src/decider.rs +++ b/pil2-components/lib/std/rs/src/decider.rs @@ -1,7 +1,7 @@ use std::sync::Arc; -use proofman_common::{ProofCtx, SetupCtx}; +use proofman_common::SetupCtx; pub trait Decider { - fn decide(&self, sctx: Arc, pctx: Arc>); + fn decide(&self, sctx: Arc); } diff --git a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs index 426b05e0..04abb0c2 100644 --- a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs +++ b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs @@ -103,7 +103,7 @@ impl SpecifiedRanges { let mut dctx: std::sync::RwLockWriteGuard<'_, proofman_common::DistributionCtx> = ectx.dctx.write().unwrap(); - let (is_myne, global_idx) = dctx.add_instance(self.airgroup_id, self.air_id, 1); + let (is_mine, global_idx) = dctx.add_instance(self.airgroup_id, self.air_id, 1); let mut multiplicities = self .mul_columns @@ -121,7 +121,7 @@ impl SpecifiedRanges { dctx.distribute_multiplicities(&mut multiplicities, owner); - if is_myne { + if is_mine { // Set the multiplicity columns as done let hints = self.hints.lock().unwrap(); @@ -133,7 +133,7 @@ impl SpecifiedRanges { let num_rows = pctx.global_info.airs[self.airgroup_id][self.air_id].num_rows; let buffer_size = multiplicities.len() * num_rows; let buffer: Vec = create_buffer_fast(buffer_size); - let air_instance = AirInstance::new(sctx.clone(), self.airgroup_id, self.air_id, None, buffer); + let air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer); pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)); pctx.air_instance_repo.air_instances.read().unwrap().len() - 1 }; @@ -295,7 +295,7 @@ impl WitnessComponent for SpecifiedRanges { let buffer = create_buffer_fast(buffer_size as usize); // Add a new air instance. Since Specified Ranges is a table, only this air instance is needed - let mut air_instance = AirInstance::new(sctx.clone(), self.airgroup_id, self.air_id, None, buffer); + let mut air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer); let mut mul_columns_guard = self.mul_columns.lock().unwrap(); for hint in hints_guard[1..].iter() { mul_columns_guard.push(get_hint_field::( diff --git a/pil2-components/lib/std/rs/src/range_check/std_range_check.rs b/pil2-components/lib/std/rs/src/range_check/std_range_check.rs index 0b7a5c9b..8d3e7e52 100644 --- a/pil2-components/lib/std/rs/src/range_check/std_range_check.rs +++ b/pil2-components/lib/std/rs/src/range_check/std_range_check.rs @@ -47,25 +47,18 @@ pub struct StdRangeCheck { } impl Decider for StdRangeCheck { - fn decide(&self, sctx: Arc, pctx: Arc>) { + fn decide(&self, sctx: Arc) { // Scan the pilout for airs that have rc-related hints - let air_groups = pctx.pilout.air_groups(); - - air_groups.iter().for_each(|air_group| { - let airs = air_group.airs(); - airs.iter().for_each(|air| { - let airgroup_id = air.airgroup_id; - let air_id = air.air_id; - let setup = sctx.get_setup(airgroup_id, air_id); - - // Obtain info from the range hints - let rc_hints = get_hint_ids_by_name(setup.p_setup.p_expressions_bin, "range_def"); - for hint in rc_hints { - // Register the range - self.register_range(sctx.clone(), airgroup_id, air_id, hint); - } - }); - }); + for (airgroup_id, air_id) in sctx.get_setups_list() { + let setup = sctx.get_setup(airgroup_id, air_id); + + // Obtain info from the range hints + let rc_hints = get_hint_ids_by_name(setup.p_setup.p_expressions_bin, "range_def"); + for hint in rc_hints { + // Register the range + self.register_range(sctx.clone(), airgroup_id, air_id, hint); + } + } } } @@ -267,8 +260,8 @@ impl StdRangeCheck { } impl WitnessComponent for StdRangeCheck { - fn start_proof(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { - self.decide(sctx, pctx); + fn start_proof(&self, _pctx: Arc>, _ectx: Arc, sctx: Arc) { + self.decide(sctx); } fn calculate_witness( diff --git a/pil2-components/lib/std/rs/src/range_check/u16air.rs b/pil2-components/lib/std/rs/src/range_check/u16air.rs index 1a7c2f6a..464861b0 100644 --- a/pil2-components/lib/std/rs/src/range_check/u16air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u16air.rs @@ -96,7 +96,7 @@ impl U16Air { let mut dctx: std::sync::RwLockWriteGuard<'_, proofman_common::DistributionCtx> = ectx.dctx.write().unwrap(); - let (is_myne, global_idx) = dctx.add_instance(self.airgroup_id, self.air_id, 1); + let (is_mine, global_idx) = dctx.add_instance(self.airgroup_id, self.air_id, 1); let mut multiplicity = match &*self.mul_column.lock().unwrap() { HintFieldValue::Column(values) => { values.iter().map(|x| x.as_canonical_biguint().to_u64().unwrap()).collect::>() @@ -107,7 +107,7 @@ impl U16Air { let owner = dctx.owner(global_idx); dctx.distribute_multiplicity(&mut multiplicity, owner); - if is_myne { + if is_mine { let air_instance_repo = &self.wcm.get_pctx().air_instance_repo; let instance: Vec = air_instance_repo.find_air_instances(self.airgroup_id, self.air_id); let air_instance_id = if !instance.is_empty() { @@ -117,7 +117,7 @@ impl U16Air { let num_rows = pctx.global_info.airs[self.airgroup_id][self.air_id].num_rows; let buffer_size = num_rows; let buffer: Vec = create_buffer_fast(buffer_size); - let air_instance = AirInstance::new(sctx.clone(), self.airgroup_id, self.air_id, None, buffer); + let air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer); pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)); pctx.air_instance_repo.air_instances.read().unwrap().len() - 1 }; @@ -170,7 +170,7 @@ impl WitnessComponent for U16Air { let buffer = create_buffer_fast(buffer_size); // Add a new air instance. Since U16Air is a table, only this air instance is needed - let mut air_instance = AirInstance::new(sctx.clone(), self.airgroup_id, self.air_id, None, buffer); + let mut air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer); *self.mul_column.lock().unwrap() = get_hint_field::( &self.wcm.get_sctx(), diff --git a/pil2-components/lib/std/rs/src/range_check/u8air.rs b/pil2-components/lib/std/rs/src/range_check/u8air.rs index ebb4fd2d..c3e2632f 100644 --- a/pil2-components/lib/std/rs/src/range_check/u8air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u8air.rs @@ -95,7 +95,7 @@ impl U8Air { let mut dctx: std::sync::RwLockWriteGuard<'_, proofman_common::DistributionCtx> = ectx.dctx.write().unwrap(); - let (is_myne, global_idx) = dctx.add_instance(self.airgroup_id, self.air_id, 1); + let (is_mine, global_idx) = dctx.add_instance(self.airgroup_id, self.air_id, 1); let mut multiplicity = match &*self.mul_column.lock().unwrap() { HintFieldValue::Column(values) => { values.iter().map(|x| x.as_canonical_biguint().to_u64().unwrap()).collect::>() @@ -106,7 +106,7 @@ impl U8Air { let owner = dctx.owner(global_idx); dctx.distribute_multiplicity(&mut multiplicity, owner); - if is_myne { + if is_mine { let air_instance_repo = &self.wcm.get_pctx().air_instance_repo; let instance: Vec = air_instance_repo.find_air_instances(self.airgroup_id, self.air_id); let air_instance_id = if !instance.is_empty() { @@ -115,7 +115,7 @@ impl U8Air { let num_rows = pctx.global_info.airs[self.airgroup_id][self.air_id].num_rows; let buffer_size = num_rows; let buffer: Vec = create_buffer_fast(buffer_size); - let air_instance = AirInstance::new(sctx.clone(), self.airgroup_id, self.air_id, None, buffer); + let air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer); pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)); pctx.air_instance_repo.air_instances.read().unwrap().len() - 1 }; @@ -167,7 +167,7 @@ impl WitnessComponent for U8Air { let buffer = create_buffer_fast(buffer_size); // Add a new air instance. Since U8Air is a table, only this air instance is needed - let mut air_instance = AirInstance::new(sctx.clone(), self.airgroup_id, self.air_id, None, buffer); + let mut air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer); *self.mul_column.lock().unwrap() = get_hint_field::( &sctx, diff --git a/pil2-components/lib/std/rs/src/std_prod.rs b/pil2-components/lib/std/rs/src/std_prod.rs index fcd43a84..0d9bb101 100644 --- a/pil2-components/lib/std/rs/src/std_prod.rs +++ b/pil2-components/lib/std/rs/src/std_prod.rs @@ -24,22 +24,18 @@ pub struct StdProd { } impl Decider for StdProd { - fn decide(&self, sctx: Arc, pctx: Arc>) { + fn decide(&self, sctx: Arc) { // Scan the pilout for airs that have prod-related hints - for airgroup in pctx.pilout.air_groups() { - for air in airgroup.airs() { - let airgroup_id = air.airgroup_id; - let air_id = air.air_id; - - let setup = sctx.get_setup(airgroup_id, air_id); - let p_expressions_bin = setup.p_setup.p_expressions_bin; - - let gprod_hints = get_hint_ids_by_name(p_expressions_bin, "gprod_col"); - let debug_hints_data = get_hint_ids_by_name(p_expressions_bin, "gprod_member_data"); - if !gprod_hints.is_empty() { - // Save the air for latter witness computation - self.prod_airs.lock().unwrap().push((airgroup_id, air_id, gprod_hints, debug_hints_data)); - } + + for (airgroup_id, air_id) in sctx.get_setups_list() { + let setup = sctx.get_setup(airgroup_id, air_id); + let p_expressions_bin = setup.p_setup.p_expressions_bin; + + let gprod_hints = get_hint_ids_by_name(p_expressions_bin, "gprod_col"); + let debug_hints_data = get_hint_ids_by_name(p_expressions_bin, "gprod_member_data"); + if !gprod_hints.is_empty() { + // Save the air for latter witness computation + self.prod_airs.lock().unwrap().push((airgroup_id, air_id, gprod_hints, debug_hints_data)); } } } @@ -249,8 +245,8 @@ impl StdProd { } impl WitnessComponent for StdProd { - fn start_proof(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { - self.decide(sctx, pctx); + fn start_proof(&self, _pctx: Arc>, _ectx: Arc, sctx: Arc) { + self.decide(sctx); } fn calculate_witness( @@ -274,12 +270,11 @@ impl WitnessComponent for StdProd { // Get the air associated with the air_instance let airgroup_id = air_instance.airgroup_id; let air_id = air_instance.air_id; - let air = pctx.pilout.get_air(airgroup_id, air_id); - let air_name = air.name().unwrap_or("unknown"); + let air_name = &pctx.global_info.airs[airgroup_id][air_id].name; log::debug!("{}: ··· Computing witness for AIR '{}' at stage {}", Self::MY_NAME, air_name, stage); - let num_rows = air.num_rows(); + let num_rows = pctx.global_info.airs[airgroup_id][air_id].num_rows; if self.mode.name == ModeName::Debug { self.debug(&pctx, &sctx, air_instance, num_rows, debug_hints_data.clone()); @@ -287,7 +282,7 @@ impl WitnessComponent for StdProd { // We know that at most one product hint exists let gprod_hint = if gprod_hints.len() > 1 { - panic!("Multiple product hints found for AIR '{}'", air.name().unwrap_or("unknown")); + panic!("Multiple product hints found for AIR '{}'", air_name); } else { gprod_hints[0] as usize }; diff --git a/pil2-components/lib/std/rs/src/std_sum.rs b/pil2-components/lib/std/rs/src/std_sum.rs index 7ddf5cfa..f74eacf0 100644 --- a/pil2-components/lib/std/rs/src/std_sum.rs +++ b/pil2-components/lib/std/rs/src/std_sum.rs @@ -24,28 +24,21 @@ pub struct StdSum { } impl Decider for StdSum { - fn decide(&self, sctx: Arc, pctx: Arc>) { + fn decide(&self, sctx: Arc) { // Scan the pilout for airs that have sum-related hints - let air_groups = pctx.pilout.air_groups(); let mut sum_airs_guard = self.sum_airs.lock().unwrap(); - air_groups.iter().for_each(|air_group| { - let airs = air_group.airs(); - airs.iter().for_each(|air| { - let airgroup_id = air.airgroup_id; - let air_id = air.air_id; - - let setup = sctx.get_setup(airgroup_id, air_id); - let p_expressions_bin = setup.p_setup.p_expressions_bin; - - let im_hints = get_hint_ids_by_name(p_expressions_bin, "im_col"); - let gsum_hints = get_hint_ids_by_name(p_expressions_bin, "gsum_col"); - let debug_hints_data = get_hint_ids_by_name(p_expressions_bin, "gsum_member_data"); - if !gsum_hints.is_empty() { - // Save the air for latter witness computation - sum_airs_guard.push((airgroup_id, air_id, im_hints, gsum_hints, debug_hints_data)); - } - }); - }); + for (airgroup_id, air_id) in sctx.get_setups_list() { + let setup = sctx.get_setup(airgroup_id, air_id); + let p_expressions_bin = setup.p_setup.p_expressions_bin; + + let im_hints = get_hint_ids_by_name(p_expressions_bin, "im_col"); + let gsum_hints = get_hint_ids_by_name(p_expressions_bin, "gsum_col"); + let debug_hints_data = get_hint_ids_by_name(p_expressions_bin, "gsum_member_data"); + if !gsum_hints.is_empty() { + // Save the air for latter witness computation + sum_airs_guard.push((airgroup_id, air_id, im_hints, gsum_hints, debug_hints_data)); + } + } } } @@ -249,8 +242,8 @@ impl StdSum { } impl WitnessComponent for StdSum { - fn start_proof(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { - self.decide(sctx, pctx); + fn start_proof(&self, _pctx: Arc>, _ectx: Arc, sctx: Arc) { + self.decide(sctx); } fn calculate_witness( @@ -275,12 +268,11 @@ impl WitnessComponent for StdSum { // Get the air associated with the air_instance let airgroup_id = air_instance.airgroup_id; let air_id = air_instance.air_id; - let air = pctx.pilout.get_air(airgroup_id, air_id); - let air_name = air.name().unwrap_or("unknown"); + let air_name = &pctx.global_info.airs[airgroup_id][air_id].name; log::debug!("{}: ··· Computing witness for AIR '{}' at stage {}", Self::MY_NAME, air_name, stage); - let num_rows = air.num_rows(); + let num_rows = pctx.global_info.airs[airgroup_id][air_id].num_rows; if self.mode.name == ModeName::Debug { self.debug(&pctx, &sctx, air_instance, num_rows, debug_hints_data.clone()); @@ -305,7 +297,7 @@ impl WitnessComponent for StdSum { // We know that at most one product hint exists let gsum_hint = if gsum_hints.len() > 1 { - panic!("Multiple product hints found for AIR '{}'", air.name().unwrap_or("unknown")); + panic!("Multiple product hints found for AIR '{}'", air_name); } else { gsum_hints[0] as usize }; diff --git a/pil2-components/test/simple/rs/src/pil_helpers/mod.rs b/pil2-components/test/simple/rs/src/pil_helpers/mod.rs index 8273843a..9daf0c06 100644 --- a/pil2-components/test/simple/rs/src/pil_helpers/mod.rs +++ b/pil2-components/test/simple/rs/src/pil_helpers/mod.rs @@ -1,7 +1,5 @@ // WARNING: This file has been autogenerated from the PILOUT file. // Manual modifications are not recommended and may be overwritten. -mod pilout; mod traces; -pub use pilout::*; pub use traces::*; diff --git a/pil2-components/test/simple/rs/src/pil_helpers/pilout.rs b/pil2-components/test/simple/rs/src/pil_helpers/pilout.rs deleted file mode 100644 index 9de28165..00000000 --- a/pil2-components/test/simple/rs/src/pil_helpers/pilout.rs +++ /dev/null @@ -1,30 +0,0 @@ -// WARNING: This file has been autogenerated from the PILOUT file. -// Manual modifications are not recommended and may be overwritten. -use proofman_common::WitnessPilout; - -pub const PILOUT_HASH: &[u8] = b"Build-hash"; - -//AIRGROUP CONSTANTS - -pub const SIMPLE_AIRGROUP_ID: usize = 0; - -//AIR CONSTANTS - -pub const SIMPLE_LEFT_AIR_IDS: &[usize] = &[0]; - -pub const SIMPLE_RIGHT_AIR_IDS: &[usize] = &[1]; - -pub struct Pilout; - -impl Pilout { - pub fn pilout() -> WitnessPilout { - let mut pilout = WitnessPilout::new("Build", 2, PILOUT_HASH.to_vec()); - - let air_group = pilout.add_air_group(Some("Simple")); - - air_group.add_air(Some("SimpleLeft"), 4); - air_group.add_air(Some("SimpleRight"), 4); - - pilout - } -} diff --git a/pil2-components/test/simple/rs/src/pil_helpers/traces.rs b/pil2-components/test/simple/rs/src/pil_helpers/traces.rs index 8795d8ae..e7fd6467 100644 --- a/pil2-components/test/simple/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/simple/rs/src/pil_helpers/traces.rs @@ -2,11 +2,24 @@ // Manual modifications are not recommended and may be overwritten. use proofman_common as common; pub use proofman_macros::trace; +pub use proofman_macros::values; -trace!(SimpleLeftRow, SimpleLeftTrace { +pub const PILOUT_HASH: &[u8] = b"Build-hash"; + +//AIRGROUP CONSTANTS + +pub const SIMPLE_AIRGROUP_ID: usize = 0; + +//AIR CONSTANTS + +pub const SIMPLE_LEFT_AIR_IDS: &[usize] = &[0]; + +pub const SIMPLE_RIGHT_AIR_IDS: &[usize] = &[1]; + +trace!(SimpleLeftTrace { a: F, b: F, c: F, d: F, e: F, f: F, g: F, h: F, -}); +}, 0, 0, 4 ); -trace!(SimpleRightRow, SimpleRightTrace { +trace!(SimpleRightTrace { a: F, b: F, c: F, d: F, mul: F, -}); +}, 0, 1, 4 ); diff --git a/pil2-components/test/simple/rs/src/simple_left.rs b/pil2-components/test/simple/rs/src/simple_left.rs index 34939e5c..77002940 100644 --- a/pil2-components/test/simple/rs/src/simple_left.rs +++ b/pil2-components/test/simple/rs/src/simple_left.rs @@ -29,15 +29,10 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = pctx.global_info.airs[SIMPLE_AIRGROUP_ID][SIMPLE_LEFT_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(SIMPLE_AIRGROUP_ID, SIMPLE_LEFT_AIR_IDS[0]); - let mut trace = SimpleLeftTrace::new(num_rows); + let mut trace = SimpleLeftTrace::new(); + let num_rows = trace.num_rows(); - log::debug!( - "{}: ··· Computing witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); // Assumes for i in 0..num_rows { @@ -61,13 +56,7 @@ where trace[i].d = trace[indices[i]].b; } - let air_instance = - AirInstance::new(sctx.clone(), SIMPLE_AIRGROUP_ID, SIMPLE_LEFT_AIR_IDS[0], None, trace.buffer.unwrap()); - - let (is_myne, gid) = ectx.dctx.write().unwrap().add_instance(SIMPLE_AIRGROUP_ID, SIMPLE_LEFT_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/simple/rs/src/simple_lib.rs b/pil2-components/test/simple/rs/src/simple_lib.rs index 69ecb24e..a15f5ff3 100644 --- a/pil2-components/test/simple/rs/src/simple_lib.rs +++ b/pil2-components/test/simple/rs/src/simple_lib.rs @@ -2,13 +2,13 @@ use std::{error::Error, path::PathBuf, sync::Arc}; use pil_std_lib::Std; use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode, WitnessPilout}; +use proofman_common::{initialize_logger, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode}; use p3_field::PrimeField; use p3_goldilocks::Goldilocks; use rand::{distributions::Standard, prelude::Distribution}; -use crate::{Pilout, SimpleLeft, SimpleRight}; +use crate::{SimpleLeft, SimpleRight}; pub struct SimpleWitness { pub wcm: Option>>, @@ -71,10 +71,6 @@ where fn calculate_witness(&mut self, stage: u32, pctx: Arc>, ectx: Arc, sctx: Arc) { self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, ectx, sctx); } - - fn pilout(&self) -> WitnessPilout { - Pilout::pilout() - } } #[no_mangle] diff --git a/pil2-components/test/simple/rs/src/simple_right.rs b/pil2-components/test/simple/rs/src/simple_right.rs index d7b2fdab..77e3c5c7 100644 --- a/pil2-components/test/simple/rs/src/simple_right.rs +++ b/pil2-components/test/simple/rs/src/simple_right.rs @@ -27,15 +27,10 @@ where } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { - let num_rows = pctx.global_info.airs[SIMPLE_AIRGROUP_ID][SIMPLE_RIGHT_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(SIMPLE_AIRGROUP_ID, SIMPLE_RIGHT_AIR_IDS[0]); - let mut trace = SimpleRightTrace::new(num_rows); + let mut trace = SimpleRightTrace::new(); + let num_rows = trace.num_rows(); - log::debug!( - "{}: ··· Computing witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); // Proves for i in 0..num_rows { @@ -48,12 +43,7 @@ where trace[i].mul = F::from_canonical_usize(1); } - let air_instance = - AirInstance::new(sctx.clone(), SIMPLE_AIRGROUP_ID, SIMPLE_RIGHT_AIR_IDS[0], None, trace.buffer.unwrap()); - let (is_myne, gid) = ectx.dctx.write().unwrap().add_instance(SIMPLE_AIRGROUP_ID, SIMPLE_RIGHT_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/connection/rs/src/connection1.rs b/pil2-components/test/std/connection/rs/src/connection1.rs index 901ad33e..c1269411 100644 --- a/pil2-components/test/std/connection/rs/src/connection1.rs +++ b/pil2-components/test/std/connection/rs/src/connection1.rs @@ -29,17 +29,10 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - // For simplicity, add a single instance of each air - let num_rows = pctx.global_info.airs[CONNECTION_AIRGROUP_ID][CONNECTION_1_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(CONNECTION_AIRGROUP_ID, CONNECTION_1_AIR_IDS[0]); + let mut trace = Connection1Trace::new_zeroes(); + let num_rows = trace.num_rows(); - let mut trace = Connection1Trace::new_zeroes(num_rows); - - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); for i in 0..num_rows { trace[i].a = rng.gen(); @@ -47,18 +40,7 @@ where trace[i].c = rng.gen(); } - let air_instance = AirInstance::new( - sctx.clone(), - CONNECTION_AIRGROUP_ID, - CONNECTION_1_AIR_IDS[0], - None, - trace.buffer.unwrap(), - ); - let (is_myne, gid) = - ectx.dctx.write().unwrap().add_instance(CONNECTION_AIRGROUP_ID, CONNECTION_1_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/connection/rs/src/connection2.rs b/pil2-components/test/std/connection/rs/src/connection2.rs index 30192ed0..79f5521f 100644 --- a/pil2-components/test/std/connection/rs/src/connection2.rs +++ b/pil2-components/test/std/connection/rs/src/connection2.rs @@ -29,15 +29,10 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = pctx.global_info.airs[CONNECTION_AIRGROUP_ID][CONNECTION_2_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(CONNECTION_AIRGROUP_ID, CONNECTION_2_AIR_IDS[0]); - let mut trace = Connection2Trace::new_zeroes(num_rows); + let mut trace = Connection2Trace::new_zeroes(); + let num_rows = trace.num_rows(); - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); for i in 0..num_rows { trace[i].a = rng.gen(); @@ -47,18 +42,7 @@ where trace[0].a = trace[1].a; - let air_instance = AirInstance::new( - sctx.clone(), - CONNECTION_AIRGROUP_ID, - CONNECTION_2_AIR_IDS[0], - None, - trace.buffer.unwrap(), - ); - let (is_myne, gid) = - ectx.dctx.write().unwrap().add_instance(CONNECTION_AIRGROUP_ID, CONNECTION_2_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/connection/rs/src/connection_lib.rs b/pil2-components/test/std/connection/rs/src/connection_lib.rs index 0b601a02..943e8727 100644 --- a/pil2-components/test/std/connection/rs/src/connection_lib.rs +++ b/pil2-components/test/std/connection/rs/src/connection_lib.rs @@ -2,13 +2,13 @@ use std::{error::Error, path::PathBuf, sync::Arc}; use pil_std_lib::Std; use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode, WitnessPilout}; +use proofman_common::{initialize_logger, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode}; use p3_field::PrimeField; use p3_goldilocks::Goldilocks; use rand::{distributions::Standard, prelude::Distribution}; -use crate::{Connection1, Connection2, ConnectionNew, Pilout}; +use crate::{Connection1, Connection2, ConnectionNew}; pub struct ConnectionWitness { pub wcm: Option>>, @@ -75,10 +75,6 @@ where fn calculate_witness(&mut self, stage: u32, pctx: Arc>, ectx: Arc, sctx: Arc) { self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, ectx, sctx); } - - fn pilout(&self) -> WitnessPilout { - Pilout::pilout() - } } #[no_mangle] diff --git a/pil2-components/test/std/connection/rs/src/connection_new.rs b/pil2-components/test/std/connection/rs/src/connection_new.rs index 004743b8..3e734d4a 100644 --- a/pil2-components/test/std/connection/rs/src/connection_new.rs +++ b/pil2-components/test/std/connection/rs/src/connection_new.rs @@ -28,16 +28,10 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = pctx.global_info.airs[CONNECTION_AIRGROUP_ID][CONNECTION_NEW_AIR_IDS[0]].num_rows; - let mut trace = ConnectionNewTrace::new_zeroes(num_rows); + let mut trace = ConnectionNewTrace::new_zeroes(); + let num_rows = trace.num_rows(); - let air = pctx.pilout.get_air(CONNECTION_AIRGROUP_ID, CONNECTION_NEW_AIR_IDS[0]); - - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let mut frame = [0; 6]; let mut conn_len = [0; 6]; @@ -139,19 +133,7 @@ where } } - let air_instance = AirInstance::new( - sctx.clone(), - CONNECTION_AIRGROUP_ID, - CONNECTION_NEW_AIR_IDS[0], - None, - trace.buffer.unwrap(), - ); - - let (is_myne, gid) = - ectx.dctx.write().unwrap().add_instance(CONNECTION_AIRGROUP_ID, CONNECTION_NEW_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/connection/rs/src/pil_helpers/mod.rs b/pil2-components/test/std/connection/rs/src/pil_helpers/mod.rs index 8273843a..9daf0c06 100644 --- a/pil2-components/test/std/connection/rs/src/pil_helpers/mod.rs +++ b/pil2-components/test/std/connection/rs/src/pil_helpers/mod.rs @@ -1,7 +1,5 @@ // WARNING: This file has been autogenerated from the PILOUT file. // Manual modifications are not recommended and may be overwritten. -mod pilout; mod traces; -pub use pilout::*; pub use traces::*; diff --git a/pil2-components/test/std/connection/rs/src/pil_helpers/pilout.rs b/pil2-components/test/std/connection/rs/src/pil_helpers/pilout.rs deleted file mode 100644 index 7e43c745..00000000 --- a/pil2-components/test/std/connection/rs/src/pil_helpers/pilout.rs +++ /dev/null @@ -1,33 +0,0 @@ -// WARNING: This file has been autogenerated from the PILOUT file. -// Manual modifications are not recommended and may be overwritten. -use proofman_common::WitnessPilout; - -pub const PILOUT_HASH: &[u8] = b"Build-hash"; - -//AIRGROUP CONSTANTS - -pub const CONNECTION_AIRGROUP_ID: usize = 0; - -//AIR CONSTANTS - -pub const CONNECTION_1_AIR_IDS: &[usize] = &[0]; - -pub const CONNECTION_2_AIR_IDS: &[usize] = &[1]; - -pub const CONNECTION_NEW_AIR_IDS: &[usize] = &[2]; - -pub struct Pilout; - -impl Pilout { - pub fn pilout() -> WitnessPilout { - let mut pilout = WitnessPilout::new("Build", 2, PILOUT_HASH.to_vec()); - - let air_group = pilout.add_air_group(Some("Connection")); - - air_group.add_air(Some("Connection1"), 8); - air_group.add_air(Some("Connection2"), 16); - air_group.add_air(Some("ConnectionNew"), 16); - - pilout - } -} diff --git a/pil2-components/test/std/connection/rs/src/pil_helpers/traces.rs b/pil2-components/test/std/connection/rs/src/pil_helpers/traces.rs index 1f7bf5dc..08fde45e 100644 --- a/pil2-components/test/std/connection/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/std/connection/rs/src/pil_helpers/traces.rs @@ -2,15 +2,30 @@ // Manual modifications are not recommended and may be overwritten. use proofman_common as common; pub use proofman_macros::trace; +pub use proofman_macros::values; -trace!(Connection1Row, Connection1Trace { +pub const PILOUT_HASH: &[u8] = b"Build-hash"; + +//AIRGROUP CONSTANTS + +pub const CONNECTION_AIRGROUP_ID: usize = 0; + +//AIR CONSTANTS + +pub const CONNECTION_1_AIR_IDS: &[usize] = &[0]; + +pub const CONNECTION_2_AIR_IDS: &[usize] = &[1]; + +pub const CONNECTION_NEW_AIR_IDS: &[usize] = &[2]; + +trace!(Connection1Trace { a: F, b: F, c: F, -}); +}, 0, 0, 8 ); -trace!(Connection2Row, Connection2Trace { +trace!(Connection2Trace { a: F, b: F, c: F, -}); +}, 0, 1, 16 ); -trace!(ConnectionNewRow, ConnectionNewTrace { +trace!(ConnectionNewTrace { a: [F; 6], b: [F; 6], c: [F; 6], d: [F; 6], -}); +}, 0, 2, 16 ); diff --git a/pil2-components/test/std/lookup/rs/src/lookup0.rs b/pil2-components/test/std/lookup/rs/src/lookup0.rs index fb71a2fe..15801a7c 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup0.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup0.rs @@ -29,16 +29,10 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = pctx.global_info.airs[LOOKUP_AIRGROUP_ID][LOOKUP_0_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_0_AIR_IDS[0]); + let mut trace = Lookup0Trace::new(); + let num_rows = trace.num_rows(); - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); - - let mut trace = Lookup0Trace::new(num_rows); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let num_lookups = trace[0].sel.len(); @@ -59,13 +53,7 @@ where } } - let air_instance = - AirInstance::new(sctx.clone(), LOOKUP_AIRGROUP_ID, LOOKUP_0_AIR_IDS[0], None, trace.buffer.unwrap()); - - let (is_myne, gid) = ectx.dctx.write().unwrap().add_instance(LOOKUP_AIRGROUP_ID, LOOKUP_0_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup1.rs b/pil2-components/test/std/lookup/rs/src/lookup1.rs index 47dbd960..42021f4d 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup1.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup1.rs @@ -29,16 +29,10 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = pctx.global_info.airs[LOOKUP_AIRGROUP_ID][LOOKUP_1_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_1_AIR_IDS[0]); + let mut trace = Lookup1Trace::new(); + let num_rows = trace.num_rows(); - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); - - let mut trace = Lookup1Trace::new(num_rows); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let num_lookups = trace[0].sel.len(); @@ -57,13 +51,7 @@ where trace[i].mul = F::from_canonical_usize(n_sel); } - let air_instance = - AirInstance::new(sctx.clone(), LOOKUP_AIRGROUP_ID, LOOKUP_1_AIR_IDS[0], None, trace.buffer.unwrap()); - - let (is_myne, gid) = ectx.dctx.write().unwrap().add_instance(LOOKUP_AIRGROUP_ID, LOOKUP_1_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs index fd4a4a63..053e6cdb 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs @@ -29,16 +29,10 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = pctx.global_info.airs[LOOKUP_AIRGROUP_ID][LOOKUP_2_12_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_2_12_AIR_IDS[0]); + let mut trace = Lookup2_12Trace::new(); + let num_rows = trace.num_rows(); - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); - - let mut trace = Lookup2_12Trace::new(num_rows); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); // TODO: Add the ability to send inputs to lookup3 // and consequently add random selectors @@ -69,13 +63,7 @@ where trace[i].sel2 = F::from_bool(true); } - let air_instance = - AirInstance::new(sctx.clone(), LOOKUP_AIRGROUP_ID, LOOKUP_2_12_AIR_IDS[0], None, trace.buffer.unwrap()); - - let (is_myne, gid) = ectx.dctx.write().unwrap().add_instance(LOOKUP_AIRGROUP_ID, LOOKUP_2_12_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs index 1c7de046..f4d8bdb6 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs @@ -29,19 +29,14 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = pctx.global_info.airs[LOOKUP_AIRGROUP_ID][LOOKUP_2_13_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_2_13_AIR_IDS[0]); - - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); - let mut trace = Lookup2_13Trace::new(num_rows); + let mut trace = Lookup2_13Trace::new(); + let num_rows = trace.num_rows(); // TODO: Add the ability to send inputs to lookup3 // and consequently add random selectors + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); + for i in 0..num_rows { // Inner lookups trace[i].a1 = rng.gen(); @@ -68,13 +63,7 @@ where trace[i].sel2 = F::from_bool(true); } - let air_instance = - AirInstance::new(sctx.clone(), LOOKUP_AIRGROUP_ID, LOOKUP_2_13_AIR_IDS[0], None, trace.buffer.unwrap()); - - let (is_myne, gid) = ectx.dctx.write().unwrap().add_instance(LOOKUP_AIRGROUP_ID, LOOKUP_2_13_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs index 12d1ff6d..8f9e5145 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs @@ -28,16 +28,11 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = pctx.global_info.airs[LOOKUP_AIRGROUP_ID][LOOKUP_2_15_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_2_15_AIR_IDS[0]); - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); + let mut trace = Lookup2_15Trace::new(); + let num_rows = trace.num_rows(); - let mut trace = Lookup2_15Trace::new(num_rows); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); // TODO: Add the ability to send inputs to lookup3 // and consequently add random selectors @@ -68,13 +63,7 @@ where trace[i].sel2 = F::from_bool(true); } - let air_instance = - AirInstance::new(sctx.clone(), LOOKUP_AIRGROUP_ID, LOOKUP_2_15_AIR_IDS[0], None, trace.buffer.unwrap()); - - let (is_myne, gid) = ectx.dctx.write().unwrap().add_instance(LOOKUP_AIRGROUP_ID, LOOKUP_2_15_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup3.rs b/pil2-components/test/std/lookup/rs/src/lookup3.rs index c97b543c..6d12c6ce 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup3.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup3.rs @@ -24,16 +24,10 @@ impl Lookup3 { pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { // For simplicity, add a single instance of each air - let num_rows = pctx.global_info.airs[LOOKUP_AIRGROUP_ID][LOOKUP_3_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(LOOKUP_AIRGROUP_ID, LOOKUP_3_AIR_IDS[0]); + let mut trace = Lookup3Trace::new(); + let num_rows = trace.num_rows(); - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); - - let mut trace = Lookup3Trace::new(num_rows); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); for i in 0..num_rows { trace[i].c1 = F::from_canonical_usize(i); @@ -57,13 +51,7 @@ impl Lookup3 { } } - let air_instance = - AirInstance::new(sctx.clone(), LOOKUP_AIRGROUP_ID, LOOKUP_3_AIR_IDS[0], None, trace.buffer.unwrap()); - - let (is_myne, gid) = ectx.dctx.write().unwrap().add_instance(LOOKUP_AIRGROUP_ID, LOOKUP_3_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup_lib.rs b/pil2-components/test/std/lookup/rs/src/lookup_lib.rs index 17ddb6d4..106a6a85 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup_lib.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup_lib.rs @@ -2,13 +2,13 @@ use std::{error::Error, path::PathBuf, sync::Arc}; use pil_std_lib::Std; use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode, WitnessPilout}; +use proofman_common::{initialize_logger, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode}; use p3_field::PrimeField; use p3_goldilocks::Goldilocks; use rand::{distributions::Standard, prelude::Distribution}; -use crate::{Lookup0, Lookup1, Lookup2_12, Lookup2_13, Lookup2_15, Lookup3, Pilout}; +use crate::{Lookup0, Lookup1, Lookup2_12, Lookup2_13, Lookup2_15, Lookup3}; pub struct LookupWitness { pub wcm: Option>>, @@ -96,10 +96,6 @@ where fn calculate_witness(&mut self, stage: u32, pctx: Arc>, ectx: Arc, sctx: Arc) { self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, ectx, sctx); } - - fn pilout(&self) -> WitnessPilout { - Pilout::pilout() - } } #[no_mangle] diff --git a/pil2-components/test/std/lookup/rs/src/pil_helpers/mod.rs b/pil2-components/test/std/lookup/rs/src/pil_helpers/mod.rs index 8273843a..9daf0c06 100644 --- a/pil2-components/test/std/lookup/rs/src/pil_helpers/mod.rs +++ b/pil2-components/test/std/lookup/rs/src/pil_helpers/mod.rs @@ -1,7 +1,5 @@ // WARNING: This file has been autogenerated from the PILOUT file. // Manual modifications are not recommended and may be overwritten. -mod pilout; mod traces; -pub use pilout::*; pub use traces::*; diff --git a/pil2-components/test/std/lookup/rs/src/pil_helpers/pilout.rs b/pil2-components/test/std/lookup/rs/src/pil_helpers/pilout.rs deleted file mode 100644 index 73c0d378..00000000 --- a/pil2-components/test/std/lookup/rs/src/pil_helpers/pilout.rs +++ /dev/null @@ -1,42 +0,0 @@ -// WARNING: This file has been autogenerated from the PILOUT file. -// Manual modifications are not recommended and may be overwritten. -use proofman_common::WitnessPilout; - -pub const PILOUT_HASH: &[u8] = b"Build-hash"; - -//AIRGROUP CONSTANTS - -pub const LOOKUP_AIRGROUP_ID: usize = 0; - -//AIR CONSTANTS - -pub const LOOKUP_0_AIR_IDS: &[usize] = &[0]; - -pub const LOOKUP_1_AIR_IDS: &[usize] = &[1]; - -pub const LOOKUP_2_12_AIR_IDS: &[usize] = &[2]; - -pub const LOOKUP_2_13_AIR_IDS: &[usize] = &[3]; - -pub const LOOKUP_2_15_AIR_IDS: &[usize] = &[4]; - -pub const LOOKUP_3_AIR_IDS: &[usize] = &[5]; - -pub struct Pilout; - -impl Pilout { - pub fn pilout() -> WitnessPilout { - let mut pilout = WitnessPilout::new("Build", 2, PILOUT_HASH.to_vec()); - - let air_group = pilout.add_air_group(Some("Lookup")); - - air_group.add_air(Some("Lookup0"), 1024); - air_group.add_air(Some("Lookup1"), 1024); - air_group.add_air(Some("Lookup2_12"), 4096); - air_group.add_air(Some("Lookup2_13"), 8192); - air_group.add_air(Some("Lookup2_15"), 32768); - air_group.add_air(Some("Lookup3"), 16384); - - pilout - } -} diff --git a/pil2-components/test/std/lookup/rs/src/pil_helpers/traces.rs b/pil2-components/test/std/lookup/rs/src/pil_helpers/traces.rs index bdc3c49c..6d0bfca8 100644 --- a/pil2-components/test/std/lookup/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/std/lookup/rs/src/pil_helpers/traces.rs @@ -2,27 +2,48 @@ // Manual modifications are not recommended and may be overwritten. use proofman_common as common; pub use proofman_macros::trace; +pub use proofman_macros::values; -trace!(Lookup0Row, Lookup0Trace { +pub const PILOUT_HASH: &[u8] = b"Build-hash"; + +//AIRGROUP CONSTANTS + +pub const LOOKUP_AIRGROUP_ID: usize = 0; + +//AIR CONSTANTS + +pub const LOOKUP_0_AIR_IDS: &[usize] = &[0]; + +pub const LOOKUP_1_AIR_IDS: &[usize] = &[1]; + +pub const LOOKUP_2_12_AIR_IDS: &[usize] = &[2]; + +pub const LOOKUP_2_13_AIR_IDS: &[usize] = &[3]; + +pub const LOOKUP_2_15_AIR_IDS: &[usize] = &[4]; + +pub const LOOKUP_3_AIR_IDS: &[usize] = &[5]; + +trace!(Lookup0Trace { f: [F; 4], t: [F; 4], sel: [F; 2], mul: [F; 2], -}); +}, 0, 0, 1024 ); -trace!(Lookup1Row, Lookup1Trace { +trace!(Lookup1Trace { f: [F; 2], t: F, sel: [F; 2], mul: F, -}); +}, 0, 1, 1024 ); -trace!(Lookup2_12Row, Lookup2_12Trace { +trace!(Lookup2_12Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, mul: F, -}); +}, 0, 2, 4096 ); -trace!(Lookup2_13Row, Lookup2_13Trace { +trace!(Lookup2_13Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, mul: F, -}); +}, 0, 3, 8192 ); -trace!(Lookup2_15Row, Lookup2_15Trace { +trace!(Lookup2_15Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, mul: F, -}); +}, 0, 4, 32768 ); -trace!(Lookup3Row, Lookup3Trace { +trace!(Lookup3Trace { c1: F, d1: F, c2: F, d2: F, mul1: F, mul2: F, -}); +}, 0, 5, 16384 ); diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs index 631b3dfd..d80bf456 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs @@ -28,16 +28,11 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = pctx.global_info.airs[PERMUTATION_AIRGROUP_ID][PERMUTATION_1_6_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(PERMUTATION_AIRGROUP_ID, PERMUTATION_1_6_AIR_IDS[0]); - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); + let mut trace = Permutation1_6Trace::new(); + let num_rows = trace.num_rows(); - let mut trace = Permutation1_6Trace::new(num_rows); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); // TODO: Add the ability to send inputs to permutation2 // and consequently add random selectors @@ -75,69 +70,9 @@ where trace[i].sel2 = trace[indices[i]].sel1; } - let air_instance = AirInstance::new( - sctx.clone(), - PERMUTATION_AIRGROUP_ID, - PERMUTATION_1_6_AIR_IDS[0], - None, - trace.buffer.unwrap(), - ); - let (is_myne, gid) = - ectx.dctx.write().unwrap().add_instance(PERMUTATION_AIRGROUP_ID, PERMUTATION_1_6_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } - - let mut trace2 = Permutation1_6Trace::new(num_rows); - - // TODO: Add the ability to send inputs to permutation2 - // and consequently add random selectors - - // Assumes - for i in 0..num_rows { - trace2[i].a1 = rng.gen(); - trace2[i].b1 = rng.gen(); - - trace2[i].a2 = F::from_canonical_u8(200); - trace2[i].b2 = F::from_canonical_u8(201); - - trace2[i].a3 = rng.gen(); - trace2[i].b3 = rng.gen(); - - trace2[i].a4 = F::from_canonical_u8(100); - trace2[i].b4 = F::from_canonical_u8(101); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); - trace2[i].sel1 = F::from_bool(rng.gen_bool(0.5)); - trace2[i].sel3 = F::one(); - } - - let mut indices2: Vec = (0..num_rows).collect(); - indices2.shuffle(&mut rng); - - // Proves - for i in 0..num_rows { - // We take a random permutation of the indices to show that the permutation check is passing - trace2[i].c1 = trace2[indices2[i]].a1; - trace2[i].d1 = trace2[indices2[i]].b1; - - trace2[i].c2 = trace2[indices2[i]].a3; - trace2[i].d2 = trace2[indices2[i]].b3; - - trace2[i].sel2 = trace2[indices2[i]].sel1; - } - - let air_instance = AirInstance::new( - sctx.clone(), - PERMUTATION_AIRGROUP_ID, - PERMUTATION_1_6_AIR_IDS[0], - None, - trace2.buffer.unwrap(), - ); - let (is_myne, gid) = - ectx.dctx.write().unwrap().add_instance(PERMUTATION_AIRGROUP_ID, PERMUTATION_1_6_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs index fe87d9ee..3c64bca2 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs @@ -28,16 +28,10 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = pctx.global_info.airs[PERMUTATION_AIRGROUP_ID][PERMUTATION_1_7_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(PERMUTATION_AIRGROUP_ID, PERMUTATION_1_7_AIR_IDS[0]); + let mut trace = Permutation1_7Trace::new(); + let num_rows = trace.num_rows(); - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); - - let mut trace = Permutation1_7Trace::new(num_rows); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); // TODO: Add the ability to send inputs to permutation2 // and consequently add random selectors @@ -76,18 +70,7 @@ where trace[i].sel2 = trace[i].sel1; } - let air_instance = AirInstance::new( - sctx.clone(), - PERMUTATION_AIRGROUP_ID, - PERMUTATION_1_7_AIR_IDS[0], - None, - trace.buffer.unwrap(), - ); - let (is_myne, gid) = - ectx.dctx.write().unwrap().add_instance(PERMUTATION_AIRGROUP_ID, PERMUTATION_1_7_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs index e2b50133..b75c243b 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs @@ -28,15 +28,10 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = pctx.global_info.airs[PERMUTATION_AIRGROUP_ID][PERMUTATION_1_8_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(PERMUTATION_AIRGROUP_ID, PERMUTATION_1_8_AIR_IDS[0]); + let mut trace = Permutation1_8Trace::new(); + let num_rows = trace.num_rows(); - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); - let mut trace = Permutation1_8Trace::new(num_rows); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); // TODO: Add the ability to send inputs to permutation2 // and consequently add random selectors @@ -75,18 +70,7 @@ where trace[i].sel2 = trace[i].sel1; } - let air_instance = AirInstance::new( - sctx.clone(), - PERMUTATION_AIRGROUP_ID, - PERMUTATION_1_8_AIR_IDS[0], - None, - trace.buffer.unwrap(), - ); - let (is_myne, gid) = - ectx.dctx.write().unwrap().add_instance(PERMUTATION_AIRGROUP_ID, PERMUTATION_1_8_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation2.rs b/pil2-components/test/std/permutation/rs/src/permutation2.rs index 2414d826..eea0b3df 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation2.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation2.rs @@ -23,16 +23,10 @@ impl Permutation2 { } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { - let num_rows = pctx.global_info.airs[PERMUTATION_AIRGROUP_ID][PERMUTATION_2_6_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(PERMUTATION_AIRGROUP_ID, PERMUTATION_2_6_AIR_IDS[0]); + let mut trace = Permutation2_6Trace::new(); + let num_rows = trace.num_rows(); - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); - - let mut trace = Permutation2_6Trace::new(num_rows); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); // Note: Here it is assumed that num_rows of permutation2 is equal to // the sum of num_rows of each variant of permutation1. @@ -48,18 +42,7 @@ impl Permutation2 { trace[i].sel = F::from_bool(true); } - let air_instance = AirInstance::new( - sctx.clone(), - PERMUTATION_AIRGROUP_ID, - PERMUTATION_2_6_AIR_IDS[0], - None, - trace.buffer.unwrap(), - ); - let (is_myne, gid) = - ectx.dctx.write().unwrap().add_instance(PERMUTATION_AIRGROUP_ID, PERMUTATION_2_6_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation_lib.rs b/pil2-components/test/std/permutation/rs/src/permutation_lib.rs index 48e97994..cbd15081 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation_lib.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation_lib.rs @@ -2,13 +2,13 @@ use std::{error::Error, path::PathBuf, sync::Arc}; use pil_std_lib::Std; use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode, WitnessPilout}; +use proofman_common::{initialize_logger, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode}; use p3_field::PrimeField; use p3_goldilocks::Goldilocks; use rand::{distributions::Standard, prelude::Distribution}; -use crate::{Permutation1_6, Permutation1_7, Permutation1_8, Permutation2, Pilout}; +use crate::{Permutation1_6, Permutation1_7, Permutation1_8, Permutation2}; pub struct PermutationWitness { pub wcm: Option>>, @@ -86,10 +86,6 @@ where fn calculate_witness(&mut self, stage: u32, pctx: Arc>, ectx: Arc, sctx: Arc) { self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, ectx, sctx); } - - fn pilout(&self) -> WitnessPilout { - Pilout::pilout() - } } #[no_mangle] diff --git a/pil2-components/test/std/permutation/rs/src/pil_helpers/mod.rs b/pil2-components/test/std/permutation/rs/src/pil_helpers/mod.rs index 8273843a..9daf0c06 100644 --- a/pil2-components/test/std/permutation/rs/src/pil_helpers/mod.rs +++ b/pil2-components/test/std/permutation/rs/src/pil_helpers/mod.rs @@ -1,7 +1,5 @@ // WARNING: This file has been autogenerated from the PILOUT file. // Manual modifications are not recommended and may be overwritten. -mod pilout; mod traces; -pub use pilout::*; pub use traces::*; diff --git a/pil2-components/test/std/permutation/rs/src/pil_helpers/pilout.rs b/pil2-components/test/std/permutation/rs/src/pil_helpers/pilout.rs deleted file mode 100644 index 12ce2855..00000000 --- a/pil2-components/test/std/permutation/rs/src/pil_helpers/pilout.rs +++ /dev/null @@ -1,36 +0,0 @@ -// WARNING: This file has been autogenerated from the PILOUT file. -// Manual modifications are not recommended and may be overwritten. -use proofman_common::WitnessPilout; - -pub const PILOUT_HASH: &[u8] = b"Build-hash"; - -//AIRGROUP CONSTANTS - -pub const PERMUTATION_AIRGROUP_ID: usize = 0; - -//AIR CONSTANTS - -pub const PERMUTATION_1_6_AIR_IDS: &[usize] = &[0]; - -pub const PERMUTATION_1_7_AIR_IDS: &[usize] = &[1]; - -pub const PERMUTATION_1_8_AIR_IDS: &[usize] = &[2]; - -pub const PERMUTATION_2_6_AIR_IDS: &[usize] = &[3]; - -pub struct Pilout; - -impl Pilout { - pub fn pilout() -> WitnessPilout { - let mut pilout = WitnessPilout::new("Build", 2, PILOUT_HASH.to_vec()); - - let air_group = pilout.add_air_group(Some("Permutation")); - - air_group.add_air(Some("Permutation1_6"), 64); - air_group.add_air(Some("Permutation1_7"), 128); - air_group.add_air(Some("Permutation1_8"), 256); - air_group.add_air(Some("Permutation2_6"), 512); - - pilout - } -} diff --git a/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs b/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs index 12c0e74b..a6406fb5 100644 --- a/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs @@ -2,19 +2,36 @@ // Manual modifications are not recommended and may be overwritten. use proofman_common as common; pub use proofman_macros::trace; +pub use proofman_macros::values; -trace!(Permutation1_6Row, Permutation1_6Trace { +pub const PILOUT_HASH: &[u8] = b"Build-hash"; + +//AIRGROUP CONSTANTS + +pub const PERMUTATION_AIRGROUP_ID: usize = 0; + +//AIR CONSTANTS + +pub const PERMUTATION_1_6_AIR_IDS: &[usize] = &[0]; + +pub const PERMUTATION_1_7_AIR_IDS: &[usize] = &[1]; + +pub const PERMUTATION_1_8_AIR_IDS: &[usize] = &[2]; + +pub const PERMUTATION_2_6_AIR_IDS: &[usize] = &[3]; + +trace!(Permutation1_6Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, sel3: F, -}); +}, 0, 0, 64 ); -trace!(Permutation1_7Row, Permutation1_7Trace { +trace!(Permutation1_7Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, sel3: F, -}); +}, 0, 1, 128 ); -trace!(Permutation1_8Row, Permutation1_8Trace { +trace!(Permutation1_8Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, sel3: F, -}); +}, 0, 2, 256 ); -trace!(Permutation2_6Row, Permutation2_6Trace { +trace!(Permutation2_6Trace { c1: F, d1: F, c2: F, d2: F, sel: F, -}); +}, 0, 3, 512 ); diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs index 2de61e24..a6d03841 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs @@ -37,16 +37,11 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = pctx.global_info.airs[MULTI_RANGE_CHECK_1_AIRGROUP_ID][MULTI_RANGE_CHECK_1_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(MULTI_RANGE_CHECK_1_AIRGROUP_ID, MULTI_RANGE_CHECK_1_AIR_IDS[0]); - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); + let mut trace = MultiRangeCheck1Trace::new_zeroes(); + let num_rows = trace.num_rows(); - let mut trace = MultiRangeCheck1Trace::new_zeroes(num_rows); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let range1 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 7) - 1), Some(false)); let range2 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(false)); @@ -107,18 +102,7 @@ where } } - let air_instance = AirInstance::new( - sctx.clone(), - MULTI_RANGE_CHECK_1_AIRGROUP_ID, - MULTI_RANGE_CHECK_1_AIR_IDS[0], - None, - trace.buffer.unwrap(), - ); - let (is_myne, gid) = - ectx.dctx.write().unwrap().add_instance(MULTI_RANGE_CHECK_1_AIRGROUP_ID, MULTI_RANGE_CHECK_1_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs index 9411c919..5090946b 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs @@ -37,16 +37,11 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = pctx.global_info.airs[MULTI_RANGE_CHECK_2_AIRGROUP_ID][MULTI_RANGE_CHECK_2_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(MULTI_RANGE_CHECK_2_AIRGROUP_ID, MULTI_RANGE_CHECK_2_AIR_IDS[0]); - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); + let mut trace = MultiRangeCheck2Trace::new_zeroes(); + let num_rows = trace.num_rows(); - let mut trace = MultiRangeCheck2Trace::new_zeroes(num_rows); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let range1 = self.std_lib.get_range(BigInt::from(1 << 5), BigInt::from((1 << 8) - 1), Some(false)); let range2 = self.std_lib.get_range(BigInt::from(1 << 8), BigInt::from((1 << 9) - 1), Some(false)); @@ -89,18 +84,7 @@ where } } - let air_instance = AirInstance::new( - sctx.clone(), - MULTI_RANGE_CHECK_2_AIRGROUP_ID, - MULTI_RANGE_CHECK_2_AIR_IDS[0], - None, - trace.buffer.unwrap(), - ); - let (is_myne, gid) = - ectx.dctx.write().unwrap().add_instance(MULTI_RANGE_CHECK_2_AIRGROUP_ID, MULTI_RANGE_CHECK_2_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/range_check/rs/src/pil_helpers/mod.rs b/pil2-components/test/std/range_check/rs/src/pil_helpers/mod.rs index 8273843a..9daf0c06 100644 --- a/pil2-components/test/std/range_check/rs/src/pil_helpers/mod.rs +++ b/pil2-components/test/std/range_check/rs/src/pil_helpers/mod.rs @@ -1,7 +1,5 @@ // WARNING: This file has been autogenerated from the PILOUT file. // Manual modifications are not recommended and may be overwritten. -mod pilout; mod traces; -pub use pilout::*; pub use traces::*; diff --git a/pil2-components/test/std/range_check/rs/src/pil_helpers/pilout.rs b/pil2-components/test/std/range_check/rs/src/pil_helpers/pilout.rs deleted file mode 100644 index 2e0d3565..00000000 --- a/pil2-components/test/std/range_check/rs/src/pil_helpers/pilout.rs +++ /dev/null @@ -1,110 +0,0 @@ -// WARNING: This file has been autogenerated from the PILOUT file. -// Manual modifications are not recommended and may be overwritten. -use proofman_common::WitnessPilout; - -pub const PILOUT_HASH: &[u8] = b"Build-hash"; - -//AIRGROUP CONSTANTS - -pub const RANGE_CHECK_3_AIRGROUP_ID: usize = 0; - -pub const RANGE_CHECK_2_AIRGROUP_ID: usize = 1; - -pub const RANGE_CHECK_1_AIRGROUP_ID: usize = 2; - -pub const RANGE_CHECK_4_AIRGROUP_ID: usize = 3; - -pub const MULTI_RANGE_CHECK_1_AIRGROUP_ID: usize = 4; - -pub const MULTI_RANGE_CHECK_2_AIRGROUP_ID: usize = 5; - -pub const RANGE_CHECK_DYNAMIC_1_AIRGROUP_ID: usize = 6; - -pub const RANGE_CHECK_DYNAMIC_2_AIRGROUP_ID: usize = 7; - -pub const RANGE_CHECK_MIX_AIRGROUP_ID: usize = 8; - -pub const U_8_AIR_AIRGROUP_ID: usize = 9; - -pub const SPECIFIED_RANGES_AIRGROUP_ID: usize = 10; - -//AIR CONSTANTS - -pub const RANGE_CHECK_3_AIR_IDS: &[usize] = &[0]; - -pub const RANGE_CHECK_2_AIR_IDS: &[usize] = &[0]; - -pub const RANGE_CHECK_1_AIR_IDS: &[usize] = &[0]; - -pub const RANGE_CHECK_4_AIR_IDS: &[usize] = &[0]; - -pub const U_16_AIR_AIR_IDS: &[usize] = &[1]; - -pub const MULTI_RANGE_CHECK_1_AIR_IDS: &[usize] = &[0]; - -pub const MULTI_RANGE_CHECK_2_AIR_IDS: &[usize] = &[0]; - -pub const RANGE_CHECK_DYNAMIC_1_AIR_IDS: &[usize] = &[0]; - -pub const RANGE_CHECK_DYNAMIC_2_AIR_IDS: &[usize] = &[0]; - -pub const RANGE_CHECK_MIX_AIR_IDS: &[usize] = &[0]; - -pub const U_8_AIR_AIR_IDS: &[usize] = &[0]; - -pub const SPECIFIED_RANGES_AIR_IDS: &[usize] = &[0]; - -pub struct Pilout; - -impl Pilout { - pub fn pilout() -> WitnessPilout { - let mut pilout = WitnessPilout::new("Build", 2, PILOUT_HASH.to_vec()); - - let air_group = pilout.add_air_group(Some("RangeCheck3")); - - air_group.add_air(Some("RangeCheck3"), 32); - - let air_group = pilout.add_air_group(Some("RangeCheck2")); - - air_group.add_air(Some("RangeCheck2"), 16); - - let air_group = pilout.add_air_group(Some("RangeCheck1")); - - air_group.add_air(Some("RangeCheck1"), 8); - - let air_group = pilout.add_air_group(Some("RangeCheck4")); - - air_group.add_air(Some("RangeCheck4"), 64); - air_group.add_air(Some("U16Air"), 65536); - - let air_group = pilout.add_air_group(Some("MultiRangeCheck1")); - - air_group.add_air(Some("MultiRangeCheck1"), 8); - - let air_group = pilout.add_air_group(Some("MultiRangeCheck2")); - - air_group.add_air(Some("MultiRangeCheck2"), 16); - - let air_group = pilout.add_air_group(Some("RangeCheckDynamic1")); - - air_group.add_air(Some("RangeCheckDynamic1"), 256); - - let air_group = pilout.add_air_group(Some("RangeCheckDynamic2")); - - air_group.add_air(Some("RangeCheckDynamic2"), 64); - - let air_group = pilout.add_air_group(Some("RangeCheckMix")); - - air_group.add_air(Some("RangeCheckMix"), 64); - - let air_group = pilout.add_air_group(Some("U8Air")); - - air_group.add_air(Some("U8Air"), 256); - - let air_group = pilout.add_air_group(Some("SpecifiedRanges")); - - air_group.add_air(Some("SpecifiedRanges"), 131072); - - pilout - } -} diff --git a/pil2-components/test/std/range_check/rs/src/pil_helpers/traces.rs b/pil2-components/test/std/range_check/rs/src/pil_helpers/traces.rs index 10ad6e66..8d95366c 100644 --- a/pil2-components/test/std/range_check/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/std/range_check/rs/src/pil_helpers/traces.rs @@ -2,51 +2,104 @@ // Manual modifications are not recommended and may be overwritten. use proofman_common as common; pub use proofman_macros::trace; +pub use proofman_macros::values; -trace!(RangeCheck3Row, RangeCheck3Trace { +pub const PILOUT_HASH: &[u8] = b"Build-hash"; + +//AIRGROUP CONSTANTS + +pub const RANGE_CHECK_3_AIRGROUP_ID: usize = 0; + +pub const RANGE_CHECK_2_AIRGROUP_ID: usize = 1; + +pub const RANGE_CHECK_1_AIRGROUP_ID: usize = 2; + +pub const RANGE_CHECK_4_AIRGROUP_ID: usize = 3; + +pub const MULTI_RANGE_CHECK_1_AIRGROUP_ID: usize = 4; + +pub const MULTI_RANGE_CHECK_2_AIRGROUP_ID: usize = 5; + +pub const RANGE_CHECK_DYNAMIC_1_AIRGROUP_ID: usize = 6; + +pub const RANGE_CHECK_DYNAMIC_2_AIRGROUP_ID: usize = 7; + +pub const RANGE_CHECK_MIX_AIRGROUP_ID: usize = 8; + +pub const U_8_AIR_AIRGROUP_ID: usize = 9; + +pub const SPECIFIED_RANGES_AIRGROUP_ID: usize = 10; + +//AIR CONSTANTS + +pub const RANGE_CHECK_3_AIR_IDS: &[usize] = &[0]; + +pub const RANGE_CHECK_2_AIR_IDS: &[usize] = &[0]; + +pub const RANGE_CHECK_1_AIR_IDS: &[usize] = &[0]; + +pub const RANGE_CHECK_4_AIR_IDS: &[usize] = &[0]; + +pub const U_16_AIR_AIR_IDS: &[usize] = &[1]; + +pub const MULTI_RANGE_CHECK_1_AIR_IDS: &[usize] = &[0]; + +pub const MULTI_RANGE_CHECK_2_AIR_IDS: &[usize] = &[0]; + +pub const RANGE_CHECK_DYNAMIC_1_AIR_IDS: &[usize] = &[0]; + +pub const RANGE_CHECK_DYNAMIC_2_AIR_IDS: &[usize] = &[0]; + +pub const RANGE_CHECK_MIX_AIR_IDS: &[usize] = &[0]; + +pub const U_8_AIR_AIR_IDS: &[usize] = &[0]; + +pub const SPECIFIED_RANGES_AIR_IDS: &[usize] = &[0]; + +trace!(RangeCheck3Trace { c1: F, c2: F, -}); +}, 0, 0, 32 ); -trace!(RangeCheck2Row, RangeCheck2Trace { +trace!(RangeCheck2Trace { b1: F, b2: F, b3: F, -}); +}, 1, 0, 16 ); -trace!(RangeCheck1Row, RangeCheck1Trace { +trace!(RangeCheck1Trace { a1: F, a2: F, a3: F, a4: F, a5: F, sel1: F, sel2: F, sel3: F, -}); +}, 2, 0, 8 ); -trace!(RangeCheck4Row, RangeCheck4Trace { +trace!(RangeCheck4Trace { a1: F, a2: F, a3: F, a4: F, a5: F, a6: F, a7: F, a8: F, sel1: F, sel2: F, -}); +}, 3, 0, 64 ); -trace!(U16AirRow, U16AirTrace { +trace!(U16AirTrace { mul: F, -}); +}, 3, 1, 65536 ); -trace!(MultiRangeCheck1Row, MultiRangeCheck1Trace { +trace!(MultiRangeCheck1Trace { a: [F; 3], sel: [F; 3], range_sel: [F; 3], -}); +}, 4, 0, 8 ); -trace!(MultiRangeCheck2Row, MultiRangeCheck2Trace { +trace!(MultiRangeCheck2Trace { a: [F; 2], sel: [F; 2], range_sel: [F; 2], -}); +}, 5, 0, 16 ); -trace!(RangeCheckDynamic1Row, RangeCheckDynamic1Trace { +trace!(RangeCheckDynamic1Trace { colu: F, sel_7: F, sel_8: F, sel_16: F, sel_17: F, -}); +}, 6, 0, 256 ); -trace!(RangeCheckDynamic2Row, RangeCheckDynamic2Trace { +trace!(RangeCheckDynamic2Trace { colu: F, sel_1: F, sel_2: F, sel_3: F, sel_4: F, sel_5: F, -}); +}, 7, 0, 64 ); -trace!(RangeCheckMixRow, RangeCheckMixTrace { +trace!(RangeCheckMixTrace { a: [F; 4], b: [F; 2], c: [F; 1], range_sel: [F; 5], -}); +}, 8, 0, 64 ); -trace!(U8AirRow, U8AirTrace { +trace!(U8AirTrace { mul: F, -}); +}, 9, 0, 256 ); -trace!(SpecifiedRangesRow, SpecifiedRangesTrace { +trace!(SpecifiedRangesTrace { mul: [F; 20], -}); +}, 10, 0, 131072 ); diff --git a/pil2-components/test/std/range_check/rs/src/range_check1.rs b/pil2-components/test/std/range_check/rs/src/range_check1.rs index 1bfd9f58..0d2c2bf6 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check1.rs @@ -33,15 +33,11 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = pctx.global_info.airs[RANGE_CHECK_1_AIRGROUP_ID][RANGE_CHECK_1_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(RANGE_CHECK_1_AIRGROUP_ID, RANGE_CHECK_1_AIR_IDS[0]); - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); - let mut trace = RangeCheck1Trace::new_zeroes(num_rows); + let mut trace = RangeCheck1Trace::new_zeroes(); + let num_rows = trace.num_rows(); + + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let range1 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(false)); let range2 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 4) - 1), Some(false)); @@ -81,18 +77,7 @@ where } } - let air_instance = AirInstance::new( - sctx.clone(), - RANGE_CHECK_1_AIRGROUP_ID, - RANGE_CHECK_1_AIR_IDS[0], - None, - trace.buffer.unwrap(), - ); - let (is_myne, gid) = - ectx.dctx.write().unwrap().add_instance(RANGE_CHECK_1_AIRGROUP_ID, RANGE_CHECK_1_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check2.rs b/pil2-components/test/std/range_check/rs/src/range_check2.rs index a405fbf2..d0d206cf 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check2.rs @@ -33,15 +33,10 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = pctx.global_info.airs[RANGE_CHECK_2_AIRGROUP_ID][RANGE_CHECK_2_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(RANGE_CHECK_2_AIRGROUP_ID, RANGE_CHECK_2_AIR_IDS[0]); + let mut trace = RangeCheck2Trace::new_zeroes(); + let num_rows = trace.num_rows(); - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); - let mut trace = RangeCheck2Trace::new_zeroes(num_rows); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let range1 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(false)); let range2 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 9) - 1), Some(false)); @@ -57,18 +52,7 @@ where self.std_lib.range_check(trace[i].b3, F::one(), range3); } - let air_instance = AirInstance::new( - sctx.clone(), - RANGE_CHECK_2_AIRGROUP_ID, - RANGE_CHECK_2_AIR_IDS[0], - None, - trace.buffer.unwrap(), - ); - let (is_myne, gid) = - ectx.dctx.write().unwrap().add_instance(RANGE_CHECK_2_AIRGROUP_ID, RANGE_CHECK_2_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check3.rs b/pil2-components/test/std/range_check/rs/src/range_check3.rs index 4eb0f168..57ac11e6 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check3.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check3.rs @@ -33,16 +33,11 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = pctx.global_info.airs[RANGE_CHECK_3_AIRGROUP_ID][RANGE_CHECK_3_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(RANGE_CHECK_3_AIRGROUP_ID, RANGE_CHECK_3_AIR_IDS[0]); - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); + let mut trace = RangeCheck3Trace::new_zeroes(); + let num_rows = trace.num_rows(); - let mut trace = RangeCheck3Trace::new_zeroes(num_rows); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let range1 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 4) - 1), Some(false)); let range2 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(false)); @@ -55,18 +50,7 @@ where self.std_lib.range_check(trace[i].c2, F::one(), range2); } - let air_instance = AirInstance::new( - sctx.clone(), - RANGE_CHECK_3_AIRGROUP_ID, - RANGE_CHECK_3_AIR_IDS[0], - None, - trace.buffer.unwrap(), - ); - let (is_myne, gid) = - ectx.dctx.write().unwrap().add_instance(RANGE_CHECK_3_AIRGROUP_ID, RANGE_CHECK_3_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check4.rs b/pil2-components/test/std/range_check/rs/src/range_check4.rs index 973e43ed..9ee2deba 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check4.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check4.rs @@ -34,16 +34,11 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = pctx.global_info.airs[RANGE_CHECK_4_AIRGROUP_ID][RANGE_CHECK_4_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(RANGE_CHECK_4_AIRGROUP_ID, RANGE_CHECK_4_AIR_IDS[0]); - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); + let mut trace = RangeCheck4Trace::new_zeroes(); + let num_rows = trace.num_rows(); - let mut trace = RangeCheck4Trace::new_zeroes(num_rows); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let range1 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 16) - 1), Some(true)); let range2 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(true)); @@ -103,18 +98,7 @@ where self.std_lib.range_check(trace[i].a8, F::one(), range9); } - let air_instance = AirInstance::new( - sctx.clone(), - RANGE_CHECK_4_AIRGROUP_ID, - RANGE_CHECK_4_AIR_IDS[0], - None, - trace.buffer.unwrap(), - ); - let (is_myne, gid) = - ectx.dctx.write().unwrap().add_instance(RANGE_CHECK_4_AIRGROUP_ID, RANGE_CHECK_4_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs index 8751d7cd..e607fad5 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs @@ -37,17 +37,11 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = - pctx.global_info.airs[RANGE_CHECK_DYNAMIC_1_AIRGROUP_ID][RANGE_CHECK_DYNAMIC_1_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(RANGE_CHECK_DYNAMIC_1_AIRGROUP_ID, RANGE_CHECK_DYNAMIC_1_AIR_IDS[0]); - - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); - let mut trace = RangeCheckDynamic1Trace::new_zeroes(num_rows); + let mut trace = RangeCheckDynamic1Trace::new_zeroes(); + let num_rows = trace.num_rows(); + + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let range7 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 7) - 1), Some(false)); let range8 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), Some(false)); @@ -86,21 +80,7 @@ where } } - let air_instance = AirInstance::new( - sctx.clone(), - RANGE_CHECK_DYNAMIC_1_AIRGROUP_ID, - RANGE_CHECK_DYNAMIC_1_AIR_IDS[0], - None, - trace.buffer.unwrap(), - ); - let (is_myne, gid) = ectx.dctx.write().unwrap().add_instance( - RANGE_CHECK_DYNAMIC_1_AIRGROUP_ID, - RANGE_CHECK_DYNAMIC_1_AIR_IDS[0], - 1, - ); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs index c43fa932..03e8c066 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs @@ -38,17 +38,11 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = - pctx.global_info.airs[RANGE_CHECK_DYNAMIC_2_AIRGROUP_ID][RANGE_CHECK_DYNAMIC_2_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(RANGE_CHECK_DYNAMIC_2_AIRGROUP_ID, RANGE_CHECK_DYNAMIC_2_AIR_IDS[0]); - - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); - let mut trace = RangeCheckDynamic2Trace::new_zeroes(num_rows); + let mut trace = RangeCheckDynamic2Trace::new_zeroes(); + let num_rows = trace.num_rows(); + + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let range1 = self.std_lib.get_range(BigInt::from(5225), BigInt::from(29023), Some(false)); let range2 = self.std_lib.get_range(BigInt::from(-8719), BigInt::from(-7269), Some(false)); @@ -99,21 +93,7 @@ where } } - let air_instance = AirInstance::new( - sctx.clone(), - RANGE_CHECK_DYNAMIC_2_AIRGROUP_ID, - RANGE_CHECK_DYNAMIC_2_AIR_IDS[0], - None, - trace.buffer.unwrap(), - ); - let (is_myne, gid) = ectx.dctx.write().unwrap().add_instance( - RANGE_CHECK_DYNAMIC_2_AIRGROUP_ID, - RANGE_CHECK_DYNAMIC_2_AIR_IDS[0], - 1, - ); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_lib.rs b/pil2-components/test/std/range_check/rs/src/range_check_lib.rs index 0f04caa6..e25389d1 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_lib.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_lib.rs @@ -2,14 +2,14 @@ use std::{cell::OnceCell, error::Error, path::PathBuf, sync::Arc}; use pil_std_lib::Std; use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode, WitnessPilout}; +use proofman_common::{initialize_logger, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode}; use p3_field::PrimeField; use p3_goldilocks::Goldilocks; use rand::{distributions::Standard, prelude::Distribution}; use crate::{ - RangeCheckMix, RangeCheckDynamic1, RangeCheckDynamic2, MultiRangeCheck1, MultiRangeCheck2, Pilout, RangeCheck1, + RangeCheckMix, RangeCheckDynamic1, RangeCheckDynamic2, MultiRangeCheck1, MultiRangeCheck2, RangeCheck1, RangeCheck2, RangeCheck3, RangeCheck4, }; @@ -114,10 +114,6 @@ where fn calculate_witness(&mut self, stage: u32, pctx: Arc>, ectx: Arc, sctx: Arc) { self.wcm.get().unwrap().calculate_witness(stage, pctx, ectx, sctx); } - - fn pilout(&self) -> WitnessPilout { - Pilout::pilout() - } } #[no_mangle] diff --git a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs index 62be39e8..1e74af04 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs @@ -38,16 +38,11 @@ where pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); - let num_rows = pctx.global_info.airs[RANGE_CHECK_MIX_AIRGROUP_ID][RANGE_CHECK_MIX_AIR_IDS[0]].num_rows; - let air = pctx.pilout.get_air(RANGE_CHECK_MIX_AIRGROUP_ID, RANGE_CHECK_MIX_AIR_IDS[0]); - log::debug!( - "{}: ··· Witness computation for AIR '{}' at stage 1", - Self::MY_NAME, - air.name().unwrap_or("unknown"), - ); + let mut trace = RangeCheckMixTrace::new_zeroes(); + let num_rows = trace.num_rows(); - let mut trace = RangeCheckMixTrace::new_zeroes(num_rows); + log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let range1 = self.std_lib.get_range(BigInt::from(0), BigInt::from((1 << 8) - 1), None); let range2 = self.std_lib.get_range(BigInt::from(50), BigInt::from((1 << 7) - 1), None); @@ -139,18 +134,7 @@ where } } - let air_instance = AirInstance::new( - sctx.clone(), - RANGE_CHECK_MIX_AIRGROUP_ID, - RANGE_CHECK_MIX_AIR_IDS[0], - None, - trace.buffer.unwrap(), - ); - let (is_myne, gid) = - ectx.dctx.write().unwrap().add_instance(RANGE_CHECK_MIX_AIRGROUP_ID, RANGE_CHECK_MIX_AIR_IDS[0], 1); - if is_myne { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); - } + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); } } diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index 7aa0ba73..421d48ff 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -71,7 +71,7 @@ impl ProofMan { let mut witness_lib = witness_lib(rom_path, public_inputs_path, ectx.verbose_mode)?; - let pctx = Arc::new(ProofCtx::create_ctx(witness_lib.pilout(), proving_key_path.clone())); + let pctx = Arc::new(ProofCtx::create_ctx(proving_key_path.clone())); let setups = Arc::new(SetupsVadcop::new(&pctx.global_info, options.aggregation, options.final_snark)); let sctx: Arc = setups.sctx.clone(); diff --git a/proofman/src/witness_library.rs b/proofman/src/witness_library.rs index d56f7477..f05be588 100644 --- a/proofman/src/witness_library.rs +++ b/proofman/src/witness_library.rs @@ -1,6 +1,6 @@ use std::{error::Error, path::PathBuf, sync::Arc}; -use proofman_common::{ExecutionCtx, ProofCtx, SetupCtx, VerboseMode, WitnessPilout}; +use proofman_common::{ExecutionCtx, ProofCtx, SetupCtx, VerboseMode}; /// This is the type of the function that is used to load a witness library. pub type WitnessLibInitFn = @@ -16,6 +16,4 @@ pub trait WitnessLibrary { fn calculate_witness(&mut self, stage: u32, pctx: Arc>, ectx: Arc, sctx: Arc); fn debug(&mut self, _pctx: Arc>, _ectx: Arc, _sctx: Arc) {} - - fn pilout(&self) -> WitnessPilout; } From abaf007118f9e3f65f694edc89d1023b3140cc7b Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Thu, 5 Dec 2024 16:28:29 +0000 Subject: [PATCH 14/64] Work in progress --- cli/assets/templates/pil_helpers_trace.rs.tt | 23 +++-- cli/src/commands/pil_helpers.rs | 20 +++- common/src/air_instance.rs | 93 +++++++++++++------ common/src/lib.rs | 2 + common/src/proof_ctx.rs | 2 +- common/src/publics.rs | 24 +++++ common/src/trace.rs | 12 ++- examples/fibonacci-square/pil/fibonaccisq.pil | 2 +- examples/fibonacci-square/src/fibonacci.rs | 17 ++-- .../fibonacci-square/src/fibonacci_lib.rs | 29 ++---- examples/fibonacci-square/src/inputs.json | 4 +- examples/fibonacci-square/src/lib.rs | 2 - examples/fibonacci-square/src/module.rs | 2 +- .../src/pil_helpers/traces.rs | 25 +++-- .../fibonacci-square/src/public_inputs.rs | 8 -- macros/src/lib.rs | 82 +++++++++------- .../rs/src/range_check/specified_ranges.rs | 4 +- .../lib/std/rs/src/range_check/u16air.rs | 4 +- .../lib/std/rs/src/range_check/u8air.rs | 4 +- .../test/simple/rs/src/pil_helpers/traces.rs | 5 +- .../test/simple/rs/src/simple_left.rs | 2 +- .../test/simple/rs/src/simple_right.rs | 2 +- .../test/std/connection/rs/src/connection1.rs | 2 +- .../test/std/connection/rs/src/connection2.rs | 2 +- .../std/connection/rs/src/connection_new.rs | 2 +- .../connection/rs/src/pil_helpers/traces.rs | 7 +- .../test/std/lookup/rs/src/lookup0.rs | 2 +- .../test/std/lookup/rs/src/lookup1.rs | 2 +- .../test/std/lookup/rs/src/lookup2_12.rs | 2 +- .../test/std/lookup/rs/src/lookup2_13.rs | 2 +- .../test/std/lookup/rs/src/lookup2_15.rs | 2 +- .../test/std/lookup/rs/src/lookup3.rs | 2 +- .../std/lookup/rs/src/pil_helpers/traces.rs | 13 +-- .../std/permutation/rs/src/permutation1_6.rs | 4 +- .../std/permutation/rs/src/permutation1_7.rs | 2 +- .../std/permutation/rs/src/permutation1_8.rs | 2 +- .../std/permutation/rs/src/permutation2.rs | 2 +- .../permutation/rs/src/pil_helpers/traces.rs | 9 +- .../range_check/rs/src/multi_range_check1.rs | 2 +- .../range_check/rs/src/multi_range_check2.rs | 2 +- .../range_check/rs/src/pil_helpers/traces.rs | 25 ++--- .../std/range_check/rs/src/range_check1.rs | 2 +- .../std/range_check/rs/src/range_check2.rs | 2 +- .../std/range_check/rs/src/range_check3.rs | 2 +- .../std/range_check/rs/src/range_check4.rs | 2 +- .../rs/src/range_check_dynamic1.rs | 2 +- .../rs/src/range_check_dynamic2.rs | 2 +- .../std/range_check/rs/src/range_check_mix.rs | 2 +- 48 files changed, 284 insertions(+), 184 deletions(-) create mode 100644 common/src/publics.rs delete mode 100644 examples/fibonacci-square/src/public_inputs.rs diff --git a/cli/assets/templates/pil_helpers_trace.rs.tt b/cli/assets/templates/pil_helpers_trace.rs.tt index 3b0d39cd..f2cec07c 100644 --- a/cli/assets/templates/pil_helpers_trace.rs.tt +++ b/cli/assets/templates/pil_helpers_trace.rs.tt @@ -14,23 +14,32 @@ pub const { constant.0 }_AIRGROUP_ID: usize = { constant.1 }; {{ for constant in constant_airs }} pub const { constant.0 }_AIR_IDS: &[usize] = &[{ constant.3 }]; {{ endfor }} - {{ for public_values in publics }} +//PUBLICS +use serde::Deserialize; +use serde::Serialize; +#[derive(Default, Debug, Serialize, Deserialize)] +pub struct {project_name}Publics \{ + {{ for column in public_values.values_u64 }} #[serde(default)] pub {column.name}: {column.type},{{ endfor }} +} + values!({ project_name }PublicValues \{ {{ for column in public_values.values }} { column.name }: { column.type },{{ endfor }} }); -{{ endfor }} -{{ for proof_vals in proof_values }} +{{ endfor }} {{ for proof_vals in proof_values }} values!({ project_name }ProofValues \{ {{ for column in proof_vals.values }} { column.name }: { column.type },{{ endfor }} }); -{{ endfor }} -{{ for air_group in air_groups }}{{ for air in air_group.airs }} +{{ endfor }} {{ for air_group in air_groups }}{{ for air in air_group.airs }} trace!({ air.name }Trace \{ {{ for column in air.columns }} { column.name }: { column.type },{{ endfor }} -}, { air_group.airgroup_id }, { air.id }, { air.num_rows } ); +}, { air_group.airgroup_id }, { air.id }, { air.num_rows }, 0 ); {{ endfor }}{{ endfor }}{{ for air_group in air_groups }}{{ for air in air_group.airs }}{{ for custom_commit in air.custom_columns }} trace!({ air.name }{custom_commit.name}Trace \{ {{ for column in custom_commit.custom_columns }} { column.name }: { column.type },{{ endfor }} -}, { air_group.airgroup_id }, { air.id }, { air.num_rows } ); +}, { air_group.airgroup_id }, { air.id }, { air.num_rows }, { custom_commit.commit_id } ); +{{ endfor }}{{ endfor }}{{ endfor }}{{ for air_group in air_groups }}{{ for air in air_group.airs }}{{ for air_values in air.air_values }} +values!({ air.name }AirValues \{ +{{ for column in air_values.values }} { column.name }: { column.type },{{ endfor }} +}); {{ endfor }}{{ endfor }}{{ endfor }} \ No newline at end of file diff --git a/cli/src/commands/pil_helpers.rs b/cli/src/commands/pil_helpers.rs index f9e933b5..e1581929 100644 --- a/cli/src/commands/pil_helpers.rs +++ b/cli/src/commands/pil_helpers.rs @@ -60,6 +60,7 @@ struct AirCtx { #[derive(Debug, Serialize)] struct ValuesCtx { values: Vec, + values_u64: Vec, } #[derive(Debug, Serialize)] @@ -174,14 +175,25 @@ impl PilHelpersCmd { }; if symbol.r#type == SymbolType::ProofValue as i32 { if proof_values.is_empty() { - proof_values.push(ValuesCtx { values: Vec::new() }); + proof_values.push(ValuesCtx { values: Vec::new(), values_u64: Vec::new() }); } proof_values[0].values.push(ColumnCtx { name: name.to_owned(), r#type }); } else { if publics.is_empty() { - publics.push(ValuesCtx { values: Vec::new() }); + publics.push(ValuesCtx { values: Vec::new(), values_u64: Vec::new() }); } publics[0].values.push(ColumnCtx { name: name.to_owned(), r#type }); + let r#type_64 = if symbol.lengths.is_empty() { + "u64".to_string() // Case when lengths.len() == 0 + } else { + // Start with "u64" and apply each length in reverse order + symbol + .lengths + .iter() + .rev() + .fold("u64".to_string(), |acc, &length| format!("[{}; {}]", acc, length)) + }; + publics[0].values_u64.push(ColumnCtx { name: name.to_owned(), r#type: r#type_64 }); } }); @@ -232,12 +244,12 @@ impl PilHelpersCmd { air.columns.push(ColumnCtx { name: name.to_owned(), r#type }); } else if symbol.r#type == SymbolType::AirValue as i32 { if air.air_values.is_empty() { - air.air_values.push(ValuesCtx { values: Vec::new() }); + air.air_values.push(ValuesCtx { values: Vec::new(), values_u64: Vec::new() }); } air.air_values[0].values.push(ColumnCtx { name: name.to_owned(), r#type }); } else if symbol.r#type == SymbolType::AirGroupValue as i32 { if air.airgroup_values.is_empty() { - air.airgroup_values.push(ValuesCtx { values: Vec::new() }); + air.airgroup_values.push(ValuesCtx { values: Vec::new(), values_u64: Vec::new() }); } air.airgroup_values[0].values.push(ColumnCtx { name: name.to_owned(), r#type }); } else { diff --git a/common/src/air_instance.rs b/common/src/air_instance.rs index 1ee101a5..844b279b 100644 --- a/common/src/air_instance.rs +++ b/common/src/air_instance.rs @@ -4,7 +4,7 @@ use p3_field::Field; use proofman_starks_lib_c::get_custom_commit_map_ids_c; use proofman_util::create_buffer_fast; -use crate::{trace::Trace, ProofCtx, ExecutionCtx, SetupCtx, StarkInfo}; +use crate::{trace::Trace, trace::Values, ProofCtx, ExecutionCtx, SetupCtx, Setup, StarkInfo}; #[repr(C)] pub struct StepsParams { @@ -58,6 +58,12 @@ impl CustomCommitsInfo { } } +#[derive(Default, Clone)] +pub struct ValuesInfo { + pub buffer: Vec, + pub calculated: HashMap, +} + /// Air instance context for managing air instances (traces) #[allow(dead_code)] #[repr(C)] @@ -90,28 +96,12 @@ impl AirInstance { airgroup_id: usize, air_id: usize, witness: Vec, + witness_custom: Option>>, + air_values: Option>>, ) -> Self { let ps = setup_ctx.get_setup(airgroup_id, air_id); - let n_custom_commits = ps.stark_info.custom_commits.len(); - let custom_commits_calculated = vec![HashMap::new(); n_custom_commits]; - - let mut custom_commits = Vec::new(); - let mut custom_commits_extended = Vec::new(); - - for i in 0..n_custom_commits { - let n_cols = - *ps.stark_info.map_sections_n.get(&(ps.stark_info.custom_commits[i].name.clone() + "0")).unwrap() - as usize; - custom_commits.push(CustomCommitsInfo::new( - create_buffer_fast((1 << ps.stark_info.stark_struct.n_bits) * n_cols), - PathBuf::new(), - )); - custom_commits_extended.push(CustomCommitsInfo::new( - create_buffer_fast((1 << ps.stark_info.stark_struct.n_bits_ext) * n_cols), - PathBuf::new(), - )); - } + let (custom_commits, custom_commits_extended, custom_commits_calculated) = Self::init_custom_commits(ps, witness_custom); AirInstance { airgroup_id, @@ -124,13 +114,13 @@ impl AirInstance { trace: None, custom_commits, custom_commits_extended, + custom_commits_calculated, airgroup_values: vec![F::zero(); ps.stark_info.airgroupvalues_map.as_ref().unwrap().len() * 3], airvalues: vec![F::zero(); ps.stark_info.airvalues_map.as_ref().unwrap().len() * 3], + airvalue_calculated: HashMap::new(), evals: vec![F::zero(); ps.stark_info.ev_map.len() * 3], commits_calculated: HashMap::new(), airgroupvalue_calculated: HashMap::new(), - airvalue_calculated: HashMap::new(), - custom_commits_calculated, stark_info: ps.stark_info.clone(), } } @@ -141,20 +131,69 @@ impl AirInstance { setup_ctx: Arc, air_segment_id: Option, trace: &mut dyn Trace, - ) -> Self { + traces_custom: Option<&mut Vec<&mut dyn Trace>>, + air_values: Option<&mut dyn Values>, + ) { let airgroup_id = trace.airgroup_id(); let air_id = trace.air_id(); - let witness = trace.detach_buffer(); + let witness = trace.get_buffer(); + + let custom_witnesses = if let Some(custom_traces) = traces_custom { + let mut custom_witnesses = Vec::new(); + for custom_trace in custom_traces.iter_mut() { + custom_witnesses.push(custom_trace.get_buffer()); + } + Some(custom_witnesses) + } else { + None + }; + + // let air_values_info = if let Some(air_values) = air_vals { - let air_instance = AirInstance::new(setup_ctx, air_segment_id, airgroup_id, air_id, witness); + // }; + + let air_instance = AirInstance::new(setup_ctx, air_segment_id, airgroup_id, air_id, witness, custom_witnesses, None); let (is_mine, gid) = execution_ctx.dctx.write().unwrap().add_instance(air_instance.airgroup_id, air_instance.air_id, 1); + if is_mine { - proof_ctx.air_instance_repo.add_air_instance(air_instance.clone(), Some(gid)); + proof_ctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); + } + } + + pub fn init_custom_commits(setup: &Setup, witness_custom: Option>>) -> (Vec>, Vec>, Vec>) { + let n_custom_commits = setup.stark_info.custom_commits.len(); + let mut custom_commits_calculated = vec![HashMap::new(); n_custom_commits]; + + let mut custom_commits = Vec::new(); + let mut custom_commits_extended = Vec::new(); + + for commit_id in 0..n_custom_commits { + let n_cols = + *setup.stark_info.map_sections_n.get(&(setup.stark_info.custom_commits[commit_id].name.clone() + "0")).unwrap() + as usize; + if let Some(witness_custom_value) = witness_custom.as_ref() { + custom_commits.push(CustomCommitsInfo::new( + witness_custom_value[commit_id].clone(), + PathBuf::new(), + )); + } else { + println!("No custom trace data found."); + } + + let ids = get_custom_commit_map_ids_c(setup.p_setup.p_stark_info, commit_id as u64, 0); + for idx in ids { + custom_commits_calculated[commit_id].insert(idx as usize, true); + } + + custom_commits_extended.push(CustomCommitsInfo::new( + create_buffer_fast((1 << setup.stark_info.stark_struct.n_bits_ext) * n_cols), + PathBuf::new(), + )); } - air_instance + (custom_commits, custom_commits_extended, custom_commits_calculated) } pub fn get_witness_ptr(&self) -> *mut u8 { diff --git a/common/src/lib.rs b/common/src/lib.rs index 26378a65..b737f087 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -10,6 +10,7 @@ mod setup; mod setup_ctx; mod std_mode; mod custom_commits; +mod publics; pub mod trace; pub mod global_info; pub mod stark_info; @@ -29,6 +30,7 @@ pub use setup_ctx::*; pub use custom_commits::*; pub use stark_info::*; pub use std_mode::*; +pub use publics::*; pub fn initialize_logger(verbose_mode: VerboseMode) { env_logger::builder() diff --git a/common/src/proof_ctx.rs b/common/src/proof_ctx.rs index 0560cb06..26223404 100644 --- a/common/src/proof_ctx.rs +++ b/common/src/proof_ctx.rs @@ -161,7 +161,7 @@ impl ProofCtx { pub fn set_proof_value_calculated(&self, id: usize) { self.proof_values.values_set.write().unwrap().insert(id, true); } - + pub fn set_public_value(&self, value: u64, public_id: u64) { self.public_inputs.inputs.write().unwrap()[(public_id as usize) * 8..(public_id as usize + 1) * 8] .copy_from_slice(&value.to_le_bytes()); diff --git a/common/src/publics.rs b/common/src/publics.rs new file mode 100644 index 00000000..b0bbb1f9 --- /dev/null +++ b/common/src/publics.rs @@ -0,0 +1,24 @@ +use serde::de::DeserializeOwned; +use std::fs::File; +use std::io::Read; +use std::path::PathBuf; + +pub fn load_from_json(path: &Option) -> T { + if let Some(path) = &path { + // Open the file if the path is Some + let mut file = File::open(path).unwrap_or_else(|_| panic!("File not found at {:?}", path)); + + if !file.metadata().unwrap().is_file() { + panic!("{:?} is not a valid file", path); + } + + let mut contents = String::new(); + file.read_to_string(&mut contents).unwrap_or_else(|err| panic!("Failed to read file: {}", err)); + + // Deserialize the contents into the expected struct + serde_json::from_str(&contents).unwrap_or_else(|err| panic!("Failed to parse JSON: {}", err)) + } else { + // Return the default value if path is None + T::default() + } +} diff --git a/common/src/trace.rs b/common/src/trace.rs index c57ebdea..ab0d9189 100644 --- a/common/src/trace.rs +++ b/common/src/trace.rs @@ -1,15 +1,23 @@ use p3_field::Field; +use std::collections::HashMap; pub trait Trace: Send { fn num_rows(&self) -> usize; fn airgroup_id(&self) -> usize; fn air_id(&self) -> usize; - fn detach_buffer(&mut self) -> Vec; - fn get_buffer_ptr(&mut self) -> *mut u8; + fn get_buffer(&mut self) -> Vec; +} + +pub trait Values: Send { + fn num_values(&self) -> usize; + fn get_buffer(&mut self) -> Vec; + fn get_values_calculated(&mut self) -> HashMap; } pub use proofman_macros::trace; +pub use proofman_macros::values; + #[cfg(test)] use crate as common; diff --git a/examples/fibonacci-square/pil/fibonaccisq.pil b/examples/fibonacci-square/pil/fibonaccisq.pil index 781cd13d..85ee0b02 100644 --- a/examples/fibonacci-square/pil/fibonaccisq.pil +++ b/examples/fibonacci-square/pil/fibonaccisq.pil @@ -36,7 +36,7 @@ airtemplate FibonacciSquare(const int N = 2**8) { (a' - b) * (1 - L1') === 0; - 2*fibo1[0] - fibo1[1] === 0; + // 2*fibo1[0] - fibo1[1] === 0; line - (flags + 1) === 0; diff --git a/examples/fibonacci-square/src/fibonacci.rs b/examples/fibonacci-square/src/fibonacci.rs index 8711b142..3dfe4176 100644 --- a/examples/fibonacci-square/src/fibonacci.rs +++ b/examples/fibonacci-square/src/fibonacci.rs @@ -1,11 +1,11 @@ use std::sync::Arc; -use proofman_common::{get_custom_commit_id, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use proofman::{WitnessManager, WitnessComponent}; use p3_field::PrimeField; -use crate::{FibonacciSquareTrace, FibonacciSquareRomTrace, Module, FIBONACCI_SQUARE_AIRGROUP_ID, FIBONACCI_SQUARE_AIR_IDS}; +use crate::{FibonacciSquareRomTrace, FibonacciSquareAirValues, FibonacciSquareTrace, Module, FIBONACCI_SQUARE_AIRGROUP_ID, FIBONACCI_SQUARE_AIR_IDS}; pub struct FibonacciSquare { module: Arc>, @@ -55,9 +55,8 @@ impl FibonacciSquare { } let mut trace_rom = FibonacciSquareRomTrace::new_zeroes(); - let commit_id = get_custom_commit_id(&sctx, FIBONACCI_SQUARE_AIRGROUP_ID, FIBONACCI_SQUARE_AIR_IDS[0], "rom"); - for i in 0..trace.num_rows() { + for i in 0..trace_rom.num_rows() { trace_rom[i].line = F::from_canonical_u64(3 + i as u64); trace_rom[i].flags = F::from_canonical_u64(2 + i as u64); } @@ -67,13 +66,11 @@ impl FibonacciSquare { pctx.set_proof_value("value1", F::from_canonical_u64(5)); pctx.set_proof_value("value2", F::from_canonical_u64(125)); - let mut air_instance = AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), Some(0), &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), Some(0), &mut trace, Some(&mut vec![&mut trace_rom]), None); - air_instance.set_airvalue("FibonacciSquare.fibo1", Some(vec![0]), F::from_canonical_u64(1)); - air_instance.set_airvalue("FibonacciSquare.fibo1", Some(vec![1]), F::from_canonical_u64(2)); - air_instance.set_airvalue_ext("FibonacciSquare.fibo3", None, vec![F::from_canonical_u64(5); 3]); - - air_instance.set_custom_commit_id_buffer(&sctx, trace_rom.detach_buffer(), commit_id); + // air_instance.set_airvalue("FibonacciSquare.fibo1", Some(vec![0]), F::from_canonical_u64(1)); + // air_instance.set_airvalue("FibonacciSquare.fibo1", Some(vec![1]), F::from_canonical_u64(2)); + // air_instance.set_airvalue_ext("FibonacciSquare.fibo3", None, vec![F::from_canonical_u64(5); 3]); Ok(b) } diff --git a/examples/fibonacci-square/src/fibonacci_lib.rs b/examples/fibonacci-square/src/fibonacci_lib.rs index f210712a..3cc993d6 100644 --- a/examples/fibonacci-square/src/fibonacci_lib.rs +++ b/examples/fibonacci-square/src/fibonacci_lib.rs @@ -1,7 +1,6 @@ -use std::io::Read; -use std::{fs::File, sync::Arc}; +use std::sync::Arc; -use proofman_common::{initialize_logger, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode}; +use proofman_common::{initialize_logger, load_from_json, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode}; use proofman::{WitnessLibrary, WitnessManager}; use pil_std_lib::Std; use p3_field::PrimeField; @@ -9,9 +8,8 @@ use p3_goldilocks::Goldilocks; use std::error::Error; use std::path::PathBuf; -use crate::FibonacciSquarePublics; -use crate::{FibonacciSquare, Module}; +use crate::{BuildPublics, FibonacciSquare, Module}; pub struct FibonacciWitness { public_inputs_path: Option, @@ -40,26 +38,11 @@ impl WitnessLibrary for FibonacciWitness { self.module = Some(module); self.std_lib = Some(std_lib); - let public_inputs: FibonacciSquarePublics = if let Some(path) = &self.public_inputs_path { - let mut file = File::open(path).unwrap(); - - if !file.metadata().unwrap().is_file() { - panic!("Public inputs file not found"); - } - - let mut contents = String::new(); - - let _ = - file.read_to_string(&mut contents).map_err(|err| format!("Failed to read public inputs file: {}", err)); - - serde_json::from_str(&contents).unwrap() - } else { - FibonacciSquarePublics::default() - }; + let public_inputs: BuildPublics = load_from_json(&self.public_inputs_path); pctx.set_public_value_by_name(public_inputs.module, "module", None); - pctx.set_public_value_by_name(public_inputs.a, "in1", None); - pctx.set_public_value_by_name(public_inputs.b, "in2", None); + pctx.set_public_value_by_name(public_inputs.in1, "in1", None); + pctx.set_public_value_by_name(public_inputs.in2, "in2", None); wcm.start_proof(pctx, ectx, sctx); } diff --git a/examples/fibonacci-square/src/inputs.json b/examples/fibonacci-square/src/inputs.json index 02ed73de..e21c9f87 100644 --- a/examples/fibonacci-square/src/inputs.json +++ b/examples/fibonacci-square/src/inputs.json @@ -1,5 +1,5 @@ { - "a": 0, - "b": 2, + "in1": 0, + "in2": 2, "module": 25 } \ No newline at end of file diff --git a/examples/fibonacci-square/src/lib.rs b/examples/fibonacci-square/src/lib.rs index c13b75c2..0badce4a 100644 --- a/examples/fibonacci-square/src/lib.rs +++ b/examples/fibonacci-square/src/lib.rs @@ -2,10 +2,8 @@ mod pil_helpers; mod fibonacci_lib; mod fibonacci; mod module; -mod public_inputs; pub use pil_helpers::*; pub use fibonacci_lib::*; pub use fibonacci::*; pub use module::*; -pub use public_inputs::*; diff --git a/examples/fibonacci-square/src/module.rs b/examples/fibonacci-square/src/module.rs index b31e71a9..f5a5445c 100644 --- a/examples/fibonacci-square/src/module.rs +++ b/examples/fibonacci-square/src/module.rs @@ -71,7 +71,7 @@ impl Module self.std_lib.range_check(F::from_canonical_u64(module), F::one(), range); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), Some(0), &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), Some(0), &mut trace, None, None); self.std_lib.unregister_predecessor(pctx, None); } diff --git a/examples/fibonacci-square/src/pil_helpers/traces.rs b/examples/fibonacci-square/src/pil_helpers/traces.rs index 2224dd0b..c70e20ba 100644 --- a/examples/fibonacci-square/src/pil_helpers/traces.rs +++ b/examples/fibonacci-square/src/pil_helpers/traces.rs @@ -18,26 +18,39 @@ pub const MODULE_AIR_IDS: &[usize] = &[1]; pub const U_8_AIR_AIR_IDS: &[usize] = &[2]; + +//PUBLICS +use serde::Deserialize; +use serde::Serialize; +#[derive(Default, Debug, Serialize, Deserialize)] +pub struct BuildPublics { + #[serde(default)] pub module: u64, #[serde(default)] pub in1: u64, #[serde(default)] pub in2: u64, #[serde(default)] pub out: u64, #[serde(default)] pub rom_root: [u64; 4], +} + values!(BuildPublicValues { module: F, in1: F, in2: F, out: F, rom_root: [F; 4], }); - + values!(BuildProofValues { value1: F, value2: F, }); - + trace!(FibonacciSquareTrace { a: F, b: F, -}, 0, 0, 1024 ); +}, 0, 0, 1024, 0 ); trace!(ModuleTrace { x: F, q: F, x_mod: F, -}, 0, 1, 1024 ); +}, 0, 1, 1024, 0 ); trace!(U8AirTrace { mul: F, -}, 0, 2, 256 ); +}, 0, 2, 256, 0 ); trace!(FibonacciSquareRomTrace { line: F, flags: F, -}, 0, 0, 1024 ); +}, 0, 0, 1024, 0 ); + +values!(FibonacciSquareAirValues { + fibo1: [F; 2], fibo3: F, +}); diff --git a/examples/fibonacci-square/src/public_inputs.rs b/examples/fibonacci-square/src/public_inputs.rs deleted file mode 100644 index 60d7b5c4..00000000 --- a/examples/fibonacci-square/src/public_inputs.rs +++ /dev/null @@ -1,8 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[derive(Default, Debug, Serialize, Deserialize)] -pub struct FibonacciSquarePublics { - pub module: u64, - pub a: u64, - pub b: u64, -} diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 4814850a..b1ae841c 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -24,7 +24,7 @@ fn trace_impl(input: TokenStream2) -> Result { let airgroup_id = parsed_input.airgroup_id; let air_id = parsed_input.air_id; let num_rows = parsed_input.num_rows; - // let commit_id = parsed_input.commit_id; + let commit_id = parsed_input.commit_id; // Calculate ROW_SIZE based on the field types let row_size = fields @@ -64,15 +64,17 @@ fn trace_impl(input: TokenStream2) -> Result { // Generate trace struct let trace_struct = quote! { - pub struct #trace_struct_name<#generics> { - pub buffer: Vec<#row_struct_name<#generics>>, + pub struct #trace_struct_name<'a, #generics> { + pub buffer: Vec<#generics>, + pub slice_trace: &'a mut [#row_struct_name<#generics>], pub num_rows: usize, pub airgroup_id: usize, pub air_id: usize, // pub commit_id: Option, + pub commit_id: usize, } - impl<#generics: Default + Clone + Copy> #trace_struct_name<#generics> { + impl<'a, #generics: Default + Clone + Copy> #trace_struct_name<'a, #generics> { const NUM_ROWS: usize = #num_rows; const AIRGROUP_ID: usize = #airgroup_id; const AIR_ID: usize = #air_id; @@ -82,17 +84,27 @@ fn trace_impl(input: TokenStream2) -> Result { assert!(num_rows >= 2); assert!(num_rows & (num_rows - 1) == 0); - let mut buff_uninit: Vec>> = Vec::with_capacity(num_rows); + let mut buff_uninit: Vec> = Vec::with_capacity(num_rows * #row_struct_name::<#generics>::ROW_SIZE); + unsafe { - buff_uninit.set_len(num_rows); + buff_uninit.set_len(num_rows * #row_struct_name::<#generics>::ROW_SIZE); } - let buffer: Vec<#row_struct_name<#generics>> = unsafe { std::mem::transmute(buff_uninit) }; + let buffer: Vec<#generics> = unsafe { std::mem::transmute(buff_uninit) }; + + let slice_trace = unsafe { + std::slice::from_raw_parts_mut( + buffer.as_ptr() as *mut #row_struct_name<#generics>, + num_rows, + ) + }; #trace_struct_name { buffer, + slice_trace, num_rows, airgroup_id: Self::AIRGROUP_ID, air_id: Self::AIR_ID, + commit_id: #commit_id, } } @@ -101,13 +113,21 @@ fn trace_impl(input: TokenStream2) -> Result { assert!(num_rows >= 2); assert!(num_rows & (num_rows - 1) == 0); - let buffer = vec![#row_struct_name::<#generics>::default(); num_rows]; - + let buffer = vec![#generics::default(); num_rows * #row_struct_name::<#generics>::ROW_SIZE]; + let slice_trace = unsafe { + std::slice::from_raw_parts_mut( + buffer.as_ptr() as *mut #row_struct_name<#generics>, + num_rows, + ) + }; + #trace_struct_name { buffer, + slice_trace, num_rows, airgroup_id: Self::AIRGROUP_ID, air_id: Self::AIR_ID, + commit_id: #commit_id, } } @@ -123,28 +143,27 @@ fn trace_impl(input: TokenStream2) -> Result { self.air_id } - pub fn detach_buffer(&mut self) -> Vec<#generics> { + pub fn get_buffer(&mut self) -> Vec<#generics> { let buffer = std::mem::take(&mut self.buffer); - let buffer: Vec<#generics> = unsafe { std::mem::transmute(buffer) }; buffer } } - impl<#generics> std::ops::Index for #trace_struct_name<#generics> { + impl<'a, #generics> std::ops::Index for #trace_struct_name<'a, #generics> { type Output = #row_struct_name<#generics>; fn index(&self, index: usize) -> &Self::Output { - &self.buffer[index] + &self.slice_trace[index] } } - impl<#generics> std::ops::IndexMut for #trace_struct_name<#generics> { + impl<'a, #generics> std::ops::IndexMut for #trace_struct_name<'a, #generics> { fn index_mut(&mut self, index: usize) -> &mut Self::Output { - &mut self.buffer[index] + &mut self.slice_trace[index] } } - impl<#generics: Send + p3_field::Field> common::trace::Trace<#generics> for #trace_struct_name<#generics> { + impl<'a, #generics: Send + p3_field::Field> common::trace::Trace<#generics> for #trace_struct_name<'a, #generics> { fn num_rows(&self) -> usize { self.num_rows } @@ -157,15 +176,10 @@ fn trace_impl(input: TokenStream2) -> Result { self.air_id } - fn detach_buffer(&mut self) -> Vec<#generics> { + fn get_buffer(&mut self) -> Vec<#generics> { let buffer = std::mem::take(&mut self.buffer); - let buffer: Vec<#generics> = unsafe { std::mem::transmute(buffer) }; buffer - } - - fn get_buffer_ptr(&mut self) -> *mut u8 { - self.buffer.as_mut_ptr() as *mut u8 - } + } } }; @@ -184,7 +198,8 @@ struct ParsedTraceInput { airgroup_id: LitInt, air_id: LitInt, num_rows: LitInt, - // commit_id: Option, + //commit_id: Option, + commit_id: LitInt, } impl Parse for ParsedTraceInput { @@ -215,9 +230,12 @@ impl Parse for ParsedTraceInput { input.parse::()?; let num_rows = input.parse::()?; - // let commit_id: Option = if input.peek(Token![,]) { + input.parse::()?; + let commit_id = input.parse::()?; + + // let commit_id = if input.peek(Token![,]) { // input.parse::()?; - // Some(input.parse()?) + // Some(input.parse::()?) // } else { // None // }; @@ -229,7 +247,8 @@ impl Parse for ParsedTraceInput { fields, airgroup_id, air_id, - num_rows, /*, commit_id */ + num_rows, + commit_id }) } } @@ -284,14 +303,13 @@ fn values_impl(input: TokenStream2) -> Result { let row_struct = quote! { #[repr(C)] - #[derive(Debug, Clone, Copy, Default)] + #[derive(Debug, Clone, Default)] pub struct #struct_name<#generic_param> { #(#field_definitions)* - } - + } impl<#generic_param: Copy> #struct_name<#generic_param> { pub const ROW_SIZE: usize = #row_size; - + pub fn as_slice(&self) -> &[#generic_param] { unsafe { std::slice::from_raw_parts( @@ -388,7 +406,7 @@ fn test_parsing_01() { assert_eq!(parsed.row_struct_name, "TraceRow"); assert_eq!(parsed.struct_name, "MyTrace"); assert_eq!(parsed.num_rows.base10_parse::().unwrap(), 34); - //assert_eq!(parsed.commit_id.unwrap().base10_parse::().unwrap(), 38); + assert_eq!(parsed.commit_id.unwrap().base10_parse::().unwrap(), 38); } #[test] diff --git a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs index 04abb0c2..0a4f1057 100644 --- a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs +++ b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs @@ -133,7 +133,7 @@ impl SpecifiedRanges { let num_rows = pctx.global_info.airs[self.airgroup_id][self.air_id].num_rows; let buffer_size = multiplicities.len() * num_rows; let buffer: Vec = create_buffer_fast(buffer_size); - let air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer); + let air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer, None, None); pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)); pctx.air_instance_repo.air_instances.read().unwrap().len() - 1 }; @@ -295,7 +295,7 @@ impl WitnessComponent for SpecifiedRanges { let buffer = create_buffer_fast(buffer_size as usize); // Add a new air instance. Since Specified Ranges is a table, only this air instance is needed - let mut air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer); + let mut air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer, None, None); let mut mul_columns_guard = self.mul_columns.lock().unwrap(); for hint in hints_guard[1..].iter() { mul_columns_guard.push(get_hint_field::( diff --git a/pil2-components/lib/std/rs/src/range_check/u16air.rs b/pil2-components/lib/std/rs/src/range_check/u16air.rs index 464861b0..d754a342 100644 --- a/pil2-components/lib/std/rs/src/range_check/u16air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u16air.rs @@ -117,7 +117,7 @@ impl U16Air { let num_rows = pctx.global_info.airs[self.airgroup_id][self.air_id].num_rows; let buffer_size = num_rows; let buffer: Vec = create_buffer_fast(buffer_size); - let air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer); + let air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer, None, None); pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)); pctx.air_instance_repo.air_instances.read().unwrap().len() - 1 }; @@ -170,7 +170,7 @@ impl WitnessComponent for U16Air { let buffer = create_buffer_fast(buffer_size); // Add a new air instance. Since U16Air is a table, only this air instance is needed - let mut air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer); + let mut air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer, None, None); *self.mul_column.lock().unwrap() = get_hint_field::( &self.wcm.get_sctx(), diff --git a/pil2-components/lib/std/rs/src/range_check/u8air.rs b/pil2-components/lib/std/rs/src/range_check/u8air.rs index c3e2632f..cf26eaa3 100644 --- a/pil2-components/lib/std/rs/src/range_check/u8air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u8air.rs @@ -115,7 +115,7 @@ impl U8Air { let num_rows = pctx.global_info.airs[self.airgroup_id][self.air_id].num_rows; let buffer_size = num_rows; let buffer: Vec = create_buffer_fast(buffer_size); - let air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer); + let air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer, None, None); pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)); pctx.air_instance_repo.air_instances.read().unwrap().len() - 1 }; @@ -167,7 +167,7 @@ impl WitnessComponent for U8Air { let buffer = create_buffer_fast(buffer_size); // Add a new air instance. Since U8Air is a table, only this air instance is needed - let mut air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer); + let mut air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer, None, None); *self.mul_column.lock().unwrap() = get_hint_field::( &sctx, diff --git a/pil2-components/test/simple/rs/src/pil_helpers/traces.rs b/pil2-components/test/simple/rs/src/pil_helpers/traces.rs index e7fd6467..383beb4b 100644 --- a/pil2-components/test/simple/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/simple/rs/src/pil_helpers/traces.rs @@ -16,10 +16,11 @@ pub const SIMPLE_LEFT_AIR_IDS: &[usize] = &[0]; pub const SIMPLE_RIGHT_AIR_IDS: &[usize] = &[1]; + trace!(SimpleLeftTrace { a: F, b: F, c: F, d: F, e: F, f: F, g: F, h: F, -}, 0, 0, 4 ); +}, 0, 0, 4, 0 ); trace!(SimpleRightTrace { a: F, b: F, c: F, d: F, mul: F, -}, 0, 1, 4 ); +}, 0, 1, 4, 0 ); diff --git a/pil2-components/test/simple/rs/src/simple_left.rs b/pil2-components/test/simple/rs/src/simple_left.rs index 77002940..2150c850 100644 --- a/pil2-components/test/simple/rs/src/simple_left.rs +++ b/pil2-components/test/simple/rs/src/simple_left.rs @@ -56,7 +56,7 @@ where trace[i].d = trace[indices[i]].b; } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/simple/rs/src/simple_right.rs b/pil2-components/test/simple/rs/src/simple_right.rs index 77e3c5c7..9c0f9c13 100644 --- a/pil2-components/test/simple/rs/src/simple_right.rs +++ b/pil2-components/test/simple/rs/src/simple_right.rs @@ -43,7 +43,7 @@ where trace[i].mul = F::from_canonical_usize(1); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/connection/rs/src/connection1.rs b/pil2-components/test/std/connection/rs/src/connection1.rs index c1269411..ec459d4a 100644 --- a/pil2-components/test/std/connection/rs/src/connection1.rs +++ b/pil2-components/test/std/connection/rs/src/connection1.rs @@ -40,7 +40,7 @@ where trace[i].c = rng.gen(); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/connection/rs/src/connection2.rs b/pil2-components/test/std/connection/rs/src/connection2.rs index 79f5521f..1a31cc9c 100644 --- a/pil2-components/test/std/connection/rs/src/connection2.rs +++ b/pil2-components/test/std/connection/rs/src/connection2.rs @@ -42,7 +42,7 @@ where trace[0].a = trace[1].a; - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/connection/rs/src/connection_new.rs b/pil2-components/test/std/connection/rs/src/connection_new.rs index 3e734d4a..32f03288 100644 --- a/pil2-components/test/std/connection/rs/src/connection_new.rs +++ b/pil2-components/test/std/connection/rs/src/connection_new.rs @@ -133,7 +133,7 @@ where } } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/connection/rs/src/pil_helpers/traces.rs b/pil2-components/test/std/connection/rs/src/pil_helpers/traces.rs index 08fde45e..0d3bb6a9 100644 --- a/pil2-components/test/std/connection/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/std/connection/rs/src/pil_helpers/traces.rs @@ -18,14 +18,15 @@ pub const CONNECTION_2_AIR_IDS: &[usize] = &[1]; pub const CONNECTION_NEW_AIR_IDS: &[usize] = &[2]; + trace!(Connection1Trace { a: F, b: F, c: F, -}, 0, 0, 8 ); +}, 0, 0, 8, 0 ); trace!(Connection2Trace { a: F, b: F, c: F, -}, 0, 1, 16 ); +}, 0, 1, 16, 0 ); trace!(ConnectionNewTrace { a: [F; 6], b: [F; 6], c: [F; 6], d: [F; 6], -}, 0, 2, 16 ); +}, 0, 2, 16, 0 ); diff --git a/pil2-components/test/std/lookup/rs/src/lookup0.rs b/pil2-components/test/std/lookup/rs/src/lookup0.rs index 15801a7c..25afa180 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup0.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup0.rs @@ -53,7 +53,7 @@ where } } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup1.rs b/pil2-components/test/std/lookup/rs/src/lookup1.rs index 42021f4d..709cd001 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup1.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup1.rs @@ -51,7 +51,7 @@ where trace[i].mul = F::from_canonical_usize(n_sel); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs index 053e6cdb..bc14c125 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs @@ -63,7 +63,7 @@ where trace[i].sel2 = F::from_bool(true); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs index f4d8bdb6..136592e1 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs @@ -63,7 +63,7 @@ where trace[i].sel2 = F::from_bool(true); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs index 8f9e5145..c3e9cd55 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs @@ -63,7 +63,7 @@ where trace[i].sel2 = F::from_bool(true); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup3.rs b/pil2-components/test/std/lookup/rs/src/lookup3.rs index 6d12c6ce..7eddf16d 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup3.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup3.rs @@ -51,7 +51,7 @@ impl Lookup3 { } } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/lookup/rs/src/pil_helpers/traces.rs b/pil2-components/test/std/lookup/rs/src/pil_helpers/traces.rs index 6d0bfca8..ae47e822 100644 --- a/pil2-components/test/std/lookup/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/std/lookup/rs/src/pil_helpers/traces.rs @@ -24,26 +24,27 @@ pub const LOOKUP_2_15_AIR_IDS: &[usize] = &[4]; pub const LOOKUP_3_AIR_IDS: &[usize] = &[5]; + trace!(Lookup0Trace { f: [F; 4], t: [F; 4], sel: [F; 2], mul: [F; 2], -}, 0, 0, 1024 ); +}, 0, 0, 1024, 0 ); trace!(Lookup1Trace { f: [F; 2], t: F, sel: [F; 2], mul: F, -}, 0, 1, 1024 ); +}, 0, 1, 1024, 0 ); trace!(Lookup2_12Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, mul: F, -}, 0, 2, 4096 ); +}, 0, 2, 4096, 0 ); trace!(Lookup2_13Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, mul: F, -}, 0, 3, 8192 ); +}, 0, 3, 8192, 0 ); trace!(Lookup2_15Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, mul: F, -}, 0, 4, 32768 ); +}, 0, 4, 32768, 0 ); trace!(Lookup3Trace { c1: F, d1: F, c2: F, d2: F, mul1: F, mul2: F, -}, 0, 5, 16384 ); +}, 0, 5, 16384, 0 ); diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs index d80bf456..a6d28b3a 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs @@ -70,9 +70,9 @@ where trace[i].sel2 = trace[indices[i]].sel1; } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs index 3c64bca2..0e743a09 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs @@ -70,7 +70,7 @@ where trace[i].sel2 = trace[i].sel1; } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs index b75c243b..7336d08a 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs @@ -70,7 +70,7 @@ where trace[i].sel2 = trace[i].sel1; } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation2.rs b/pil2-components/test/std/permutation/rs/src/permutation2.rs index eea0b3df..56080c06 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation2.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation2.rs @@ -42,7 +42,7 @@ impl Permutation2 { trace[i].sel = F::from_bool(true); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs b/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs index a6406fb5..f4d74870 100644 --- a/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs @@ -20,18 +20,19 @@ pub const PERMUTATION_1_8_AIR_IDS: &[usize] = &[2]; pub const PERMUTATION_2_6_AIR_IDS: &[usize] = &[3]; + trace!(Permutation1_6Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, sel3: F, -}, 0, 0, 64 ); +}, 0, 0, 64, 0 ); trace!(Permutation1_7Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, sel3: F, -}, 0, 1, 128 ); +}, 0, 1, 128, 0 ); trace!(Permutation1_8Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, sel3: F, -}, 0, 2, 256 ); +}, 0, 2, 256, 0 ); trace!(Permutation2_6Trace { c1: F, d1: F, c2: F, d2: F, sel: F, -}, 0, 3, 512 ); +}, 0, 3, 512, 0 ); diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs index a6d03841..25b04fdd 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs @@ -102,7 +102,7 @@ where } } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs index 5090946b..2753b780 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs @@ -84,7 +84,7 @@ where } } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/range_check/rs/src/pil_helpers/traces.rs b/pil2-components/test/std/range_check/rs/src/pil_helpers/traces.rs index 8d95366c..bf630af7 100644 --- a/pil2-components/test/std/range_check/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/std/range_check/rs/src/pil_helpers/traces.rs @@ -56,50 +56,51 @@ pub const U_8_AIR_AIR_IDS: &[usize] = &[0]; pub const SPECIFIED_RANGES_AIR_IDS: &[usize] = &[0]; + trace!(RangeCheck3Trace { c1: F, c2: F, -}, 0, 0, 32 ); +}, 0, 0, 32, 0 ); trace!(RangeCheck2Trace { b1: F, b2: F, b3: F, -}, 1, 0, 16 ); +}, 1, 0, 16, 0 ); trace!(RangeCheck1Trace { a1: F, a2: F, a3: F, a4: F, a5: F, sel1: F, sel2: F, sel3: F, -}, 2, 0, 8 ); +}, 2, 0, 8, 0 ); trace!(RangeCheck4Trace { a1: F, a2: F, a3: F, a4: F, a5: F, a6: F, a7: F, a8: F, sel1: F, sel2: F, -}, 3, 0, 64 ); +}, 3, 0, 64, 0 ); trace!(U16AirTrace { mul: F, -}, 3, 1, 65536 ); +}, 3, 1, 65536, 0 ); trace!(MultiRangeCheck1Trace { a: [F; 3], sel: [F; 3], range_sel: [F; 3], -}, 4, 0, 8 ); +}, 4, 0, 8, 0 ); trace!(MultiRangeCheck2Trace { a: [F; 2], sel: [F; 2], range_sel: [F; 2], -}, 5, 0, 16 ); +}, 5, 0, 16, 0 ); trace!(RangeCheckDynamic1Trace { colu: F, sel_7: F, sel_8: F, sel_16: F, sel_17: F, -}, 6, 0, 256 ); +}, 6, 0, 256, 0 ); trace!(RangeCheckDynamic2Trace { colu: F, sel_1: F, sel_2: F, sel_3: F, sel_4: F, sel_5: F, -}, 7, 0, 64 ); +}, 7, 0, 64, 0 ); trace!(RangeCheckMixTrace { a: [F; 4], b: [F; 2], c: [F; 1], range_sel: [F; 5], -}, 8, 0, 64 ); +}, 8, 0, 64, 0 ); trace!(U8AirTrace { mul: F, -}, 9, 0, 256 ); +}, 9, 0, 256, 0 ); trace!(SpecifiedRangesTrace { mul: [F; 20], -}, 10, 0, 131072 ); +}, 10, 0, 131072, 0 ); diff --git a/pil2-components/test/std/range_check/rs/src/range_check1.rs b/pil2-components/test/std/range_check/rs/src/range_check1.rs index 0d2c2bf6..9685aa40 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check1.rs @@ -77,7 +77,7 @@ where } } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check2.rs b/pil2-components/test/std/range_check/rs/src/range_check2.rs index d0d206cf..3075779f 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check2.rs @@ -52,7 +52,7 @@ where self.std_lib.range_check(trace[i].b3, F::one(), range3); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check3.rs b/pil2-components/test/std/range_check/rs/src/range_check3.rs index 57ac11e6..c42bbec6 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check3.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check3.rs @@ -50,7 +50,7 @@ where self.std_lib.range_check(trace[i].c2, F::one(), range2); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check4.rs b/pil2-components/test/std/range_check/rs/src/range_check4.rs index 9ee2deba..e43d82fe 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check4.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check4.rs @@ -98,7 +98,7 @@ where self.std_lib.range_check(trace[i].a8, F::one(), range9); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs index e607fad5..5a159922 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs @@ -80,7 +80,7 @@ where } } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs index 03e8c066..5133dbf2 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs @@ -93,7 +93,7 @@ where } } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs index 1e74af04..cf8d82a9 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs @@ -134,7 +134,7 @@ where } } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace); + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); } } From 88dbc73d88c794c77603b1b19119615ddd92049d Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Thu, 5 Dec 2024 21:11:08 +0000 Subject: [PATCH 15/64] Keep working on cleaning --- common/src/air_instance.rs | 67 ++++++++++++++----- common/src/proof_ctx.rs | 19 ++---- examples/fibonacci-square/pil/fibonaccisq.pil | 4 +- examples/fibonacci-square/src/fibonacci.rs | 2 +- .../src/pil_helpers/traces.rs | 4 -- hints/src/hints.rs | 40 +++++------ proofman/src/proofman.rs | 2 +- provers/stark/src/stark_prover.rs | 32 ++++----- 8 files changed, 96 insertions(+), 74 deletions(-) diff --git a/common/src/air_instance.rs b/common/src/air_instance.rs index 844b279b..5ace47c4 100644 --- a/common/src/air_instance.rs +++ b/common/src/air_instance.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, os::raw::c_void, sync::Arc}; +use std::{os::raw::c_void, sync::Arc}; use std::path::PathBuf; use p3_field::Field; use proofman_starks_lib_c::get_custom_commit_map_ids_c; @@ -61,7 +61,7 @@ impl CustomCommitsInfo { #[derive(Default, Clone)] pub struct ValuesInfo { pub buffer: Vec, - pub calculated: HashMap, + pub calculated: Vec, } /// Air instance context for managing air instances (traces) @@ -75,17 +75,23 @@ pub struct AirInstance { pub air_instance_id: Option, pub idx: Option, pub global_idx: Option, + pub witness: Vec, pub trace: Option>, + pub commits_calculated: Vec, + pub custom_commits: Vec>, pub custom_commits_extended: Vec>, + pub custom_commits_calculated: Vec>, + pub airgroup_values: Vec, + pub airgroupvalue_calculated: Vec, + pub airvalues: Vec, + pub airvalue_calculated: Vec, + pub evals: Vec, - pub commits_calculated: HashMap, - pub airgroupvalue_calculated: HashMap, - pub airvalue_calculated: HashMap, - pub custom_commits_calculated: Vec>, + pub stark_info: StarkInfo, } @@ -112,15 +118,15 @@ impl AirInstance { global_idx: None, witness, trace: None, + commits_calculated: vec![false; ps.stark_info.cm_pols_map.as_ref().unwrap().len()], custom_commits, custom_commits_extended, custom_commits_calculated, airgroup_values: vec![F::zero(); ps.stark_info.airgroupvalues_map.as_ref().unwrap().len() * 3], + airgroupvalue_calculated: vec![false; ps.stark_info.airgroupvalues_map.as_ref().unwrap().len()], airvalues: vec![F::zero(); ps.stark_info.airvalues_map.as_ref().unwrap().len() * 3], - airvalue_calculated: HashMap::new(), + airvalue_calculated: vec![false; ps.stark_info.airgroupvalues_map.as_ref().unwrap().len()], evals: vec![F::zero(); ps.stark_info.ev_map.len() * 3], - commits_calculated: HashMap::new(), - airgroupvalue_calculated: HashMap::new(), stark_info: ps.stark_info.clone(), } } @@ -162,9 +168,9 @@ impl AirInstance { } } - pub fn init_custom_commits(setup: &Setup, witness_custom: Option>>) -> (Vec>, Vec>, Vec>) { + pub fn init_custom_commits(setup: &Setup, witness_custom: Option>>) -> (Vec>, Vec>, Vec>) { let n_custom_commits = setup.stark_info.custom_commits.len(); - let mut custom_commits_calculated = vec![HashMap::new(); n_custom_commits]; + let mut custom_commits_calculated = Vec::new(); let mut custom_commits = Vec::new(); let mut custom_commits_extended = Vec::new(); @@ -173,6 +179,7 @@ impl AirInstance { let n_cols = *setup.stark_info.map_sections_n.get(&(setup.stark_info.custom_commits[commit_id].name.clone() + "0")).unwrap() as usize; + custom_commits_calculated.push(vec![false; n_cols]); if let Some(witness_custom_value) = witness_custom.as_ref() { custom_commits.push(CustomCommitsInfo::new( witness_custom_value[commit_id].clone(), @@ -184,7 +191,7 @@ impl AirInstance { let ids = get_custom_commit_map_ids_c(setup.p_setup.p_stark_info, commit_id as u64, 0); for idx in ids { - custom_commits_calculated[commit_id].insert(idx as usize, true); + custom_commits_calculated[commit_id][idx as usize] = true; } custom_commits_extended.push(CustomCommitsInfo::new( @@ -200,6 +207,18 @@ impl AirInstance { self.witness.as_ptr() as *mut u8 } + pub fn get_evals_ptr(&self) -> *mut u8 { + self.evals.as_ptr() as *mut u8 + } + + pub fn get_airgroup_values_ptr(&self) -> *mut u8 { + self.airgroup_values.as_ptr() as *mut u8 + } + + pub fn get_airvalues_ptr(&self) -> *mut u8 { + self.airvalues.as_ptr() as *mut u8 + } + pub fn set_trace(&mut self, trace: Vec) { self.trace = Some(trace); } @@ -227,6 +246,22 @@ impl AirInstance { ptrs } + pub fn is_commit_initialized(&self, index: usize) -> bool { + self.commits_calculated[index] + } + + pub fn is_airgroup_value_initialized(&self, index: usize) -> bool { + self.airgroupvalue_calculated[index] + } + + pub fn is_airvalue_initialized(&self, index: usize) -> bool { + self.airvalue_calculated[index] + } + + pub fn is_custom_commit_initialized(&self, commit_id: usize, index: usize) -> bool { + self.custom_commits_calculated[commit_id][index] + } + pub fn set_custom_commit_cached_file(&mut self, setup_ctx: &SetupCtx, commit_id: u64, cached_file: PathBuf) { let ps = setup_ctx.get_setup(self.airgroup_id, self.air_id); @@ -364,11 +399,11 @@ impl AirInstance { } pub fn set_commit_calculated(&mut self, id: usize) { - self.commits_calculated.insert(id, true); + self.commits_calculated[id] = true; } pub fn set_custom_commit_calculated(&mut self, commit_id: usize, id: usize) { - self.custom_commits_calculated[commit_id].insert(id, true); + self.custom_commits_calculated[commit_id][id] = true; } pub fn set_air_instance_id(&mut self, air_instance_id: usize, idx: usize) { @@ -377,10 +412,10 @@ impl AirInstance { } pub fn set_airgroupvalue_calculated(&mut self, id: usize) { - self.airgroupvalue_calculated.insert(id, true); + self.airgroupvalue_calculated[id] = true; } pub fn set_airvalue_calculated(&mut self, id: usize) { - self.airvalue_calculated.insert(id, true); + self.airvalue_calculated[id] = true; } } diff --git a/common/src/proof_ctx.rs b/common/src/proof_ctx.rs index 26223404..f3b749fc 100644 --- a/common/src/proof_ctx.rs +++ b/common/src/proof_ctx.rs @@ -1,4 +1,3 @@ -use std::collections::HashMap; use std::sync::RwLock; use std::path::PathBuf; @@ -11,11 +10,6 @@ pub struct PublicInputs { pub inputs_set: RwLock>, } -impl Default for PublicInputs { - fn default() -> Self { - Self { inputs: RwLock::new(Vec::new()), inputs_set: RwLock::new(Vec::new()) } - } -} impl PublicInputs { pub fn new(n_publics: usize) -> Self { @@ -28,12 +22,12 @@ impl PublicInputs { pub struct ProofValues { pub values: RwLock>, - pub values_set: RwLock>, + pub values_set: RwLock>, } -impl Default for ProofValues { - fn default() -> Self { - Self { values: RwLock::new(Vec::new()), values_set: RwLock::new(HashMap::new()) } +impl ProofValues { + fn new(n_proof_values: usize) -> Self { + Self { values: RwLock::new(vec![F::zero(); n_proof_values * 3]), values_set: RwLock::new(vec![false; n_proof_values]) } } } @@ -95,10 +89,7 @@ impl ProofCtx { let global_info: GlobalInfo = GlobalInfo::new(&proving_key_path); - let proof_values = ProofValues { - values: RwLock::new(vec![F::zero(); global_info.n_proof_values * 3]), - values_set: RwLock::new(HashMap::new()), - }; + let proof_values = ProofValues::new(global_info.n_proof_values); let n_publics = global_info.n_publics; Self { global_info, diff --git a/examples/fibonacci-square/pil/fibonaccisq.pil b/examples/fibonacci-square/pil/fibonaccisq.pil index 85ee0b02..2b02f01e 100644 --- a/examples/fibonacci-square/pil/fibonaccisq.pil +++ b/examples/fibonacci-square/pil/fibonaccisq.pil @@ -20,8 +20,8 @@ on final proof checkProofValues(); airtemplate FibonacciSquare(const int N = 2**8) { commit stage(0) public(rom_root) rom; - airval fibo1[2]; - airval stage(2) fibo3; + // airval fibo1[2]; + // airval stage(2) fibo3; col fixed L1 = [1,0...]; col witness a,b; diff --git a/examples/fibonacci-square/src/fibonacci.rs b/examples/fibonacci-square/src/fibonacci.rs index 3dfe4176..64799d6a 100644 --- a/examples/fibonacci-square/src/fibonacci.rs +++ b/examples/fibonacci-square/src/fibonacci.rs @@ -5,7 +5,7 @@ use proofman::{WitnessManager, WitnessComponent}; use p3_field::PrimeField; -use crate::{FibonacciSquareRomTrace, FibonacciSquareAirValues, FibonacciSquareTrace, Module, FIBONACCI_SQUARE_AIRGROUP_ID, FIBONACCI_SQUARE_AIR_IDS}; +use crate::{FibonacciSquareRomTrace, FibonacciSquareTrace, Module, FIBONACCI_SQUARE_AIRGROUP_ID, FIBONACCI_SQUARE_AIR_IDS}; pub struct FibonacciSquare { module: Arc>, diff --git a/examples/fibonacci-square/src/pil_helpers/traces.rs b/examples/fibonacci-square/src/pil_helpers/traces.rs index c70e20ba..5efdfa3b 100644 --- a/examples/fibonacci-square/src/pil_helpers/traces.rs +++ b/examples/fibonacci-square/src/pil_helpers/traces.rs @@ -50,7 +50,3 @@ trace!(U8AirTrace { trace!(FibonacciSquareRomTrace { line: F, flags: F, }, 0, 0, 1024, 0 ); - -values!(FibonacciSquareAirValues { - fibo1: [F; 2], fibo3: F, -}); diff --git a/hints/src/hints.rs b/hints/src/hints.rs index f7d0a9ac..8f8692a5 100644 --- a/hints/src/hints.rs +++ b/hints/src/hints.rs @@ -693,9 +693,9 @@ pub fn mul_hint_fields( trace: air_instance.get_trace_ptr() as *mut c_void, public_inputs: public_inputs_ptr, challenges: challenges_ptr, - airgroup_values: air_instance.airgroup_values.as_ptr() as *mut c_void, - airvalues: air_instance.airvalues.as_ptr() as *mut c_void, - evals: air_instance.evals.as_ptr() as *mut c_void, + airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, + airvalues: air_instance.get_airvalues_ptr() as *mut c_void, + evals: air_instance.get_evals_ptr() as *mut c_void, xdivxsub: std::ptr::null_mut(), p_const_pols: const_pols_ptr, p_const_tree: const_tree_ptr, @@ -739,9 +739,9 @@ pub fn acc_hint_field( trace: air_instance.get_trace_ptr() as *mut c_void, public_inputs: public_inputs_ptr, challenges: challenges_ptr, - airgroup_values: air_instance.airgroup_values.as_ptr() as *mut c_void, - airvalues: air_instance.airvalues.as_ptr() as *mut c_void, - evals: air_instance.evals.as_ptr() as *mut c_void, + airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, + airvalues: air_instance.get_airvalues_ptr() as *mut c_void, + evals: air_instance.get_evals_ptr() as *mut c_void, xdivxsub: std::ptr::null_mut(), p_const_pols: const_pols_ptr, p_const_tree: const_tree_ptr, @@ -793,9 +793,9 @@ pub fn acc_mul_hint_fields( trace: air_instance.get_trace_ptr() as *mut c_void, public_inputs: public_inputs_ptr, challenges: challenges_ptr, - airgroup_values: air_instance.airgroup_values.as_ptr() as *mut c_void, - airvalues: air_instance.airvalues.as_ptr() as *mut c_void, - evals: air_instance.evals.as_ptr() as *mut c_void, + airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, + airvalues: air_instance.get_airvalues_ptr() as *mut c_void, + evals: air_instance.get_evals_ptr() as *mut c_void, xdivxsub: std::ptr::null_mut(), p_const_pols: const_pols_ptr, p_const_tree: const_tree_ptr, @@ -844,9 +844,9 @@ pub fn get_hint_field( trace: air_instance.get_trace_ptr() as *mut c_void, public_inputs: public_inputs_ptr, challenges: challenges_ptr, - airgroup_values: air_instance.airgroup_values.as_ptr() as *mut c_void, - airvalues: air_instance.airvalues.as_ptr() as *mut c_void, - evals: air_instance.evals.as_ptr() as *mut c_void, + airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, + airvalues: air_instance.get_airvalues_ptr() as *mut c_void, + evals: air_instance.get_evals_ptr() as *mut c_void, xdivxsub: std::ptr::null_mut(), p_const_pols: const_pols_ptr, p_const_tree: const_tree_ptr, @@ -898,9 +898,9 @@ pub fn get_hint_field_a( trace: air_instance.get_trace_ptr() as *mut c_void, public_inputs: public_inputs_ptr, challenges: challenges_ptr, - airgroup_values: air_instance.airgroup_values.as_ptr() as *mut c_void, - airvalues: air_instance.airvalues.as_ptr() as *mut c_void, - evals: air_instance.evals.as_ptr() as *mut c_void, + airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, + airvalues: air_instance.get_airvalues_ptr() as *mut c_void, + evals: air_instance.get_evals_ptr() as *mut c_void, xdivxsub: std::ptr::null_mut(), p_const_pols: const_pols_ptr, p_const_tree: const_tree_ptr, @@ -958,9 +958,9 @@ pub fn get_hint_field_m( trace: air_instance.get_trace_ptr() as *mut c_void, public_inputs: public_inputs_ptr, challenges: challenges_ptr, - airgroup_values: air_instance.airgroup_values.as_ptr() as *mut c_void, - airvalues: air_instance.airvalues.as_ptr() as *mut c_void, - evals: air_instance.evals.as_ptr() as *mut c_void, + airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, + airvalues: air_instance.get_airvalues_ptr() as *mut c_void, + evals: air_instance.get_evals_ptr() as *mut c_void, xdivxsub: std::ptr::null_mut(), p_const_pols: const_pols_ptr, p_const_tree: const_tree_ptr, @@ -1180,8 +1180,8 @@ pub fn set_hint_field_val( trace: std::ptr::null_mut(), public_inputs: std::ptr::null_mut(), challenges: std::ptr::null_mut(), - airgroup_values: air_instance.airgroup_values.as_mut_ptr() as *mut c_void, - airvalues: air_instance.airvalues.as_mut_ptr() as *mut c_void, + airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, + airvalues: air_instance.get_airvalues_ptr() as *mut c_void, evals: std::ptr::null_mut(), xdivxsub: std::ptr::null_mut(), p_const_pols: std::ptr::null_mut(), diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index 421d48ff..cf8f0a8a 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -157,7 +157,7 @@ impl ProofMan { witness_lib.end_proof(); for i in 0..pctx.global_info.n_proof_values { - if !pctx.proof_values.values_set.read().unwrap().contains_key(&i) { + if !pctx.proof_values.values_set.read().unwrap()[i] { panic!( "Proof cannot be generated: Proof value {} is not set", pctx.global_info.proof_values_map.as_ref().expect("REASON").get(i).unwrap().name diff --git a/provers/stark/src/stark_prover.rs b/provers/stark/src/stark_prover.rs index a33d8147..8ed3e8ba 100644 --- a/provers/stark/src/stark_prover.rs +++ b/provers/stark/src/stark_prover.rs @@ -140,9 +140,9 @@ impl Prover for StarkProver { trace: air_instance.get_trace_ptr() as *mut c_void, public_inputs: (*public_inputs_guard).as_ptr() as *mut c_void, challenges: (*challenges_guard).as_ptr() as *mut c_void, - airgroup_values: air_instance.airgroup_values.as_ptr() as *mut c_void, - airvalues: air_instance.airvalues.as_ptr() as *mut c_void, - evals: air_instance.evals.as_ptr() as *mut c_void, + airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, + airvalues: air_instance.get_airvalues_ptr() as *mut c_void, + evals: air_instance.get_evals_ptr() as *mut c_void, xdivxsub: std::ptr::null_mut(), p_const_pols: const_pols_ptr, p_const_tree: std::ptr::null_mut(), @@ -177,9 +177,9 @@ impl Prover for StarkProver { trace: air_instance.get_trace_ptr() as *mut c_void, public_inputs: (*public_inputs_guard).as_ptr() as *mut c_void, challenges: (*challenges_guard).as_ptr() as *mut c_void, - airgroup_values: air_instance.airgroup_values.as_ptr() as *mut c_void, - airvalues: air_instance.airvalues.as_ptr() as *mut c_void, - evals: air_instance.evals.as_ptr() as *mut c_void, + airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, + airvalues: air_instance.get_airvalues_ptr() as *mut c_void, + evals: air_instance.get_evals_ptr() as *mut c_void, xdivxsub: std::ptr::null_mut(), p_const_pols: const_pols_ptr, p_const_tree: const_tree_ptr, @@ -206,7 +206,7 @@ impl Prover for StarkProver { for i in 0..n_commits { let cm_pol = self.stark_info.cm_pols_map.as_ref().expect("REASON").get(i).unwrap(); if (cm_pol.stage < stage_id as u64 || cm_pol.stage == stage_id as u64 && !cm_pol.im_pol) - && !air_instance.commits_calculated.contains_key(&i) + && !air_instance.is_commit_initialized(i) { panic!("Intermediate polynomials for stage {} cannot be calculated: Witness column {} is not calculated", stage_id, cm_pol.name); } @@ -250,7 +250,7 @@ impl Prover for StarkProver { let n_commits = self.stark_info.cm_pols_map.as_ref().expect("REASON").len(); for i in 0..n_commits { let cm_pol = self.stark_info.cm_pols_map.as_ref().expect("REASON").get(i).unwrap(); - if cm_pol.stage == stage_id as u64 && !air_instance.commits_calculated.contains_key(&i) { + if cm_pol.stage == stage_id as u64 && !air_instance.is_commit_initialized(i) { panic!("Stage {} cannot be committed: Witness column {} is not calculated", stage_id, cm_pol.name); } } @@ -258,7 +258,7 @@ impl Prover for StarkProver { let n_airgroupvalues = self.stark_info.airgroupvalues_map.as_ref().expect("REASON").len(); for i in 0..n_airgroupvalues { let airgroup_value = self.stark_info.airgroupvalues_map.as_ref().expect("REASON").get(i).unwrap(); - if airgroup_value.stage == stage_id as u64 && !air_instance.airgroupvalue_calculated.contains_key(&i) { + if airgroup_value.stage == stage_id as u64 && !air_instance.is_airgroup_value_initialized(i) { panic!( "Stage {} cannot be committed: Airgroupvalue {} is not calculated", stage_id, airgroup_value.name @@ -270,7 +270,7 @@ impl Prover for StarkProver { for i in 0..n_airvalues { let air_value = self.stark_info.airvalues_map.as_ref().expect("REASON").get(i).unwrap(); - if air_value.stage == stage_id as u64 && !air_instance.airvalue_calculated.contains_key(&i) { + if air_value.stage == stage_id as u64 && !air_instance.is_airvalue_initialized(i) { panic!("Stage {} cannot be committed: Airvalue {} is not calculated", stage_id, air_value.name); } } @@ -280,7 +280,7 @@ impl Prover for StarkProver { let n_custom_commits = self.stark_info.custom_commits_map[i].as_ref().expect("REASON").len(); for j in 0..n_custom_commits { let custom_pol = self.stark_info.custom_commits_map[i].as_ref().expect("REASON").get(j).unwrap(); - if stage_id as u64 == custom_pol.stage && !air_instance.custom_commits_calculated[i].contains_key(&j) { + if stage_id as u64 == custom_pol.stage && !air_instance.is_custom_commit_initialized(i, j) { panic!( "Stage {} cannot be committed: Custom commit of {} that is {} is not calculated", stage_id, self.stark_info.custom_commits[i].name, custom_pol.name @@ -589,7 +589,7 @@ impl Prover for StarkProver { } } else if stage == (Self::num_stages(self) + 2) as u64 { let air_instance = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap()[self.prover_idx]; - let evals = air_instance.evals.as_ptr() as *mut c_void; + let evals = air_instance.get_evals_ptr() as *mut c_void; calculate_hash_c( p_stark, value.as_mut_ptr() as *mut c_void, @@ -750,7 +750,7 @@ impl StarkProver { challenges: std::ptr::null_mut(), airgroup_values: std::ptr::null_mut(), airvalues: std::ptr::null_mut(), - evals: air_instance.evals.as_mut_ptr() as *mut c_void, + evals: air_instance.get_evals_ptr() as *mut c_void, xdivxsub: std::ptr::null_mut(), p_const_pols: std::ptr::null_mut(), p_const_tree: const_tree_ptr, @@ -782,9 +782,9 @@ impl StarkProver { trace: air_instance.get_trace_ptr() as *mut c_void, public_inputs: (*public_inputs_guard).as_ptr() as *mut c_void, challenges: (*challenges_guard).as_ptr() as *mut c_void, - airgroup_values: air_instance.airgroup_values.as_ptr() as *mut c_void, - airvalues: air_instance.airvalues.as_ptr() as *mut c_void, - evals: air_instance.evals.as_ptr() as *mut c_void, + airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, + airvalues: air_instance.get_airvalues_ptr() as *mut c_void, + evals: air_instance.get_evals_ptr() as *mut c_void, xdivxsub: (*buff_helper_guard).as_ptr() as *mut c_void, p_const_pols: const_pols_ptr, p_const_tree: const_tree_ptr, From 2d425167779a44b326c97af541e987ae234ea4e0 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 9 Dec 2024 13:00:29 +0000 Subject: [PATCH 16/64] Cleaning completed --- Cargo.lock | 18 ++ Cargo.toml | 2 +- cli/assets/templates/pil_helpers_mod.rs.tt | 1 + cli/assets/templates/pil_helpers_trace.rs.tt | 14 +- .../templates/pil_helpers_trace_new.rs.tt | 31 --- cli/src/commands/pil_helpers.rs | 30 ++- common/src/air_instance.rs | 130 +++-------- common/src/proof_ctx.rs | 113 +++++----- common/src/prover.rs | 1 - common/src/setup.rs | 10 + common/src/trace.rs | 3 - examples/fibonacci-square/pil/fibonaccisq.pil | 8 +- examples/fibonacci-square/src/fibonacci.rs | 56 +++-- .../fibonacci-square/src/fibonacci_lib.rs | 18 +- examples/fibonacci-square/src/module.rs | 17 +- .../fibonacci-square/src/pil_helpers/mod.rs | 1 + .../src/pil_helpers/traces.rs | 25 ++- hints/src/hints.rs | 92 +++----- macros/src/lib.rs | 201 +++++++++++++----- .../rs/src/range_check/specified_ranges.rs | 5 +- .../std/rs/src/range_check/std_range_check.rs | 2 +- .../lib/std/rs/src/range_check/u16air.rs | 5 +- .../lib/std/rs/src/range_check/u8air.rs | 5 +- pil2-components/lib/std/rs/src/std_prod.rs | 7 +- pil2-components/lib/std/rs/src/std_sum.rs | 11 +- .../test/simple/rs/src/pil_helpers/traces.rs | 1 - .../test/simple/rs/src/simple_left.rs | 7 +- .../test/simple/rs/src/simple_right.rs | 7 +- .../test/std/connection/rs/src/connection1.rs | 7 +- .../test/std/connection/rs/src/connection2.rs | 7 +- .../std/connection/rs/src/connection_new.rs | 7 +- .../connection/rs/src/pil_helpers/traces.rs | 1 - .../test/std/lookup/rs/src/lookup0.rs | 7 +- .../test/std/lookup/rs/src/lookup1.rs | 7 +- .../test/std/lookup/rs/src/lookup2_12.rs | 7 +- .../test/std/lookup/rs/src/lookup2_13.rs | 7 +- .../test/std/lookup/rs/src/lookup2_15.rs | 7 +- .../test/std/lookup/rs/src/lookup3.rs | 7 +- .../std/lookup/rs/src/pil_helpers/traces.rs | 2 + .../std/permutation/rs/src/permutation1_6.rs | 7 +- .../std/permutation/rs/src/permutation1_7.rs | 7 +- .../std/permutation/rs/src/permutation1_8.rs | 7 +- .../std/permutation/rs/src/permutation2.rs | 7 +- .../permutation/rs/src/pil_helpers/traces.rs | 1 - .../range_check/rs/src/multi_range_check1.rs | 11 +- .../range_check/rs/src/multi_range_check2.rs | 11 +- .../range_check/rs/src/pil_helpers/traces.rs | 1 - .../std/range_check/rs/src/range_check1.rs | 7 +- .../std/range_check/rs/src/range_check2.rs | 13 +- .../std/range_check/rs/src/range_check3.rs | 13 +- .../std/range_check/rs/src/range_check4.rs | 7 +- .../rs/src/range_check_dynamic1.rs | 11 +- .../rs/src/range_check_dynamic2.rs | 11 +- .../std/range_check/rs/src/range_check_mix.rs | 11 +- proofman/src/global_constraints.rs | 71 ++----- proofman/src/proofman.rs | 53 +---- proofman/src/recursion.rs | 55 ++--- proofman/src/witness_manager.rs | 15 +- provers/stark/src/stark_prover.rs | 174 ++++----------- 59 files changed, 631 insertions(+), 749 deletions(-) delete mode 100644 cli/assets/templates/pil_helpers_trace_new.rs.tt diff --git a/Cargo.lock b/Cargo.lock index 1e62d32a..8275c6dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -972,6 +972,24 @@ dependencies = [ "getrandom", ] +[[package]] +name = "range-check" +version = "0.1.0" +dependencies = [ + "env_logger", + "log", + "num-bigint", + "num-traits", + "p3-field", + "p3-goldilocks", + "pil-std-lib", + "proofman", + "proofman-cli", + "proofman-common", + "proofman-macros", + "rand", +] + [[package]] name = "rayon" version = "1.10.0" diff --git a/Cargo.toml b/Cargo.toml index 02a3dd7c..61c1fe2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ members = [ "transcript", "util", "pil2-components/lib/std/rs", - # "pil2-components/test/std/range_check/rs", + "pil2-components/test/std/range_check/rs", # "pil2-components/test/std/lookup/rs", # "pil2-components/test/std/connection/rs", # "pil2-components/test/std/permutation/rs", diff --git a/cli/assets/templates/pil_helpers_mod.rs.tt b/cli/assets/templates/pil_helpers_mod.rs.tt index 9daf0c06..8e9f77af 100644 --- a/cli/assets/templates/pil_helpers_mod.rs.tt +++ b/cli/assets/templates/pil_helpers_mod.rs.tt @@ -1,5 +1,6 @@ // WARNING: This file has been autogenerated from the PILOUT file. // Manual modifications are not recommended and may be overwritten. +#[rustfmt::skip] mod traces; pub use traces::*; diff --git a/cli/assets/templates/pil_helpers_trace.rs.tt b/cli/assets/templates/pil_helpers_trace.rs.tt index f2cec07c..d9d9e109 100644 --- a/cli/assets/templates/pil_helpers_trace.rs.tt +++ b/cli/assets/templates/pil_helpers_trace.rs.tt @@ -4,6 +4,8 @@ use proofman_common as common; pub use proofman_macros::trace; pub use proofman_macros::values; +type FieldExtension = [F; 3]; + pub const PILOUT_HASH: &[u8] = b"{ project_name }-hash"; //AIRGROUP CONSTANTS @@ -14,20 +16,22 @@ pub const { constant.0 }_AIRGROUP_ID: usize = { constant.1 }; {{ for constant in constant_airs }} pub const { constant.0 }_AIR_IDS: &[usize] = &[{ constant.3 }]; {{ endfor }} -{{ for public_values in publics }} +{{ for public_values in publics }} //PUBLICS use serde::Deserialize; use serde::Serialize; #[derive(Default, Debug, Serialize, Deserialize)] pub struct {project_name}Publics \{ - {{ for column in public_values.values_u64 }} #[serde(default)] pub {column.name}: {column.type},{{ endfor }} + {{ for column in public_values.values_u64 }}#[serde(default)] + pub {column.name}: {column.type}, + {{ endfor }} } -values!({ project_name }PublicValues \{ +values!({ project_name }PublicValues \{ {{ for column in public_values.values }} { column.name }: { column.type },{{ endfor }} }); {{ endfor }} {{ for proof_vals in proof_values }} -values!({ project_name }ProofValues \{ +values!({ project_name }ProofValues \{ {{ for column in proof_vals.values }} { column.name }: { column.type },{{ endfor }} }); {{ endfor }} {{ for air_group in air_groups }}{{ for air in air_group.airs }} @@ -39,7 +43,7 @@ trace!({ air.name }{custom_commit.name}Trace \{ {{ for column in custom_commit.custom_columns }} { column.name }: { column.type },{{ endfor }} }, { air_group.airgroup_id }, { air.id }, { air.num_rows }, { custom_commit.commit_id } ); {{ endfor }}{{ endfor }}{{ endfor }}{{ for air_group in air_groups }}{{ for air in air_group.airs }}{{ for air_values in air.air_values }} -values!({ air.name }AirValues \{ +values!({ air.name }AirValues \{ {{ for column in air_values.values }} { column.name }: { column.type },{{ endfor }} }); {{ endfor }}{{ endfor }}{{ endfor }} \ No newline at end of file diff --git a/cli/assets/templates/pil_helpers_trace_new.rs.tt b/cli/assets/templates/pil_helpers_trace_new.rs.tt deleted file mode 100644 index 4ccd72e5..00000000 --- a/cli/assets/templates/pil_helpers_trace_new.rs.tt +++ /dev/null @@ -1,31 +0,0 @@ -// WARNING: This file has been autogenerated from the PILOUT file. -// Manual modifications are not recommended and may be overwritten. -use proofman_common as common; -pub use proofman_macros::trace; -{{ for public_values in publics }} -values!({ project_name }PublicValues \{ -{{ for column in public_values.values }} { column.name }: { column.type },{{ endfor }} -}); -{{ endfor }} -{{ for proof_vals in proof_values }} -values!({ project_name }ProofValues \{ -{{ for column in proof_vals.values }} { column.name }: { column.type },{{ endfor }} -}); -{{ endfor }} -{{ for air_group in air_groups }}{{ for air in air_group.airs }} -trace!({ air.name }Row, { air.name }Trace \{ -{{ for column in air.columns }} { column.name }: { column.type },{{ endfor }} -}); -{{ endfor }}{{ endfor }}{{ for air_group in air_groups }}{{ for air in air_group.airs }}{{ for custom_commit in air.custom_columns }} -trace!({ air.name }{custom_commit.name}Row, { air.name }{custom_commit.name}Trace \{ -{{ for column in custom_commit.custom_columns }} { column.name }: { column.type },{{ endfor }} -}); -{{ endfor }}{{ endfor }}{{ endfor }}{{ for air_group in air_groups }}{{ for air in air_group.airs }}{{ for air_values in air.air_values }} -values!({ air.name }AirValues \{ -{{ for column in air_values.values }} { column.name }: { column.type },{{ endfor }} -}); -{{ endfor }}{{ endfor }}{{ endfor }}{{ for air_group in air_groups }}{{ for air in air_group.airs }}{{ for airgroup_values in air.airgroup_values }} -values!({ air.name }AirGroupValues \{ -{{ for column in airgroup_values.values }} { column.name }: { column.type },{{ endfor }} -}); -{{ endfor }}{{ endfor }}{{ endfor }} \ No newline at end of file diff --git a/cli/src/commands/pil_helpers.rs b/cli/src/commands/pil_helpers.rs index e1581929..47534bba 100644 --- a/cli/src/commands/pil_helpers.rs +++ b/cli/src/commands/pil_helpers.rs @@ -173,11 +173,21 @@ impl PilHelpersCmd { // Start with "F" and apply each length in reverse order symbol.lengths.iter().rev().fold("F".to_string(), |acc, &length| format!("[{}; {}]", acc, length)) }; + let ext_type = if symbol.lengths.is_empty() { + "FieldExtension".to_string() // Case when lengths.len() == 0 + } else { + // Start with "F" and apply each length in reverse order + symbol + .lengths + .iter() + .rev() + .fold("FieldExtension".to_string(), |acc, &length| format!("[{}; {}]", acc, length)) + }; if symbol.r#type == SymbolType::ProofValue as i32 { if proof_values.is_empty() { proof_values.push(ValuesCtx { values: Vec::new(), values_u64: Vec::new() }); } - proof_values[0].values.push(ColumnCtx { name: name.to_owned(), r#type }); + proof_values[0].values.push(ColumnCtx { name: name.to_owned(), r#type: ext_type }); } else { if publics.is_empty() { publics.push(ValuesCtx { values: Vec::new(), values_u64: Vec::new() }); @@ -240,18 +250,27 @@ impl PilHelpersCmd { .rev() .fold("F".to_string(), |acc, &length| format!("[{}; {}]", acc, length)) }; + let ext_type = + if symbol.lengths.is_empty() { + "FieldExtension".to_string() // Case when lengths.len() == 0 + } else { + // Start with "F" and apply each length in reverse order + symbol.lengths.iter().rev().fold("FieldExtension".to_string(), |acc, &length| { + format!("[{}; {}]", acc, length) + }) + }; if symbol.r#type == SymbolType::WitnessCol as i32 { air.columns.push(ColumnCtx { name: name.to_owned(), r#type }); } else if symbol.r#type == SymbolType::AirValue as i32 { if air.air_values.is_empty() { air.air_values.push(ValuesCtx { values: Vec::new(), values_u64: Vec::new() }); } - air.air_values[0].values.push(ColumnCtx { name: name.to_owned(), r#type }); + air.air_values[0].values.push(ColumnCtx { name: name.to_owned(), r#type: ext_type }); } else if symbol.r#type == SymbolType::AirGroupValue as i32 { if air.airgroup_values.is_empty() { air.airgroup_values.push(ValuesCtx { values: Vec::new(), values_u64: Vec::new() }); } - air.airgroup_values[0].values.push(ColumnCtx { name: name.to_owned(), r#type }); + air.airgroup_values[0].values.push(ColumnCtx { name: name.to_owned(), r#type: ext_type }); } else { air.custom_columns[symbol.commit_id.unwrap() as usize] .custom_columns @@ -284,7 +303,10 @@ impl PilHelpersCmd { fs::write(pil_helpers_path.join("mod.rs"), MOD_RS)?; // Write traces.rs - fs::write(pil_helpers_path.join("traces.rs"), tt.render("traces.rs", &context)?)?; + fs::write( + pil_helpers_path.join("traces.rs"), + tt.render("traces.rs", &context)?.replace("<", "<").replace(">", ">"), + )?; Ok(()) } diff --git a/common/src/air_instance.rs b/common/src/air_instance.rs index 5ace47c4..ea92dc42 100644 --- a/common/src/air_instance.rs +++ b/common/src/air_instance.rs @@ -1,7 +1,6 @@ use std::{os::raw::c_void, sync::Arc}; use std::path::PathBuf; use p3_field::Field; -use proofman_starks_lib_c::get_custom_commit_map_ids_c; use proofman_util::create_buffer_fast; use crate::{trace::Trace, trace::Values, ProofCtx, ExecutionCtx, SetupCtx, Setup, StarkInfo}; @@ -58,12 +57,6 @@ impl CustomCommitsInfo { } } -#[derive(Default, Clone)] -pub struct ValuesInfo { - pub buffer: Vec, - pub calculated: Vec, -} - /// Air instance context for managing air instances (traces) #[allow(dead_code)] #[repr(C)] @@ -75,23 +68,13 @@ pub struct AirInstance { pub air_instance_id: Option, pub idx: Option, pub global_idx: Option, - pub witness: Vec, pub trace: Option>, - pub commits_calculated: Vec, - pub custom_commits: Vec>, pub custom_commits_extended: Vec>, - pub custom_commits_calculated: Vec>, - pub airgroup_values: Vec, - pub airgroupvalue_calculated: Vec, - pub airvalues: Vec, - pub airvalue_calculated: Vec, - pub evals: Vec, - pub stark_info: StarkInfo, } @@ -103,11 +86,17 @@ impl AirInstance { air_id: usize, witness: Vec, witness_custom: Option>>, - air_values: Option>>, + air_values: Option>, ) -> Self { let ps = setup_ctx.get_setup(airgroup_id, air_id); - let (custom_commits, custom_commits_extended, custom_commits_calculated) = Self::init_custom_commits(ps, witness_custom); + let (custom_commits, custom_commits_extended) = Self::init_custom_commits(ps, witness_custom); + + let airvalues = if let Some(air_values) = air_values { + air_values + } else { + vec![F::zero(); ps.stark_info.airvalues_map.as_ref().unwrap().len() * 3] + }; AirInstance { airgroup_id, @@ -118,14 +107,10 @@ impl AirInstance { global_idx: None, witness, trace: None, - commits_calculated: vec![false; ps.stark_info.cm_pols_map.as_ref().unwrap().len()], custom_commits, custom_commits_extended, - custom_commits_calculated, airgroup_values: vec![F::zero(); ps.stark_info.airgroupvalues_map.as_ref().unwrap().len() * 3], - airgroupvalue_calculated: vec![false; ps.stark_info.airgroupvalues_map.as_ref().unwrap().len()], - airvalues: vec![F::zero(); ps.stark_info.airvalues_map.as_ref().unwrap().len() * 3], - airvalue_calculated: vec![false; ps.stark_info.airgroupvalues_map.as_ref().unwrap().len()], + airvalues, evals: vec![F::zero(); ps.stark_info.ev_map.len() * 3], stark_info: ps.stark_info.clone(), } @@ -153,12 +138,18 @@ impl AirInstance { } else { None }; - - // let air_values_info = if let Some(air_values) = air_vals { - // }; + let air_values_info = if let Some(air_values) = air_values { Some(air_values.get_buffer()) } else { None }; - let air_instance = AirInstance::new(setup_ctx, air_segment_id, airgroup_id, air_id, witness, custom_witnesses, None); + let air_instance = AirInstance::new( + setup_ctx, + air_segment_id, + airgroup_id, + air_id, + witness, + custom_witnesses, + air_values_info, + ); let (is_mine, gid) = execution_ctx.dctx.write().unwrap().add_instance(air_instance.airgroup_id, air_instance.air_id, 1); @@ -168,39 +159,34 @@ impl AirInstance { } } - pub fn init_custom_commits(setup: &Setup, witness_custom: Option>>) -> (Vec>, Vec>, Vec>) { + pub fn init_custom_commits( + setup: &Setup, + witness_custom: Option>>, + ) -> (Vec>, Vec>) { let n_custom_commits = setup.stark_info.custom_commits.len(); - let mut custom_commits_calculated = Vec::new(); let mut custom_commits = Vec::new(); let mut custom_commits_extended = Vec::new(); for commit_id in 0..n_custom_commits { - let n_cols = - *setup.stark_info.map_sections_n.get(&(setup.stark_info.custom_commits[commit_id].name.clone() + "0")).unwrap() - as usize; - custom_commits_calculated.push(vec![false; n_cols]); + let n_cols = *setup + .stark_info + .map_sections_n + .get(&(setup.stark_info.custom_commits[commit_id].name.clone() + "0")) + .unwrap() as usize; if let Some(witness_custom_value) = witness_custom.as_ref() { - custom_commits.push(CustomCommitsInfo::new( - witness_custom_value[commit_id].clone(), - PathBuf::new(), - )); + custom_commits.push(CustomCommitsInfo::new(witness_custom_value[commit_id].clone(), PathBuf::new())); } else { println!("No custom trace data found."); } - let ids = get_custom_commit_map_ids_c(setup.p_setup.p_stark_info, commit_id as u64, 0); - for idx in ids { - custom_commits_calculated[commit_id][idx as usize] = true; - } - custom_commits_extended.push(CustomCommitsInfo::new( create_buffer_fast((1 << setup.stark_info.stark_struct.n_bits_ext) * n_cols), PathBuf::new(), )); } - (custom_commits, custom_commits_extended, custom_commits_calculated) + (custom_commits, custom_commits_extended) } pub fn get_witness_ptr(&self) -> *mut u8 { @@ -246,42 +232,12 @@ impl AirInstance { ptrs } - pub fn is_commit_initialized(&self, index: usize) -> bool { - self.commits_calculated[index] - } - - pub fn is_airgroup_value_initialized(&self, index: usize) -> bool { - self.airgroupvalue_calculated[index] - } - - pub fn is_airvalue_initialized(&self, index: usize) -> bool { - self.airvalue_calculated[index] - } - - pub fn is_custom_commit_initialized(&self, commit_id: usize, index: usize) -> bool { - self.custom_commits_calculated[commit_id][index] - } - - pub fn set_custom_commit_cached_file(&mut self, setup_ctx: &SetupCtx, commit_id: u64, cached_file: PathBuf) { - let ps = setup_ctx.get_setup(self.airgroup_id, self.air_id); - + pub fn set_custom_commit_cached_file(&mut self, commit_id: u64, cached_file: PathBuf) { self.custom_commits[commit_id as usize].cached_file = cached_file; - - let ids = get_custom_commit_map_ids_c(ps.p_setup.p_stark_info, commit_id, 0); - for idx in ids { - self.set_custom_commit_calculated(commit_id as usize, idx as usize); - } } - pub fn set_custom_commit_id_buffer(&mut self, setup_ctx: &SetupCtx, buffer: Vec, commit_id: u64) { + pub fn set_custom_commit_id_buffer(&mut self, buffer: Vec, commit_id: u64) { self.custom_commits[commit_id as usize].buffer = buffer; - - let ps = setup_ctx.get_setup(self.airgroup_id, self.air_id); - - let ids = get_custom_commit_map_ids_c(ps.p_setup.p_stark_info, commit_id, 0); - for idx in ids { - self.set_custom_commit_calculated(commit_id as usize, idx as usize); - } } pub fn set_airvalue(&mut self, name: &str, lengths: Option>, value: F) { @@ -305,7 +261,6 @@ impl AirInstance { .unwrap_or_else(|| panic!("Name {} with specified lengths {:?} not found in airvalues", name, lengths)); self.airvalues[airvalue_id * 3] = value; - self.set_airvalue_calculated(airvalue_id); } pub fn set_airvalue_ext(&mut self, name: &str, lengths: Option>, value: Vec) { @@ -335,8 +290,6 @@ impl AirInstance { self.airvalues[airvalue_id * 3] = value_iter.next().unwrap(); self.airvalues[airvalue_id * 3 + 1] = value_iter.next().unwrap(); self.airvalues[airvalue_id * 3 + 2] = value_iter.next().unwrap(); - - self.set_airvalue_calculated(airvalue_id); } pub fn set_airgroupvalue(&mut self, name: &str, lengths: Option>, value: F) { @@ -362,7 +315,6 @@ impl AirInstance { }); self.airgroup_values[airgroupvalue_id * 3] = value; - self.set_airgroupvalue_calculated(airgroupvalue_id); } pub fn set_airgroupvalue_ext(&mut self, name: &str, lengths: Option>, value: Vec) { @@ -394,28 +346,10 @@ impl AirInstance { self.airgroup_values[airgroupvalue_id * 3] = value_iter.next().unwrap(); self.airgroup_values[airgroupvalue_id * 3 + 1] = value_iter.next().unwrap(); self.airgroup_values[airgroupvalue_id * 3 + 2] = value_iter.next().unwrap(); - - self.set_airgroupvalue_calculated(airgroupvalue_id); - } - - pub fn set_commit_calculated(&mut self, id: usize) { - self.commits_calculated[id] = true; - } - - pub fn set_custom_commit_calculated(&mut self, commit_id: usize, id: usize) { - self.custom_commits_calculated[commit_id][id] = true; } pub fn set_air_instance_id(&mut self, air_instance_id: usize, idx: usize) { self.air_instance_id = Some(air_instance_id); self.idx = Some(idx); } - - pub fn set_airgroupvalue_calculated(&mut self, id: usize) { - self.airgroupvalue_calculated[id] = true; - } - - pub fn set_airvalue_calculated(&mut self, id: usize) { - self.airvalue_calculated[id] = true; - } } diff --git a/common/src/proof_ctx.rs b/common/src/proof_ctx.rs index f3b749fc..c11e1871 100644 --- a/common/src/proof_ctx.rs +++ b/common/src/proof_ctx.rs @@ -5,49 +5,19 @@ use p3_field::Field; use crate::{AirInstancesRepository, GlobalInfo, StdMode, VerboseMode}; -pub struct PublicInputs { - pub inputs: RwLock>, - pub inputs_set: RwLock>, -} - - -impl PublicInputs { - pub fn new(n_publics: usize) -> Self { - Self { - inputs: RwLock::new(vec![0; n_publics * std::mem::size_of::()]), - inputs_set: RwLock::new(vec![false; n_publics]), - } - } -} - -pub struct ProofValues { +pub struct Values { pub values: RwLock>, - pub values_set: RwLock>, } -impl ProofValues { - fn new(n_proof_values: usize) -> Self { - Self { values: RwLock::new(vec![F::zero(); n_proof_values * 3]), values_set: RwLock::new(vec![false; n_proof_values]) } +impl Values { + pub fn new(n_values: usize) -> Self { + Self { values: RwLock::new(vec![F::zero(); n_values]) } } } -pub struct Challenges { - pub challenges: RwLock>, -} - -impl Default for Challenges { - fn default() -> Self { - Self { challenges: RwLock::new(Vec::new()) } - } -} - -pub struct BuffHelper { - pub buff_helper: RwLock>, -} - -impl Default for BuffHelper { +impl Default for Values { fn default() -> Self { - Self { buff_helper: RwLock::new(Vec::new()) } + Self { values: RwLock::new(Vec::new()) } } } @@ -73,10 +43,10 @@ impl ProofOptions { #[allow(dead_code)] pub struct ProofCtx { - pub public_inputs: PublicInputs, - pub proof_values: ProofValues, - pub challenges: Challenges, - pub buff_helper: BuffHelper, + pub public_inputs: Values, + pub proof_values: Values, + pub challenges: Values, + pub buff_helper: Values, pub global_info: GlobalInfo, pub air_instance_repo: AirInstancesRepository, } @@ -88,15 +58,15 @@ impl ProofCtx { log::info!("{}: Creating proof context", Self::MY_NAME); let global_info: GlobalInfo = GlobalInfo::new(&proving_key_path); - - let proof_values = ProofValues::new(global_info.n_proof_values); let n_publics = global_info.n_publics; + let n_proof_values = global_info.n_proof_values; + Self { global_info, - public_inputs: PublicInputs::new(n_publics), - proof_values, - challenges: Challenges::default(), - buff_helper: BuffHelper::default(), + public_inputs: Values::new(n_publics), + proof_values: Values::new(n_proof_values * 3), + challenges: Values::default(), + buff_helper: Values::default(), air_instance_repo: AirInstancesRepository::new(), } } @@ -121,8 +91,6 @@ impl ProofCtx { self.proof_values.values.write().unwrap()[3 * id] = value; self.proof_values.values.write().unwrap()[3 * id + 1] = F::zero(); self.proof_values.values.write().unwrap()[3 * id + 2] = F::zero(); - - self.set_proof_value_calculated(id); } pub fn set_proof_value_ext(&self, name: &str, value: Vec) { @@ -145,22 +113,18 @@ impl ProofCtx { self.proof_values.values.write().unwrap()[3 * id] = value[0]; self.proof_values.values.write().unwrap()[3 * id + 1] = value[1]; self.proof_values.values.write().unwrap()[3 * id + 2] = value[2]; - - self.set_proof_value_calculated(id); } - pub fn set_proof_value_calculated(&self, id: usize) { - self.proof_values.values_set.write().unwrap().insert(id, true); + pub fn get_proof_values_ptr(&self) -> *mut u8 { + let guard = &self.proof_values.values.read().unwrap(); + guard.as_ptr() as *mut u8 } - - pub fn set_public_value(&self, value: u64, public_id: u64) { - self.public_inputs.inputs.write().unwrap()[(public_id as usize) * 8..(public_id as usize + 1) * 8] - .copy_from_slice(&value.to_le_bytes()); - self.public_inputs.inputs_set.write().unwrap()[public_id as usize] = true; + pub fn set_public_value(&self, value: F, public_id: usize) { + self.public_inputs.values.write().unwrap()[public_id] = value; } - pub fn set_public_value_by_name(&self, value: u64, public_name: &str, lengths: Option>) { + pub fn set_public_value_by_name(&self, value: F, public_name: &str, lengths: Option>) { let n_publics: usize = self.global_info.publics_map.as_ref().expect("REASON").len(); let public_id = (0..n_publics) .find(|&i| { @@ -182,10 +146,10 @@ impl ProofCtx { panic!("Name {} with specified lengths {:?} not found in publics_map", public_name, lengths) }); - self.set_public_value(value, public_id as u64); + self.set_public_value(value, public_id); } - pub fn get_public_value(&self, public_name: &str) -> u64 { + pub fn get_public_value(&self, public_name: &str) -> F { let n_publics: usize = self.global_info.publics_map.as_ref().expect("REASON").len(); let public_id = (0..n_publics) .find(|&i| { @@ -194,10 +158,29 @@ impl ProofCtx { }) .unwrap_or_else(|| panic!("Name {} not found in publics_map", public_name)); - u64::from_le_bytes( - self.public_inputs.inputs.read().unwrap()[public_id * 8..(public_id + 1) * 8] - .try_into() - .expect("Expected 8 bytes for u64"), - ) + self.public_inputs.values.read().unwrap()[public_id] + } + + pub fn get_publics(&self) -> std::sync::RwLockWriteGuard> { + self.public_inputs.values.write().unwrap() + } + + pub fn get_proof_values(&self) -> std::sync::RwLockWriteGuard> { + self.proof_values.values.write().unwrap() + } + + pub fn get_publics_ptr(&self) -> *mut u8 { + let guard = &self.public_inputs.values.read().unwrap(); + guard.as_ptr() as *mut u8 + } + + pub fn get_challenges_ptr(&self) -> *mut u8 { + let guard = &self.challenges.values.read().unwrap(); + guard.as_ptr() as *mut u8 + } + + pub fn get_buff_helper_ptr(&self) -> *mut u8 { + let guard = &self.buff_helper.values.read().unwrap(); + guard.as_ptr() as *mut u8 } } diff --git a/common/src/prover.rs b/common/src/prover.rs index dcf14e56..f3ff8582 100644 --- a/common/src/prover.rs +++ b/common/src/prover.rs @@ -82,7 +82,6 @@ pub trait Prover { fn num_stages(&self) -> u32; fn get_challenges(&self, stage_id: u32, proof_ctx: Arc>, transcript: &FFITranscript); fn calculate_stage(&mut self, stage_id: u32, setup_ctx: Arc, proof_ctx: Arc>); - fn check_stage(&self, stage_id: u32, proof_ctx: Arc>); fn commit_stage(&mut self, stage_id: u32, proof_ctx: Arc>) -> ProverStatus; fn calculate_xdivxsub(&mut self, proof_ctx: Arc>); fn calculate_lev(&mut self, proof_ctx: Arc>); diff --git a/common/src/setup.rs b/common/src/setup.rs index f433d189..442760a9 100644 --- a/common/src/setup.rs +++ b/common/src/setup.rs @@ -149,4 +149,14 @@ impl Setup { }; *self.const_tree.values.write().unwrap() = const_tree; } + + pub fn get_const_ptr(&self) -> *mut u8 { + let guard = &self.const_pols.values.read().unwrap(); + guard.as_ptr() as *mut u8 + } + + pub fn get_const_tree_ptr(&self) -> *mut u8 { + let guard = &self.const_tree.values.read().unwrap(); + guard.as_ptr() as *mut u8 + } } diff --git a/common/src/trace.rs b/common/src/trace.rs index ab0d9189..ab9dd4cb 100644 --- a/common/src/trace.rs +++ b/common/src/trace.rs @@ -1,5 +1,4 @@ use p3_field::Field; -use std::collections::HashMap; pub trait Trace: Send { fn num_rows(&self) -> usize; @@ -9,9 +8,7 @@ pub trait Trace: Send { } pub trait Values: Send { - fn num_values(&self) -> usize; fn get_buffer(&mut self) -> Vec; - fn get_values_calculated(&mut self) -> HashMap; } pub use proofman_macros::trace; diff --git a/examples/fibonacci-square/pil/fibonaccisq.pil b/examples/fibonacci-square/pil/fibonaccisq.pil index 2b02f01e..8719b7b8 100644 --- a/examples/fibonacci-square/pil/fibonaccisq.pil +++ b/examples/fibonacci-square/pil/fibonaccisq.pil @@ -20,8 +20,8 @@ on final proof checkProofValues(); airtemplate FibonacciSquare(const int N = 2**8) { commit stage(0) public(rom_root) rom; - // airval fibo1[2]; - // airval stage(2) fibo3; + airval fibo1[2]; + airval stage(2) fibo3; col fixed L1 = [1,0...]; col witness a,b; @@ -36,11 +36,11 @@ airtemplate FibonacciSquare(const int N = 2**8) { (a' - b) * (1 - L1') === 0; - // 2*fibo1[0] - fibo1[1] === 0; + 2*fibo1[0] - fibo1[1] === 0; line - (flags + 1) === 0; - @test_hint{ custom_col: line }; +@test_hint{ custom_col: line }; permutation_assumes(MODULE_ID, [a*a + b*b, b'], 1 - L1'); } \ No newline at end of file diff --git a/examples/fibonacci-square/src/fibonacci.rs b/examples/fibonacci-square/src/fibonacci.rs index 64799d6a..1d92b1cb 100644 --- a/examples/fibonacci-square/src/fibonacci.rs +++ b/examples/fibonacci-square/src/fibonacci.rs @@ -3,21 +3,27 @@ use std::sync::Arc; use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use proofman::{WitnessManager, WitnessComponent}; -use p3_field::PrimeField; +use p3_field::PrimeField64; -use crate::{FibonacciSquareRomTrace, FibonacciSquareTrace, Module, FIBONACCI_SQUARE_AIRGROUP_ID, FIBONACCI_SQUARE_AIR_IDS}; +use crate::{ + FibonacciSquareRomTrace, BuildPublicValues, BuildProofValues, FibonacciSquareAirValues, FibonacciSquareTrace, + Module, +}; -pub struct FibonacciSquare { +pub struct FibonacciSquare { module: Arc>, } -impl FibonacciSquare { +impl FibonacciSquare { const MY_NAME: &'static str = "FiboSqre"; pub fn new(wcm: Arc>, module: Arc>) -> Arc { let fibonacci = Arc::new(Self { module }); - wcm.register_component(fibonacci.clone(), Some(FIBONACCI_SQUARE_AIRGROUP_ID), Some(FIBONACCI_SQUARE_AIR_IDS)); + let airgroup_id = FibonacciSquareTrace::::get_airgroup_id(); + let air_id = FibonacciSquareTrace::::get_air_id(); + + wcm.register_component(fibonacci.clone(), airgroup_id, air_id); fibonacci } @@ -36,9 +42,11 @@ impl FibonacciSquare { ) -> Result> { log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); - let module = pctx.get_public_value("module"); - let mut a = pctx.get_public_value("in1"); - let mut b = pctx.get_public_value("in2"); + let mut publics = BuildPublicValues::from_vec_guard(pctx.get_publics()); + + let module = F::as_canonical_u64(&publics.module); + let mut a = F::as_canonical_u64(&publics.in1); + let mut b = F::as_canonical_u64(&publics.in2); let mut trace = FibonacciSquareTrace::new_zeroes(); @@ -54,6 +62,8 @@ impl FibonacciSquare { trace[i].b = F::from_canonical_u64(b); } + publics.out = trace[trace.num_rows() - 1].b; + let mut trace_rom = FibonacciSquareRomTrace::new_zeroes(); for i in 0..trace_rom.num_rows() { @@ -61,22 +71,30 @@ impl FibonacciSquare { trace_rom[i].flags = F::from_canonical_u64(2 + i as u64); } - pctx.set_public_value_by_name(b, "out", None); - - pctx.set_proof_value("value1", F::from_canonical_u64(5)); - pctx.set_proof_value("value2", F::from_canonical_u64(125)); - - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), Some(0), &mut trace, Some(&mut vec![&mut trace_rom]), None); - - // air_instance.set_airvalue("FibonacciSquare.fibo1", Some(vec![0]), F::from_canonical_u64(1)); - // air_instance.set_airvalue("FibonacciSquare.fibo1", Some(vec![1]), F::from_canonical_u64(2)); - // air_instance.set_airvalue_ext("FibonacciSquare.fibo3", None, vec![F::from_canonical_u64(5); 3]); + let mut proof_values = BuildProofValues::from_vec_guard(pctx.get_proof_values()); + proof_values.value1[0] = F::from_canonical_u64(5); + proof_values.value2[0] = F::from_canonical_u64(125); + + let mut air_values = FibonacciSquareAirValues::::new(); + air_values.fibo1[0][0] = F::from_canonical_u64(1); + air_values.fibo1[1][0] = F::from_canonical_u64(2); + air_values.fibo3 = [F::from_canonical_u64(5), F::from_canonical_u64(5), F::from_canonical_u64(5)]; + + AirInstance::from_trace( + pctx.clone(), + ectx.clone(), + sctx.clone(), + Some(0), + &mut trace, + Some(&mut vec![&mut trace_rom]), + Some(&mut air_values), + ); Ok(b) } } -impl WitnessComponent for FibonacciSquare { +impl WitnessComponent for FibonacciSquare { fn calculate_witness( &self, _stage: u32, diff --git a/examples/fibonacci-square/src/fibonacci_lib.rs b/examples/fibonacci-square/src/fibonacci_lib.rs index 3cc993d6..bcdf13ec 100644 --- a/examples/fibonacci-square/src/fibonacci_lib.rs +++ b/examples/fibonacci-square/src/fibonacci_lib.rs @@ -3,15 +3,15 @@ use std::sync::Arc; use proofman_common::{initialize_logger, load_from_json, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode}; use proofman::{WitnessLibrary, WitnessManager}; use pil_std_lib::Std; -use p3_field::PrimeField; +use p3_field::PrimeField64; use p3_goldilocks::Goldilocks; use std::error::Error; use std::path::PathBuf; -use crate::{BuildPublics, FibonacciSquare, Module}; +use crate::{BuildPublics, BuildPublicValues, FibonacciSquare, Module}; -pub struct FibonacciWitness { +pub struct FibonacciWitness { public_inputs_path: Option, wcm: Option>>, fibonacci: Option>>, @@ -19,13 +19,13 @@ pub struct FibonacciWitness { std_lib: Option>>, } -impl FibonacciWitness { +impl FibonacciWitness { pub fn new(public_inputs_path: Option) -> Self { Self { public_inputs_path, wcm: None, fibonacci: None, module: None, std_lib: None } } } -impl WitnessLibrary for FibonacciWitness { +impl WitnessLibrary for FibonacciWitness { fn start_proof(&mut self, pctx: Arc>, ectx: Arc, sctx: Arc) { let wcm = Arc::new(WitnessManager::new(pctx.clone(), ectx.clone(), sctx.clone())); @@ -40,9 +40,11 @@ impl WitnessLibrary for FibonacciWitness { let public_inputs: BuildPublics = load_from_json(&self.public_inputs_path); - pctx.set_public_value_by_name(public_inputs.module, "module", None); - pctx.set_public_value_by_name(public_inputs.in1, "in1", None); - pctx.set_public_value_by_name(public_inputs.in2, "in2", None); + let mut publics = BuildPublicValues::from_vec_guard(pctx.get_publics()); + + publics.module = F::from_canonical_u64(public_inputs.module); + publics.in1 = F::from_canonical_u64(public_inputs.in1); + publics.in2 = F::from_canonical_u64(public_inputs.in2); wcm.start_proof(pctx, ectx, sctx); } diff --git a/examples/fibonacci-square/src/module.rs b/examples/fibonacci-square/src/module.rs index f5a5445c..66fcc141 100644 --- a/examples/fibonacci-square/src/module.rs +++ b/examples/fibonacci-square/src/module.rs @@ -3,23 +3,26 @@ use std::sync::{Arc, Mutex}; use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use proofman::{WitnessManager, WitnessComponent}; use pil_std_lib::Std; -use p3_field::{AbstractField, PrimeField}; +use p3_field::{AbstractField, PrimeField64}; use num_bigint::BigInt; -use crate::{ModuleTrace, FIBONACCI_SQUARE_AIRGROUP_ID, MODULE_AIR_IDS}; +use crate::{ModuleTrace}; -pub struct Module { +pub struct Module { inputs: Mutex>, std_lib: Arc>, } -impl Module { +impl Module { const MY_NAME: &'static str = "ModuleSM"; pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let module = Arc::new(Module { inputs: Mutex::new(Vec::new()), std_lib }); - wcm.register_component(module.clone(), Some(FIBONACCI_SQUARE_AIRGROUP_ID), Some(MODULE_AIR_IDS)); + let airgroup_id = ModuleTrace::::get_airgroup_id(); + let air_id = ModuleTrace::::get_air_id(); + + wcm.register_component(module.clone(), airgroup_id, air_id); // Register dependency relations module.std_lib.register_predecessor(); @@ -44,7 +47,7 @@ impl Module fn calculate_trace(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); - let module = pctx.get_public_value("module"); + let module = F::as_canonical_u64(&pctx.get_public_value("module")); let mut trace = ModuleTrace::new_zeroes(); @@ -77,7 +80,7 @@ impl Module } } -impl WitnessComponent for Module { +impl WitnessComponent for Module { fn calculate_witness( &self, _stage: u32, diff --git a/examples/fibonacci-square/src/pil_helpers/mod.rs b/examples/fibonacci-square/src/pil_helpers/mod.rs index 9daf0c06..8e9f77af 100644 --- a/examples/fibonacci-square/src/pil_helpers/mod.rs +++ b/examples/fibonacci-square/src/pil_helpers/mod.rs @@ -1,5 +1,6 @@ // WARNING: This file has been autogenerated from the PILOUT file. // Manual modifications are not recommended and may be overwritten. +#[rustfmt::skip] mod traces; pub use traces::*; diff --git a/examples/fibonacci-square/src/pil_helpers/traces.rs b/examples/fibonacci-square/src/pil_helpers/traces.rs index 5efdfa3b..1eb43da5 100644 --- a/examples/fibonacci-square/src/pil_helpers/traces.rs +++ b/examples/fibonacci-square/src/pil_helpers/traces.rs @@ -4,6 +4,8 @@ use proofman_common as common; pub use proofman_macros::trace; pub use proofman_macros::values; +type FieldExtension = [F; 3]; + pub const PILOUT_HASH: &[u8] = b"Build-hash"; //AIRGROUP CONSTANTS @@ -24,15 +26,24 @@ use serde::Deserialize; use serde::Serialize; #[derive(Default, Debug, Serialize, Deserialize)] pub struct BuildPublics { - #[serde(default)] pub module: u64, #[serde(default)] pub in1: u64, #[serde(default)] pub in2: u64, #[serde(default)] pub out: u64, #[serde(default)] pub rom_root: [u64; 4], + #[serde(default)] + pub module: u64, + #[serde(default)] + pub in1: u64, + #[serde(default)] + pub in2: u64, + #[serde(default)] + pub out: u64, + #[serde(default)] + pub rom_root: [u64; 4], + } - -values!(BuildPublicValues { +values!(BuildPublicValues { module: F, in1: F, in2: F, out: F, rom_root: [F; 4], }); -values!(BuildProofValues { - value1: F, value2: F, +values!(BuildProofValues { + value1: FieldExtension, value2: FieldExtension, }); trace!(FibonacciSquareTrace { @@ -50,3 +61,7 @@ trace!(U8AirTrace { trace!(FibonacciSquareRomTrace { line: F, flags: F, }, 0, 0, 1024, 0 ); + +values!(FibonacciSquareAirValues { + fibo1: [FieldExtension; 2], fibo3: FieldExtension, +}); diff --git a/hints/src/hints.rs b/hints/src/hints.rs index 8f8692a5..8eba895c 100644 --- a/hints/src/hints.rs +++ b/hints/src/hints.rs @@ -682,23 +682,17 @@ pub fn mul_hint_fields( ) -> u64 { let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); - let public_inputs_ptr = (*proof_ctx.public_inputs.inputs.read().unwrap()).as_ptr() as *mut c_void; - let challenges_ptr = (*proof_ctx.challenges.challenges.read().unwrap()).as_ptr() as *mut c_void; - - let const_pols_ptr = (*setup.const_pols.values.read().unwrap()).as_ptr() as *mut c_void; - let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; - let steps_params = StepsParams { witness: air_instance.get_witness_ptr() as *mut c_void, trace: air_instance.get_trace_ptr() as *mut c_void, - public_inputs: public_inputs_ptr, - challenges: challenges_ptr, + public_inputs: proof_ctx.get_publics_ptr() as *mut c_void, + challenges: proof_ctx.get_challenges_ptr() as *mut c_void, airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, airvalues: air_instance.get_airvalues_ptr() as *mut c_void, evals: air_instance.get_evals_ptr() as *mut c_void, xdivxsub: std::ptr::null_mut(), - p_const_pols: const_pols_ptr, - p_const_tree: const_tree_ptr, + p_const_pols: setup.get_const_ptr() as *mut c_void, + p_const_tree: setup.get_const_tree_ptr() as *mut c_void, custom_commits: air_instance.get_custom_commits_ptr(), custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; @@ -728,23 +722,17 @@ pub fn acc_hint_field( ) -> (u64, u64) { let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); - let public_inputs_ptr = (*proof_ctx.public_inputs.inputs.read().unwrap()).as_ptr() as *mut c_void; - let challenges_ptr = (*proof_ctx.challenges.challenges.read().unwrap()).as_ptr() as *mut c_void; - - let const_pols_ptr = (*setup.const_pols.values.read().unwrap()).as_ptr() as *mut c_void; - let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; - let steps_params = StepsParams { witness: air_instance.get_witness_ptr() as *mut c_void, trace: air_instance.get_trace_ptr() as *mut c_void, - public_inputs: public_inputs_ptr, - challenges: challenges_ptr, + public_inputs: proof_ctx.get_publics_ptr() as *mut c_void, + challenges: proof_ctx.get_challenges_ptr() as *mut c_void, airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, airvalues: air_instance.get_airvalues_ptr() as *mut c_void, evals: air_instance.get_evals_ptr() as *mut c_void, xdivxsub: std::ptr::null_mut(), - p_const_pols: const_pols_ptr, - p_const_tree: const_tree_ptr, + p_const_pols: setup.get_const_ptr() as *mut c_void, + p_const_tree: setup.get_const_tree_ptr() as *mut c_void, custom_commits: air_instance.get_custom_commits_ptr(), custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; @@ -782,23 +770,17 @@ pub fn acc_mul_hint_fields( ) -> (u64, u64) { let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); - let public_inputs_ptr = (*proof_ctx.public_inputs.inputs.read().unwrap()).as_ptr() as *mut c_void; - let challenges_ptr = (*proof_ctx.challenges.challenges.read().unwrap()).as_ptr() as *mut c_void; - - let const_pols_ptr = (*setup.const_pols.values.read().unwrap()).as_ptr() as *mut c_void; - let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; - let steps_params = StepsParams { witness: air_instance.get_witness_ptr() as *mut c_void, trace: air_instance.get_trace_ptr() as *mut c_void, - public_inputs: public_inputs_ptr, - challenges: challenges_ptr, + public_inputs: proof_ctx.get_publics_ptr() as *mut c_void, + challenges: proof_ctx.get_challenges_ptr() as *mut c_void, airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, airvalues: air_instance.get_airvalues_ptr() as *mut c_void, evals: air_instance.get_evals_ptr() as *mut c_void, xdivxsub: std::ptr::null_mut(), - p_const_pols: const_pols_ptr, - p_const_tree: const_tree_ptr, + p_const_pols: setup.get_const_ptr() as *mut c_void, + p_const_tree: setup.get_const_tree_ptr() as *mut c_void, custom_commits: air_instance.get_custom_commits_ptr(), custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; @@ -833,23 +815,17 @@ pub fn get_hint_field( ) -> HintFieldValue { let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); - let public_inputs_ptr = (*proof_ctx.public_inputs.inputs.read().unwrap()).as_ptr() as *mut c_void; - let challenges_ptr = (*proof_ctx.challenges.challenges.read().unwrap()).as_ptr() as *mut c_void; - - let const_pols_ptr = (*setup.const_pols.values.read().unwrap()).as_ptr() as *mut c_void; - let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; - let steps_params = StepsParams { witness: air_instance.get_witness_ptr() as *mut c_void, trace: air_instance.get_trace_ptr() as *mut c_void, - public_inputs: public_inputs_ptr, - challenges: challenges_ptr, + public_inputs: proof_ctx.get_publics_ptr() as *mut c_void, + challenges: proof_ctx.get_challenges_ptr() as *mut c_void, airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, airvalues: air_instance.get_airvalues_ptr() as *mut c_void, evals: air_instance.get_evals_ptr() as *mut c_void, xdivxsub: std::ptr::null_mut(), - p_const_pols: const_pols_ptr, - p_const_tree: const_tree_ptr, + p_const_pols: setup.get_const_ptr() as *mut c_void, + p_const_tree: setup.get_const_tree_ptr() as *mut c_void, custom_commits: air_instance.get_custom_commits_ptr(), custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; @@ -887,23 +863,17 @@ pub fn get_hint_field_a( ) -> HintFieldValuesVec { let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); - let public_inputs_ptr = (*proof_ctx.public_inputs.inputs.read().unwrap()).as_ptr() as *mut c_void; - let challenges_ptr = (*proof_ctx.challenges.challenges.read().unwrap()).as_ptr() as *mut c_void; - - let const_pols_ptr = (*setup.const_pols.values.read().unwrap()).as_ptr() as *mut c_void; - let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; - let steps_params = StepsParams { witness: air_instance.get_witness_ptr() as *mut c_void, trace: air_instance.get_trace_ptr() as *mut c_void, - public_inputs: public_inputs_ptr, - challenges: challenges_ptr, + public_inputs: proof_ctx.get_publics_ptr() as *mut c_void, + challenges: proof_ctx.get_challenges_ptr() as *mut c_void, airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, airvalues: air_instance.get_airvalues_ptr() as *mut c_void, evals: air_instance.get_evals_ptr() as *mut c_void, xdivxsub: std::ptr::null_mut(), - p_const_pols: const_pols_ptr, - p_const_tree: const_tree_ptr, + p_const_pols: setup.get_const_ptr() as *mut c_void, + p_const_tree: setup.get_const_tree_ptr() as *mut c_void, custom_commits: air_instance.get_custom_commits_ptr(), custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; @@ -947,23 +917,17 @@ pub fn get_hint_field_m( ) -> HintFieldValues { let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); - let public_inputs_ptr = (*proof_ctx.public_inputs.inputs.read().unwrap()).as_ptr() as *mut c_void; - let challenges_ptr = (*proof_ctx.challenges.challenges.read().unwrap()).as_ptr() as *mut c_void; - - let const_pols_ptr = (*setup.const_pols.values.read().unwrap()).as_ptr() as *mut c_void; - let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; - let steps_params = StepsParams { witness: air_instance.get_witness_ptr() as *mut c_void, trace: air_instance.get_trace_ptr() as *mut c_void, - public_inputs: public_inputs_ptr, - challenges: challenges_ptr, + public_inputs: proof_ctx.get_publics_ptr() as *mut c_void, + challenges: proof_ctx.get_challenges_ptr() as *mut c_void, airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, airvalues: air_instance.get_airvalues_ptr() as *mut c_void, evals: air_instance.get_evals_ptr() as *mut c_void, xdivxsub: std::ptr::null_mut(), - p_const_pols: const_pols_ptr, - p_const_tree: const_tree_ptr, + p_const_pols: setup.get_const_ptr() as *mut c_void, + p_const_tree: setup.get_const_tree_ptr() as *mut c_void, custom_commits: air_instance.get_custom_commits_ptr(), custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; @@ -1163,9 +1127,7 @@ pub fn set_hint_field( _ => panic!("Only column and column extended are accepted"), }; - let id = set_hint_field_c((&setup.p_setup).into(), (&steps_params).into(), values_ptr, hint_id, hint_field_name); - - air_instance.set_commit_calculated(id as usize); + set_hint_field_c((&setup.p_setup).into(), (&steps_params).into(), values_ptr, hint_id, hint_field_name); } pub fn set_hint_field_val( @@ -1207,9 +1169,7 @@ pub fn set_hint_field_val( let values_ptr = value_array.as_ptr() as *mut c_void; - let id = set_hint_field_c((&setup.p_setup).into(), (&steps_params).into(), values_ptr, hint_id, hint_field_name); - - air_instance.set_airgroupvalue_calculated(id as usize); + set_hint_field_c((&setup.p_setup).into(), (&steps_params).into(), values_ptr, hint_id, hint_field_name); } pub fn print_row(setup_ctx: &SetupCtx, air_instance: &AirInstance, stage: u64, row: u64) { diff --git a/macros/src/lib.rs b/macros/src/lib.rs index b1ae841c..91386a17 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -50,15 +50,6 @@ fn trace_impl(input: TokenStream2) -> Result { impl<#generics: Copy> #row_struct_name<#generics> { pub const ROW_SIZE: usize = #row_size; - - pub fn as_slice(&self) -> &[#generics] { - unsafe { - std::slice::from_raw_parts( - self as *const #row_struct_name<#generics> as *const #generics, - #row_size, - ) - } - } } }; @@ -85,12 +76,12 @@ fn trace_impl(input: TokenStream2) -> Result { assert!(num_rows & (num_rows - 1) == 0); let mut buff_uninit: Vec> = Vec::with_capacity(num_rows * #row_struct_name::<#generics>::ROW_SIZE); - + unsafe { buff_uninit.set_len(num_rows * #row_struct_name::<#generics>::ROW_SIZE); } let buffer: Vec<#generics> = unsafe { std::mem::transmute(buff_uninit) }; - + let slice_trace = unsafe { std::slice::from_raw_parts_mut( buffer.as_ptr() as *mut #row_struct_name<#generics>, @@ -120,7 +111,7 @@ fn trace_impl(input: TokenStream2) -> Result { num_rows, ) }; - + #trace_struct_name { buffer, slice_trace, @@ -135,6 +126,14 @@ fn trace_impl(input: TokenStream2) -> Result { self.num_rows } + pub fn get_airgroup_id() -> usize { + Self::AIRGROUP_ID + } + + pub fn get_air_id() -> usize { + Self::AIR_ID + } + pub fn airgroup_id(&self) -> usize { self.airgroup_id } @@ -179,7 +178,7 @@ fn trace_impl(input: TokenStream2) -> Result { fn get_buffer(&mut self) -> Vec<#generics> { let buffer = std::mem::take(&mut self.buffer); buffer - } + } } }; @@ -247,8 +246,8 @@ impl Parse for ParsedTraceInput { fields, airgroup_id, air_id, - num_rows, - commit_id + num_rows, + commit_id, }) } } @@ -280,20 +279,19 @@ pub fn values(input: TokenStream) -> TokenStream { fn values_impl(input: TokenStream2) -> Result { let parsed_input: ParsedValuesInput = parse2(input)?; - let struct_name = parsed_input.struct_name; - let generic_param = parsed_input.generic_param; - let dimensions = parsed_input.dimensions; + let row_struct_name = parsed_input.row_struct_name; + let values_struct_name = parsed_input.struct_name; + let generics = parsed_input.generics.params; let fields = parsed_input.fields; - // Calculate ROW_SIZE based on the field types - let row_size = fields + // Calculate TOTAL_SIZE based on the field types + let total_size = fields .named .iter() - .map(|field| calculate_field_size_literal(&field.ty)) + .map(|field| calculate_field_slots(&field.ty)) .collect::>>()? .into_iter() - .sum::() - * dimensions; + .sum::(); // Generate row struct let field_definitions = fields.named.iter().map(|field| { @@ -303,49 +301,156 @@ fn values_impl(input: TokenStream2) -> Result { let row_struct = quote! { #[repr(C)] - #[derive(Debug, Clone, Default)] - pub struct #struct_name<#generic_param> { + #[derive(Debug, Clone, Copy, Default)] + pub struct #row_struct_name<#generics> { #(#field_definitions)* - } - impl<#generic_param: Copy> #struct_name<#generic_param> { - pub const ROW_SIZE: usize = #row_size; + } - pub fn as_slice(&self) -> &[#generic_param] { - unsafe { - std::slice::from_raw_parts( - self as *const #struct_name<#generic_param> as *const #generic_param, - #row_size, - ) + impl<#generics: Copy> #row_struct_name<#generics> { + pub const TOTAL_SIZE: usize = #total_size; + } + }; + + let values_struct = quote! { + pub struct #values_struct_name<'a, #generics> { + pub buffer: Vec<#generics>, + pub slice_values: &'a mut #row_struct_name<#generics>, + } + + impl<'a, #generics: Default + Clone + Copy> #values_struct_name<'a, #generics> { + pub fn new() -> Self { + let mut buffer = vec![#generics::default(); #row_struct_name::<#generics>::TOTAL_SIZE]; // Interpolate here as well + + let slice_values = unsafe { + let ptr = buffer.as_mut_ptr() as *mut #row_struct_name<#generics>; + &mut *ptr + }; + + #values_struct_name { + buffer: buffer, + slice_values, + } + } + + pub fn from_vec( + mut external_buffer: Vec<#generics>, + ) -> Self { + let slice_values = unsafe { + // Create a mutable slice from the raw pointer of external_buffer + let ptr = external_buffer.as_mut_ptr() as *mut #row_struct_name<#generics>; + &mut *ptr + }; + + // Return the struct with the owned buffers and borrowed slices + #values_struct_name { + buffer: external_buffer, + slice_values, + } + } + + pub fn from_vec_guard( + mut external_buffer_rw: std::sync::RwLockWriteGuard>, + ) -> Self { + let slice_values = unsafe { + let ptr = external_buffer_rw.as_mut_ptr() as *mut #row_struct_name<#generics>; + &mut *ptr + }; + + #values_struct_name { + buffer: Vec::new(), + slice_values, } } } + + impl<'a, #generics> std::ops::Deref for #values_struct_name<'a, #generics> { + type Target = #row_struct_name<#generics>; + + fn deref(&self) -> &Self::Target { + &self.slice_values + } + } + + impl<'a, #generics> std::ops::DerefMut for #values_struct_name<'a, #generics> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.slice_values + } + } + + impl<'a, #generics: Send + p3_field::Field> common::trace::Values<#generics> for #values_struct_name<'a, #generics> { + fn get_buffer(&mut self) -> Vec<#generics> { + let buffer = std::mem::take(&mut self.buffer); + buffer + } + } + }; Ok(quote! { #row_struct + #values_struct }) } struct ParsedValuesInput { - pub struct_name: Ident, - pub generic_param: Ident, - pub dimensions: usize, - pub fields: FieldsNamed, + row_struct_name: Ident, + struct_name: Ident, + generics: Generics, + fields: FieldsNamed, } impl Parse for ParsedValuesInput { fn parse(input: ParseStream) -> Result { - let struct_name: Ident = input.parse()?; - input.parse::()?; - let generic_param: Ident = input.parse()?; - input.parse::()?; - let dimensions: LitInt = input.parse()?; - input.parse::]>()?; + let lookahead = input.lookahead1(); + let row_struct_name; + + // Handle explicit or implicit row struct names + if lookahead.peek(Ident) && input.peek2(Token![,]) { + row_struct_name = Some(input.parse::()?); + input.parse::()?; // Skip comma after explicit row name + } else { + row_struct_name = None; + } + + let struct_name = input.parse::()?; + let row_struct_name = row_struct_name.unwrap_or_else(|| format_ident!("{}Row", struct_name)); + + let generics: Generics = input.parse()?; let fields: FieldsNamed = input.parse()?; - Ok(ParsedValuesInput { struct_name, generic_param, dimensions: dimensions.base10_parse()?, fields }) + + Ok(ParsedValuesInput { row_struct_name, struct_name, generics, fields }) } } +fn calculate_field_slots(ty: &syn::Type) -> Result { + match ty { + // Handle `F` + syn::Type::Path(type_path) if is_ident(type_path, "F") => Ok(1), + + // Handle `FieldExtension` + syn::Type::Path(type_path) if is_ident(type_path, "FieldExtension") => { + // Assuming FieldExtension size is always 3 slots for this example. + Ok(3) + } + + // Handle `[F; N]` and `[FieldExtension; N]` + syn::Type::Array(type_array) => { + let len = type_array.len.to_token_stream().to_string().parse::().map_err(|e| { + syn::Error::new_spanned(&type_array.len, format!("Failed to parse array length: {}", e)) + })?; + let elem_slots = calculate_field_slots(&type_array.elem)?; + Ok(len * elem_slots) + } + + _ => Err(syn::Error::new_spanned(ty, "Unsupported type for slot calculation")), + } +} + +// Helper to check if a type is a specific identifier +fn is_ident(type_path: &syn::TypePath, name: &str) -> bool { + type_path.path.segments.last().map_or(false, |seg| seg.ident == name) +} + #[test] fn test_parse_values_01() { let input = quote! { @@ -353,7 +458,7 @@ fn test_parse_values_01() { }; let parsed: ParsedValuesInput = parse2(input).unwrap(); assert_eq!(parsed.struct_name, "Values"); - assert_eq!(parsed.generic_param, "F"); + assert_eq!(parsed.generics, "F"); assert_eq!(parsed.dimensions, 3); } @@ -364,7 +469,7 @@ fn test_parse_values_02() { }; let parsed: ParsedValuesInput = parse2(input).unwrap(); assert_eq!(parsed.struct_name, "Something"); - assert_eq!(parsed.generic_param, "G"); + assert_eq!(parsed.generics, "G"); assert_eq!(parsed.dimensions, 2); } @@ -375,7 +480,7 @@ fn test_parse_values_03() { }; let parsed: ParsedValuesInput = parse2(input).unwrap(); assert_eq!(parsed.struct_name, "Something"); - assert_eq!(parsed.generic_param, "G"); + assert_eq!(parsed.generics, "G"); assert_eq!(parsed.dimensions, 189_432); } diff --git a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs index 0a4f1057..0a585329 100644 --- a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs +++ b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs @@ -73,7 +73,7 @@ impl SpecifiedRanges { mul_columns: Mutex::new(Vec::new()), }); - wcm.register_component(specified_ranges.clone(), Some(airgroup_id), Some(&[air_id])); + wcm.register_component(specified_ranges.clone(), airgroup_id, air_id); specified_ranges } @@ -133,7 +133,8 @@ impl SpecifiedRanges { let num_rows = pctx.global_info.airs[self.airgroup_id][self.air_id].num_rows; let buffer_size = multiplicities.len() * num_rows; let buffer: Vec = create_buffer_fast(buffer_size); - let air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer, None, None); + let air_instance = + AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer, None, None); pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)); pctx.air_instance_repo.air_instances.read().unwrap().len() - 1 }; diff --git a/pil2-components/lib/std/rs/src/range_check/std_range_check.rs b/pil2-components/lib/std/rs/src/range_check/std_range_check.rs index 8d3e7e52..3b3b0ae5 100644 --- a/pil2-components/lib/std/rs/src/range_check/std_range_check.rs +++ b/pil2-components/lib/std/rs/src/range_check/std_range_check.rs @@ -80,7 +80,7 @@ impl StdRangeCheck { let std_range_check = Arc::new(Self { mode, ranges: Mutex::new(Vec::new()), u8air, u16air, specified_ranges }); - wcm.register_component(std_range_check.clone(), None, None); + wcm.register_std(std_range_check.clone()); std_range_check } diff --git a/pil2-components/lib/std/rs/src/range_check/u16air.rs b/pil2-components/lib/std/rs/src/range_check/u16air.rs index d754a342..8512d515 100644 --- a/pil2-components/lib/std/rs/src/range_check/u16air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u16air.rs @@ -66,7 +66,7 @@ impl U16Air { mul_column: Mutex::new(HintFieldValue::Field(F::zero())), }); - wcm.register_component(u16air.clone(), Some(airgroup_id), Some(&[air_id])); + wcm.register_component(u16air.clone(), airgroup_id, air_id); u16air } @@ -117,7 +117,8 @@ impl U16Air { let num_rows = pctx.global_info.airs[self.airgroup_id][self.air_id].num_rows; let buffer_size = num_rows; let buffer: Vec = create_buffer_fast(buffer_size); - let air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer, None, None); + let air_instance = + AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer, None, None); pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)); pctx.air_instance_repo.air_instances.read().unwrap().len() - 1 }; diff --git a/pil2-components/lib/std/rs/src/range_check/u8air.rs b/pil2-components/lib/std/rs/src/range_check/u8air.rs index cf26eaa3..85a06b8a 100644 --- a/pil2-components/lib/std/rs/src/range_check/u8air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u8air.rs @@ -65,7 +65,7 @@ impl U8Air { mul_column: Mutex::new(HintFieldValue::Field(F::zero())), }); - wcm.register_component(u8air.clone(), Some(airgroup_id), Some(&[air_id])); + wcm.register_component(u8air.clone(), airgroup_id, air_id); u8air } @@ -115,7 +115,8 @@ impl U8Air { let num_rows = pctx.global_info.airs[self.airgroup_id][self.air_id].num_rows; let buffer_size = num_rows; let buffer: Vec = create_buffer_fast(buffer_size); - let air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer, None, None); + let air_instance = + AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer, None, None); pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)); pctx.air_instance_repo.air_instances.read().unwrap().len() - 1 }; diff --git a/pil2-components/lib/std/rs/src/std_prod.rs b/pil2-components/lib/std/rs/src/std_prod.rs index 0d9bb101..c534c48e 100644 --- a/pil2-components/lib/std/rs/src/std_prod.rs +++ b/pil2-components/lib/std/rs/src/std_prod.rs @@ -51,7 +51,7 @@ impl StdProd { debug_data: if mode.name == ModeName::Debug { Some(Mutex::new(HashMap::new())) } else { None }, }); - wcm.register_component(std_prod.clone(), None, None); + wcm.register_std(std_prod.clone()); std_prod } @@ -290,7 +290,7 @@ impl WitnessComponent for StdProd { // This call calculates "numerator" / "denominator" and accumulates it into "reference". Its last value is stored into "result" // Alternatively, this could be done using get_hint_field and set_hint_field methods and calculating the operations in Rust, // TODO: GENERALIZE CALLS - let (pol_id, airgroupvalue_id) = acc_mul_hint_fields::( + acc_mul_hint_fields::( &sctx, &pctx, air_instance, @@ -303,9 +303,6 @@ impl WitnessComponent for StdProd { HintFieldOptions::inverse(), false, ); - - air_instance.set_commit_calculated(pol_id as usize); - air_instance.set_airgroupvalue_calculated(airgroupvalue_id as usize); } } } diff --git a/pil2-components/lib/std/rs/src/std_sum.rs b/pil2-components/lib/std/rs/src/std_sum.rs index f74eacf0..7b89d6ee 100644 --- a/pil2-components/lib/std/rs/src/std_sum.rs +++ b/pil2-components/lib/std/rs/src/std_sum.rs @@ -52,7 +52,7 @@ impl StdSum { debug_data: if mode.name == ModeName::Debug { Some(Mutex::new(HashMap::new())) } else { None }, }); - wcm.register_component(std_sum.clone(), None, None); + wcm.register_std(std_sum.clone()); std_sum } @@ -280,7 +280,7 @@ impl WitnessComponent for StdSum { // Populate the im columns for hint in im_hints { - let id = mul_hint_fields::( + mul_hint_fields::( &sctx, &pctx, air_instance, @@ -291,8 +291,6 @@ impl WitnessComponent for StdSum { "denominator", HintFieldOptions::inverse(), ); - - air_instance.set_commit_calculated(id as usize); } // We know that at most one product hint exists @@ -305,7 +303,7 @@ impl WitnessComponent for StdSum { // This call accumulates "expression" into "reference" expression and stores its last value to "result" // Alternatively, this could be done using get_hint_field and set_hint_field methods and doing the accumulation in Rust, // TODO: GENERALIZE CALLS - let (pol_id, airgroupvalue_id) = acc_mul_hint_fields::( + acc_mul_hint_fields::( &sctx, &pctx, air_instance, @@ -318,9 +316,6 @@ impl WitnessComponent for StdSum { HintFieldOptions::inverse(), true, ); - - air_instance.set_commit_calculated(pol_id as usize); - air_instance.set_airgroupvalue_calculated(airgroupvalue_id as usize); } } } diff --git a/pil2-components/test/simple/rs/src/pil_helpers/traces.rs b/pil2-components/test/simple/rs/src/pil_helpers/traces.rs index 383beb4b..bb74ad83 100644 --- a/pil2-components/test/simple/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/simple/rs/src/pil_helpers/traces.rs @@ -16,7 +16,6 @@ pub const SIMPLE_LEFT_AIR_IDS: &[usize] = &[0]; pub const SIMPLE_RIGHT_AIR_IDS: &[usize] = &[1]; - trace!(SimpleLeftTrace { a: F, b: F, c: F, d: F, e: F, f: F, g: F, h: F, }, 0, 0, 4, 0 ); diff --git a/pil2-components/test/simple/rs/src/simple_left.rs b/pil2-components/test/simple/rs/src/simple_left.rs index 2150c850..30ea3698 100644 --- a/pil2-components/test/simple/rs/src/simple_left.rs +++ b/pil2-components/test/simple/rs/src/simple_left.rs @@ -6,7 +6,7 @@ use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, seq::SliceRandom}; -use crate::{SimpleLeftTrace, SIMPLE_AIRGROUP_ID, SIMPLE_LEFT_AIR_IDS}; +use crate::SimpleLeftTrace; pub struct SimpleLeft { _phantom: std::marker::PhantomData, @@ -21,7 +21,10 @@ where pub fn new(wcm: Arc>) -> Arc { let simple_left = Arc::new(Self { _phantom: std::marker::PhantomData }); - wcm.register_component(simple_left.clone(), Some(SIMPLE_AIRGROUP_ID), Some(SIMPLE_LEFT_AIR_IDS)); + let airgroup_id = SimpleLeftTrace::::get_airgroup_id(); + let air_id = SimpleLeftTrace::::get_air_id(); + + wcm.register_component(simple_left.clone(), airgroup_id, air_id); simple_left } diff --git a/pil2-components/test/simple/rs/src/simple_right.rs b/pil2-components/test/simple/rs/src/simple_right.rs index 9c0f9c13..1731ded9 100644 --- a/pil2-components/test/simple/rs/src/simple_right.rs +++ b/pil2-components/test/simple/rs/src/simple_right.rs @@ -6,7 +6,7 @@ use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution}; -use crate::{SimpleRightTrace, SIMPLE_AIRGROUP_ID, SIMPLE_RIGHT_AIR_IDS}; +use crate::SimpleRightTrace; pub struct SimpleRight { _phantom: std::marker::PhantomData, @@ -21,7 +21,10 @@ where pub fn new(wcm: Arc>) -> Arc { let simple_right = Arc::new(Self { _phantom: std::marker::PhantomData }); - wcm.register_component(simple_right.clone(), Some(SIMPLE_AIRGROUP_ID), Some(SIMPLE_RIGHT_AIR_IDS)); + let airgroup_id = SimpleRightTrace::::get_airgroup_id(); + let air_id = SimpleRightTrace::::get_air_id(); + + wcm.register_component(simple_right.clone(), airgroup_id, air_id); simple_right } diff --git a/pil2-components/test/std/connection/rs/src/connection1.rs b/pil2-components/test/std/connection/rs/src/connection1.rs index ec459d4a..89de6fee 100644 --- a/pil2-components/test/std/connection/rs/src/connection1.rs +++ b/pil2-components/test/std/connection/rs/src/connection1.rs @@ -6,7 +6,7 @@ use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; -use crate::{Connection1Trace, CONNECTION_1_AIR_IDS, CONNECTION_AIRGROUP_ID}; +use crate::Connection1Trace; pub struct Connection1 { _phantom: std::marker::PhantomData, @@ -21,7 +21,10 @@ where pub fn new(wcm: Arc>) -> Arc { let connection1 = Arc::new(Self { _phantom: std::marker::PhantomData }); - wcm.register_component(connection1.clone(), Some(CONNECTION_AIRGROUP_ID), Some(CONNECTION_1_AIR_IDS)); + let airgroup_id = Connection1Trace::::get_airgroup_id(); + let air_id = Connection1Trace::::get_air_id(); + + wcm.register_component(connection1.clone(), airgroup_id, air_id); connection1 } diff --git a/pil2-components/test/std/connection/rs/src/connection2.rs b/pil2-components/test/std/connection/rs/src/connection2.rs index 1a31cc9c..8cccbf21 100644 --- a/pil2-components/test/std/connection/rs/src/connection2.rs +++ b/pil2-components/test/std/connection/rs/src/connection2.rs @@ -6,7 +6,7 @@ use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; -use crate::{Connection2Trace, CONNECTION_2_AIR_IDS, CONNECTION_AIRGROUP_ID}; +use crate::Connection2Trace; pub struct Connection2 { _phantom: std::marker::PhantomData, @@ -21,7 +21,10 @@ where pub fn new(wcm: Arc>) -> Arc { let connection2 = Arc::new(Self { _phantom: std::marker::PhantomData }); - wcm.register_component(connection2.clone(), Some(CONNECTION_AIRGROUP_ID), Some(CONNECTION_2_AIR_IDS)); + let airgroup_id = Connection2Trace::::get_airgroup_id(); + let air_id = Connection2Trace::::get_air_id(); + + wcm.register_component(connection2.clone(), airgroup_id, air_id); connection2 } diff --git a/pil2-components/test/std/connection/rs/src/connection_new.rs b/pil2-components/test/std/connection/rs/src/connection_new.rs index 32f03288..a49b1dca 100644 --- a/pil2-components/test/std/connection/rs/src/connection_new.rs +++ b/pil2-components/test/std/connection/rs/src/connection_new.rs @@ -6,7 +6,7 @@ use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; -use crate::{ConnectionNewTrace, CONNECTION_AIRGROUP_ID, CONNECTION_NEW_AIR_IDS}; +use crate::ConnectionNewTrace; pub struct ConnectionNew { _phantom: std::marker::PhantomData, @@ -21,7 +21,10 @@ where pub fn new(wcm: Arc>) -> Arc { let connection_new = Arc::new(Self { _phantom: std::marker::PhantomData }); - wcm.register_component(connection_new.clone(), Some(CONNECTION_AIRGROUP_ID), Some(CONNECTION_NEW_AIR_IDS)); + let airgroup_id = ConnectionNewTrace::::get_airgroup_id(); + let air_id = ConnectionNewTrace::::get_air_id(); + + wcm.register_component(connection_new.clone(), airgroup_id, air_id); connection_new } diff --git a/pil2-components/test/std/connection/rs/src/pil_helpers/traces.rs b/pil2-components/test/std/connection/rs/src/pil_helpers/traces.rs index 0d3bb6a9..b46a23ca 100644 --- a/pil2-components/test/std/connection/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/std/connection/rs/src/pil_helpers/traces.rs @@ -18,7 +18,6 @@ pub const CONNECTION_2_AIR_IDS: &[usize] = &[1]; pub const CONNECTION_NEW_AIR_IDS: &[usize] = &[2]; - trace!(Connection1Trace { a: F, b: F, c: F, }, 0, 0, 8, 0 ); diff --git a/pil2-components/test/std/lookup/rs/src/lookup0.rs b/pil2-components/test/std/lookup/rs/src/lookup0.rs index 25afa180..a63e3560 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup0.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup0.rs @@ -6,7 +6,7 @@ use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; -use crate::{Lookup0Trace, LOOKUP_0_AIR_IDS, LOOKUP_AIRGROUP_ID}; +use crate::Lookup0Trace; pub struct Lookup0 { _phantom: std::marker::PhantomData, @@ -21,7 +21,10 @@ where pub fn new(wcm: Arc>) -> Arc { let lookup0 = Arc::new(Self { _phantom: std::marker::PhantomData }); - wcm.register_component(lookup0.clone(), Some(LOOKUP_AIRGROUP_ID), Some(LOOKUP_0_AIR_IDS)); + let airgroup_id = Lookup0Trace::::get_airgroup_id(); + let air_id = Lookup0Trace::::get_air_id(); + + wcm.register_component(lookup0.clone(), airgroup_id, air_id); lookup0 } diff --git a/pil2-components/test/std/lookup/rs/src/lookup1.rs b/pil2-components/test/std/lookup/rs/src/lookup1.rs index 709cd001..1324fd56 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup1.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup1.rs @@ -6,7 +6,7 @@ use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; -use crate::{Lookup1Trace, LOOKUP_1_AIR_IDS, LOOKUP_AIRGROUP_ID}; +use crate::Lookup1Trace; pub struct Lookup1 { _phantom: std::marker::PhantomData, @@ -21,7 +21,10 @@ where pub fn new(wcm: Arc>) -> Arc { let lookup1 = Arc::new(Self { _phantom: std::marker::PhantomData }); - wcm.register_component(lookup1.clone(), Some(LOOKUP_AIRGROUP_ID), Some(LOOKUP_1_AIR_IDS)); + let airgroup_id = Lookup1Trace::::get_airgroup_id(); + let air_id = Lookup1Trace::::get_air_id(); + + wcm.register_component(lookup1.clone(), airgroup_id, air_id); lookup1 } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs index bc14c125..8a54b4e1 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs @@ -6,7 +6,7 @@ use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; -use crate::{Lookup2_12Trace, LOOKUP_2_12_AIR_IDS, LOOKUP_AIRGROUP_ID}; +use crate::Lookup2_12Trace; pub struct Lookup2_12 { _phantom: std::marker::PhantomData, @@ -21,7 +21,10 @@ where pub fn new(wcm: Arc>) -> Arc { let lookup2_12 = Arc::new(Self { _phantom: std::marker::PhantomData }); - wcm.register_component(lookup2_12.clone(), Some(LOOKUP_AIRGROUP_ID), Some(LOOKUP_2_12_AIR_IDS)); + let airgroup_id = Lookup2_12Trace::::get_airgroup_id(); + let air_id = Lookup2_12Trace::::get_air_id(); + + wcm.register_component(lookup2_12.clone(), airgroup_id, air_id); lookup2_12 } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs index 136592e1..d98da402 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs @@ -6,7 +6,7 @@ use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; -use crate::{Lookup2_13Trace, LOOKUP_2_13_AIR_IDS, LOOKUP_AIRGROUP_ID}; +use crate::Lookup2_13Trace; pub struct Lookup2_13 { _phantom: std::marker::PhantomData, @@ -21,7 +21,10 @@ where pub fn new(wcm: Arc>) -> Arc { let lookup2_13 = Arc::new(Self { _phantom: std::marker::PhantomData }); - wcm.register_component(lookup2_13.clone(), Some(LOOKUP_AIRGROUP_ID), Some(LOOKUP_2_13_AIR_IDS)); + let airgroup_id = Lookup2_13Trace::::get_airgroup_id(); + let air_id = Lookup2_13Trace::::get_air_id(); + + wcm.register_component(lookup2_13.clone(), airgroup_id, air_id); lookup2_13 } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs index c3e9cd55..ea8baa8f 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs @@ -6,7 +6,7 @@ use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; -use crate::{Lookup2_15Trace, LOOKUP_2_15_AIR_IDS, LOOKUP_AIRGROUP_ID}; +use crate::Lookup2_15Trace; pub struct Lookup2_15 { _phantom: std::marker::PhantomData, @@ -21,7 +21,10 @@ where pub fn new(wcm: Arc>) -> Arc { let lookup2_15 = Arc::new(Self { _phantom: std::marker::PhantomData }); - wcm.register_component(lookup2_15.clone(), Some(LOOKUP_AIRGROUP_ID), Some(LOOKUP_2_15_AIR_IDS)); + let airgroup_id = Lookup2_15Trace::::get_airgroup_id(); + let air_id = Lookup2_15Trace::::get_air_id(); + + wcm.register_component(lookup2_15.clone(), airgroup_id, air_id); lookup2_15 } diff --git a/pil2-components/test/std/lookup/rs/src/lookup3.rs b/pil2-components/test/std/lookup/rs/src/lookup3.rs index 7eddf16d..291f81a5 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup3.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup3.rs @@ -5,7 +5,7 @@ use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; -use crate::{Lookup3Trace, LOOKUP_3_AIR_IDS, LOOKUP_AIRGROUP_ID}; +use crate::Lookup3Trace; pub struct Lookup3 { _phantom: std::marker::PhantomData, @@ -17,7 +17,10 @@ impl Lookup3 { pub fn new(wcm: Arc>) -> Arc { let lookup3 = Arc::new(Self { _phantom: std::marker::PhantomData }); - wcm.register_component(lookup3.clone(), Some(LOOKUP_AIRGROUP_ID), Some(LOOKUP_3_AIR_IDS)); + let airgroup_id = Lookup3Trace::::get_airgroup_id(); + let air_id = Lookup3Trace::::get_air_id(); + + wcm.register_component(lookup3.clone(), airgroup_id, air_id); lookup3 } diff --git a/pil2-components/test/std/lookup/rs/src/pil_helpers/traces.rs b/pil2-components/test/std/lookup/rs/src/pil_helpers/traces.rs index ae47e822..9150a8de 100644 --- a/pil2-components/test/std/lookup/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/std/lookup/rs/src/pil_helpers/traces.rs @@ -4,6 +4,8 @@ use proofman_common as common; pub use proofman_macros::trace; pub use proofman_macros::values; +type FieldExtension = [F; 3]; + pub const PILOUT_HASH: &[u8] = b"Build-hash"; //AIRGROUP CONSTANTS diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs index a6d28b3a..56d82d3c 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs @@ -6,7 +6,7 @@ use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, seq::SliceRandom, Rng}; -use crate::{Permutation1_6Trace, PERMUTATION_1_6_AIR_IDS, PERMUTATION_AIRGROUP_ID}; +use crate::Permutation1_6Trace; pub struct Permutation1_6 { _phantom: std::marker::PhantomData, @@ -21,7 +21,10 @@ where pub fn new(wcm: Arc>) -> Arc { let permutation1_6 = Arc::new(Self { _phantom: std::marker::PhantomData }); - wcm.register_component(permutation1_6.clone(), Some(PERMUTATION_AIRGROUP_ID), Some(PERMUTATION_1_6_AIR_IDS)); + let airgroup_id = Permutation1_6Trace::::get_airgroup_id(); + let air_id = Permutation1_6Trace::::get_air_id(); + + wcm.register_component(permutation1_6.clone(), airgroup_id, air_id); permutation1_6 } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs index 0e743a09..c5e86009 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs @@ -6,7 +6,7 @@ use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; -use crate::{Permutation1_7Trace, PERMUTATION_1_7_AIR_IDS, PERMUTATION_AIRGROUP_ID}; +use crate::Permutation1_7Trace; pub struct Permutation1_7 { _phantom: std::marker::PhantomData, @@ -21,7 +21,10 @@ where pub fn new(wcm: Arc>) -> Arc { let permutation1_7 = Arc::new(Self { _phantom: std::marker::PhantomData }); - wcm.register_component(permutation1_7.clone(), Some(PERMUTATION_AIRGROUP_ID), Some(PERMUTATION_1_7_AIR_IDS)); + let airgroup_id = Permutation1_7Trace::::get_airgroup_id(); + let air_id = Permutation1_7Trace::::get_air_id(); + + wcm.register_component(permutation1_7.clone(), airgroup_id, air_id); permutation1_7 } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs index 7336d08a..449daac8 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs @@ -6,7 +6,7 @@ use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; -use crate::{Permutation1_8Trace, PERMUTATION_1_8_AIR_IDS, PERMUTATION_AIRGROUP_ID}; +use crate::Permutation1_8Trace; pub struct Permutation1_8 { _phantom: std::marker::PhantomData, @@ -21,7 +21,10 @@ where pub fn new(wcm: Arc>) -> Arc { let permutation1_8 = Arc::new(Self { _phantom: std::marker::PhantomData }); - wcm.register_component(permutation1_8.clone(), Some(PERMUTATION_AIRGROUP_ID), Some(PERMUTATION_1_8_AIR_IDS)); + let airgroup_id = Permutation1_8Trace::::get_airgroup_id(); + let air_id = Permutation1_8Trace::::get_air_id(); + + wcm.register_component(permutation1_8.clone(), airgroup_id, air_id); permutation1_8 } diff --git a/pil2-components/test/std/permutation/rs/src/permutation2.rs b/pil2-components/test/std/permutation/rs/src/permutation2.rs index 56080c06..7572121e 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation2.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation2.rs @@ -5,7 +5,7 @@ use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; -use crate::{Permutation2_6Trace, PERMUTATION_2_6_AIR_IDS, PERMUTATION_AIRGROUP_ID}; +use crate::Permutation2_6Trace; pub struct Permutation2 { _phantom: std::marker::PhantomData, @@ -16,8 +16,11 @@ impl Permutation2 { pub fn new(wcm: Arc>) -> Arc { let permutation2 = Arc::new(Self { _phantom: std::marker::PhantomData }); + + let airgroup_id = Permutation2_6Trace::::get_airgroup_id(); + let air_id = Permutation2_6Trace::::get_air_id(); - wcm.register_component(permutation2.clone(), Some(PERMUTATION_AIRGROUP_ID), Some(PERMUTATION_2_6_AIR_IDS)); + wcm.register_component(permutation2.clone(), airgroup_id, air_id); permutation2 } diff --git a/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs b/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs index f4d74870..c496b1ab 100644 --- a/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs @@ -20,7 +20,6 @@ pub const PERMUTATION_1_8_AIR_IDS: &[usize] = &[2]; pub const PERMUTATION_2_6_AIR_IDS: &[usize] = &[3]; - trace!(Permutation1_6Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, sel3: F, }, 0, 0, 64, 0 ); diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs index 25b04fdd..e3dac4dd 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs @@ -8,7 +8,7 @@ use num_bigint::BigInt; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; -use crate::{MultiRangeCheck1Trace, MULTI_RANGE_CHECK_1_AIRGROUP_ID, MULTI_RANGE_CHECK_1_AIR_IDS}; +use crate::MultiRangeCheck1Trace; pub struct MultiRangeCheck1 { std_lib: Arc>, @@ -23,11 +23,10 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let multi_range_check1 = Arc::new(Self { std_lib }); - wcm.register_component( - multi_range_check1.clone(), - Some(MULTI_RANGE_CHECK_1_AIRGROUP_ID), - Some(MULTI_RANGE_CHECK_1_AIR_IDS), - ); + let airgroup_id = MultiRangeCheck1Trace::::get_airgroup_id(); + let air_id = MultiRangeCheck1Trace::::get_air_id(); + + wcm.register_component(multi_range_check1.clone(), airgroup_id, air_id); // Register dependency relations multi_range_check1.std_lib.register_predecessor(); diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs index 2753b780..258a5778 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs @@ -8,7 +8,7 @@ use num_bigint::BigInt; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; -use crate::{MultiRangeCheck2Trace, MULTI_RANGE_CHECK_2_AIRGROUP_ID, MULTI_RANGE_CHECK_2_AIR_IDS}; +use crate::MultiRangeCheck2Trace; pub struct MultiRangeCheck2 { std_lib: Arc>, @@ -23,11 +23,10 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let multi_range_check2 = Arc::new(Self { std_lib }); - wcm.register_component( - multi_range_check2.clone(), - Some(MULTI_RANGE_CHECK_2_AIRGROUP_ID), - Some(MULTI_RANGE_CHECK_2_AIR_IDS), - ); + let airgroup_id = MultiRangeCheck2Trace::::get_airgroup_id(); + let air_id = MultiRangeCheck2Trace::::get_air_id(); + + wcm.register_component(multi_range_check2.clone(), airgroup_id, air_id); // Register dependency relations multi_range_check2.std_lib.register_predecessor(); diff --git a/pil2-components/test/std/range_check/rs/src/pil_helpers/traces.rs b/pil2-components/test/std/range_check/rs/src/pil_helpers/traces.rs index bf630af7..4bf075f7 100644 --- a/pil2-components/test/std/range_check/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/std/range_check/rs/src/pil_helpers/traces.rs @@ -56,7 +56,6 @@ pub const U_8_AIR_AIR_IDS: &[usize] = &[0]; pub const SPECIFIED_RANGES_AIR_IDS: &[usize] = &[0]; - trace!(RangeCheck3Trace { c1: F, c2: F, }, 0, 0, 32, 0 ); diff --git a/pil2-components/test/std/range_check/rs/src/range_check1.rs b/pil2-components/test/std/range_check/rs/src/range_check1.rs index 9685aa40..47e46855 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check1.rs @@ -8,7 +8,7 @@ use num_bigint::BigInt; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; -use crate::{RangeCheck1Trace, RANGE_CHECK_1_AIRGROUP_ID, RANGE_CHECK_1_AIR_IDS}; +use crate::RangeCheck1Trace; pub struct RangeCheck1 { std_lib: Arc>, @@ -23,7 +23,10 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let range_check1 = Arc::new(Self { std_lib }); - wcm.register_component(range_check1.clone(), Some(RANGE_CHECK_1_AIRGROUP_ID), Some(RANGE_CHECK_1_AIR_IDS)); + let airgroup_id = RangeCheck1Trace::::get_airgroup_id(); + let air_id = RangeCheck1Trace::::get_air_id(); + + wcm.register_component(range_check1.clone(), airgroup_id, air_id); // Register dependency relations range_check1.std_lib.register_predecessor(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check2.rs b/pil2-components/test/std/range_check/rs/src/range_check2.rs index 3075779f..f8204bb0 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check2.rs @@ -8,7 +8,7 @@ use num_bigint::BigInt; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; -use crate::{RangeCheck2Trace, RANGE_CHECK_2_AIRGROUP_ID, RANGE_CHECK_2_AIR_IDS}; +use crate::RangeCheck2Trace; pub struct RangeCheck2 { std_lib: Arc>, @@ -21,14 +21,17 @@ where const MY_NAME: &'static str = "RngChck2"; pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { - let range_check1 = Arc::new(Self { std_lib }); + let range_check2 = Arc::new(Self { std_lib }); - wcm.register_component(range_check1.clone(), Some(RANGE_CHECK_2_AIRGROUP_ID), Some(RANGE_CHECK_2_AIR_IDS)); + let airgroup_id = RangeCheck2Trace::::get_airgroup_id(); + let air_id = RangeCheck2Trace::::get_air_id(); + + wcm.register_component(range_check2.clone(), airgroup_id, air_id); // Register dependency relations - range_check1.std_lib.register_predecessor(); + range_check2.std_lib.register_predecessor(); - range_check1 + range_check2 } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { diff --git a/pil2-components/test/std/range_check/rs/src/range_check3.rs b/pil2-components/test/std/range_check/rs/src/range_check3.rs index c42bbec6..8d728565 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check3.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check3.rs @@ -8,7 +8,7 @@ use num_bigint::BigInt; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; -use crate::{RangeCheck3Trace, RANGE_CHECK_3_AIRGROUP_ID, RANGE_CHECK_3_AIR_IDS}; +use crate::RangeCheck3Trace; pub struct RangeCheck3 { std_lib: Arc>, @@ -21,14 +21,17 @@ where const MY_NAME: &'static str = "RngChck3"; pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { - let range_check1 = Arc::new(Self { std_lib }); + let range_check3 = Arc::new(Self { std_lib }); - wcm.register_component(range_check1.clone(), Some(RANGE_CHECK_3_AIRGROUP_ID), Some(RANGE_CHECK_3_AIR_IDS)); + let airgroup_id = RangeCheck3Trace::::get_airgroup_id(); + let air_id = RangeCheck3Trace::::get_air_id(); + + wcm.register_component(range_check3.clone(), airgroup_id, air_id); // Register dependency relations - range_check1.std_lib.register_predecessor(); + range_check3.std_lib.register_predecessor(); - range_check1 + range_check3 } pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { diff --git a/pil2-components/test/std/range_check/rs/src/range_check4.rs b/pil2-components/test/std/range_check/rs/src/range_check4.rs index e43d82fe..7ba608d4 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check4.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check4.rs @@ -9,7 +9,7 @@ use num_traits::ToPrimitive; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; -use crate::{RangeCheck4Trace, RANGE_CHECK_4_AIRGROUP_ID, RANGE_CHECK_4_AIR_IDS}; +use crate::RangeCheck4Trace; pub struct RangeCheck4 { std_lib: Arc>, @@ -24,7 +24,10 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let range_check4 = Arc::new(Self { std_lib }); - wcm.register_component(range_check4.clone(), Some(RANGE_CHECK_4_AIRGROUP_ID), Some(RANGE_CHECK_4_AIR_IDS)); + let airgroup_id = RangeCheck4Trace::::get_airgroup_id(); + let air_id = RangeCheck4Trace::::get_air_id(); + + wcm.register_component(range_check4.clone(), airgroup_id, air_id); // Register dependency relations range_check4.std_lib.register_predecessor(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs index 5a159922..929a12f2 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs @@ -8,7 +8,7 @@ use num_bigint::BigInt; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; -use crate::{RangeCheckDynamic1Trace, RANGE_CHECK_DYNAMIC_1_AIRGROUP_ID, RANGE_CHECK_DYNAMIC_1_AIR_IDS}; +use crate::RangeCheckDynamic1Trace; pub struct RangeCheckDynamic1 { std_lib: Arc>, @@ -23,11 +23,10 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let range_check_dynamic1 = Arc::new(Self { std_lib }); - wcm.register_component( - range_check_dynamic1.clone(), - Some(RANGE_CHECK_DYNAMIC_1_AIRGROUP_ID), - Some(RANGE_CHECK_DYNAMIC_1_AIR_IDS), - ); + let airgroup_id = RangeCheckDynamic1Trace::::get_airgroup_id(); + let air_id = RangeCheckDynamic1Trace::::get_air_id(); + + wcm.register_component(range_check_dynamic1.clone(), airgroup_id, air_id); // Register dependency relations range_check_dynamic1.std_lib.register_predecessor(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs index 5133dbf2..8e90c3c5 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs @@ -9,7 +9,7 @@ use num_traits::ToPrimitive; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; -use crate::{RangeCheckDynamic2Trace, RANGE_CHECK_DYNAMIC_2_AIRGROUP_ID, RANGE_CHECK_DYNAMIC_2_AIR_IDS}; +use crate::RangeCheckDynamic2Trace; pub struct RangeCheckDynamic2 { std_lib: Arc>, @@ -24,11 +24,10 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let range_check_dynamic2 = Arc::new(Self { std_lib }); - wcm.register_component( - range_check_dynamic2.clone(), - Some(RANGE_CHECK_DYNAMIC_2_AIRGROUP_ID), - Some(RANGE_CHECK_DYNAMIC_2_AIR_IDS), - ); + let airgroup_id = RangeCheckDynamic2Trace::::get_airgroup_id(); + let air_id = RangeCheckDynamic2Trace::::get_air_id(); + + wcm.register_component(range_check_dynamic2.clone(), airgroup_id, air_id); // Register dependency relations range_check_dynamic2.std_lib.register_predecessor(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs index cf8d82a9..a80f30ca 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs @@ -9,7 +9,7 @@ use num_traits::ToPrimitive; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; -use crate::{RangeCheckMixTrace, RANGE_CHECK_MIX_AIRGROUP_ID, RANGE_CHECK_MIX_AIR_IDS}; +use crate::RangeCheckMixTrace; pub struct RangeCheckMix { std_lib: Arc>, @@ -24,11 +24,10 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let range_check_mix = Arc::new(Self { std_lib }); - wcm.register_component( - range_check_mix.clone(), - Some(RANGE_CHECK_MIX_AIRGROUP_ID), - Some(RANGE_CHECK_MIX_AIR_IDS), - ); + let airgroup_id = RangeCheckMixTrace::::get_airgroup_id(); + let air_id = RangeCheckMixTrace::::get_air_id(); + + wcm.register_component(range_check_mix.clone(), airgroup_id, air_id); // Register dependency relations range_check_mix.std_lib.register_predecessor(); diff --git a/proofman/src/global_constraints.rs b/proofman/src/global_constraints.rs index 4b6c3053..9abbee71 100644 --- a/proofman/src/global_constraints.rs +++ b/proofman/src/global_constraints.rs @@ -64,15 +64,6 @@ pub fn verify_global_constraints_proof( log::info!("{}: --> Checking global constraints", MY_NAME); - let public_inputs_guard = pctx.public_inputs.inputs.read().unwrap(); - let public_inputs = (*public_inputs_guard).as_ptr() as *mut c_void; - - let challenges_guard = pctx.challenges.challenges.read().unwrap(); - let challenges = (*challenges_guard).as_ptr() as *mut c_void; - - let proof_values_guard = pctx.proof_values.values.read().unwrap(); - let proof_values = (*proof_values_guard).as_ptr() as *mut c_void; - let mut airgroupvalues = aggregate_airgroupvals(pctx.clone()); let mut airgroup_values_ptrs: Vec<*mut F> = airgroupvalues @@ -82,9 +73,9 @@ pub fn verify_global_constraints_proof( let raw_ptr = verify_global_constraints_c( sctx.get_global_bin(), - public_inputs, - challenges, - proof_values, + pctx.get_publics_ptr() as *mut c_void, + pctx.get_challenges_ptr() as *mut c_void, + pctx.get_proof_values_ptr() as *mut c_void, airgroup_values_ptrs.as_mut_ptr() as *mut *mut c_void, ); @@ -102,25 +93,17 @@ pub fn get_hint_field_gc( hint_field_name: &str, print_expression: bool, ) -> HintFieldValue { - let public_inputs_ptr = pctx.public_inputs.inputs.read().unwrap().as_ptr() as *mut c_void; - let mut airgroupvalues = aggregate_airgroupvals(pctx.clone()); let mut airgroup_values_ptrs: Vec<*mut F> = airgroupvalues .iter_mut() // Iterate mutably over the inner Vecs .map(|inner_vec| inner_vec.as_mut_ptr()) // Get a raw pointer to each inner Vec .collect(); - let challenges_guard = pctx.challenges.challenges.read().unwrap(); - let challenges = (*challenges_guard).as_ptr() as *mut c_void; - - let proof_values_guard = pctx.proof_values.values.read().unwrap(); - let proof_values = (*proof_values_guard).as_ptr() as *mut c_void; - let raw_ptr = get_hint_field_global_constraints_c( sctx.get_global_bin(), - public_inputs_ptr, - challenges, - proof_values, + pctx.get_publics_ptr() as *mut c_void, + pctx.get_challenges_ptr() as *mut c_void, + pctx.get_proof_values_ptr() as *mut c_void, airgroup_values_ptrs.as_mut_ptr() as *mut *mut c_void, hint_id, hint_field_name, @@ -144,25 +127,17 @@ pub fn get_hint_field_gc_a( hint_field_name: &str, print_expression: bool, ) -> HintFieldValuesVec { - let public_inputs_ptr = pctx.public_inputs.inputs.read().unwrap().as_ptr() as *mut c_void; - let mut airgroupvalues = aggregate_airgroupvals(pctx.clone()); let mut airgroup_values_ptrs: Vec<*mut F> = airgroupvalues .iter_mut() // Iterate mutably over the inner Vecs .map(|inner_vec| inner_vec.as_mut_ptr()) // Get a raw pointer to each inner Vec .collect(); - let challenges_guard = pctx.challenges.challenges.read().unwrap(); - let challenges = (*challenges_guard).as_ptr() as *mut c_void; - - let proof_values_guard = pctx.proof_values.values.read().unwrap(); - let proof_values = (*proof_values_guard).as_ptr() as *mut c_void; - let raw_ptr = get_hint_field_global_constraints_c( sctx.get_global_bin(), - public_inputs_ptr, - challenges, - proof_values, + pctx.get_publics_ptr() as *mut c_void, + pctx.get_challenges_ptr() as *mut c_void, + pctx.get_proof_values_ptr() as *mut c_void, airgroup_values_ptrs.as_mut_ptr() as *mut *mut c_void, hint_id, hint_field_name, @@ -192,25 +167,17 @@ pub fn get_hint_field_gc_m( hint_field_name: &str, print_expression: bool, ) -> HintFieldValues { - let public_inputs_ptr = pctx.public_inputs.inputs.read().unwrap().as_ptr() as *mut c_void; - let mut airgroupvalues = aggregate_airgroupvals(pctx.clone()); let mut airgroup_values_ptrs: Vec<*mut F> = airgroupvalues .iter_mut() // Iterate mutably over the inner Vecs .map(|inner_vec| inner_vec.as_mut_ptr()) // Get a raw pointer to each inner Vec .collect(); - let challenges_guard = pctx.challenges.challenges.read().unwrap(); - let challenges = (*challenges_guard).as_ptr() as *mut c_void; - - let proof_values_guard = pctx.proof_values.values.read().unwrap(); - let proof_values = (*proof_values_guard).as_ptr() as *mut c_void; - let raw_ptr = get_hint_field_global_constraints_c( sctx.get_global_bin(), - public_inputs_ptr, - challenges, - proof_values, + pctx.get_publics_ptr() as *mut c_void, + pctx.get_challenges_ptr() as *mut c_void, + pctx.get_proof_values_ptr() as *mut c_void, airgroup_values_ptrs.as_mut_ptr() as *mut *mut c_void, hint_id, hint_field_name, @@ -245,9 +212,6 @@ pub fn set_hint_field( hint_field_name: &str, value: HintFieldOutput, ) { - let proof_values_guard = pctx.proof_values.values.read().unwrap(); - let proof_values = (*proof_values_guard).as_ptr() as *mut c_void; - let mut value_array: Vec = Vec::new(); match value { @@ -263,8 +227,11 @@ pub fn set_hint_field( let values_ptr = value_array.as_ptr() as *mut c_void; - let id = - set_hint_field_global_constraints_c(sctx.get_global_bin(), proof_values, values_ptr, hint_id, hint_field_name); - - pctx.set_proof_value_calculated(id as usize); + set_hint_field_global_constraints_c( + sctx.get_global_bin(), + pctx.get_proof_values_ptr() as *mut c_void, + values_ptr, + hint_id, + hint_field_name, + ); } diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index cf8f0a8a..efa18dfe 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -104,7 +104,6 @@ impl ProofMan { let mut transcript: FFITranscript = provers[0].new_transcript(); - Self::check_stage(0, &mut provers, pctx.clone()); for prover in provers.iter_mut() { prover.commit_stage(0, pctx.clone()); } @@ -121,27 +120,11 @@ impl ProofMan { } Self::calculate_stage(stage, &mut provers, sctx.clone(), pctx.clone()); - Self::check_stage(stage, &mut provers, pctx.clone()); if !options.verify_constraints { Self::commit_stage(stage, &mut provers, pctx.clone()); } - let publics_set = pctx.public_inputs.inputs_set.read().unwrap(); - for i in 0..pctx.global_info.n_publics { - let public = pctx.global_info.publics_map.as_ref().expect("REASON").get(i).unwrap(); - if !publics_set[i] { - if !public.lengths.is_empty() { - panic!( - "Not all publics are set: Public {}[{}] is not calculated", - public.name, public.lengths[0] - ); - } else { - panic!("Not all publics are set: Public {} is not calculated", public.name); - } - } - } - if !options.verify_constraints || stage < num_commit_stages { Self::calculate_challenges( stage, @@ -156,15 +139,6 @@ impl ProofMan { witness_lib.end_proof(); - for i in 0..pctx.global_info.n_proof_values { - if !pctx.proof_values.values_set.read().unwrap()[i] { - panic!( - "Proof cannot be generated: Proof value {} is not set", - pctx.global_info.proof_values_map.as_ref().expect("REASON").get(i).unwrap().name - ); - } - } - if options.verify_constraints { return verify_constraints_proof(pctx.clone(), ectx.clone(), sctx.clone(), provers, witness_lib); } @@ -331,7 +305,7 @@ impl ProofMan { let buff_helper: Vec = create_buffer_fast(buff_helper_size); - *pctx.buff_helper.buff_helper.write().unwrap() = buff_helper; + *pctx.buff_helper.values.write().unwrap() = buff_helper; timer_stop_and_log_debug!(INITIALIZE_PROVERS); } @@ -450,13 +424,6 @@ impl ProofMan { } } - pub fn check_stage(stage: u32, provers: &mut [Box>], proof_ctx: Arc>) { - log::debug!("{}: Checking stage can be calculated", Self::MY_NAME); - for prover in provers.iter_mut() { - prover.check_stage(stage, proof_ctx.clone()); - } - } - pub fn commit_stage(stage: u32, provers: &mut [Box>], proof_ctx: Arc>) { if stage as usize == proof_ctx.global_info.n_challenges.len() + 1 { info!("{}: Committing stage Q", Self::MY_NAME); @@ -515,10 +482,7 @@ impl ProofMan { verify_constraints: bool, ) { if stage == 1 { - let public_inputs_guard = pctx.public_inputs.inputs.read().unwrap(); - let public_inputs = (*public_inputs_guard).as_ptr() as *mut c_void; - - transcript.add_elements(public_inputs, pctx.global_info.n_publics); + transcript.add_elements(pctx.get_publics_ptr() as *mut c_void, pctx.global_info.n_publics); } let dctx = ectx.dctx.read().unwrap(); @@ -662,25 +626,18 @@ impl ProofMan { proves.push(prover.get_zkin_proof(proof_ctx.clone(), output_dir)); prover.free(); } - let public_inputs_guard = proof_ctx.public_inputs.inputs.read().unwrap(); - let challenges_guard = proof_ctx.challenges.challenges.read().unwrap(); - let proof_values_guard = proof_ctx.proof_values.values.read().unwrap(); let n_publics = proof_ctx.global_info.n_publics as u64; - let public_inputs = (*public_inputs_guard).as_ptr() as *mut c_void; - let challenges = (*challenges_guard).as_ptr() as *mut c_void; - let n_proof_values = proof_ctx.global_info.n_proof_values as u64; - let proof_values = (*proof_values_guard).as_ptr() as *mut c_void; let global_info_path = proof_ctx.global_info.get_proving_key_path().join("pilout.globalInfo.json"); let global_info_file: &str = global_info_path.to_str().unwrap(); - save_publics_c(n_publics, public_inputs, output_dir); + save_publics_c(n_publics, proof_ctx.get_publics_ptr() as *mut c_void, output_dir); - save_proof_values_c(n_proof_values, proof_values, output_dir); + save_proof_values_c(n_proof_values, proof_ctx.get_proof_values_ptr() as *mut c_void, output_dir); - save_challenges_c(challenges, global_info_file, output_dir); + save_challenges_c(proof_ctx.get_challenges_ptr() as *mut c_void, global_info_file, output_dir); timer_stop_and_log_debug!(FINALIZING_PROOF); proves diff --git a/proofman/src/recursion.rs b/proofman/src/recursion.rs index a823109e..0bf65f60 100644 --- a/proofman/src/recursion.rs +++ b/proofman/src/recursion.rs @@ -76,14 +76,11 @@ pub fn generate_vadcop_recursive1_proof( false => String::from(""), }; - let const_pols_ptr = (*setup.const_pols.values.read().unwrap()).as_ptr() as *mut c_void; - let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; - zkin = gen_recursive_proof_c( p_setup, p_address, - const_pols_ptr, - const_tree_ptr, + setup.get_const_ptr() as *mut c_void, + setup.get_const_tree_ptr() as *mut c_void, p_publics, &proof_file, global_info_file, @@ -139,14 +136,11 @@ pub fn generate_vadcop_recursive1_proof( false => String::from(""), }; - let const_pols_ptr = (*setup.const_pols.values.read().unwrap()).as_ptr() as *mut c_void; - let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; - let p_prove = gen_recursive_proof_c( p_setup, p_address, - const_pols_ptr, - const_tree_ptr, + setup.get_const_ptr() as *mut c_void, + setup.get_const_tree_ptr() as *mut c_void, p_publics, &proof_file, global_info_file, @@ -232,16 +226,10 @@ pub fn generate_vadcop_recursive2_proof( let p_setup: *mut c_void = (&setup.p_setup).into(); let p_stark_info: *mut c_void = setup.p_setup.p_stark_info; - let public_inputs_guard = pctx.public_inputs.inputs.read().unwrap(); - let challenges_guard = pctx.challenges.challenges.read().unwrap(); - - let public_inputs = (*public_inputs_guard).as_ptr() as *mut c_void; - let challenges = (*challenges_guard).as_ptr() as *mut c_void; - let zkin_recursive2 = join_zkin_recursive2_c( airgroup as u64, - public_inputs, - challenges, + pctx.get_publics_ptr() as *mut c_void, + pctx.get_challenges_ptr() as *mut c_void, global_info_file, airgroup_proofs[airgroup][j].unwrap(), airgroup_proofs[airgroup][j + 1].unwrap(), @@ -284,14 +272,12 @@ pub fn generate_vadcop_recursive2_proof( MY_NAME, format!("··· Generating recursive2 proof for instances of {}", air_instance_name) ); - let const_pols_ptr = (*setup.const_pols.values.read().unwrap()).as_ptr() as *mut c_void; - let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; let zkin = gen_recursive_proof_c( p_setup, p_address, - const_pols_ptr, - const_tree_ptr, + setup.get_const_ptr() as *mut c_void, + setup.get_const_tree_ptr() as *mut c_void, p_publics, &proof_file, global_info_file, @@ -327,13 +313,6 @@ pub fn generate_vadcop_recursive2_proof( for proofs in airgroup_proofs { proofs_recursive2.push(proofs[0].unwrap()); } - let public_inputs_guard = pctx.public_inputs.inputs.read().unwrap(); - let challenges_guard = pctx.challenges.challenges.read().unwrap(); - let proof_values_guard = pctx.proof_values.values.read().unwrap(); - - let public_inputs = (*public_inputs_guard).as_ptr() as *mut c_void; - let challenges = (*challenges_guard).as_ptr() as *mut c_void; - let proof_values = (*proof_values_guard).as_ptr() as *mut c_void; let mut stark_infos_recursive2 = Vec::new(); for (idx, _) in pctx.global_info.air_groups.iter().enumerate() { @@ -345,9 +324,9 @@ pub fn generate_vadcop_recursive2_proof( let stark_infos_recursive2_ptr = stark_infos_recursive2.as_mut_ptr(); zkin_final = join_zkin_final_c( - public_inputs, - proof_values, - challenges, + pctx.get_publics_ptr() as *mut c_void, + pctx.get_proof_values_ptr() as *mut c_void, + pctx.get_challenges_ptr() as *mut c_void, global_info_file, proofs_recursive2_ptr, stark_infos_recursive2_ptr, @@ -379,13 +358,11 @@ pub fn generate_vadcop_final_proof( log::info!("{}: ··· Generating vadcop final proof", MY_NAME); timer_start_trace!(GENERATE_VADCOP_FINAL_PROOF); // prove - let const_pols_ptr = (*setup.const_pols.values.read().unwrap()).as_ptr() as *mut c_void; - let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; let p_prove = gen_recursive_proof_c( p_setup, p_address, - const_pols_ptr, - const_tree_ptr, + setup.get_const_ptr() as *mut c_void, + setup.get_const_tree_ptr() as *mut c_void, p_publics, output_dir_path.join("proofs/vadcop_final_proof.json").to_string_lossy().as_ref(), global_info_file, @@ -421,13 +398,11 @@ pub fn generate_recursivef_proof( log::info!("{}: ··· Generating recursiveF proof", MY_NAME); timer_start_trace!(GENERATE_RECURSIVEF_PROOF); // prove - let const_pols_ptr = (*setup.const_pols.values.read().unwrap()).as_ptr() as *mut c_void; - let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; let p_prove = gen_recursive_proof_c( p_setup, p_address, - const_pols_ptr, - const_tree_ptr, + setup.get_const_ptr() as *mut c_void, + setup.get_const_tree_ptr() as *mut c_void, p_publics, output_dir_path.join("proofs/recursivef.json").to_string_lossy().as_ref(), global_info_file, diff --git a/proofman/src/witness_manager.rs b/proofman/src/witness_manager.rs index f28ccf81..30d33639 100644 --- a/proofman/src/witness_manager.rs +++ b/proofman/src/witness_manager.rs @@ -26,19 +26,16 @@ impl WitnessManager { WitnessManager { components: RwLock::new(Vec::new()), airs: RwLock::new(HashMap::new()), pctx, ectx, sctx } } - pub fn register_component( - &self, - component: Arc>, - airgroup_id: Option, - air_ids: Option<&[AirId]>, - ) { + pub fn register_component(&self, component: Arc>, airgroup_id: AirGroupId, air_id: AirId) { self.components.write().unwrap().push(component); let idx = self.components.write().unwrap().len() - 1; - if let Some(air_ids) = air_ids { - self.register_airs(airgroup_id.unwrap(), air_ids, idx); - } + self.register_air(airgroup_id, air_id, idx); + } + + pub fn register_std(&self, component: Arc>) { + self.components.write().unwrap().push(component); } pub fn register_airs(&self, airgroup_id: AirGroupId, air_ids: &[AirId], component_idx: usize) { diff --git a/provers/stark/src/stark_prover.rs b/provers/stark/src/stark_prover.rs index 8ed3e8ba..8f464613 100644 --- a/provers/stark/src/stark_prover.rs +++ b/provers/stark/src/stark_prover.rs @@ -98,12 +98,7 @@ impl Prover for StarkProver { //initialize the common challenges if have not been initialized by another prover let challenges = vec![F::zero(); self.stark_info.challenges_map.as_ref().unwrap().len() * Self::FIELD_EXTENSION]; - *proof_ctx.challenges.challenges.write().unwrap() = challenges; - - let number_stage1_commits = *self.stark_info.map_sections_n.get("cm1").unwrap() as usize; - for i in 0..number_stage1_commits { - air_instance.set_commit_calculated(i); - } + *proof_ctx.challenges.values.write().unwrap() = challenges; self.initialized = true; } @@ -130,21 +125,16 @@ impl Prover for StarkProver { let setup = setup_ctx.get_setup(self.airgroup_id, self.air_id); - let public_inputs_guard = proof_ctx.public_inputs.inputs.read().unwrap(); - let challenges_guard = proof_ctx.challenges.challenges.read().unwrap(); - - let const_pols_ptr = (*setup.const_pols.values.read().unwrap()).as_ptr() as *mut c_void; - let steps_params = StepsParams { witness: air_instance.get_witness_ptr() as *mut c_void, trace: air_instance.get_trace_ptr() as *mut c_void, - public_inputs: (*public_inputs_guard).as_ptr() as *mut c_void, - challenges: (*challenges_guard).as_ptr() as *mut c_void, + public_inputs: proof_ctx.get_publics_ptr() as *mut c_void, + challenges: proof_ctx.get_challenges_ptr() as *mut c_void, airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, airvalues: air_instance.get_airvalues_ptr() as *mut c_void, evals: air_instance.get_evals_ptr() as *mut c_void, xdivxsub: std::ptr::null_mut(), - p_const_pols: const_pols_ptr, + p_const_pols: setup.get_const_ptr() as *mut c_void, p_const_tree: std::ptr::null_mut(), custom_commits: air_instance.get_custom_commits_ptr(), custom_commits_extended: [std::ptr::null_mut(); 10], @@ -162,27 +152,19 @@ impl Prover for StarkProver { fn calculate_stage(&mut self, stage_id: u32, setup_ctx: Arc, proof_ctx: Arc>) { let air_instance = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap()[self.prover_idx]; - let n_commits = self.stark_info.cm_pols_map.as_ref().expect("REASON").len(); - let setup = setup_ctx.get_setup(self.airgroup_id, self.air_id); - let public_inputs_guard = proof_ctx.public_inputs.inputs.read().unwrap(); - let challenges_guard = proof_ctx.challenges.challenges.read().unwrap(); - - let const_pols_ptr = (*setup.const_pols.values.read().unwrap()).as_ptr() as *mut c_void; - let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; - let steps_params = StepsParams { witness: air_instance.get_witness_ptr() as *mut c_void, trace: air_instance.get_trace_ptr() as *mut c_void, - public_inputs: (*public_inputs_guard).as_ptr() as *mut c_void, - challenges: (*challenges_guard).as_ptr() as *mut c_void, + public_inputs: proof_ctx.get_publics_ptr() as *mut c_void, + challenges: proof_ctx.get_challenges_ptr() as *mut c_void, airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, airvalues: air_instance.get_airvalues_ptr() as *mut c_void, evals: air_instance.get_evals_ptr() as *mut c_void, xdivxsub: std::ptr::null_mut(), - p_const_pols: const_pols_ptr, - p_const_tree: const_tree_ptr, + p_const_pols: setup.get_const_ptr() as *mut c_void, + p_const_tree: setup.get_const_tree_ptr() as *mut c_void, custom_commits: air_instance.get_custom_commits_ptr(), custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; @@ -203,22 +185,8 @@ impl Prover for StarkProver { self.instance_id, air_name ); - for i in 0..n_commits { - let cm_pol = self.stark_info.cm_pols_map.as_ref().expect("REASON").get(i).unwrap(); - if (cm_pol.stage < stage_id as u64 || cm_pol.stage == stage_id as u64 && !cm_pol.im_pol) - && !air_instance.is_commit_initialized(i) - { - panic!("Intermediate polynomials for stage {} cannot be calculated: Witness column {} is not calculated", stage_id, cm_pol.name); - } - } calculate_impols_expressions_c(self.p_stark, stage_id as u64, (&steps_params).into()); - for i in 0..n_commits { - let cm_pol = self.stark_info.cm_pols_map.as_ref().expect("REASON").get(i).unwrap(); - if cm_pol.stage == stage_id as u64 && cm_pol.im_pol { - air_instance.set_commit_calculated(i); - } - } } if stage_id as usize == proof_ctx.global_info.n_challenges.len() { @@ -235,58 +203,6 @@ impl Prover for StarkProver { air_name ); calculate_quotient_polynomial_c(self.p_stark, (&steps_params).into()); - for i in 0..n_commits { - let cm_pol = self.stark_info.cm_pols_map.as_ref().expect("REASON").get(i).unwrap(); - if cm_pol.stage == (proof_ctx.global_info.n_challenges.len() + 1) as u64 { - air_instance.set_commit_calculated(i); - } - } - } - } - - fn check_stage(&self, stage_id: u32, proof_ctx: Arc>) { - let air_instance = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap()[self.prover_idx]; - - let n_commits = self.stark_info.cm_pols_map.as_ref().expect("REASON").len(); - for i in 0..n_commits { - let cm_pol = self.stark_info.cm_pols_map.as_ref().expect("REASON").get(i).unwrap(); - if cm_pol.stage == stage_id as u64 && !air_instance.is_commit_initialized(i) { - panic!("Stage {} cannot be committed: Witness column {} is not calculated", stage_id, cm_pol.name); - } - } - - let n_airgroupvalues = self.stark_info.airgroupvalues_map.as_ref().expect("REASON").len(); - for i in 0..n_airgroupvalues { - let airgroup_value = self.stark_info.airgroupvalues_map.as_ref().expect("REASON").get(i).unwrap(); - if airgroup_value.stage == stage_id as u64 && !air_instance.is_airgroup_value_initialized(i) { - panic!( - "Stage {} cannot be committed: Airgroupvalue {} is not calculated", - stage_id, airgroup_value.name - ); - } - } - - let n_airvalues = self.stark_info.airvalues_map.as_ref().expect("REASON").len(); - for i in 0..n_airvalues { - let air_value = self.stark_info.airvalues_map.as_ref().expect("REASON").get(i).unwrap(); - - if air_value.stage == stage_id as u64 && !air_instance.is_airvalue_initialized(i) { - panic!("Stage {} cannot be committed: Airvalue {} is not calculated", stage_id, air_value.name); - } - } - - let n_custom_commits = self.stark_info.custom_commits_map.len(); - for i in 0..n_custom_commits { - let n_custom_commits = self.stark_info.custom_commits_map[i].as_ref().expect("REASON").len(); - for j in 0..n_custom_commits { - let custom_pol = self.stark_info.custom_commits_map[i].as_ref().expect("REASON").get(j).unwrap(); - if stage_id as u64 == custom_pol.stage && !air_instance.is_custom_commit_initialized(i, j) { - panic!( - "Stage {} cannot be committed: Custom commit of {} that is {} is not calculated", - stage_id, self.stark_info.custom_commits[i].name, custom_pol.name - ); - } - } } } @@ -296,9 +212,6 @@ impl Prover for StarkProver { let p_stark = self.p_stark; let p_proof = self.p_proof; - let buff_helper_guard = proof_ctx.buff_helper.buff_helper.read().unwrap(); - let buff_helper = (*buff_helper_guard).as_ptr() as *mut c_void; - let air_name = &proof_ctx.global_info.airs[self.airgroup_id][self.air_id].name; if stage_id >= 1 { debug!( @@ -319,7 +232,15 @@ impl Prover for StarkProver { let trace = air_instance.get_trace_ptr() as *mut c_void; let element_type = if type_name::() == type_name::() { 1 } else { 0 }; - commit_stage_c(p_stark, element_type, stage_id as u64, witness, trace, p_proof, buff_helper); + commit_stage_c( + p_stark, + element_type, + stage_id as u64, + witness, + trace, + p_proof, + proof_ctx.get_buff_helper_ptr() as *mut c_void, + ); timer_stop_and_log_trace!(STARK_COMMIT_STAGE_, stage_id); } else { @@ -340,7 +261,7 @@ impl Prover for StarkProver { air_instance.custom_commits[commit_id].buffer.as_ptr() as *mut c_void, air_instance.custom_commits_extended[commit_id].buffer.as_ptr() as *mut c_void, p_proof, - buff_helper, + proof_ctx.get_buff_helper_ptr() as *mut c_void, "", ); } else { @@ -356,7 +277,7 @@ impl Prover for StarkProver { } } - let mut value = vec![Goldilocks::zero(); self.n_field_elements]; + let mut value = vec![F::zero(); self.n_field_elements]; treesGL_get_root_c( p_stark, (self.stark_info.n_stages + 2 + commit_id as u32) as u64, @@ -369,8 +290,8 @@ impl Prover for StarkProver { ); for (idx, val) in value.iter().enumerate() { proof_ctx.set_public_value( - val.as_canonical_u64(), - self.stark_info.custom_commits[commit_id].public_values[idx].idx, + *val, + self.stark_info.custom_commits[commit_id].public_values[idx].idx as usize, ); } } @@ -420,10 +341,7 @@ impl Prover for StarkProver { } fn calculate_xdivxsub(&mut self, proof_ctx: Arc>) { - let challenges_guard = proof_ctx.challenges.challenges.read().unwrap(); - - let buff_helper_guard = proof_ctx.buff_helper.buff_helper.read().unwrap(); - let xdivxsub = (*buff_helper_guard).as_ptr() as *mut c_void; + let challenges_guard = proof_ctx.challenges.values.read().unwrap(); let challenges_map = self.stark_info.challenges_map.as_ref().unwrap(); @@ -436,14 +354,11 @@ impl Prover for StarkProver { } let xi_challenge = &(*challenges_guard)[xi_challenge_index * Self::FIELD_EXTENSION] as *const F as *mut c_void; - calculate_xdivxsub_c(self.p_stark, xi_challenge, xdivxsub); + calculate_xdivxsub_c(self.p_stark, xi_challenge, proof_ctx.get_buff_helper_ptr() as *mut c_void); } fn calculate_lev(&mut self, proof_ctx: Arc>) { - let challenges_guard = proof_ctx.challenges.challenges.read().unwrap(); - - let buff_helper_guard = proof_ctx.buff_helper.buff_helper.read().unwrap(); - let lev = (*buff_helper_guard).as_ptr() as *mut c_void; + let challenges_guard = proof_ctx.challenges.values.read().unwrap(); let challenges_map = self.stark_info.challenges_map.as_ref().unwrap(); @@ -456,7 +371,7 @@ impl Prover for StarkProver { } let xi_challenge = &(*challenges_guard)[xi_challenge_index * Self::FIELD_EXTENSION] as *const F as *mut c_void; - compute_lev_c(self.p_stark, xi_challenge, lev); + compute_lev_c(self.p_stark, xi_challenge, proof_ctx.get_buff_helper_ptr() as *mut c_void); } fn get_buff_helper_size(&self) -> usize { @@ -637,7 +552,7 @@ impl Prover for StarkProver { let challenges_map = self.stark_info.challenges_map.as_ref().unwrap(); - let challenges = &*proof_ctx.challenges.challenges.read().unwrap(); + let challenges = &*proof_ctx.challenges.values.read().unwrap(); for i in 0..challenges_map.len() { if challenges_map[i].stage == stage_id as u64 { let challenge = &challenges[i * Self::FIELD_EXTENSION]; @@ -653,7 +568,7 @@ impl Prover for StarkProver { } } else { //Fri folding + . queries: add one challenge for each step - let mut challenges_guard = proof_ctx.challenges.challenges.write().unwrap(); + let mut challenges_guard = proof_ctx.challenges.values.write().unwrap(); challenges_guard.extend(std::iter::repeat(F::zero()).take(3)); transcript.get_challenge(&(*challenges_guard)[challenges_guard.len() - 3] as *const F as *mut c_void); @@ -673,11 +588,6 @@ impl Prover for StarkProver { fn get_zkin_proof(&self, proof_ctx: Arc>, output_dir: &str) -> *mut c_void { let gidx = proof_ctx.air_instance_repo.air_instances.read().unwrap()[self.prover_idx].global_idx.unwrap(); - let public_inputs_guard = proof_ctx.public_inputs.inputs.read().unwrap(); - let public_inputs = (*public_inputs_guard).as_ptr() as *mut c_void; - - let challenges_guard = proof_ctx.challenges.challenges.read().unwrap(); - let challenges = (*challenges_guard).as_ptr() as *mut c_void; let global_info_path = proof_ctx.global_info.get_proving_key_path().join("pilout.globalInfo.json"); let global_info_file: &str = global_info_path.to_str().unwrap(); @@ -685,8 +595,8 @@ impl Prover for StarkProver { fri_proof_get_zkinproof_c( gidx as u64, self.p_proof, - public_inputs, - challenges, + proof_ctx.get_publics_ptr() as *mut c_void, + proof_ctx.get_challenges_ptr() as *mut c_void, self.p_stark_info, global_info_file, output_dir, @@ -738,9 +648,6 @@ impl StarkProver { let p_stark = self.p_stark; let p_proof = self.p_proof; - let buff_helper_guard = proof_ctx.buff_helper.buff_helper.read().unwrap(); - let buff_helper = (*buff_helper_guard).as_ptr() as *mut c_void; - let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; let steps_params = StepsParams { @@ -758,7 +665,7 @@ impl StarkProver { custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; - compute_evals_c(p_stark, (&steps_params).into(), buff_helper, p_proof); + compute_evals_c(p_stark, (&steps_params).into(), proof_ctx.get_buff_helper_ptr() as *mut c_void, p_proof); } fn compute_fri_pol(&mut self, _opening_id: u32, setup_ctx: Arc, proof_ctx: Arc>) { @@ -768,26 +675,19 @@ impl StarkProver { let setup = setup_ctx.get_setup(self.airgroup_id, self.air_id); - let public_inputs_guard = proof_ctx.public_inputs.inputs.read().unwrap(); - let challenges_guard = proof_ctx.challenges.challenges.read().unwrap(); - let buff_helper_guard = proof_ctx.buff_helper.buff_helper.read().unwrap(); - - let const_pols_ptr = (*setup.const_pols.values.read().unwrap()).as_ptr() as *mut c_void; - let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; - let p_stark = self.p_stark; let steps_params = StepsParams { witness: std::ptr::null_mut(), trace: air_instance.get_trace_ptr() as *mut c_void, - public_inputs: (*public_inputs_guard).as_ptr() as *mut c_void, - challenges: (*challenges_guard).as_ptr() as *mut c_void, + public_inputs: proof_ctx.get_publics_ptr() as *mut c_void, + challenges: proof_ctx.get_challenges_ptr() as *mut c_void, airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, airvalues: air_instance.get_airvalues_ptr() as *mut c_void, evals: air_instance.get_evals_ptr() as *mut c_void, - xdivxsub: (*buff_helper_guard).as_ptr() as *mut c_void, - p_const_pols: const_pols_ptr, - p_const_tree: const_tree_ptr, + xdivxsub: proof_ctx.get_buff_helper_ptr() as *mut c_void, + p_const_pols: setup.get_const_ptr() as *mut c_void, + p_const_tree: setup.get_const_tree_ptr() as *mut c_void, custom_commits: air_instance.get_custom_commits_ptr(), custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; @@ -818,7 +718,7 @@ impl StarkProver { let fri_pol = get_fri_pol_c(self.p_stark_info, buffer); - let challenges_guard = proof_ctx.challenges.challenges.read().unwrap(); + let challenges_guard = proof_ctx.challenges.values.read().unwrap(); let challenge: Vec = challenges_guard.iter().skip(challenges_guard.len() - 3).cloned().collect(); let current_bits = steps[step_index as usize].n_bits; @@ -850,7 +750,7 @@ impl StarkProver { let mut fri_queries = vec![u64::default(); n_queries as usize]; - let challenges_guard = proof_ctx.challenges.challenges.read().unwrap(); + let challenges_guard = proof_ctx.challenges.values.read().unwrap(); let challenge: Vec = challenges_guard.iter().skip(challenges_guard.len() - 3).cloned().collect(); From 5c46416f1ff0f90f482f5c48a3d9089447d337ea Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 9 Dec 2024 13:46:23 +0000 Subject: [PATCH 17/64] Minor fix --- common/src/trace.rs | 81 +++++++++++++-------------------------------- macros/src/lib.rs | 39 ++-------------------- 2 files changed, 26 insertions(+), 94 deletions(-) diff --git a/common/src/trace.rs b/common/src/trace.rs index ab9dd4cb..231d6473 100644 --- a/common/src/trace.rs +++ b/common/src/trace.rs @@ -1,13 +1,11 @@ -use p3_field::Field; - -pub trait Trace: Send { +pub trait Trace: Send { fn num_rows(&self) -> usize; fn airgroup_id(&self) -> usize; fn air_id(&self) -> usize; fn get_buffer(&mut self) -> Vec; } -pub trait Values: Send { +pub trait Values: Send { fn get_buffer(&mut self) -> Vec; } @@ -18,48 +16,15 @@ pub use proofman_macros::values; #[cfg(test)] use crate as common; -#[test] -#[should_panic] -fn test_errors_are_launched_when_num_rows_is_invalid_1() { - let mut buffer = vec![0u8; 3]; - trace!(SimpleRow, Simple { a: F }); - let _ = Simple::map_buffer(&mut buffer, 1, 0); -} - -#[test] -#[should_panic] -fn test_errors_are_launched_when_num_rows_is_invalid_2() { - let mut buffer = vec![0u8; 3]; - trace!(SimpleRow, Simple { a: F }); - let _ = Simple::map_buffer(&mut buffer, 3, 0); -} - -#[test] -#[should_panic] -fn test_errors_are_launched_when_num_rows_is_invalid_3() { - trace!(SimpleRow, Simple { a: F }); - let _ = Simple::::new(1); -} - -#[test] -#[should_panic] -fn test_errors_are_launched_when_num_rows_is_invalid_4() { - trace!(SimpleRow, Simple { a: F }); - let _ = Simple::::new(3); -} #[test] fn check() { - const OFFSET: usize = 1; - let num_rows = 8; - - trace!(TraceRow, MyTrace { a: F, b:F}); + trace!(TraceRow, MyTrace { a: F, b:F}, 8, 0, 0, 0); assert_eq!(TraceRow::::ROW_SIZE, 2); - let mut buffer = vec![0usize; num_rows * TraceRow::::ROW_SIZE + OFFSET]; - let trace = MyTrace::map_buffer(&mut buffer, num_rows, OFFSET); - let mut trace = trace.unwrap(); + let mut trace = MyTrace::new(); + let num_rows = trace.num_rows(); // Set values for i in 0..num_rows { @@ -75,15 +40,12 @@ fn check() { } #[test] -fn check_array() { - let num_rows = 8; - - trace!(TraceRow, MyTrace { a: F, b: [F; 3], c: F }); +fn check_array() { + trace!(TraceRow, MyTrace { a: F, b: [F; 3], c: F }, 8, 0, 0, 0); assert_eq!(TraceRow::::ROW_SIZE, 5); - let mut buffer = vec![0usize; num_rows * TraceRow::::ROW_SIZE]; - let trace = MyTrace::map_buffer(&mut buffer, num_rows, 0); - let mut trace = trace.unwrap(); + let mut trace = MyTrace::new(); + let num_rows = trace.num_rows(); // Set values for i in 0..num_rows { @@ -94,6 +56,8 @@ fn check_array() { trace[i].c = i * 40; } + let buffer = trace.get_buffer(); + // Check values for i in 0..num_rows { assert_eq!(buffer[i * TraceRow::::ROW_SIZE], i); @@ -106,14 +70,12 @@ fn check_array() { #[test] fn check_multi_array() { - let num_rows = 8; - - trace!(TraceRow, MyTrace { a: [[F;3]; 2], b: F }); + trace!(TraceRow, MyTrace { a: [[F;3]; 2], b: F }, 8, 0, 0, 0); assert_eq!(TraceRow::::ROW_SIZE, 7); - let mut buffer = vec![0usize; num_rows * TraceRow::::ROW_SIZE]; - let trace = MyTrace::map_buffer(&mut buffer, num_rows, 0); - let mut trace = trace.unwrap(); + + let mut trace = MyTrace::new(); + let num_rows = trace.num_rows(); // Set values for i in 0..num_rows { @@ -126,6 +88,8 @@ fn check_multi_array() { trace[i].b = i + 3; } + let buffer = trace.get_buffer(); + // Check values for i in 0..num_rows { assert_eq!(buffer[i * TraceRow::::ROW_SIZE], i); @@ -140,14 +104,13 @@ fn check_multi_array() { #[test] fn check_multi_array_2() { - let num_rows = 8; - trace!(TraceRow, MyTrace { a: [[F;3]; 2], b: F, c: [F; 2] }); + trace!(TraceRow, MyTrace { a: [[F;3]; 2], b: F, c: [F; 2] }, 8, 0, 0, 0); assert_eq!(TraceRow::::ROW_SIZE, 9); - let mut buffer = vec![0usize; num_rows * TraceRow::::ROW_SIZE]; - let trace = MyTrace::map_buffer(&mut buffer, num_rows, 0); - let mut trace = trace.unwrap(); + + let mut trace = MyTrace::new(); + let num_rows = trace.num_rows(); // Set values for i in 0..num_rows { @@ -162,6 +125,8 @@ fn check_multi_array_2() { trace[i].c[1] = i + 2; } + let buffer = trace.get_buffer(); + // Check values for i in 0..num_rows { assert_eq!(buffer[i * TraceRow::::ROW_SIZE], i); diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 91386a17..ddd3f703 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -162,7 +162,7 @@ fn trace_impl(input: TokenStream2) -> Result { } } - impl<'a, #generics: Send + p3_field::Field> common::trace::Trace<#generics> for #trace_struct_name<'a, #generics> { + impl<'a, #generics: Send> common::trace::Trace<#generics> for #trace_struct_name<'a, #generics> { fn num_rows(&self) -> usize { self.num_rows } @@ -377,7 +377,7 @@ fn values_impl(input: TokenStream2) -> Result { } } - impl<'a, #generics: Send + p3_field::Field> common::trace::Values<#generics> for #values_struct_name<'a, #generics> { + impl<'a, #generics: Send> common::trace::Values<#generics> for #values_struct_name<'a, #generics> { fn get_buffer(&mut self) -> Vec<#generics> { let buffer = std::mem::take(&mut self.buffer); buffer @@ -451,39 +451,6 @@ fn is_ident(type_path: &syn::TypePath, name: &str) -> bool { type_path.path.segments.last().map_or(false, |seg| seg.ident == name) } -#[test] -fn test_parse_values_01() { - let input = quote! { - Values { a: F, b: F } - }; - let parsed: ParsedValuesInput = parse2(input).unwrap(); - assert_eq!(parsed.struct_name, "Values"); - assert_eq!(parsed.generics, "F"); - assert_eq!(parsed.dimensions, 3); -} - -#[test] -fn test_parse_values_02() { - let input = quote! { - Something { a: G } - }; - let parsed: ParsedValuesInput = parse2(input).unwrap(); - assert_eq!(parsed.struct_name, "Something"); - assert_eq!(parsed.generics, "G"); - assert_eq!(parsed.dimensions, 2); -} - -#[test] -fn test_parse_values_03() { - let input = quote! { - Something { a: G, b: [G; 4] } - }; - let parsed: ParsedValuesInput = parse2(input).unwrap(); - assert_eq!(parsed.struct_name, "Something"); - assert_eq!(parsed.generics, "G"); - assert_eq!(parsed.dimensions, 189_432); -} - #[test] fn test_trace_macro_generates_default_row_struct() { let input = quote! { @@ -511,7 +478,7 @@ fn test_parsing_01() { assert_eq!(parsed.row_struct_name, "TraceRow"); assert_eq!(parsed.struct_name, "MyTrace"); assert_eq!(parsed.num_rows.base10_parse::().unwrap(), 34); - assert_eq!(parsed.commit_id.unwrap().base10_parse::().unwrap(), 38); + assert_eq!(parsed.commit_id.base10_parse::().unwrap(), 38); } #[test] From ce824557dfd4d7fd8c7043049b0bbecc6e83228e Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 9 Dec 2024 13:56:17 +0000 Subject: [PATCH 18/64] fixing ci --- Cargo.lock | 18 --------- Cargo.toml | 2 +- cli/assets/templates/pil_helpers_trace.rs.tt | 1 + common/src/air_instance.rs | 2 +- common/src/trace.rs | 16 ++++---- macros/src/lib.rs | 15 +++++--- .../std/permutation/rs/src/permutation1_6.rs | 37 ++++++++++++++++++- .../std/permutation/rs/src/permutation2.rs | 2 +- .../std/permutation/rs/src/pil_helpers/mod.rs | 1 + .../permutation/rs/src/pil_helpers/traces.rs | 4 ++ 10 files changed, 62 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8275c6dc..1e62d32a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -972,24 +972,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "range-check" -version = "0.1.0" -dependencies = [ - "env_logger", - "log", - "num-bigint", - "num-traits", - "p3-field", - "p3-goldilocks", - "pil-std-lib", - "proofman", - "proofman-cli", - "proofman-common", - "proofman-macros", - "rand", -] - [[package]] name = "rayon" version = "1.10.0" diff --git a/Cargo.toml b/Cargo.toml index 61c1fe2c..02a3dd7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ members = [ "transcript", "util", "pil2-components/lib/std/rs", - "pil2-components/test/std/range_check/rs", + # "pil2-components/test/std/range_check/rs", # "pil2-components/test/std/lookup/rs", # "pil2-components/test/std/connection/rs", # "pil2-components/test/std/permutation/rs", diff --git a/cli/assets/templates/pil_helpers_trace.rs.tt b/cli/assets/templates/pil_helpers_trace.rs.tt index d9d9e109..41cedb2c 100644 --- a/cli/assets/templates/pil_helpers_trace.rs.tt +++ b/cli/assets/templates/pil_helpers_trace.rs.tt @@ -4,6 +4,7 @@ use proofman_common as common; pub use proofman_macros::trace; pub use proofman_macros::values; +#[warn(dead_code)] type FieldExtension = [F; 3]; pub const PILOUT_HASH: &[u8] = b"{ project_name }-hash"; diff --git a/common/src/air_instance.rs b/common/src/air_instance.rs index ea92dc42..2efc714a 100644 --- a/common/src/air_instance.rs +++ b/common/src/air_instance.rs @@ -139,7 +139,7 @@ impl AirInstance { None }; - let air_values_info = if let Some(air_values) = air_values { Some(air_values.get_buffer()) } else { None }; + let air_values_info = air_values.map(|air_values| air_values.get_buffer()); let air_instance = AirInstance::new( setup_ctx, diff --git a/common/src/trace.rs b/common/src/trace.rs index 231d6473..7fe9e4e8 100644 --- a/common/src/trace.rs +++ b/common/src/trace.rs @@ -16,10 +16,9 @@ pub use proofman_macros::values; #[cfg(test)] use crate as common; - #[test] fn check() { - trace!(TraceRow, MyTrace { a: F, b:F}, 8, 0, 0, 0); + trace!(TraceRow, MyTrace { a: F, b:F}, 0, 0, 8, 0); assert_eq!(TraceRow::::ROW_SIZE, 2); @@ -40,8 +39,8 @@ fn check() { } #[test] -fn check_array() { - trace!(TraceRow, MyTrace { a: F, b: [F; 3], c: F }, 8, 0, 0, 0); +fn check_array() { + trace!(TraceRow, MyTrace { a: F, b: [F; 3], c: F }, 0, 0, 8, 0); assert_eq!(TraceRow::::ROW_SIZE, 5); let mut trace = MyTrace::new(); @@ -70,7 +69,7 @@ fn check_array() { #[test] fn check_multi_array() { - trace!(TraceRow, MyTrace { a: [[F;3]; 2], b: F }, 8, 0, 0, 0); + trace!(TraceRow, MyTrace { a: [[F;3]; 2], b: F }, 0, 0, 8, 0); assert_eq!(TraceRow::::ROW_SIZE, 7); @@ -104,11 +103,10 @@ fn check_multi_array() { #[test] fn check_multi_array_2() { - - trace!(TraceRow, MyTrace { a: [[F;3]; 2], b: F, c: [F; 2] }, 8, 0, 0, 0); + trace!(TraceRow, MyTrace { a: [[F;3]; 2], b: F, c: [F; 2] }, 0, 0, 8, 0); assert_eq!(TraceRow::::ROW_SIZE, 9); - + let mut trace = MyTrace::new(); let num_rows = trace.num_rows(); @@ -126,7 +124,7 @@ fn check_multi_array_2() { } let buffer = trace.get_buffer(); - + // Check values for i in 0..num_rows { assert_eq!(buffer[i * TraceRow::::ROW_SIZE], i); diff --git a/macros/src/lib.rs b/macros/src/lib.rs index ddd3f703..8f2c80c2 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -454,7 +454,7 @@ fn is_ident(type_path: &syn::TypePath, name: &str) -> bool { #[test] fn test_trace_macro_generates_default_row_struct() { let input = quote! { - Simple { a: F, b: F }, 2, 788 + Simple { a: F, b: F }, 0,0,0,0 }; let _generated = trace_impl(input).unwrap(); @@ -463,7 +463,7 @@ fn test_trace_macro_generates_default_row_struct() { #[test] fn test_trace_macro_with_explicit_row_struct_name() { let input = quote! { - SimpleRow, Simple { a: F, b: F }, 4 + SimpleRow, Simple { a: F, b: F }, 0,0,0,0 }; let _generated = trace_impl(input).unwrap(); @@ -472,11 +472,13 @@ fn test_trace_macro_with_explicit_row_struct_name() { #[test] fn test_parsing_01() { let input = quote! { - TraceRow, MyTrace { a: F, b: F }, 34, 38 + TraceRow, MyTrace { a: F, b: F }, 0, 0, 34, 38 }; let parsed: ParsedTraceInput = parse2(input).unwrap(); assert_eq!(parsed.row_struct_name, "TraceRow"); assert_eq!(parsed.struct_name, "MyTrace"); + assert_eq!(parsed.airgroup_id.base10_parse::().unwrap(), 0); + assert_eq!(parsed.air_id.base10_parse::().unwrap(), 0); assert_eq!(parsed.num_rows.base10_parse::().unwrap(), 34); assert_eq!(parsed.commit_id.base10_parse::().unwrap(), 38); } @@ -484,18 +486,21 @@ fn test_parsing_01() { #[test] fn test_parsing_02() { let input = quote! { - SimpleRow, Simple { a: F }, 127_456 + SimpleRow, Simple { a: F }, 0, 0, 127_456, 0 }; let parsed: ParsedTraceInput = parse2(input).unwrap(); assert_eq!(parsed.row_struct_name, "SimpleRow"); assert_eq!(parsed.struct_name, "Simple"); + assert_eq!(parsed.airgroup_id.base10_parse::().unwrap(), 0); + assert_eq!(parsed.air_id.base10_parse::().unwrap(), 0); assert_eq!(parsed.num_rows.base10_parse::().unwrap(), 127_456); + assert_eq!(parsed.commit_id.base10_parse::().unwrap(), 0); } #[test] fn test_parsing_03() { let input = quote! { - Simple { a: F }, 2 + Simple { a: F }, 0, 0, 0, 0 }; let parsed: ParsedTraceInput = parse2(input).unwrap(); assert_eq!(parsed.row_struct_name, "SimpleRow"); diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs index 56d82d3c..29b7ae93 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs @@ -75,7 +75,42 @@ where AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let mut trace2 = Permutation1_6Trace::new(); + + // Assumes + for i in 0..num_rows { + trace2[i].a1 = rng.gen(); + trace2[i].b1 = rng.gen(); + + trace2[i].a2 = F::from_canonical_u8(200); + trace2[i].b2 = F::from_canonical_u8(201); + + trace2[i].a3 = rng.gen(); + trace2[i].b3 = rng.gen(); + + trace2[i].a4 = F::from_canonical_u8(100); + trace2[i].b4 = F::from_canonical_u8(101); + + trace2[i].sel1 = F::from_bool(rng.gen_bool(0.5)); + trace2[i].sel3 = F::one(); + } + + let mut indices: Vec = (0..num_rows).collect(); + indices.shuffle(&mut rng); + + // Proves + for i in 0..num_rows { + // We take a random permutation of the indices to show that the permutation check is passing + trace2[i].c1 = trace2[indices[i]].a1; + trace2[i].d1 = trace2[indices[i]].b1; + + trace2[i].c2 = trace2[indices[i]].a3; + trace2[i].d2 = trace2[indices[i]].b3; + + trace2[i].sel2 = trace2[indices[i]].sel1; + } + + AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace2, None, None); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation2.rs b/pil2-components/test/std/permutation/rs/src/permutation2.rs index 7572121e..7e164e24 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation2.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation2.rs @@ -16,7 +16,7 @@ impl Permutation2 { pub fn new(wcm: Arc>) -> Arc { let permutation2 = Arc::new(Self { _phantom: std::marker::PhantomData }); - + let airgroup_id = Permutation2_6Trace::::get_airgroup_id(); let air_id = Permutation2_6Trace::::get_air_id(); diff --git a/pil2-components/test/std/permutation/rs/src/pil_helpers/mod.rs b/pil2-components/test/std/permutation/rs/src/pil_helpers/mod.rs index 9daf0c06..8e9f77af 100644 --- a/pil2-components/test/std/permutation/rs/src/pil_helpers/mod.rs +++ b/pil2-components/test/std/permutation/rs/src/pil_helpers/mod.rs @@ -1,5 +1,6 @@ // WARNING: This file has been autogenerated from the PILOUT file. // Manual modifications are not recommended and may be overwritten. +#[rustfmt::skip] mod traces; pub use traces::*; diff --git a/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs b/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs index c496b1ab..e23b6d38 100644 --- a/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs @@ -4,6 +4,9 @@ use proofman_common as common; pub use proofman_macros::trace; pub use proofman_macros::values; +#[warn(dead_code)] +type FieldExtension = [F; 3]; + pub const PILOUT_HASH: &[u8] = b"Build-hash"; //AIRGROUP CONSTANTS @@ -20,6 +23,7 @@ pub const PERMUTATION_1_8_AIR_IDS: &[usize] = &[2]; pub const PERMUTATION_2_6_AIR_IDS: &[usize] = &[3]; + trace!(Permutation1_6Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, sel3: F, }, 0, 0, 64, 0 ); From 9c942c5bfa5cd351e5753bfbf3394ee8c6e02261 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 9 Dec 2024 14:33:42 +0000 Subject: [PATCH 19/64] Minor changes and starting cleaning unsafes from ffi --- .../src/pil_helpers/traces.rs | 2 + hints/src/hints.rs | 4 +- .../rs/src/range_check/specified_ranges.rs | 8 + .../std/rs/src/range_check/std_range_check.rs | 34 ++- .../lib/std/rs/src/range_check/u16air.rs | 8 + .../lib/std/rs/src/range_check/u8air.rs | 8 + pil2-components/lib/std/rs/src/std.rs | 20 +- pil2-stark/lib/include/starks_lib.h | 1 - pil2-stark/src/api/starks_api.cpp | 14 -- pil2-stark/src/api/starks_api.hpp | 1 - proofman/src/global_constraints.rs | 40 ++-- proofman/src/proofman.rs | 2 +- proofman/src/recursion.rs | 78 +++---- provers/stark/src/stark_prover.rs | 19 +- provers/starks-lib-c/bindings_starks.rs | 9 +- provers/starks-lib-c/src/ffi_starks.rs | 194 ++++++++---------- 16 files changed, 221 insertions(+), 221 deletions(-) diff --git a/examples/fibonacci-square/src/pil_helpers/traces.rs b/examples/fibonacci-square/src/pil_helpers/traces.rs index 1eb43da5..fd3ac7f5 100644 --- a/examples/fibonacci-square/src/pil_helpers/traces.rs +++ b/examples/fibonacci-square/src/pil_helpers/traces.rs @@ -4,6 +4,7 @@ use proofman_common as common; pub use proofman_macros::trace; pub use proofman_macros::values; +#[warn(dead_code)] type FieldExtension = [F; 3]; pub const PILOUT_HASH: &[u8] = b"Build-hash"; @@ -38,6 +39,7 @@ pub struct BuildPublics { pub rom_root: [u64; 4], } + values!(BuildPublicValues { module: F, in1: F, in2: F, out: F, rom_root: [F; 4], }); diff --git a/hints/src/hints.rs b/hints/src/hints.rs index 8eba895c..e3785d94 100644 --- a/hints/src/hints.rs +++ b/hints/src/hints.rs @@ -1176,8 +1176,8 @@ pub fn print_row(setup_ctx: &SetupCtx, air_instance: &AirInstance, let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); let buffer = match stage == 1 { - true => air_instance.get_witness_ptr() as *mut c_void, - false => air_instance.get_trace_ptr() as *mut c_void, + true => air_instance.get_witness_ptr(), + false => air_instance.get_trace_ptr(), }; print_row_c((&setup.p_setup).into(), buffer, stage, row); diff --git a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs index 0a585329..42c092d8 100644 --- a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs +++ b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs @@ -179,6 +179,14 @@ impl SpecifiedRanges { mul_columns[range_index].add(index, *mul); } } + + pub fn airgroup_id(&self) -> usize { + self.airgroup_id + } + + pub fn air_id(&self) -> usize { + self.air_id + } } impl WitnessComponent for SpecifiedRanges { diff --git a/pil2-components/lib/std/rs/src/range_check/std_range_check.rs b/pil2-components/lib/std/rs/src/range_check/std_range_check.rs index 3b3b0ae5..dc12c1ec 100644 --- a/pil2-components/lib/std/rs/src/range_check/std_range_check.rs +++ b/pil2-components/lib/std/rs/src/range_check/std_range_check.rs @@ -25,25 +25,31 @@ pub enum RangeCheckAir { } #[derive(Clone, Debug, PartialEq, Eq, Hash)] -enum StdRangeCheckType { +pub enum StdRangeCheckType { Valid(RangeCheckAir), U8AirDouble, U16AirDouble, } #[derive(Clone, Debug)] -struct StdRangeItem { +pub struct StdRangeItem { rc_type: StdRangeCheckType, range: Range, } +impl StdRangeItem { + pub fn range_type(&self) -> StdRangeCheckType { + self.rc_type.clone() + } +} + // TODO: Remove Arc pub struct StdRangeCheck { mode: StdMode, ranges: Mutex>>, - u8air: Option>>, - u16air: Option>>, - specified_ranges: Option>>, + pub u8air: Option>>, + pub u16air: Option>>, + pub specified_ranges: Option>>, } impl Decider for StdRangeCheck { @@ -257,6 +263,24 @@ impl StdRangeCheck { specified_ranges.drain_inputs(); } } + + pub fn get_ranges(&self) -> Vec<(usize, usize, RangeCheckAir)> { + let mut ranges = Vec::new(); + + if let Some(u8air) = self.u8air.as_ref() { + ranges.push((u8air.airgroup_id(), u8air.air_id(), RangeCheckAir::U8Air)); + } + + if let Some(u16air) = self.u16air.as_ref() { + ranges.push((u16air.airgroup_id(), u16air.air_id(), RangeCheckAir::U16Air)); + } + + if let Some(specified_ranges) = self.specified_ranges.as_ref() { + ranges.push((specified_ranges.airgroup_id(), specified_ranges.air_id(), RangeCheckAir::SpecifiedRanges)); + } + + ranges + } } impl WitnessComponent for StdRangeCheck { diff --git a/pil2-components/lib/std/rs/src/range_check/u16air.rs b/pil2-components/lib/std/rs/src/range_check/u16air.rs index 8512d515..f5cff12d 100644 --- a/pil2-components/lib/std/rs/src/range_check/u16air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u16air.rs @@ -153,6 +153,14 @@ impl U16Air { mul_column.add(index, *mul); } } + + pub fn airgroup_id(&self) -> usize { + self.airgroup_id + } + + pub fn air_id(&self) -> usize { + self.air_id + } } impl WitnessComponent for U16Air { diff --git a/pil2-components/lib/std/rs/src/range_check/u8air.rs b/pil2-components/lib/std/rs/src/range_check/u8air.rs index 85a06b8a..b72a3d88 100644 --- a/pil2-components/lib/std/rs/src/range_check/u8air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u8air.rs @@ -150,6 +150,14 @@ impl U8Air { mul_column.add(index, *mul); } } + + pub fn airgroup_id(&self) -> usize { + self.airgroup_id + } + + pub fn air_id(&self) -> usize { + self.air_id + } } impl WitnessComponent for U8Air { diff --git a/pil2-components/lib/std/rs/src/std.rs b/pil2-components/lib/std/rs/src/std.rs index e8d8486c..66291125 100644 --- a/pil2-components/lib/std/rs/src/std.rs +++ b/pil2-components/lib/std/rs/src/std.rs @@ -10,7 +10,7 @@ use rayon::Scope; use proofman::WitnessManager; use proofman_common::ProofCtx; -use crate::{StdProd, StdRangeCheck, StdSum}; +use crate::{StdProd, StdRangeCheck, RangeCheckAir, StdSum}; pub struct Std { range_check: Arc>, @@ -52,4 +52,22 @@ impl Std { pub fn range_check(&self, val: F, multiplicity: F, id: usize) { self.range_check.assign_values(val, multiplicity, id); } + + pub fn get_ranges(&self) -> Vec<(usize, usize, RangeCheckAir)> { + self.range_check.get_ranges() + } + + pub fn drain_inputs(&self, rc_type: &RangeCheckAir) { + match rc_type { + RangeCheckAir::U8Air => { + self.range_check.u8air.as_ref().unwrap().drain_inputs(); + } + RangeCheckAir::U16Air => { + self.range_check.u16air.as_ref().unwrap().drain_inputs(); + } + RangeCheckAir::SpecifiedRanges => { + self.range_check.specified_ranges.as_ref().unwrap().drain_inputs(); + } + }; + } } diff --git a/pil2-stark/lib/include/starks_lib.h b/pil2-stark/lib/include/starks_lib.h index 11480875..50339410 100644 --- a/pil2-stark/lib/include/starks_lib.h +++ b/pil2-stark/lib/include/starks_lib.h @@ -26,7 +26,6 @@ // ======================================================================================== void *stark_info_new(char* filename); uint64_t get_map_total_n(void *pStarkInfo); - void *get_custom_commit_map_ids(void *pStarkInfo, uint64_t commit_id, uint64_t stage); void stark_info_free(void *pStarkInfo); // Prover Helpers diff --git a/pil2-stark/src/api/starks_api.cpp b/pil2-stark/src/api/starks_api.cpp index 374fe6bc..1b3546e3 100644 --- a/pil2-stark/src/api/starks_api.cpp +++ b/pil2-stark/src/api/starks_api.cpp @@ -161,20 +161,6 @@ uint64_t get_map_total_n(void *pStarkInfo) return ((StarkInfo *)pStarkInfo)->mapTotalN; } -void *get_custom_commit_map_ids(void *pStarkInfo, uint64_t commit_id, uint64_t stage) { - auto starkInfo = *(StarkInfo *)pStarkInfo; - VecU64Result customCommitIds; - customCommitIds.nElements = starkInfo.customCommits[commit_id].stageWidths[stage]; - customCommitIds.ids = new uint64_t[customCommitIds.nElements]; - uint64_t c = 0; - for(uint64_t i = 0; i < starkInfo.customCommitsMap[commit_id].size(); ++i) { - if(starkInfo.customCommitsMap[commit_id][i].stage == stage) { - customCommitIds.ids[c++] = i; - } - } - return new VecU64Result(customCommitIds); -} - void stark_info_free(void *pStarkInfo) { auto starkInfo = (StarkInfo *)pStarkInfo; diff --git a/pil2-stark/src/api/starks_api.hpp b/pil2-stark/src/api/starks_api.hpp index 11480875..50339410 100644 --- a/pil2-stark/src/api/starks_api.hpp +++ b/pil2-stark/src/api/starks_api.hpp @@ -26,7 +26,6 @@ // ======================================================================================== void *stark_info_new(char* filename); uint64_t get_map_total_n(void *pStarkInfo); - void *get_custom_commit_map_ids(void *pStarkInfo, uint64_t commit_id, uint64_t stage); void stark_info_free(void *pStarkInfo); // Prover Helpers diff --git a/proofman/src/global_constraints.rs b/proofman/src/global_constraints.rs index 9abbee71..5a03b753 100644 --- a/proofman/src/global_constraints.rs +++ b/proofman/src/global_constraints.rs @@ -8,8 +8,6 @@ use std::{collections::HashMap, sync::Arc}; use proofman_common::{GlobalConstraintInfo, GlobalConstraintsResults, ExtensionField, ProofCtx, SetupCtx}; -use std::os::raw::c_void; - pub fn aggregate_airgroupvals(pctx: Arc>) -> Vec> { const FIELD_EXTENSION: usize = 3; @@ -73,10 +71,10 @@ pub fn verify_global_constraints_proof( let raw_ptr = verify_global_constraints_c( sctx.get_global_bin(), - pctx.get_publics_ptr() as *mut c_void, - pctx.get_challenges_ptr() as *mut c_void, - pctx.get_proof_values_ptr() as *mut c_void, - airgroup_values_ptrs.as_mut_ptr() as *mut *mut c_void, + pctx.get_publics_ptr(), + pctx.get_challenges_ptr(), + pctx.get_proof_values_ptr(), + airgroup_values_ptrs.as_mut_ptr() as *mut *mut u8, ); unsafe { @@ -101,10 +99,10 @@ pub fn get_hint_field_gc( let raw_ptr = get_hint_field_global_constraints_c( sctx.get_global_bin(), - pctx.get_publics_ptr() as *mut c_void, - pctx.get_challenges_ptr() as *mut c_void, - pctx.get_proof_values_ptr() as *mut c_void, - airgroup_values_ptrs.as_mut_ptr() as *mut *mut c_void, + pctx.get_publics_ptr(), + pctx.get_challenges_ptr(), + pctx.get_proof_values_ptr(), + airgroup_values_ptrs.as_mut_ptr() as *mut *mut u8, hint_id, hint_field_name, print_expression, @@ -135,10 +133,10 @@ pub fn get_hint_field_gc_a( let raw_ptr = get_hint_field_global_constraints_c( sctx.get_global_bin(), - pctx.get_publics_ptr() as *mut c_void, - pctx.get_challenges_ptr() as *mut c_void, - pctx.get_proof_values_ptr() as *mut c_void, - airgroup_values_ptrs.as_mut_ptr() as *mut *mut c_void, + pctx.get_publics_ptr(), + pctx.get_challenges_ptr(), + pctx.get_proof_values_ptr(), + airgroup_values_ptrs.as_mut_ptr() as *mut *mut u8, hint_id, hint_field_name, print_expression, @@ -175,10 +173,10 @@ pub fn get_hint_field_gc_m( let raw_ptr = get_hint_field_global_constraints_c( sctx.get_global_bin(), - pctx.get_publics_ptr() as *mut c_void, - pctx.get_challenges_ptr() as *mut c_void, - pctx.get_proof_values_ptr() as *mut c_void, - airgroup_values_ptrs.as_mut_ptr() as *mut *mut c_void, + pctx.get_publics_ptr(), + pctx.get_challenges_ptr(), + pctx.get_proof_values_ptr(), + airgroup_values_ptrs.as_mut_ptr() as *mut *mut u8, hint_id, hint_field_name, print_expression, @@ -225,12 +223,10 @@ pub fn set_hint_field( } }; - let values_ptr = value_array.as_ptr() as *mut c_void; - set_hint_field_global_constraints_c( sctx.get_global_bin(), - pctx.get_proof_values_ptr() as *mut c_void, - values_ptr, + pctx.get_proof_values_ptr(), + value_array.as_ptr() as *mut u8, hint_id, hint_field_name, ); diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index efa18dfe..180f961c 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -637,7 +637,7 @@ impl ProofMan { save_proof_values_c(n_proof_values, proof_ctx.get_proof_values_ptr() as *mut c_void, output_dir); - save_challenges_c(proof_ctx.get_challenges_ptr() as *mut c_void, global_info_file, output_dir); + save_challenges_c(proof_ctx.get_challenges_ptr(), global_info_file, output_dir); timer_stop_and_log_debug!(FINALIZING_PROOF); proves diff --git a/proofman/src/recursion.rs b/proofman/src/recursion.rs index 0bf65f60..c97e832c 100644 --- a/proofman/src/recursion.rs +++ b/proofman/src/recursion.rs @@ -55,9 +55,6 @@ pub fn generate_vadcop_recursive1_proof( let (buffer, publics) = generate_witness::(&setup_path, setup, proofs[prover_idx], 18)?; - let p_publics = publics.as_ptr() as *mut c_void; - let p_address = buffer.as_ptr() as *mut c_void; - log::info!( "{}: {}", MY_NAME, @@ -78,10 +75,10 @@ pub fn generate_vadcop_recursive1_proof( zkin = gen_recursive_proof_c( p_setup, - p_address, - setup.get_const_ptr() as *mut c_void, - setup.get_const_tree_ptr() as *mut c_void, - p_publics, + buffer.as_ptr() as *mut u8, + setup.get_const_ptr(), + setup.get_const_tree_ptr(), + publics.as_ptr() as *mut u8, &proof_file, global_info_file, air_instance.airgroup_id as u64, @@ -115,9 +112,6 @@ pub fn generate_vadcop_recursive1_proof( let (buffer, publics) = generate_witness::(&setup_path, setup, zkin, 18)?; - let p_publics = publics.as_ptr() as *mut c_void; - let p_address = buffer.as_ptr() as *mut c_void; - log::info!( "{}: {}", MY_NAME, @@ -138,10 +132,10 @@ pub fn generate_vadcop_recursive1_proof( let p_prove = gen_recursive_proof_c( p_setup, - p_address, - setup.get_const_ptr() as *mut c_void, - setup.get_const_tree_ptr() as *mut c_void, - p_publics, + buffer.as_ptr() as *mut u8, + setup.get_const_ptr(), + setup.get_const_tree_ptr(), + publics.as_ptr() as *mut u8, &proof_file, global_info_file, air_instance.airgroup_id as u64, @@ -228,8 +222,8 @@ pub fn generate_vadcop_recursive2_proof( let zkin_recursive2 = join_zkin_recursive2_c( airgroup as u64, - pctx.get_publics_ptr() as *mut c_void, - pctx.get_challenges_ptr() as *mut c_void, + pctx.get_publics_ptr(), + pctx.get_challenges_ptr(), global_info_file, airgroup_proofs[airgroup][j].unwrap(), airgroup_proofs[airgroup][j + 1].unwrap(), @@ -248,8 +242,6 @@ pub fn generate_vadcop_recursive2_proof( let setup_path = pctx.global_info.get_air_setup_path(airgroup, 0, &ProofType::Recursive2); let (buffer, publics) = generate_witness::(&setup_path, setup, zkin_recursive2_updated, 18)?; - let p_publics = publics.as_ptr() as *mut c_void; - let p_address = buffer.as_ptr() as *mut c_void; timer_start_trace!(GENERATE_RECURSIVE2_PROOF); let proof_file = match save_proof { @@ -275,10 +267,10 @@ pub fn generate_vadcop_recursive2_proof( let zkin = gen_recursive_proof_c( p_setup, - p_address, - setup.get_const_ptr() as *mut c_void, - setup.get_const_tree_ptr() as *mut c_void, - p_publics, + buffer.as_ptr() as *mut u8, + setup.get_const_ptr(), + setup.get_const_tree_ptr(), + publics.as_ptr() as *mut u8, &proof_file, global_info_file, airgroup as u64, @@ -324,9 +316,9 @@ pub fn generate_vadcop_recursive2_proof( let stark_infos_recursive2_ptr = stark_infos_recursive2.as_mut_ptr(); zkin_final = join_zkin_final_c( - pctx.get_publics_ptr() as *mut c_void, - pctx.get_proof_values_ptr() as *mut c_void, - pctx.get_challenges_ptr() as *mut c_void, + pctx.get_publics_ptr(), + pctx.get_proof_values_ptr(), + pctx.get_challenges_ptr(), global_info_file, proofs_recursive2_ptr, stark_infos_recursive2_ptr, @@ -352,18 +344,16 @@ pub fn generate_vadcop_final_proof( let setup_path = pctx.global_info.get_setup_path("vadcop_final"); let (buffer, publics) = generate_witness::(&setup_path, &setup, proof, 18)?; - let p_address = buffer.as_ptr() as *mut c_void; - let p_publics = publics.as_ptr() as *mut c_void; log::info!("{}: ··· Generating vadcop final proof", MY_NAME); timer_start_trace!(GENERATE_VADCOP_FINAL_PROOF); // prove let p_prove = gen_recursive_proof_c( p_setup, - p_address, - setup.get_const_ptr() as *mut c_void, - setup.get_const_tree_ptr() as *mut c_void, - p_publics, + buffer.as_ptr() as *mut u8, + setup.get_const_ptr(), + setup.get_const_tree_ptr(), + publics.as_ptr() as *mut u8, output_dir_path.join("proofs/vadcop_final_proof.json").to_string_lossy().as_ref(), global_info_file, 0, @@ -392,18 +382,16 @@ pub fn generate_recursivef_proof( let setup_path = pctx.global_info.get_setup_path("recursivef"); let (buffer, publics) = generate_witness::(&setup_path, &setup, proof, 12)?; - let p_address = buffer.as_ptr() as *mut c_void; - let p_publics = publics.as_ptr() as *mut c_void; log::info!("{}: ··· Generating recursiveF proof", MY_NAME); timer_start_trace!(GENERATE_RECURSIVEF_PROOF); // prove let p_prove = gen_recursive_proof_c( p_setup, - p_address, - setup.get_const_ptr() as *mut c_void, - setup.get_const_tree_ptr() as *mut c_void, - p_publics, + buffer.as_ptr() as *mut u8, + setup.get_const_ptr(), + setup.get_const_tree_ptr(), + publics.as_ptr() as *mut u8, output_dir_path.join("proofs/recursivef.json").to_string_lossy().as_ref(), global_info_file, 0, @@ -444,12 +432,12 @@ pub fn generate_fflonk_snark_proof( let size_witness = get_size_witness(); let witness: Vec = create_buffer_fast((size_witness * 32) as usize); - let witness_ptr = witness.as_ptr() as *mut c_void; + let witness_ptr = witness.as_ptr() as *mut u8; let get_witness: Symbol = library.get(b"getWitness\0")?; let nmutex = 128; - get_witness(proof, dat_filename_ptr, witness_ptr, nmutex); + get_witness(proof, dat_filename_ptr, witness_ptr as *mut c_void, nmutex); timer_stop_and_log_trace!(CALCULATE_FINAL_WITNESS); @@ -479,11 +467,11 @@ fn generate_witness( let n = 1 << (setup.stark_info.stark_struct.n_bits); let buffer: Vec = create_buffer_fast(n_cols * n); - let p_address = buffer.as_ptr() as *mut c_void; + let p_address = buffer.as_ptr() as *mut u8; let n_publics = setup.stark_info.n_publics as usize; let publics: Vec = create_buffer_fast(n_publics); - let p_publics = publics.as_ptr() as *mut c_void; + let p_publics = publics.as_ptr() as *mut u8; let rust_lib_filename = setup_path.display().to_string() + ".so"; let rust_lib_path = Path::new(rust_lib_filename.as_str()); @@ -497,11 +485,11 @@ fn generate_witness( // Call the function let dat_filename = setup_path.display().to_string() + ".dat"; let dat_filename_str = CString::new(dat_filename.as_str()).unwrap(); - let dat_filename_ptr = dat_filename_str.as_ptr() as *mut std::os::raw::c_char; + let dat_filename_ptr = dat_filename_str.as_ptr() as *const i8; let exec_filename = setup_path.display().to_string() + ".exec"; let exec_filename_str = CString::new(exec_filename.as_str()).unwrap(); - let exec_filename_ptr = exec_filename_str.as_ptr() as *mut std::os::raw::c_char; + let exec_filename_ptr = exec_filename_str.as_ptr() as *const i8; let get_size_witness: Symbol = library.get(b"getSizeWitness\0")?; let size_witness = get_size_witness(); @@ -513,13 +501,13 @@ fn generate_witness( let n_adds = u64::from_le_bytes(n_adds); let witness: Vec = create_buffer_fast((size_witness + n_adds) as usize); - let witness_ptr = witness.as_ptr() as *mut c_void; + let witness_ptr = witness.as_ptr() as *mut u8; let get_witness: Symbol = library.get(b"getWitness\0")?; let nmutex = 128; - get_witness(zkin, dat_filename_ptr, witness_ptr, nmutex); + get_witness(zkin, dat_filename_ptr, witness_ptr as *mut c_void, nmutex); get_committed_pols_c( witness_ptr, diff --git a/provers/stark/src/stark_prover.rs b/provers/stark/src/stark_prover.rs index 8f464613..ed50289c 100644 --- a/provers/stark/src/stark_prover.rs +++ b/provers/stark/src/stark_prover.rs @@ -527,10 +527,8 @@ impl Prover for StarkProver { fri_proof_get_tree_root_c(p_proof, value.as_mut_ptr() as *mut c_void, step_index as u64); } else { let air_instance = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap()[self.prover_idx]; - let buffer = air_instance.get_trace_ptr() as *mut c_void; - let n_hash = (1 << (steps[n_steps].n_bits)) * Self::FIELD_EXTENSION as u64; - let fri_pol = get_fri_pol_c(self.p_stark_info, buffer); + let fri_pol = get_fri_pol_c(self.p_stark_info, air_instance.get_trace_ptr()); calculate_hash_c(p_stark, value.as_mut_ptr() as *mut c_void, fri_pol, n_hash); } } @@ -714,9 +712,8 @@ impl StarkProver { } let air_instance = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap()[self.prover_idx]; - let buffer = air_instance.get_trace_ptr() as *mut c_void; - let fri_pol = get_fri_pol_c(self.p_stark_info, buffer); + let fri_pol = get_fri_pol_c(self.p_stark_info, air_instance.get_trace_ptr()); let challenges_guard = proof_ctx.challenges.values.read().unwrap(); let challenge: Vec = challenges_guard.iter().skip(challenges_guard.len() - 3).cloned().collect(); @@ -726,8 +723,8 @@ impl StarkProver { compute_fri_folding_c( step_index as u64, - fri_pol, - challenge.as_ptr() as *mut c_void, + fri_pol as *mut u8, + challenge.as_ptr() as *mut u8, self.stark_info.stark_struct.n_bits_ext, prev_bits, current_bits, @@ -735,7 +732,7 @@ impl StarkProver { if step_index != n_steps { let next_bits = steps[(step_index + 1) as usize].n_bits; - compute_fri_merkelize_c(self.p_stark, p_proof, step_index as u64, fri_pol, current_bits, next_bits); + compute_fri_merkelize_c(self.p_stark, p_proof, step_index as u64, fri_pol as *mut u8, current_bits, next_bits); } } @@ -774,9 +771,7 @@ impl StarkProver { ); let air_instance = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap()[self.prover_idx]; - let buffer = air_instance.get_trace_ptr() as *mut c_void; - - let fri_pol = get_fri_pol_c(self.p_stark_info, buffer); + let fri_pol = get_fri_pol_c(self.p_stark_info, air_instance.get_trace_ptr()); let n_trees = self.num_stages() + 2 + self.stark_info.custom_commits.len() as u32; compute_queries_c(p_stark, p_proof, fri_queries.as_mut_ptr(), n_queries, n_trees as u64); @@ -793,7 +788,7 @@ impl StarkProver { set_fri_final_pol_c( p_proof, - fri_pol, + fri_pol as *mut u8, self.stark_info.stark_struct.steps[self.stark_info.stark_struct.steps.len() - 1].n_bits, ); } diff --git a/provers/starks-lib-c/bindings_starks.rs b/provers/starks-lib-c/bindings_starks.rs index 16e203e9..220ce495 100644 --- a/provers/starks-lib-c/bindings_starks.rs +++ b/provers/starks-lib-c/bindings_starks.rs @@ -80,14 +80,7 @@ extern "C" { #[link_name = "\u{1}_Z15get_map_total_nPv"] pub fn get_map_total_n(pStarkInfo: *mut ::std::os::raw::c_void) -> u64; } -extern "C" { - #[link_name = "\u{1}_Z25get_custom_commit_map_idsPvmm"] - pub fn get_custom_commit_map_ids( - pStarkInfo: *mut ::std::os::raw::c_void, - commit_id: u64, - stage: u64, - ) -> *mut ::std::os::raw::c_void; -} + extern "C" { #[link_name = "\u{1}_Z15stark_info_freePv"] pub fn stark_info_free(pStarkInfo: *mut ::std::os::raw::c_void); diff --git a/provers/starks-lib-c/src/ffi_starks.rs b/provers/starks-lib-c/src/ffi_starks.rs index 6d156f44..49609ef8 100644 --- a/provers/starks-lib-c/src/ffi_starks.rs +++ b/provers/starks-lib-c/src/ffi_starks.rs @@ -20,7 +20,7 @@ include!("../bindings_starks.rs"); use std::ffi::CString; #[cfg(not(feature = "no_lib_link"))] -pub fn save_challenges_c(p_challenges: *mut std::os::raw::c_void, global_info_file: &str, output_dir: &str) { +pub fn save_challenges_c(p_challenges: *mut u8, global_info_file: &str, output_dir: &str) { unsafe { let file_dir = CString::new(output_dir).unwrap(); let file_ptr = file_dir.as_ptr() as *mut std::os::raw::c_char; @@ -127,20 +127,6 @@ pub fn get_map_totaln_c(p_stark_info: *mut c_void) -> u64 { unsafe { get_map_total_n(p_stark_info) } } -#[cfg(not(feature = "no_lib_link"))] -pub fn get_custom_commit_map_ids_c(p_stark_info: *mut c_void, commit_id: u64, stage: u64) -> Vec { - unsafe { - let raw_ptr = get_custom_commit_map_ids(p_stark_info, commit_id, stage); - - let ids_result = Box::from_raw(raw_ptr as *mut VecU64Result); - - let slice = std::slice::from_raw_parts(ids_result.values, ids_result.n_values as usize); - - // Copy the contents of the slice into a Vec - - slice.to_vec() - } -} #[cfg(not(feature = "no_lib_link"))] pub fn stark_info_free_c(p_stark_info: *mut c_void) { @@ -402,8 +388,8 @@ pub fn calculate_xdivxsub_c(p_stark: *mut c_void, xi_challenge: *mut c_void, xdi } #[cfg(not(feature = "no_lib_link"))] -pub fn get_fri_pol_c(p_stark_info: *mut c_void, buffer: *mut c_void) -> *mut c_void { - unsafe { get_fri_pol(p_stark_info, buffer) } +pub fn get_fri_pol_c(p_stark_info: *mut c_void, buffer: *mut u8) -> *mut c_void { + unsafe { get_fri_pol(p_stark_info, buffer as *mut std::os::raw::c_void) } } #[cfg(not(feature = "no_lib_link"))] @@ -510,14 +496,14 @@ pub fn compute_evals_c(p_stark: *mut c_void, params: *mut c_void, lev: *mut c_vo #[cfg(not(feature = "no_lib_link"))] pub fn compute_fri_folding_c( step: u64, - buffer: *mut c_void, - challenge: *mut c_void, + buffer: *mut u8, + challenge: *mut u8, n_bits_ext: u64, prev_bits: u64, current_bits: u64, ) { unsafe { - compute_fri_folding(step, buffer, challenge, n_bits_ext, prev_bits, current_bits); + compute_fri_folding(step, buffer as *mut std::os::raw::c_void, challenge as *mut std::os::raw::c_void, n_bits_ext, prev_bits, current_bits); } } @@ -526,12 +512,12 @@ pub fn compute_fri_merkelize_c( p_starks: *mut c_void, p_proof: *mut c_void, step: u64, - buffer: *mut c_void, + buffer: *mut u8, current_bits: u64, next_bits: u64, ) { unsafe { - compute_fri_merkelize(p_starks, p_proof, step, buffer, current_bits, next_bits); + compute_fri_merkelize(p_starks, p_proof, step, buffer as *mut std::os::raw::c_void, current_bits, next_bits); } } @@ -563,9 +549,9 @@ pub fn compute_fri_queries_c( } #[cfg(not(feature = "no_lib_link"))] -pub fn set_fri_final_pol_c(p_proof: *mut c_void, buffer: *mut c_void, n_bits: u64) { +pub fn set_fri_final_pol_c(p_proof: *mut c_void, buffer: *mut u8, n_bits: u64) { unsafe { - set_fri_final_pol(p_proof, buffer, n_bits); + set_fri_final_pol(p_proof, buffer as *mut std::os::raw::c_void, n_bits); } } @@ -624,22 +610,22 @@ pub fn verify_constraints_c(p_setup: *mut c_void, p_steps_params: *mut c_void) - #[cfg(not(feature = "no_lib_link"))] pub fn verify_global_constraints_c( p_global_constraints_bin: *mut c_void, - publics: *mut c_void, - challenges: *mut c_void, - proof_values: *mut c_void, - airgroupvalues: *mut *mut c_void, + publics: *mut u8, + challenges: *mut u8, + proof_values: *mut u8, + airgroupvalues: *mut *mut u8, ) -> *mut c_void { - unsafe { verify_global_constraints(p_global_constraints_bin, publics, challenges, proof_values, airgroupvalues) } + unsafe { verify_global_constraints(p_global_constraints_bin, publics as *mut std::os::raw::c_void, challenges as *mut std::os::raw::c_void, proof_values as *mut std::os::raw::c_void, airgroupvalues as *mut *mut std::os::raw::c_void) } } #[cfg(not(feature = "no_lib_link"))] #[allow(clippy::too_many_arguments)] pub fn get_hint_field_global_constraints_c( p_global_constraints_bin: *mut c_void, - publics: *mut c_void, - challenges: *mut c_void, - proof_values: *mut c_void, - airgroupvalues: *mut *mut c_void, + publics: *mut u8, + challenges: *mut u8, + proof_values: *mut u8, + airgroupvalues: *mut *mut u8, hint_id: u64, hint_field_name: &str, print_expression: bool, @@ -648,10 +634,10 @@ pub fn get_hint_field_global_constraints_c( unsafe { get_hint_field_global_constraints( p_global_constraints_bin, - publics, - challenges, - proof_values, - airgroupvalues, + publics as *mut std::os::raw::c_void, + challenges as *mut std::os::raw::c_void, + proof_values as *mut std::os::raw::c_void, + airgroupvalues as *mut *mut std::os::raw::c_void, hint_id, field_name.as_ptr() as *mut std::os::raw::c_char, print_expression, @@ -662,8 +648,8 @@ pub fn get_hint_field_global_constraints_c( #[cfg(not(feature = "no_lib_link"))] pub fn set_hint_field_global_constraints_c( p_global_constraints_bin: *mut c_void, - proof_values: *mut c_void, - values: *mut c_void, + proof_values: *mut u8, + values: *mut u8, hint_id: u64, hint_field_name: &str, ) -> u64 { @@ -671,8 +657,8 @@ pub fn set_hint_field_global_constraints_c( unsafe { set_hint_field_global_constraints( p_global_constraints_bin, - proof_values, - values, + proof_values as *mut std::os::raw::c_void, + values as *mut std::os::raw::c_void, hint_id, field_name.as_ptr() as *mut std::os::raw::c_char, ) @@ -680,9 +666,9 @@ pub fn set_hint_field_global_constraints_c( } #[cfg(not(feature = "no_lib_link"))] -pub fn print_row_c(p_setup_ctx: *mut c_void, buffer: *mut c_void, stage: u64, row: u64) { +pub fn print_row_c(p_setup_ctx: *mut c_void, buffer: *mut u8, stage: u64, row: u64) { unsafe { - print_row(p_setup_ctx, buffer, stage, row); + print_row(p_setup_ctx, buffer as *mut std::os::raw::c_void, stage, row); } } @@ -690,10 +676,10 @@ pub fn print_row_c(p_setup_ctx: *mut c_void, buffer: *mut c_void, stage: u64, ro #[allow(clippy::too_many_arguments)] pub fn gen_recursive_proof_c( p_setup_ctx: *mut c_void, - p_address: *mut c_void, - p_const_pols: *mut c_void, - p_const_tree: *mut c_void, - p_public_inputs: *mut c_void, + p_address: *mut u8, + p_const_pols: *mut u8, + p_const_tree: *mut u8, + p_public_inputs: *mut u8, proof_file: &str, global_info_file: &str, airgroup_id: u64, @@ -710,10 +696,10 @@ pub fn gen_recursive_proof_c( p_setup_ctx, global_info_file_ptr, airgroup_id, - p_address, - p_const_pols, - p_const_tree, - p_public_inputs, + p_address as *mut std::os::raw::c_void, + p_const_pols as *mut std::os::raw::c_void, + p_const_tree as *mut std::os::raw::c_void, + p_public_inputs as *mut std::os::raw::c_void, proof_file_ptr, vadcop, ) @@ -738,9 +724,9 @@ pub fn add_recursive2_verkey_c(p_zkin: *mut c_void, recursive2_verkey: &str) -> #[cfg(not(feature = "no_lib_link"))] pub fn join_zkin_final_c( - p_publics: *mut c_void, - p_proof_values: *mut c_void, - p_challenges: *mut c_void, + p_publics: *mut u8, + p_proof_values: *mut u8, + p_challenges: *mut u8, global_info_file: &str, zkin_recursive2: *mut *mut c_void, stark_info_recursive2: *mut *mut c_void, @@ -750,9 +736,9 @@ pub fn join_zkin_final_c( unsafe { join_zkin_final( - p_publics, - p_proof_values, - p_challenges, + p_publics as *mut std::os::raw::c_void, + p_proof_values as *mut std::os::raw::c_void, + p_challenges as *mut std::os::raw::c_void, global_info_file_ptr, zkin_recursive2, stark_info_recursive2, @@ -763,8 +749,8 @@ pub fn join_zkin_final_c( #[cfg(not(feature = "no_lib_link"))] pub fn join_zkin_recursive2_c( airgroup_id: u64, - p_publics: *mut c_void, - p_challenges: *mut c_void, + p_publics: *mut u8, + p_challenges: *mut u8, global_info_file: &str, zkin1: *mut c_void, zkin2: *mut c_void, @@ -777,8 +763,8 @@ pub fn join_zkin_recursive2_c( join_zkin_recursive2( global_info_file_ptr, airgroup_id, - p_publics, - p_challenges, + p_publics as *mut std::os::raw::c_void, + p_challenges as *mut std::os::raw::c_void, zkin1, zkin2, stark_info_recursive2, @@ -824,29 +810,29 @@ pub fn serialized_proof_free_c(zkin_cstr: *mut std::os::raw::c_char) { #[cfg(not(feature = "no_lib_link"))] #[allow(clippy::too_many_arguments)] pub fn get_committed_pols_c( - circomWitness: *mut ::std::os::raw::c_void, - execFile: *mut ::std::os::raw::c_char, - witness: *mut ::std::os::raw::c_void, - pPublics: *mut ::std::os::raw::c_void, + circomWitness: *mut u8, + execFile: *const i8, + witness: *mut u8, + pPublics: *mut u8, sizeWitness: u64, N: u64, nPublics: u64, nCols: u64, ) { unsafe { - get_committed_pols(circomWitness, execFile, witness, pPublics, sizeWitness, N, nPublics, nCols); + get_committed_pols(circomWitness as *mut std::os::raw::c_void, execFile as *mut std::os::raw::c_char, witness as *mut std::os::raw::c_void, pPublics as *mut std::os::raw::c_void, sizeWitness, N, nPublics, nCols); } } #[cfg(not(feature = "no_lib_link"))] -pub fn gen_final_snark_proof_c(circomWitnessFinal: *mut ::std::os::raw::c_void, zkeyFile: &str, outputDir: &str) { +pub fn gen_final_snark_proof_c(circomWitnessFinal: *mut u8, zkeyFile: &str, outputDir: &str) { let zkey_file_name = CString::new(zkeyFile).unwrap(); let zkey_file_ptr = zkey_file_name.as_ptr() as *mut std::os::raw::c_char; let output_dir_name = CString::new(outputDir).unwrap(); let output_dir_ptr = output_dir_name.as_ptr() as *mut std::os::raw::c_char; unsafe { - gen_final_snark_proof(circomWitnessFinal, zkey_file_ptr, output_dir_ptr); + gen_final_snark_proof(circomWitnessFinal as *mut std::os::raw::c_void, zkey_file_ptr, output_dir_ptr); } } @@ -861,7 +847,7 @@ pub fn set_log_level_c(level: u64) { // MOCK METHODS FOR TESTING // ------------------------ #[cfg(feature = "no_lib_link")] -pub fn save_challenges_c(_p_challenges: *mut std::os::raw::c_void, _global_info_file: &str, _output_dir: &str) { +pub fn save_challenges_c(_p_challenges: *mut u8, _global_info_file: &str, _output_dir: &str) { trace!("{}: ··· {}", "ffi ", "save_challenges: This is a mock call because there is no linked library"); } @@ -951,16 +937,6 @@ pub fn get_custom_commit_id_c(_p_stark_info: *mut c_void, _name: &str) -> u64 { 100000000 } -#[cfg(feature = "no_lib_link")] -pub fn get_custom_commit_map_ids_c(_p_stark_info: *mut c_void, _commit_id: u64, _stage: u64) -> Vec { - trace!( - "{}: ··· {}", - "ffi ", - "get_custom_commit_map_ids: This is a mock call because there is no linked library" - ); - Vec::new() -} - #[cfg(feature = "no_lib_link")] pub fn stark_info_free_c(_p_stark_info: *mut c_void) { trace!("{}: ··· {}", "ffi ", "starkinfo_free: This is a mock call because there is no linked library"); @@ -1205,7 +1181,7 @@ pub fn calculate_xdivxsub_c(_p_stark: *mut c_void, _xi_challenge: *mut c_void, _ } #[cfg(feature = "no_lib_link")] -pub fn get_fri_pol_c(_p_stark_info: *mut c_void, _buffer: *mut c_void) -> *mut c_void { +pub fn get_fri_pol_c(_p_stark_info: *mut c_void, _buffer: *mut u8) -> *mut c_void { trace!("ffi : ··· {}", "get_fri_pol: This is a mock call because there is no linked library"); std::ptr::null_mut() } @@ -1213,8 +1189,8 @@ pub fn get_fri_pol_c(_p_stark_info: *mut c_void, _buffer: *mut c_void) -> *mut c #[cfg(feature = "no_lib_link")] pub fn compute_fri_folding_c( _step: u64, - _buffer: *mut c_void, - _challenge: *mut c_void, + _buffer: *mut u8, + _challenge: *mut u8, _n_bits_ext: u64, _prev_bits: u64, _current_bits: u64, @@ -1227,7 +1203,7 @@ pub fn compute_fri_merkelize_c( _p_starks: *mut c_void, _p_proof: *mut c_void, _step: u64, - _buffer: *mut c_void, + _buffer: *mut u8, _current_bits: u64, _next_bits: u64, ) { @@ -1258,7 +1234,7 @@ pub fn compute_fri_queries_c( } #[cfg(feature = "no_lib_link")] -pub fn set_fri_final_pol_c(_p_proof: *mut c_void, _buffer: *mut c_void, _n_bits: u64) { +pub fn set_fri_final_pol_c(_p_proof: *mut c_void, _buffer: *mut u8, _n_bits: u64) { trace!("{}: ··· {}", "ffi ", "set_fri_final_pol: This is a mock call because there is no linked library"); } @@ -1311,10 +1287,10 @@ pub fn verify_constraints_c(_p_setup: *mut c_void, _p_steps_params: *mut c_void) #[cfg(feature = "no_lib_link")] pub fn verify_global_constraints_c( _p_global_constraints_bin: *mut c_void, - _publics: *mut c_void, - _challenges: *mut c_void, - _proof_values: *mut c_void, - _airgroupvalues: *mut *mut c_void, + _publics: *mut u8, + _challenges: *mut u8, + _proof_values: *mut u8, + _airgroupvalues: *mut *mut u8, ) -> *mut c_void { trace!( "{}: ··· {}", @@ -1328,10 +1304,10 @@ pub fn verify_global_constraints_c( #[allow(clippy::too_many_arguments)] pub fn get_hint_field_global_constraints_c( _p_global_constraints_bin: *mut c_void, - _publics: *mut c_void, - _challenges: *mut c_void, - _proof_values: *mut c_void, - _airgroupvalues: *mut *mut c_void, + _publics: *mut u8, + _challenges: *mut u8, + _proof_values: *mut u8, + _airgroupvalues: *mut *mut u8, _hint_id: u64, _hint_field_name: &str, _print_expression: bool, @@ -1347,8 +1323,8 @@ pub fn get_hint_field_global_constraints_c( #[cfg(feature = "no_lib_link")] pub fn set_hint_field_global_constraints_c( _p_global_constraints_bin: *mut c_void, - _proof_values: *mut c_void, - _values: *mut c_void, + _proof_values: *mut u8, + _values: *mut u8, _hint_id: u64, _hint_field_name: &str, ) -> u64 { @@ -1361,7 +1337,7 @@ pub fn set_hint_field_global_constraints_c( } #[cfg(feature = "no_lib_link")] -pub fn print_row_c(_p_setup_ctx: *mut c_void, _buffer: *mut c_void, _stage: u64, _row: u64) { +pub fn print_row_c(_p_setup_ctx: *mut c_void, _buffer: *mut u8, _stage: u64, _row: u64) { trace!("{}: ··· {}", "ffi ", "print_row: This is a mock call because there is no linked library"); } @@ -1369,10 +1345,10 @@ pub fn print_row_c(_p_setup_ctx: *mut c_void, _buffer: *mut c_void, _stage: u64, #[allow(clippy::too_many_arguments)] pub fn gen_recursive_proof_c( _p_setup_ctx: *mut c_void, - _p_address: *mut c_void, - _p_const_pols: *mut c_void, - _p_const_tree: *mut c_void, - _p_public_inputs: *mut c_void, + _p_address: *mut u8, + _p_const_pols: *mut u8, + _p_const_tree: *mut u8, + _p_public_inputs: *mut u8, _proof_file: &str, _global_info_file: &str, _airgroup_id: u64, @@ -1397,8 +1373,8 @@ pub fn add_recursive2_verkey_c(_p_zkin: *mut c_void, _recursive2_verkey: &str) - #[cfg(feature = "no_lib_link")] pub fn join_zkin_recursive2_c( _airgroup_id: u64, - _p_publics: *mut c_void, - _p_challenges: *mut c_void, + _p_publics: *mut u8, + _p_challenges: *mut u8, _global_info_file: &str, _zkin1: *mut c_void, _zkin2: *mut c_void, @@ -1410,9 +1386,9 @@ pub fn join_zkin_recursive2_c( #[cfg(feature = "no_lib_link")] pub fn join_zkin_final_c( - _p_publics: *mut c_void, - _p_proof_values: *mut c_void, - _p_challenges: *mut c_void, + _p_publics: *mut u8, + _p_proof_values: *mut u8, + _p_challenges: *mut u8, _global_info_file: &str, _zkin_recursive2: *mut *mut c_void, _stark_info_recursive2: *mut *mut c_void, @@ -1452,10 +1428,10 @@ pub fn serialized_proof_free_c(_zkin_cstr: *mut std::os::raw::c_char) { #[cfg(feature = "no_lib_link")] #[allow(clippy::too_many_arguments)] pub fn get_committed_pols_c( - _circomWitness: *mut ::std::os::raw::c_void, - _execFile: *mut ::std::os::raw::c_char, - _witness: *mut ::std::os::raw::c_void, - _pPublics: *mut ::std::os::raw::c_void, + _circomWitness: *mut u8, + _execFile: *const i8, + _witness: *mut u8, + _pPublics: *mut u8, _sizeWitness: u64, _N: u64, _nPublics: u64, @@ -1465,7 +1441,7 @@ pub fn get_committed_pols_c( } #[cfg(feature = "no_lib_link")] -pub fn gen_final_snark_proof_c(_circomWitnessFinal: *mut ::std::os::raw::c_void, _zkeyFile: &str, _outputDir: &str) { +pub fn gen_final_snark_proof_c(_circomWitnessFinal: *mut u8, _zkeyFile: &str, _outputDir: &str) { trace!("{}: ··· {}", "ffi ", "gen_final_snark_proof: This is a mock call because there is no linked library"); } From f27bf268bd22fa8910d2c13dcf13ae471d66f99d Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 9 Dec 2024 14:37:54 +0000 Subject: [PATCH 20/64] Cargo fmt --- provers/stark/src/stark_prover.rs | 9 +++++++- provers/starks-lib-c/src/ffi_starks.rs | 31 ++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/provers/stark/src/stark_prover.rs b/provers/stark/src/stark_prover.rs index ed50289c..899a33db 100644 --- a/provers/stark/src/stark_prover.rs +++ b/provers/stark/src/stark_prover.rs @@ -732,7 +732,14 @@ impl StarkProver { if step_index != n_steps { let next_bits = steps[(step_index + 1) as usize].n_bits; - compute_fri_merkelize_c(self.p_stark, p_proof, step_index as u64, fri_pol as *mut u8, current_bits, next_bits); + compute_fri_merkelize_c( + self.p_stark, + p_proof, + step_index as u64, + fri_pol as *mut u8, + current_bits, + next_bits, + ); } } diff --git a/provers/starks-lib-c/src/ffi_starks.rs b/provers/starks-lib-c/src/ffi_starks.rs index 49609ef8..65c14d67 100644 --- a/provers/starks-lib-c/src/ffi_starks.rs +++ b/provers/starks-lib-c/src/ffi_starks.rs @@ -127,7 +127,6 @@ pub fn get_map_totaln_c(p_stark_info: *mut c_void) -> u64 { unsafe { get_map_total_n(p_stark_info) } } - #[cfg(not(feature = "no_lib_link"))] pub fn stark_info_free_c(p_stark_info: *mut c_void) { unsafe { @@ -503,7 +502,14 @@ pub fn compute_fri_folding_c( current_bits: u64, ) { unsafe { - compute_fri_folding(step, buffer as *mut std::os::raw::c_void, challenge as *mut std::os::raw::c_void, n_bits_ext, prev_bits, current_bits); + compute_fri_folding( + step, + buffer as *mut std::os::raw::c_void, + challenge as *mut std::os::raw::c_void, + n_bits_ext, + prev_bits, + current_bits, + ); } } @@ -615,7 +621,15 @@ pub fn verify_global_constraints_c( proof_values: *mut u8, airgroupvalues: *mut *mut u8, ) -> *mut c_void { - unsafe { verify_global_constraints(p_global_constraints_bin, publics as *mut std::os::raw::c_void, challenges as *mut std::os::raw::c_void, proof_values as *mut std::os::raw::c_void, airgroupvalues as *mut *mut std::os::raw::c_void) } + unsafe { + verify_global_constraints( + p_global_constraints_bin, + publics as *mut std::os::raw::c_void, + challenges as *mut std::os::raw::c_void, + proof_values as *mut std::os::raw::c_void, + airgroupvalues as *mut *mut std::os::raw::c_void, + ) + } } #[cfg(not(feature = "no_lib_link"))] @@ -820,7 +834,16 @@ pub fn get_committed_pols_c( nCols: u64, ) { unsafe { - get_committed_pols(circomWitness as *mut std::os::raw::c_void, execFile as *mut std::os::raw::c_char, witness as *mut std::os::raw::c_void, pPublics as *mut std::os::raw::c_void, sizeWitness, N, nPublics, nCols); + get_committed_pols( + circomWitness as *mut std::os::raw::c_void, + execFile as *mut std::os::raw::c_char, + witness as *mut std::os::raw::c_void, + pPublics as *mut std::os::raw::c_void, + sizeWitness, + N, + nPublics, + nCols, + ); } } From 8f8ab9e583ea77dbcb15f2cf067c09fa56970d31 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 9 Dec 2024 14:38:51 +0000 Subject: [PATCH 21/64] Cargo clippy --- proofman/src/recursion.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proofman/src/recursion.rs b/proofman/src/recursion.rs index c97e832c..072b8ffb 100644 --- a/proofman/src/recursion.rs +++ b/proofman/src/recursion.rs @@ -485,11 +485,11 @@ fn generate_witness( // Call the function let dat_filename = setup_path.display().to_string() + ".dat"; let dat_filename_str = CString::new(dat_filename.as_str()).unwrap(); - let dat_filename_ptr = dat_filename_str.as_ptr() as *const i8; + let dat_filename_ptr = dat_filename_str.as_ptr(); let exec_filename = setup_path.display().to_string() + ".exec"; let exec_filename_str = CString::new(exec_filename.as_str()).unwrap(); - let exec_filename_ptr = exec_filename_str.as_ptr() as *const i8; + let exec_filename_ptr = exec_filename_str.as_ptr(); let get_size_witness: Symbol = library.get(b"getSizeWitness\0")?; let size_witness = get_size_witness(); From 91d992a46d1dfdf4cc84c253d0f0fdf0e65de41a Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 9 Dec 2024 15:24:07 +0000 Subject: [PATCH 22/64] Keep cleaning c_void --- common/src/air_instance.rs | 40 ++-- common/src/custom_commits.rs | 5 +- common/src/setup.rs | 14 +- hints/src/hints.rs | 134 ++++++------ proofman/src/proofman.rs | 10 +- provers/stark/src/stark_prover.rs | 119 +++++------ provers/starks-lib-c/src/ffi_starks.rs | 270 ++++++++++++++----------- transcript/src/ffi_transcript.rs | 2 +- 8 files changed, 306 insertions(+), 288 deletions(-) diff --git a/common/src/air_instance.rs b/common/src/air_instance.rs index 2efc714a..c4173651 100644 --- a/common/src/air_instance.rs +++ b/common/src/air_instance.rs @@ -1,4 +1,4 @@ -use std::{os::raw::c_void, sync::Arc}; +use std::sync::Arc; use std::path::PathBuf; use p3_field::Field; use proofman_util::create_buffer_fast; @@ -7,23 +7,23 @@ use crate::{trace::Trace, trace::Values, ProofCtx, ExecutionCtx, SetupCtx, Setup #[repr(C)] pub struct StepsParams { - pub witness: *mut c_void, - pub trace: *mut c_void, - pub public_inputs: *mut c_void, - pub challenges: *mut c_void, - pub airgroup_values: *mut c_void, - pub airvalues: *mut c_void, - pub evals: *mut c_void, - pub xdivxsub: *mut c_void, - pub p_const_pols: *mut c_void, - pub p_const_tree: *mut c_void, - pub custom_commits: [*mut c_void; 10], - pub custom_commits_extended: [*mut c_void; 10], + pub witness: *mut u8, + pub trace: *mut u8, + pub public_inputs: *mut u8, + pub challenges: *mut u8, + pub airgroup_values: *mut u8, + pub airvalues: *mut u8, + pub evals: *mut u8, + pub xdivxsub: *mut u8, + pub p_const_pols: *mut u8, + pub p_const_tree: *mut u8, + pub custom_commits: [*mut u8; 10], + pub custom_commits_extended: [*mut u8; 10], } -impl From<&StepsParams> for *mut c_void { - fn from(params: &StepsParams) -> *mut c_void { - params as *const StepsParams as *mut c_void +impl From<&StepsParams> for *mut u8 { + fn from(params: &StepsParams) -> *mut u8 { + params as *const StepsParams as *mut u8 } } @@ -216,18 +216,18 @@ impl AirInstance { } } - pub fn get_custom_commits_ptr(&self) -> [*mut c_void; 10] { + pub fn get_custom_commits_ptr(&self) -> [*mut u8; 10] { let mut ptrs = [std::ptr::null_mut(); 10]; for (i, custom_commit) in self.custom_commits.iter().enumerate() { - ptrs[i] = custom_commit.buffer.as_ptr() as *mut c_void; + ptrs[i] = custom_commit.buffer.as_ptr() as *mut u8; } ptrs } - pub fn get_custom_commits_extended_ptr(&self) -> [*mut c_void; 10] { + pub fn get_custom_commits_extended_ptr(&self) -> [*mut u8; 10] { let mut ptrs = [std::ptr::null_mut(); 10]; for (i, custom_commit) in self.custom_commits_extended.iter().enumerate() { - ptrs[i] = custom_commit.buffer.as_ptr() as *mut c_void; + ptrs[i] = custom_commit.buffer.as_ptr() as *mut u8; } ptrs } diff --git a/common/src/custom_commits.rs b/common/src/custom_commits.rs index dba9d09c..bed8f223 100644 --- a/common/src/custom_commits.rs +++ b/common/src/custom_commits.rs @@ -2,7 +2,6 @@ use proofman_starks_lib_c::{extend_and_merkelize_custom_commit_c, fri_proof_new_ use p3_goldilocks::Goldilocks; use serde_json::Value; use std::collections::HashMap; -use std::os::raw::c_void; use std::path::PathBuf; use crate::{Setup, SetupCtx}; @@ -50,8 +49,8 @@ pub fn get_custom_commit_trace( starks_new_c((&setup.p_setup).into(), std::ptr::null_mut()), commit_id, step, - buffer.as_ptr() as *mut c_void, - buffer_ext.as_ptr() as *mut c_void, + buffer.as_ptr() as *mut u8, + buffer_ext.as_ptr() as *mut u8, fri_proof_new_c((&setup.p_setup).into()), std::ptr::null_mut(), buffer_str, diff --git a/common/src/setup.rs b/common/src/setup.rs index 442760a9..b5c565e1 100644 --- a/common/src/setup.rs +++ b/common/src/setup.rs @@ -115,8 +115,7 @@ impl Setup { let const_size = get_const_size_c(p_stark_info) as usize; let const_pols: Vec = create_buffer_fast(const_size); - let p_const_pols_address = const_pols.as_ptr() as *mut c_void; - load_const_pols_c(p_const_pols_address, const_pols_path.as_str(), const_size as u64); + load_const_pols_c(const_pols.as_ptr() as *mut u8, const_pols_path.as_str(), const_size as u64); *self.const_pols.values.write().unwrap() = const_pols; } @@ -138,14 +137,17 @@ impl Setup { let const_tree: Vec = create_buffer_fast(const_tree_size); - let p_const_tree_address = const_tree.as_ptr() as *mut c_void; if PathBuf::from(&const_pols_tree_path).exists() { - load_const_tree_c(p_const_tree_address, const_pols_tree_path.as_str(), const_tree_size as u64); + load_const_tree_c(const_tree.as_ptr() as *mut u8, const_pols_tree_path.as_str(), const_tree_size as u64); } else { let const_pols = self.const_pols.values.read().unwrap(); - let p_const_pols_address = (*const_pols).as_ptr() as *mut c_void; let tree_filename = if save_file { const_pols_tree_path.as_str() } else { "" }; - calculate_const_tree_c(p_stark_info, p_const_pols_address, p_const_tree_address, tree_filename); + calculate_const_tree_c( + p_stark_info, + (*const_pols).as_ptr() as *mut u8, + const_tree.as_ptr() as *mut u8, + tree_filename, + ); }; *self.const_tree.values.write().unwrap() = const_tree; } diff --git a/hints/src/hints.rs b/hints/src/hints.rs index e3785d94..6c937130 100644 --- a/hints/src/hints.rs +++ b/hints/src/hints.rs @@ -8,8 +8,6 @@ use std::collections::HashMap; use p3_field::Field; use proofman_common::{AirInstance, ExtensionField, ProofCtx, SetupCtx, StepsParams}; -use std::os::raw::c_void; - use std::ops::{Add, Div, Mul, Sub, AddAssign, DivAssign, MulAssign, SubAssign}; use std::fmt::{Display, Debug, Formatter, Result}; @@ -54,9 +52,9 @@ pub struct HintFieldOptions { pub compilation_time: bool, } -impl From<&HintFieldOptions> for *mut c_void { - fn from(options: &HintFieldOptions) -> *mut c_void { - options as *const HintFieldOptions as *mut c_void +impl From<&HintFieldOptions> for *mut u8 { + fn from(options: &HintFieldOptions) -> *mut u8 { + options as *const HintFieldOptions as *mut u8 } } @@ -656,7 +654,7 @@ impl HintCol { } } -pub fn get_hint_ids_by_name(p_expressions_bin: *mut c_void, name: &str) -> Vec { +pub fn get_hint_ids_by_name(p_expressions_bin: *mut std::os::raw::c_void, name: &str) -> Vec { let raw_ptr = get_hint_ids_by_name_c(p_expressions_bin, name); let hint_ids_result = unsafe { Box::from_raw(raw_ptr as *mut VecU64Result) }; @@ -683,16 +681,16 @@ pub fn mul_hint_fields( let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); let steps_params = StepsParams { - witness: air_instance.get_witness_ptr() as *mut c_void, - trace: air_instance.get_trace_ptr() as *mut c_void, - public_inputs: proof_ctx.get_publics_ptr() as *mut c_void, - challenges: proof_ctx.get_challenges_ptr() as *mut c_void, - airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, - airvalues: air_instance.get_airvalues_ptr() as *mut c_void, - evals: air_instance.get_evals_ptr() as *mut c_void, + witness: air_instance.get_witness_ptr(), + trace: air_instance.get_trace_ptr(), + public_inputs: proof_ctx.get_publics_ptr(), + challenges: proof_ctx.get_challenges_ptr(), + airgroup_values: air_instance.get_airgroup_values_ptr(), + airvalues: air_instance.get_airvalues_ptr(), + evals: air_instance.get_evals_ptr(), xdivxsub: std::ptr::null_mut(), - p_const_pols: setup.get_const_ptr() as *mut c_void, - p_const_tree: setup.get_const_tree_ptr() as *mut c_void, + p_const_pols: setup.get_const_ptr(), + p_const_tree: setup.get_const_tree_ptr(), custom_commits: air_instance.get_custom_commits_ptr(), custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; @@ -723,16 +721,16 @@ pub fn acc_hint_field( let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); let steps_params = StepsParams { - witness: air_instance.get_witness_ptr() as *mut c_void, - trace: air_instance.get_trace_ptr() as *mut c_void, - public_inputs: proof_ctx.get_publics_ptr() as *mut c_void, - challenges: proof_ctx.get_challenges_ptr() as *mut c_void, - airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, - airvalues: air_instance.get_airvalues_ptr() as *mut c_void, - evals: air_instance.get_evals_ptr() as *mut c_void, + witness: air_instance.get_witness_ptr(), + trace: air_instance.get_trace_ptr(), + public_inputs: proof_ctx.get_publics_ptr(), + challenges: proof_ctx.get_challenges_ptr(), + airgroup_values: air_instance.get_airgroup_values_ptr(), + airvalues: air_instance.get_airvalues_ptr(), + evals: air_instance.get_evals_ptr(), xdivxsub: std::ptr::null_mut(), - p_const_pols: setup.get_const_ptr() as *mut c_void, - p_const_tree: setup.get_const_tree_ptr() as *mut c_void, + p_const_pols: setup.get_const_ptr(), + p_const_tree: setup.get_const_tree_ptr(), custom_commits: air_instance.get_custom_commits_ptr(), custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; @@ -771,16 +769,16 @@ pub fn acc_mul_hint_fields( let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); let steps_params = StepsParams { - witness: air_instance.get_witness_ptr() as *mut c_void, - trace: air_instance.get_trace_ptr() as *mut c_void, - public_inputs: proof_ctx.get_publics_ptr() as *mut c_void, - challenges: proof_ctx.get_challenges_ptr() as *mut c_void, - airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, - airvalues: air_instance.get_airvalues_ptr() as *mut c_void, - evals: air_instance.get_evals_ptr() as *mut c_void, + witness: air_instance.get_witness_ptr(), + trace: air_instance.get_trace_ptr(), + public_inputs: proof_ctx.get_publics_ptr(), + challenges: proof_ctx.get_challenges_ptr(), + airgroup_values: air_instance.get_airgroup_values_ptr(), + airvalues: air_instance.get_airvalues_ptr(), + evals: air_instance.get_evals_ptr(), xdivxsub: std::ptr::null_mut(), - p_const_pols: setup.get_const_ptr() as *mut c_void, - p_const_tree: setup.get_const_tree_ptr() as *mut c_void, + p_const_pols: setup.get_const_ptr(), + p_const_tree: setup.get_const_tree_ptr(), custom_commits: air_instance.get_custom_commits_ptr(), custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; @@ -816,16 +814,16 @@ pub fn get_hint_field( let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); let steps_params = StepsParams { - witness: air_instance.get_witness_ptr() as *mut c_void, - trace: air_instance.get_trace_ptr() as *mut c_void, - public_inputs: proof_ctx.get_publics_ptr() as *mut c_void, - challenges: proof_ctx.get_challenges_ptr() as *mut c_void, - airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, - airvalues: air_instance.get_airvalues_ptr() as *mut c_void, - evals: air_instance.get_evals_ptr() as *mut c_void, + witness: air_instance.get_witness_ptr(), + trace: air_instance.get_trace_ptr(), + public_inputs: proof_ctx.get_publics_ptr(), + challenges: proof_ctx.get_challenges_ptr(), + airgroup_values: air_instance.get_airgroup_values_ptr(), + airvalues: air_instance.get_airvalues_ptr(), + evals: air_instance.get_evals_ptr(), xdivxsub: std::ptr::null_mut(), - p_const_pols: setup.get_const_ptr() as *mut c_void, - p_const_tree: setup.get_const_tree_ptr() as *mut c_void, + p_const_pols: setup.get_const_ptr(), + p_const_tree: setup.get_const_tree_ptr(), custom_commits: air_instance.get_custom_commits_ptr(), custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; @@ -864,16 +862,16 @@ pub fn get_hint_field_a( let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); let steps_params = StepsParams { - witness: air_instance.get_witness_ptr() as *mut c_void, - trace: air_instance.get_trace_ptr() as *mut c_void, - public_inputs: proof_ctx.get_publics_ptr() as *mut c_void, - challenges: proof_ctx.get_challenges_ptr() as *mut c_void, - airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, - airvalues: air_instance.get_airvalues_ptr() as *mut c_void, - evals: air_instance.get_evals_ptr() as *mut c_void, + witness: air_instance.get_witness_ptr(), + trace: air_instance.get_trace_ptr(), + public_inputs: proof_ctx.get_publics_ptr(), + challenges: proof_ctx.get_challenges_ptr(), + airgroup_values: air_instance.get_airgroup_values_ptr(), + airvalues: air_instance.get_airvalues_ptr(), + evals: air_instance.get_evals_ptr(), xdivxsub: std::ptr::null_mut(), - p_const_pols: setup.get_const_ptr() as *mut c_void, - p_const_tree: setup.get_const_tree_ptr() as *mut c_void, + p_const_pols: setup.get_const_ptr(), + p_const_tree: setup.get_const_tree_ptr(), custom_commits: air_instance.get_custom_commits_ptr(), custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; @@ -918,16 +916,16 @@ pub fn get_hint_field_m( let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); let steps_params = StepsParams { - witness: air_instance.get_witness_ptr() as *mut c_void, - trace: air_instance.get_trace_ptr() as *mut c_void, - public_inputs: proof_ctx.get_publics_ptr() as *mut c_void, - challenges: proof_ctx.get_challenges_ptr() as *mut c_void, - airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, - airvalues: air_instance.get_airvalues_ptr() as *mut c_void, - evals: air_instance.get_evals_ptr() as *mut c_void, + witness: air_instance.get_witness_ptr(), + trace: air_instance.get_trace_ptr(), + public_inputs: proof_ctx.get_publics_ptr(), + challenges: proof_ctx.get_challenges_ptr(), + airgroup_values: air_instance.get_airgroup_values_ptr(), + airvalues: air_instance.get_airvalues_ptr(), + evals: air_instance.get_evals_ptr(), xdivxsub: std::ptr::null_mut(), - p_const_pols: setup.get_const_ptr() as *mut c_void, - p_const_tree: setup.get_const_tree_ptr() as *mut c_void, + p_const_pols: setup.get_const_ptr(), + p_const_tree: setup.get_const_tree_ptr(), custom_commits: air_instance.get_custom_commits_ptr(), custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; @@ -1105,8 +1103,8 @@ pub fn set_hint_field( values: &HintFieldValue, ) { let steps_params = StepsParams { - witness: air_instance.get_witness_ptr() as *mut c_void, - trace: air_instance.get_trace_ptr() as *mut c_void, + witness: air_instance.get_witness_ptr(), + trace: air_instance.get_trace_ptr(), public_inputs: std::ptr::null_mut(), challenges: std::ptr::null_mut(), airgroup_values: std::ptr::null_mut(), @@ -1121,9 +1119,9 @@ pub fn set_hint_field( let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); - let values_ptr: *mut c_void = match values { - HintFieldValue::Column(vec) => vec.as_ptr() as *mut c_void, - HintFieldValue::ColumnExtended(vec) => vec.as_ptr() as *mut c_void, + let values_ptr: *mut u8 = match values { + HintFieldValue::Column(vec) => vec.as_ptr() as *mut u8, + HintFieldValue::ColumnExtended(vec) => vec.as_ptr() as *mut u8, _ => panic!("Only column and column extended are accepted"), }; @@ -1142,8 +1140,8 @@ pub fn set_hint_field_val( trace: std::ptr::null_mut(), public_inputs: std::ptr::null_mut(), challenges: std::ptr::null_mut(), - airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, - airvalues: air_instance.get_airvalues_ptr() as *mut c_void, + airgroup_values: air_instance.get_airgroup_values_ptr(), + airvalues: air_instance.get_airvalues_ptr(), evals: std::ptr::null_mut(), xdivxsub: std::ptr::null_mut(), p_const_pols: std::ptr::null_mut(), @@ -1167,7 +1165,7 @@ pub fn set_hint_field_val( } }; - let values_ptr = value_array.as_ptr() as *mut c_void; + let values_ptr = value_array.as_ptr() as *mut u8; set_hint_field_c((&setup.p_setup).into(), (&steps_params).into(), values_ptr, hint_id, hint_field_name); } diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index 180f961c..1ac01b92 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -482,7 +482,7 @@ impl ProofMan { verify_constraints: bool, ) { if stage == 1 { - transcript.add_elements(pctx.get_publics_ptr() as *mut c_void, pctx.global_info.n_publics); + transcript.add_elements(pctx.get_publics_ptr(), pctx.global_info.n_publics); } let dctx = ectx.dctx.read().unwrap(); @@ -504,7 +504,7 @@ impl ProofMan { for group_idxs in dctx.my_groups.iter() { if verify_constraints { let dummy_elements = [F::zero(), F::one(), F::two(), F::neg_one()]; - transcript.add_elements(dummy_elements.as_ptr() as *mut c_void, 4); + transcript.add_elements(dummy_elements.as_ptr() as *mut u8, 4); } else { let mut values = Vec::new(); for idx in group_idxs.iter() { @@ -518,7 +518,7 @@ impl ProofMan { } if !values.is_empty() { let value = Self::hash_b_tree(&*provers[0], values); - transcript.add_elements(value.as_ptr() as *mut c_void, value.len()); + transcript.add_elements(value.as_ptr() as *mut u8, value.len()); } } } @@ -633,9 +633,9 @@ impl ProofMan { let global_info_path = proof_ctx.global_info.get_proving_key_path().join("pilout.globalInfo.json"); let global_info_file: &str = global_info_path.to_str().unwrap(); - save_publics_c(n_publics, proof_ctx.get_publics_ptr() as *mut c_void, output_dir); + save_publics_c(n_publics, proof_ctx.get_publics_ptr(), output_dir); - save_proof_values_c(n_proof_values, proof_ctx.get_proof_values_ptr() as *mut c_void, output_dir); + save_proof_values_c(n_proof_values, proof_ctx.get_proof_values_ptr(), output_dir); save_challenges_c(proof_ctx.get_challenges_ptr(), global_info_file, output_dir); diff --git a/provers/stark/src/stark_prover.rs b/provers/stark/src/stark_prover.rs index 899a33db..619d2143 100644 --- a/provers/stark/src/stark_prover.rs +++ b/provers/stark/src/stark_prover.rs @@ -53,9 +53,7 @@ impl StarkProver { pub fn new(sctx: Arc, airgroup_id: usize, air_id: usize, instance_id: usize, prover_idx: usize) -> Self { let setup = sctx.get_setup(airgroup_id, air_id); - let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; - - let p_stark = starks_new_c((&setup.p_setup).into(), const_tree_ptr); + let p_stark = starks_new_c((&setup.p_setup).into(), setup.get_const_tree_ptr()); let stark_info = setup.stark_info.clone(); @@ -126,15 +124,15 @@ impl Prover for StarkProver { let setup = setup_ctx.get_setup(self.airgroup_id, self.air_id); let steps_params = StepsParams { - witness: air_instance.get_witness_ptr() as *mut c_void, - trace: air_instance.get_trace_ptr() as *mut c_void, - public_inputs: proof_ctx.get_publics_ptr() as *mut c_void, - challenges: proof_ctx.get_challenges_ptr() as *mut c_void, - airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, - airvalues: air_instance.get_airvalues_ptr() as *mut c_void, - evals: air_instance.get_evals_ptr() as *mut c_void, + witness: air_instance.get_witness_ptr(), + trace: air_instance.get_trace_ptr(), + public_inputs: proof_ctx.get_publics_ptr(), + challenges: proof_ctx.get_challenges_ptr(), + airgroup_values: air_instance.get_airgroup_values_ptr(), + airvalues: air_instance.get_airvalues_ptr(), + evals: air_instance.get_evals_ptr(), xdivxsub: std::ptr::null_mut(), - p_const_pols: setup.get_const_ptr() as *mut c_void, + p_const_pols: setup.get_const_ptr(), p_const_tree: std::ptr::null_mut(), custom_commits: air_instance.get_custom_commits_ptr(), custom_commits_extended: [std::ptr::null_mut(); 10], @@ -155,16 +153,16 @@ impl Prover for StarkProver { let setup = setup_ctx.get_setup(self.airgroup_id, self.air_id); let steps_params = StepsParams { - witness: air_instance.get_witness_ptr() as *mut c_void, - trace: air_instance.get_trace_ptr() as *mut c_void, - public_inputs: proof_ctx.get_publics_ptr() as *mut c_void, - challenges: proof_ctx.get_challenges_ptr() as *mut c_void, - airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, - airvalues: air_instance.get_airvalues_ptr() as *mut c_void, - evals: air_instance.get_evals_ptr() as *mut c_void, + witness: air_instance.get_witness_ptr(), + trace: air_instance.get_trace_ptr(), + public_inputs: proof_ctx.get_publics_ptr(), + challenges: proof_ctx.get_challenges_ptr(), + airgroup_values: air_instance.get_airgroup_values_ptr(), + airvalues: air_instance.get_airvalues_ptr(), + evals: air_instance.get_evals_ptr(), xdivxsub: std::ptr::null_mut(), - p_const_pols: setup.get_const_ptr() as *mut c_void, - p_const_tree: setup.get_const_tree_ptr() as *mut c_void, + p_const_pols: setup.get_const_ptr(), + p_const_tree: setup.get_const_tree_ptr(), custom_commits: air_instance.get_custom_commits_ptr(), custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; @@ -225,11 +223,10 @@ impl Prover for StarkProver { timer_start_trace!(STARK_COMMIT_STAGE_, stage_id); let witness = match stage_id == 1 { - true => air_instance.get_witness_ptr() as *mut c_void, + true => air_instance.get_witness_ptr(), false => std::ptr::null_mut(), }; - let trace = air_instance.get_trace_ptr() as *mut c_void; let element_type = if type_name::() == type_name::() { 1 } else { 0 }; commit_stage_c( @@ -237,9 +234,9 @@ impl Prover for StarkProver { element_type, stage_id as u64, witness, - trace, + air_instance.get_trace_ptr(), p_proof, - proof_ctx.get_buff_helper_ptr() as *mut c_void, + proof_ctx.get_buff_helper_ptr(), ); timer_stop_and_log_trace!(STARK_COMMIT_STAGE_, stage_id); @@ -258,10 +255,10 @@ impl Prover for StarkProver { p_stark, commit_id as u64, stage_id as u64, - air_instance.custom_commits[commit_id].buffer.as_ptr() as *mut c_void, - air_instance.custom_commits_extended[commit_id].buffer.as_ptr() as *mut c_void, + air_instance.custom_commits[commit_id].buffer.as_ptr() as *mut u8, + air_instance.custom_commits_extended[commit_id].buffer.as_ptr() as *mut u8, p_proof, - proof_ctx.get_buff_helper_ptr() as *mut c_void, + proof_ctx.get_buff_helper_ptr(), "", ); } else { @@ -269,8 +266,8 @@ impl Prover for StarkProver { p_stark, commit_id as u64, stage_id as u64, - air_instance.custom_commits[commit_id].buffer.as_ptr() as *mut c_void, - air_instance.custom_commits_extended[commit_id].buffer.as_ptr() as *mut c_void, + air_instance.custom_commits[commit_id].buffer.as_ptr() as *mut u8, + air_instance.custom_commits_extended[commit_id].buffer.as_ptr() as *mut u8, p_proof, air_instance.custom_commits[commit_id].cached_file.to_str().unwrap(), ); @@ -281,7 +278,7 @@ impl Prover for StarkProver { treesGL_get_root_c( p_stark, (self.stark_info.n_stages + 2 + commit_id as u32) as u64, - value.as_mut_ptr() as *mut c_void, + value.as_mut_ptr() as *mut u8, ); if !self.stark_info.custom_commits[commit_id].public_values.is_empty() { assert!( @@ -354,7 +351,7 @@ impl Prover for StarkProver { } let xi_challenge = &(*challenges_guard)[xi_challenge_index * Self::FIELD_EXTENSION] as *const F as *mut c_void; - calculate_xdivxsub_c(self.p_stark, xi_challenge, proof_ctx.get_buff_helper_ptr() as *mut c_void); + calculate_xdivxsub_c(self.p_stark, xi_challenge, proof_ctx.get_buff_helper_ptr()); } fn calculate_lev(&mut self, proof_ctx: Arc>) { @@ -371,7 +368,7 @@ impl Prover for StarkProver { } let xi_challenge = &(*challenges_guard)[xi_challenge_index * Self::FIELD_EXTENSION] as *const F as *mut c_void; - compute_lev_c(self.p_stark, xi_challenge, proof_ctx.get_buff_helper_ptr() as *mut c_void); + compute_lev_c(self.p_stark, xi_challenge, proof_ctx.get_buff_helper_ptr()); } fn get_buff_helper_size(&self) -> usize { @@ -396,12 +393,7 @@ impl Prover for StarkProver { fn calculate_hash(&self, values: Vec) -> Vec { let hash = vec![F::zero(); self.n_field_elements]; - calculate_hash_c( - self.p_stark, - hash.as_ptr() as *mut c_void, - values.as_ptr() as *mut c_void, - values.len() as u64, - ); + calculate_hash_c(self.p_stark, hash.as_ptr() as *mut u8, values.as_ptr() as *mut u8, values.len() as u64); hash } @@ -465,7 +457,7 @@ impl Prover for StarkProver { } let mut root = vec![F::zero(); self.n_field_elements]; - treesGL_get_root_c(p_stark, stage - 1, root.as_mut_ptr() as *mut c_void); + treesGL_get_root_c(p_stark, stage - 1, root.as_mut_ptr() as *mut u8); trace!( "{}: ··· MerkleTree root for stage {} of instance {} of {} is: {:?}", Self::MY_NAME, @@ -495,20 +487,19 @@ impl Prover for StarkProver { calculate_hash_c( p_stark, - value.as_mut_ptr() as *mut c_void, - values_hash.as_mut_ptr() as *mut c_void, + value.as_mut_ptr() as *mut u8, + values_hash.as_mut_ptr() as *mut u8, size as u64, ); } else { - treesGL_get_root_c(p_stark, stage - 1, value.as_mut_ptr() as *mut c_void); + treesGL_get_root_c(p_stark, stage - 1, value.as_mut_ptr() as *mut u8); } } else if stage == (Self::num_stages(self) + 2) as u64 { let air_instance = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap()[self.prover_idx]; - let evals = air_instance.get_evals_ptr() as *mut c_void; calculate_hash_c( p_stark, - value.as_mut_ptr() as *mut c_void, - evals, + value.as_mut_ptr() as *mut u8, + air_instance.get_evals_ptr(), (self.stark_info.ev_map.len() * Self::FIELD_EXTENSION) as u64, ); } else if stage > (Self::num_stages(self) + 3) as u64 { @@ -524,12 +515,12 @@ impl Prover for StarkProver { let n_steps = steps.len() - 1; if step_index < n_steps { let p_proof = self.p_proof; - fri_proof_get_tree_root_c(p_proof, value.as_mut_ptr() as *mut c_void, step_index as u64); + fri_proof_get_tree_root_c(p_proof, value.as_mut_ptr() as *mut u8, step_index as u64); } else { let air_instance = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap()[self.prover_idx]; let n_hash = (1 << (steps[n_steps].n_bits)) * Self::FIELD_EXTENSION as u64; let fri_pol = get_fri_pol_c(self.p_stark_info, air_instance.get_trace_ptr()); - calculate_hash_c(p_stark, value.as_mut_ptr() as *mut c_void, fri_pol, n_hash); + calculate_hash_c(p_stark, value.as_mut_ptr() as *mut u8, fri_pol as *mut u8, n_hash); } } } @@ -593,8 +584,8 @@ impl Prover for StarkProver { fri_proof_get_zkinproof_c( gidx as u64, self.p_proof, - proof_ctx.get_publics_ptr() as *mut c_void, - proof_ctx.get_challenges_ptr() as *mut c_void, + proof_ctx.get_publics_ptr(), + proof_ctx.get_challenges_ptr(), self.p_stark_info, global_info_file, output_dir, @@ -646,24 +637,22 @@ impl StarkProver { let p_stark = self.p_stark; let p_proof = self.p_proof; - let const_tree_ptr = (*setup.const_tree.values.read().unwrap()).as_ptr() as *mut c_void; - let steps_params = StepsParams { witness: std::ptr::null_mut(), - trace: air_instance.get_trace_ptr() as *mut c_void, + trace: air_instance.get_trace_ptr(), public_inputs: std::ptr::null_mut(), challenges: std::ptr::null_mut(), airgroup_values: std::ptr::null_mut(), airvalues: std::ptr::null_mut(), - evals: air_instance.get_evals_ptr() as *mut c_void, + evals: air_instance.get_evals_ptr(), xdivxsub: std::ptr::null_mut(), p_const_pols: std::ptr::null_mut(), - p_const_tree: const_tree_ptr, + p_const_tree: setup.get_const_tree_ptr(), custom_commits: air_instance.get_custom_commits_ptr(), custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; - compute_evals_c(p_stark, (&steps_params).into(), proof_ctx.get_buff_helper_ptr() as *mut c_void, p_proof); + compute_evals_c(p_stark, (&steps_params).into(), proof_ctx.get_buff_helper_ptr(), p_proof); } fn compute_fri_pol(&mut self, _opening_id: u32, setup_ctx: Arc, proof_ctx: Arc>) { @@ -677,15 +666,15 @@ impl StarkProver { let steps_params = StepsParams { witness: std::ptr::null_mut(), - trace: air_instance.get_trace_ptr() as *mut c_void, - public_inputs: proof_ctx.get_publics_ptr() as *mut c_void, - challenges: proof_ctx.get_challenges_ptr() as *mut c_void, - airgroup_values: air_instance.get_airgroup_values_ptr() as *mut c_void, - airvalues: air_instance.get_airvalues_ptr() as *mut c_void, - evals: air_instance.get_evals_ptr() as *mut c_void, - xdivxsub: proof_ctx.get_buff_helper_ptr() as *mut c_void, - p_const_pols: setup.get_const_ptr() as *mut c_void, - p_const_tree: setup.get_const_tree_ptr() as *mut c_void, + trace: air_instance.get_trace_ptr(), + public_inputs: proof_ctx.get_publics_ptr(), + challenges: proof_ctx.get_challenges_ptr(), + airgroup_values: air_instance.get_airgroup_values_ptr(), + airvalues: air_instance.get_airvalues_ptr(), + evals: air_instance.get_evals_ptr(), + xdivxsub: proof_ctx.get_buff_helper_ptr(), + p_const_pols: setup.get_const_ptr(), + p_const_tree: setup.get_const_tree_ptr(), custom_commits: air_instance.get_custom_commits_ptr(), custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; @@ -762,7 +751,7 @@ impl StarkProver { let transcript_permutation = FFITranscript::new(p_stark, element_type, self.merkle_tree_arity, self.merkle_tree_custom); - transcript_permutation.add_elements(challenge.as_ptr() as *mut c_void, Self::FIELD_EXTENSION); + transcript_permutation.add_elements(challenge.as_ptr() as *mut u8, Self::FIELD_EXTENSION); transcript_permutation.get_permutations( fri_queries.as_mut_ptr(), n_queries, diff --git a/provers/starks-lib-c/src/ffi_starks.rs b/provers/starks-lib-c/src/ffi_starks.rs index 65c14d67..2b2d8b78 100644 --- a/provers/starks-lib-c/src/ffi_starks.rs +++ b/provers/starks-lib-c/src/ffi_starks.rs @@ -33,18 +33,26 @@ pub fn save_challenges_c(p_challenges: *mut u8, global_info_file: &str, output_d } #[cfg(not(feature = "no_lib_link"))] -pub fn save_publics_c(n_publics: u64, public_inputs: *mut std::os::raw::c_void, output_dir: &str) { +pub fn save_publics_c(n_publics: u64, public_inputs: *mut u8, output_dir: &str) { let file_dir: CString = CString::new(output_dir).unwrap(); unsafe { - save_publics(n_publics, public_inputs, file_dir.as_ptr() as *mut std::os::raw::c_char); + save_publics( + n_publics, + public_inputs as *mut std::os::raw::c_void, + file_dir.as_ptr() as *mut std::os::raw::c_char, + ); } } #[cfg(not(feature = "no_lib_link"))] -pub fn save_proof_values_c(n_proof_values: u64, proof_values: *mut std::os::raw::c_void, output_dir: &str) { +pub fn save_proof_values_c(n_proof_values: u64, proof_values: *mut u8, output_dir: &str) { let file_dir: CString = CString::new(output_dir).unwrap(); unsafe { - save_proof_values(n_proof_values, proof_values, file_dir.as_ptr() as *mut std::os::raw::c_char); + save_proof_values( + n_proof_values, + proof_values as *mut std::os::raw::c_void, + file_dir.as_ptr() as *mut std::os::raw::c_char, + ); } } @@ -54,28 +62,28 @@ pub fn fri_proof_new_c(p_setup_ctx: *mut c_void) -> *mut c_void { } #[cfg(not(feature = "no_lib_link"))] -pub fn fri_proof_get_tree_root_c(p_fri_proof: *mut c_void, root: *mut c_void, tree_index: u64) { +pub fn fri_proof_get_tree_root_c(p_fri_proof: *mut c_void, root: *mut u8, tree_index: u64) { unsafe { - fri_proof_get_tree_root(p_fri_proof, root, tree_index); + fri_proof_get_tree_root(p_fri_proof, root as *mut std::os::raw::c_void, tree_index); } } #[cfg(not(feature = "no_lib_link"))] -pub fn fri_proof_set_airgroup_values_c(p_fri_proof: *mut c_void, p_airgroup_values: *mut c_void) { - unsafe { fri_proof_set_airgroupvalues(p_fri_proof, p_airgroup_values) } +pub fn fri_proof_set_airgroup_values_c(p_fri_proof: *mut c_void, p_airgroup_values: *mut u8) { + unsafe { fri_proof_set_airgroupvalues(p_fri_proof, p_airgroup_values as *mut std::os::raw::c_void) } } #[cfg(not(feature = "no_lib_link"))] -pub fn fri_proof_set_air_values_c(p_fri_proof: *mut c_void, p_air_values: *mut c_void) { - unsafe { fri_proof_set_airvalues(p_fri_proof, p_air_values) } +pub fn fri_proof_set_air_values_c(p_fri_proof: *mut c_void, p_air_values: *mut u8) { + unsafe { fri_proof_set_airvalues(p_fri_proof, p_air_values as *mut std::os::raw::c_void) } } #[cfg(not(feature = "no_lib_link"))] pub fn fri_proof_get_zkinproof_c( proof_id: u64, p_fri_proof: *mut c_void, - p_publics: *mut c_void, - p_challenges: *mut c_void, + p_publics: *mut u8, + p_challenges: *mut u8, p_stark_info: *mut c_void, global_info_file: &str, output_dir_file: &str, @@ -90,8 +98,8 @@ pub fn fri_proof_get_zkinproof_c( fri_proof_get_zkinproof( proof_id, p_fri_proof, - p_publics, - p_challenges, + p_publics as *mut std::os::raw::c_void, + p_challenges as *mut std::os::raw::c_void, p_stark_info, global_info_file_ptr, file_ptr, @@ -147,11 +155,15 @@ pub fn prover_helpers_free_c(p_prover_helpers: *mut c_void) { } #[cfg(not(feature = "no_lib_link"))] -pub fn load_const_pols_c(pConstPolsAddress: *mut c_void, const_filename: &str, const_size: u64) { +pub fn load_const_pols_c(pConstPolsAddress: *mut u8, const_filename: &str, const_size: u64) { unsafe { let const_filename: CString = CString::new(const_filename).unwrap(); - load_const_pols(pConstPolsAddress, const_filename.as_ptr() as *mut std::os::raw::c_char, const_size); + load_const_pols( + pConstPolsAddress as *mut std::os::raw::c_void, + const_filename.as_ptr() as *mut std::os::raw::c_char, + const_size, + ); } } @@ -166,19 +178,23 @@ pub fn get_const_tree_size_c(pStarkInfo: *mut c_void) -> u64 { } #[cfg(not(feature = "no_lib_link"))] -pub fn load_const_tree_c(pConstPolsTreeAddress: *mut c_void, tree_filename: &str, const_tree_size: u64) { +pub fn load_const_tree_c(pConstPolsTreeAddress: *mut u8, tree_filename: &str, const_tree_size: u64) { unsafe { let tree_filename: CString = CString::new(tree_filename).unwrap(); - load_const_tree(pConstPolsTreeAddress, tree_filename.as_ptr() as *mut std::os::raw::c_char, const_tree_size); + load_const_tree( + pConstPolsTreeAddress as *mut std::os::raw::c_void, + tree_filename.as_ptr() as *mut std::os::raw::c_char, + const_tree_size, + ); } } #[cfg(not(feature = "no_lib_link"))] pub fn calculate_const_tree_c( pStarkInfo: *mut c_void, - pConstPols: *mut c_void, - pConstPolsTreeAddress: *mut c_void, + pConstPols: *mut u8, + pConstPolsTreeAddress: *mut u8, tree_filename: &str, ) { unsafe { @@ -186,8 +202,8 @@ pub fn calculate_const_tree_c( calculate_const_tree( pStarkInfo, - pConstPols, - pConstPolsTreeAddress, + pConstPols as *mut std::os::raw::c_void, + pConstPolsTreeAddress as *mut std::os::raw::c_void, tree_filename.as_ptr() as *mut std::os::raw::c_char, ); } @@ -218,19 +234,19 @@ pub fn get_hint_ids_by_name_c(p_expressions_bin: *mut c_void, hint_name: &str) - #[cfg(not(feature = "no_lib_link"))] pub fn get_hint_field_c( p_setup_ctx: *mut c_void, - p_steps_params: *mut c_void, + p_steps_params: *mut u8, hint_id: u64, hint_field_name: &str, - hint_options: *mut c_void, + hint_options: *mut u8, ) -> *mut c_void { let field_name = CString::new(hint_field_name).unwrap(); unsafe { get_hint_field( p_setup_ctx, - p_steps_params, + p_steps_params as *mut std::os::raw::c_void, hint_id, field_name.as_ptr() as *mut std::os::raw::c_char, - hint_options, + hint_options as *mut std::os::raw::c_void, ) } } @@ -239,13 +255,13 @@ pub fn get_hint_field_c( #[allow(clippy::too_many_arguments)] pub fn mul_hint_fields_c( p_setup_ctx: *mut c_void, - p_steps_params: *mut c_void, + p_steps_params: *mut u8, hint_id: u64, hint_field_dest: &str, hint_field_name1: &str, hint_field_name2: &str, - hint_options1: *mut c_void, - hint_options2: *mut c_void, + hint_options1: *mut u8, + hint_options2: *mut u8, ) -> u64 { let field_dest = CString::new(hint_field_dest).unwrap(); let field_name1 = CString::new(hint_field_name1).unwrap(); @@ -254,13 +270,13 @@ pub fn mul_hint_fields_c( unsafe { mul_hint_fields( p_setup_ctx, - p_steps_params, + p_steps_params as *mut std::os::raw::c_void, hint_id, field_dest.as_ptr() as *mut std::os::raw::c_char, field_name1.as_ptr() as *mut std::os::raw::c_char, field_name2.as_ptr() as *mut std::os::raw::c_char, - hint_options1, - hint_options2, + hint_options1 as *mut std::os::raw::c_void, + hint_options2 as *mut std::os::raw::c_void, ) } } @@ -268,7 +284,7 @@ pub fn mul_hint_fields_c( #[cfg(not(feature = "no_lib_link"))] pub fn acc_hint_field_c( p_setup_ctx: *mut c_void, - p_steps_params: *mut c_void, + p_steps_params: *mut u8, hint_id: u64, hint_field_dest: &str, hint_field_airgroupvalue: &str, @@ -282,7 +298,7 @@ pub fn acc_hint_field_c( unsafe { acc_hint_field( p_setup_ctx, - p_steps_params, + p_steps_params as *mut std::os::raw::c_void, hint_id, field_dest.as_ptr() as *mut std::os::raw::c_char, field_airgroupvalue.as_ptr() as *mut std::os::raw::c_char, @@ -296,14 +312,14 @@ pub fn acc_hint_field_c( #[allow(clippy::too_many_arguments)] pub fn acc_mul_hint_fields_c( p_setup_ctx: *mut c_void, - p_steps_params: *mut c_void, + p_steps_params: *mut u8, hint_id: u64, hint_field_dest: &str, hint_field_airgroupvalue: &str, hint_field_name1: &str, hint_field_name2: &str, - hint_options1: *mut c_void, - hint_options2: *mut c_void, + hint_options1: *mut u8, + hint_options2: *mut u8, add: bool, ) -> *mut c_void { let field_dest = CString::new(hint_field_dest).unwrap(); @@ -314,14 +330,14 @@ pub fn acc_mul_hint_fields_c( unsafe { acc_mul_hint_fields( p_setup_ctx, - p_steps_params, + p_steps_params as *mut std::os::raw::c_void, hint_id, field_dest.as_ptr() as *mut std::os::raw::c_char, field_airgroupvalue.as_ptr() as *mut std::os::raw::c_char, field_name1.as_ptr() as *mut std::os::raw::c_char, field_name2.as_ptr() as *mut std::os::raw::c_char, - hint_options1, - hint_options2, + hint_options1 as *mut std::os::raw::c_void, + hint_options2 as *mut std::os::raw::c_void, add, ) } @@ -330,20 +346,26 @@ pub fn acc_mul_hint_fields_c( #[cfg(not(feature = "no_lib_link"))] pub fn set_hint_field_c( p_setup_ctx: *mut c_void, - p_params: *mut c_void, - values: *mut c_void, + p_params: *mut u8, + values: *mut u8, hint_id: u64, hint_field_name: &str, ) -> u64 { unsafe { let field_name = CString::new(hint_field_name).unwrap(); - set_hint_field(p_setup_ctx, p_params, values, hint_id, field_name.as_ptr() as *mut std::os::raw::c_char) + set_hint_field( + p_setup_ctx, + p_params as *mut std::os::raw::c_void, + values as *mut std::os::raw::c_void, + hint_id, + field_name.as_ptr() as *mut std::os::raw::c_char, + ) } } #[cfg(not(feature = "no_lib_link"))] -pub fn starks_new_c(p_setup_ctx: *mut c_void, p_const_tree: *mut c_void) -> *mut c_void { - unsafe { starks_new(p_setup_ctx, p_const_tree) } +pub fn starks_new_c(p_setup_ctx: *mut c_void, p_const_tree: *mut u8) -> *mut c_void { + unsafe { starks_new(p_setup_ctx, p_const_tree as *mut std::os::raw::c_void) } } #[cfg(not(feature = "no_lib_link"))] @@ -366,9 +388,9 @@ pub fn merkle_tree_free_c(merkle_tree: *mut c_void) { } #[cfg(not(feature = "no_lib_link"))] -pub fn treesGL_get_root_c(pStark: *mut c_void, index: u64, root: *mut c_void) { +pub fn treesGL_get_root_c(pStark: *mut c_void, index: u64, root: *mut u8) { unsafe { - treesGL_get_root(pStark, index, root); + treesGL_get_root(pStark, index, root as *mut std::os::raw::c_void); } } @@ -380,9 +402,9 @@ pub fn treesGL_set_root_c(pStark: *mut c_void, index: u64, pProof: *mut c_void) } #[cfg(not(feature = "no_lib_link"))] -pub fn calculate_xdivxsub_c(p_stark: *mut c_void, xi_challenge: *mut c_void, xdivxsub: *mut c_void) { +pub fn calculate_xdivxsub_c(p_stark: *mut c_void, xi_challenge: *mut c_void, xdivxsub: *mut u8) { unsafe { - calculate_xdivxsub(p_stark, xi_challenge, xdivxsub); + calculate_xdivxsub(p_stark, xi_challenge, xdivxsub as *mut std::os::raw::c_void); } } @@ -392,23 +414,23 @@ pub fn get_fri_pol_c(p_stark_info: *mut c_void, buffer: *mut u8) -> *mut c_void } #[cfg(not(feature = "no_lib_link"))] -pub fn calculate_fri_polynomial_c(p_starks: *mut c_void, p_steps_params: *mut c_void) { +pub fn calculate_fri_polynomial_c(p_starks: *mut c_void, p_steps_params: *mut u8) { unsafe { - calculate_fri_polynomial(p_starks, p_steps_params); + calculate_fri_polynomial(p_starks, p_steps_params as *mut std::os::raw::c_void); } } #[cfg(not(feature = "no_lib_link"))] -pub fn calculate_quotient_polynomial_c(p_starks: *mut c_void, p_steps_params: *mut c_void) { +pub fn calculate_quotient_polynomial_c(p_starks: *mut c_void, p_steps_params: *mut u8) { unsafe { - calculate_quotient_polynomial(p_starks, p_steps_params); + calculate_quotient_polynomial(p_starks, p_steps_params as *mut std::os::raw::c_void); } } #[cfg(not(feature = "no_lib_link"))] -pub fn calculate_impols_expressions_c(p_starks: *mut c_void, step: u64, p_steps_params: *mut c_void) { +pub fn calculate_impols_expressions_c(p_starks: *mut c_void, step: u64, p_steps_params: *mut u8) { unsafe { - calculate_impols_expressions(p_starks, step, p_steps_params); + calculate_impols_expressions(p_starks, step, p_steps_params as *mut std::os::raw::c_void); } } @@ -418,10 +440,10 @@ pub fn extend_and_merkelize_custom_commit_c( p_starks: *mut c_void, commit_id: u64, step: u64, - buffer: *mut c_void, - buffer_ext: *mut c_void, + buffer: *mut u8, + buffer_ext: *mut u8, p_proof: *mut c_void, - p_buff_helper: *mut c_void, + p_buff_helper: *mut u8, buffer_file: &str, ) { let buffer_file_name = CString::new(buffer_file).unwrap(); @@ -430,10 +452,10 @@ pub fn extend_and_merkelize_custom_commit_c( p_starks, commit_id, step, - buffer, - buffer_ext, + buffer as *mut std::os::raw::c_void, + buffer_ext as *mut std::os::raw::c_void, p_proof, - p_buff_helper, + p_buff_helper as *mut std::os::raw::c_void, buffer_file_name.as_ptr() as *mut std::os::raw::c_char, ); } @@ -444,8 +466,8 @@ pub fn load_custom_commit_c( p_starks: *mut c_void, commit_id: u64, step: u64, - buffer: *mut c_void, - buffer_ext: *mut c_void, + buffer: *mut u8, + buffer_ext: *mut u8, p_proof: *mut c_void, buffer_file: &str, ) { @@ -455,8 +477,8 @@ pub fn load_custom_commit_c( p_starks, commit_id, step, - buffer, - buffer_ext, + buffer as *mut std::os::raw::c_void, + buffer_ext as *mut std::os::raw::c_void, p_proof, buffer_file_name.as_ptr() as *mut std::os::raw::c_char, ); @@ -468,27 +490,35 @@ pub fn commit_stage_c( p_starks: *mut c_void, element_type: u32, step: u64, - witness: *mut c_void, - buffer: *mut c_void, + witness: *mut u8, + buffer: *mut u8, p_proof: *mut c_void, - p_buff_helper: *mut c_void, + p_buff_helper: *mut u8, ) { unsafe { - commit_stage(p_starks, element_type, step, witness, buffer, p_proof, p_buff_helper); + commit_stage( + p_starks, + element_type, + step, + witness as *mut std::os::raw::c_void, + buffer as *mut std::os::raw::c_void, + p_proof, + p_buff_helper as *mut std::os::raw::c_void, + ); } } #[cfg(not(feature = "no_lib_link"))] -pub fn compute_lev_c(p_stark: *mut c_void, xi_challenge: *mut c_void, lev: *mut c_void) { +pub fn compute_lev_c(p_stark: *mut c_void, xi_challenge: *mut c_void, lev: *mut u8) { unsafe { - compute_lev(p_stark, xi_challenge, lev); + compute_lev(p_stark, xi_challenge, lev as *mut std::os::raw::c_void); } } #[cfg(not(feature = "no_lib_link"))] -pub fn compute_evals_c(p_stark: *mut c_void, params: *mut c_void, lev: *mut c_void, pProof: *mut c_void) { +pub fn compute_evals_c(p_stark: *mut c_void, params: *mut u8, lev: *mut u8, pProof: *mut c_void) { unsafe { - compute_evals(p_stark, params, lev, pProof); + compute_evals(p_stark, params as *mut std::os::raw::c_void, lev as *mut std::os::raw::c_void, pProof); } } @@ -562,9 +592,9 @@ pub fn set_fri_final_pol_c(p_proof: *mut c_void, buffer: *mut u8, n_bits: u64) { } #[cfg(not(feature = "no_lib_link"))] -pub fn calculate_hash_c(pStarks: *mut c_void, pHhash: *mut c_void, pBuffer: *mut c_void, nElements: u64) { +pub fn calculate_hash_c(pStarks: *mut c_void, pHhash: *mut u8, pBuffer: *mut u8, nElements: u64) { unsafe { - calculate_hash(pStarks, pHhash, pBuffer, nElements); + calculate_hash(pStarks, pHhash as *mut std::os::raw::c_void, pBuffer as *mut std::os::raw::c_void, nElements); } } @@ -574,9 +604,9 @@ pub fn transcript_new_c(element_type: u32, arity: u64, custom: bool) -> *mut c_v } #[cfg(not(feature = "no_lib_link"))] -pub fn transcript_add_c(p_transcript: *mut c_void, p_input: *mut c_void, size: u64) { +pub fn transcript_add_c(p_transcript: *mut c_void, p_input: *mut u8, size: u64) { unsafe { - transcript_add(p_transcript, p_input, size); + transcript_add(p_transcript, p_input as *mut std::os::raw::c_void, size); } } @@ -609,8 +639,8 @@ pub fn get_permutations_c(p_transcript: *mut c_void, res: *mut u64, n: u64, n_bi } #[cfg(not(feature = "no_lib_link"))] -pub fn verify_constraints_c(p_setup: *mut c_void, p_steps_params: *mut c_void) -> *mut c_void { - unsafe { verify_constraints(p_setup, p_steps_params) } +pub fn verify_constraints_c(p_setup: *mut c_void, p_steps_params: *mut u8) -> *mut c_void { + unsafe { verify_constraints(p_setup, p_steps_params as *mut std::os::raw::c_void) } } #[cfg(not(feature = "no_lib_link"))] @@ -875,12 +905,12 @@ pub fn save_challenges_c(_p_challenges: *mut u8, _global_info_file: &str, _outpu } #[cfg(feature = "no_lib_link")] -pub fn save_publics_c(_n_publics: u64, _public_inputs: *mut c_void, _output_dir: &str) { +pub fn save_publics_c(_n_publics: u64, _public_inputs: *mut u8, _output_dir: &str) { trace!("{}: ··· {}", "ffi ", "save_publics: This is a mock call because there is no linked library"); } #[cfg(feature = "no_lib_link")] -pub fn save_proof_values_c(_n_proof_values: u64, _proof_values: *mut c_void, _output_dir: &str) { +pub fn save_proof_values_c(_n_proof_values: u64, _proof_values: *mut u8, _output_dir: &str) { trace!("{}: ··· {}", "ffi ", "save_proof_values: This is a mock call because there is no linked library"); } @@ -891,13 +921,13 @@ pub fn fri_proof_new_c(_p_setup_ctx: *mut c_void) -> *mut c_void { } #[cfg(feature = "no_lib_link")] -pub fn fri_proof_get_tree_root_c(_p_fri_proof: *mut c_void, _root: *mut c_void, _tree_index: u64) -> *mut c_void { +pub fn fri_proof_get_tree_root_c(_p_fri_proof: *mut c_void, _root: *mut u8, _tree_index: u64) -> *mut c_void { trace!("{}: ··· {}", "ffi ", "fri_proof_get_tree_root: This is a mock call because there is no linked library"); std::ptr::null_mut() } #[cfg(feature = "no_lib_link")] -pub fn fri_proof_set_airgroup_values_c(_p_fri_proof: *mut c_void, _p_params: *mut c_void) { +pub fn fri_proof_set_airgroup_values_c(_p_fri_proof: *mut c_void, _p_params: *mut u8) { trace!( "{}: ··· {}", "ffi ", @@ -906,7 +936,7 @@ pub fn fri_proof_set_airgroup_values_c(_p_fri_proof: *mut c_void, _p_params: *mu } #[cfg(feature = "no_lib_link")] -pub fn fri_proof_set_air_values_c(_p_fri_proof: *mut c_void, _p_params: *mut c_void) { +pub fn fri_proof_set_air_values_c(_p_fri_proof: *mut c_void, _p_params: *mut u8) { trace!( "{}: ··· {}", "ffi ", @@ -918,8 +948,8 @@ pub fn fri_proof_set_air_values_c(_p_fri_proof: *mut c_void, _p_params: *mut c_v pub fn fri_proof_get_zkinproof_c( _proof_id: u64, _p_fri_proof: *mut c_void, - _p_publics: *mut c_void, - _p_challenges: *mut c_void, + _p_publics: *mut u8, + _p_challenges: *mut u8, _p_stark_info: *mut c_void, _global_info_file: &str, _output_dir_file: &str, @@ -975,7 +1005,7 @@ pub fn prover_helpers_new_c(_p_stark_info: *mut c_void) -> *mut c_void { pub fn prover_helpers_free_c(_p_prover_helpers: *mut c_void) {} #[cfg(feature = "no_lib_link")] -pub fn load_const_pols_c(_pConstPolsAddress: *mut c_void, _const_filename: &str, _const_size: u64) { +pub fn load_const_pols_c(_pConstPolsAddress: *mut u8, _const_filename: &str, _const_size: u64) { trace!("{}: ··· {}", "ffi ", "load_const_pols: This is a mock call because there is no linked library"); } @@ -992,15 +1022,15 @@ pub fn get_const_size_c(_pStarkInfo: *mut c_void) -> u64 { } #[cfg(feature = "no_lib_link")] -pub fn load_const_tree_c(_pConstPolsTreeAddress: *mut c_void, _tree_filename: &str, _const_tree_size: u64) { +pub fn load_const_tree_c(_pConstPolsTreeAddress: *mut u8, _tree_filename: &str, _const_tree_size: u64) { trace!("{}: ··· {}", "ffi ", "load_const_tree: This is a mock call because there is no linked library"); } #[cfg(feature = "no_lib_link")] pub fn calculate_const_tree_c( _pStarkInfo: *mut c_void, - _pConstPols: *mut c_void, - _pConstPolsTreeAddress: *mut c_void, + _pConstPols: *mut u8, + _pConstPolsTreeAddress: *mut u8, _tree_filename: &str, ) { trace!("{}: ··· {}", "ffi ", "calculate_const_tree: This is a mock call because there is no linked library"); @@ -1023,10 +1053,10 @@ pub fn get_hint_ids_by_name_c(_p_expressions_bin: *mut c_void, _hint_name: &str) #[cfg(feature = "no_lib_link")] pub fn get_hint_field_c( _p_setup_ctx: *mut c_void, - _p_steps_params: *mut c_void, + _p_steps_params: *mut u8, _hint_id: u64, _hint_field_name: &str, - _hint_options: *mut c_void, + _hint_options: *mut u8, ) -> *mut c_void { trace!("{}: ··· {}", "ffi ", "get_hint_field: This is a mock call because there is no linked library"); std::ptr::null_mut() @@ -1036,13 +1066,13 @@ pub fn get_hint_field_c( #[allow(clippy::too_many_arguments)] pub fn mul_hint_fields_c( _p_setup_ctx: *mut c_void, - _p_steps_params: *mut c_void, + _p_steps_params: *mut u8, _hint_id: u64, _hint_field_dest: &str, _hint_field_name1: &str, _hint_field_name2: &str, - _hint_options1: *mut c_void, - _hint_options2: *mut c_void, + _hint_options1: *mut u8, + _hint_options2: *mut u8, ) -> u64 { trace!("{}: ··· {}", "ffi ", "mul_hint_fields: This is a mock call because there is no linked library"); 0 @@ -1051,7 +1081,7 @@ pub fn mul_hint_fields_c( #[cfg(feature = "no_lib_link")] pub fn acc_hint_field_c( _p_setup_ctx: *mut c_void, - _p_steps_params: *mut c_void, + _p_steps_params: *mut u8, _hint_id: u64, _hint_field_dest: &str, _hint_field_airgroupvalue: &str, @@ -1066,14 +1096,14 @@ pub fn acc_hint_field_c( #[allow(clippy::too_many_arguments)] pub fn acc_mul_hint_fields_c( _p_setup_ctx: *mut c_void, - _p_steps_params: *mut c_void, + _p_steps_params: *mut u8, _hint_id: u64, _hint_field_dest: &str, _hint_field_airgroupvalue: &str, _hint_field_name1: &str, _hint_field_name2: &str, - _hint_options1: *mut c_void, - _hint_options2: *mut c_void, + _hint_options1: *mut u8, + _hint_options2: *mut u8, _add: bool, ) -> *mut c_void { trace!("{}: ··· {}", "ffi ", "acc_mul_hint_fields: This is a mock call because there is no linked library"); @@ -1083,8 +1113,8 @@ pub fn acc_mul_hint_fields_c( #[cfg(feature = "no_lib_link")] pub fn set_hint_field_c( _p_setup_ctx: *mut c_void, - _p_params: *mut c_void, - _values: *mut c_void, + _p_params: *mut u8, + _values: *mut u8, _hint_id: u64, _hint_field_name: &str, ) -> u64 { @@ -1093,7 +1123,7 @@ pub fn set_hint_field_c( } #[cfg(feature = "no_lib_link")] -pub fn starks_new_c(_p_setup: *mut c_void, _p_const_tree: *mut c_void) -> *mut c_void { +pub fn starks_new_c(_p_setup: *mut c_void, _p_const_tree: *mut u8) -> *mut c_void { trace!("{}: ··· {}", "ffi ", "starks_new: This is a mock call because there is no linked library"); std::ptr::null_mut() } @@ -1115,7 +1145,7 @@ pub fn merkle_tree_free_c(_merkle_tree: *mut c_void) { } #[cfg(feature = "no_lib_link")] -pub fn treesGL_get_root_c(_pStark: *mut c_void, _index: u64, _root: *mut c_void) { +pub fn treesGL_get_root_c(_pStark: *mut c_void, _index: u64, _root: *mut u8) { trace!("{}: ··· {}", "ffi ", "treesGL_get_root: This is a mock call because there is no linked library"); } @@ -1125,17 +1155,17 @@ pub fn treesGL_set_root_c(_pStark: *mut c_void, _index: u64, _pProof: *mut c_voi } #[cfg(feature = "no_lib_link")] -pub fn calculate_fri_polynomial_c(_p_starks: *mut c_void, _p_steps_params: *mut c_void) { +pub fn calculate_fri_polynomial_c(_p_starks: *mut c_void, _p_steps_params: *mut u8) { trace!("mckzkevm: ··· {}", "calculate_fri_polynomial: This is a mock call because there is no linked library"); } #[cfg(feature = "no_lib_link")] -pub fn calculate_quotient_polynomial_c(_p_starks: *mut c_void, _p_steps_params: *mut c_void) { +pub fn calculate_quotient_polynomial_c(_p_starks: *mut c_void, _p_steps_params: *mut u8) { trace!("mckzkevm: ··· {}", "calculate_quotient_polynomial: This is a mock call because there is no linked library"); } #[cfg(feature = "no_lib_link")] -pub fn calculate_impols_expressions_c(_p_starks: *mut c_void, _step: u64, _p_steps_params: *mut c_void) { +pub fn calculate_impols_expressions_c(_p_starks: *mut c_void, _step: u64, _p_steps_params: *mut u8) { trace!( "{}: ··· {}", "mckzkevm", @@ -1149,10 +1179,10 @@ pub fn extend_and_merkelize_custom_commit_c( _p_starks: *mut c_void, _commit_id: u64, _step: u64, - _buffer: *mut c_void, - _buffer_ext: *mut c_void, + _buffer: *mut u8, + _buffer_ext: *mut u8, _p_proof: *mut c_void, - _p_buff_helper: *mut c_void, + _p_buff_helper: *mut u8, _tree_file: &str, ) { trace!( @@ -1167,8 +1197,8 @@ pub fn load_custom_commit_c( _p_starks: *mut c_void, _commit_id: u64, _step: u64, - _buffer: *mut c_void, - _buffer_ext: *mut c_void, + _buffer: *mut u8, + _buffer_ext: *mut u8, _p_proof: *mut c_void, _tree_file: &str, ) { @@ -1180,26 +1210,26 @@ pub fn commit_stage_c( _p_starks: *mut c_void, _element_type: u32, _step: u64, - _witness: *mut c_void, - _buffer: *mut c_void, + _witness: *mut u8, + _buffer: *mut u8, _p_proof: *mut c_void, - _p_buff_helper: *mut c_void, + _p_buff_helper: *mut u8, ) { trace!("{}: ··· {}", "ffi ", "commit_stage: This is a mock call because there is no linked library"); } #[cfg(feature = "no_lib_link")] -pub fn compute_lev_c(_p_stark: *mut c_void, _xi_challenge: *mut c_void, _lev: *mut c_void) { +pub fn compute_lev_c(_p_stark: *mut c_void, _xi_challenge: *mut c_void, _lev: *mut u8) { trace!("{}: ··· {}", "ffi ", "compute_lev: This is a mock call because there is no linked library"); } #[cfg(feature = "no_lib_link")] -pub fn compute_evals_c(_p_stark: *mut c_void, _params: *mut c_void, _lev: *mut c_void, _pProof: *mut c_void) { +pub fn compute_evals_c(_p_stark: *mut c_void, _params: *mut u8, _lev: *mut u8, _pProof: *mut c_void) { trace!("{}: ··· {}", "ffi ", "compute_evals: This is a mock call because there is no linked library"); } #[cfg(feature = "no_lib_link")] -pub fn calculate_xdivxsub_c(_p_stark: *mut c_void, _xi_challenge: *mut c_void, _buffer: *mut c_void) { +pub fn calculate_xdivxsub_c(_p_stark: *mut c_void, _xi_challenge: *mut c_void, _buffer: *mut u8) { trace!("{}: ··· {}", "ffi ", "calculate_xdivxsub: This is a mock call because there is no linked library"); } @@ -1262,7 +1292,7 @@ pub fn set_fri_final_pol_c(_p_proof: *mut c_void, _buffer: *mut u8, _n_bits: u64 } #[cfg(feature = "no_lib_link")] -pub fn calculate_hash_c(_pStarks: *mut c_void, _pHhash: *mut c_void, _pBuffer: *mut c_void, _nElements: u64) { +pub fn calculate_hash_c(_pStarks: *mut c_void, _pHhash: *mut u8, _pBuffer: *mut u8, _nElements: u64) { trace!("{}: ··· {}", "ffi ", "calculate_hash: This is a mock call because there is no linked library"); } @@ -1273,7 +1303,7 @@ pub fn transcript_new_c(_element_type: u32, _arity: u64, _custom: bool) -> *mut } #[cfg(feature = "no_lib_link")] -pub fn transcript_add_c(_p_transcript: *mut c_void, _p_input: *mut c_void, _size: u64) { +pub fn transcript_add_c(_p_transcript: *mut c_void, _p_input: *mut u8, _size: u64) { trace!("{}: ··· {}", "ffi ", "transcript_add: This is a mock call because there is no linked library"); } @@ -1302,7 +1332,7 @@ pub fn get_permutations_c(_p_transcript: *mut c_void, _res: *mut u64, _n: u64, _ } #[cfg(feature = "no_lib_link")] -pub fn verify_constraints_c(_p_setup: *mut c_void, _p_steps_params: *mut c_void) -> *mut c_void { +pub fn verify_constraints_c(_p_setup: *mut c_void, _p_steps_params: *mut u8) -> *mut c_void { trace!("{}: ··· {}", "ffi ", "verify_constraints: This is a mock call because there is no linked library"); std::ptr::null_mut() } diff --git a/transcript/src/ffi_transcript.rs b/transcript/src/ffi_transcript.rs index d7c1b0c5..7b6d202d 100644 --- a/transcript/src/ffi_transcript.rs +++ b/transcript/src/ffi_transcript.rs @@ -20,7 +20,7 @@ impl FFITranscript { Self { element_type, p_stark, p_transcript } } - pub fn add_elements(&self, input: *mut c_void, size: usize) { + pub fn add_elements(&self, input: *mut u8, size: usize) { transcript_add_c(self.p_transcript, input, size as u64); } From accbe0e50e372ef041ad8d63de0be1f50ba3b015 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 9 Dec 2024 16:27:39 +0000 Subject: [PATCH 23/64] Removing slice_trace --- macros/src/lib.rs | 71 ++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 8f2c80c2..126428b0 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -55,17 +55,17 @@ fn trace_impl(input: TokenStream2) -> Result { // Generate trace struct let trace_struct = quote! { - pub struct #trace_struct_name<'a, #generics> { - pub buffer: Vec<#generics>, - pub slice_trace: &'a mut [#row_struct_name<#generics>], + pub struct #trace_struct_name<#generics> { + pub buffer: Vec<#row_struct_name<#generics>>, pub num_rows: usize, + pub row_size: usize, pub airgroup_id: usize, pub air_id: usize, // pub commit_id: Option, pub commit_id: usize, } - impl<'a, #generics: Default + Clone + Copy> #trace_struct_name<'a, #generics> { + impl<#generics: Default + Clone + Copy> #trace_struct_name<#generics> { const NUM_ROWS: usize = #num_rows; const AIRGROUP_ID: usize = #airgroup_id; const AIR_ID: usize = #air_id; @@ -75,24 +75,17 @@ fn trace_impl(input: TokenStream2) -> Result { assert!(num_rows >= 2); assert!(num_rows & (num_rows - 1) == 0); - let mut buff_uninit: Vec> = Vec::with_capacity(num_rows * #row_struct_name::<#generics>::ROW_SIZE); + let mut buff_uninit: Vec>> = Vec::with_capacity(num_rows); unsafe { buff_uninit.set_len(num_rows * #row_struct_name::<#generics>::ROW_SIZE); } - let buffer: Vec<#generics> = unsafe { std::mem::transmute(buff_uninit) }; - - let slice_trace = unsafe { - std::slice::from_raw_parts_mut( - buffer.as_ptr() as *mut #row_struct_name<#generics>, - num_rows, - ) - }; + let buffer: Vec<#row_struct_name::<#generics>> = unsafe { std::mem::transmute(buff_uninit) }; #trace_struct_name { buffer, - slice_trace, num_rows, + row_size: #row_struct_name::<#generics>::ROW_SIZE, airgroup_id: Self::AIRGROUP_ID, air_id: Self::AIR_ID, commit_id: #commit_id, @@ -104,18 +97,12 @@ fn trace_impl(input: TokenStream2) -> Result { assert!(num_rows >= 2); assert!(num_rows & (num_rows - 1) == 0); - let buffer = vec![#generics::default(); num_rows * #row_struct_name::<#generics>::ROW_SIZE]; - let slice_trace = unsafe { - std::slice::from_raw_parts_mut( - buffer.as_ptr() as *mut #row_struct_name<#generics>, - num_rows, - ) - }; + let buffer = vec![#row_struct_name::<#generics>::default(); num_rows]; #trace_struct_name { buffer, - slice_trace, num_rows, + row_size: #row_struct_name::<#generics>::ROW_SIZE, airgroup_id: Self::AIRGROUP_ID, air_id: Self::AIR_ID, commit_id: #commit_id, @@ -143,26 +130,34 @@ fn trace_impl(input: TokenStream2) -> Result { } pub fn get_buffer(&mut self) -> Vec<#generics> { - let buffer = std::mem::take(&mut self.buffer); - buffer + let mut buffer = std::mem::take(&mut self.buffer); + unsafe { + let ptr = buffer.as_mut_ptr(); + let capacity = buffer.capacity() * self.row_size; + let len = buffer.len() * self.row_size; + + std::mem::forget(buffer); + + Vec::from_raw_parts(ptr.cast(), len, capacity) + } } } - impl<'a, #generics> std::ops::Index for #trace_struct_name<'a, #generics> { + impl<#generics> std::ops::Index for #trace_struct_name<#generics> { type Output = #row_struct_name<#generics>; fn index(&self, index: usize) -> &Self::Output { - &self.slice_trace[index] + &self.buffer[index] } } - impl<'a, #generics> std::ops::IndexMut for #trace_struct_name<'a, #generics> { + impl<#generics> std::ops::IndexMut for #trace_struct_name<#generics> { fn index_mut(&mut self, index: usize) -> &mut Self::Output { - &mut self.slice_trace[index] + &mut self.buffer[index] } } - impl<'a, #generics: Send> common::trace::Trace<#generics> for #trace_struct_name<'a, #generics> { + impl<#generics: Send> common::trace::Trace<#generics> for #trace_struct_name<#generics> { fn num_rows(&self) -> usize { self.num_rows } @@ -176,8 +171,16 @@ fn trace_impl(input: TokenStream2) -> Result { } fn get_buffer(&mut self) -> Vec<#generics> { - let buffer = std::mem::take(&mut self.buffer); - buffer + let mut buffer = std::mem::take(&mut self.buffer); + unsafe { + let ptr = buffer.as_mut_ptr(); + let capacity = buffer.capacity() * self.row_size; + let len = buffer.len() * self.row_size; + + std::mem::forget(buffer); + + Vec::from_raw_parts(ptr.cast(), len, capacity) + } } } }; @@ -348,9 +351,9 @@ fn values_impl(input: TokenStream2) -> Result { } } - pub fn from_vec_guard( - mut external_buffer_rw: std::sync::RwLockWriteGuard>, - ) -> Self { + pub fn from_vec_guard( + mut external_buffer_rw: std::sync::RwLockWriteGuard>, + ) -> Self { let slice_values = unsafe { let ptr = external_buffer_rw.as_mut_ptr() as *mut #row_struct_name<#generics>; &mut *ptr From d6f19fa738174076a01e7187081de97db1fcb2ad Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 9 Dec 2024 17:29:59 +0000 Subject: [PATCH 24/64] Updating macro with optional custom commit --- cli/assets/templates/pil_helpers_trace.rs.tt | 4 +-- macros/src/lib.rs | 22 ++++++--------- .../test/simple/rs/src/pil_helpers/mod.rs | 1 + .../test/simple/rs/src/pil_helpers/traces.rs | 8 ++++-- .../std/connection/rs/src/pil_helpers/mod.rs | 1 + .../connection/rs/src/pil_helpers/traces.rs | 10 +++++-- .../test/std/lookup/rs/src/pil_helpers/mod.rs | 1 + .../std/lookup/rs/src/pil_helpers/traces.rs | 13 +++++---- .../permutation/rs/src/pil_helpers/traces.rs | 10 +++---- .../std/range_check/rs/src/pil_helpers/mod.rs | 1 + .../range_check/rs/src/pil_helpers/traces.rs | 28 +++++++++++-------- 11 files changed, 56 insertions(+), 43 deletions(-) diff --git a/cli/assets/templates/pil_helpers_trace.rs.tt b/cli/assets/templates/pil_helpers_trace.rs.tt index 41cedb2c..445d7b78 100644 --- a/cli/assets/templates/pil_helpers_trace.rs.tt +++ b/cli/assets/templates/pil_helpers_trace.rs.tt @@ -4,7 +4,7 @@ use proofman_common as common; pub use proofman_macros::trace; pub use proofman_macros::values; -#[warn(dead_code)] +#[allow(dead_code)] type FieldExtension = [F; 3]; pub const PILOUT_HASH: &[u8] = b"{ project_name }-hash"; @@ -38,7 +38,7 @@ values!({ project_name }ProofValues \{ {{ endfor }} {{ for air_group in air_groups }}{{ for air in air_group.airs }} trace!({ air.name }Trace \{ {{ for column in air.columns }} { column.name }: { column.type },{{ endfor }} -}, { air_group.airgroup_id }, { air.id }, { air.num_rows }, 0 ); +}, { air_group.airgroup_id }, { air.id }, { air.num_rows } ); {{ endfor }}{{ endfor }}{{ for air_group in air_groups }}{{ for air in air_group.airs }}{{ for custom_commit in air.custom_columns }} trace!({ air.name }{custom_commit.name}Trace \{ {{ for column in custom_commit.custom_columns }} { column.name }: { column.type },{{ endfor }} diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 126428b0..f4933d0f 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -61,8 +61,7 @@ fn trace_impl(input: TokenStream2) -> Result { pub row_size: usize, pub airgroup_id: usize, pub air_id: usize, - // pub commit_id: Option, - pub commit_id: usize, + pub commit_id: Option, } impl<#generics: Default + Clone + Copy> #trace_struct_name<#generics> { @@ -200,8 +199,7 @@ struct ParsedTraceInput { airgroup_id: LitInt, air_id: LitInt, num_rows: LitInt, - //commit_id: Option, - commit_id: LitInt, + commit_id: TokenStream2, } impl Parse for ParsedTraceInput { @@ -232,15 +230,13 @@ impl Parse for ParsedTraceInput { input.parse::()?; let num_rows = input.parse::()?; - input.parse::()?; - let commit_id = input.parse::()?; - - // let commit_id = if input.peek(Token![,]) { - // input.parse::()?; - // Some(input.parse::()?) - // } else { - // None - // }; + let commit_id: TokenStream2 = if input.peek(Token![,]) { + input.parse::()?; + let commit_id = input.parse::()?; + quote!(Some(#commit_id)) + } else { + quote!(None) + }; Ok(ParsedTraceInput { row_struct_name, diff --git a/pil2-components/test/simple/rs/src/pil_helpers/mod.rs b/pil2-components/test/simple/rs/src/pil_helpers/mod.rs index 9daf0c06..8e9f77af 100644 --- a/pil2-components/test/simple/rs/src/pil_helpers/mod.rs +++ b/pil2-components/test/simple/rs/src/pil_helpers/mod.rs @@ -1,5 +1,6 @@ // WARNING: This file has been autogenerated from the PILOUT file. // Manual modifications are not recommended and may be overwritten. +#[rustfmt::skip] mod traces; pub use traces::*; diff --git a/pil2-components/test/simple/rs/src/pil_helpers/traces.rs b/pil2-components/test/simple/rs/src/pil_helpers/traces.rs index bb74ad83..388900e3 100644 --- a/pil2-components/test/simple/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/simple/rs/src/pil_helpers/traces.rs @@ -4,6 +4,9 @@ use proofman_common as common; pub use proofman_macros::trace; pub use proofman_macros::values; +#[allow(dead_code)] +type FieldExtension = [F; 3]; + pub const PILOUT_HASH: &[u8] = b"Build-hash"; //AIRGROUP CONSTANTS @@ -16,10 +19,11 @@ pub const SIMPLE_LEFT_AIR_IDS: &[usize] = &[0]; pub const SIMPLE_RIGHT_AIR_IDS: &[usize] = &[1]; + trace!(SimpleLeftTrace { a: F, b: F, c: F, d: F, e: F, f: F, g: F, h: F, -}, 0, 0, 4, 0 ); +}, 0, 0, 4 ); trace!(SimpleRightTrace { a: F, b: F, c: F, d: F, mul: F, -}, 0, 1, 4, 0 ); +}, 0, 1, 4 ); diff --git a/pil2-components/test/std/connection/rs/src/pil_helpers/mod.rs b/pil2-components/test/std/connection/rs/src/pil_helpers/mod.rs index 9daf0c06..8e9f77af 100644 --- a/pil2-components/test/std/connection/rs/src/pil_helpers/mod.rs +++ b/pil2-components/test/std/connection/rs/src/pil_helpers/mod.rs @@ -1,5 +1,6 @@ // WARNING: This file has been autogenerated from the PILOUT file. // Manual modifications are not recommended and may be overwritten. +#[rustfmt::skip] mod traces; pub use traces::*; diff --git a/pil2-components/test/std/connection/rs/src/pil_helpers/traces.rs b/pil2-components/test/std/connection/rs/src/pil_helpers/traces.rs index b46a23ca..35fd4886 100644 --- a/pil2-components/test/std/connection/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/std/connection/rs/src/pil_helpers/traces.rs @@ -4,6 +4,9 @@ use proofman_common as common; pub use proofman_macros::trace; pub use proofman_macros::values; +#[allow(dead_code)] +type FieldExtension = [F; 3]; + pub const PILOUT_HASH: &[u8] = b"Build-hash"; //AIRGROUP CONSTANTS @@ -18,14 +21,15 @@ pub const CONNECTION_2_AIR_IDS: &[usize] = &[1]; pub const CONNECTION_NEW_AIR_IDS: &[usize] = &[2]; + trace!(Connection1Trace { a: F, b: F, c: F, -}, 0, 0, 8, 0 ); +}, 0, 0, 8 ); trace!(Connection2Trace { a: F, b: F, c: F, -}, 0, 1, 16, 0 ); +}, 0, 1, 16 ); trace!(ConnectionNewTrace { a: [F; 6], b: [F; 6], c: [F; 6], d: [F; 6], -}, 0, 2, 16, 0 ); +}, 0, 2, 16 ); diff --git a/pil2-components/test/std/lookup/rs/src/pil_helpers/mod.rs b/pil2-components/test/std/lookup/rs/src/pil_helpers/mod.rs index 9daf0c06..8e9f77af 100644 --- a/pil2-components/test/std/lookup/rs/src/pil_helpers/mod.rs +++ b/pil2-components/test/std/lookup/rs/src/pil_helpers/mod.rs @@ -1,5 +1,6 @@ // WARNING: This file has been autogenerated from the PILOUT file. // Manual modifications are not recommended and may be overwritten. +#[rustfmt::skip] mod traces; pub use traces::*; diff --git a/pil2-components/test/std/lookup/rs/src/pil_helpers/traces.rs b/pil2-components/test/std/lookup/rs/src/pil_helpers/traces.rs index 9150a8de..a1ec8083 100644 --- a/pil2-components/test/std/lookup/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/std/lookup/rs/src/pil_helpers/traces.rs @@ -4,6 +4,7 @@ use proofman_common as common; pub use proofman_macros::trace; pub use proofman_macros::values; +#[allow(dead_code)] type FieldExtension = [F; 3]; pub const PILOUT_HASH: &[u8] = b"Build-hash"; @@ -29,24 +30,24 @@ pub const LOOKUP_3_AIR_IDS: &[usize] = &[5]; trace!(Lookup0Trace { f: [F; 4], t: [F; 4], sel: [F; 2], mul: [F; 2], -}, 0, 0, 1024, 0 ); +}, 0, 0, 1024 ); trace!(Lookup1Trace { f: [F; 2], t: F, sel: [F; 2], mul: F, -}, 0, 1, 1024, 0 ); +}, 0, 1, 1024 ); trace!(Lookup2_12Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, mul: F, -}, 0, 2, 4096, 0 ); +}, 0, 2, 4096 ); trace!(Lookup2_13Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, mul: F, -}, 0, 3, 8192, 0 ); +}, 0, 3, 8192 ); trace!(Lookup2_15Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, mul: F, -}, 0, 4, 32768, 0 ); +}, 0, 4, 32768 ); trace!(Lookup3Trace { c1: F, d1: F, c2: F, d2: F, mul1: F, mul2: F, -}, 0, 5, 16384, 0 ); +}, 0, 5, 16384 ); diff --git a/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs b/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs index e23b6d38..3be8f3e2 100644 --- a/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/std/permutation/rs/src/pil_helpers/traces.rs @@ -4,7 +4,7 @@ use proofman_common as common; pub use proofman_macros::trace; pub use proofman_macros::values; -#[warn(dead_code)] +#[allow(dead_code)] type FieldExtension = [F; 3]; pub const PILOUT_HASH: &[u8] = b"Build-hash"; @@ -26,16 +26,16 @@ pub const PERMUTATION_2_6_AIR_IDS: &[usize] = &[3]; trace!(Permutation1_6Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, sel3: F, -}, 0, 0, 64, 0 ); +}, 0, 0, 64 ); trace!(Permutation1_7Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, sel3: F, -}, 0, 1, 128, 0 ); +}, 0, 1, 128 ); trace!(Permutation1_8Trace { a1: F, b1: F, a2: F, b2: F, a3: F, b3: F, a4: F, b4: F, c1: F, d1: F, c2: F, d2: F, sel1: F, sel2: F, sel3: F, -}, 0, 2, 256, 0 ); +}, 0, 2, 256 ); trace!(Permutation2_6Trace { c1: F, d1: F, c2: F, d2: F, sel: F, -}, 0, 3, 512, 0 ); +}, 0, 3, 512 ); diff --git a/pil2-components/test/std/range_check/rs/src/pil_helpers/mod.rs b/pil2-components/test/std/range_check/rs/src/pil_helpers/mod.rs index 9daf0c06..8e9f77af 100644 --- a/pil2-components/test/std/range_check/rs/src/pil_helpers/mod.rs +++ b/pil2-components/test/std/range_check/rs/src/pil_helpers/mod.rs @@ -1,5 +1,6 @@ // WARNING: This file has been autogenerated from the PILOUT file. // Manual modifications are not recommended and may be overwritten. +#[rustfmt::skip] mod traces; pub use traces::*; diff --git a/pil2-components/test/std/range_check/rs/src/pil_helpers/traces.rs b/pil2-components/test/std/range_check/rs/src/pil_helpers/traces.rs index 4bf075f7..d9f65fdb 100644 --- a/pil2-components/test/std/range_check/rs/src/pil_helpers/traces.rs +++ b/pil2-components/test/std/range_check/rs/src/pil_helpers/traces.rs @@ -4,6 +4,9 @@ use proofman_common as common; pub use proofman_macros::trace; pub use proofman_macros::values; +#[allow(dead_code)] +type FieldExtension = [F; 3]; + pub const PILOUT_HASH: &[u8] = b"Build-hash"; //AIRGROUP CONSTANTS @@ -56,50 +59,51 @@ pub const U_8_AIR_AIR_IDS: &[usize] = &[0]; pub const SPECIFIED_RANGES_AIR_IDS: &[usize] = &[0]; + trace!(RangeCheck3Trace { c1: F, c2: F, -}, 0, 0, 32, 0 ); +}, 0, 0, 32 ); trace!(RangeCheck2Trace { b1: F, b2: F, b3: F, -}, 1, 0, 16, 0 ); +}, 1, 0, 16 ); trace!(RangeCheck1Trace { a1: F, a2: F, a3: F, a4: F, a5: F, sel1: F, sel2: F, sel3: F, -}, 2, 0, 8, 0 ); +}, 2, 0, 8 ); trace!(RangeCheck4Trace { a1: F, a2: F, a3: F, a4: F, a5: F, a6: F, a7: F, a8: F, sel1: F, sel2: F, -}, 3, 0, 64, 0 ); +}, 3, 0, 64 ); trace!(U16AirTrace { mul: F, -}, 3, 1, 65536, 0 ); +}, 3, 1, 65536 ); trace!(MultiRangeCheck1Trace { a: [F; 3], sel: [F; 3], range_sel: [F; 3], -}, 4, 0, 8, 0 ); +}, 4, 0, 8 ); trace!(MultiRangeCheck2Trace { a: [F; 2], sel: [F; 2], range_sel: [F; 2], -}, 5, 0, 16, 0 ); +}, 5, 0, 16 ); trace!(RangeCheckDynamic1Trace { colu: F, sel_7: F, sel_8: F, sel_16: F, sel_17: F, -}, 6, 0, 256, 0 ); +}, 6, 0, 256 ); trace!(RangeCheckDynamic2Trace { colu: F, sel_1: F, sel_2: F, sel_3: F, sel_4: F, sel_5: F, -}, 7, 0, 64, 0 ); +}, 7, 0, 64 ); trace!(RangeCheckMixTrace { a: [F; 4], b: [F; 2], c: [F; 1], range_sel: [F; 5], -}, 8, 0, 64, 0 ); +}, 8, 0, 64 ); trace!(U8AirTrace { mul: F, -}, 9, 0, 256, 0 ); +}, 9, 0, 256 ); trace!(SpecifiedRangesTrace { mul: [F; 20], -}, 10, 0, 131072, 0 ); +}, 10, 0, 131072 ); From 7e2b39b623b245f8df5ee8da3a278eeb59279eca Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 9 Dec 2024 17:35:16 +0000 Subject: [PATCH 25/64] Fix --- macros/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/macros/src/lib.rs b/macros/src/lib.rs index f4933d0f..2ed4f155 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -179,7 +179,7 @@ fn trace_impl(input: TokenStream2) -> Result { std::mem::forget(buffer); Vec::from_raw_parts(ptr.cast(), len, capacity) - } + } } } }; @@ -479,7 +479,7 @@ fn test_parsing_01() { assert_eq!(parsed.airgroup_id.base10_parse::().unwrap(), 0); assert_eq!(parsed.air_id.base10_parse::().unwrap(), 0); assert_eq!(parsed.num_rows.base10_parse::().unwrap(), 34); - assert_eq!(parsed.commit_id.base10_parse::().unwrap(), 38); + // assert_eq!(parsed.commit_id.to_string().parse::().unwrap(), 38); } #[test] @@ -493,7 +493,7 @@ fn test_parsing_02() { assert_eq!(parsed.airgroup_id.base10_parse::().unwrap(), 0); assert_eq!(parsed.air_id.base10_parse::().unwrap(), 0); assert_eq!(parsed.num_rows.base10_parse::().unwrap(), 127_456); - assert_eq!(parsed.commit_id.base10_parse::().unwrap(), 0); + // assert_eq!(parsed.commit_id.to_string().parse::().unwrap(), 0); } #[test] From 5c20eb95849d834f409a36772e00c99331d17e04 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Tue, 10 Dec 2024 09:57:26 +0000 Subject: [PATCH 26/64] Improving AirInstance calls --- common/src/air_instance.rs | 149 ++++++++++-------- common/src/air_instances_repository.rs | 14 -- common/src/proof_ctx.rs | 3 +- examples/fibonacci-square/src/fibonacci.rs | 32 ++-- examples/fibonacci-square/src/module.rs | 16 +- hints/src/hints.rs | 20 +-- macros/src/lib.rs | 16 +- .../rs/src/range_check/specified_ranges.rs | 6 +- .../std/rs/src/range_check/std_range_check.rs | 2 +- .../lib/std/rs/src/range_check/u16air.rs | 6 +- .../lib/std/rs/src/range_check/u8air.rs | 6 +- pil2-components/lib/std/rs/src/std_prod.rs | 2 +- pil2-components/lib/std/rs/src/std_sum.rs | 2 +- .../test/simple/rs/src/simple_left.rs | 12 +- .../test/simple/rs/src/simple_right.rs | 11 +- .../test/std/connection/rs/src/connection1.rs | 11 +- .../test/std/connection/rs/src/connection2.rs | 11 +- .../std/connection/rs/src/connection_new.rs | 11 +- .../test/std/lookup/rs/src/lookup0.rs | 11 +- .../test/std/lookup/rs/src/lookup1.rs | 11 +- .../test/std/lookup/rs/src/lookup2_12.rs | 11 +- .../test/std/lookup/rs/src/lookup2_13.rs | 11 +- .../test/std/lookup/rs/src/lookup2_15.rs | 11 +- .../test/std/lookup/rs/src/lookup3.rs | 11 +- .../std/permutation/rs/src/permutation1_6.rs | 14 +- .../std/permutation/rs/src/permutation1_7.rs | 11 +- .../std/permutation/rs/src/permutation1_8.rs | 11 +- .../std/permutation/rs/src/permutation2.rs | 11 +- .../range_check/rs/src/multi_range_check1.rs | 11 +- .../range_check/rs/src/multi_range_check2.rs | 11 +- .../std/range_check/rs/src/range_check1.rs | 11 +- .../std/range_check/rs/src/range_check2.rs | 11 +- .../std/range_check/rs/src/range_check3.rs | 11 +- .../std/range_check/rs/src/range_check4.rs | 11 +- .../rs/src/range_check_dynamic1.rs | 11 +- .../rs/src/range_check_dynamic2.rs | 11 +- .../std/range_check/rs/src/range_check_mix.rs | 11 +- pil2-stark/lib/include/starks_lib.h | 2 +- pil2-stark/src/api/starks_api.cpp | 4 +- pil2-stark/src/api/starks_api.hpp | 2 +- pil2-stark/src/starkpil/expressions_avx.hpp | 4 +- .../src/starkpil/expressions_avx512.hpp | 4 +- pil2-stark/src/starkpil/expressions_pack.hpp | 4 +- .../src/starkpil/gen_recursive_proof.hpp | 16 +- pil2-stark/src/starkpil/hints.hpp | 6 +- pil2-stark/src/starkpil/starks.cpp | 22 +-- pil2-stark/src/starkpil/starks.hpp | 4 +- pil2-stark/src/starkpil/steps.hpp | 2 +- proofman/src/witness_manager.rs | 14 +- provers/stark/src/stark_prover.rs | 31 ++-- 50 files changed, 329 insertions(+), 328 deletions(-) diff --git a/common/src/air_instance.rs b/common/src/air_instance.rs index c4173651..0d6bba36 100644 --- a/common/src/air_instance.rs +++ b/common/src/air_instance.rs @@ -3,12 +3,12 @@ use std::path::PathBuf; use p3_field::Field; use proofman_util::create_buffer_fast; -use crate::{trace::Trace, trace::Values, ProofCtx, ExecutionCtx, SetupCtx, Setup, StarkInfo}; +use crate::{trace::Trace, trace::Values, SetupCtx, Setup, StarkInfo}; #[repr(C)] pub struct StepsParams { - pub witness: *mut u8, pub trace: *mut u8, + pub aux_trace: *mut u8, pub public_inputs: *mut u8, pub challenges: *mut u8, pub airgroup_values: *mut u8, @@ -30,8 +30,8 @@ impl From<&StepsParams> for *mut u8 { impl Default for StepsParams { fn default() -> Self { StepsParams { - witness: ptr::null_mut(), trace: ptr::null_mut(), + aux_trace: ptr::null_mut(), public_inputs: ptr::null_mut(), challenges: ptr::null_mut(), airgroup_values: ptr::null_mut(), @@ -57,6 +57,52 @@ impl CustomCommitsInfo { } } +pub struct TraceInfo { + airgroup_id: usize, + air_id: usize, + trace: Vec, + custom_traces: Option>>, + air_values: Option>, +} + +impl TraceInfo { + pub fn new(airgroup_id: usize, air_id: usize, trace: Vec) -> Self { + Self { airgroup_id, air_id, trace, custom_traces: None, air_values: None } + } + + pub fn with_custom_traces(mut self, custom_traces: Vec>) -> Self { + self.custom_traces = Some(custom_traces); + self + } + + pub fn with_air_values(mut self, air_values: Vec) -> Self { + self.air_values = Some(air_values); + self + } +} + +pub struct FromTrace<'a, F> { + pub trace: &'a mut dyn Trace, + pub custom_traces: Option>>, + pub air_values: Option<&'a mut dyn Values>, +} + +impl<'a, F> FromTrace<'a, F> { + pub fn new(trace: &'a mut dyn Trace) -> Self { + Self { trace, custom_traces: None, air_values: None } + } + + pub fn with_custom_traces(mut self, custom_traces: Vec<&'a mut dyn Trace>) -> Self { + self.custom_traces = Some(custom_traces); + self + } + + pub fn with_air_values(mut self, air_values: &'a mut dyn Values) -> Self { + self.air_values = Some(air_values); + self + } +} + /// Air instance context for managing air instances (traces) #[allow(dead_code)] #[repr(C)] @@ -64,12 +110,11 @@ impl CustomCommitsInfo { pub struct AirInstance { pub airgroup_id: usize, pub air_id: usize, - pub air_segment_id: Option, pub air_instance_id: Option, pub idx: Option, pub global_idx: Option, - pub witness: Vec, - pub trace: Option>, + pub trace: Vec, + pub aux_trace: Option>, pub custom_commits: Vec>, pub custom_commits_extended: Vec>, pub airgroup_values: Vec, @@ -79,20 +124,15 @@ pub struct AirInstance { } impl AirInstance { - pub fn new( - setup_ctx: Arc, - air_segment_id: Option, - airgroup_id: usize, - air_id: usize, - witness: Vec, - witness_custom: Option>>, - air_values: Option>, - ) -> Self { + pub fn new(setup_ctx: Arc, trace_info: TraceInfo) -> Self { + let airgroup_id = trace_info.airgroup_id; + let air_id = trace_info.air_id; + let ps = setup_ctx.get_setup(airgroup_id, air_id); - let (custom_commits, custom_commits_extended) = Self::init_custom_commits(ps, witness_custom); + let (custom_commits, custom_commits_extended) = Self::init_custom_commits(ps, trace_info.custom_traces); - let airvalues = if let Some(air_values) = air_values { + let airvalues = if let Some(air_values) = trace_info.air_values { air_values } else { vec![F::zero(); ps.stark_info.airvalues_map.as_ref().unwrap().len() * 3] @@ -101,12 +141,11 @@ impl AirInstance { AirInstance { airgroup_id, air_id, - air_segment_id, air_instance_id: None, idx: None, global_idx: None, - witness, - trace: None, + trace: trace_info.trace, + aux_trace: None, custom_commits, custom_commits_extended, airgroup_values: vec![F::zero(); ps.stark_info.airgroupvalues_map.as_ref().unwrap().len() * 3], @@ -116,52 +155,28 @@ impl AirInstance { } } - pub fn from_trace( - proof_ctx: Arc>, - execution_ctx: Arc, - setup_ctx: Arc, - air_segment_id: Option, - trace: &mut dyn Trace, - traces_custom: Option<&mut Vec<&mut dyn Trace>>, - air_values: Option<&mut dyn Values>, - ) { - let airgroup_id = trace.airgroup_id(); - let air_id = trace.air_id(); - let witness = trace.get_buffer(); - - let custom_witnesses = if let Some(custom_traces) = traces_custom { - let mut custom_witnesses = Vec::new(); + pub fn new_from_trace(setup_ctx: Arc, mut traces: FromTrace<'_, F>) -> Self { + let mut trace_info = + TraceInfo::new(traces.trace.airgroup_id(), traces.trace.air_id(), traces.trace.get_buffer()); + + if let Some(custom_traces) = traces.custom_traces.as_mut() { + let mut traces = Vec::new(); for custom_trace in custom_traces.iter_mut() { - custom_witnesses.push(custom_trace.get_buffer()); + traces.push(custom_trace.get_buffer()); } - Some(custom_witnesses) - } else { - None - }; - - let air_values_info = air_values.map(|air_values| air_values.get_buffer()); - - let air_instance = AirInstance::new( - setup_ctx, - air_segment_id, - airgroup_id, - air_id, - witness, - custom_witnesses, - air_values_info, - ); - - let (is_mine, gid) = - execution_ctx.dctx.write().unwrap().add_instance(air_instance.airgroup_id, air_instance.air_id, 1); + trace_info = trace_info.with_custom_traces(traces); + } - if is_mine { - proof_ctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); + if let Some(air_values) = traces.air_values.as_mut() { + trace_info = trace_info.with_air_values(air_values.get_buffer()); } + + AirInstance::new(setup_ctx, trace_info) } pub fn init_custom_commits( setup: &Setup, - witness_custom: Option>>, + traces_custom: Option>>, ) -> (Vec>, Vec>) { let n_custom_commits = setup.stark_info.custom_commits.len(); @@ -174,8 +189,8 @@ impl AirInstance { .map_sections_n .get(&(setup.stark_info.custom_commits[commit_id].name.clone() + "0")) .unwrap() as usize; - if let Some(witness_custom_value) = witness_custom.as_ref() { - custom_commits.push(CustomCommitsInfo::new(witness_custom_value[commit_id].clone(), PathBuf::new())); + if let Some(traces_custom_vals) = traces_custom.as_ref() { + custom_commits.push(CustomCommitsInfo::new(traces_custom_vals[commit_id].clone(), PathBuf::new())); } else { println!("No custom trace data found."); } @@ -189,8 +204,8 @@ impl AirInstance { (custom_commits, custom_commits_extended) } - pub fn get_witness_ptr(&self) -> *mut u8 { - self.witness.as_ptr() as *mut u8 + pub fn get_trace_ptr(&self) -> *mut u8 { + self.trace.as_ptr() as *mut u8 } pub fn get_evals_ptr(&self) -> *mut u8 { @@ -205,13 +220,13 @@ impl AirInstance { self.airvalues.as_ptr() as *mut u8 } - pub fn set_trace(&mut self, trace: Vec) { - self.trace = Some(trace); + pub fn set_aux_trace(&mut self, aux_trace: Vec) { + self.aux_trace = Some(aux_trace); } - pub fn get_trace_ptr(&self) -> *mut u8 { - match &self.trace { - Some(trace) => trace.as_ptr() as *mut u8, + pub fn get_aux_trace_ptr(&self) -> *mut u8 { + match &self.aux_trace { + Some(aux_trace) => aux_trace.as_ptr() as *mut u8, None => std::ptr::null_mut(), // Return null if `trace` is `None` } } diff --git a/common/src/air_instances_repository.rs b/common/src/air_instances_repository.rs index 15e1a616..df671c20 100644 --- a/common/src/air_instances_repository.rs +++ b/common/src/air_instances_repository.rs @@ -63,18 +63,4 @@ impl AirInstancesRepository { indices } - - pub fn find_last_segment(&self, airgroup_id: usize, air_id: usize) -> Option { - let air_instances = self.air_instances.read().unwrap(); - - air_instances - .iter() - .filter(|air_instance| { - air_instance.airgroup_id == airgroup_id - && air_instance.air_id == air_id - && air_instance.air_segment_id.is_some() - }) - .map(|air_instance| air_instance.air_segment_id.unwrap_or(0)) - .max() - } } diff --git a/common/src/proof_ctx.rs b/common/src/proof_ctx.rs index c11e1871..055f3c51 100644 --- a/common/src/proof_ctx.rs +++ b/common/src/proof_ctx.rs @@ -60,12 +60,13 @@ impl ProofCtx { let global_info: GlobalInfo = GlobalInfo::new(&proving_key_path); let n_publics = global_info.n_publics; let n_proof_values = global_info.n_proof_values; + let n_challenges = global_info.n_challenges.iter().fold(0, |acc, &x| acc + x); Self { global_info, public_inputs: Values::new(n_publics), proof_values: Values::new(n_proof_values * 3), - challenges: Values::default(), + challenges: Values::new(n_challenges * 3), buff_helper: Values::default(), air_instance_repo: AirInstancesRepository::new(), } diff --git a/examples/fibonacci-square/src/fibonacci.rs b/examples/fibonacci-square/src/fibonacci.rs index 1d92b1cb..3e19c8f1 100644 --- a/examples/fibonacci-square/src/fibonacci.rs +++ b/examples/fibonacci-square/src/fibonacci.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{AirInstance, FromTrace, ExecutionCtx, ProofCtx, SetupCtx}; use proofman::{WitnessManager, WitnessComponent}; use p3_field::PrimeField64; @@ -20,26 +20,22 @@ impl FibonacciSquare { pub fn new(wcm: Arc>, module: Arc>) -> Arc { let fibonacci = Arc::new(Self { module }); - let airgroup_id = FibonacciSquareTrace::::get_airgroup_id(); - let air_id = FibonacciSquareTrace::::get_air_id(); - - wcm.register_component(fibonacci.clone(), airgroup_id, air_id); + wcm.register_component( + fibonacci.clone(), + FibonacciSquareTrace::::AIRGROUP_ID, + FibonacciSquareTrace::::AIR_ID, + ); fibonacci } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { - if let Err(e) = Self::calculate_trace(self, pctx, ectx, sctx) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + if let Err(e) = Self::calculate_trace(self, pctx, sctx) { panic!("Failed to calculate fibonacci: {:?}", e); } } - fn calculate_trace( - &self, - pctx: Arc>, - ectx: Arc, - sctx: Arc, - ) -> Result> { + fn calculate_trace(&self, pctx: Arc>, sctx: Arc) -> Result> { log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let mut publics = BuildPublicValues::from_vec_guard(pctx.get_publics()); @@ -80,15 +76,11 @@ impl FibonacciSquare { air_values.fibo1[1][0] = F::from_canonical_u64(2); air_values.fibo3 = [F::from_canonical_u64(5), F::from_canonical_u64(5), F::from_canonical_u64(5)]; - AirInstance::from_trace( - pctx.clone(), - ectx.clone(), + let air_instance = AirInstance::new_from_trace( sctx.clone(), - Some(0), - &mut trace, - Some(&mut vec![&mut trace_rom]), - Some(&mut air_values), + FromTrace::new(&mut trace).with_custom_traces(vec![&mut trace_rom]).with_air_values(&mut air_values), ); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); Ok(b) } diff --git a/examples/fibonacci-square/src/module.rs b/examples/fibonacci-square/src/module.rs index 66fcc141..50601981 100644 --- a/examples/fibonacci-square/src/module.rs +++ b/examples/fibonacci-square/src/module.rs @@ -1,6 +1,6 @@ use std::sync::{Arc, Mutex}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use proofman::{WitnessManager, WitnessComponent}; use pil_std_lib::Std; use p3_field::{AbstractField, PrimeField64}; @@ -19,10 +19,7 @@ impl Module< pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let module = Arc::new(Module { inputs: Mutex::new(Vec::new()), std_lib }); - let airgroup_id = ModuleTrace::::get_airgroup_id(); - let air_id = ModuleTrace::::get_air_id(); - - wcm.register_component(module.clone(), airgroup_id, air_id); + wcm.register_component(module.clone(), ModuleTrace::::AIRGROUP_ID, ModuleTrace::::AIR_ID); // Register dependency relations module.std_lib.register_predecessor(); @@ -40,11 +37,11 @@ impl Module< x_mod } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { - self.calculate_trace(pctx, ectx, sctx); + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + self.calculate_trace(pctx, sctx); } - fn calculate_trace(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + fn calculate_trace(&self, pctx: Arc>, sctx: Arc) { log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let module = F::as_canonical_u64(&pctx.get_public_value("module")); @@ -74,7 +71,8 @@ impl Module< self.std_lib.range_check(F::from_canonical_u64(module), F::one(), range); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), Some(0), &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); self.std_lib.unregister_predecessor(pctx, None); } diff --git a/hints/src/hints.rs b/hints/src/hints.rs index 6c937130..2cda0c98 100644 --- a/hints/src/hints.rs +++ b/hints/src/hints.rs @@ -681,8 +681,8 @@ pub fn mul_hint_fields( let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); let steps_params = StepsParams { - witness: air_instance.get_witness_ptr(), trace: air_instance.get_trace_ptr(), + aux_trace: air_instance.get_aux_trace_ptr(), public_inputs: proof_ctx.get_publics_ptr(), challenges: proof_ctx.get_challenges_ptr(), airgroup_values: air_instance.get_airgroup_values_ptr(), @@ -721,8 +721,8 @@ pub fn acc_hint_field( let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); let steps_params = StepsParams { - witness: air_instance.get_witness_ptr(), trace: air_instance.get_trace_ptr(), + aux_trace: air_instance.get_aux_trace_ptr(), public_inputs: proof_ctx.get_publics_ptr(), challenges: proof_ctx.get_challenges_ptr(), airgroup_values: air_instance.get_airgroup_values_ptr(), @@ -769,8 +769,8 @@ pub fn acc_mul_hint_fields( let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); let steps_params = StepsParams { - witness: air_instance.get_witness_ptr(), trace: air_instance.get_trace_ptr(), + aux_trace: air_instance.get_aux_trace_ptr(), public_inputs: proof_ctx.get_publics_ptr(), challenges: proof_ctx.get_challenges_ptr(), airgroup_values: air_instance.get_airgroup_values_ptr(), @@ -814,8 +814,8 @@ pub fn get_hint_field( let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); let steps_params = StepsParams { - witness: air_instance.get_witness_ptr(), trace: air_instance.get_trace_ptr(), + aux_trace: air_instance.get_aux_trace_ptr(), public_inputs: proof_ctx.get_publics_ptr(), challenges: proof_ctx.get_challenges_ptr(), airgroup_values: air_instance.get_airgroup_values_ptr(), @@ -862,8 +862,8 @@ pub fn get_hint_field_a( let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); let steps_params = StepsParams { - witness: air_instance.get_witness_ptr(), trace: air_instance.get_trace_ptr(), + aux_trace: air_instance.get_aux_trace_ptr(), public_inputs: proof_ctx.get_publics_ptr(), challenges: proof_ctx.get_challenges_ptr(), airgroup_values: air_instance.get_airgroup_values_ptr(), @@ -916,8 +916,8 @@ pub fn get_hint_field_m( let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); let steps_params = StepsParams { - witness: air_instance.get_witness_ptr(), trace: air_instance.get_trace_ptr(), + aux_trace: air_instance.get_aux_trace_ptr(), public_inputs: proof_ctx.get_publics_ptr(), challenges: proof_ctx.get_challenges_ptr(), airgroup_values: air_instance.get_airgroup_values_ptr(), @@ -1103,8 +1103,8 @@ pub fn set_hint_field( values: &HintFieldValue, ) { let steps_params = StepsParams { - witness: air_instance.get_witness_ptr(), trace: air_instance.get_trace_ptr(), + aux_trace: air_instance.get_aux_trace_ptr(), public_inputs: std::ptr::null_mut(), challenges: std::ptr::null_mut(), airgroup_values: std::ptr::null_mut(), @@ -1136,8 +1136,8 @@ pub fn set_hint_field_val( value: HintFieldOutput, ) { let steps_params = StepsParams { - witness: std::ptr::null_mut(), trace: std::ptr::null_mut(), + aux_trace: std::ptr::null_mut(), public_inputs: std::ptr::null_mut(), challenges: std::ptr::null_mut(), airgroup_values: air_instance.get_airgroup_values_ptr(), @@ -1174,8 +1174,8 @@ pub fn print_row(setup_ctx: &SetupCtx, air_instance: &AirInstance, let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); let buffer = match stage == 1 { - true => air_instance.get_witness_ptr(), - false => air_instance.get_trace_ptr(), + true => air_instance.get_trace_ptr(), + false => air_instance.get_aux_trace_ptr(), }; print_row_c((&setup.p_setup).into(), buffer, stage, row); diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 2ed4f155..fa434368 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -65,9 +65,9 @@ fn trace_impl(input: TokenStream2) -> Result { } impl<#generics: Default + Clone + Copy> #trace_struct_name<#generics> { - const NUM_ROWS: usize = #num_rows; - const AIRGROUP_ID: usize = #airgroup_id; - const AIR_ID: usize = #air_id; + pub const NUM_ROWS: usize = #num_rows; + pub const AIRGROUP_ID: usize = #airgroup_id; + pub const AIR_ID: usize = #air_id; pub fn new() -> Self { let num_rows = Self::NUM_ROWS; @@ -77,7 +77,7 @@ fn trace_impl(input: TokenStream2) -> Result { let mut buff_uninit: Vec>> = Vec::with_capacity(num_rows); unsafe { - buff_uninit.set_len(num_rows * #row_struct_name::<#generics>::ROW_SIZE); + buff_uninit.set_len(num_rows); } let buffer: Vec<#row_struct_name::<#generics>> = unsafe { std::mem::transmute(buff_uninit) }; @@ -112,14 +112,6 @@ fn trace_impl(input: TokenStream2) -> Result { self.num_rows } - pub fn get_airgroup_id() -> usize { - Self::AIRGROUP_ID - } - - pub fn get_air_id() -> usize { - Self::AIR_ID - } - pub fn airgroup_id(&self) -> usize { self.airgroup_id } diff --git a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs index 42c092d8..d420926f 100644 --- a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs +++ b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs @@ -5,7 +5,7 @@ use num_traits::ToPrimitive; use p3_field::PrimeField; use proofman::{get_hint_field_gc, WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{TraceInfo, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use proofman_hints::{ get_hint_field, get_hint_field_constant, get_hint_ids_by_name, set_hint_field, HintFieldOptions, HintFieldValue, }; @@ -134,7 +134,7 @@ impl SpecifiedRanges { let buffer_size = multiplicities.len() * num_rows; let buffer: Vec = create_buffer_fast(buffer_size); let air_instance = - AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer, None, None); + AirInstance::new(sctx.clone(), TraceInfo::new(self.airgroup_id, self.air_id, buffer)); pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)); pctx.air_instance_repo.air_instances.read().unwrap().len() - 1 }; @@ -304,7 +304,7 @@ impl WitnessComponent for SpecifiedRanges { let buffer = create_buffer_fast(buffer_size as usize); // Add a new air instance. Since Specified Ranges is a table, only this air instance is needed - let mut air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer, None, None); + let mut air_instance = AirInstance::new(sctx.clone(), TraceInfo::new(self.airgroup_id, self.air_id, buffer)); let mut mul_columns_guard = self.mul_columns.lock().unwrap(); for hint in hints_guard[1..].iter() { mul_columns_guard.push(get_hint_field::( diff --git a/pil2-components/lib/std/rs/src/range_check/std_range_check.rs b/pil2-components/lib/std/rs/src/range_check/std_range_check.rs index dc12c1ec..f788d3ec 100644 --- a/pil2-components/lib/std/rs/src/range_check/std_range_check.rs +++ b/pil2-components/lib/std/rs/src/range_check/std_range_check.rs @@ -86,7 +86,7 @@ impl StdRangeCheck { let std_range_check = Arc::new(Self { mode, ranges: Mutex::new(Vec::new()), u8air, u16air, specified_ranges }); - wcm.register_std(std_range_check.clone()); + wcm.register_proxy_component(std_range_check.clone()); std_range_check } diff --git a/pil2-components/lib/std/rs/src/range_check/u16air.rs b/pil2-components/lib/std/rs/src/range_check/u16air.rs index f5cff12d..4ac75bfd 100644 --- a/pil2-components/lib/std/rs/src/range_check/u16air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u16air.rs @@ -4,7 +4,7 @@ use num_traits::ToPrimitive; use p3_field::{Field, PrimeField}; use proofman::{get_hint_field_gc, WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{TraceInfo, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use proofman_hints::{get_hint_field, get_hint_ids_by_name, set_hint_field, HintFieldOptions, HintFieldValue}; use proofman_util::create_buffer_fast; @@ -118,7 +118,7 @@ impl U16Air { let buffer_size = num_rows; let buffer: Vec = create_buffer_fast(buffer_size); let air_instance = - AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer, None, None); + AirInstance::new(sctx.clone(), TraceInfo::new(self.airgroup_id, self.air_id, buffer)); pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)); pctx.air_instance_repo.air_instances.read().unwrap().len() - 1 }; @@ -179,7 +179,7 @@ impl WitnessComponent for U16Air { let buffer = create_buffer_fast(buffer_size); // Add a new air instance. Since U16Air is a table, only this air instance is needed - let mut air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer, None, None); + let mut air_instance = AirInstance::new(sctx.clone(), TraceInfo::new(self.airgroup_id, self.air_id, buffer)); *self.mul_column.lock().unwrap() = get_hint_field::( &self.wcm.get_sctx(), diff --git a/pil2-components/lib/std/rs/src/range_check/u8air.rs b/pil2-components/lib/std/rs/src/range_check/u8air.rs index b72a3d88..5d98c548 100644 --- a/pil2-components/lib/std/rs/src/range_check/u8air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u8air.rs @@ -3,7 +3,7 @@ use num_traits::ToPrimitive; use p3_field::{Field, PrimeField}; use proofman::{get_hint_field_gc, WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{TraceInfo, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use proofman_hints::{get_hint_field, get_hint_ids_by_name, set_hint_field, HintFieldOptions, HintFieldValue}; use proofman_util::create_buffer_fast; use std::sync::atomic::Ordering; @@ -116,7 +116,7 @@ impl U8Air { let buffer_size = num_rows; let buffer: Vec = create_buffer_fast(buffer_size); let air_instance = - AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer, None, None); + AirInstance::new(sctx.clone(), TraceInfo::new(self.airgroup_id, self.air_id, buffer)); pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)); pctx.air_instance_repo.air_instances.read().unwrap().len() - 1 }; @@ -176,7 +176,7 @@ impl WitnessComponent for U8Air { let buffer = create_buffer_fast(buffer_size); // Add a new air instance. Since U8Air is a table, only this air instance is needed - let mut air_instance = AirInstance::new(sctx.clone(), None, self.airgroup_id, self.air_id, buffer, None, None); + let mut air_instance = AirInstance::new(sctx.clone(), TraceInfo::new(self.airgroup_id, self.air_id, buffer)); *self.mul_column.lock().unwrap() = get_hint_field::( &sctx, diff --git a/pil2-components/lib/std/rs/src/std_prod.rs b/pil2-components/lib/std/rs/src/std_prod.rs index c534c48e..b8314074 100644 --- a/pil2-components/lib/std/rs/src/std_prod.rs +++ b/pil2-components/lib/std/rs/src/std_prod.rs @@ -51,7 +51,7 @@ impl StdProd { debug_data: if mode.name == ModeName::Debug { Some(Mutex::new(HashMap::new())) } else { None }, }); - wcm.register_std(std_prod.clone()); + wcm.register_proxy_component(std_prod.clone()); std_prod } diff --git a/pil2-components/lib/std/rs/src/std_sum.rs b/pil2-components/lib/std/rs/src/std_sum.rs index 7b89d6ee..bdbba01a 100644 --- a/pil2-components/lib/std/rs/src/std_sum.rs +++ b/pil2-components/lib/std/rs/src/std_sum.rs @@ -52,7 +52,7 @@ impl StdSum { debug_data: if mode.name == ModeName::Debug { Some(Mutex::new(HashMap::new())) } else { None }, }); - wcm.register_std(std_sum.clone()); + wcm.register_proxy_component(std_sum.clone()); std_sum } diff --git a/pil2-components/test/simple/rs/src/simple_left.rs b/pil2-components/test/simple/rs/src/simple_left.rs index 30ea3698..74ec8c5a 100644 --- a/pil2-components/test/simple/rs/src/simple_left.rs +++ b/pil2-components/test/simple/rs/src/simple_left.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, seq::SliceRandom}; @@ -21,15 +21,12 @@ where pub fn new(wcm: Arc>) -> Arc { let simple_left = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = SimpleLeftTrace::::get_airgroup_id(); - let air_id = SimpleLeftTrace::::get_air_id(); - - wcm.register_component(simple_left.clone(), airgroup_id, air_id); + wcm.register_component(simple_left.clone(), SimpleLeftTrace::::AIRGROUP_ID, SimpleLeftTrace::::AIR_ID); simple_left } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = SimpleLeftTrace::new(); @@ -59,7 +56,8 @@ where trace[i].d = trace[indices[i]].b; } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/simple/rs/src/simple_right.rs b/pil2-components/test/simple/rs/src/simple_right.rs index 1731ded9..d2fcaa39 100644 --- a/pil2-components/test/simple/rs/src/simple_right.rs +++ b/pil2-components/test/simple/rs/src/simple_right.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution}; @@ -21,15 +21,15 @@ where pub fn new(wcm: Arc>) -> Arc { let simple_right = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = SimpleRightTrace::::get_airgroup_id(); - let air_id = SimpleRightTrace::::get_air_id(); + let airgroup_id = SimpleRightTrace::::AIRGROUP_ID; + let air_id = SimpleRightTrace::::AIR_ID; wcm.register_component(simple_right.clone(), airgroup_id, air_id); simple_right } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut trace = SimpleRightTrace::new(); let num_rows = trace.num_rows(); @@ -46,7 +46,8 @@ where trace[i].mul = F::from_canonical_usize(1); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/connection/rs/src/connection1.rs b/pil2-components/test/std/connection/rs/src/connection1.rs index 89de6fee..81e5ac3b 100644 --- a/pil2-components/test/std/connection/rs/src/connection1.rs +++ b/pil2-components/test/std/connection/rs/src/connection1.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -21,15 +21,15 @@ where pub fn new(wcm: Arc>) -> Arc { let connection1 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Connection1Trace::::get_airgroup_id(); - let air_id = Connection1Trace::::get_air_id(); + let airgroup_id = Connection1Trace::::AIRGROUP_ID; + let air_id = Connection1Trace::::AIR_ID; wcm.register_component(connection1.clone(), airgroup_id, air_id); connection1 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Connection1Trace::new_zeroes(); @@ -43,7 +43,8 @@ where trace[i].c = rng.gen(); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/connection/rs/src/connection2.rs b/pil2-components/test/std/connection/rs/src/connection2.rs index 8cccbf21..ebeffe6e 100644 --- a/pil2-components/test/std/connection/rs/src/connection2.rs +++ b/pil2-components/test/std/connection/rs/src/connection2.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -21,15 +21,15 @@ where pub fn new(wcm: Arc>) -> Arc { let connection2 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Connection2Trace::::get_airgroup_id(); - let air_id = Connection2Trace::::get_air_id(); + let airgroup_id = Connection2Trace::::AIRGROUP_ID; + let air_id = Connection2Trace::::AIR_ID; wcm.register_component(connection2.clone(), airgroup_id, air_id); connection2 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Connection2Trace::new_zeroes(); @@ -45,7 +45,8 @@ where trace[0].a = trace[1].a; - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/connection/rs/src/connection_new.rs b/pil2-components/test/std/connection/rs/src/connection_new.rs index a49b1dca..5cb9c451 100644 --- a/pil2-components/test/std/connection/rs/src/connection_new.rs +++ b/pil2-components/test/std/connection/rs/src/connection_new.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -21,15 +21,15 @@ where pub fn new(wcm: Arc>) -> Arc { let connection_new = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = ConnectionNewTrace::::get_airgroup_id(); - let air_id = ConnectionNewTrace::::get_air_id(); + let airgroup_id = ConnectionNewTrace::::AIRGROUP_ID; + let air_id = ConnectionNewTrace::::AIR_ID; wcm.register_component(connection_new.clone(), airgroup_id, air_id); connection_new } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = ConnectionNewTrace::new_zeroes(); let num_rows = trace.num_rows(); @@ -136,7 +136,8 @@ where } } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup0.rs b/pil2-components/test/std/lookup/rs/src/lookup0.rs index a63e3560..6e940321 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup0.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup0.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -21,15 +21,15 @@ where pub fn new(wcm: Arc>) -> Arc { let lookup0 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Lookup0Trace::::get_airgroup_id(); - let air_id = Lookup0Trace::::get_air_id(); + let airgroup_id = Lookup0Trace::::AIRGROUP_ID; + let air_id = Lookup0Trace::::AIR_ID; wcm.register_component(lookup0.clone(), airgroup_id, air_id); lookup0 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup0Trace::new(); @@ -56,7 +56,8 @@ where } } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup1.rs b/pil2-components/test/std/lookup/rs/src/lookup1.rs index 1324fd56..e33cda8c 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup1.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup1.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -21,15 +21,15 @@ where pub fn new(wcm: Arc>) -> Arc { let lookup1 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Lookup1Trace::::get_airgroup_id(); - let air_id = Lookup1Trace::::get_air_id(); + let airgroup_id = Lookup1Trace::::AIRGROUP_ID; + let air_id = Lookup1Trace::::AIR_ID; wcm.register_component(lookup1.clone(), airgroup_id, air_id); lookup1 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup1Trace::new(); @@ -54,7 +54,8 @@ where trace[i].mul = F::from_canonical_usize(n_sel); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs index 8a54b4e1..9a96c0be 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -21,15 +21,15 @@ where pub fn new(wcm: Arc>) -> Arc { let lookup2_12 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Lookup2_12Trace::::get_airgroup_id(); - let air_id = Lookup2_12Trace::::get_air_id(); + let airgroup_id = Lookup2_12Trace::::AIRGROUP_ID; + let air_id = Lookup2_12Trace::::AIR_ID; wcm.register_component(lookup2_12.clone(), airgroup_id, air_id); lookup2_12 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup2_12Trace::new(); @@ -66,7 +66,8 @@ where trace[i].sel2 = F::from_bool(true); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs index d98da402..3dca3cf1 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -21,15 +21,15 @@ where pub fn new(wcm: Arc>) -> Arc { let lookup2_13 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Lookup2_13Trace::::get_airgroup_id(); - let air_id = Lookup2_13Trace::::get_air_id(); + let airgroup_id = Lookup2_13Trace::::AIRGROUP_ID; + let air_id = Lookup2_13Trace::::AIR_ID; wcm.register_component(lookup2_13.clone(), airgroup_id, air_id); lookup2_13 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup2_13Trace::new(); @@ -66,7 +66,8 @@ where trace[i].sel2 = F::from_bool(true); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs index ea8baa8f..01c31dff 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -21,15 +21,15 @@ where pub fn new(wcm: Arc>) -> Arc { let lookup2_15 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Lookup2_15Trace::::get_airgroup_id(); - let air_id = Lookup2_15Trace::::get_air_id(); + let airgroup_id = Lookup2_15Trace::::AIRGROUP_ID; + let air_id = Lookup2_15Trace::::AIR_ID; wcm.register_component(lookup2_15.clone(), airgroup_id, air_id); lookup2_15 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup2_15Trace::new(); @@ -66,7 +66,8 @@ where trace[i].sel2 = F::from_bool(true); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup3.rs b/pil2-components/test/std/lookup/rs/src/lookup3.rs index 291f81a5..c7bba92c 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup3.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup3.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; @@ -17,15 +17,15 @@ impl Lookup3 { pub fn new(wcm: Arc>) -> Arc { let lookup3 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Lookup3Trace::::get_airgroup_id(); - let air_id = Lookup3Trace::::get_air_id(); + let airgroup_id = Lookup3Trace::::AIRGROUP_ID; + let air_id = Lookup3Trace::::AIR_ID; wcm.register_component(lookup3.clone(), airgroup_id, air_id); lookup3 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { // For simplicity, add a single instance of each air let mut trace = Lookup3Trace::new(); let num_rows = trace.num_rows(); @@ -54,7 +54,8 @@ impl Lookup3 { } } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs index 29b7ae93..26041fbc 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, seq::SliceRandom, Rng}; @@ -21,15 +21,15 @@ where pub fn new(wcm: Arc>) -> Arc { let permutation1_6 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Permutation1_6Trace::::get_airgroup_id(); - let air_id = Permutation1_6Trace::::get_air_id(); + let airgroup_id = Permutation1_6Trace::::AIRGROUP_ID; + let air_id = Permutation1_6Trace::::AIR_ID; wcm.register_component(permutation1_6.clone(), airgroup_id, air_id); permutation1_6 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Permutation1_6Trace::new(); @@ -73,7 +73,8 @@ where trace[i].sel2 = trace[indices[i]].sel1; } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); let mut trace2 = Permutation1_6Trace::new(); @@ -110,7 +111,8 @@ where trace2[i].sel2 = trace2[indices[i]].sel1; } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace2, None, None); + let air_instance2 = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace2)); + pctx.air_instance_repo.add_air_instance(air_instance2, Some(0)); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs index c5e86009..d00dd978 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -21,15 +21,15 @@ where pub fn new(wcm: Arc>) -> Arc { let permutation1_7 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Permutation1_7Trace::::get_airgroup_id(); - let air_id = Permutation1_7Trace::::get_air_id(); + let airgroup_id = Permutation1_7Trace::::AIRGROUP_ID; + let air_id = Permutation1_7Trace::::AIR_ID; wcm.register_component(permutation1_7.clone(), airgroup_id, air_id); permutation1_7 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Permutation1_7Trace::new(); let num_rows = trace.num_rows(); @@ -73,7 +73,8 @@ where trace[i].sel2 = trace[i].sel1; } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs index 449daac8..79d94991 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -21,15 +21,15 @@ where pub fn new(wcm: Arc>) -> Arc { let permutation1_8 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Permutation1_8Trace::::get_airgroup_id(); - let air_id = Permutation1_8Trace::::get_air_id(); + let airgroup_id = Permutation1_8Trace::::AIRGROUP_ID; + let air_id = Permutation1_8Trace::::AIR_ID; wcm.register_component(permutation1_8.clone(), airgroup_id, air_id); permutation1_8 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Permutation1_8Trace::new(); let num_rows = trace.num_rows(); @@ -73,7 +73,8 @@ where trace[i].sel2 = trace[i].sel1; } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation2.rs b/pil2-components/test/std/permutation/rs/src/permutation2.rs index 7e164e24..bf4bb9a5 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation2.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation2.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; @@ -17,15 +17,15 @@ impl Permutation2 { pub fn new(wcm: Arc>) -> Arc { let permutation2 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Permutation2_6Trace::::get_airgroup_id(); - let air_id = Permutation2_6Trace::::get_air_id(); + let airgroup_id = Permutation2_6Trace::::AIRGROUP_ID; + let air_id = Permutation2_6Trace::::AIR_ID; wcm.register_component(permutation2.clone(), airgroup_id, air_id); permutation2 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut trace = Permutation2_6Trace::new(); let num_rows = trace.num_rows(); @@ -45,7 +45,8 @@ impl Permutation2 { trace[i].sel = F::from_bool(true); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs index e3dac4dd..6237b4c0 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -23,8 +23,8 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let multi_range_check1 = Arc::new(Self { std_lib }); - let airgroup_id = MultiRangeCheck1Trace::::get_airgroup_id(); - let air_id = MultiRangeCheck1Trace::::get_air_id(); + let airgroup_id = MultiRangeCheck1Trace::::AIRGROUP_ID; + let air_id = MultiRangeCheck1Trace::::AIR_ID; wcm.register_component(multi_range_check1.clone(), airgroup_id, air_id); @@ -34,7 +34,7 @@ where multi_range_check1 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = MultiRangeCheck1Trace::new_zeroes(); @@ -101,7 +101,8 @@ where } } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs index 258a5778..37fe6137 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -23,8 +23,8 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let multi_range_check2 = Arc::new(Self { std_lib }); - let airgroup_id = MultiRangeCheck2Trace::::get_airgroup_id(); - let air_id = MultiRangeCheck2Trace::::get_air_id(); + let airgroup_id = MultiRangeCheck2Trace::::AIRGROUP_ID; + let air_id = MultiRangeCheck2Trace::::AIR_ID; wcm.register_component(multi_range_check2.clone(), airgroup_id, air_id); @@ -34,7 +34,7 @@ where multi_range_check2 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = MultiRangeCheck2Trace::new_zeroes(); @@ -83,7 +83,8 @@ where } } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check1.rs b/pil2-components/test/std/range_check/rs/src/range_check1.rs index 47e46855..c08f9fd9 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check1.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -23,8 +23,8 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let range_check1 = Arc::new(Self { std_lib }); - let airgroup_id = RangeCheck1Trace::::get_airgroup_id(); - let air_id = RangeCheck1Trace::::get_air_id(); + let airgroup_id = RangeCheck1Trace::::AIRGROUP_ID; + let air_id = RangeCheck1Trace::::AIR_ID; wcm.register_component(range_check1.clone(), airgroup_id, air_id); @@ -34,7 +34,7 @@ where range_check1 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck1Trace::new_zeroes(); @@ -80,7 +80,8 @@ where } } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check2.rs b/pil2-components/test/std/range_check/rs/src/range_check2.rs index f8204bb0..64554f95 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check2.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -23,8 +23,8 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let range_check2 = Arc::new(Self { std_lib }); - let airgroup_id = RangeCheck2Trace::::get_airgroup_id(); - let air_id = RangeCheck2Trace::::get_air_id(); + let airgroup_id = RangeCheck2Trace::::AIRGROUP_ID; + let air_id = RangeCheck2Trace::::AIR_ID; wcm.register_component(range_check2.clone(), airgroup_id, air_id); @@ -34,7 +34,7 @@ where range_check2 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck2Trace::new_zeroes(); let num_rows = trace.num_rows(); @@ -55,7 +55,8 @@ where self.std_lib.range_check(trace[i].b3, F::one(), range3); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check3.rs b/pil2-components/test/std/range_check/rs/src/range_check3.rs index 8d728565..aa299c48 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check3.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check3.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -23,8 +23,8 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let range_check3 = Arc::new(Self { std_lib }); - let airgroup_id = RangeCheck3Trace::::get_airgroup_id(); - let air_id = RangeCheck3Trace::::get_air_id(); + let airgroup_id = RangeCheck3Trace::::AIRGROUP_ID; + let air_id = RangeCheck3Trace::::AIR_ID; wcm.register_component(range_check3.clone(), airgroup_id, air_id); @@ -34,7 +34,7 @@ where range_check3 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck3Trace::new_zeroes(); @@ -53,7 +53,8 @@ where self.std_lib.range_check(trace[i].c2, F::one(), range2); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check4.rs b/pil2-components/test/std/range_check/rs/src/range_check4.rs index 7ba608d4..47a081b2 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check4.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check4.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use num_bigint::BigInt; use num_traits::ToPrimitive; @@ -24,8 +24,8 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let range_check4 = Arc::new(Self { std_lib }); - let airgroup_id = RangeCheck4Trace::::get_airgroup_id(); - let air_id = RangeCheck4Trace::::get_air_id(); + let airgroup_id = RangeCheck4Trace::::AIRGROUP_ID; + let air_id = RangeCheck4Trace::::AIR_ID; wcm.register_component(range_check4.clone(), airgroup_id, air_id); @@ -35,7 +35,7 @@ where range_check4 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck4Trace::new_zeroes(); @@ -101,7 +101,8 @@ where self.std_lib.range_check(trace[i].a8, F::one(), range9); } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs index 929a12f2..1882a188 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -23,8 +23,8 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let range_check_dynamic1 = Arc::new(Self { std_lib }); - let airgroup_id = RangeCheckDynamic1Trace::::get_airgroup_id(); - let air_id = RangeCheckDynamic1Trace::::get_air_id(); + let airgroup_id = RangeCheckDynamic1Trace::::AIRGROUP_ID; + let air_id = RangeCheckDynamic1Trace::::AIR_ID; wcm.register_component(range_check_dynamic1.clone(), airgroup_id, air_id); @@ -34,7 +34,7 @@ where range_check_dynamic1 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheckDynamic1Trace::new_zeroes(); @@ -79,7 +79,8 @@ where } } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs index 8e90c3c5..bcf787aa 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use num_bigint::BigInt; use num_traits::ToPrimitive; @@ -24,8 +24,8 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let range_check_dynamic2 = Arc::new(Self { std_lib }); - let airgroup_id = RangeCheckDynamic2Trace::::get_airgroup_id(); - let air_id = RangeCheckDynamic2Trace::::get_air_id(); + let airgroup_id = RangeCheckDynamic2Trace::::AIRGROUP_ID; + let air_id = RangeCheckDynamic2Trace::::AIR_ID; wcm.register_component(range_check_dynamic2.clone(), airgroup_id, air_id); @@ -35,7 +35,7 @@ where range_check_dynamic2 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheckDynamic2Trace::new_zeroes(); @@ -92,7 +92,8 @@ where } } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs index a80f30ca..dde83fc9 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use num_bigint::BigInt; use num_traits::ToPrimitive; @@ -24,8 +24,8 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let range_check_mix = Arc::new(Self { std_lib }); - let airgroup_id = RangeCheckMixTrace::::get_airgroup_id(); - let air_id = RangeCheckMixTrace::::get_air_id(); + let airgroup_id = RangeCheckMixTrace::::AIRGROUP_ID; + let air_id = RangeCheckMixTrace::::AIR_ID; wcm.register_component(range_check_mix.clone(), airgroup_id, air_id); @@ -35,7 +35,7 @@ where range_check_mix } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheckMixTrace::new_zeroes(); @@ -133,7 +133,8 @@ where } } - AirInstance::from_trace(pctx.clone(), ectx.clone(), sctx.clone(), None, &mut trace, None, None); + let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); } } diff --git a/pil2-stark/lib/include/starks_lib.h b/pil2-stark/lib/include/starks_lib.h index 50339410..dd3c24b9 100644 --- a/pil2-stark/lib/include/starks_lib.h +++ b/pil2-stark/lib/include/starks_lib.h @@ -72,7 +72,7 @@ void extend_and_merkelize_custom_commit(void *pStarks, uint64_t commitId, uint64_t step, void *buffer, void *bufferExt, void *pProof, void *pBuffHelper, char *treeFile); void load_custom_commit(void *pStarks, uint64_t commitId, uint64_t step, void *buffer, void *bufferExt, void *pProof, char *treeFile); - void commit_stage(void *pStarks, uint32_t elementType, uint64_t step, void *witness, void *buffer, void *pProof, void *pBuffHelper); + void commit_stage(void *pStarks, uint32_t elementType, uint64_t step, void *trace, void *buffer, void *pProof, void *pBuffHelper); void compute_lev(void *pStarks, void *xiChallenge, void* LEv); void compute_evals(void *pStarks, void *params, void *LEv, void *pProof); diff --git a/pil2-stark/src/api/starks_api.cpp b/pil2-stark/src/api/starks_api.cpp index 1b3546e3..a300d952 100644 --- a/pil2-stark/src/api/starks_api.cpp +++ b/pil2-stark/src/api/starks_api.cpp @@ -320,13 +320,13 @@ void load_custom_commit(void *pStarks, uint64_t commitId, uint64_t step, void *b starks->loadCustomCommit(commitId, step, (Goldilocks::Element *)buffer, (Goldilocks::Element *)bufferExt, *(FRIProof *)pProof, string(bufferFile)); } -void commit_stage(void *pStarks, uint32_t elementType, uint64_t step, void *witness, void *buffer, void *pProof, void *pBuffHelper) { +void commit_stage(void *pStarks, uint32_t elementType, uint64_t step, void *trace, void *buffer, void *pProof, void *pBuffHelper) { // type == 1 => Goldilocks // type == 2 => BN128 switch (elementType) { case 1: - ((Starks *)pStarks)->commitStage(step, (Goldilocks::Element *)witness, (Goldilocks::Element *)buffer, *(FRIProof *)pProof, (Goldilocks::Element *)pBuffHelper); + ((Starks *)pStarks)->commitStage(step, (Goldilocks::Element *)trace, (Goldilocks::Element *)buffer, *(FRIProof *)pProof, (Goldilocks::Element *)pBuffHelper); break; default: cerr << "Invalid elementType: " << elementType << endl; diff --git a/pil2-stark/src/api/starks_api.hpp b/pil2-stark/src/api/starks_api.hpp index 50339410..dd3c24b9 100644 --- a/pil2-stark/src/api/starks_api.hpp +++ b/pil2-stark/src/api/starks_api.hpp @@ -72,7 +72,7 @@ void extend_and_merkelize_custom_commit(void *pStarks, uint64_t commitId, uint64_t step, void *buffer, void *bufferExt, void *pProof, void *pBuffHelper, char *treeFile); void load_custom_commit(void *pStarks, uint64_t commitId, uint64_t step, void *buffer, void *bufferExt, void *pProof, char *treeFile); - void commit_stage(void *pStarks, uint32_t elementType, uint64_t step, void *witness, void *buffer, void *pProof, void *pBuffHelper); + void commit_stage(void *pStarks, uint32_t elementType, uint64_t step, void *trace, void *buffer, void *pProof, void *pBuffHelper); void compute_lev(void *pStarks, void *xiChallenge, void* LEv); void compute_evals(void *pStarks, void *params, void *LEv, void *pProof); diff --git a/pil2-stark/src/starkpil/expressions_avx.hpp b/pil2-stark/src/starkpil/expressions_avx.hpp index 0834c013..f03d5c5e 100644 --- a/pil2-stark/src/starkpil/expressions_avx.hpp +++ b/pil2-stark/src/starkpil/expressions_avx.hpp @@ -125,9 +125,9 @@ class ExpressionsAvx : public ExpressionsCtx { for(uint64_t j = 0; j < nrowsPack; ++j) { uint64_t l = (row + j + nextStrides[o]) % domainSize; if(stage == 1 && !domainExtended) { - bufferT[nrowsPack*o + j] = params.witness[l * nColsStages[stage] + stagePos + d]; + bufferT[nrowsPack*o + j] = params.trace[l * nColsStages[stage] + stagePos + d]; } else { - bufferT[nrowsPack*o + j] = params.trace[offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; + bufferT[nrowsPack*o + j] = params.aux_trace[offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; } } diff --git a/pil2-stark/src/starkpil/expressions_avx512.hpp b/pil2-stark/src/starkpil/expressions_avx512.hpp index 0340550b..664313fe 100644 --- a/pil2-stark/src/starkpil/expressions_avx512.hpp +++ b/pil2-stark/src/starkpil/expressions_avx512.hpp @@ -125,9 +125,9 @@ class ExpressionsAvx512 : public ExpressionsCtx { for(uint64_t j = 0; j < nrowsPack; ++j) { uint64_t l = (row + j + nextStrides[o]) % domainSize; if(stage == 1 && !domainExtended) { - bufferT[nrowsPack*o + j] = params.witness[l * nColsStages[stage] + stagePos + d]; + bufferT[nrowsPack*o + j] = params.trace[l * nColsStages[stage] + stagePos + d]; } else { - bufferT[nrowsPack*o + j] = params.trace[offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; + bufferT[nrowsPack*o + j] = params.aux_trace[offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; } } Goldilocks::load_avx512(bufferT_[nColsStagesAcc[ns*o + stage] + (stagePos + d)], &bufferT[nrowsPack*o]); diff --git a/pil2-stark/src/starkpil/expressions_pack.hpp b/pil2-stark/src/starkpil/expressions_pack.hpp index d4a589d8..43460400 100644 --- a/pil2-stark/src/starkpil/expressions_pack.hpp +++ b/pil2-stark/src/starkpil/expressions_pack.hpp @@ -120,9 +120,9 @@ class ExpressionsPack : public ExpressionsCtx { for(uint64_t j = 0; j < nrowsPack; ++j) { uint64_t l = (row + j + nextStrides[o]) % domainSize; if(stage == 1 && !domainExtended) { - bufferT_[(nColsStagesAcc[ns*o + stage] + (stagePos + d))*nrowsPack + j] = params.witness[l * nColsStages[stage] + stagePos + d]; + bufferT_[(nColsStagesAcc[ns*o + stage] + (stagePos + d))*nrowsPack + j] = params.trace[l * nColsStages[stage] + stagePos + d]; } else { - bufferT_[(nColsStagesAcc[ns*o + stage] + (stagePos + d))*nrowsPack + j] = params.trace[offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; + bufferT_[(nColsStagesAcc[ns*o + stage] + (stagePos + d))*nrowsPack + j] = params.aux_trace[offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; } } } diff --git a/pil2-stark/src/starkpil/gen_recursive_proof.hpp b/pil2-stark/src/starkpil/gen_recursive_proof.hpp index 9463c11c..52c6ac23 100644 --- a/pil2-stark/src/starkpil/gen_recursive_proof.hpp +++ b/pil2-stark/src/starkpil/gen_recursive_proof.hpp @@ -67,7 +67,7 @@ void *genRecursiveProof(SetupCtx& setupCtx, json& globalInfo, uint64_t airgroupI } } TimerStart(STARK_COMMIT_STAGE_1); - starks.commitStage(1, params.witness, params.trace, proof); + starks.commitStage(1, params.trace, params.aux_trace, proof); TimerStopAndLog(STARK_COMMIT_STAGE_1); starks.addTranscript(transcript, &proof.proof.roots[0][0], nFieldElements); @@ -101,7 +101,7 @@ void *genRecursiveProof(SetupCtx& setupCtx, json& globalInfo, uint64_t airgroupI } Polinomial gprodTransposedPol; - setupCtx.starkInfo.getPolynomial(gprodTransposedPol, params.trace, "cm", setupCtx.starkInfo.cmPolsMap[gprodFieldId], false); + setupCtx.starkInfo.getPolynomial(gprodTransposedPol, params.aux_trace, "cm", setupCtx.starkInfo.cmPolsMap[gprodFieldId], false); #pragma omp parallel for for(uint64_t j = 0; j < N; ++j) { std::memcpy(gprodTransposedPol[j], &gprod[j*FIELD_EXTENSION], FIELD_EXTENSION * sizeof(Goldilocks::Element)); @@ -115,7 +115,7 @@ void *genRecursiveProof(SetupCtx& setupCtx, json& globalInfo, uint64_t airgroupI TimerStopAndLog(CALCULATE_IM_POLS); TimerStart(STARK_COMMIT_STAGE_2); - starks.commitStage(2, nullptr, params.trace, proof); + starks.commitStage(2, nullptr, params.aux_trace, proof); TimerStopAndLog(STARK_COMMIT_STAGE_2); starks.addTranscript(transcript, &proof.proof.roots[1][0], nFieldElements); @@ -130,10 +130,10 @@ void *genRecursiveProof(SetupCtx& setupCtx, json& globalInfo, uint64_t airgroupI } } - expressionsCtx.calculateExpression(params, ¶ms.trace[setupCtx.starkInfo.mapOffsets[std::make_pair("q", true)]], setupCtx.starkInfo.cExpId); + expressionsCtx.calculateExpression(params, ¶ms.aux_trace[setupCtx.starkInfo.mapOffsets[std::make_pair("q", true)]], setupCtx.starkInfo.cExpId); TimerStart(STARK_COMMIT_QUOTIENT_POLYNOMIAL); - starks.commitStage(setupCtx.starkInfo.nStages + 1, nullptr, params.trace, proof); + starks.commitStage(setupCtx.starkInfo.nStages + 1, nullptr, params.aux_trace, proof); TimerStopAndLog(STARK_COMMIT_QUOTIENT_POLYNOMIAL); starks.addTranscript(transcript, &proof.proof.roots[setupCtx.starkInfo.nStages][0], nFieldElements); TimerStopAndLog(STARK_STEP_Q); @@ -150,7 +150,7 @@ void *genRecursiveProof(SetupCtx& setupCtx, json& globalInfo, uint64_t airgroupI } Goldilocks::Element *xiChallenge = &challenges[xiChallengeIndex * FIELD_EXTENSION]; - Goldilocks::Element* LEv = ¶ms.trace[setupCtx.starkInfo.mapOffsets[make_pair("LEv", true)]]; + Goldilocks::Element* LEv = ¶ms.aux_trace[setupCtx.starkInfo.mapOffsets[make_pair("LEv", true)]]; starks.computeLEv(xiChallenge, LEv); starks.computeEvals(params ,LEv, proof); @@ -179,13 +179,13 @@ void *genRecursiveProof(SetupCtx& setupCtx, json& globalInfo, uint64_t airgroupI TimerStart(STARK_STEP_FRI); TimerStart(COMPUTE_FRI_POLYNOMIAL); - params.xDivXSub = ¶ms.trace[setupCtx.starkInfo.mapOffsets[std::make_pair("xDivXSubXi", true)]]; + params.xDivXSub = ¶ms.aux_trace[setupCtx.starkInfo.mapOffsets[std::make_pair("xDivXSubXi", true)]]; starks.calculateXDivXSub(xiChallenge, params.xDivXSub); starks.calculateFRIPolynomial(params); TimerStopAndLog(COMPUTE_FRI_POLYNOMIAL); Goldilocks::Element challenge[FIELD_EXTENSION]; - Goldilocks::Element *friPol = ¶ms.trace[setupCtx.starkInfo.mapOffsets[std::make_pair("f", true)]]; + Goldilocks::Element *friPol = ¶ms.aux_trace[setupCtx.starkInfo.mapOffsets[std::make_pair("f", true)]]; TimerStart(STARK_FRI_FOLDING); uint64_t nBitsExt = setupCtx.starkInfo.starkStruct.steps[0].nBits; diff --git a/pil2-stark/src/starkpil/hints.hpp b/pil2-stark/src/starkpil/hints.hpp index 9e241a1c..913d1322 100644 --- a/pil2-stark/src/starkpil/hints.hpp +++ b/pil2-stark/src/starkpil/hints.hpp @@ -217,7 +217,7 @@ HintFieldValues getHintField( hintFieldInfo.fieldType = dim == 1 ? HintFieldType::Column : HintFieldType::ColumnExtended; hintFieldInfo.offset = dim; if(!hintOptions.dest) { - Goldilocks::Element *pAddress = setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].stage == 1 ? params.witness : params.trace; + Goldilocks::Element *pAddress = setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].stage == 1 ? params.trace : params.aux_trace; getPolynomial(setupCtx, pAddress, hintFieldInfo.values, setupCtx.starkInfo.cmPolsMap[hintFieldVal.id], hintFieldVal.rowOffsetIndex, "cm"); if(hintOptions.inverse) { zklog.error("Inverse not supported still for polynomials"); @@ -364,7 +364,7 @@ uint64_t setHintField(SetupCtx& setupCtx, StepsParams& params, Goldilocks::Eleme auto hintFieldVal = hintField->values[0]; if(hintFieldVal.operand == opType::cm) { - Goldilocks::Element *pAddress = setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].stage > 1 ? params.trace : params.witness; + Goldilocks::Element *pAddress = setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].stage > 1 ? params.aux_trace : params.trace; setPolynomial(setupCtx, pAddress, values, hintFieldVal.id); } else if(hintFieldVal.operand == opType::airgroupvalue) { if(setupCtx.starkInfo.airgroupValuesMap[hintFieldVal.id].stage > 1) { @@ -452,7 +452,7 @@ uint64_t multiplyHintFields(SetupCtx& setupCtx, StepsParams ¶ms, uint64_t hi HintFieldValue hintFieldDestVal = hintFieldDest->values[0]; uint64_t offset = setupCtx.starkInfo.mapSectionsN["cm" + to_string(setupCtx.starkInfo.cmPolsMap[hintFieldDestVal.id].stage)]; - Goldilocks::Element *buff = ¶ms.trace[setupCtx.starkInfo.mapOffsets[std::make_pair("cm" + to_string(setupCtx.starkInfo.cmPolsMap[hintFieldDestVal.id].stage), false)] + setupCtx.starkInfo.cmPolsMap[hintFieldDestVal.id].stagePos]; + Goldilocks::Element *buff = ¶ms.aux_trace[setupCtx.starkInfo.mapOffsets[std::make_pair("cm" + to_string(setupCtx.starkInfo.cmPolsMap[hintFieldDestVal.id].stage), false)] + setupCtx.starkInfo.cmPolsMap[hintFieldDestVal.id].stagePos]; opHintFields(setupCtx, params, buff, offset, hintId, {hintFieldName1, hintFieldName2}, {hintOptions1, hintOptions2}); diff --git a/pil2-stark/src/starkpil/starks.cpp b/pil2-stark/src/starkpil/starks.cpp index 4a1687d2..cef93362 100644 --- a/pil2-stark/src/starkpil/starks.cpp +++ b/pil2-stark/src/starkpil/starks.cpp @@ -59,7 +59,7 @@ void Starks::loadCustomCommit(uint64_t commitId, uint64_t step, Gol } template -void Starks::extendAndMerkelize(uint64_t step, Goldilocks::Element *witness, Goldilocks::Element *buffer, FRIProof &proof, Goldilocks::Element *pBuffHelper) +void Starks::extendAndMerkelize(uint64_t step, Goldilocks::Element *trace, Goldilocks::Element *aux_trace, FRIProof &proof, Goldilocks::Element *pBuffHelper) { uint64_t N = 1 << setupCtx.starkInfo.starkStruct.nBits; uint64_t NExtended = 1 << setupCtx.starkInfo.starkStruct.nBitsExt; @@ -67,8 +67,8 @@ void Starks::extendAndMerkelize(uint64_t step, Goldilocks::Element std::string section = "cm" + to_string(step); uint64_t nCols = setupCtx.starkInfo.mapSectionsN["cm" + to_string(step)]; - Goldilocks::Element *pBuff = step == 1 ? witness : &buffer[setupCtx.starkInfo.mapOffsets[make_pair(section, false)]]; - Goldilocks::Element *pBuffExtended = &buffer[setupCtx.starkInfo.mapOffsets[make_pair(section, true)]]; + Goldilocks::Element *pBuff = step == 1 ? trace : &aux_trace[setupCtx.starkInfo.mapOffsets[make_pair(section, false)]]; + Goldilocks::Element *pBuffExtended = &aux_trace[setupCtx.starkInfo.mapOffsets[make_pair(section, true)]]; NTT_Goldilocks ntt(N); if(pBuffHelper != nullptr) { @@ -83,16 +83,16 @@ void Starks::extendAndMerkelize(uint64_t step, Goldilocks::Element } template -void Starks::commitStage(uint64_t step, Goldilocks::Element *witness, Goldilocks::Element *trace, FRIProof &proof, Goldilocks::Element* pBuffHelper) +void Starks::commitStage(uint64_t step, Goldilocks::Element *trace, Goldilocks::Element *aux_trace, FRIProof &proof, Goldilocks::Element* pBuffHelper) { if (step <= setupCtx.starkInfo.nStages) { - extendAndMerkelize(step, witness, trace, proof, pBuffHelper); + extendAndMerkelize(step, trace, aux_trace, proof, pBuffHelper); } else { - computeQ(step, trace, proof, pBuffHelper); + computeQ(step, aux_trace, proof, pBuffHelper); } } @@ -244,7 +244,7 @@ void Starks::evmap(StepsParams& params, Goldilocks::Element *LEv) int num_threads = omp_get_max_threads(); int size_thread = size_eval * FIELD_EXTENSION; - Goldilocks::Element *evals_acc = ¶ms.trace[setupCtx.starkInfo.mapOffsets[std::make_pair("evals", true)]]; + Goldilocks::Element *evals_acc = ¶ms.aux_trace[setupCtx.starkInfo.mapOffsets[std::make_pair("evals", true)]]; memset(&evals_acc[0], 0, num_threads * size_thread * sizeof(Goldilocks::Element)); Polinomial *ordPols = new Polinomial[size_eval]; @@ -253,7 +253,7 @@ void Starks::evmap(StepsParams& params, Goldilocks::Element *LEv) { EvMap ev = setupCtx.starkInfo.evMap[i]; string type = ev.type == EvMap::eType::cm ? "cm" : ev.type == EvMap::eType::custom ? "custom" : "fixed"; - Goldilocks::Element *pAddress = type == "cm" ? params.trace : type == "custom" ? params.pCustomCommitsExtended[ev.commitId] : ¶ms.pConstPolsExtendedTreeAddress[2]; + Goldilocks::Element *pAddress = type == "cm" ? params.aux_trace : type == "custom" ? params.pCustomCommitsExtended[ev.commitId] : ¶ms.pConstPolsExtendedTreeAddress[2]; PolMap polInfo = type == "cm" ? setupCtx.starkInfo.cmPolsMap[ev.id] : type == "custom" ? setupCtx.starkInfo.customCommitsMap[ev.commitId][ev.id] : setupCtx.starkInfo.constPolsMap[ev.id]; setupCtx.starkInfo.getPolynomial(ordPols[i], pAddress, type, polInfo, true); } @@ -341,7 +341,7 @@ void Starks::calculateImPolsExpressions(uint64_t step, StepsParams std::vector dests; for(uint64_t i = 0; i < setupCtx.starkInfo.cmPolsMap.size(); i++) { if(setupCtx.starkInfo.cmPolsMap[i].imPol && setupCtx.starkInfo.cmPolsMap[i].stage == step) { - Goldilocks::Element* pAddress = setupCtx.starkInfo.cmPolsMap[i].stage == 1 ? params.witness : params.trace; + Goldilocks::Element* pAddress = setupCtx.starkInfo.cmPolsMap[i].stage == 1 ? params.trace : params.aux_trace; Dest destStruct(&pAddress[setupCtx.starkInfo.mapOffsets[std::make_pair("cm" + to_string(step), false)] + setupCtx.starkInfo.cmPolsMap[i].stagePos], setupCtx.starkInfo.mapSectionsN["cm" + to_string(step)]); destStruct.addParams(setupCtx.expressionsBin.expressionsInfo[setupCtx.starkInfo.cmPolsMap[i].expId], false); @@ -371,7 +371,7 @@ void Starks::calculateQuotientPolynomial(StepsParams ¶ms) { #else ExpressionsPack expressionsCtx(setupCtx); #endif - expressionsCtx.calculateExpression(params, ¶ms.trace[setupCtx.starkInfo.mapOffsets[std::make_pair("q", true)]], setupCtx.starkInfo.cExpId); + expressionsCtx.calculateExpression(params, ¶ms.aux_trace[setupCtx.starkInfo.mapOffsets[std::make_pair("q", true)]], setupCtx.starkInfo.cExpId); } template @@ -383,5 +383,5 @@ void Starks::calculateFRIPolynomial(StepsParams ¶ms) { #else ExpressionsPack expressionsCtx(setupCtx); #endif - expressionsCtx.calculateExpression(params, ¶ms.trace[setupCtx.starkInfo.mapOffsets[std::make_pair("f", true)]], setupCtx.starkInfo.friExpId); + expressionsCtx.calculateExpression(params, ¶ms.aux_trace[setupCtx.starkInfo.mapOffsets[std::make_pair("f", true)]], setupCtx.starkInfo.friExpId); } \ No newline at end of file diff --git a/pil2-stark/src/starkpil/starks.hpp b/pil2-stark/src/starkpil/starks.hpp index ef4a8232..0f44e3aa 100644 --- a/pil2-stark/src/starkpil/starks.hpp +++ b/pil2-stark/src/starkpil/starks.hpp @@ -75,9 +75,9 @@ class Starks void extendAndMerkelizeCustomCommit(uint64_t commitId, uint64_t step, Goldilocks::Element *buffer, Goldilocks::Element *bufferExt, FRIProof &proof, Goldilocks::Element *pBuffHelper, string bufferFile); void loadCustomCommit(uint64_t commitId, uint64_t step, Goldilocks::Element *buffer, Goldilocks::Element *bufferExt, FRIProof &proof, string bufferFile); - void extendAndMerkelize(uint64_t step, Goldilocks::Element *witness, Goldilocks::Element *buffer, FRIProof &proof, Goldilocks::Element* pBuffHelper = nullptr); + void extendAndMerkelize(uint64_t step, Goldilocks::Element *trace, Goldilocks::Element *buffer, FRIProof &proof, Goldilocks::Element* pBuffHelper = nullptr); - void commitStage(uint64_t step, Goldilocks::Element *witness, Goldilocks::Element *buffer, FRIProof &proof, Goldilocks::Element* pBuffHelper = nullptr); + void commitStage(uint64_t step, Goldilocks::Element *trace, Goldilocks::Element *buffer, FRIProof &proof, Goldilocks::Element* pBuffHelper = nullptr); void computeQ(uint64_t step, Goldilocks::Element *buffer, FRIProof &proof, Goldilocks::Element* pBuffHelper = nullptr); void calculateImPolsExpressions(uint64_t step, StepsParams& params); diff --git a/pil2-stark/src/starkpil/steps.hpp b/pil2-stark/src/starkpil/steps.hpp index 9211e5f3..9575acd4 100644 --- a/pil2-stark/src/starkpil/steps.hpp +++ b/pil2-stark/src/starkpil/steps.hpp @@ -5,8 +5,8 @@ struct StepsParams { - Goldilocks::Element *witness; Goldilocks::Element *trace; + Goldilocks::Element *aux_trace; Goldilocks::Element *publicInputs; Goldilocks::Element *challenges; Goldilocks::Element *airgroupValues; diff --git a/proofman/src/witness_manager.rs b/proofman/src/witness_manager.rs index 30d33639..61c353d5 100644 --- a/proofman/src/witness_manager.rs +++ b/proofman/src/witness_manager.rs @@ -34,7 +34,7 @@ impl WitnessManager { self.register_air(airgroup_id, air_id, idx); } - pub fn register_std(&self, component: Arc>) { + pub fn register_proxy_component(&self, component: Arc>) { self.components.write().unwrap().push(component); } @@ -79,12 +79,12 @@ impl WitnessManager { let mut components = HashMap::new(); let airs = self.airs.read().unwrap(); for (air_instance_id, air_instance) in air_instances.iter().enumerate() { - let component = airs.get(&(air_instance.airgroup_id, air_instance.air_id)).unwrap(); - - components - .entry((air_instance.airgroup_id, air_instance.air_id)) - .or_insert_with(Vec::new) - .push((component, air_instance_id)); + if let Some(component) = airs.get(&(air_instance.airgroup_id, air_instance.air_id)) { + components + .entry((air_instance.airgroup_id, air_instance.air_id)) + .or_insert_with(Vec::new) + .push((component, air_instance_id)); + } } drop(air_instances); diff --git a/provers/stark/src/stark_prover.rs b/provers/stark/src/stark_prover.rs index 619d2143..00c06cec 100644 --- a/provers/stark/src/stark_prover.rs +++ b/provers/stark/src/stark_prover.rs @@ -90,13 +90,8 @@ impl Prover for StarkProver { fn build(&mut self, proof_ctx: Arc>) { let air_instance = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap()[self.prover_idx]; - let trace = create_buffer_fast(get_map_totaln_c(self.p_stark_info) as usize); - air_instance.set_trace(trace); - - //initialize the common challenges if have not been initialized by another prover - let challenges = - vec![F::zero(); self.stark_info.challenges_map.as_ref().unwrap().len() * Self::FIELD_EXTENSION]; - *proof_ctx.challenges.values.write().unwrap() = challenges; + let aux_trace = create_buffer_fast(get_map_totaln_c(self.p_stark_info) as usize); + air_instance.set_aux_trace(aux_trace); self.initialized = true; } @@ -124,8 +119,8 @@ impl Prover for StarkProver { let setup = setup_ctx.get_setup(self.airgroup_id, self.air_id); let steps_params = StepsParams { - witness: air_instance.get_witness_ptr(), trace: air_instance.get_trace_ptr(), + aux_trace: air_instance.get_aux_trace_ptr(), public_inputs: proof_ctx.get_publics_ptr(), challenges: proof_ctx.get_challenges_ptr(), airgroup_values: air_instance.get_airgroup_values_ptr(), @@ -153,8 +148,8 @@ impl Prover for StarkProver { let setup = setup_ctx.get_setup(self.airgroup_id, self.air_id); let steps_params = StepsParams { - witness: air_instance.get_witness_ptr(), trace: air_instance.get_trace_ptr(), + aux_trace: air_instance.get_aux_trace_ptr(), public_inputs: proof_ctx.get_publics_ptr(), challenges: proof_ctx.get_challenges_ptr(), airgroup_values: air_instance.get_airgroup_values_ptr(), @@ -223,7 +218,7 @@ impl Prover for StarkProver { timer_start_trace!(STARK_COMMIT_STAGE_, stage_id); let witness = match stage_id == 1 { - true => air_instance.get_witness_ptr(), + true => air_instance.get_trace_ptr(), false => std::ptr::null_mut(), }; @@ -234,7 +229,7 @@ impl Prover for StarkProver { element_type, stage_id as u64, witness, - air_instance.get_trace_ptr(), + air_instance.get_aux_trace_ptr(), p_proof, proof_ctx.get_buff_helper_ptr(), ); @@ -519,7 +514,7 @@ impl Prover for StarkProver { } else { let air_instance = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap()[self.prover_idx]; let n_hash = (1 << (steps[n_steps].n_bits)) * Self::FIELD_EXTENSION as u64; - let fri_pol = get_fri_pol_c(self.p_stark_info, air_instance.get_trace_ptr()); + let fri_pol = get_fri_pol_c(self.p_stark_info, air_instance.get_aux_trace_ptr()); calculate_hash_c(p_stark, value.as_mut_ptr() as *mut u8, fri_pol as *mut u8, n_hash); } } @@ -638,8 +633,8 @@ impl StarkProver { let p_proof = self.p_proof; let steps_params = StepsParams { - witness: std::ptr::null_mut(), - trace: air_instance.get_trace_ptr(), + trace: std::ptr::null_mut(), + aux_trace: air_instance.get_aux_trace_ptr(), public_inputs: std::ptr::null_mut(), challenges: std::ptr::null_mut(), airgroup_values: std::ptr::null_mut(), @@ -665,8 +660,8 @@ impl StarkProver { let p_stark = self.p_stark; let steps_params = StepsParams { - witness: std::ptr::null_mut(), - trace: air_instance.get_trace_ptr(), + trace: std::ptr::null_mut(), + aux_trace: air_instance.get_aux_trace_ptr(), public_inputs: proof_ctx.get_publics_ptr(), challenges: proof_ctx.get_challenges_ptr(), airgroup_values: air_instance.get_airgroup_values_ptr(), @@ -702,7 +697,7 @@ impl StarkProver { let air_instance = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap()[self.prover_idx]; - let fri_pol = get_fri_pol_c(self.p_stark_info, air_instance.get_trace_ptr()); + let fri_pol = get_fri_pol_c(self.p_stark_info, air_instance.get_aux_trace_ptr()); let challenges_guard = proof_ctx.challenges.values.read().unwrap(); let challenge: Vec = challenges_guard.iter().skip(challenges_guard.len() - 3).cloned().collect(); @@ -767,7 +762,7 @@ impl StarkProver { ); let air_instance = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap()[self.prover_idx]; - let fri_pol = get_fri_pol_c(self.p_stark_info, air_instance.get_trace_ptr()); + let fri_pol = get_fri_pol_c(self.p_stark_info, air_instance.get_aux_trace_ptr()); let n_trees = self.num_stages() + 2 + self.stark_info.custom_commits.len() as u32; compute_queries_c(p_stark, p_proof, fri_queries.as_mut_ptr(), n_queries, n_trees as u64); From 1a7578cf8bb6bbec54eb752e53ad2cd4c27b9a96 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Tue, 10 Dec 2024 10:09:14 +0000 Subject: [PATCH 27/64] Clippy fix --- common/src/proof_ctx.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/proof_ctx.rs b/common/src/proof_ctx.rs index 055f3c51..e0081c06 100644 --- a/common/src/proof_ctx.rs +++ b/common/src/proof_ctx.rs @@ -60,7 +60,7 @@ impl ProofCtx { let global_info: GlobalInfo = GlobalInfo::new(&proving_key_path); let n_publics = global_info.n_publics; let n_proof_values = global_info.n_proof_values; - let n_challenges = global_info.n_challenges.iter().fold(0, |acc, &x| acc + x); + let n_challenges = 4 + global_info.n_challenges.iter().sum::(); Self { global_info, From 2cc1a1cbdfec98d6a1c217c7513acd62d00fb2ef Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Tue, 10 Dec 2024 11:09:23 +0000 Subject: [PATCH 28/64] All tests pasing --- Cargo.lock | 47 +++++++++---------- common/src/lib.rs | 13 +---- common/src/utils.rs | 22 +++++++++ examples/fibonacci-square/src/fibonacci.rs | 15 ++++-- examples/fibonacci-square/src/module.rs | 10 ++-- .../test/simple/rs/src/simple_left.rs | 6 +-- .../test/simple/rs/src/simple_right.rs | 6 +-- .../test/std/connection/rs/src/connection1.rs | 6 +-- .../test/std/connection/rs/src/connection2.rs | 6 +-- .../std/connection/rs/src/connection_new.rs | 6 +-- .../test/std/lookup/rs/src/lookup0.rs | 6 +-- .../test/std/lookup/rs/src/lookup1.rs | 6 +-- .../test/std/lookup/rs/src/lookup2_12.rs | 6 +-- .../test/std/lookup/rs/src/lookup2_13.rs | 6 +-- .../test/std/lookup/rs/src/lookup2_15.rs | 6 +-- .../test/std/lookup/rs/src/lookup3.rs | 6 +-- .../std/permutation/rs/src/permutation1_6.rs | 8 ++-- .../std/permutation/rs/src/permutation1_7.rs | 6 +-- .../std/permutation/rs/src/permutation1_8.rs | 6 +-- .../std/permutation/rs/src/permutation2.rs | 6 +-- .../range_check/rs/src/multi_range_check1.rs | 6 +-- .../range_check/rs/src/multi_range_check2.rs | 6 +-- .../std/range_check/rs/src/range_check1.rs | 6 +-- .../std/range_check/rs/src/range_check2.rs | 6 +-- .../std/range_check/rs/src/range_check3.rs | 6 +-- .../std/range_check/rs/src/range_check4.rs | 6 +-- .../rs/src/range_check_dynamic1.rs | 6 +-- .../rs/src/range_check_dynamic2.rs | 6 +-- .../std/range_check/rs/src/range_check_mix.rs | 6 +-- provers/stark/src/stark_prover.rs | 4 -- 30 files changed, 135 insertions(+), 122 deletions(-) create mode 100644 common/src/utils.rs diff --git a/Cargo.lock b/Cargo.lock index 1e62d32a..f9a03335 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,9 +125,9 @@ checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" [[package]] name = "cc" -version = "1.2.2" +version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f34d93e62b03caf570cccc334cbc6c2fceca82f39211051345108adcba3eebdc" +checksum = "27f657647bcff5394bf56c7317665bbf790a137a50eaaa5c6bfbb9e27a518f2d" dependencies = [ "shlex", ] @@ -160,9 +160,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.22" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69371e34337c4c984bbe322360c2547210bf632eb2814bbe78a6e87a2935bd2b" +checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" dependencies = [ "clap_builder", "clap_derive", @@ -170,9 +170,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.22" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e24c1b4099818523236a8ca881d2b45db98dadfb4625cf6608c12069fcbbde1" +checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" dependencies = [ "anstream", "anstyle", @@ -194,9 +194,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "colorchoice" @@ -316,9 +316,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "fibonacci-square" @@ -447,9 +447,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.167" +version = "0.2.168" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" +checksum = "5aaeb2981e0606ca11d79718f8bb01164f1d6ed75080182d3abf017e6d244b6d" [[package]] name = "libffi" @@ -882,9 +882,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0487d90e047de87f984913713b85c601c05609aad5b0df4b4573fbf69aa13f" +checksum = "2c0fef6c4230e4ccf618a35c59d7ede15dea37de8427500f50aff708806e42ec" dependencies = [ "bytes", "prost-derive", @@ -892,11 +892,10 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c1318b19085f08681016926435853bbf7858f9c082d0999b80550ff5d9abe15" +checksum = "d0f3e5beed80eb580c68e2c600937ac2c4eedabdfd5ef1e5b7ea4f3fba84497b" dependencies = [ - "bytes", "heck", "itertools 0.13.0", "log", @@ -913,9 +912,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9552f850d5f0964a4e4d0bf306459ac29323ddfbae05e35a7c0d35cb0803cc5" +checksum = "157c5a9d7ea5c2ed2d9fb8f495b64759f7816c7eaea54ba3978f0d63000162e3" dependencies = [ "anyhow", "itertools 0.13.0", @@ -926,9 +925,9 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4759aa0d3a6232fb8dbdb97b61de2c20047c68aca932c7ed76da9d788508d670" +checksum = "cc2f1e56baa61e93533aebc21af4d2134b70f66275e0fcdf3cbe43d77ff7e8fc" dependencies = [ "prost", ] @@ -1029,15 +1028,15 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" -version = "0.38.41" +version = "0.38.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" +checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85" dependencies = [ "bitflags", "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/common/src/lib.rs b/common/src/lib.rs index b737f087..77e25c6d 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -14,10 +14,10 @@ mod publics; pub mod trace; pub mod global_info; pub mod stark_info; +pub mod utils; pub use air_instance::*; pub use air_instances_repository::*; -use proofman_starks_lib_c::set_log_level_c; pub use verbose_mode::*; pub use execution_ctx::*; pub use distribution_ctx::*; @@ -31,13 +31,4 @@ pub use custom_commits::*; pub use stark_info::*; pub use std_mode::*; pub use publics::*; - -pub fn initialize_logger(verbose_mode: VerboseMode) { - env_logger::builder() - .format_timestamp(None) - .format_level(true) - .format_target(false) - .filter_level(verbose_mode.into()) - .init(); - set_log_level_c(verbose_mode.into()); -} +pub use utils::*; diff --git a/common/src/utils.rs b/common/src/utils.rs new file mode 100644 index 00000000..25d4ed57 --- /dev/null +++ b/common/src/utils.rs @@ -0,0 +1,22 @@ +use crate::{AirInstance, ExecutionCtx, ProofCtx, VerboseMode}; +use proofman_starks_lib_c::set_log_level_c; +use std::sync::Arc; +use p3_field::Field; + +pub fn add_air_instance(air_instance: AirInstance, ectx: Arc, pctx: Arc>) { + let (is_mine, gid) = ectx.dctx.write().unwrap().add_instance(air_instance.airgroup_id, air_instance.air_id, 1); + + if is_mine { + pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); + } +} + +pub fn initialize_logger(verbose_mode: VerboseMode) { + env_logger::builder() + .format_timestamp(None) + .format_level(true) + .format_target(false) + .filter_level(verbose_mode.into()) + .init(); + set_log_level_c(verbose_mode.into()); +} diff --git a/examples/fibonacci-square/src/fibonacci.rs b/examples/fibonacci-square/src/fibonacci.rs index 3e19c8f1..b1ade1a8 100644 --- a/examples/fibonacci-square/src/fibonacci.rs +++ b/examples/fibonacci-square/src/fibonacci.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use proofman_common::{AirInstance, FromTrace, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, AirInstance, FromTrace, ExecutionCtx, ProofCtx, SetupCtx}; use proofman::{WitnessManager, WitnessComponent}; use p3_field::PrimeField64; @@ -29,13 +29,18 @@ impl FibonacciSquare { fibonacci } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { - if let Err(e) = Self::calculate_trace(self, pctx, sctx) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + if let Err(e) = Self::calculate_trace(self, pctx, ectx, sctx) { panic!("Failed to calculate fibonacci: {:?}", e); } } - fn calculate_trace(&self, pctx: Arc>, sctx: Arc) -> Result> { + fn calculate_trace( + &self, + pctx: Arc>, + ectx: Arc, + sctx: Arc, + ) -> Result> { log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let mut publics = BuildPublicValues::from_vec_guard(pctx.get_publics()); @@ -80,7 +85,7 @@ impl FibonacciSquare { sctx.clone(), FromTrace::new(&mut trace).with_custom_traces(vec![&mut trace_rom]).with_air_values(&mut air_values), ); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); Ok(b) } diff --git a/examples/fibonacci-square/src/module.rs b/examples/fibonacci-square/src/module.rs index 50601981..767e13c4 100644 --- a/examples/fibonacci-square/src/module.rs +++ b/examples/fibonacci-square/src/module.rs @@ -1,6 +1,6 @@ use std::sync::{Arc, Mutex}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use proofman::{WitnessManager, WitnessComponent}; use pil_std_lib::Std; use p3_field::{AbstractField, PrimeField64}; @@ -37,11 +37,11 @@ impl Module< x_mod } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { - self.calculate_trace(pctx, sctx); + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + self.calculate_trace(pctx, ectx, sctx); } - fn calculate_trace(&self, pctx: Arc>, sctx: Arc) { + fn calculate_trace(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let module = F::as_canonical_u64(&pctx.get_public_value("module")); @@ -72,7 +72,7 @@ impl Module< } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); self.std_lib.unregister_predecessor(pctx, None); } diff --git a/pil2-components/test/simple/rs/src/simple_left.rs b/pil2-components/test/simple/rs/src/simple_left.rs index 74ec8c5a..fdd515a7 100644 --- a/pil2-components/test/simple/rs/src/simple_left.rs +++ b/pil2-components/test/simple/rs/src/simple_left.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, seq::SliceRandom}; @@ -26,7 +26,7 @@ where simple_left } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = SimpleLeftTrace::new(); @@ -57,7 +57,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/simple/rs/src/simple_right.rs b/pil2-components/test/simple/rs/src/simple_right.rs index d2fcaa39..07e9262c 100644 --- a/pil2-components/test/simple/rs/src/simple_right.rs +++ b/pil2-components/test/simple/rs/src/simple_right.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution}; @@ -29,7 +29,7 @@ where simple_right } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut trace = SimpleRightTrace::new(); let num_rows = trace.num_rows(); @@ -47,7 +47,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/connection/rs/src/connection1.rs b/pil2-components/test/std/connection/rs/src/connection1.rs index 81e5ac3b..cca23170 100644 --- a/pil2-components/test/std/connection/rs/src/connection1.rs +++ b/pil2-components/test/std/connection/rs/src/connection1.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where connection1 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Connection1Trace::new_zeroes(); @@ -44,7 +44,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/connection/rs/src/connection2.rs b/pil2-components/test/std/connection/rs/src/connection2.rs index ebeffe6e..e97170fa 100644 --- a/pil2-components/test/std/connection/rs/src/connection2.rs +++ b/pil2-components/test/std/connection/rs/src/connection2.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where connection2 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Connection2Trace::new_zeroes(); @@ -46,7 +46,7 @@ where trace[0].a = trace[1].a; let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/connection/rs/src/connection_new.rs b/pil2-components/test/std/connection/rs/src/connection_new.rs index 5cb9c451..e74254a5 100644 --- a/pil2-components/test/std/connection/rs/src/connection_new.rs +++ b/pil2-components/test/std/connection/rs/src/connection_new.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where connection_new } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = ConnectionNewTrace::new_zeroes(); let num_rows = trace.num_rows(); @@ -137,7 +137,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup0.rs b/pil2-components/test/std/lookup/rs/src/lookup0.rs index 6e940321..9af9d722 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup0.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup0.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where lookup0 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup0Trace::new(); @@ -57,7 +57,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup1.rs b/pil2-components/test/std/lookup/rs/src/lookup1.rs index e33cda8c..db258833 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup1.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup1.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where lookup1 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup1Trace::new(); @@ -55,7 +55,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs index 9a96c0be..64fcb3f8 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where lookup2_12 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup2_12Trace::new(); @@ -67,7 +67,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs index 3dca3cf1..11c72e41 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where lookup2_13 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup2_13Trace::new(); @@ -67,7 +67,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs index 01c31dff..3931c522 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where lookup2_15 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup2_15Trace::new(); @@ -67,7 +67,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup3.rs b/pil2-components/test/std/lookup/rs/src/lookup3.rs index c7bba92c..99b53848 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup3.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup3.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; @@ -25,7 +25,7 @@ impl Lookup3 { lookup3 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { // For simplicity, add a single instance of each air let mut trace = Lookup3Trace::new(); let num_rows = trace.num_rows(); @@ -55,7 +55,7 @@ impl Lookup3 { } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs index 26041fbc..d9953bfe 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, seq::SliceRandom, Rng}; @@ -29,7 +29,7 @@ where permutation1_6 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Permutation1_6Trace::new(); @@ -74,7 +74,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx.clone(), pctx.clone()); let mut trace2 = Permutation1_6Trace::new(); @@ -112,7 +112,7 @@ where } let air_instance2 = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace2)); - pctx.air_instance_repo.add_air_instance(air_instance2, Some(0)); + add_air_instance::(air_instance2, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs index d00dd978..a9777baf 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where permutation1_7 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Permutation1_7Trace::new(); let num_rows = trace.num_rows(); @@ -74,7 +74,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs index 79d94991..ed926ace 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where permutation1_8 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Permutation1_8Trace::new(); let num_rows = trace.num_rows(); @@ -74,7 +74,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation2.rs b/pil2-components/test/std/permutation/rs/src/permutation2.rs index bf4bb9a5..ef238253 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation2.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation2.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use p3_field::PrimeField; @@ -25,7 +25,7 @@ impl Permutation2 { permutation2 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut trace = Permutation2_6Trace::new(); let num_rows = trace.num_rows(); @@ -46,7 +46,7 @@ impl Permutation2 { } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs index 6237b4c0..98edc8c2 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -34,7 +34,7 @@ where multi_range_check1 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = MultiRangeCheck1Trace::new_zeroes(); @@ -102,7 +102,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs index 37fe6137..ce07c6be 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -34,7 +34,7 @@ where multi_range_check2 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = MultiRangeCheck2Trace::new_zeroes(); @@ -84,7 +84,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check1.rs b/pil2-components/test/std/range_check/rs/src/range_check1.rs index c08f9fd9..645f8518 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check1.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -34,7 +34,7 @@ where range_check1 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck1Trace::new_zeroes(); @@ -81,7 +81,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check2.rs b/pil2-components/test/std/range_check/rs/src/range_check2.rs index 64554f95..2398773f 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check2.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -34,7 +34,7 @@ where range_check2 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck2Trace::new_zeroes(); let num_rows = trace.num_rows(); @@ -56,7 +56,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check3.rs b/pil2-components/test/std/range_check/rs/src/range_check3.rs index aa299c48..2a254d34 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check3.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check3.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -34,7 +34,7 @@ where range_check3 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck3Trace::new_zeroes(); @@ -54,7 +54,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check4.rs b/pil2-components/test/std/range_check/rs/src/range_check4.rs index 47a081b2..651e412e 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check4.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check4.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use num_bigint::BigInt; use num_traits::ToPrimitive; @@ -35,7 +35,7 @@ where range_check4 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck4Trace::new_zeroes(); @@ -102,7 +102,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs index 1882a188..40ac4b17 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -34,7 +34,7 @@ where range_check_dynamic1 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheckDynamic1Trace::new_zeroes(); @@ -80,7 +80,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs index bcf787aa..5cea35a1 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use num_bigint::BigInt; use num_traits::ToPrimitive; @@ -35,7 +35,7 @@ where range_check_dynamic2 } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheckDynamic2Trace::new_zeroes(); @@ -93,7 +93,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs index dde83fc9..89cecafd 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; use num_bigint::BigInt; use num_traits::ToPrimitive; @@ -35,7 +35,7 @@ where range_check_mix } - pub fn execute(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheckMixTrace::new_zeroes(); @@ -134,7 +134,7 @@ where } let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(0)); + add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/provers/stark/src/stark_prover.rs b/provers/stark/src/stark_prover.rs index 00c06cec..279f31a9 100644 --- a/provers/stark/src/stark_prover.rs +++ b/provers/stark/src/stark_prover.rs @@ -29,7 +29,6 @@ pub struct VecU64Result { #[allow(dead_code)] pub struct StarkProver { - initialized: bool, prover_idx: usize, air_id: usize, airgroup_id: usize, @@ -69,7 +68,6 @@ impl StarkProver { let p_proof = fri_proof_new_c((&setup.p_setup).into()); Self { - initialized: true, prover_idx, air_id, airgroup_id, @@ -92,8 +90,6 @@ impl Prover for StarkProver { let aux_trace = create_buffer_fast(get_map_totaln_c(self.p_stark_info) as usize); air_instance.set_aux_trace(aux_trace); - - self.initialized = true; } fn free(&mut self) { From c0625c6c5108cbdb239a900a91bdc1edf26b9df4 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Tue, 10 Dec 2024 12:10:25 +0000 Subject: [PATCH 29/64] Improving pil-helpers airvalues --- cli/src/commands/pil_helpers.rs | 6 +- common/src/air_instance.rs | 88 ++++++++++++------- examples/fibonacci-square/src/fibonacci.rs | 4 +- .../src/pil_helpers/traces.rs | 10 +-- pil2-stark/src/starkpil/expressions_avx.hpp | 15 +++- .../src/starkpil/expressions_avx512.hpp | 16 +++- pil2-stark/src/starkpil/expressions_pack.hpp | 19 ++-- pil2-stark/src/starkpil/proof_stark.hpp | 36 +++++--- provers/stark/src/stark_prover.rs | 50 +++++------ 9 files changed, 152 insertions(+), 92 deletions(-) diff --git a/cli/src/commands/pil_helpers.rs b/cli/src/commands/pil_helpers.rs index 47534bba..3b22e151 100644 --- a/cli/src/commands/pil_helpers.rs +++ b/cli/src/commands/pil_helpers.rs @@ -265,7 +265,11 @@ impl PilHelpersCmd { if air.air_values.is_empty() { air.air_values.push(ValuesCtx { values: Vec::new(), values_u64: Vec::new() }); } - air.air_values[0].values.push(ColumnCtx { name: name.to_owned(), r#type: ext_type }); + if symbol.stage == Some(1) { + air.air_values[0].values.push(ColumnCtx { name: name.to_owned(), r#type }); + } else { + air.air_values[0].values.push(ColumnCtx { name: name.to_owned(), r#type: ext_type }); + } } else if symbol.r#type == SymbolType::AirGroupValue as i32 { if air.airgroup_values.is_empty() { air.airgroup_values.push(ValuesCtx { values: Vec::new(), values_u64: Vec::new() }); diff --git a/common/src/air_instance.rs b/common/src/air_instance.rs index 0d6bba36..c6e3f057 100644 --- a/common/src/air_instance.rs +++ b/common/src/air_instance.rs @@ -257,54 +257,78 @@ impl AirInstance { pub fn set_airvalue(&mut self, name: &str, lengths: Option>, value: F) { let airvalues_map = self.stark_info.airvalues_map.as_ref().unwrap(); - let airvalue_id = (0..airvalues_map.len()) - .find(|&i| { - let airvalue = airvalues_map.get(i).unwrap(); - - // Check if name matches - let name_matches = airvalues_map[i].name == name; + let mut id = 0; + let mut found = false; + for air_value in airvalues_map { + // Check if name matches + let name_matches = air_value.name == name; + + + // If lengths is provided, check that it matches airvalue.lengths + let lengths_match = if let Some(ref provided_lengths) = lengths { + Some(&air_value.lengths) == Some(provided_lengths) + } else { + true // If lengths is None, skip the lengths check + }; - // If lengths is provided, check that it matches airvalue.lengths - let lengths_match = if let Some(ref provided_lengths) = lengths { - Some(&airvalue.lengths) == Some(provided_lengths) + if !name_matches || !lengths_match { + if air_value.stage == 1 { + id += 1; } else { - true // If lengths is None, skip the lengths check - }; + id += 3; + } + } else { + found = true; + break; + } + } - name_matches && lengths_match - }) - .unwrap_or_else(|| panic!("Name {} with specified lengths {:?} not found in airvalues", name, lengths)); + if !found { + panic!("Name {} with specified lengths {:?} not found in airvalues", name, lengths); + } - self.airvalues[airvalue_id * 3] = value; + self.airvalues[id] = value; } pub fn set_airvalue_ext(&mut self, name: &str, lengths: Option>, value: Vec) { let airvalues_map = self.stark_info.airvalues_map.as_ref().unwrap(); - let airvalue_id = (0..airvalues_map.len()) - .find(|&i| { - let airvalue = airvalues_map.get(i).unwrap(); - - // Check if name matches - let name_matches = airvalues_map[i].name == name; + let mut id = 0; + let mut found = false; + for air_value in airvalues_map { + // Check if name matches + let name_matches = air_value.name == name; + + + // If lengths is provided, check that it matches airvalue.lengths + let lengths_match = if let Some(ref provided_lengths) = lengths { + Some(&air_value.lengths) == Some(provided_lengths) + } else { + true // If lengths is None, skip the lengths check + }; - // If lengths is provided, check that it matches airvalue.lengths - let lengths_match = if let Some(ref provided_lengths) = lengths { - Some(&airvalue.lengths) == Some(provided_lengths) + if !name_matches || !lengths_match { + if air_value.stage == 1 { + id += 1; } else { - true // If lengths is None, skip the lengths check - }; + id += 3; + } + } else { + found = true; + break; + } + } - name_matches && lengths_match - }) - .unwrap_or_else(|| panic!("Name {} with specified lengths {:?} not found in airvalues", name, lengths)); + if !found { + panic!("Name {} with specified lengths {:?} not found in airvalues", name, lengths); + } assert!(value.len() == 3, "Value vector must have exactly 3 elements"); let mut value_iter = value.into_iter(); - self.airvalues[airvalue_id * 3] = value_iter.next().unwrap(); - self.airvalues[airvalue_id * 3 + 1] = value_iter.next().unwrap(); - self.airvalues[airvalue_id * 3 + 2] = value_iter.next().unwrap(); + self.airvalues[id] = value_iter.next().unwrap(); + self.airvalues[id + 1] = value_iter.next().unwrap(); + self.airvalues[id + 2] = value_iter.next().unwrap(); } pub fn set_airgroupvalue(&mut self, name: &str, lengths: Option>, value: F) { diff --git a/examples/fibonacci-square/src/fibonacci.rs b/examples/fibonacci-square/src/fibonacci.rs index b1ade1a8..54a831e5 100644 --- a/examples/fibonacci-square/src/fibonacci.rs +++ b/examples/fibonacci-square/src/fibonacci.rs @@ -77,8 +77,8 @@ impl FibonacciSquare { proof_values.value2[0] = F::from_canonical_u64(125); let mut air_values = FibonacciSquareAirValues::::new(); - air_values.fibo1[0][0] = F::from_canonical_u64(1); - air_values.fibo1[1][0] = F::from_canonical_u64(2); + air_values.fibo1[0] = F::from_canonical_u64(1); + air_values.fibo1[1] = F::from_canonical_u64(2); air_values.fibo3 = [F::from_canonical_u64(5), F::from_canonical_u64(5), F::from_canonical_u64(5)]; let air_instance = AirInstance::new_from_trace( diff --git a/examples/fibonacci-square/src/pil_helpers/traces.rs b/examples/fibonacci-square/src/pil_helpers/traces.rs index fd3ac7f5..c537e313 100644 --- a/examples/fibonacci-square/src/pil_helpers/traces.rs +++ b/examples/fibonacci-square/src/pil_helpers/traces.rs @@ -4,7 +4,7 @@ use proofman_common as common; pub use proofman_macros::trace; pub use proofman_macros::values; -#[warn(dead_code)] +#[allow(dead_code)] type FieldExtension = [F; 3]; pub const PILOUT_HASH: &[u8] = b"Build-hash"; @@ -50,20 +50,20 @@ values!(BuildProofValues { trace!(FibonacciSquareTrace { a: F, b: F, -}, 0, 0, 1024, 0 ); +}, 0, 0, 1024 ); trace!(ModuleTrace { x: F, q: F, x_mod: F, -}, 0, 1, 1024, 0 ); +}, 0, 1, 1024 ); trace!(U8AirTrace { mul: F, -}, 0, 2, 256, 0 ); +}, 0, 2, 256 ); trace!(FibonacciSquareRomTrace { line: F, flags: F, }, 0, 0, 1024, 0 ); values!(FibonacciSquareAirValues { - fibo1: [FieldExtension; 2], fibo3: FieldExtension, + fibo1: [F; 2], fibo3: FieldExtension, }); diff --git a/pil2-stark/src/starkpil/expressions_avx.hpp b/pil2-stark/src/starkpil/expressions_avx.hpp index f03d5c5e..8086c567 100644 --- a/pil2-stark/src/starkpil/expressions_avx.hpp +++ b/pil2-stark/src/starkpil/expressions_avx.hpp @@ -313,10 +313,19 @@ class ExpressionsAvx : public ExpressionsCtx { } Goldilocks3::Element_avx airValues[setupCtx.starkInfo.airValuesMap.size()]; + uint64_t p = 0; for(uint64_t i = 0; i < setupCtx.starkInfo.airValuesMap.size(); ++i) { - airValues[i][0] = _mm256_set1_epi64x(params.airValues[i * FIELD_EXTENSION].fe); - airValues[i][1] = _mm256_set1_epi64x(params.airValues[i * FIELD_EXTENSION + 1].fe); - airValues[i][2] = _mm256_set1_epi64x(params.airValues[i * FIELD_EXTENSION + 2].fe); + if(setupCtx.starkInfo.airValuesMap[i].stage == 1) { + airValues[i][0] = _mm256_set1_epi64x(params.airValues[p].fe); + airValues[i][1] = _mm256_set1_epi64x(0); + airValues[i][2] = _mm256_set1_epi64x(0); + p += 1; + } else { + airValues[i][0] = _mm256_set1_epi64x(params.airValues[p].fe); + airValues[i][1] = _mm256_set1_epi64x(params.airValues[p + 1].fe); + airValues[i][2] = _mm256_set1_epi64x(params.airValues[p + 2].fe); + p += 3; + } } Goldilocks3::Element_avx evals[setupCtx.starkInfo.evMap.size()]; diff --git a/pil2-stark/src/starkpil/expressions_avx512.hpp b/pil2-stark/src/starkpil/expressions_avx512.hpp index 664313fe..9655106f 100644 --- a/pil2-stark/src/starkpil/expressions_avx512.hpp +++ b/pil2-stark/src/starkpil/expressions_avx512.hpp @@ -311,11 +311,19 @@ class ExpressionsAvx512 : public ExpressionsCtx { airgroupValues[i][2] = _mm512_set1_epi64(params.airgroupValues[i * FIELD_EXTENSION + 2].fe); } - Goldilocks3::Element_avx512 airValues[setupCtx.starkInfo.airValuesMap.size()]; + uint64_t p = 0; for(uint64_t i = 0; i < setupCtx.starkInfo.airValuesMap.size(); ++i) { - airValues[i][0] = _mm512_set1_epi64(params.airValues[i * FIELD_EXTENSION].fe); - airValues[i][1] = _mm512_set1_epi64(params.airValues[i * FIELD_EXTENSION + 1].fe); - airValues[i][2] = _mm512_set1_epi64(params.airValues[i * FIELD_EXTENSION + 2].fe); + if(setupCtx.starkInfo.airValuesMap[i].stage == 1) { + airValues[i][0] = _mm512_set1_epi64x(params.airValues[p].fe); + airValues[i][1] = _mm512_set1_epi64x(0); + airValues[i][2] = _mm512_set1_epi64x(0); + p += 1; + } else { + airValues[i][0] = _mm512_set1_epi64x(params.airValues[p].fe); + airValues[i][1] = _mm512_set1_epi64x(params.airValues[p + 1].fe); + airValues[i][2] = _mm512_set1_epi64x(params.airValues[p + 2].fe); + p += 3; + } } Goldilocks3::Element_avx512 evals[setupCtx.starkInfo.evMap.size()]; diff --git a/pil2-stark/src/starkpil/expressions_pack.hpp b/pil2-stark/src/starkpil/expressions_pack.hpp index 43460400..0e37c210 100644 --- a/pil2-stark/src/starkpil/expressions_pack.hpp +++ b/pil2-stark/src/starkpil/expressions_pack.hpp @@ -330,17 +330,26 @@ class ExpressionsPack : public ExpressionsCtx { } Goldilocks::Element airValues[setupCtx.starkInfo.airValuesMap.size()*FIELD_EXTENSION*nrowsPack]; + uint64_t p = 0; if(!compilation_time) { for(uint64_t i = 0; i < setupCtx.starkInfo.airValuesMap.size(); ++i) { for(uint64_t j = 0; j < nrowsPack; ++j) { - airValues[(i*FIELD_EXTENSION)*nrowsPack + j] = params.airValues[i * FIELD_EXTENSION]; - airValues[(i*FIELD_EXTENSION + 1)*nrowsPack + j] = params.airValues[i * FIELD_EXTENSION + 1]; - airValues[(i*FIELD_EXTENSION + 2)*nrowsPack + j] = params.airValues[i * FIELD_EXTENSION + 2]; + if(setupCtx.starkInfo.airValuesMap[i].stage == 1) { + airValues[(i*FIELD_EXTENSION)*nrowsPack + j] = params.airValues[p]; + airValues[(i*FIELD_EXTENSION + 1)*nrowsPack + j] = Goldilocks::zero(); + airValues[(i*FIELD_EXTENSION + 2)*nrowsPack + j] = Goldilocks::zero(); + p += 1; + } else { + airValues[(i*FIELD_EXTENSION)*nrowsPack + j] = params.airValues[p]; + airValues[(i*FIELD_EXTENSION + 1)*nrowsPack + j] = params.airValues[p + 1]; + airValues[(i*FIELD_EXTENSION + 2)*nrowsPack + j] = params.airValues[p + 2]; + p += 3; + } } } - } + } - // #pragma omp parallel for + #pragma omp parallel for for (uint64_t i = 0; i < domainSize; i+= nrowsPack) { Goldilocks::Element bufferT_[nOpenings*nCols*nrowsPack]; diff --git a/pil2-stark/src/starkpil/proof_stark.hpp b/pil2-stark/src/starkpil/proof_stark.hpp index 73dd1b46..04226727 100644 --- a/pil2-stark/src/starkpil/proof_stark.hpp +++ b/pil2-stark/src/starkpil/proof_stark.hpp @@ -198,6 +198,7 @@ template class Proofs { public: + StarkInfo &starkInfo; uint64_t nStages; uint64_t nCustomCommits; uint64_t nFieldElements; @@ -209,19 +210,20 @@ class Proofs std::vector> airgroupValues; std::vector> airValues; std::vector customCommits; - Proofs(StarkInfo &starkInfo) : - fri(starkInfo), - evals(starkInfo.evMap.size(), std::vector(FIELD_EXTENSION, Goldilocks::zero())), - airgroupValues(starkInfo.airgroupValuesMap.size(), std::vector(FIELD_EXTENSION, Goldilocks::zero())), - airValues(starkInfo.airValuesMap.size(), std::vector(FIELD_EXTENSION, Goldilocks::zero())), - customCommits(starkInfo.customCommits.size()) + Proofs(StarkInfo &starkInfo_) : + starkInfo(starkInfo_), + fri(starkInfo_), + evals(starkInfo_.evMap.size(), std::vector(FIELD_EXTENSION, Goldilocks::zero())), + airgroupValues(starkInfo_.airgroupValuesMap.size(), std::vector(FIELD_EXTENSION, Goldilocks::zero())), + airValues(starkInfo_.airValuesMap.size(), std::vector(FIELD_EXTENSION, Goldilocks::zero())), + customCommits(starkInfo_.customCommits.size()) { - nStages = starkInfo.nStages + 1; - nCustomCommits = starkInfo.customCommits.size(); + nStages = starkInfo_.nStages + 1; + nCustomCommits = starkInfo_.customCommits.size(); roots = new ElementType*[nStages + nCustomCommits]; - nFieldElements = starkInfo.starkStruct.verificationHashType == "GL" ? HASH_SIZE : 1; - airId = starkInfo.airId; - airgroupId = starkInfo.airgroupId; + nFieldElements = starkInfo_.starkStruct.verificationHashType == "GL" ? HASH_SIZE : 1; + airId = starkInfo_.airId; + airgroupId = starkInfo_.airgroupId; for(uint64_t i = 0; i < nStages + nCustomCommits; i++) { roots[i] = new ElementType[nFieldElements]; @@ -254,9 +256,17 @@ class Proofs } void setAirValues(Goldilocks::Element *_airValues) { - for (uint64_t i = 0; i < airValues.size(); i++) + uint64_t p = 0; + for (uint64_t i = 0; i < starkInfo.airValuesMap.size(); i++) { - std::memcpy(&airValues[i][0], &_airValues[i * FIELD_EXTENSION], FIELD_EXTENSION * sizeof(Goldilocks::Element)); + if(starkInfo.airValuesMap[i].stage == 1) { + airValues[i][0] = _airValues[p++]; + airValues[i][1] = Goldilocks::zero(); + airValues[i][2] = Goldilocks::zero(); + } else { + std::memcpy(&airValues[i][0], &_airValues[p], FIELD_EXTENSION * sizeof(Goldilocks::Element)); + p += 3; + } } } diff --git a/provers/stark/src/stark_prover.rs b/provers/stark/src/stark_prover.rs index 279f31a9..5b937766 100644 --- a/provers/stark/src/stark_prover.rs +++ b/provers/stark/src/stark_prover.rs @@ -401,28 +401,16 @@ impl Prover for StarkProver { let mut value = vec![Goldilocks::zero(); self.n_field_elements]; if stage <= (Self::num_stages(self) + 1) as u64 { - let (n_airvals_stage, indexes): (usize, Vec) = self + let n_airvals_stage: usize = self .stark_info .airvalues_map .as_ref() .map(|map| { - let mut indexes = Vec::new(); - let count = map - .iter() - .enumerate() - .filter(|(index, entry)| { - if entry.stage == stage { - indexes.push(*index); - true - } else { - false - } - }) - .count(); - - (count, indexes) + map.iter() + .filter(|entry| entry.stage == stage) + .count() }) - .unwrap_or((0, Vec::new())); + .unwrap_or(0); if stage == 1 || n_airvals_stage > 0 { let size = if stage == 1 { @@ -462,17 +450,25 @@ impl Prover for StarkProver { values_hash[index] = root_value; } let air_instance = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap()[self.prover_idx]; - for index in 0..n_airvals_stage { - if stage == 1 { - values_hash[2 * self.n_field_elements + index] = - air_instance.airvalues[indexes[index] * Self::FIELD_EXTENSION]; + let airvalues_map = self.stark_info.airvalues_map.as_ref().unwrap(); + let mut p = 0; + let mut count = 0; + for air_value in airvalues_map { + if air_value.stage > stage { break; } + if air_value.stage == 1 { + if stage == 1 { + values_hash[2 * self.n_field_elements + count] = air_instance.airvalues[p]; + count+=1; + } + p+=1; } else { - values_hash[self.n_field_elements + index * Self::FIELD_EXTENSION] = - air_instance.airvalues[indexes[index] * Self::FIELD_EXTENSION]; - values_hash[self.n_field_elements + index * Self::FIELD_EXTENSION + 1] = - air_instance.airvalues[indexes[index] * Self::FIELD_EXTENSION]; - values_hash[self.n_field_elements + index * Self::FIELD_EXTENSION + 2] = - air_instance.airvalues[indexes[index] * Self::FIELD_EXTENSION]; + if air_value.stage == stage { + values_hash[self.n_field_elements + count] = air_instance.airvalues[p]; + values_hash[self.n_field_elements + count + 1] = air_instance.airvalues[p + 1]; + values_hash[self.n_field_elements + count + 2] = air_instance.airvalues[p + 2]; + count += 3; + } + p+= 3; } } From dd6e4c5fe63eee0e47ea599a94b0a7a99ab3b447 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Tue, 10 Dec 2024 12:47:00 +0000 Subject: [PATCH 30/64] Fixing airgroupvalues to be compatible with new airvalues handling --- common/src/air_instance.rs | 102 ++++-------------- pil2-stark/src/starkpil/expressions_avx.hpp | 17 ++- .../src/starkpil/expressions_avx512.hpp | 18 +++- pil2-stark/src/starkpil/expressions_pack.hpp | 17 ++- pil2-stark/src/starkpil/proof_stark.hpp | 12 ++- 5 files changed, 72 insertions(+), 94 deletions(-) diff --git a/common/src/air_instance.rs b/common/src/air_instance.rs index c6e3f057..e4b6e6f9 100644 --- a/common/src/air_instance.rs +++ b/common/src/air_instance.rs @@ -1,9 +1,10 @@ use std::sync::Arc; +use std::ptr; use std::path::PathBuf; use p3_field::Field; use proofman_util::create_buffer_fast; -use crate::{trace::Trace, trace::Values, SetupCtx, Setup, StarkInfo}; +use crate::{trace::Trace, trace::Values, SetupCtx, Setup, StarkInfo, PolMap}; #[repr(C)] pub struct StepsParams { @@ -41,11 +42,12 @@ impl Default for StepsParams { p_const_pols: ptr::null_mut(), p_const_tree: ptr::null_mut(), custom_commits: [ptr::null_mut(); 10], + custom_commits_extended: [ptr::null_mut(); 10], } } } -#[derive(Default)] +#[derive(Default, Clone)] pub struct CustomCommitsInfo { pub buffer: Vec, pub cached_file: PathBuf, @@ -255,24 +257,23 @@ impl AirInstance { self.custom_commits[commit_id as usize].buffer = buffer; } - pub fn set_airvalue(&mut self, name: &str, lengths: Option>, value: F) { - let airvalues_map = self.stark_info.airvalues_map.as_ref().unwrap(); + fn find_value_map(values_map: &Vec, name: &str, lengths: Option>) -> usize { let mut id = 0; let mut found = false; - for air_value in airvalues_map { + for value in values_map { // Check if name matches - let name_matches = air_value.name == name; + let name_matches = value.name == name; // If lengths is provided, check that it matches airvalue.lengths let lengths_match = if let Some(ref provided_lengths) = lengths { - Some(&air_value.lengths) == Some(provided_lengths) + Some(&value.lengths) == Some(provided_lengths) } else { true // If lengths is None, skip the lengths check }; if !name_matches || !lengths_match { - if air_value.stage == 1 { + if value.stage == 1 { id += 1; } else { id += 3; @@ -287,40 +288,18 @@ impl AirInstance { panic!("Name {} with specified lengths {:?} not found in airvalues", name, lengths); } + id + } + + pub fn set_airvalue(&mut self, name: &str, lengths: Option>, value: F) { + let airvalues_map = self.stark_info.airvalues_map.as_ref().unwrap(); + let id = Self::find_value_map(airvalues_map, name, lengths); self.airvalues[id] = value; } pub fn set_airvalue_ext(&mut self, name: &str, lengths: Option>, value: Vec) { let airvalues_map = self.stark_info.airvalues_map.as_ref().unwrap(); - let mut id = 0; - let mut found = false; - for air_value in airvalues_map { - // Check if name matches - let name_matches = air_value.name == name; - - - // If lengths is provided, check that it matches airvalue.lengths - let lengths_match = if let Some(ref provided_lengths) = lengths { - Some(&air_value.lengths) == Some(provided_lengths) - } else { - true // If lengths is None, skip the lengths check - }; - - if !name_matches || !lengths_match { - if air_value.stage == 1 { - id += 1; - } else { - id += 3; - } - } else { - found = true; - break; - } - } - - if !found { - panic!("Name {} with specified lengths {:?} not found in airvalues", name, lengths); - } + let id = Self::find_value_map(airvalues_map, name, lengths); assert!(value.len() == 3, "Value vector must have exactly 3 elements"); @@ -333,58 +312,21 @@ impl AirInstance { pub fn set_airgroupvalue(&mut self, name: &str, lengths: Option>, value: F) { let airgroupvalues_map = self.stark_info.airgroupvalues_map.as_ref().unwrap(); - let airgroupvalue_id = (0..airgroupvalues_map.len()) - .find(|&i| { - let airgroupvalue = airgroupvalues_map.get(i).unwrap(); - - // Check if name matches - let name_matches = airgroupvalues_map[i].name == name; - - // If lengths is provided, check that it matches airgroupvalues.lengths - let lengths_match = if let Some(ref provided_lengths) = lengths { - Some(&airgroupvalue.lengths) == Some(provided_lengths) - } else { - true // If lengths is None, skip the lengths check - }; - - name_matches && lengths_match - }) - .unwrap_or_else(|| { - panic!("Name {} with specified lengths {:?} not found in airgroupvalues", name, lengths) - }); - - self.airgroup_values[airgroupvalue_id * 3] = value; + let id = Self::find_value_map(airgroupvalues_map, name, lengths); + self.airgroup_values[id] = value; } pub fn set_airgroupvalue_ext(&mut self, name: &str, lengths: Option>, value: Vec) { let airgroupvalues_map = self.stark_info.airgroupvalues_map.as_ref().unwrap(); - let airgroupvalue_id = (0..airgroupvalues_map.len()) - .find(|&i| { - let airgroupvalue = airgroupvalues_map.get(i).unwrap(); - - // Check if name matches - let name_matches = airgroupvalues_map[i].name == name; - - // If lengths is provided, check that it matches airgroupvalues.lengths - let lengths_match = if let Some(ref provided_lengths) = lengths { - Some(&airgroupvalue.lengths) == Some(provided_lengths) - } else { - true // If lengths is None, skip the lengths check - }; - - name_matches && lengths_match - }) - .unwrap_or_else(|| { - panic!("Name {} with specified lengths {:?} not found in airgroupvalues", name, lengths) - }); + let id = Self::find_value_map(airgroupvalues_map, name, lengths); assert!(value.len() == 3, "Value vector must have exactly 3 elements"); let mut value_iter = value.into_iter(); - self.airgroup_values[airgroupvalue_id * 3] = value_iter.next().unwrap(); - self.airgroup_values[airgroupvalue_id * 3 + 1] = value_iter.next().unwrap(); - self.airgroup_values[airgroupvalue_id * 3 + 2] = value_iter.next().unwrap(); + self.airgroup_values[id] = value_iter.next().unwrap(); + self.airgroup_values[id + 1] = value_iter.next().unwrap(); + self.airgroup_values[id + 2] = value_iter.next().unwrap(); } pub fn set_air_instance_id(&mut self, air_instance_id: usize, idx: usize) { diff --git a/pil2-stark/src/starkpil/expressions_avx.hpp b/pil2-stark/src/starkpil/expressions_avx.hpp index 8086c567..f416d515 100644 --- a/pil2-stark/src/starkpil/expressions_avx.hpp +++ b/pil2-stark/src/starkpil/expressions_avx.hpp @@ -306,14 +306,23 @@ class ExpressionsAvx : public ExpressionsCtx { } Goldilocks3::Element_avx airgroupValues[setupCtx.starkInfo.airgroupValuesMap.size()]; + uint64_t p = 0; for(uint64_t i = 0; i < setupCtx.starkInfo.airgroupValuesMap.size(); ++i) { - airgroupValues[i][0] = _mm256_set1_epi64x(params.airgroupValues[i * FIELD_EXTENSION].fe); - airgroupValues[i][1] = _mm256_set1_epi64x(params.airgroupValues[i * FIELD_EXTENSION + 1].fe); - airgroupValues[i][2] = _mm256_set1_epi64x(params.airgroupValues[i * FIELD_EXTENSION + 2].fe); + if(setupCtx.starkInfo.airgroupValuesMap[i].stage == 1) { + airgroupValues[i][0] = _mm256_set1_epi64x(params.airgroupValues[p].fe); + airgroupValues[i][1] = _mm256_set1_epi64x(0); + airgroupValues[i][2] = _mm256_set1_epi64x(0); + p += 1; + } else { + airgroupValues[i][0] = _mm256_set1_epi64x(params.airgroupValues[p].fe); + airgroupValues[i][1] = _mm256_set1_epi64x(params.airgroupValues[p + 1].fe); + airgroupValues[i][2] = _mm256_set1_epi64x(params.airgroupValues[p + 2].fe); + p += 3; + } } Goldilocks3::Element_avx airValues[setupCtx.starkInfo.airValuesMap.size()]; - uint64_t p = 0; + p = 0; for(uint64_t i = 0; i < setupCtx.starkInfo.airValuesMap.size(); ++i) { if(setupCtx.starkInfo.airValuesMap[i].stage == 1) { airValues[i][0] = _mm256_set1_epi64x(params.airValues[p].fe); diff --git a/pil2-stark/src/starkpil/expressions_avx512.hpp b/pil2-stark/src/starkpil/expressions_avx512.hpp index 9655106f..fbf474f6 100644 --- a/pil2-stark/src/starkpil/expressions_avx512.hpp +++ b/pil2-stark/src/starkpil/expressions_avx512.hpp @@ -305,13 +305,23 @@ class ExpressionsAvx512 : public ExpressionsCtx { } Goldilocks3::Element_avx512 airgroupValues[setupCtx.starkInfo.airgroupValuesMap.size()]; + uint64_t p = 0; for(uint64_t i = 0; i < setupCtx.starkInfo.airgroupValuesMap.size(); ++i) { - airgroupValues[i][0] = _mm512_set1_epi64(params.airgroupValues[i * FIELD_EXTENSION].fe); - airgroupValues[i][1] = _mm512_set1_epi64(params.airgroupValues[i * FIELD_EXTENSION + 1].fe); - airgroupValues[i][2] = _mm512_set1_epi64(params.airgroupValues[i * FIELD_EXTENSION + 2].fe); + if(setupCtx.starkInfo.airgroupValuesMap[i].stage == 1) { + airgroupValues[i][0] = _mm512_set1_epi64x(params.airgroupValues[p].fe); + airgroupValues[i][1] = _mm512_set1_epi64x(0); + airgroupValues[i][2] = _mm512_set1_epi64x(0); + p += 1; + } else { + airgroupValues[i][0] = _mm512_set1_epi64x(params.airgroupValues[p].fe); + airgroupValues[i][1] = _mm512_set1_epi64x(params.airgroupValues[p + 1].fe); + airgroupValues[i][2] = _mm512_set1_epi64x(params.airgroupValues[p + 2].fe); + p += 3; + } } - uint64_t p = 0; + Goldilocks3::Element_avx512 airValues[setupCtx.starkInfo.airValuesMap.size()]; + p = 0; for(uint64_t i = 0; i < setupCtx.starkInfo.airValuesMap.size(); ++i) { if(setupCtx.starkInfo.airValuesMap[i].stage == 1) { airValues[i][0] = _mm512_set1_epi64x(params.airValues[p].fe); diff --git a/pil2-stark/src/starkpil/expressions_pack.hpp b/pil2-stark/src/starkpil/expressions_pack.hpp index 0e37c210..014f86c9 100644 --- a/pil2-stark/src/starkpil/expressions_pack.hpp +++ b/pil2-stark/src/starkpil/expressions_pack.hpp @@ -319,18 +319,27 @@ class ExpressionsPack : public ExpressionsCtx { } Goldilocks::Element airgroupValues[setupCtx.starkInfo.airgroupValuesMap.size()*FIELD_EXTENSION*nrowsPack]; + uint64_t p = 0; if(!compilation_time) { for(uint64_t i = 0; i < setupCtx.starkInfo.airgroupValuesMap.size(); ++i) { for(uint64_t j = 0; j < nrowsPack; ++j) { - airgroupValues[(i*FIELD_EXTENSION)*nrowsPack + j] = params.airgroupValues[i * FIELD_EXTENSION]; - airgroupValues[(i*FIELD_EXTENSION + 1)*nrowsPack + j] = params.airgroupValues[i * FIELD_EXTENSION + 1]; - airgroupValues[(i*FIELD_EXTENSION + 2)*nrowsPack + j] = params.airgroupValues[i * FIELD_EXTENSION + 2]; + if(setupCtx.starkInfo.airgroupValuesMap[i].stage == 1) { + airgroupValues[(i*FIELD_EXTENSION)*nrowsPack + j] = params.airgroupValues[p]; + airgroupValues[(i*FIELD_EXTENSION + 1)*nrowsPack + j] = Goldilocks::zero(); + airgroupValues[(i*FIELD_EXTENSION + 2)*nrowsPack + j] = Goldilocks::zero(); + p += 1; + } else { + airgroupValues[(i*FIELD_EXTENSION)*nrowsPack + j] = params.airgroupValues[p]; + airgroupValues[(i*FIELD_EXTENSION + 1)*nrowsPack + j] = params.airgroupValues[p + 1]; + airgroupValues[(i*FIELD_EXTENSION + 2)*nrowsPack + j] = params.airgroupValues[p + 2]; + p += 3; + } } } } Goldilocks::Element airValues[setupCtx.starkInfo.airValuesMap.size()*FIELD_EXTENSION*nrowsPack]; - uint64_t p = 0; + p = 0; if(!compilation_time) { for(uint64_t i = 0; i < setupCtx.starkInfo.airValuesMap.size(); ++i) { for(uint64_t j = 0; j < nrowsPack; ++j) { diff --git a/pil2-stark/src/starkpil/proof_stark.hpp b/pil2-stark/src/starkpil/proof_stark.hpp index 04226727..5ac3da07 100644 --- a/pil2-stark/src/starkpil/proof_stark.hpp +++ b/pil2-stark/src/starkpil/proof_stark.hpp @@ -249,9 +249,17 @@ class Proofs } void setAirgroupValues(Goldilocks::Element *_airgroupValues) { - for (uint64_t i = 0; i < airgroupValues.size(); i++) + uint64_t p = 0; + for (uint64_t i = 0; i < starkInfo.airgroupValuesMap.size(); i++) { - std::memcpy(&airgroupValues[i][0], &_airgroupValues[i * FIELD_EXTENSION], FIELD_EXTENSION * sizeof(Goldilocks::Element)); + if(starkInfo.airgroupValuesMap[i].stage == 1) { + airgroupValues[i][0] = _airgroupValues[p++]; + airgroupValues[i][1] = Goldilocks::zero(); + airgroupValues[i][2] = Goldilocks::zero(); + } else { + std::memcpy(&airgroupValues[i][0], &_airgroupValues[p], FIELD_EXTENSION * sizeof(Goldilocks::Element)); + p += 3; + } } } From cb1006fa65ea012575fdd39bd6def1245c55b761 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Tue, 10 Dec 2024 13:05:31 +0000 Subject: [PATCH 31/64] Fixing cargo fmt --- common/src/air_instance.rs | 1 - provers/stark/src/stark_prover.rs | 16 +++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/common/src/air_instance.rs b/common/src/air_instance.rs index e4b6e6f9..77e87b36 100644 --- a/common/src/air_instance.rs +++ b/common/src/air_instance.rs @@ -264,7 +264,6 @@ impl AirInstance { // Check if name matches let name_matches = value.name == name; - // If lengths is provided, check that it matches airvalue.lengths let lengths_match = if let Some(ref provided_lengths) = lengths { Some(&value.lengths) == Some(provided_lengths) diff --git a/provers/stark/src/stark_prover.rs b/provers/stark/src/stark_prover.rs index 5b937766..5a05110a 100644 --- a/provers/stark/src/stark_prover.rs +++ b/provers/stark/src/stark_prover.rs @@ -405,11 +405,7 @@ impl Prover for StarkProver { .stark_info .airvalues_map .as_ref() - .map(|map| { - map.iter() - .filter(|entry| entry.stage == stage) - .count() - }) + .map(|map| map.iter().filter(|entry| entry.stage == stage).count()) .unwrap_or(0); if stage == 1 || n_airvals_stage > 0 { @@ -454,13 +450,15 @@ impl Prover for StarkProver { let mut p = 0; let mut count = 0; for air_value in airvalues_map { - if air_value.stage > stage { break; } + if air_value.stage > stage { + break; + } if air_value.stage == 1 { if stage == 1 { values_hash[2 * self.n_field_elements + count] = air_instance.airvalues[p]; - count+=1; + count += 1; } - p+=1; + p += 1; } else { if air_value.stage == stage { values_hash[self.n_field_elements + count] = air_instance.airvalues[p]; @@ -468,7 +466,7 @@ impl Prover for StarkProver { values_hash[self.n_field_elements + count + 2] = air_instance.airvalues[p + 2]; count += 3; } - p+= 3; + p += 3; } } From b997644e232c22b499c2dccdb7b6044d18d6b562 Mon Sep 17 00:00:00 2001 From: Xavier Pinsach <10213118+xavi-pinsach@users.noreply.github.com> Date: Wed, 11 Dec 2024 08:47:49 +0000 Subject: [PATCH 32/64] add dctx function --- common/src/execution_ctx.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/common/src/execution_ctx.rs b/common/src/execution_ctx.rs index eb198be3..10a3f2df 100644 --- a/common/src/execution_ctx.rs +++ b/common/src/execution_ctx.rs @@ -18,6 +18,17 @@ impl ExecutionCtx { pub fn builder() -> ExecutionCtxBuilder { ExecutionCtxBuilder::new() } + + pub fn dctx_add_instance(&self, airgroup_id: usize, air_id: usize, weight: usize) -> (bool, usize) { + let mut dctx = self.dctx.write().unwrap(); + dctx.add_instance(airgroup_id, air_id, weight) + } + + pub fn dctx_distribute_multiplicity(&self, multiplicity: &mut [u64], instance_idx: usize) { + let dctx = self.dctx.write().unwrap(); + let owner = dctx.owner(instance_idx); + dctx.distribute_multiplicity(multiplicity, owner); + } } pub struct ExecutionCtxBuilder { From 9795265ef9d87eeb68b687e2ca1d0aaa4dd69f22 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Wed, 11 Dec 2024 14:08:04 +0000 Subject: [PATCH 33/64] Removing setup ctx from air_instance --- common/src/air_instance.rs | 221 ++++++------------ common/src/execution_ctx.rs | 2 +- common/src/trace.rs | 1 + examples/fibonacci-square/src/fibonacci.rs | 6 +- examples/fibonacci-square/src/module.rs | 10 +- macros/src/lib.rs | 4 + .../rs/src/range_check/specified_ranges.rs | 6 +- .../lib/std/rs/src/range_check/u16air.rs | 6 +- .../lib/std/rs/src/range_check/u8air.rs | 6 +- .../test/simple/rs/src/simple_left.rs | 4 +- .../test/simple/rs/src/simple_right.rs | 4 +- .../test/std/connection/rs/src/connection1.rs | 4 +- .../test/std/connection/rs/src/connection2.rs | 4 +- .../std/connection/rs/src/connection_new.rs | 4 +- .../test/std/lookup/rs/src/lookup0.rs | 4 +- .../test/std/lookup/rs/src/lookup1.rs | 4 +- .../test/std/lookup/rs/src/lookup2_12.rs | 4 +- .../test/std/lookup/rs/src/lookup2_13.rs | 4 +- .../test/std/lookup/rs/src/lookup2_15.rs | 4 +- .../test/std/lookup/rs/src/lookup3.rs | 4 +- .../std/permutation/rs/src/permutation1_6.rs | 6 +- .../std/permutation/rs/src/permutation1_7.rs | 4 +- .../std/permutation/rs/src/permutation1_8.rs | 4 +- .../std/permutation/rs/src/permutation2.rs | 4 +- .../range_check/rs/src/multi_range_check1.rs | 4 +- .../range_check/rs/src/multi_range_check2.rs | 4 +- .../std/range_check/rs/src/range_check1.rs | 4 +- .../std/range_check/rs/src/range_check2.rs | 4 +- .../std/range_check/rs/src/range_check3.rs | 4 +- .../std/range_check/rs/src/range_check4.rs | 4 +- .../rs/src/range_check_dynamic1.rs | 4 +- .../rs/src/range_check_dynamic2.rs | 4 +- .../std/range_check/rs/src/range_check_mix.rs | 4 +- provers/stark/src/stark_prover.rs | 64 +++-- 34 files changed, 179 insertions(+), 245 deletions(-) diff --git a/common/src/air_instance.rs b/common/src/air_instance.rs index 77e87b36..78538d43 100644 --- a/common/src/air_instance.rs +++ b/common/src/air_instance.rs @@ -1,10 +1,8 @@ -use std::sync::Arc; use std::ptr; -use std::path::PathBuf; use p3_field::Field; use proofman_util::create_buffer_fast; -use crate::{trace::Trace, trace::Values, SetupCtx, Setup, StarkInfo, PolMap}; +use crate::{trace::Trace, trace::Values}; #[repr(C)] pub struct StepsParams { @@ -47,32 +45,26 @@ impl Default for StepsParams { } } -#[derive(Default, Clone)] -pub struct CustomCommitsInfo { - pub buffer: Vec, - pub cached_file: PathBuf, -} - -impl CustomCommitsInfo { - pub fn new(buffer: Vec, cached_file: PathBuf) -> Self { - Self { buffer, cached_file } - } +pub struct CustomCommitInfo { + pub trace: Vec, + pub commit_id: usize, } pub struct TraceInfo { airgroup_id: usize, air_id: usize, trace: Vec, - custom_traces: Option>>, + custom_traces: Option>>, air_values: Option>, + airgroup_values: Option>, } impl TraceInfo { pub fn new(airgroup_id: usize, air_id: usize, trace: Vec) -> Self { - Self { airgroup_id, air_id, trace, custom_traces: None, air_values: None } + Self { airgroup_id, air_id, trace, custom_traces: None, air_values: None, airgroup_values: None } } - pub fn with_custom_traces(mut self, custom_traces: Vec>) -> Self { + pub fn with_custom_traces(mut self, custom_traces: Vec>) -> Self { self.custom_traces = Some(custom_traces); self } @@ -81,17 +73,23 @@ impl TraceInfo { self.air_values = Some(air_values); self } + + pub fn with_airgroup_values(mut self, airgroup_values: Vec) -> Self { + self.air_values = Some(airgroup_values); + self + } } pub struct FromTrace<'a, F> { pub trace: &'a mut dyn Trace, pub custom_traces: Option>>, pub air_values: Option<&'a mut dyn Values>, + pub airgroup_values: Option<&'a mut dyn Values>, } impl<'a, F> FromTrace<'a, F> { pub fn new(trace: &'a mut dyn Trace) -> Self { - Self { trace, custom_traces: None, air_values: None } + Self { trace, custom_traces: None, air_values: None, airgroup_values: None } } pub fn with_custom_traces(mut self, custom_traces: Vec<&'a mut dyn Trace>) -> Self { @@ -103,6 +101,11 @@ impl<'a, F> FromTrace<'a, F> { self.air_values = Some(air_values); self } + + pub fn with_airgroup_values(mut self, airgroup_values: &'a mut dyn Values) -> Self { + self.airgroup_values = Some(airgroup_values); + self + } } /// Air instance context for managing air instances (traces) @@ -116,29 +119,24 @@ pub struct AirInstance { pub idx: Option, pub global_idx: Option, pub trace: Vec, - pub aux_trace: Option>, - pub custom_commits: Vec>, - pub custom_commits_extended: Vec>, + pub aux_trace: Vec, + pub custom_commits: Vec>, + pub custom_commits_extended: Vec>, pub airgroup_values: Vec, pub airvalues: Vec, pub evals: Vec, - pub stark_info: StarkInfo, } impl AirInstance { - pub fn new(setup_ctx: Arc, trace_info: TraceInfo) -> Self { + pub fn new(trace_info: TraceInfo) -> Self { let airgroup_id = trace_info.airgroup_id; let air_id = trace_info.air_id; - let ps = setup_ctx.get_setup(airgroup_id, air_id); + let custom_commits = Self::init_custom_commits(trace_info.custom_traces); - let (custom_commits, custom_commits_extended) = Self::init_custom_commits(ps, trace_info.custom_traces); + let airvalues = trace_info.air_values.unwrap_or_default(); - let airvalues = if let Some(air_values) = trace_info.air_values { - air_values - } else { - vec![F::zero(); ps.stark_info.airvalues_map.as_ref().unwrap().len() * 3] - }; + let airgroup_values = trace_info.airgroup_values.unwrap_or_default(); AirInstance { airgroup_id, @@ -147,24 +145,26 @@ impl AirInstance { idx: None, global_idx: None, trace: trace_info.trace, - aux_trace: None, + aux_trace: Vec::new(), custom_commits, - custom_commits_extended, - airgroup_values: vec![F::zero(); ps.stark_info.airgroupvalues_map.as_ref().unwrap().len() * 3], + custom_commits_extended: vec![Vec::new(); 10], + airgroup_values, airvalues, - evals: vec![F::zero(); ps.stark_info.ev_map.len() * 3], - stark_info: ps.stark_info.clone(), + evals: Vec::new(), } } - pub fn new_from_trace(setup_ctx: Arc, mut traces: FromTrace<'_, F>) -> Self { + pub fn new_from_trace(mut traces: FromTrace<'_, F>) -> Self { let mut trace_info = TraceInfo::new(traces.trace.airgroup_id(), traces.trace.air_id(), traces.trace.get_buffer()); if let Some(custom_traces) = traces.custom_traces.as_mut() { let mut traces = Vec::new(); for custom_trace in custom_traces.iter_mut() { - traces.push(custom_trace.get_buffer()); + traces.push(CustomCommitInfo { + trace: custom_trace.get_buffer(), + commit_id: custom_trace.commit_id().unwrap(), + }); } trace_info = trace_info.with_custom_traces(traces); } @@ -173,37 +173,19 @@ impl AirInstance { trace_info = trace_info.with_air_values(air_values.get_buffer()); } - AirInstance::new(setup_ctx, trace_info) + AirInstance::new(trace_info) } - pub fn init_custom_commits( - setup: &Setup, - traces_custom: Option>>, - ) -> (Vec>, Vec>) { - let n_custom_commits = setup.stark_info.custom_commits.len(); - - let mut custom_commits = Vec::new(); - let mut custom_commits_extended = Vec::new(); - - for commit_id in 0..n_custom_commits { - let n_cols = *setup - .stark_info - .map_sections_n - .get(&(setup.stark_info.custom_commits[commit_id].name.clone() + "0")) - .unwrap() as usize; - if let Some(traces_custom_vals) = traces_custom.as_ref() { - custom_commits.push(CustomCommitsInfo::new(traces_custom_vals[commit_id].clone(), PathBuf::new())); - } else { - println!("No custom trace data found."); + pub fn init_custom_commits(traces_custom: Option>>) -> Vec> { + if let Some(traces_custom) = traces_custom { + let mut custom_commits = vec![Vec::new(); traces_custom.len()]; + for trace in traces_custom { + custom_commits[trace.commit_id] = trace.trace; } - - custom_commits_extended.push(CustomCommitsInfo::new( - create_buffer_fast((1 << setup.stark_info.stark_struct.n_bits_ext) * n_cols), - PathBuf::new(), - )); + custom_commits + } else { + vec![Vec::new(); 10] } - - (custom_commits, custom_commits_extended) } pub fn get_trace_ptr(&self) -> *mut u8 { @@ -222,21 +204,41 @@ impl AirInstance { self.airvalues.as_ptr() as *mut u8 } - pub fn set_aux_trace(&mut self, aux_trace: Vec) { - self.aux_trace = Some(aux_trace); + pub fn init_evals(&mut self, size: usize) { + self.evals = vec![F::zero(); size]; + } + + pub fn init_aux_trace(&mut self, size: usize) { + self.aux_trace = create_buffer_fast(size); + } + + pub fn init_airvalues(&mut self, size: usize) { + self.airvalues = vec![F::zero(); size]; + } + + pub fn init_airgroup_values(&mut self, size: usize) { + self.airgroup_values = vec![F::zero(); size]; + } + + pub fn init_custom_commit(&mut self, commit_id: usize, size: usize) { + self.custom_commits[commit_id] = create_buffer_fast(size); + } + + pub fn init_custom_commit_extended(&mut self, commit_id: usize, size: usize) { + self.custom_commits_extended[commit_id] = create_buffer_fast(size); } pub fn get_aux_trace_ptr(&self) -> *mut u8 { - match &self.aux_trace { - Some(aux_trace) => aux_trace.as_ptr() as *mut u8, - None => std::ptr::null_mut(), // Return null if `trace` is `None` + match &self.aux_trace.is_empty() { + false => self.aux_trace.as_ptr() as *mut u8, + true => std::ptr::null_mut(), // Return null if `trace` is `None` } } pub fn get_custom_commits_ptr(&self) -> [*mut u8; 10] { let mut ptrs = [std::ptr::null_mut(); 10]; for (i, custom_commit) in self.custom_commits.iter().enumerate() { - ptrs[i] = custom_commit.buffer.as_ptr() as *mut u8; + ptrs[i] = custom_commit.as_ptr() as *mut u8; } ptrs } @@ -244,90 +246,11 @@ impl AirInstance { pub fn get_custom_commits_extended_ptr(&self) -> [*mut u8; 10] { let mut ptrs = [std::ptr::null_mut(); 10]; for (i, custom_commit) in self.custom_commits_extended.iter().enumerate() { - ptrs[i] = custom_commit.buffer.as_ptr() as *mut u8; + ptrs[i] = custom_commit.as_ptr() as *mut u8; } ptrs } - pub fn set_custom_commit_cached_file(&mut self, commit_id: u64, cached_file: PathBuf) { - self.custom_commits[commit_id as usize].cached_file = cached_file; - } - - pub fn set_custom_commit_id_buffer(&mut self, buffer: Vec, commit_id: u64) { - self.custom_commits[commit_id as usize].buffer = buffer; - } - - fn find_value_map(values_map: &Vec, name: &str, lengths: Option>) -> usize { - let mut id = 0; - let mut found = false; - for value in values_map { - // Check if name matches - let name_matches = value.name == name; - - // If lengths is provided, check that it matches airvalue.lengths - let lengths_match = if let Some(ref provided_lengths) = lengths { - Some(&value.lengths) == Some(provided_lengths) - } else { - true // If lengths is None, skip the lengths check - }; - - if !name_matches || !lengths_match { - if value.stage == 1 { - id += 1; - } else { - id += 3; - } - } else { - found = true; - break; - } - } - - if !found { - panic!("Name {} with specified lengths {:?} not found in airvalues", name, lengths); - } - - id - } - - pub fn set_airvalue(&mut self, name: &str, lengths: Option>, value: F) { - let airvalues_map = self.stark_info.airvalues_map.as_ref().unwrap(); - let id = Self::find_value_map(airvalues_map, name, lengths); - self.airvalues[id] = value; - } - - pub fn set_airvalue_ext(&mut self, name: &str, lengths: Option>, value: Vec) { - let airvalues_map = self.stark_info.airvalues_map.as_ref().unwrap(); - let id = Self::find_value_map(airvalues_map, name, lengths); - - assert!(value.len() == 3, "Value vector must have exactly 3 elements"); - - let mut value_iter = value.into_iter(); - - self.airvalues[id] = value_iter.next().unwrap(); - self.airvalues[id + 1] = value_iter.next().unwrap(); - self.airvalues[id + 2] = value_iter.next().unwrap(); - } - - pub fn set_airgroupvalue(&mut self, name: &str, lengths: Option>, value: F) { - let airgroupvalues_map = self.stark_info.airgroupvalues_map.as_ref().unwrap(); - let id = Self::find_value_map(airgroupvalues_map, name, lengths); - self.airgroup_values[id] = value; - } - - pub fn set_airgroupvalue_ext(&mut self, name: &str, lengths: Option>, value: Vec) { - let airgroupvalues_map = self.stark_info.airgroupvalues_map.as_ref().unwrap(); - let id = Self::find_value_map(airgroupvalues_map, name, lengths); - - assert!(value.len() == 3, "Value vector must have exactly 3 elements"); - - let mut value_iter = value.into_iter(); - - self.airgroup_values[id] = value_iter.next().unwrap(); - self.airgroup_values[id + 1] = value_iter.next().unwrap(); - self.airgroup_values[id + 2] = value_iter.next().unwrap(); - } - pub fn set_air_instance_id(&mut self, air_instance_id: usize, idx: usize) { self.air_instance_id = Some(air_instance_id); self.idx = Some(idx); diff --git a/common/src/execution_ctx.rs b/common/src/execution_ctx.rs index 10a3f2df..184b3f7f 100644 --- a/common/src/execution_ctx.rs +++ b/common/src/execution_ctx.rs @@ -25,7 +25,7 @@ impl ExecutionCtx { } pub fn dctx_distribute_multiplicity(&self, multiplicity: &mut [u64], instance_idx: usize) { - let dctx = self.dctx.write().unwrap(); + let dctx = self.dctx.read().unwrap(); let owner = dctx.owner(instance_idx); dctx.distribute_multiplicity(multiplicity, owner); } diff --git a/common/src/trace.rs b/common/src/trace.rs index 7fe9e4e8..59f84458 100644 --- a/common/src/trace.rs +++ b/common/src/trace.rs @@ -2,6 +2,7 @@ pub trait Trace: Send { fn num_rows(&self) -> usize; fn airgroup_id(&self) -> usize; fn air_id(&self) -> usize; + fn commit_id(&self) -> Option; fn get_buffer(&mut self) -> Vec; } diff --git a/examples/fibonacci-square/src/fibonacci.rs b/examples/fibonacci-square/src/fibonacci.rs index 54a831e5..4b836173 100644 --- a/examples/fibonacci-square/src/fibonacci.rs +++ b/examples/fibonacci-square/src/fibonacci.rs @@ -29,8 +29,8 @@ impl FibonacciSquare { fibonacci } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { - if let Err(e) = Self::calculate_trace(self, pctx, ectx, sctx) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + if let Err(e) = Self::calculate_trace(self, pctx, ectx) { panic!("Failed to calculate fibonacci: {:?}", e); } } @@ -39,7 +39,6 @@ impl FibonacciSquare { &self, pctx: Arc>, ectx: Arc, - sctx: Arc, ) -> Result> { log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); @@ -82,7 +81,6 @@ impl FibonacciSquare { air_values.fibo3 = [F::from_canonical_u64(5), F::from_canonical_u64(5), F::from_canonical_u64(5)]; let air_instance = AirInstance::new_from_trace( - sctx.clone(), FromTrace::new(&mut trace).with_custom_traces(vec![&mut trace_rom]).with_air_values(&mut air_values), ); add_air_instance::(air_instance, ectx, pctx.clone()); diff --git a/examples/fibonacci-square/src/module.rs b/examples/fibonacci-square/src/module.rs index 767e13c4..7ffa0fbe 100644 --- a/examples/fibonacci-square/src/module.rs +++ b/examples/fibonacci-square/src/module.rs @@ -6,7 +6,7 @@ use pil_std_lib::Std; use p3_field::{AbstractField, PrimeField64}; use num_bigint::BigInt; -use crate::{ModuleTrace}; +use crate::ModuleTrace; pub struct Module { inputs: Mutex>, @@ -37,11 +37,11 @@ impl Module< x_mod } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { - self.calculate_trace(pctx, ectx, sctx); + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + self.calculate_trace(pctx, ectx); } - fn calculate_trace(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + fn calculate_trace(&self, pctx: Arc>, ectx: Arc) { log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let module = F::as_canonical_u64(&pctx.get_public_value("module")); @@ -71,7 +71,7 @@ impl Module< self.std_lib.range_check(F::from_canonical_u64(module), F::one(), range); } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); self.std_lib.unregister_predecessor(pctx, None); diff --git a/macros/src/lib.rs b/macros/src/lib.rs index fa434368..36ad45b2 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -161,6 +161,10 @@ fn trace_impl(input: TokenStream2) -> Result { self.air_id } + fn commit_id(&self) -> Option { + self.commit_id + } + fn get_buffer(&mut self) -> Vec<#generics> { let mut buffer = std::mem::take(&mut self.buffer); unsafe { diff --git a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs index d420926f..9a28a700 100644 --- a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs +++ b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs @@ -95,7 +95,6 @@ impl SpecifiedRanges { let mut inputs = self.inputs.lock().unwrap(); let drained_inputs = inputs.drain(..).collect(); let pctx = self.wcm.get_pctx(); - let sctx = self.wcm.get_sctx(); let ectx = self.wcm.get_ectx(); // Perform the last update @@ -133,8 +132,7 @@ impl SpecifiedRanges { let num_rows = pctx.global_info.airs[self.airgroup_id][self.air_id].num_rows; let buffer_size = multiplicities.len() * num_rows; let buffer: Vec = create_buffer_fast(buffer_size); - let air_instance = - AirInstance::new(sctx.clone(), TraceInfo::new(self.airgroup_id, self.air_id, buffer)); + let air_instance = AirInstance::new(TraceInfo::new(self.airgroup_id, self.air_id, buffer)); pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)); pctx.air_instance_repo.air_instances.read().unwrap().len() - 1 }; @@ -304,7 +302,7 @@ impl WitnessComponent for SpecifiedRanges { let buffer = create_buffer_fast(buffer_size as usize); // Add a new air instance. Since Specified Ranges is a table, only this air instance is needed - let mut air_instance = AirInstance::new(sctx.clone(), TraceInfo::new(self.airgroup_id, self.air_id, buffer)); + let mut air_instance = AirInstance::new(TraceInfo::new(self.airgroup_id, self.air_id, buffer)); let mut mul_columns_guard = self.mul_columns.lock().unwrap(); for hint in hints_guard[1..].iter() { mul_columns_guard.push(get_hint_field::( diff --git a/pil2-components/lib/std/rs/src/range_check/u16air.rs b/pil2-components/lib/std/rs/src/range_check/u16air.rs index 4ac75bfd..6dccac6f 100644 --- a/pil2-components/lib/std/rs/src/range_check/u16air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u16air.rs @@ -88,7 +88,6 @@ impl U16Air { let mut inputs = self.inputs.lock().unwrap(); let drained_inputs = inputs.drain(..).collect(); let pctx = self.wcm.get_pctx(); - let sctx = self.wcm.get_sctx(); let ectx = self.wcm.get_ectx(); // Perform the last update @@ -117,8 +116,7 @@ impl U16Air { let num_rows = pctx.global_info.airs[self.airgroup_id][self.air_id].num_rows; let buffer_size = num_rows; let buffer: Vec = create_buffer_fast(buffer_size); - let air_instance = - AirInstance::new(sctx.clone(), TraceInfo::new(self.airgroup_id, self.air_id, buffer)); + let air_instance = AirInstance::new(TraceInfo::new(self.airgroup_id, self.air_id, buffer)); pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)); pctx.air_instance_repo.air_instances.read().unwrap().len() - 1 }; @@ -179,7 +177,7 @@ impl WitnessComponent for U16Air { let buffer = create_buffer_fast(buffer_size); // Add a new air instance. Since U16Air is a table, only this air instance is needed - let mut air_instance = AirInstance::new(sctx.clone(), TraceInfo::new(self.airgroup_id, self.air_id, buffer)); + let mut air_instance = AirInstance::new(TraceInfo::new(self.airgroup_id, self.air_id, buffer)); *self.mul_column.lock().unwrap() = get_hint_field::( &self.wcm.get_sctx(), diff --git a/pil2-components/lib/std/rs/src/range_check/u8air.rs b/pil2-components/lib/std/rs/src/range_check/u8air.rs index 5d98c548..a45acbf7 100644 --- a/pil2-components/lib/std/rs/src/range_check/u8air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u8air.rs @@ -87,7 +87,6 @@ impl U8Air { let mut inputs = self.inputs.lock().unwrap(); let drained_inputs = inputs.drain(..).collect(); let pctx = self.wcm.get_pctx(); - let sctx = self.wcm.get_sctx(); let ectx = self.wcm.get_ectx(); // Perform the last update @@ -115,8 +114,7 @@ impl U8Air { let num_rows = pctx.global_info.airs[self.airgroup_id][self.air_id].num_rows; let buffer_size = num_rows; let buffer: Vec = create_buffer_fast(buffer_size); - let air_instance = - AirInstance::new(sctx.clone(), TraceInfo::new(self.airgroup_id, self.air_id, buffer)); + let air_instance = AirInstance::new(TraceInfo::new(self.airgroup_id, self.air_id, buffer)); pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)); pctx.air_instance_repo.air_instances.read().unwrap().len() - 1 }; @@ -176,7 +174,7 @@ impl WitnessComponent for U8Air { let buffer = create_buffer_fast(buffer_size); // Add a new air instance. Since U8Air is a table, only this air instance is needed - let mut air_instance = AirInstance::new(sctx.clone(), TraceInfo::new(self.airgroup_id, self.air_id, buffer)); + let mut air_instance = AirInstance::new(TraceInfo::new(self.airgroup_id, self.air_id, buffer)); *self.mul_column.lock().unwrap() = get_hint_field::( &sctx, diff --git a/pil2-components/test/simple/rs/src/simple_left.rs b/pil2-components/test/simple/rs/src/simple_left.rs index fdd515a7..33143c4e 100644 --- a/pil2-components/test/simple/rs/src/simple_left.rs +++ b/pil2-components/test/simple/rs/src/simple_left.rs @@ -26,7 +26,7 @@ where simple_left } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = SimpleLeftTrace::new(); @@ -56,7 +56,7 @@ where trace[i].d = trace[indices[i]].b; } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/simple/rs/src/simple_right.rs b/pil2-components/test/simple/rs/src/simple_right.rs index 07e9262c..40a6879b 100644 --- a/pil2-components/test/simple/rs/src/simple_right.rs +++ b/pil2-components/test/simple/rs/src/simple_right.rs @@ -29,7 +29,7 @@ where simple_right } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut trace = SimpleRightTrace::new(); let num_rows = trace.num_rows(); @@ -46,7 +46,7 @@ where trace[i].mul = F::from_canonical_usize(1); } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/connection/rs/src/connection1.rs b/pil2-components/test/std/connection/rs/src/connection1.rs index cca23170..132b0738 100644 --- a/pil2-components/test/std/connection/rs/src/connection1.rs +++ b/pil2-components/test/std/connection/rs/src/connection1.rs @@ -29,7 +29,7 @@ where connection1 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Connection1Trace::new_zeroes(); @@ -43,7 +43,7 @@ where trace[i].c = rng.gen(); } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/connection/rs/src/connection2.rs b/pil2-components/test/std/connection/rs/src/connection2.rs index e97170fa..2fd2e130 100644 --- a/pil2-components/test/std/connection/rs/src/connection2.rs +++ b/pil2-components/test/std/connection/rs/src/connection2.rs @@ -29,7 +29,7 @@ where connection2 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Connection2Trace::new_zeroes(); @@ -45,7 +45,7 @@ where trace[0].a = trace[1].a; - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/connection/rs/src/connection_new.rs b/pil2-components/test/std/connection/rs/src/connection_new.rs index e74254a5..7bc74d41 100644 --- a/pil2-components/test/std/connection/rs/src/connection_new.rs +++ b/pil2-components/test/std/connection/rs/src/connection_new.rs @@ -29,7 +29,7 @@ where connection_new } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = ConnectionNewTrace::new_zeroes(); let num_rows = trace.num_rows(); @@ -136,7 +136,7 @@ where } } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup0.rs b/pil2-components/test/std/lookup/rs/src/lookup0.rs index 9af9d722..0bef6f13 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup0.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup0.rs @@ -29,7 +29,7 @@ where lookup0 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup0Trace::new(); @@ -56,7 +56,7 @@ where } } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup1.rs b/pil2-components/test/std/lookup/rs/src/lookup1.rs index db258833..637643b0 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup1.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup1.rs @@ -29,7 +29,7 @@ where lookup1 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup1Trace::new(); @@ -54,7 +54,7 @@ where trace[i].mul = F::from_canonical_usize(n_sel); } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs index 64fcb3f8..b416e4b9 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs @@ -29,7 +29,7 @@ where lookup2_12 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup2_12Trace::new(); @@ -66,7 +66,7 @@ where trace[i].sel2 = F::from_bool(true); } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs index 11c72e41..5c029de7 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs @@ -29,7 +29,7 @@ where lookup2_13 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup2_13Trace::new(); @@ -66,7 +66,7 @@ where trace[i].sel2 = F::from_bool(true); } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs index 3931c522..a691b33a 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs @@ -29,7 +29,7 @@ where lookup2_15 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup2_15Trace::new(); @@ -66,7 +66,7 @@ where trace[i].sel2 = F::from_bool(true); } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/lookup/rs/src/lookup3.rs b/pil2-components/test/std/lookup/rs/src/lookup3.rs index 99b53848..dbea2e25 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup3.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup3.rs @@ -25,7 +25,7 @@ impl Lookup3 { lookup3 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { // For simplicity, add a single instance of each air let mut trace = Lookup3Trace::new(); let num_rows = trace.num_rows(); @@ -54,7 +54,7 @@ impl Lookup3 { } } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs index d9953bfe..59a97fd3 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs @@ -29,7 +29,7 @@ where permutation1_6 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Permutation1_6Trace::new(); @@ -73,7 +73,7 @@ where trace[i].sel2 = trace[indices[i]].sel1; } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx.clone(), pctx.clone()); let mut trace2 = Permutation1_6Trace::new(); @@ -111,7 +111,7 @@ where trace2[i].sel2 = trace2[indices[i]].sel1; } - let air_instance2 = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace2)); + let air_instance2 = AirInstance::new_from_trace( FromTrace::new(&mut trace2)); add_air_instance::(air_instance2, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs index a9777baf..8c4cd54d 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs @@ -29,7 +29,7 @@ where permutation1_7 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Permutation1_7Trace::new(); let num_rows = trace.num_rows(); @@ -73,7 +73,7 @@ where trace[i].sel2 = trace[i].sel1; } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs index ed926ace..02add697 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs @@ -29,7 +29,7 @@ where permutation1_8 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Permutation1_8Trace::new(); let num_rows = trace.num_rows(); @@ -73,7 +73,7 @@ where trace[i].sel2 = trace[i].sel1; } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation2.rs b/pil2-components/test/std/permutation/rs/src/permutation2.rs index ef238253..d3d72541 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation2.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation2.rs @@ -25,7 +25,7 @@ impl Permutation2 { permutation2 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut trace = Permutation2_6Trace::new(); let num_rows = trace.num_rows(); @@ -45,7 +45,7 @@ impl Permutation2 { trace[i].sel = F::from_bool(true); } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs index 98edc8c2..702b1dc4 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs @@ -34,7 +34,7 @@ where multi_range_check1 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = MultiRangeCheck1Trace::new_zeroes(); @@ -101,7 +101,7 @@ where } } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs index ce07c6be..7462715a 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs @@ -34,7 +34,7 @@ where multi_range_check2 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = MultiRangeCheck2Trace::new_zeroes(); @@ -83,7 +83,7 @@ where } } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check1.rs b/pil2-components/test/std/range_check/rs/src/range_check1.rs index 645f8518..7c3008bd 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check1.rs @@ -34,7 +34,7 @@ where range_check1 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck1Trace::new_zeroes(); @@ -80,7 +80,7 @@ where } } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check2.rs b/pil2-components/test/std/range_check/rs/src/range_check2.rs index 2398773f..fe9b124d 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check2.rs @@ -34,7 +34,7 @@ where range_check2 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck2Trace::new_zeroes(); let num_rows = trace.num_rows(); @@ -55,7 +55,7 @@ where self.std_lib.range_check(trace[i].b3, F::one(), range3); } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check3.rs b/pil2-components/test/std/range_check/rs/src/range_check3.rs index 2a254d34..84b845ee 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check3.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check3.rs @@ -34,7 +34,7 @@ where range_check3 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck3Trace::new_zeroes(); @@ -53,7 +53,7 @@ where self.std_lib.range_check(trace[i].c2, F::one(), range2); } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check4.rs b/pil2-components/test/std/range_check/rs/src/range_check4.rs index 651e412e..b4863f1f 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check4.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check4.rs @@ -35,7 +35,7 @@ where range_check4 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck4Trace::new_zeroes(); @@ -101,7 +101,7 @@ where self.std_lib.range_check(trace[i].a8, F::one(), range9); } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs index 40ac4b17..bc642187 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs @@ -34,7 +34,7 @@ where range_check_dynamic1 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheckDynamic1Trace::new_zeroes(); @@ -79,7 +79,7 @@ where } } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs index 5cea35a1..fef27da6 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs @@ -35,7 +35,7 @@ where range_check_dynamic2 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheckDynamic2Trace::new_zeroes(); @@ -92,7 +92,7 @@ where } } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs index 89cecafd..91abe5cc 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs @@ -35,7 +35,7 @@ where range_check_mix } - pub fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheckMixTrace::new_zeroes(); @@ -133,7 +133,7 @@ where } } - let air_instance = AirInstance::new_from_trace(sctx.clone(), FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); add_air_instance::(air_instance, ectx, pctx.clone()); } } diff --git a/provers/stark/src/stark_prover.rs b/provers/stark/src/stark_prover.rs index 5a05110a..bec01f39 100644 --- a/provers/stark/src/stark_prover.rs +++ b/provers/stark/src/stark_prover.rs @@ -11,7 +11,7 @@ use proofman_common::{ }; use log::{debug, trace}; use transcript::FFITranscript; -use proofman_util::{create_buffer_fast, timer_start_trace, timer_stop_and_log_trace}; +use proofman_util::{timer_start_trace, timer_stop_and_log_trace}; use proofman_starks_lib_c::*; use p3_goldilocks::Goldilocks; use p3_field::AbstractField; @@ -87,9 +87,35 @@ impl StarkProver { impl Prover for StarkProver { fn build(&mut self, proof_ctx: Arc>) { let air_instance = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap()[self.prover_idx]; + air_instance.init_aux_trace(get_map_totaln_c(self.p_stark_info) as usize); + air_instance.init_evals(self.stark_info.ev_map.len() * Self::FIELD_EXTENSION); - let aux_trace = create_buffer_fast(get_map_totaln_c(self.p_stark_info) as usize); - air_instance.set_aux_trace(aux_trace); + let n_custom_commits = self.stark_info.custom_commits.len(); + + for commit_id in 0..n_custom_commits { + let n_cols = *self + .stark_info + .map_sections_n + .get(&(self.stark_info.custom_commits[commit_id].name.clone() + "0")) + .unwrap() as usize; + + if air_instance.custom_commits[commit_id].is_empty() { + air_instance.init_custom_commit(commit_id, (1 << self.stark_info.stark_struct.n_bits_ext) * n_cols); + } + air_instance + .init_custom_commit_extended(commit_id, (1 << self.stark_info.stark_struct.n_bits_ext) * n_cols); + } + + let n_airgroup_values = self.stark_info.airgroupvalues_map.as_ref().unwrap().len(); + let n_air_values = self.stark_info.airvalues_map.as_ref().unwrap().len(); + + if n_air_values > 0 && air_instance.airvalues.is_empty() { + air_instance.init_airvalues(n_air_values * Self::FIELD_EXTENSION); + } + + if n_airgroup_values > 0 && air_instance.airgroup_values.is_empty() { + air_instance.init_airgroup_values(n_airgroup_values * Self::FIELD_EXTENSION); + } } fn free(&mut self) { @@ -241,28 +267,16 @@ impl Prover for StarkProver { .any(|custom_commit| custom_commit.stage == stage_id as u64); if custom_commits_stage { - if air_instance.custom_commits[commit_id].cached_file.to_str() == Some("") { - extend_and_merkelize_custom_commit_c( - p_stark, - commit_id as u64, - stage_id as u64, - air_instance.custom_commits[commit_id].buffer.as_ptr() as *mut u8, - air_instance.custom_commits_extended[commit_id].buffer.as_ptr() as *mut u8, - p_proof, - proof_ctx.get_buff_helper_ptr(), - "", - ); - } else { - load_custom_commit_c( - p_stark, - commit_id as u64, - stage_id as u64, - air_instance.custom_commits[commit_id].buffer.as_ptr() as *mut u8, - air_instance.custom_commits_extended[commit_id].buffer.as_ptr() as *mut u8, - p_proof, - air_instance.custom_commits[commit_id].cached_file.to_str().unwrap(), - ); - } + extend_and_merkelize_custom_commit_c( + p_stark, + commit_id as u64, + stage_id as u64, + air_instance.custom_commits[commit_id].as_ptr() as *mut u8, + air_instance.custom_commits_extended[commit_id].as_ptr() as *mut u8, + p_proof, + proof_ctx.get_buff_helper_ptr(), + "", + ); } let mut value = vec![F::zero(); self.n_field_elements]; From 7e6b20576ff13e76b24f22a02310118b55fb0bf7 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Thu, 12 Dec 2024 14:42:30 +0000 Subject: [PATCH 34/64] Pointing to 0.0.17 pil2-proofman-js --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f6e9c17f..959b4e5b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -158,7 +158,7 @@ jobs: uses: actions/checkout@v4 with: repository: 0xPolygonHermez/pil2-proofman-js - ref: feature/setup + ref: 0.0.17 path: pil2-proofman-js - name: Install pil2-proofman-js dependencies @@ -260,7 +260,7 @@ jobs: uses: actions/checkout@v4 with: repository: 0xPolygonHermez/pil2-proofman-js - ref: 0.0.16 + ref: 0.0.17 path: pil2-proofman-js - name: Install pil2-proofman-js dependencies From 5ed06d35c0084ba784950e8cf432a989fa45e585 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Thu, 12 Dec 2024 14:49:47 +0000 Subject: [PATCH 35/64] Fix C++ compilation --- pil2-stark/src/starkpil/hints.hpp | 39 +++++-------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/pil2-stark/src/starkpil/hints.hpp b/pil2-stark/src/starkpil/hints.hpp index 1f0ac722..84444efa 100644 --- a/pil2-stark/src/starkpil/hints.hpp +++ b/pil2-stark/src/starkpil/hints.hpp @@ -409,42 +409,15 @@ void addHintField(SetupCtx& setupCtx, StepsParams& params, uint64_t hintId, Dest }); HintFieldValue hintFieldVal = hintField->values[0]; - Dest destStruct(dest, offset); - - for(uint64_t i = 0; i < hintFieldNames.size(); ++i) { - std::string name = hintFieldNames[i]; - auto hintField = std::find_if(hint.fields.begin(), hint.fields.end(), [name](const HintField& hintField) { - return hintField.name == name; - }); - HintFieldValue hintFieldVal = hintField->values[0]; - - if(hintField == hint.fields.end()) { - zklog.error("Hint field " + name + " not found in hint " + hint.name + "."); - exitProcess(); - exit(-1); - } - - if(hintFieldOptions[i].print_expression) { - std::string expression_line = getExpressionDebug(setupCtx, hintId, hintFieldNames[i], hintFieldVal); - cout << expression_line << endl; - } - if(hintFieldVal.operand == opType::cm) { - destStruct.addCmPol(setupCtx.starkInfo.cmPolsMap[hintFieldVal.id], hintFieldVal.rowOffsetIndex, hintFieldOptions[i].inverse); - } else if(hintFieldVal.operand == opType::const_) { - destStruct.addConstPol(setupCtx.starkInfo.constPolsMap[hintFieldVal.id], hintFieldVal.rowOffsetIndex, hintFieldOptions[i].inverse); - } else if(hintFieldVal.operand == opType::number) { - destStruct.addNumber(hintFieldVal.value, hintFieldOptions[i].inverse); - } else if(hintFieldVal.operand == opType::tmp) { - destStruct.addParams(setupCtx.expressionsBin.expressionsInfo[hintFieldVal.id], hintFieldOptions[i].inverse); - } else { - zklog.error("Op type " + to_string(hintFieldVal.operand) + "is not considered yet."); - exitProcess(); - exit(-1); - } + if(hintField == hint.fields.end()) { + zklog.error("Hint field " + hintFieldName + " not found in hint " + hint.name + "."); + exitProcess(); + exit(-1); } if(hintFieldOptions.print_expression) { - printExpressionDebug(setupCtx, hintId, hintFieldName, hintFieldVal); + std::string expression_line = getExpressionDebug(setupCtx, hintId, hintFieldName, hintFieldVal); + cout << expression_line << endl; } if(hintFieldVal.operand == opType::cm) { destStruct.addCmPol(setupCtx.starkInfo.cmPolsMap[hintFieldVal.id], hintFieldVal.rowOffsetIndex, hintFieldOptions.inverse); From a6ecfd6907bbfcb830674016f155c8cfd4e729f1 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Thu, 12 Dec 2024 14:52:23 +0000 Subject: [PATCH 36/64] Fix ffi when no_lib_link --- provers/starks-lib-c/src/ffi_starks.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/provers/starks-lib-c/src/ffi_starks.rs b/provers/starks-lib-c/src/ffi_starks.rs index ce80775e..3100f96f 100644 --- a/provers/starks-lib-c/src/ffi_starks.rs +++ b/provers/starks-lib-c/src/ffi_starks.rs @@ -1154,13 +1154,13 @@ pub fn acc_mul_hint_fields_c( #[allow(clippy::too_many_arguments)] pub fn update_airgroupvalue_c( _p_setup_ctx: *mut c_void, - _p_steps_params: *mut c_void, + _p_steps_params: *mut u8, _hint_id: u64, _hint_field_airgroupvalue: &str, _hint_field_name1: &str, _hint_field_name2: &str, - _hint_options1: *mut c_void, - _hint_options2: *mut c_void, + _hint_options1: *mut u8, + _hint_options2: *mut u8, _add: bool, ) -> *mut c_void { trace!("{}: ··· {}", "ffi ", "update_airgroupvalue: This is a mock call because there is no linked library"); From 8e10ab82d69928c9c11613d45f183b0aa8bdcea7 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Thu, 12 Dec 2024 14:57:42 +0000 Subject: [PATCH 37/64] Compilation fibonacci error --- examples/fibonacci-square/pil/fibonaccisq.pil | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/fibonacci-square/pil/fibonaccisq.pil b/examples/fibonacci-square/pil/fibonaccisq.pil index c2be0a37..0e37abf1 100644 --- a/examples/fibonacci-square/pil/fibonaccisq.pil +++ b/examples/fibonacci-square/pil/fibonaccisq.pil @@ -36,7 +36,7 @@ airtemplate FibonacciSquare(const int N = 2**8) { (a' - b) * (1 - L1') === 0; - mod * value1 - value2 === 0; + module * value1 - value2 === 0; 2*fibo1[0] - fibo1[1] === 0; line - (flags + 1) === 0; From 8a8a5fd66e2bfa88587ef1984123020c8f47aae0 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Fri, 13 Dec 2024 09:16:00 +0000 Subject: [PATCH 38/64] Removing execution ctx --- cli/src/commands/prove.rs | 30 ++-- cli/src/commands/verify_constraints.rs | 30 ++-- common/src/custom_commits.rs | 58 -------- common/src/execution_ctx.rs | 89 ------------ common/src/lib.rs | 6 +- common/src/proof_ctx.rs | 20 ++- common/src/std_mode.rs | 10 +- common/src/utils.rs | 6 +- examples/fibonacci-square/src/fibonacci.rs | 15 +- .../fibonacci-square/src/fibonacci_lib.rs | 18 +-- examples/fibonacci-square/src/module.rs | 11 +- .../rs/src/range_check/specified_ranges.rs | 8 +- .../std/rs/src/range_check/std_range_check.rs | 5 +- .../lib/std/rs/src/range_check/u16air.rs | 8 +- .../lib/std/rs/src/range_check/u8air.rs | 8 +- pil2-components/lib/std/rs/src/std.rs | 2 +- pil2-components/lib/std/rs/src/std_prod.rs | 21 +-- pil2-components/lib/std/rs/src/std_sum.rs | 21 +-- .../test/simple/rs/src/simple_left.rs | 7 +- .../test/simple/rs/src/simple_lib.rs | 22 +-- .../test/simple/rs/src/simple_right.rs | 7 +- .../test/std/connection/rs/src/connection1.rs | 8 +- .../test/std/connection/rs/src/connection2.rs | 8 +- .../std/connection/rs/src/connection_lib.rs | 24 ++-- .../std/connection/rs/src/connection_new.rs | 8 +- .../test/std/lookup/rs/src/lookup0.rs | 8 +- .../test/std/lookup/rs/src/lookup1.rs | 8 +- .../test/std/lookup/rs/src/lookup2_12.rs | 8 +- .../test/std/lookup/rs/src/lookup2_13.rs | 8 +- .../test/std/lookup/rs/src/lookup2_15.rs | 8 +- .../test/std/lookup/rs/src/lookup3.rs | 8 +- .../test/std/lookup/rs/src/lookup_lib.rs | 30 ++-- .../std/permutation/rs/src/permutation1_6.rs | 10 +- .../std/permutation/rs/src/permutation1_7.rs | 8 +- .../std/permutation/rs/src/permutation1_8.rs | 8 +- .../std/permutation/rs/src/permutation2.rs | 8 +- .../std/permutation/rs/src/permutation_lib.rs | 26 ++-- .../range_check/rs/src/multi_range_check1.rs | 8 +- .../range_check/rs/src/multi_range_check2.rs | 8 +- .../std/range_check/rs/src/range_check1.rs | 8 +- .../std/range_check/rs/src/range_check2.rs | 8 +- .../std/range_check/rs/src/range_check3.rs | 8 +- .../std/range_check/rs/src/range_check4.rs | 8 +- .../rs/src/range_check_dynamic1.rs | 8 +- .../rs/src/range_check_dynamic2.rs | 8 +- .../std/range_check/rs/src/range_check_lib.rs | 36 ++--- .../std/range_check/rs/src/range_check_mix.rs | 8 +- proofman/src/constraints.rs | 6 +- proofman/src/proofman.rs | 128 +++++------------- proofman/src/recursion.rs | 5 +- proofman/src/witness_component.rs | 5 +- proofman/src/witness_executor.rs | 4 +- proofman/src/witness_library.rs | 10 +- proofman/src/witness_manager.rs | 22 ++- 54 files changed, 320 insertions(+), 556 deletions(-) delete mode 100644 common/src/custom_commits.rs delete mode 100644 common/src/execution_ctx.rs diff --git a/cli/src/commands/prove.rs b/cli/src/commands/prove.rs index bc8ede47..d18fac36 100644 --- a/cli/src/commands/prove.rs +++ b/cli/src/commands/prove.rs @@ -1,8 +1,7 @@ // extern crate env_logger; use clap::Parser; -use proofman_common::{initialize_logger, parse_cached_buffers, StdMode, DEFAULT_PRINT_VALS}; +use proofman_common::{initialize_logger, StdMode, DEFAULT_PRINT_VALS}; use std::path::PathBuf; -use std::collections::HashMap; use colored::Colorize; use crate::commands::field::Field; @@ -31,10 +30,6 @@ pub struct ProveCmd { #[clap(short = 'i', long)] pub public_inputs: Option, - /// Cached buffer path - #[clap(short = 'c', long, value_parser = parse_cached_buffers)] - pub cached_buffers: Option>, - /// Setup folder path #[clap(long)] pub proving_key: PathBuf, @@ -83,16 +78,18 @@ impl ProveCmd { fs::create_dir_all(self.output_dir.join("proofs")).expect("Failed to create the proofs directory"); let std_mode: StdMode = if self.debug == 1 { - let op_ids = self.opids.as_ref().map(|ids| { - ids.iter() - .flat_map(|id| { - id.split(',') - .map(|s| s.trim()) // Trim any surrounding whitespace - .filter_map(|s| s.parse::().ok()) // Try parsing as u64 - .collect::>() // Collect into a Vec - }) - .collect::>() // Collect the entire iterator into a Vec - }); + let op_ids = self.opids.as_ref().map_or_else( + Vec::new, // Provide an empty Vec if self.opids is None + |ids| { + ids.iter() + .flat_map(|id| { + id.split(',') + .map(|s| s.trim()) // Trim any surrounding whitespace + .filter_map(|s| s.parse::().ok()) // Try parsing as u64 + }) + .collect::>() // Collect the entire iterator into a Vec + }, + ); let n_values = self.print.unwrap_or(DEFAULT_PRINT_VALS); let print_to_file = self.print_to_file; @@ -106,7 +103,6 @@ impl ProveCmd { self.witness_lib.clone(), self.rom.clone(), self.public_inputs.clone(), - self.cached_buffers.clone(), self.proving_key.clone(), self.output_dir.clone(), ProofOptions::new(false, self.verbose.into(), std_mode, self.aggregation, self.final_snark), diff --git a/cli/src/commands/verify_constraints.rs b/cli/src/commands/verify_constraints.rs index 02495b76..75ae8390 100644 --- a/cli/src/commands/verify_constraints.rs +++ b/cli/src/commands/verify_constraints.rs @@ -1,7 +1,6 @@ // extern crate env_logger; use clap::Parser; -use std::collections::HashMap; -use proofman_common::{initialize_logger, parse_cached_buffers, StdMode, DEFAULT_PRINT_VALS}; +use proofman_common::{initialize_logger, StdMode, DEFAULT_PRINT_VALS}; use std::path::PathBuf; use colored::Colorize; use crate::commands::field::Field; @@ -29,10 +28,6 @@ pub struct VerifyConstraintsCmd { #[clap(short = 'i', long)] pub public_inputs: Option, - /// Cached buffer path - #[clap(short = 'c', long, value_parser = parse_cached_buffers)] - pub cached_buffers: Option>, - /// Setup folder path #[clap(long)] pub proving_key: PathBuf, @@ -65,16 +60,18 @@ impl VerifyConstraintsCmd { initialize_logger(self.verbose.into()); let std_mode: StdMode = if self.debug == 1 { - let op_ids = self.opids.as_ref().map(|ids| { - ids.iter() - .flat_map(|id| { - id.split(',') - .map(|s| s.trim()) // Trim any surrounding whitespace - .filter_map(|s| s.parse::().ok()) // Try parsing as u64 - .collect::>() // Collect into a Vec - }) - .collect::>() // Collect the entire iterator into a Vec - }); + let op_ids = self.opids.as_ref().map_or_else( + Vec::new, // Provide an empty Vec if self.opids is None + |ids| { + ids.iter() + .flat_map(|id| { + id.split(',') + .map(|s| s.trim()) // Trim any surrounding whitespace + .filter_map(|s| s.parse::().ok()) // Try parsing as u64 + }) + .collect::>() // Collect the entire iterator into a Vec + }, + ); let n_values = self.print.unwrap_or(DEFAULT_PRINT_VALS); let print_to_file = self.print_to_file; @@ -88,7 +85,6 @@ impl VerifyConstraintsCmd { self.witness_lib.clone(), self.rom.clone(), self.public_inputs.clone(), - self.cached_buffers.clone(), self.proving_key.clone(), PathBuf::new(), ProofOptions::new(true, self.verbose.into(), std_mode, false, false), diff --git a/common/src/custom_commits.rs b/common/src/custom_commits.rs deleted file mode 100644 index bed8f223..00000000 --- a/common/src/custom_commits.rs +++ /dev/null @@ -1,58 +0,0 @@ -use proofman_starks_lib_c::{extend_and_merkelize_custom_commit_c, fri_proof_new_c, starks_new_c}; -use p3_goldilocks::Goldilocks; -use serde_json::Value; -use std::collections::HashMap; -use std::path::PathBuf; - -use crate::{Setup, SetupCtx}; - -pub fn parse_cached_buffers(s: &str) -> Result, String> { - let json_data: Value = serde_json::from_str(s).map_err(|e| format!("Invalid JSON: {}", e))?; - let mut map = HashMap::new(); - - if let Some(obj) = json_data.as_object() { - for (key, value) in obj { - if let Some(path_str) = value.as_str() { - map.insert(key.clone(), PathBuf::from(path_str)); - } else { - return Err(format!("Expected string for path in key '{}'", key)); - } - } - } else { - return Err("Expected JSON object for cached_buffers".to_string()); - } - - Ok(map) -} - -pub fn get_custom_commit_id(sctx: &SetupCtx, airgroup_id: usize, air_id: usize, name: &str) -> u64 { - let ps = sctx.get_setup(airgroup_id, air_id); - let commit_id = match ps.stark_info.custom_commits.iter().position(|custom_commit| custom_commit.name == name) { - Some(commit_id) => commit_id as u64, - None => { - eprintln!("Custom commit '{}' not found in custom commits.", name); - std::process::exit(1); - } - }; - commit_id -} - -pub fn get_custom_commit_trace( - commit_id: u64, - step: u64, - setup: &Setup, - buffer: Vec, - buffer_ext: Vec, - buffer_str: &str, -) { - extend_and_merkelize_custom_commit_c( - starks_new_c((&setup.p_setup).into(), std::ptr::null_mut()), - commit_id, - step, - buffer.as_ptr() as *mut u8, - buffer_ext.as_ptr() as *mut u8, - fri_proof_new_c((&setup.p_setup).into()), - std::ptr::null_mut(), - buffer_str, - ); -} diff --git a/common/src/execution_ctx.rs b/common/src/execution_ctx.rs deleted file mode 100644 index 184b3f7f..00000000 --- a/common/src/execution_ctx.rs +++ /dev/null @@ -1,89 +0,0 @@ -use std::path::PathBuf; -use crate::{DistributionCtx, StdMode, VerboseMode}; -use std::sync::RwLock; -use std::collections::HashMap; -#[allow(dead_code)] -/// Represents the context when executing a witness computer plugin -pub struct ExecutionCtx { - pub rom_path: Option, - pub cached_buffers_path: Option>, - /// If true, the plugin must generate the public outputs - pub public_output: bool, - pub verbose_mode: VerboseMode, - pub dctx: RwLock, - pub std_mode: StdMode, -} - -impl ExecutionCtx { - pub fn builder() -> ExecutionCtxBuilder { - ExecutionCtxBuilder::new() - } - - pub fn dctx_add_instance(&self, airgroup_id: usize, air_id: usize, weight: usize) -> (bool, usize) { - let mut dctx = self.dctx.write().unwrap(); - dctx.add_instance(airgroup_id, air_id, weight) - } - - pub fn dctx_distribute_multiplicity(&self, multiplicity: &mut [u64], instance_idx: usize) { - let dctx = self.dctx.read().unwrap(); - let owner = dctx.owner(instance_idx); - dctx.distribute_multiplicity(multiplicity, owner); - } -} - -pub struct ExecutionCtxBuilder { - rom_path: Option, - cached_buffers_path: Option>, - public_output: bool, - verbose_mode: VerboseMode, - std_mode: StdMode, -} - -impl Default for ExecutionCtxBuilder { - fn default() -> Self { - Self::new() - } -} - -impl ExecutionCtxBuilder { - pub fn new() -> Self { - ExecutionCtxBuilder { - rom_path: None, - cached_buffers_path: None, - public_output: true, - verbose_mode: VerboseMode::Info, - std_mode: StdMode::default(), - } - } - - pub fn with_rom_path(mut self, rom_path: Option) -> Self { - self.rom_path = rom_path; - self - } - - pub fn with_cached_buffers_path(mut self, cached_buffers_path: Option>) -> Self { - self.cached_buffers_path = cached_buffers_path; - self - } - - pub fn with_verbose_mode(mut self, verbose_mode: VerboseMode) -> Self { - self.verbose_mode = verbose_mode; - self - } - - pub fn with_std_mode(mut self, std_mode: StdMode) -> Self { - self.std_mode = std_mode; - self - } - - pub fn build(self) -> ExecutionCtx { - ExecutionCtx { - rom_path: self.rom_path, - cached_buffers_path: self.cached_buffers_path, - public_output: self.public_output, - verbose_mode: self.verbose_mode, - dctx: RwLock::new(DistributionCtx::new()), - std_mode: self.std_mode, - } - } -} diff --git a/common/src/lib.rs b/common/src/lib.rs index 77e25c6d..cebcb031 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -1,7 +1,6 @@ mod air_instance; mod air_instances_repository; mod verbose_mode; -mod execution_ctx; mod distribution_ctx; mod proof_ctx; mod prover; @@ -9,7 +8,6 @@ mod extended_field; mod setup; mod setup_ctx; mod std_mode; -mod custom_commits; mod publics; pub mod trace; pub mod global_info; @@ -19,16 +17,14 @@ pub mod utils; pub use air_instance::*; pub use air_instances_repository::*; pub use verbose_mode::*; -pub use execution_ctx::*; -pub use distribution_ctx::*; pub use proof_ctx::*; pub use prover::*; pub use extended_field::*; pub use global_info::*; pub use setup::*; pub use setup_ctx::*; -pub use custom_commits::*; pub use stark_info::*; pub use std_mode::*; pub use publics::*; pub use utils::*; +pub use distribution_ctx::*; diff --git a/common/src/proof_ctx.rs b/common/src/proof_ctx.rs index e0081c06..8dfc45fb 100644 --- a/common/src/proof_ctx.rs +++ b/common/src/proof_ctx.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use p3_field::Field; -use crate::{AirInstancesRepository, GlobalInfo, StdMode, VerboseMode}; +use crate::{distribution_ctx::DistributionCtx, AirInstancesRepository, GlobalInfo, StdMode, VerboseMode}; pub struct Values { pub values: RwLock>, @@ -21,6 +21,7 @@ impl Default for Values { } } +#[derive(Clone)] pub struct ProofOptions { pub verify_constraints: bool, pub verbose_mode: VerboseMode, @@ -49,12 +50,14 @@ pub struct ProofCtx { pub buff_helper: Values, pub global_info: GlobalInfo, pub air_instance_repo: AirInstancesRepository, + pub options: ProofOptions, + pub dctx: RwLock, } impl ProofCtx { const MY_NAME: &'static str = "ProofCtx"; - pub fn create_ctx(proving_key_path: PathBuf) -> Self { + pub fn create_ctx(proving_key_path: PathBuf, options: ProofOptions) -> Self { log::info!("{}: Creating proof context", Self::MY_NAME); let global_info: GlobalInfo = GlobalInfo::new(&proving_key_path); @@ -69,9 +72,22 @@ impl ProofCtx { challenges: Values::new(n_challenges * 3), buff_helper: Values::default(), air_instance_repo: AirInstancesRepository::new(), + dctx: RwLock::new(DistributionCtx::new()), + options, } } + pub fn dctx_add_instance(&self, airgroup_id: usize, air_id: usize, weight: usize) -> (bool, usize) { + let mut dctx = self.dctx.write().unwrap(); + dctx.add_instance(airgroup_id, air_id, weight) + } + + pub fn dctx_distribute_multiplicity(&self, multiplicity: &mut [u64], instance_idx: usize) { + let dctx = self.dctx.read().unwrap(); + let owner = dctx.owner(instance_idx); + dctx.distribute_multiplicity(multiplicity, owner); + } + pub fn set_proof_value(&self, name: &str, value: F) { let id = (0..self.global_info.n_proof_values) .find(|&i| { diff --git a/common/src/std_mode.rs b/common/src/std_mode.rs index 0c11e9f5..0022e83f 100644 --- a/common/src/std_mode.rs +++ b/common/src/std_mode.rs @@ -7,13 +7,13 @@ pub const DEFAULT_PRINT_VALS: usize = 10; #[derive(Clone)] pub struct StdMode { pub name: ModeName, - pub opids: Option>, + pub opids: Vec, pub n_vals: usize, pub print_to_file: bool, } impl StdMode { - pub const fn new(name: ModeName, opids: Option>, n_vals: usize, print_to_file: bool) -> Self { + pub const fn new(name: ModeName, opids: Vec, n_vals: usize, print_to_file: bool) -> Self { if n_vals == 0 { panic!("n_vals must be greater than 0"); } @@ -25,8 +25,8 @@ impl StdMode { impl From for StdMode { fn from(v: u8) -> Self { match v { - 0 => StdMode::new(ModeName::Standard, None, DEFAULT_PRINT_VALS, false), - 1 => StdMode::new(ModeName::Debug, None, DEFAULT_PRINT_VALS, false), + 0 => StdMode::new(ModeName::Standard, Vec::new(), DEFAULT_PRINT_VALS, false), + 1 => StdMode::new(ModeName::Debug, Vec::new(), DEFAULT_PRINT_VALS, false), _ => panic!("Invalid mode"), } } @@ -34,7 +34,7 @@ impl From for StdMode { impl Default for StdMode { fn default() -> Self { - StdMode::new(ModeName::Standard, None, DEFAULT_PRINT_VALS, false) + StdMode::new(ModeName::Standard, Vec::new(), DEFAULT_PRINT_VALS, false) } } diff --git a/common/src/utils.rs b/common/src/utils.rs index 25d4ed57..956e38a2 100644 --- a/common/src/utils.rs +++ b/common/src/utils.rs @@ -1,10 +1,10 @@ -use crate::{AirInstance, ExecutionCtx, ProofCtx, VerboseMode}; +use crate::{AirInstance, ProofCtx, VerboseMode}; use proofman_starks_lib_c::set_log_level_c; use std::sync::Arc; use p3_field::Field; -pub fn add_air_instance(air_instance: AirInstance, ectx: Arc, pctx: Arc>) { - let (is_mine, gid) = ectx.dctx.write().unwrap().add_instance(air_instance.airgroup_id, air_instance.air_id, 1); +pub fn add_air_instance(air_instance: AirInstance, pctx: Arc>) { + let (is_mine, gid) = pctx.dctx.write().unwrap().add_instance(air_instance.airgroup_id, air_instance.air_id, 1); if is_mine { pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); diff --git a/examples/fibonacci-square/src/fibonacci.rs b/examples/fibonacci-square/src/fibonacci.rs index 4b836173..c77bd000 100644 --- a/examples/fibonacci-square/src/fibonacci.rs +++ b/examples/fibonacci-square/src/fibonacci.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use proofman_common::{add_air_instance, AirInstance, FromTrace, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, AirInstance, FromTrace, ProofCtx, SetupCtx}; use proofman::{WitnessManager, WitnessComponent}; use p3_field::PrimeField64; @@ -29,17 +29,13 @@ impl FibonacciSquare { fibonacci } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { - if let Err(e) = Self::calculate_trace(self, pctx, ectx) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + if let Err(e) = Self::calculate_trace(self, pctx) { panic!("Failed to calculate fibonacci: {:?}", e); } } - fn calculate_trace( - &self, - pctx: Arc>, - ectx: Arc, - ) -> Result> { + fn calculate_trace(&self, pctx: Arc>) -> Result> { log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let mut publics = BuildPublicValues::from_vec_guard(pctx.get_publics()); @@ -83,7 +79,7 @@ impl FibonacciSquare { let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace).with_custom_traces(vec![&mut trace_rom]).with_air_values(&mut air_values), ); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); Ok(b) } @@ -95,7 +91,6 @@ impl WitnessComponent for FibonacciSquare { _stage: u32, _air_instance_id: Option, _pctx: Arc>, - _ectx: Arc, _sctx: Arc, ) { } diff --git a/examples/fibonacci-square/src/fibonacci_lib.rs b/examples/fibonacci-square/src/fibonacci_lib.rs index bcdf13ec..9206bbc8 100644 --- a/examples/fibonacci-square/src/fibonacci_lib.rs +++ b/examples/fibonacci-square/src/fibonacci_lib.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use proofman_common::{initialize_logger, load_from_json, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode}; +use proofman_common::{initialize_logger, load_from_json, ProofCtx, SetupCtx, VerboseMode}; use proofman::{WitnessLibrary, WitnessManager}; use pil_std_lib::Std; use p3_field::PrimeField64; @@ -26,8 +26,8 @@ impl FibonacciWitness { } impl WitnessLibrary for FibonacciWitness { - fn start_proof(&mut self, pctx: Arc>, ectx: Arc, sctx: Arc) { - let wcm = Arc::new(WitnessManager::new(pctx.clone(), ectx.clone(), sctx.clone())); + fn start_proof(&mut self, pctx: Arc>, sctx: Arc) { + let wcm = Arc::new(WitnessManager::new(pctx.clone(), sctx.clone())); let std_lib = Std::new(wcm.clone()); let module = Module::new(wcm.clone(), std_lib.clone()); @@ -46,20 +46,20 @@ impl WitnessLibrary for FibonacciWitness { publics.in1 = F::from_canonical_u64(public_inputs.in1); publics.in2 = F::from_canonical_u64(public_inputs.in2); - wcm.start_proof(pctx, ectx, sctx); + wcm.start_proof(pctx, sctx); } fn end_proof(&mut self) { self.wcm.as_ref().unwrap().end_proof(); } - fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { - self.fibonacci.as_ref().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.module.as_ref().unwrap().execute(pctx, ectx, sctx); + fn execute(&self, pctx: Arc>, sctx: Arc) { + self.fibonacci.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); + self.module.as_ref().unwrap().execute(pctx, sctx); } - fn calculate_witness(&mut self, stage: u32, pctx: Arc>, ectx: Arc, sctx: Arc) { - self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, ectx, sctx); + fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { + self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, sctx); } } diff --git a/examples/fibonacci-square/src/module.rs b/examples/fibonacci-square/src/module.rs index 7ffa0fbe..8d76e956 100644 --- a/examples/fibonacci-square/src/module.rs +++ b/examples/fibonacci-square/src/module.rs @@ -1,6 +1,6 @@ use std::sync::{Arc, Mutex}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use proofman::{WitnessManager, WitnessComponent}; use pil_std_lib::Std; use p3_field::{AbstractField, PrimeField64}; @@ -37,11 +37,11 @@ impl Module< x_mod } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { - self.calculate_trace(pctx, ectx); + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + self.calculate_trace(pctx); } - fn calculate_trace(&self, pctx: Arc>, ectx: Arc) { + fn calculate_trace(&self, pctx: Arc>) { log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let module = F::as_canonical_u64(&pctx.get_public_value("module")); @@ -72,7 +72,7 @@ impl Module< } let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); self.std_lib.unregister_predecessor(pctx, None); } @@ -84,7 +84,6 @@ impl WitnessComponent for Module { _stage: u32, _air_instance_id: Option, _pctx: Arc>, - _ectx: Arc, _sctx: Arc, ) { } diff --git a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs index 9a28a700..1a10b51e 100644 --- a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs +++ b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs @@ -5,7 +5,7 @@ use num_traits::ToPrimitive; use p3_field::PrimeField; use proofman::{get_hint_field_gc, WitnessComponent, WitnessManager}; -use proofman_common::{TraceInfo, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{AirInstance, DistributionCtx, ProofCtx, SetupCtx, TraceInfo}; use proofman_hints::{ get_hint_field, get_hint_field_constant, get_hint_ids_by_name, set_hint_field, HintFieldOptions, HintFieldValue, }; @@ -95,12 +95,11 @@ impl SpecifiedRanges { let mut inputs = self.inputs.lock().unwrap(); let drained_inputs = inputs.drain(..).collect(); let pctx = self.wcm.get_pctx(); - let ectx = self.wcm.get_ectx(); // Perform the last update self.update_multiplicity(drained_inputs); - let mut dctx: std::sync::RwLockWriteGuard<'_, proofman_common::DistributionCtx> = ectx.dctx.write().unwrap(); + let mut dctx: std::sync::RwLockWriteGuard<'_, DistributionCtx> = pctx.dctx.write().unwrap(); let (is_mine, global_idx) = dctx.add_instance(self.airgroup_id, self.air_id, 1); @@ -188,7 +187,7 @@ impl SpecifiedRanges { } impl WitnessComponent for SpecifiedRanges { - fn start_proof(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + fn start_proof(&self, pctx: Arc>, sctx: Arc) { // Obtain info from the mul hints let setup = sctx.get_setup(self.airgroup_id, self.air_id); let specified_hints = get_hint_ids_by_name(setup.p_setup.p_expressions_bin, "specified_ranges"); @@ -343,7 +342,6 @@ impl WitnessComponent for SpecifiedRanges { _stage: u32, _air_instance: Option, _pctx: Arc>, - _ectx: Arc, _sctx: Arc, ) { } diff --git a/pil2-components/lib/std/rs/src/range_check/std_range_check.rs b/pil2-components/lib/std/rs/src/range_check/std_range_check.rs index f788d3ec..016759ae 100644 --- a/pil2-components/lib/std/rs/src/range_check/std_range_check.rs +++ b/pil2-components/lib/std/rs/src/range_check/std_range_check.rs @@ -8,7 +8,7 @@ use num_bigint::BigInt; use p3_field::PrimeField; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{ExecutionCtx, ProofCtx, SetupCtx, StdMode, ModeName}; +use proofman_common::{ProofCtx, SetupCtx, StdMode, ModeName}; use proofman_hints::{get_hint_field_constant, get_hint_ids_by_name, HintFieldOptions, HintFieldValue}; use rayon::Scope; @@ -284,7 +284,7 @@ impl StdRangeCheck { } impl WitnessComponent for StdRangeCheck { - fn start_proof(&self, _pctx: Arc>, _ectx: Arc, sctx: Arc) { + fn start_proof(&self, _pctx: Arc>, sctx: Arc) { self.decide(sctx); } @@ -293,7 +293,6 @@ impl WitnessComponent for StdRangeCheck { _stage: u32, _air_instance: Option, _pctx: Arc>, - _ectx: Arc, _sctx: Arc, ) { // Nothing to do diff --git a/pil2-components/lib/std/rs/src/range_check/u16air.rs b/pil2-components/lib/std/rs/src/range_check/u16air.rs index 6dccac6f..e6df4913 100644 --- a/pil2-components/lib/std/rs/src/range_check/u16air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u16air.rs @@ -4,7 +4,7 @@ use num_traits::ToPrimitive; use p3_field::{Field, PrimeField}; use proofman::{get_hint_field_gc, WitnessComponent, WitnessManager}; -use proofman_common::{TraceInfo, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{TraceInfo, AirInstance, ProofCtx, SetupCtx}; use proofman_hints::{get_hint_field, get_hint_ids_by_name, set_hint_field, HintFieldOptions, HintFieldValue}; use proofman_util::create_buffer_fast; @@ -88,12 +88,11 @@ impl U16Air { let mut inputs = self.inputs.lock().unwrap(); let drained_inputs = inputs.drain(..).collect(); let pctx = self.wcm.get_pctx(); - let ectx = self.wcm.get_ectx(); // Perform the last update self.update_multiplicity(drained_inputs); - let mut dctx: std::sync::RwLockWriteGuard<'_, proofman_common::DistributionCtx> = ectx.dctx.write().unwrap(); + let mut dctx: std::sync::RwLockWriteGuard<'_, proofman_common::DistributionCtx> = pctx.dctx.write().unwrap(); let (is_mine, global_idx) = dctx.add_instance(self.airgroup_id, self.air_id, 1); let mut multiplicity = match &*self.mul_column.lock().unwrap() { @@ -162,7 +161,7 @@ impl U16Air { } impl WitnessComponent for U16Air { - fn start_proof(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + fn start_proof(&self, pctx: Arc>, sctx: Arc) { // Obtain info from the mul hints let setup = sctx.get_setup(self.airgroup_id, self.air_id); let u16air_hints = get_hint_ids_by_name(setup.p_setup.p_expressions_bin, "u16air"); @@ -197,7 +196,6 @@ impl WitnessComponent for U16Air { _stage: u32, _air_instance: Option, _pctx: Arc>, - _ectx: Arc, _sctx: Arc, ) { } diff --git a/pil2-components/lib/std/rs/src/range_check/u8air.rs b/pil2-components/lib/std/rs/src/range_check/u8air.rs index a45acbf7..938b75e8 100644 --- a/pil2-components/lib/std/rs/src/range_check/u8air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u8air.rs @@ -3,7 +3,7 @@ use num_traits::ToPrimitive; use p3_field::{Field, PrimeField}; use proofman::{get_hint_field_gc, WitnessComponent, WitnessManager}; -use proofman_common::{TraceInfo, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{TraceInfo, AirInstance, ProofCtx, SetupCtx}; use proofman_hints::{get_hint_field, get_hint_ids_by_name, set_hint_field, HintFieldOptions, HintFieldValue}; use proofman_util::create_buffer_fast; use std::sync::atomic::Ordering; @@ -87,12 +87,11 @@ impl U8Air { let mut inputs = self.inputs.lock().unwrap(); let drained_inputs = inputs.drain(..).collect(); let pctx = self.wcm.get_pctx(); - let ectx = self.wcm.get_ectx(); // Perform the last update self.update_multiplicity(drained_inputs); - let mut dctx: std::sync::RwLockWriteGuard<'_, proofman_common::DistributionCtx> = ectx.dctx.write().unwrap(); + let mut dctx: std::sync::RwLockWriteGuard<'_, proofman_common::DistributionCtx> = pctx.dctx.write().unwrap(); let (is_mine, global_idx) = dctx.add_instance(self.airgroup_id, self.air_id, 1); let mut multiplicity = match &*self.mul_column.lock().unwrap() { @@ -159,7 +158,7 @@ impl U8Air { } impl WitnessComponent for U8Air { - fn start_proof(&self, pctx: Arc>, _ectx: Arc, sctx: Arc) { + fn start_proof(&self, pctx: Arc>, sctx: Arc) { // Obtain info from the mul hints let setup = sctx.get_setup(self.airgroup_id, self.air_id); let u8air_hints = get_hint_ids_by_name(setup.p_setup.p_expressions_bin, "u8air"); @@ -194,7 +193,6 @@ impl WitnessComponent for U8Air { _stage: u32, _air_instance: Option, _pctx: Arc>, - _ectx: Arc, _sctx: Arc, ) { } diff --git a/pil2-components/lib/std/rs/src/std.rs b/pil2-components/lib/std/rs/src/std.rs index 66291125..db0ddc7e 100644 --- a/pil2-components/lib/std/rs/src/std.rs +++ b/pil2-components/lib/std/rs/src/std.rs @@ -21,7 +21,7 @@ impl Std { const MY_NAME: &'static str = "STD "; pub fn new(wcm: Arc>) -> Arc { - let mode = wcm.get_ectx().std_mode.clone(); + let mode = wcm.get_pctx().options.std_mode.clone(); log::info!("{}: ··· The PIL2 STD library has been initialized on mode {}", Self::MY_NAME, mode.name); diff --git a/pil2-components/lib/std/rs/src/std_prod.rs b/pil2-components/lib/std/rs/src/std_prod.rs index e0a7af52..02a8ade9 100644 --- a/pil2-components/lib/std/rs/src/std_prod.rs +++ b/pil2-components/lib/std/rs/src/std_prod.rs @@ -7,7 +7,7 @@ use num_traits::ToPrimitive; use p3_field::PrimeField; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ModeName, ProofCtx, SetupCtx, StdMode}; +use proofman_common::{AirInstance, ModeName, ProofCtx, SetupCtx, StdMode}; use proofman_hints::{ get_hint_field, get_hint_field_a, get_hint_field_constant, get_hint_field_constant_a, get_hint_ids_by_name, update_airgroupvalue, acc_mul_hint_fields, HintFieldOptions, HintFieldOutput, HintFieldValue, HintFieldValuesVec, @@ -91,10 +91,10 @@ impl StdProd { let opid = get_hint_field::(sctx, pctx, air_instance, *hint as usize, "opid", HintFieldOptions::default()); let opid = if let HintFieldValue::Field(opid) = opid { - if let Some(opids) = &self.mode.opids { - if !opids.contains(&opid.as_canonical_biguint().to_u64().expect("Cannot convert to u64")) { - continue; - } + if !self.mode.opids.is_empty() + && !self.mode.opids.contains(&opid.as_canonical_biguint().to_u64().expect("Cannot convert to u64")) + { + continue; } opid @@ -245,18 +245,11 @@ impl StdProd { } impl WitnessComponent for StdProd { - fn start_proof(&self, _pctx: Arc>, _ectx: Arc, sctx: Arc) { + fn start_proof(&self, _pctx: Arc>, sctx: Arc) { self.decide(sctx); } - fn calculate_witness( - &self, - stage: u32, - _air_instance: Option, - pctx: Arc>, - _ectx: Arc, - sctx: Arc, - ) { + fn calculate_witness(&self, stage: u32, _air_instance: Option, pctx: Arc>, sctx: Arc) { if stage == 2 { let prod_airs = self.prod_airs.lock().unwrap(); diff --git a/pil2-components/lib/std/rs/src/std_sum.rs b/pil2-components/lib/std/rs/src/std_sum.rs index a246aac2..644329b3 100644 --- a/pil2-components/lib/std/rs/src/std_sum.rs +++ b/pil2-components/lib/std/rs/src/std_sum.rs @@ -7,7 +7,7 @@ use num_traits::ToPrimitive; use p3_field::PrimeField; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx, StdMode, ModeName}; +use proofman_common::{AirInstance, ProofCtx, SetupCtx, StdMode, ModeName}; use proofman_hints::{ get_hint_field, get_hint_field_a, get_hint_field_constant, get_hint_field_constant_a, acc_mul_hint_fields, update_airgroupvalue, get_hint_ids_by_name, mul_hint_fields, HintFieldOptions, HintFieldOutput, HintFieldValue, @@ -93,10 +93,10 @@ impl StdSum { let opid = get_hint_field::(sctx, pctx, air_instance, *hint as usize, "opid", HintFieldOptions::default()); if let HintFieldOutput::Field(opid) = opid.get(0) { - if let Some(opids) = &self.mode.opids { - if !opids.contains(&opid.as_canonical_biguint().to_u64().expect("Cannot convert to u64")) { - continue; - } + if !self.mode.opids.is_empty() + && !self.mode.opids.contains(&opid.as_canonical_biguint().to_u64().expect("Cannot convert to u64")) + { + continue; } } else { panic!("opid must be a field element"); @@ -243,18 +243,11 @@ impl StdSum { } impl WitnessComponent for StdSum { - fn start_proof(&self, _pctx: Arc>, _ectx: Arc, sctx: Arc) { + fn start_proof(&self, _pctx: Arc>, sctx: Arc) { self.decide(sctx); } - fn calculate_witness( - &self, - stage: u32, - _air_instance: Option, - pctx: Arc>, - _ectx: Arc, - sctx: Arc, - ) { + fn calculate_witness(&self, stage: u32, _air_instance: Option, pctx: Arc>, sctx: Arc) { if stage == 2 { let sum_airs = self.sum_airs.lock().unwrap(); diff --git a/pil2-components/test/simple/rs/src/simple_left.rs b/pil2-components/test/simple/rs/src/simple_left.rs index 33143c4e..01f6eba3 100644 --- a/pil2-components/test/simple/rs/src/simple_left.rs +++ b/pil2-components/test/simple/rs/src/simple_left.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, seq::SliceRandom}; @@ -26,7 +26,7 @@ where simple_left } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = SimpleLeftTrace::new(); @@ -57,7 +57,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -70,7 +70,6 @@ where _stage: u32, _air_instance_id: Option, _pctx: Arc>, - _ectx: Arc, _sctx: Arc, ) { } diff --git a/pil2-components/test/simple/rs/src/simple_lib.rs b/pil2-components/test/simple/rs/src/simple_lib.rs index a15f5ff3..1e0f085f 100644 --- a/pil2-components/test/simple/rs/src/simple_lib.rs +++ b/pil2-components/test/simple/rs/src/simple_lib.rs @@ -2,7 +2,7 @@ use std::{error::Error, path::PathBuf, sync::Arc}; use pil_std_lib::Std; use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode}; +use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; use p3_field::PrimeField; use p3_goldilocks::Goldilocks; @@ -34,8 +34,8 @@ where Self { wcm: None, simple_left: None, simple_right: None, std_lib: None } } - pub fn initialize(&mut self, pctx: Arc>, ectx: Arc, sctx: Arc) { - let wcm = Arc::new(WitnessManager::new(pctx, ectx, sctx)); + pub fn initialize(&mut self, pctx: Arc>, sctx: Arc) { + let wcm = Arc::new(WitnessManager::new(pctx, sctx)); let std_lib = Std::new(wcm.clone()); let simple_left = SimpleLeft::new(wcm.clone()); @@ -52,24 +52,24 @@ impl WitnessLibrary for SimpleWitness where Standard: Distribution, { - fn start_proof(&mut self, pctx: Arc>, ectx: Arc, sctx: Arc) { - self.initialize(pctx.clone(), ectx.clone(), sctx.clone()); + fn start_proof(&mut self, pctx: Arc>, sctx: Arc) { + self.initialize(pctx.clone(), sctx.clone()); - self.wcm.as_ref().unwrap().start_proof(pctx, ectx, sctx); + self.wcm.as_ref().unwrap().start_proof(pctx, sctx); } fn end_proof(&mut self) { self.wcm.as_ref().unwrap().end_proof(); } - fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + fn execute(&self, pctx: Arc>, sctx: Arc) { // Execute those components that need to be executed - self.simple_left.as_ref().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.simple_right.as_ref().unwrap().execute(pctx, ectx, sctx); + self.simple_left.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); + self.simple_right.as_ref().unwrap().execute(pctx, sctx); } - fn calculate_witness(&mut self, stage: u32, pctx: Arc>, ectx: Arc, sctx: Arc) { - self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, ectx, sctx); + fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { + self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, sctx); } } diff --git a/pil2-components/test/simple/rs/src/simple_right.rs b/pil2-components/test/simple/rs/src/simple_right.rs index 40a6879b..c581046c 100644 --- a/pil2-components/test/simple/rs/src/simple_right.rs +++ b/pil2-components/test/simple/rs/src/simple_right.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution}; @@ -29,7 +29,7 @@ where simple_right } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut trace = SimpleRightTrace::new(); let num_rows = trace.num_rows(); @@ -47,7 +47,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -60,7 +60,6 @@ where _stage: u32, _air_instance_id: Option, _pctx: Arc>, - _ectx: Arc, _sctx: Arc, ) { } diff --git a/pil2-components/test/std/connection/rs/src/connection1.rs b/pil2-components/test/std/connection/rs/src/connection1.rs index 132b0738..992d0a6f 100644 --- a/pil2-components/test/std/connection/rs/src/connection1.rs +++ b/pil2-components/test/std/connection/rs/src/connection1.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where connection1 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Connection1Trace::new_zeroes(); @@ -44,7 +44,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -57,7 +57,7 @@ where _stage: u32, _air_instance_id: Option, _pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { } diff --git a/pil2-components/test/std/connection/rs/src/connection2.rs b/pil2-components/test/std/connection/rs/src/connection2.rs index 2fd2e130..e42c9385 100644 --- a/pil2-components/test/std/connection/rs/src/connection2.rs +++ b/pil2-components/test/std/connection/rs/src/connection2.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where connection2 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Connection2Trace::new_zeroes(); @@ -46,7 +46,7 @@ where trace[0].a = trace[1].a; let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -59,7 +59,7 @@ where _stage: u32, _air_instance_id: Option, _pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { } diff --git a/pil2-components/test/std/connection/rs/src/connection_lib.rs b/pil2-components/test/std/connection/rs/src/connection_lib.rs index 943e8727..7099ad3e 100644 --- a/pil2-components/test/std/connection/rs/src/connection_lib.rs +++ b/pil2-components/test/std/connection/rs/src/connection_lib.rs @@ -2,7 +2,7 @@ use std::{error::Error, path::PathBuf, sync::Arc}; use pil_std_lib::Std; use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode}; +use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; use p3_field::PrimeField; use p3_goldilocks::Goldilocks; @@ -35,8 +35,8 @@ where ConnectionWitness { wcm: None, connection1: None, connection2: None, connection_new: None, std_lib: None } } - pub fn initialize(&mut self, pctx: Arc>, ectx: Arc, sctx: Arc) { - let wcm = Arc::new(WitnessManager::new(pctx, ectx, sctx)); + pub fn initialize(&mut self, pctx: Arc>, sctx: Arc) { + let wcm = Arc::new(WitnessManager::new(pctx, sctx)); let std_lib = Std::new(wcm.clone()); let connection1 = Connection1::new(wcm.clone()); @@ -55,25 +55,25 @@ impl WitnessLibrary for ConnectionWitness where Standard: Distribution, { - fn start_proof(&mut self, pctx: Arc>, ectx: Arc, sctx: Arc) { - self.initialize(pctx.clone(), ectx.clone(), sctx.clone()); + fn start_proof(&mut self, pctx: Arc>, sctx: Arc) { + self.initialize(pctx.clone(), sctx.clone()); - self.wcm.as_ref().unwrap().start_proof(pctx, ectx, sctx); + self.wcm.as_ref().unwrap().start_proof(pctx, sctx); } fn end_proof(&mut self) { self.wcm.as_ref().unwrap().end_proof(); } - fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + fn execute(&self, pctx: Arc>, sctx: Arc) { // Execute those components that need to be executed - self.connection1.as_ref().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.connection2.as_ref().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.connection_new.as_ref().unwrap().execute(pctx, ectx, sctx); + self.connection1.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); + self.connection2.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); + self.connection_new.as_ref().unwrap().execute(pctx, sctx); } - fn calculate_witness(&mut self, stage: u32, pctx: Arc>, ectx: Arc, sctx: Arc) { - self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, ectx, sctx); + fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { + self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, sctx); } } diff --git a/pil2-components/test/std/connection/rs/src/connection_new.rs b/pil2-components/test/std/connection/rs/src/connection_new.rs index 7bc74d41..3742b224 100644 --- a/pil2-components/test/std/connection/rs/src/connection_new.rs +++ b/pil2-components/test/std/connection/rs/src/connection_new.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where connection_new } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = ConnectionNewTrace::new_zeroes(); let num_rows = trace.num_rows(); @@ -137,7 +137,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -150,7 +150,7 @@ where _stage: u32, _air_instance_id: Option, _pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { } diff --git a/pil2-components/test/std/lookup/rs/src/lookup0.rs b/pil2-components/test/std/lookup/rs/src/lookup0.rs index 0bef6f13..eaa72447 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup0.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup0.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where lookup0 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup0Trace::new(); @@ -57,7 +57,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -70,7 +70,7 @@ where _stage: u32, _air_instance_id: Option, _pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { } diff --git a/pil2-components/test/std/lookup/rs/src/lookup1.rs b/pil2-components/test/std/lookup/rs/src/lookup1.rs index 637643b0..452d70dc 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup1.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup1.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where lookup1 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup1Trace::new(); @@ -55,7 +55,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -68,7 +68,7 @@ where _stage: u32, _air_instance_id: Option, _pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs index b416e4b9..df73ac2d 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where lookup2_12 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup2_12Trace::new(); @@ -67,7 +67,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -80,7 +80,7 @@ where _stage: u32, _air_instance_id: Option, _pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs index 5c029de7..f11d89f5 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where lookup2_13 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup2_13Trace::new(); @@ -67,7 +67,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -80,7 +80,7 @@ where _stage: u32, _air_instance_id: Option, _pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs index a691b33a..7accb79c 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where lookup2_15 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Lookup2_15Trace::new(); @@ -67,7 +67,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -80,7 +80,7 @@ where _stage: u32, _air_instance_id: Option, _pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { } diff --git a/pil2-components/test/std/lookup/rs/src/lookup3.rs b/pil2-components/test/std/lookup/rs/src/lookup3.rs index dbea2e25..23d0746f 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup3.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup3.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use p3_field::PrimeField; @@ -25,7 +25,7 @@ impl Lookup3 { lookup3 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { // For simplicity, add a single instance of each air let mut trace = Lookup3Trace::new(); let num_rows = trace.num_rows(); @@ -55,7 +55,7 @@ impl Lookup3 { } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -65,7 +65,7 @@ impl WitnessComponent for Lookup3 { _stage: u32, _air_instance_id: Option, _pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { } diff --git a/pil2-components/test/std/lookup/rs/src/lookup_lib.rs b/pil2-components/test/std/lookup/rs/src/lookup_lib.rs index 106a6a85..ed8370d5 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup_lib.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup_lib.rs @@ -2,7 +2,7 @@ use std::{error::Error, path::PathBuf, sync::Arc}; use pil_std_lib::Std; use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode}; +use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; use p3_field::PrimeField; use p3_goldilocks::Goldilocks; @@ -47,8 +47,8 @@ where } } - pub fn initialize(&mut self, pctx: Arc>, ectx: Arc, sctx: Arc) { - let wcm = Arc::new(WitnessManager::new(pctx, ectx, sctx)); + pub fn initialize(&mut self, pctx: Arc>, sctx: Arc) { + let wcm = Arc::new(WitnessManager::new(pctx, sctx)); let std_lib = Std::new(wcm.clone()); let lookup0 = Lookup0::new(wcm.clone()); @@ -73,28 +73,28 @@ impl WitnessLibrary for LookupWitness where Standard: Distribution, { - fn start_proof(&mut self, pctx: Arc>, ectx: Arc, sctx: Arc) { - self.initialize(pctx.clone(), ectx.clone(), sctx.clone()); + fn start_proof(&mut self, pctx: Arc>, sctx: Arc) { + self.initialize(pctx.clone(), sctx.clone()); - self.wcm.as_ref().unwrap().start_proof(pctx, ectx, sctx); + self.wcm.as_ref().unwrap().start_proof(pctx, sctx); } fn end_proof(&mut self) { self.wcm.as_ref().unwrap().end_proof(); } - fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + fn execute(&self, pctx: Arc>, sctx: Arc) { // Execute those components that need to be executed - self.lookup0.as_ref().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.lookup1.as_ref().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.lookup2_12.as_ref().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.lookup2_13.as_ref().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.lookup2_15.as_ref().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.lookup3.as_ref().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); + self.lookup0.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); + self.lookup1.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); + self.lookup2_12.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); + self.lookup2_13.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); + self.lookup2_15.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); + self.lookup3.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); } - fn calculate_witness(&mut self, stage: u32, pctx: Arc>, ectx: Arc, sctx: Arc) { - self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, ectx, sctx); + fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { + self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, sctx); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs index 59a97fd3..663c93e7 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, seq::SliceRandom, Rng}; @@ -29,7 +29,7 @@ where permutation1_6 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Permutation1_6Trace::new(); @@ -74,7 +74,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx.clone(), pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); let mut trace2 = Permutation1_6Trace::new(); @@ -112,7 +112,7 @@ where } let air_instance2 = AirInstance::new_from_trace( FromTrace::new(&mut trace2)); - add_air_instance::(air_instance2, ectx, pctx.clone()); + add_air_instance::(air_instance2, pctx.clone()); } } @@ -125,7 +125,7 @@ where _stage: u32, _air_instance_id: Option, _pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs index 8c4cd54d..1c057bf5 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where permutation1_7 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Permutation1_7Trace::new(); let num_rows = trace.num_rows(); @@ -74,7 +74,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -87,7 +87,7 @@ where _stage: u32, _air_instance_id: Option, _pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs index 02add697..7aebf774 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -29,7 +29,7 @@ where permutation1_8 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = Permutation1_8Trace::new(); let num_rows = trace.num_rows(); @@ -74,7 +74,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -87,7 +87,7 @@ where _stage: u32, _air_instance_id: Option, _pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { } diff --git a/pil2-components/test/std/permutation/rs/src/permutation2.rs b/pil2-components/test/std/permutation/rs/src/permutation2.rs index d3d72541..5a27b7dc 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation2.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation2.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use p3_field::PrimeField; @@ -25,7 +25,7 @@ impl Permutation2 { permutation2 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut trace = Permutation2_6Trace::new(); let num_rows = trace.num_rows(); @@ -46,7 +46,7 @@ impl Permutation2 { } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -56,7 +56,7 @@ impl WitnessComponent for Permutation2 { _stage: u32, _air_instance_id: Option, _pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { } diff --git a/pil2-components/test/std/permutation/rs/src/permutation_lib.rs b/pil2-components/test/std/permutation/rs/src/permutation_lib.rs index cbd15081..3b0b8c42 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation_lib.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation_lib.rs @@ -2,7 +2,7 @@ use std::{error::Error, path::PathBuf, sync::Arc}; use pil_std_lib::Std; use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode}; +use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; use p3_field::PrimeField; use p3_goldilocks::Goldilocks; @@ -43,8 +43,8 @@ where } } - pub fn initialize(&mut self, pctx: Arc>, ectx: Arc, sctx: Arc) { - let wcm = Arc::new(WitnessManager::new(pctx, ectx, sctx)); + pub fn initialize(&mut self, pctx: Arc>, sctx: Arc) { + let wcm = Arc::new(WitnessManager::new(pctx, sctx)); let std_lib = Std::new(wcm.clone()); let permutation1_6 = Permutation1_6::new(wcm.clone()); @@ -65,26 +65,26 @@ impl WitnessLibrary for PermutationWitness where Standard: Distribution, { - fn start_proof(&mut self, pctx: Arc>, ectx: Arc, sctx: Arc) { - self.initialize(pctx.clone(), ectx.clone(), sctx.clone()); + fn start_proof(&mut self, pctx: Arc>, sctx: Arc) { + self.initialize(pctx.clone(), sctx.clone()); - self.wcm.as_ref().unwrap().start_proof(pctx, ectx, sctx); + self.wcm.as_ref().unwrap().start_proof(pctx, sctx); } fn end_proof(&mut self) { self.wcm.as_ref().unwrap().end_proof(); } - fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + fn execute(&self, pctx: Arc>, sctx: Arc) { // Execute those components that need to be executed - self.permutation1_6.as_ref().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.permutation1_7.as_ref().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.permutation1_8.as_ref().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.permutation2.as_ref().unwrap().execute(pctx, ectx, sctx); + self.permutation1_6.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); + self.permutation1_7.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); + self.permutation1_8.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); + self.permutation2.as_ref().unwrap().execute(pctx, sctx); } - fn calculate_witness(&mut self, stage: u32, pctx: Arc>, ectx: Arc, sctx: Arc) { - self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, ectx, sctx); + fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { + self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, sctx); } } diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs index 702b1dc4..f6e542c7 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -34,7 +34,7 @@ where multi_range_check1 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = MultiRangeCheck1Trace::new_zeroes(); @@ -102,7 +102,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -115,7 +115,7 @@ where _stage: u32, _air_instance_id: Option, pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { self.std_lib.unregister_predecessor(pctx, None); diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs index 7462715a..b3b63359 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -34,7 +34,7 @@ where multi_range_check2 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = MultiRangeCheck2Trace::new_zeroes(); @@ -84,7 +84,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -97,7 +97,7 @@ where _stage: u32, _air_instance_id: Option, pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { self.std_lib.unregister_predecessor(pctx, None); diff --git a/pil2-components/test/std/range_check/rs/src/range_check1.rs b/pil2-components/test/std/range_check/rs/src/range_check1.rs index 7c3008bd..93ad1d81 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check1.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -34,7 +34,7 @@ where range_check1 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck1Trace::new_zeroes(); @@ -81,7 +81,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -94,7 +94,7 @@ where _stage: u32, _air_instance_id: Option, pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { self.std_lib.unregister_predecessor(pctx, None); diff --git a/pil2-components/test/std/range_check/rs/src/range_check2.rs b/pil2-components/test/std/range_check/rs/src/range_check2.rs index fe9b124d..295c15e0 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check2.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -34,7 +34,7 @@ where range_check2 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck2Trace::new_zeroes(); let num_rows = trace.num_rows(); @@ -56,7 +56,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -69,7 +69,7 @@ where _stage: u32, _air_instance_id: Option, pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { self.std_lib.unregister_predecessor(pctx, None); diff --git a/pil2-components/test/std/range_check/rs/src/range_check3.rs b/pil2-components/test/std/range_check/rs/src/range_check3.rs index 84b845ee..ef512890 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check3.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check3.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -34,7 +34,7 @@ where range_check3 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck3Trace::new_zeroes(); @@ -54,7 +54,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -67,7 +67,7 @@ where _stage: u32, _air_instance_id: Option, pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { self.std_lib.unregister_predecessor(pctx, None); diff --git a/pil2-components/test/std/range_check/rs/src/range_check4.rs b/pil2-components/test/std/range_check/rs/src/range_check4.rs index b4863f1f..afcdca71 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check4.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check4.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use num_bigint::BigInt; use num_traits::ToPrimitive; @@ -35,7 +35,7 @@ where range_check4 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck4Trace::new_zeroes(); @@ -102,7 +102,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -115,7 +115,7 @@ where _stage: u32, _air_instance_id: Option, pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { self.std_lib.unregister_predecessor(pctx, None); diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs index bc642187..7e9e2094 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -34,7 +34,7 @@ where range_check_dynamic1 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheckDynamic1Trace::new_zeroes(); @@ -80,7 +80,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -93,7 +93,7 @@ where _stage: u32, _air_instance_id: Option, pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { self.std_lib.unregister_predecessor(pctx, None); diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs index fef27da6..e4903c4d 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use num_bigint::BigInt; use num_traits::ToPrimitive; @@ -35,7 +35,7 @@ where range_check_dynamic2 } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheckDynamic2Trace::new_zeroes(); @@ -93,7 +93,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -106,7 +106,7 @@ where _stage: u32, _air_instance_id: Option, pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { self.std_lib.unregister_predecessor(pctx, None); diff --git a/pil2-components/test/std/range_check/rs/src/range_check_lib.rs b/pil2-components/test/std/range_check/rs/src/range_check_lib.rs index e25389d1..5e76e529 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_lib.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_lib.rs @@ -2,7 +2,7 @@ use std::{cell::OnceCell, error::Error, path::PathBuf, sync::Arc}; use pil_std_lib::Std; use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ExecutionCtx, ProofCtx, SetupCtx, VerboseMode}; +use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; use p3_field::PrimeField; use p3_goldilocks::Goldilocks; @@ -56,8 +56,8 @@ where } } - fn initialize(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { - let wcm = Arc::new(WitnessManager::new(pctx, ectx, sctx)); + fn initialize(&self, pctx: Arc>, sctx: Arc) { + let wcm = Arc::new(WitnessManager::new(pctx, sctx)); let std_lib = Std::new(wcm.clone()); let range_check1 = RangeCheck1::new(wcm.clone(), std_lib.clone()); @@ -88,31 +88,31 @@ impl WitnessLibrary for RangeCheckWitness where Standard: Distribution, { - fn start_proof(&mut self, pctx: Arc>, ectx: Arc, sctx: Arc) { - self.initialize(pctx.clone(), ectx.clone(), sctx.clone()); + fn start_proof(&mut self, pctx: Arc>, sctx: Arc) { + self.initialize(pctx.clone(), sctx.clone()); - self.wcm.get().unwrap().start_proof(pctx, ectx, sctx); + self.wcm.get().unwrap().start_proof(pctx, sctx); } fn end_proof(&mut self) { self.wcm.get().unwrap().end_proof(); } - fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + fn execute(&self, pctx: Arc>, sctx: Arc) { // Execute those components that need to be executed - self.range_check1.get().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.range_check2.get().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.range_check3.get().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.range_check4.get().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.multi_range_check1.get().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.multi_range_check2.get().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.range_check_dynamic1.get().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.range_check_dynamic2.get().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); - self.range_check_mix.get().unwrap().execute(pctx.clone(), ectx.clone(), sctx.clone()); + self.range_check1.get().unwrap().execute(pctx.clone(), sctx.clone()); + self.range_check2.get().unwrap().execute(pctx.clone(), sctx.clone()); + self.range_check3.get().unwrap().execute(pctx.clone(), sctx.clone()); + self.range_check4.get().unwrap().execute(pctx.clone(), sctx.clone()); + self.multi_range_check1.get().unwrap().execute(pctx.clone(), sctx.clone()); + self.multi_range_check2.get().unwrap().execute(pctx.clone(), sctx.clone()); + self.range_check_dynamic1.get().unwrap().execute(pctx.clone(), sctx.clone()); + self.range_check_dynamic2.get().unwrap().execute(pctx.clone(), sctx.clone()); + self.range_check_mix.get().unwrap().execute(pctx.clone(), sctx.clone()); } - fn calculate_witness(&mut self, stage: u32, pctx: Arc>, ectx: Arc, sctx: Arc) { - self.wcm.get().unwrap().calculate_witness(stage, pctx, ectx, sctx); + fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { + self.wcm.get().unwrap().calculate_witness(stage, pctx, sctx); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs index 91abe5cc..b71d9a21 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; use num_bigint::BigInt; use num_traits::ToPrimitive; @@ -35,7 +35,7 @@ where range_check_mix } - pub fn execute(&self, pctx: Arc>, ectx: Arc, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>, _sctx: Arc) { let mut rng = rand::thread_rng(); let mut trace = RangeCheckMixTrace::new_zeroes(); @@ -134,7 +134,7 @@ where } let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); - add_air_instance::(air_instance, ectx, pctx.clone()); + add_air_instance::(air_instance, pctx.clone()); } } @@ -147,7 +147,7 @@ where _stage: u32, _air_instance_id: Option, pctx: Arc>, - _ectx: Arc, + _ _sctx: Arc, ) { self.std_lib.unregister_predecessor(pctx, None); diff --git a/proofman/src/constraints.rs b/proofman/src/constraints.rs index f3305f58..ed5ad172 100644 --- a/proofman/src/constraints.rs +++ b/proofman/src/constraints.rs @@ -5,13 +5,13 @@ use std::sync::Arc; use crate::{verify_global_constraints_proof, WitnessLibrary}; -use proofman_common::{ExecutionCtx, ProofCtx, Prover, SetupCtx}; +use proofman_common::{ProofCtx, Prover, SetupCtx}; use colored::*; pub fn verify_constraints_proof( pctx: Arc>, - ectx: Arc, + sctx: Arc, provers: &mut [Box>], witness_lib: &mut Box>, @@ -20,7 +20,7 @@ pub fn verify_constraints_proof( log::info!("{}: --> Checking constraints", MY_NAME); - witness_lib.debug(pctx.clone(), ectx.clone(), sctx.clone()); + witness_lib.debug(pctx.clone(), sctx.clone()); let mut constraints = Vec::new(); for prover in provers.iter() { diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index 6f2f4c9b..ac2de754 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -20,7 +20,7 @@ use crate::{ generate_recursivef_proof, generate_fflonk_snark_proof, }; -use proofman_common::{ExecutionCtx, ProofCtx, ProofOptions, ProofType, Prover, SetupCtx, SetupsVadcop}; +use proofman_common::{ProofCtx, ProofOptions, ProofType, Prover, SetupCtx, SetupsVadcop}; use std::os::raw::c_void; @@ -39,7 +39,6 @@ impl ProofMan { witness_lib_path: PathBuf, rom_path: Option, public_inputs_path: Option, - cached_buffers_paths: Option>, proving_key_path: PathBuf, output_dir_path: PathBuf, options: ProofOptions, @@ -52,34 +51,27 @@ impl ProofMan { &witness_lib_path, &rom_path, &public_inputs_path, - &cached_buffers_paths, &proving_key_path, &output_dir_path, options.verify_constraints, )?; - let ectx = ExecutionCtx::builder() - .with_rom_path(rom_path.clone()) - .with_cached_buffers_path(cached_buffers_paths.clone()) - .with_verbose_mode(options.verbose_mode) - .with_std_mode(options.std_mode) - .build(); - let ectx = Arc::new(ectx); + // Load the witness computation dynamic library let library = unsafe { Library::new(&witness_lib_path)? }; let witness_lib: Symbol> = unsafe { library.get(b"init_library")? }; - let mut witness_lib = witness_lib(rom_path, public_inputs_path, ectx.verbose_mode)?; + let mut witness_lib = witness_lib(rom_path, public_inputs_path, options.verbose_mode)?; - let pctx = Arc::new(ProofCtx::create_ctx(proving_key_path.clone())); + let pctx = Arc::new(ProofCtx::create_ctx(proving_key_path.clone(), options)); - let setups = Arc::new(SetupsVadcop::new(&pctx.global_info, options.aggregation, options.final_snark)); + let setups = Arc::new(SetupsVadcop::new(&pctx.global_info, pctx.options.aggregation, pctx.options.final_snark)); let sctx: Arc = setups.sctx.clone(); - Self::initialize_witness(&mut witness_lib, pctx.clone(), ectx.clone(), sctx.clone()); - witness_lib.calculate_witness(1, pctx.clone(), ectx.clone(), sctx.clone()); + Self::initialize_witness(&mut witness_lib, pctx.clone(), sctx.clone()); + witness_lib.calculate_witness(1, pctx.clone(), sctx.clone()); - let mut dctx = ectx.dctx.write().unwrap(); + let mut dctx = pctx.dctx.write().unwrap(); dctx.close(pctx.global_info.air_groups.len()); let mpi_rank = dctx.rank; drop(dctx); @@ -87,16 +79,10 @@ impl ProofMan { Self::print_summary(pctx.clone()); } - Self::initialize_fixed_pols( - setups.clone(), - pctx.clone(), - ectx.clone(), - options.aggregation, - options.final_snark, - ); + Self::initialize_fixed_pols(setups.clone(), pctx.clone()); let mut provers: Vec>> = Vec::new(); - Self::initialize_provers(sctx.clone(), &mut provers, pctx.clone(), ectx.clone()); + Self::initialize_provers(sctx.clone(), &mut provers, pctx.clone()); if provers.is_empty() { return Err("No instances found".into()); @@ -115,56 +101,42 @@ impl ProofMan { if stage != 1 { timer_start_debug!(CALCULATING_WITNESS); info!("{}: Calculating witness stage {}", Self::MY_NAME, stage); - witness_lib.calculate_witness(stage, pctx.clone(), ectx.clone(), sctx.clone()); + witness_lib.calculate_witness(stage, pctx.clone(), sctx.clone()); timer_stop_and_log_debug!(CALCULATING_WITNESS); } Self::calculate_stage(stage, &mut provers, sctx.clone(), pctx.clone()); - if !options.verify_constraints { + if !pctx.options.verify_constraints { Self::commit_stage(stage, &mut provers, pctx.clone()); } - if !options.verify_constraints || stage < num_commit_stages { - Self::calculate_challenges( - stage, - &mut provers, - pctx.clone(), - ectx.clone(), - &mut transcript, - options.verify_constraints, - ); + if !pctx.options.verify_constraints || stage < num_commit_stages { + Self::calculate_challenges(stage, &mut provers, pctx.clone(), &mut transcript); } } witness_lib.end_proof(); - if options.verify_constraints { - return verify_constraints_proof(pctx.clone(), ectx.clone(), sctx.clone(), &mut provers, &mut witness_lib); + if pctx.options.verify_constraints { + return verify_constraints_proof(pctx.clone(), sctx.clone(), &mut provers, &mut witness_lib); } // Compute Quotient polynomial Self::get_challenges(num_commit_stages + 1, &mut provers, pctx.clone(), &transcript); Self::calculate_stage(num_commit_stages + 1, &mut provers, sctx.clone(), pctx.clone()); Self::commit_stage(num_commit_stages + 1, &mut provers, pctx.clone()); - Self::calculate_challenges( - num_commit_stages + 1, - &mut provers, - pctx.clone(), - ectx.clone(), - &mut transcript, - false, - ); + Self::calculate_challenges(num_commit_stages + 1, &mut provers, pctx.clone(), &mut transcript); // Compute openings - Self::opening_stages(&mut provers, pctx.clone(), sctx.clone(), ectx.clone(), &mut transcript); + Self::opening_stages(&mut provers, pctx.clone(), sctx.clone(), &mut transcript); //Generate proves_out let proves_out = Self::finalize_proof(&mut provers, pctx.clone(), output_dir_path.to_string_lossy().as_ref()); timer_stop_and_log_info!(GENERATING_PROOF); - if !options.aggregation { + if !pctx.options.aggregation { return Ok(()); } @@ -177,12 +149,11 @@ impl ProofMan { timer_stop_and_log_info!(GENERATING_COMPRESSOR_AND_RECURSIVE1_PROOFS); log::info!("{}: Compressor and recursive1 proofs generated successfully", Self::MY_NAME); - ectx.dctx.read().unwrap().barrier(); + pctx.dctx.read().unwrap().barrier(); timer_start_info!(GENERATING_RECURSIVE2_PROOFS); let sctx_recursive2 = setups.sctx_recursive2.clone(); let recursive2_proof = generate_vadcop_recursive2_proof( &pctx, - &ectx, sctx_recursive2.as_ref().unwrap().clone(), &recursive1_proofs, output_dir_path.clone(), @@ -191,7 +162,7 @@ impl ProofMan { timer_stop_and_log_info!(GENERATING_RECURSIVE2_PROOFS); log::info!("{}: Recursive2 proofs generated successfully", Self::MY_NAME); - ectx.dctx.read().unwrap().barrier(); + pctx.dctx.read().unwrap().barrier(); if mpi_rank == 0 { timer_start_info!(GENERATING_VADCOP_FINAL_PROOF); let final_proof = generate_vadcop_final_proof( @@ -205,7 +176,7 @@ impl ProofMan { timer_stop_and_log_info!(GENERATING_AGGREGATION_PROOFS); - if options.final_snark { + if pctx.options.final_snark { timer_start_info!(GENERATING_RECURSIVE_F_PROOF); let recursivef_proof = generate_recursivef_proof( &pctx, @@ -222,20 +193,15 @@ impl ProofMan { } timer_stop_and_log_info!(GENERATING_VADCOP_PROOF); log::info!("{}: Proofs generated successfully", Self::MY_NAME); - ectx.dctx.read().unwrap().barrier(); + pctx.dctx.read().unwrap().barrier(); Ok(()) } - fn initialize_witness( - witness_lib: &mut Box>, - pctx: Arc>, - ectx: Arc, - sctx: Arc, - ) { + fn initialize_witness(witness_lib: &mut Box>, pctx: Arc>, sctx: Arc) { timer_start_debug!(INITIALIZE_WITNESS); - witness_lib.start_proof(pctx.clone(), ectx.clone(), sctx.clone()); + witness_lib.start_proof(pctx.clone(), sctx.clone()); - witness_lib.execute(pctx.clone(), ectx, sctx); + witness_lib.execute(pctx.clone(), sctx); // After the execution print the planned instances trace!("{}: --> Air instances: ", Self::MY_NAME); @@ -269,12 +235,7 @@ impl ProofMan { timer_stop_and_log_debug!(INITIALIZE_WITNESS); } - fn initialize_provers( - sctx: Arc, - provers: &mut Vec>>, - pctx: Arc>, - _ectx: Arc, - ) { + fn initialize_provers(sctx: Arc, provers: &mut Vec>>, pctx: Arc>) { timer_start_debug!(INITIALIZE_PROVERS); info!("{}: Initializing provers", Self::MY_NAME); for air_instance in pctx.air_instance_repo.air_instances.read().unwrap().iter() { @@ -309,13 +270,7 @@ impl ProofMan { timer_stop_and_log_debug!(INITIALIZE_PROVERS); } - fn initialize_fixed_pols( - setups: Arc, - pctx: Arc>, - _ectx: Arc, - aggregation: bool, - final_snark: bool, - ) { + fn initialize_fixed_pols(setups: Arc, pctx: Arc>) { info!("{}: Initializing setup fixed pols", Self::MY_NAME); timer_start_debug!(INITIALIZE_SETUP); timer_start_debug!(INITIALIZE_CONST_POLS); @@ -334,7 +289,7 @@ impl ProofMan { timer_stop_and_log_debug!(INITIALIZE_CONST_POLS); - if aggregation { + if pctx.options.aggregation { info!("{}: Initializing setup fixed pols aggregation", Self::MY_NAME); let sctx_compressor = setups.sctx_compressor.as_ref().unwrap().clone(); @@ -389,7 +344,7 @@ impl ProofMan { setup_vadcop_final.load_const_pols_tree(&pctx.global_info, &ProofType::VadcopFinal, false); timer_stop_and_log_debug!(INITIALIZE_CONST_POLS_VADCOP_FINAL); - if final_snark { + if pctx.options.final_snark { let setup_recursivef = setups.setup_recursivef.as_ref().unwrap().clone(); timer_start_debug!(INITIALIZE_CONST_POLS_RECURSIVE_FINAL); info!("{}: ··· Initializing setup fixed pols recursive final", Self::MY_NAME); @@ -477,15 +432,14 @@ impl ProofMan { stage: u32, provers: &mut [Box>], pctx: Arc>, - ectx: Arc, + transcript: &mut FFITranscript, - verify_constraints: bool, ) { if stage == 1 { transcript.add_elements(pctx.get_publics_ptr(), pctx.global_info.n_publics); } - let dctx = ectx.dctx.read().unwrap(); + let dctx = pctx.dctx.read().unwrap(); // calculate my roots let mut roots: Vec = vec![0; 4 * provers.len()]; @@ -502,7 +456,7 @@ impl ProofMan { // add challenges to transcript in order for group_idxs in dctx.my_groups.iter() { - if verify_constraints { + if pctx.options.verify_constraints { let dummy_elements = [F::zero(), F::one(), F::two(), F::neg_one()]; transcript.add_elements(dummy_elements.as_ptr() as *mut u8, 4); } else { @@ -538,7 +492,7 @@ impl ProofMan { provers: &mut [Box>], pctx: Arc>, sctx: Arc, - ectx: Arc, + transcript: &mut FFITranscript, ) { let num_commit_stages = pctx.global_info.n_challenges.len() as u32; @@ -557,7 +511,7 @@ impl ProofMan { } timer_stop_and_log_debug!(CALCULATING_EVALS); - Self::calculate_challenges(num_commit_stages + 2, provers, pctx.clone(), ectx.clone(), transcript, false); + Self::calculate_challenges(num_commit_stages + 2, provers, pctx.clone(), transcript); // Calculate fri polynomial Self::get_challenges(pctx.global_info.n_challenges.len() as u32 + 3, provers, pctx.clone(), transcript); @@ -611,9 +565,7 @@ impl ProofMan { pctx.global_info.n_challenges.len() as u32 + 4 + opening_id, provers, pctx.clone(), - ectx.clone(), transcript, - false, ); } timer_stop_and_log_debug!(CALCULATING_FRI_STEP); @@ -685,7 +637,6 @@ impl ProofMan { witness_lib_path: &PathBuf, rom_path: &Option, public_inputs_path: &Option, - cached_buffers_paths: &Option>, proving_key_path: &PathBuf, output_dir_path: &PathBuf, verify_constraints: bool, @@ -709,15 +660,6 @@ impl ProofMan { } } - // Check each path in cached_buffers_paths exists - if let Some(cached_buffers) = cached_buffers_paths { - for (key, path) in cached_buffers { - if !path.exists() { - return Err(format!("Cached buffer not found for key '{}' at path: {:?}", key, path).into()); - } - } - } - // Check proving_key_path exists if !proving_key_path.exists() { return Err(format!("Proving key folder not found at path: {:?}", proving_key_path).into()); diff --git a/proofman/src/recursion.rs b/proofman/src/recursion.rs index c00a33b8..0b1875f5 100644 --- a/proofman/src/recursion.rs +++ b/proofman/src/recursion.rs @@ -7,7 +7,7 @@ use proofman_starks_lib_c::*; use std::path::{Path, PathBuf}; use std::io::Read; -use proofman_common::{ExecutionCtx, ProofCtx, ProofType, Setup, SetupCtx, SetupsVadcop}; +use proofman_common::{ProofCtx, ProofType, Setup, SetupCtx, SetupsVadcop}; use std::os::raw::{c_void, c_char}; @@ -154,7 +154,6 @@ pub fn generate_vadcop_recursive1_proof( pub fn generate_vadcop_recursive2_proof( pctx: &ProofCtx, - ectx: &ExecutionCtx, sctx: Arc, proofs: &[*mut c_void], output_dir_path: PathBuf, @@ -165,7 +164,7 @@ pub fn generate_vadcop_recursive2_proof( let global_info_path = pctx.global_info.get_proving_key_path().join("pilout.globalInfo.json"); let global_info_file: &str = global_info_path.to_str().unwrap(); - let mut dctx = ectx.dctx.write().unwrap(); + let mut dctx = pctx.dctx.write().unwrap(); let n_airgroups = pctx.global_info.air_groups.len(); let mut alives = Vec::with_capacity(n_airgroups); let mut airgroup_proofs: Vec>> = Vec::with_capacity(n_airgroups); diff --git a/proofman/src/witness_component.rs b/proofman/src/witness_component.rs index 97694446..9381ea66 100644 --- a/proofman/src/witness_component.rs +++ b/proofman/src/witness_component.rs @@ -1,16 +1,15 @@ use std::sync::Arc; -use proofman_common::{ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{ProofCtx, SetupCtx}; pub trait WitnessComponent: Send + Sync { - fn start_proof(&self, _pctx: Arc>, _ectx: Arc, _sctx: Arc) {} + fn start_proof(&self, _pctx: Arc>, _sctx: Arc) {} fn calculate_witness( &self, _stage: u32, _air_instance: Option, _pctx: Arc>, - _ectx: Arc, _sctx: Arc, ) { } diff --git a/proofman/src/witness_executor.rs b/proofman/src/witness_executor.rs index 7ac119dc..b84c911f 100644 --- a/proofman/src/witness_executor.rs +++ b/proofman/src/witness_executor.rs @@ -1,5 +1,5 @@ -use proofman_common::{ExecutionCtx, ProofCtx}; +use proofman_common::ProofCtx; pub trait WitnessExecutor { - fn execute(&self, pctx: &mut ProofCtx, ectx: &mut ExecutionCtx); + fn execute(&self, pctx: &mut ProofCtx); } diff --git a/proofman/src/witness_library.rs b/proofman/src/witness_library.rs index f05be588..f8923844 100644 --- a/proofman/src/witness_library.rs +++ b/proofman/src/witness_library.rs @@ -1,19 +1,19 @@ use std::{error::Error, path::PathBuf, sync::Arc}; -use proofman_common::{ExecutionCtx, ProofCtx, SetupCtx, VerboseMode}; +use proofman_common::{ProofCtx, SetupCtx, VerboseMode}; /// This is the type of the function that is used to load a witness library. pub type WitnessLibInitFn = fn(Option, Option, VerboseMode) -> Result>, Box>; pub trait WitnessLibrary { - fn start_proof(&mut self, pctx: Arc>, ectx: Arc, sctx: Arc); + fn start_proof(&mut self, pctx: Arc>, sctx: Arc); fn end_proof(&mut self); - fn execute(&self, pctx: Arc>, ectx: Arc, sctx: Arc); + fn execute(&self, pctx: Arc>, sctx: Arc); - fn calculate_witness(&mut self, stage: u32, pctx: Arc>, ectx: Arc, sctx: Arc); + fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc); - fn debug(&mut self, _pctx: Arc>, _ectx: Arc, _sctx: Arc) {} + fn debug(&mut self, _pctx: Arc>, _sctx: Arc) {} } diff --git a/proofman/src/witness_manager.rs b/proofman/src/witness_manager.rs index 61c353d5..a85348bb 100644 --- a/proofman/src/witness_manager.rs +++ b/proofman/src/witness_manager.rs @@ -3,7 +3,7 @@ use std::{ sync::{Arc, RwLock}, }; -use proofman_common::{ExecutionCtx, ProofCtx, SetupCtx}; +use proofman_common::{ProofCtx, SetupCtx}; use proofman_util::{timer_start_debug, timer_stop_and_log_debug}; use crate::WitnessComponent; @@ -15,15 +15,15 @@ pub struct WitnessManager { airs: RwLock>, // First usize is the air_id, second usize is the index of the component in the components vector pctx: Arc>, - ectx: Arc, + sctx: Arc, } impl WitnessManager { const MY_NAME: &'static str = "WCMnager"; - pub fn new(pctx: Arc>, ectx: Arc, sctx: Arc) -> Self { - WitnessManager { components: RwLock::new(Vec::new()), airs: RwLock::new(HashMap::new()), pctx, ectx, sctx } + pub fn new(pctx: Arc>, sctx: Arc) -> Self { + WitnessManager { components: RwLock::new(Vec::new()), airs: RwLock::new(HashMap::new()), pctx, sctx } } pub fn register_component(&self, component: Arc>, airgroup_id: AirGroupId, air_id: AirId) { @@ -52,9 +52,9 @@ impl WitnessManager { self.airs.write().unwrap().insert((airgroup_id, air_id), component_idx); } - pub fn start_proof(&self, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn start_proof(&self, pctx: Arc>, sctx: Arc) { for component in self.components.read().unwrap().iter() { - component.start_proof(pctx.clone(), ectx.clone(), sctx.clone()); + component.start_proof(pctx.clone(), sctx.clone()); } } @@ -64,7 +64,7 @@ impl WitnessManager { } } - pub fn calculate_witness(&self, stage: u32, pctx: Arc>, ectx: Arc, sctx: Arc) { + pub fn calculate_witness(&self, stage: u32, pctx: Arc>, sctx: Arc) { log::info!( "{}: Calculating witness for stage {} / {}", Self::MY_NAME, @@ -94,7 +94,7 @@ impl WitnessManager { for component_group in components.values() { for (component_idx, id) in component_group.iter() { let component = &self_components[**component_idx]; - component.calculate_witness(stage, Some(*id), pctx.clone(), ectx.clone(), sctx.clone()); + component.calculate_witness(stage, Some(*id), pctx.clone(), sctx.clone()); used_components.push(**component_idx); } } @@ -102,7 +102,7 @@ impl WitnessManager { // Call one time all unused components for component_idx in 0..self.components.read().unwrap().len() { if !used_components.contains(&component_idx) { - self_components[component_idx].calculate_witness(stage, None, pctx.clone(), ectx.clone(), sctx.clone()); + self_components[component_idx].calculate_witness(stage, None, pctx.clone(), sctx.clone()); } } @@ -113,10 +113,6 @@ impl WitnessManager { self.pctx.clone() } - pub fn get_ectx(&self) -> Arc { - self.ectx.clone() - } - pub fn get_sctx(&self) -> Arc { self.sctx.clone() } From 8480f613802666fdec346b2b2868e5da225833d0 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Fri, 13 Dec 2024 09:49:26 +0000 Subject: [PATCH 39/64] More cleaning --- examples/fibonacci-square/src/fibonacci.rs | 2 +- .../fibonacci-square/src/fibonacci_lib.rs | 6 +++--- examples/fibonacci-square/src/module.rs | 2 +- .../test/simple/rs/src/simple_left.rs | 2 +- .../test/simple/rs/src/simple_lib.rs | 8 ++++---- .../test/simple/rs/src/simple_right.rs | 2 +- .../test/std/connection/rs/src/connection1.rs | 2 +- .../test/std/connection/rs/src/connection2.rs | 2 +- .../std/connection/rs/src/connection_lib.rs | 8 ++++---- .../std/connection/rs/src/connection_new.rs | 2 +- .../test/std/lookup/rs/src/lookup0.rs | 2 +- .../test/std/lookup/rs/src/lookup1.rs | 2 +- .../test/std/lookup/rs/src/lookup2_12.rs | 2 +- .../test/std/lookup/rs/src/lookup2_13.rs | 2 +- .../test/std/lookup/rs/src/lookup2_15.rs | 2 +- .../test/std/lookup/rs/src/lookup3.rs | 2 +- .../test/std/lookup/rs/src/lookup_lib.rs | 14 ++++++------- .../std/permutation/rs/src/permutation1_6.rs | 2 +- .../std/permutation/rs/src/permutation1_7.rs | 2 +- .../std/permutation/rs/src/permutation1_8.rs | 2 +- .../std/permutation/rs/src/permutation2.rs | 2 +- .../std/permutation/rs/src/permutation_lib.rs | 10 +++++----- .../range_check/rs/src/multi_range_check1.rs | 2 +- .../range_check/rs/src/multi_range_check2.rs | 2 +- .../std/range_check/rs/src/range_check1.rs | 2 +- .../std/range_check/rs/src/range_check2.rs | 2 +- .../std/range_check/rs/src/range_check3.rs | 2 +- .../std/range_check/rs/src/range_check4.rs | 2 +- .../rs/src/range_check_dynamic1.rs | 2 +- .../rs/src/range_check_dynamic2.rs | 2 +- .../std/range_check/rs/src/range_check_lib.rs | 20 +++++++++---------- .../std/range_check/rs/src/range_check_mix.rs | 2 +- proofman/src/constraints.rs | 2 +- proofman/src/proofman.rs | 2 +- proofman/src/witness_library.rs | 4 ++-- 35 files changed, 63 insertions(+), 63 deletions(-) diff --git a/examples/fibonacci-square/src/fibonacci.rs b/examples/fibonacci-square/src/fibonacci.rs index c77bd000..3096b0a7 100644 --- a/examples/fibonacci-square/src/fibonacci.rs +++ b/examples/fibonacci-square/src/fibonacci.rs @@ -29,7 +29,7 @@ impl FibonacciSquare { fibonacci } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { if let Err(e) = Self::calculate_trace(self, pctx) { panic!("Failed to calculate fibonacci: {:?}", e); } diff --git a/examples/fibonacci-square/src/fibonacci_lib.rs b/examples/fibonacci-square/src/fibonacci_lib.rs index 9206bbc8..d74a5add 100644 --- a/examples/fibonacci-square/src/fibonacci_lib.rs +++ b/examples/fibonacci-square/src/fibonacci_lib.rs @@ -53,9 +53,9 @@ impl WitnessLibrary for FibonacciWitness { self.wcm.as_ref().unwrap().end_proof(); } - fn execute(&self, pctx: Arc>, sctx: Arc) { - self.fibonacci.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); - self.module.as_ref().unwrap().execute(pctx, sctx); + fn execute(&self, pctx: Arc>) { + self.fibonacci.as_ref().unwrap().execute(pctx.clone()); + self.module.as_ref().unwrap().execute(pctx); } fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { diff --git a/examples/fibonacci-square/src/module.rs b/examples/fibonacci-square/src/module.rs index 8d76e956..9da0b417 100644 --- a/examples/fibonacci-square/src/module.rs +++ b/examples/fibonacci-square/src/module.rs @@ -37,7 +37,7 @@ impl Module< x_mod } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { self.calculate_trace(pctx); } diff --git a/pil2-components/test/simple/rs/src/simple_left.rs b/pil2-components/test/simple/rs/src/simple_left.rs index 01f6eba3..64f5794a 100644 --- a/pil2-components/test/simple/rs/src/simple_left.rs +++ b/pil2-components/test/simple/rs/src/simple_left.rs @@ -26,7 +26,7 @@ where simple_left } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = SimpleLeftTrace::new(); diff --git a/pil2-components/test/simple/rs/src/simple_lib.rs b/pil2-components/test/simple/rs/src/simple_lib.rs index 1e0f085f..b13a8726 100644 --- a/pil2-components/test/simple/rs/src/simple_lib.rs +++ b/pil2-components/test/simple/rs/src/simple_lib.rs @@ -62,13 +62,13 @@ where self.wcm.as_ref().unwrap().end_proof(); } - fn execute(&self, pctx: Arc>, sctx: Arc) { + fn execute(&self, pctx: Arc>) { // Execute those components that need to be executed - self.simple_left.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); - self.simple_right.as_ref().unwrap().execute(pctx, sctx); + self.simple_left.as_ref().unwrap().execute(pctx.clone()); + self.simple_right.as_ref().unwrap().execute(pctx); } - fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { + fn calculate_witness(&mut self, stage: u32, pctx: Arc>) { self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, sctx); } } diff --git a/pil2-components/test/simple/rs/src/simple_right.rs b/pil2-components/test/simple/rs/src/simple_right.rs index c581046c..85a16aa1 100644 --- a/pil2-components/test/simple/rs/src/simple_right.rs +++ b/pil2-components/test/simple/rs/src/simple_right.rs @@ -29,7 +29,7 @@ where simple_right } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut trace = SimpleRightTrace::new(); let num_rows = trace.num_rows(); diff --git a/pil2-components/test/std/connection/rs/src/connection1.rs b/pil2-components/test/std/connection/rs/src/connection1.rs index 992d0a6f..032e20e9 100644 --- a/pil2-components/test/std/connection/rs/src/connection1.rs +++ b/pil2-components/test/std/connection/rs/src/connection1.rs @@ -29,7 +29,7 @@ where connection1 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = Connection1Trace::new_zeroes(); diff --git a/pil2-components/test/std/connection/rs/src/connection2.rs b/pil2-components/test/std/connection/rs/src/connection2.rs index e42c9385..4b5bbb50 100644 --- a/pil2-components/test/std/connection/rs/src/connection2.rs +++ b/pil2-components/test/std/connection/rs/src/connection2.rs @@ -29,7 +29,7 @@ where connection2 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = Connection2Trace::new_zeroes(); diff --git a/pil2-components/test/std/connection/rs/src/connection_lib.rs b/pil2-components/test/std/connection/rs/src/connection_lib.rs index 7099ad3e..2ea26141 100644 --- a/pil2-components/test/std/connection/rs/src/connection_lib.rs +++ b/pil2-components/test/std/connection/rs/src/connection_lib.rs @@ -65,11 +65,11 @@ where self.wcm.as_ref().unwrap().end_proof(); } - fn execute(&self, pctx: Arc>, sctx: Arc) { + fn execute(&self, pctx: Arc>) { // Execute those components that need to be executed - self.connection1.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); - self.connection2.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); - self.connection_new.as_ref().unwrap().execute(pctx, sctx); + self.connection1.as_ref().unwrap().execute(pctx.clone()); + self.connection2.as_ref().unwrap().execute(pctx.clone()); + self.connection_new.as_ref().unwrap().execute(pctx); } fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { diff --git a/pil2-components/test/std/connection/rs/src/connection_new.rs b/pil2-components/test/std/connection/rs/src/connection_new.rs index 3742b224..ac0a2234 100644 --- a/pil2-components/test/std/connection/rs/src/connection_new.rs +++ b/pil2-components/test/std/connection/rs/src/connection_new.rs @@ -29,7 +29,7 @@ where connection_new } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = ConnectionNewTrace::new_zeroes(); let num_rows = trace.num_rows(); diff --git a/pil2-components/test/std/lookup/rs/src/lookup0.rs b/pil2-components/test/std/lookup/rs/src/lookup0.rs index eaa72447..aa6dd9b8 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup0.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup0.rs @@ -29,7 +29,7 @@ where lookup0 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = Lookup0Trace::new(); diff --git a/pil2-components/test/std/lookup/rs/src/lookup1.rs b/pil2-components/test/std/lookup/rs/src/lookup1.rs index 452d70dc..f8350d43 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup1.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup1.rs @@ -29,7 +29,7 @@ where lookup1 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = Lookup1Trace::new(); diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs index df73ac2d..20b9478c 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs @@ -29,7 +29,7 @@ where lookup2_12 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = Lookup2_12Trace::new(); diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs index f11d89f5..cc493e2b 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs @@ -29,7 +29,7 @@ where lookup2_13 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = Lookup2_13Trace::new(); diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs index 7accb79c..5fa33b37 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs @@ -29,7 +29,7 @@ where lookup2_15 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = Lookup2_15Trace::new(); diff --git a/pil2-components/test/std/lookup/rs/src/lookup3.rs b/pil2-components/test/std/lookup/rs/src/lookup3.rs index 23d0746f..54358dce 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup3.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup3.rs @@ -25,7 +25,7 @@ impl Lookup3 { lookup3 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { // For simplicity, add a single instance of each air let mut trace = Lookup3Trace::new(); let num_rows = trace.num_rows(); diff --git a/pil2-components/test/std/lookup/rs/src/lookup_lib.rs b/pil2-components/test/std/lookup/rs/src/lookup_lib.rs index ed8370d5..069cb8a0 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup_lib.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup_lib.rs @@ -83,14 +83,14 @@ where self.wcm.as_ref().unwrap().end_proof(); } - fn execute(&self, pctx: Arc>, sctx: Arc) { + fn execute(&self, pctx: Arc>) { // Execute those components that need to be executed - self.lookup0.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); - self.lookup1.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); - self.lookup2_12.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); - self.lookup2_13.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); - self.lookup2_15.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); - self.lookup3.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); + self.lookup0.as_ref().unwrap().execute(pctx.clone()); + self.lookup1.as_ref().unwrap().execute(pctx.clone()); + self.lookup2_12.as_ref().unwrap().execute(pctx.clone()); + self.lookup2_13.as_ref().unwrap().execute(pctx.clone()); + self.lookup2_15.as_ref().unwrap().execute(pctx.clone()); + self.lookup3.as_ref().unwrap().execute(pctx.clone()); } fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs index 663c93e7..f684153f 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs @@ -29,7 +29,7 @@ where permutation1_6 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = Permutation1_6Trace::new(); diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs index 1c057bf5..6e603808 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs @@ -29,7 +29,7 @@ where permutation1_7 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = Permutation1_7Trace::new(); let num_rows = trace.num_rows(); diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs index 7aebf774..f3082e33 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs @@ -29,7 +29,7 @@ where permutation1_8 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = Permutation1_8Trace::new(); let num_rows = trace.num_rows(); diff --git a/pil2-components/test/std/permutation/rs/src/permutation2.rs b/pil2-components/test/std/permutation/rs/src/permutation2.rs index 5a27b7dc..4d7ce188 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation2.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation2.rs @@ -25,7 +25,7 @@ impl Permutation2 { permutation2 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut trace = Permutation2_6Trace::new(); let num_rows = trace.num_rows(); diff --git a/pil2-components/test/std/permutation/rs/src/permutation_lib.rs b/pil2-components/test/std/permutation/rs/src/permutation_lib.rs index 3b0b8c42..bfbd043f 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation_lib.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation_lib.rs @@ -75,12 +75,12 @@ where self.wcm.as_ref().unwrap().end_proof(); } - fn execute(&self, pctx: Arc>, sctx: Arc) { + fn execute(&self, pctx: Arc>) { // Execute those components that need to be executed - self.permutation1_6.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); - self.permutation1_7.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); - self.permutation1_8.as_ref().unwrap().execute(pctx.clone(), sctx.clone()); - self.permutation2.as_ref().unwrap().execute(pctx, sctx); + self.permutation1_6.as_ref().unwrap().execute(pctx.clone()); + self.permutation1_7.as_ref().unwrap().execute(pctx.clone()); + self.permutation1_8.as_ref().unwrap().execute(pctx.clone()); + self.permutation2.as_ref().unwrap().execute(pctx); } fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs index f6e542c7..119622c8 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs @@ -34,7 +34,7 @@ where multi_range_check1 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = MultiRangeCheck1Trace::new_zeroes(); diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs index b3b63359..d9a78820 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs @@ -34,7 +34,7 @@ where multi_range_check2 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = MultiRangeCheck2Trace::new_zeroes(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check1.rs b/pil2-components/test/std/range_check/rs/src/range_check1.rs index 93ad1d81..fcdb0d6c 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check1.rs @@ -34,7 +34,7 @@ where range_check1 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck1Trace::new_zeroes(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check2.rs b/pil2-components/test/std/range_check/rs/src/range_check2.rs index 295c15e0..289b4d81 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check2.rs @@ -34,7 +34,7 @@ where range_check2 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck2Trace::new_zeroes(); let num_rows = trace.num_rows(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check3.rs b/pil2-components/test/std/range_check/rs/src/range_check3.rs index ef512890..c2d7e1ea 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check3.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check3.rs @@ -34,7 +34,7 @@ where range_check3 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck3Trace::new_zeroes(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check4.rs b/pil2-components/test/std/range_check/rs/src/range_check4.rs index afcdca71..439a497c 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check4.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check4.rs @@ -35,7 +35,7 @@ where range_check4 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck4Trace::new_zeroes(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs index 7e9e2094..fae4f655 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs @@ -34,7 +34,7 @@ where range_check_dynamic1 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = RangeCheckDynamic1Trace::new_zeroes(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs index e4903c4d..4693d12a 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs @@ -35,7 +35,7 @@ where range_check_dynamic2 } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = RangeCheckDynamic2Trace::new_zeroes(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check_lib.rs b/pil2-components/test/std/range_check/rs/src/range_check_lib.rs index 5e76e529..91823c59 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_lib.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_lib.rs @@ -98,17 +98,17 @@ where self.wcm.get().unwrap().end_proof(); } - fn execute(&self, pctx: Arc>, sctx: Arc) { + fn execute(&self, pctx: Arc>) { // Execute those components that need to be executed - self.range_check1.get().unwrap().execute(pctx.clone(), sctx.clone()); - self.range_check2.get().unwrap().execute(pctx.clone(), sctx.clone()); - self.range_check3.get().unwrap().execute(pctx.clone(), sctx.clone()); - self.range_check4.get().unwrap().execute(pctx.clone(), sctx.clone()); - self.multi_range_check1.get().unwrap().execute(pctx.clone(), sctx.clone()); - self.multi_range_check2.get().unwrap().execute(pctx.clone(), sctx.clone()); - self.range_check_dynamic1.get().unwrap().execute(pctx.clone(), sctx.clone()); - self.range_check_dynamic2.get().unwrap().execute(pctx.clone(), sctx.clone()); - self.range_check_mix.get().unwrap().execute(pctx.clone(), sctx.clone()); + self.range_check1.get().unwrap().execute(pctx.clone()); + self.range_check2.get().unwrap().execute(pctx.clone()); + self.range_check3.get().unwrap().execute(pctx.clone()); + self.range_check4.get().unwrap().execute(pctx.clone()); + self.multi_range_check1.get().unwrap().execute(pctx.clone()); + self.multi_range_check2.get().unwrap().execute(pctx.clone()); + self.range_check_dynamic1.get().unwrap().execute(pctx.clone()); + self.range_check_dynamic2.get().unwrap().execute(pctx.clone()); + self.range_check_mix.get().unwrap().execute(pctx.clone()); } fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { diff --git a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs index b71d9a21..92d0f4ff 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs @@ -35,7 +35,7 @@ where range_check_mix } - pub fn execute(&self, pctx: Arc>, _sctx: Arc) { + pub fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = RangeCheckMixTrace::new_zeroes(); diff --git a/proofman/src/constraints.rs b/proofman/src/constraints.rs index ed5ad172..89036d39 100644 --- a/proofman/src/constraints.rs +++ b/proofman/src/constraints.rs @@ -20,7 +20,7 @@ pub fn verify_constraints_proof( log::info!("{}: --> Checking constraints", MY_NAME); - witness_lib.debug(pctx.clone(), sctx.clone()); + witness_lib.debug(pctx.clone()); let mut constraints = Vec::new(); for prover in provers.iter() { diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index ac2de754..6bb5ec60 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -201,7 +201,7 @@ impl ProofMan { timer_start_debug!(INITIALIZE_WITNESS); witness_lib.start_proof(pctx.clone(), sctx.clone()); - witness_lib.execute(pctx.clone(), sctx); + witness_lib.execute(pctx.clone()); // After the execution print the planned instances trace!("{}: --> Air instances: ", Self::MY_NAME); diff --git a/proofman/src/witness_library.rs b/proofman/src/witness_library.rs index f8923844..eb0eb631 100644 --- a/proofman/src/witness_library.rs +++ b/proofman/src/witness_library.rs @@ -11,9 +11,9 @@ pub trait WitnessLibrary { fn end_proof(&mut self); - fn execute(&self, pctx: Arc>, sctx: Arc); + fn execute(&self, pctx: Arc>); fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc); - fn debug(&mut self, _pctx: Arc>, _sctx: Arc) {} + fn debug(&mut self, _pctx: Arc>) {} } From b4f007aca4b77912649832ebd6ba73fdf048e9a5 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Fri, 13 Dec 2024 10:11:21 +0000 Subject: [PATCH 40/64] Still more cleaning --- examples/fibonacci-square/src/fibonacci.rs | 13 ++---------- examples/fibonacci-square/src/module.rs | 13 ++---------- .../rs/src/range_check/specified_ranges.rs | 9 -------- .../std/rs/src/range_check/std_range_check.rs | 10 --------- .../lib/std/rs/src/range_check/u16air.rs | 9 -------- .../lib/std/rs/src/range_check/u8air.rs | 9 -------- .../test/simple/rs/src/simple_left.rs | 18 +++------------- .../test/simple/rs/src/simple_lib.rs | 4 ++-- .../test/simple/rs/src/simple_right.rs | 18 +++------------- .../test/std/connection/rs/src/connection1.rs | 19 +++-------------- .../test/std/connection/rs/src/connection2.rs | 19 +++-------------- .../std/connection/rs/src/connection_lib.rs | 2 +- .../std/connection/rs/src/connection_new.rs | 19 +++-------------- .../test/std/lookup/rs/src/lookup0.rs | 19 +++-------------- .../test/std/lookup/rs/src/lookup1.rs | 19 +++-------------- .../test/std/lookup/rs/src/lookup2_12.rs | 19 +++-------------- .../test/std/lookup/rs/src/lookup2_13.rs | 19 +++-------------- .../test/std/lookup/rs/src/lookup2_15.rs | 19 +++-------------- .../test/std/lookup/rs/src/lookup3.rs | 16 +++----------- .../test/std/lookup/rs/src/lookup_lib.rs | 8 +++---- .../std/permutation/rs/src/permutation1_6.rs | 21 ++++--------------- .../std/permutation/rs/src/permutation1_7.rs | 19 +++-------------- .../std/permutation/rs/src/permutation1_8.rs | 19 +++-------------- .../std/permutation/rs/src/permutation2.rs | 16 +++----------- .../std/permutation/rs/src/permutation_lib.rs | 8 +++---- .../range_check/rs/src/multi_range_check1.rs | 21 ++++--------------- .../range_check/rs/src/multi_range_check2.rs | 21 ++++--------------- .../std/range_check/rs/src/range_check1.rs | 21 ++++--------------- .../std/range_check/rs/src/range_check2.rs | 21 ++++--------------- .../std/range_check/rs/src/range_check3.rs | 21 ++++--------------- .../std/range_check/rs/src/range_check4.rs | 21 ++++--------------- .../rs/src/range_check_dynamic1.rs | 21 ++++--------------- .../rs/src/range_check_dynamic2.rs | 21 ++++--------------- .../std/range_check/rs/src/range_check_lib.rs | 8 +++---- .../std/range_check/rs/src/range_check_mix.rs | 21 ++++--------------- 35 files changed, 101 insertions(+), 460 deletions(-) diff --git a/examples/fibonacci-square/src/fibonacci.rs b/examples/fibonacci-square/src/fibonacci.rs index 3096b0a7..56ed114c 100644 --- a/examples/fibonacci-square/src/fibonacci.rs +++ b/examples/fibonacci-square/src/fibonacci.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use proofman_common::{add_air_instance, AirInstance, FromTrace, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, AirInstance, FromTrace, ProofCtx}; use proofman::{WitnessManager, WitnessComponent}; use p3_field::PrimeField64; @@ -85,13 +85,4 @@ impl FibonacciSquare { } } -impl WitnessComponent for FibonacciSquare { - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - _pctx: Arc>, - _sctx: Arc, - ) { - } -} +impl WitnessComponent for FibonacciSquare {} diff --git a/examples/fibonacci-square/src/module.rs b/examples/fibonacci-square/src/module.rs index 9da0b417..733d5358 100644 --- a/examples/fibonacci-square/src/module.rs +++ b/examples/fibonacci-square/src/module.rs @@ -1,6 +1,6 @@ use std::sync::{Arc, Mutex}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use proofman::{WitnessManager, WitnessComponent}; use pil_std_lib::Std; use p3_field::{AbstractField, PrimeField64}; @@ -78,13 +78,4 @@ impl Module< } } -impl WitnessComponent for Module { - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - _pctx: Arc>, - _sctx: Arc, - ) { - } -} +impl WitnessComponent for Module {} diff --git a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs index 1a10b51e..926ccf28 100644 --- a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs +++ b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs @@ -336,13 +336,4 @@ impl WitnessComponent for SpecifiedRanges { //pctx.air_instance_repo.add_air_instance(air_instance); // note: there is room for simplification here } - - fn calculate_witness( - &self, - _stage: u32, - _air_instance: Option, - _pctx: Arc>, - _sctx: Arc, - ) { - } } diff --git a/pil2-components/lib/std/rs/src/range_check/std_range_check.rs b/pil2-components/lib/std/rs/src/range_check/std_range_check.rs index 016759ae..47a92ab6 100644 --- a/pil2-components/lib/std/rs/src/range_check/std_range_check.rs +++ b/pil2-components/lib/std/rs/src/range_check/std_range_check.rs @@ -287,14 +287,4 @@ impl WitnessComponent for StdRangeCheck { fn start_proof(&self, _pctx: Arc>, sctx: Arc) { self.decide(sctx); } - - fn calculate_witness( - &self, - _stage: u32, - _air_instance: Option, - _pctx: Arc>, - _sctx: Arc, - ) { - // Nothing to do - } } diff --git a/pil2-components/lib/std/rs/src/range_check/u16air.rs b/pil2-components/lib/std/rs/src/range_check/u16air.rs index e6df4913..07bcbfa1 100644 --- a/pil2-components/lib/std/rs/src/range_check/u16air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u16air.rs @@ -190,13 +190,4 @@ impl WitnessComponent for U16Air { //pctx.air_instance_repo.add_air_instance(air_instance); //note: there is room for simplification here } - - fn calculate_witness( - &self, - _stage: u32, - _air_instance: Option, - _pctx: Arc>, - _sctx: Arc, - ) { - } } diff --git a/pil2-components/lib/std/rs/src/range_check/u8air.rs b/pil2-components/lib/std/rs/src/range_check/u8air.rs index 938b75e8..f32c37e3 100644 --- a/pil2-components/lib/std/rs/src/range_check/u8air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u8air.rs @@ -187,13 +187,4 @@ impl WitnessComponent for U8Air { //pctx.air_instance_repo.add_air_instance(air_instance); //note: there is room for simplification heres } - - fn calculate_witness( - &self, - _stage: u32, - _air_instance: Option, - _pctx: Arc>, - _sctx: Arc, - ) { - } } diff --git a/pil2-components/test/simple/rs/src/simple_left.rs b/pil2-components/test/simple/rs/src/simple_left.rs index 64f5794a..6b594065 100644 --- a/pil2-components/test/simple/rs/src/simple_left.rs +++ b/pil2-components/test/simple/rs/src/simple_left.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, seq::SliceRandom}; @@ -56,21 +56,9 @@ where trace[i].d = trace[indices[i]].b; } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); } } -impl WitnessComponent for SimpleLeft -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - _pctx: Arc>, - _sctx: Arc, - ) { - } -} +impl WitnessComponent for SimpleLeft where Standard: Distribution {} diff --git a/pil2-components/test/simple/rs/src/simple_lib.rs b/pil2-components/test/simple/rs/src/simple_lib.rs index b13a8726..bc35edfc 100644 --- a/pil2-components/test/simple/rs/src/simple_lib.rs +++ b/pil2-components/test/simple/rs/src/simple_lib.rs @@ -2,7 +2,7 @@ use std::{error::Error, path::PathBuf, sync::Arc}; use pil_std_lib::Std; use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; +use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; use p3_field::PrimeField; use p3_goldilocks::Goldilocks; @@ -68,7 +68,7 @@ where self.simple_right.as_ref().unwrap().execute(pctx); } - fn calculate_witness(&mut self, stage: u32, pctx: Arc>) { + fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, sctx); } } diff --git a/pil2-components/test/simple/rs/src/simple_right.rs b/pil2-components/test/simple/rs/src/simple_right.rs index 85a16aa1..1a53b807 100644 --- a/pil2-components/test/simple/rs/src/simple_right.rs +++ b/pil2-components/test/simple/rs/src/simple_right.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution}; @@ -46,21 +46,9 @@ where trace[i].mul = F::from_canonical_usize(1); } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); } } -impl WitnessComponent for SimpleRight -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - _pctx: Arc>, - _sctx: Arc, - ) { - } -} +impl WitnessComponent for SimpleRight where Standard: Distribution {} diff --git a/pil2-components/test/std/connection/rs/src/connection1.rs b/pil2-components/test/std/connection/rs/src/connection1.rs index 032e20e9..48131dd4 100644 --- a/pil2-components/test/std/connection/rs/src/connection1.rs +++ b/pil2-components/test/std/connection/rs/src/connection1.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -43,22 +43,9 @@ where trace[i].c = rng.gen(); } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); } } -impl WitnessComponent for Connection1 -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - _pctx: Arc>, - _ - _sctx: Arc, - ) { - } -} +impl WitnessComponent for Connection1 where Standard: Distribution {} diff --git a/pil2-components/test/std/connection/rs/src/connection2.rs b/pil2-components/test/std/connection/rs/src/connection2.rs index 4b5bbb50..eed78fc1 100644 --- a/pil2-components/test/std/connection/rs/src/connection2.rs +++ b/pil2-components/test/std/connection/rs/src/connection2.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -45,22 +45,9 @@ where trace[0].a = trace[1].a; - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); } } -impl WitnessComponent for Connection2 -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - _pctx: Arc>, - _ - _sctx: Arc, - ) { - } -} +impl WitnessComponent for Connection2 where Standard: Distribution {} diff --git a/pil2-components/test/std/connection/rs/src/connection_lib.rs b/pil2-components/test/std/connection/rs/src/connection_lib.rs index 2ea26141..631cda91 100644 --- a/pil2-components/test/std/connection/rs/src/connection_lib.rs +++ b/pil2-components/test/std/connection/rs/src/connection_lib.rs @@ -2,7 +2,7 @@ use std::{error::Error, path::PathBuf, sync::Arc}; use pil_std_lib::Std; use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; +use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; use p3_field::PrimeField; use p3_goldilocks::Goldilocks; diff --git a/pil2-components/test/std/connection/rs/src/connection_new.rs b/pil2-components/test/std/connection/rs/src/connection_new.rs index ac0a2234..37a21436 100644 --- a/pil2-components/test/std/connection/rs/src/connection_new.rs +++ b/pil2-components/test/std/connection/rs/src/connection_new.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -136,22 +136,9 @@ where } } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); } } -impl WitnessComponent for ConnectionNew -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - _pctx: Arc>, - _ - _sctx: Arc, - ) { - } -} +impl WitnessComponent for ConnectionNew where Standard: Distribution {} diff --git a/pil2-components/test/std/lookup/rs/src/lookup0.rs b/pil2-components/test/std/lookup/rs/src/lookup0.rs index aa6dd9b8..491512db 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup0.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup0.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -56,22 +56,9 @@ where } } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); } } -impl WitnessComponent for Lookup0 -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - _pctx: Arc>, - _ - _sctx: Arc, - ) { - } -} +impl WitnessComponent for Lookup0 where Standard: Distribution {} diff --git a/pil2-components/test/std/lookup/rs/src/lookup1.rs b/pil2-components/test/std/lookup/rs/src/lookup1.rs index f8350d43..e0985b0d 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup1.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup1.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -54,22 +54,9 @@ where trace[i].mul = F::from_canonical_usize(n_sel); } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); } } -impl WitnessComponent for Lookup1 -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - _pctx: Arc>, - _ - _sctx: Arc, - ) { - } -} +impl WitnessComponent for Lookup1 where Standard: Distribution {} diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs index 20b9478c..fa4ddd94 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -66,22 +66,9 @@ where trace[i].sel2 = F::from_bool(true); } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); } } -impl WitnessComponent for Lookup2_12 -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - _pctx: Arc>, - _ - _sctx: Arc, - ) { - } -} +impl WitnessComponent for Lookup2_12 where Standard: Distribution {} diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs index cc493e2b..0326165c 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -66,22 +66,9 @@ where trace[i].sel2 = F::from_bool(true); } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); } } -impl WitnessComponent for Lookup2_13 -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - _pctx: Arc>, - _ - _sctx: Arc, - ) { - } -} +impl WitnessComponent for Lookup2_13 where Standard: Distribution {} diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs index 5fa33b37..9a34af74 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -66,22 +66,9 @@ where trace[i].sel2 = F::from_bool(true); } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); } } -impl WitnessComponent for Lookup2_15 -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - _pctx: Arc>, - _ - _sctx: Arc, - ) { - } -} +impl WitnessComponent for Lookup2_15 where Standard: Distribution {} diff --git a/pil2-components/test/std/lookup/rs/src/lookup3.rs b/pil2-components/test/std/lookup/rs/src/lookup3.rs index 54358dce..89b60b5c 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup3.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup3.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; @@ -54,19 +54,9 @@ impl Lookup3 { } } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); } } -impl WitnessComponent for Lookup3 { - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - _pctx: Arc>, - _ - _sctx: Arc, - ) { - } -} +impl WitnessComponent for Lookup3 {} diff --git a/pil2-components/test/std/lookup/rs/src/lookup_lib.rs b/pil2-components/test/std/lookup/rs/src/lookup_lib.rs index 069cb8a0..77a389b9 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup_lib.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup_lib.rs @@ -2,7 +2,7 @@ use std::{error::Error, path::PathBuf, sync::Arc}; use pil_std_lib::Std; use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; +use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; use p3_field::PrimeField; use p3_goldilocks::Goldilocks; @@ -47,7 +47,7 @@ where } } - pub fn initialize(&mut self, pctx: Arc>, sctx: Arc) { + pub fn initialize(&mut self, pctx: Arc>, sctx: Arc) { let wcm = Arc::new(WitnessManager::new(pctx, sctx)); let std_lib = Std::new(wcm.clone()); @@ -73,7 +73,7 @@ impl WitnessLibrary for LookupWitness where Standard: Distribution, { - fn start_proof(&mut self, pctx: Arc>, sctx: Arc) { + fn start_proof(&mut self, pctx: Arc>, sctx: Arc) { self.initialize(pctx.clone(), sctx.clone()); self.wcm.as_ref().unwrap().start_proof(pctx, sctx); @@ -93,7 +93,7 @@ where self.lookup3.as_ref().unwrap().execute(pctx.clone()); } - fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { + fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, sctx); } } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs index f684153f..35eb20d5 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, seq::SliceRandom, Rng}; @@ -73,7 +73,7 @@ where trace[i].sel2 = trace[indices[i]].sel1; } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); let mut trace2 = Permutation1_6Trace::new(); @@ -111,22 +111,9 @@ where trace2[i].sel2 = trace2[indices[i]].sel1; } - let air_instance2 = AirInstance::new_from_trace( FromTrace::new(&mut trace2)); + let air_instance2 = AirInstance::new_from_trace(FromTrace::new(&mut trace2)); add_air_instance::(air_instance2, pctx.clone()); } } -impl WitnessComponent for Permutation1_6 -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - _pctx: Arc>, - _ - _sctx: Arc, - ) { - } -} +impl WitnessComponent for Permutation1_6 where Standard: Distribution {} diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs index 6e603808..4258900b 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -73,22 +73,9 @@ where trace[i].sel2 = trace[i].sel1; } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); } } -impl WitnessComponent for Permutation1_7 -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - _pctx: Arc>, - _ - _sctx: Arc, - ) { - } -} +impl WitnessComponent for Permutation1_7 where Standard: Distribution {} diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs index f3082e33..e623eaf0 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; use rand::{distributions::Standard, prelude::Distribution, Rng}; @@ -73,22 +73,9 @@ where trace[i].sel2 = trace[i].sel1; } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); } } -impl WitnessComponent for Permutation1_8 -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - _pctx: Arc>, - _ - _sctx: Arc, - ) { - } -} +impl WitnessComponent for Permutation1_8 where Standard: Distribution {} diff --git a/pil2-components/test/std/permutation/rs/src/permutation2.rs b/pil2-components/test/std/permutation/rs/src/permutation2.rs index 4d7ce188..b780d504 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation2.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation2.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; @@ -45,19 +45,9 @@ impl Permutation2 { trace[i].sel = F::from_bool(true); } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); } } -impl WitnessComponent for Permutation2 { - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - _pctx: Arc>, - _ - _sctx: Arc, - ) { - } -} +impl WitnessComponent for Permutation2 {} diff --git a/pil2-components/test/std/permutation/rs/src/permutation_lib.rs b/pil2-components/test/std/permutation/rs/src/permutation_lib.rs index bfbd043f..62161cf1 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation_lib.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation_lib.rs @@ -2,7 +2,7 @@ use std::{error::Error, path::PathBuf, sync::Arc}; use pil_std_lib::Std; use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; +use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; use p3_field::PrimeField; use p3_goldilocks::Goldilocks; @@ -43,7 +43,7 @@ where } } - pub fn initialize(&mut self, pctx: Arc>, sctx: Arc) { + pub fn initialize(&mut self, pctx: Arc>, sctx: Arc) { let wcm = Arc::new(WitnessManager::new(pctx, sctx)); let std_lib = Std::new(wcm.clone()); @@ -65,7 +65,7 @@ impl WitnessLibrary for PermutationWitness where Standard: Distribution, { - fn start_proof(&mut self, pctx: Arc>, sctx: Arc) { + fn start_proof(&mut self, pctx: Arc>, sctx: Arc) { self.initialize(pctx.clone(), sctx.clone()); self.wcm.as_ref().unwrap().start_proof(pctx, sctx); @@ -83,7 +83,7 @@ where self.permutation2.as_ref().unwrap().execute(pctx); } - fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { + fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, sctx); } } diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs index 119622c8..1dc9fabd 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -101,23 +101,10 @@ where } } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - } -} - -impl WitnessComponent for MultiRangeCheck1 -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - pctx: Arc>, - _ - _sctx: Arc, - ) { self.std_lib.unregister_predecessor(pctx, None); } } + +impl WitnessComponent for MultiRangeCheck1 where Standard: Distribution {} diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs index d9a78820..2f80f350 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -83,23 +83,10 @@ where } } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - } -} - -impl WitnessComponent for MultiRangeCheck2 -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - pctx: Arc>, - _ - _sctx: Arc, - ) { self.std_lib.unregister_predecessor(pctx, None); } } + +impl WitnessComponent for MultiRangeCheck2 where Standard: Distribution {} diff --git a/pil2-components/test/std/range_check/rs/src/range_check1.rs b/pil2-components/test/std/range_check/rs/src/range_check1.rs index fcdb0d6c..c32d57a6 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check1.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -80,23 +80,10 @@ where } } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - } -} - -impl WitnessComponent for RangeCheck1 -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - pctx: Arc>, - _ - _sctx: Arc, - ) { self.std_lib.unregister_predecessor(pctx, None); } } + +impl WitnessComponent for RangeCheck1 where Standard: Distribution {} diff --git a/pil2-components/test/std/range_check/rs/src/range_check2.rs b/pil2-components/test/std/range_check/rs/src/range_check2.rs index 289b4d81..81bbbbc0 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check2.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -55,23 +55,10 @@ where self.std_lib.range_check(trace[i].b3, F::one(), range3); } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - } -} - -impl WitnessComponent for RangeCheck2 -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - pctx: Arc>, - _ - _sctx: Arc, - ) { self.std_lib.unregister_predecessor(pctx, None); } } + +impl WitnessComponent for RangeCheck2 where Standard: Distribution {} diff --git a/pil2-components/test/std/range_check/rs/src/range_check3.rs b/pil2-components/test/std/range_check/rs/src/range_check3.rs index c2d7e1ea..33f69aba 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check3.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check3.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -53,23 +53,10 @@ where self.std_lib.range_check(trace[i].c2, F::one(), range2); } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - } -} - -impl WitnessComponent for RangeCheck3 -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - pctx: Arc>, - _ - _sctx: Arc, - ) { self.std_lib.unregister_predecessor(pctx, None); } } + +impl WitnessComponent for RangeCheck3 where Standard: Distribution {} diff --git a/pil2-components/test/std/range_check/rs/src/range_check4.rs b/pil2-components/test/std/range_check/rs/src/range_check4.rs index 439a497c..8c932605 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check4.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check4.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use num_bigint::BigInt; use num_traits::ToPrimitive; @@ -101,23 +101,10 @@ where self.std_lib.range_check(trace[i].a8, F::one(), range9); } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - } -} - -impl WitnessComponent for RangeCheck4 -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - pctx: Arc>, - _ - _sctx: Arc, - ) { self.std_lib.unregister_predecessor(pctx, None); } } + +impl WitnessComponent for RangeCheck4 where Standard: Distribution {} diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs index fae4f655..c3947165 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use num_bigint::BigInt; use p3_field::PrimeField; @@ -79,23 +79,10 @@ where } } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - } -} - -impl WitnessComponent for RangeCheckDynamic1 -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - pctx: Arc>, - _ - _sctx: Arc, - ) { self.std_lib.unregister_predecessor(pctx, None); } } + +impl WitnessComponent for RangeCheckDynamic1 where Standard: Distribution {} diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs index 4693d12a..929f93b7 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use num_bigint::BigInt; use num_traits::ToPrimitive; @@ -92,23 +92,10 @@ where } } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - } -} - -impl WitnessComponent for RangeCheckDynamic2 -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - pctx: Arc>, - _ - _sctx: Arc, - ) { self.std_lib.unregister_predecessor(pctx, None); } } + +impl WitnessComponent for RangeCheckDynamic2 where Standard: Distribution {} diff --git a/pil2-components/test/std/range_check/rs/src/range_check_lib.rs b/pil2-components/test/std/range_check/rs/src/range_check_lib.rs index 91823c59..bd154aeb 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_lib.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_lib.rs @@ -2,7 +2,7 @@ use std::{cell::OnceCell, error::Error, path::PathBuf, sync::Arc}; use pil_std_lib::Std; use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; +use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; use p3_field::PrimeField; use p3_goldilocks::Goldilocks; @@ -56,7 +56,7 @@ where } } - fn initialize(&self, pctx: Arc>, sctx: Arc) { + fn initialize(&self, pctx: Arc>, sctx: Arc) { let wcm = Arc::new(WitnessManager::new(pctx, sctx)); let std_lib = Std::new(wcm.clone()); @@ -88,7 +88,7 @@ impl WitnessLibrary for RangeCheckWitness where Standard: Distribution, { - fn start_proof(&mut self, pctx: Arc>, sctx: Arc) { + fn start_proof(&mut self, pctx: Arc>, sctx: Arc) { self.initialize(pctx.clone(), sctx.clone()); self.wcm.get().unwrap().start_proof(pctx, sctx); @@ -111,7 +111,7 @@ where self.range_check_mix.get().unwrap().execute(pctx.clone()); } - fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { + fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { self.wcm.get().unwrap().calculate_witness(stage, pctx, sctx); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs index 92d0f4ff..3f14653f 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use pil_std_lib::Std; use proofman::{WitnessComponent, WitnessManager}; -use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx, SetupCtx}; +use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use num_bigint::BigInt; use num_traits::ToPrimitive; @@ -133,23 +133,10 @@ where } } - let air_instance = AirInstance::new_from_trace( FromTrace::new(&mut trace)); + let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - } -} - -impl WitnessComponent for RangeCheckMix -where - Standard: Distribution, -{ - fn calculate_witness( - &self, - _stage: u32, - _air_instance_id: Option, - pctx: Arc>, - _ - _sctx: Arc, - ) { self.std_lib.unregister_predecessor(pctx, None); } } + +impl WitnessComponent for RangeCheckMix where Standard: Distribution {} From 7d1bd95817b1b2d74abfb83cf0b6b356ff9da6c7 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Fri, 13 Dec 2024 19:12:40 +0000 Subject: [PATCH 41/64] Keep cleaning --- examples/fibonacci-square/src/fibonacci.rs | 6 +- examples/fibonacci-square/src/module.rs | 2 +- .../rs/src/range_check/specified_ranges.rs | 2 +- .../std/rs/src/range_check/std_range_check.rs | 2 +- .../lib/std/rs/src/range_check/u16air.rs | 2 +- .../lib/std/rs/src/range_check/u8air.rs | 2 +- pil2-components/lib/std/rs/src/std_prod.rs | 4 +- pil2-components/lib/std/rs/src/std_sum.rs | 4 +- .../test/simple/rs/src/simple_left.rs | 2 +- .../test/simple/rs/src/simple_right.rs | 5 +- .../test/std/connection/rs/src/connection1.rs | 7 +- .../test/std/connection/rs/src/connection2.rs | 5 +- .../std/connection/rs/src/connection_new.rs | 5 +- .../test/std/lookup/rs/src/lookup0.rs | 5 +- .../test/std/lookup/rs/src/lookup1.rs | 5 +- .../test/std/lookup/rs/src/lookup2_12.rs | 5 +- .../test/std/lookup/rs/src/lookup2_13.rs | 5 +- .../test/std/lookup/rs/src/lookup2_15.rs | 5 +- .../test/std/lookup/rs/src/lookup3.rs | 5 +- .../std/permutation/rs/src/permutation1_6.rs | 5 +- .../std/permutation/rs/src/permutation1_7.rs | 5 +- .../std/permutation/rs/src/permutation1_8.rs | 5 +- .../std/permutation/rs/src/permutation2.rs | 7 +- .../range_check/rs/src/multi_range_check1.rs | 5 +- .../range_check/rs/src/multi_range_check2.rs | 5 +- .../std/range_check/rs/src/range_check1.rs | 5 +- .../std/range_check/rs/src/range_check2.rs | 5 +- .../std/range_check/rs/src/range_check3.rs | 5 +- .../std/range_check/rs/src/range_check4.rs | 5 +- .../rs/src/range_check_dynamic1.rs | 5 +- .../rs/src/range_check_dynamic2.rs | 5 +- .../std/range_check/rs/src/range_check_mix.rs | 5 +- proofman/src/global_constraints.rs | 98 +++++++++++++++++++ proofman/src/lib.rs | 2 - proofman/src/witness_component.rs | 9 +- proofman/src/witness_executor.rs | 5 - proofman/src/witness_manager.rs | 68 +------------ 37 files changed, 140 insertions(+), 187 deletions(-) delete mode 100644 proofman/src/witness_executor.rs diff --git a/examples/fibonacci-square/src/fibonacci.rs b/examples/fibonacci-square/src/fibonacci.rs index 56ed114c..eddfd490 100644 --- a/examples/fibonacci-square/src/fibonacci.rs +++ b/examples/fibonacci-square/src/fibonacci.rs @@ -20,11 +20,7 @@ impl FibonacciSquare { pub fn new(wcm: Arc>, module: Arc>) -> Arc { let fibonacci = Arc::new(Self { module }); - wcm.register_component( - fibonacci.clone(), - FibonacciSquareTrace::::AIRGROUP_ID, - FibonacciSquareTrace::::AIR_ID, - ); + wcm.register_component(fibonacci.clone()); fibonacci } diff --git a/examples/fibonacci-square/src/module.rs b/examples/fibonacci-square/src/module.rs index 733d5358..7d5f59b2 100644 --- a/examples/fibonacci-square/src/module.rs +++ b/examples/fibonacci-square/src/module.rs @@ -19,7 +19,7 @@ impl Module< pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let module = Arc::new(Module { inputs: Mutex::new(Vec::new()), std_lib }); - wcm.register_component(module.clone(), ModuleTrace::::AIRGROUP_ID, ModuleTrace::::AIR_ID); + wcm.register_component(module.clone()); // Register dependency relations module.std_lib.register_predecessor(); diff --git a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs index 926ccf28..8d2c292a 100644 --- a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs +++ b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs @@ -73,7 +73,7 @@ impl SpecifiedRanges { mul_columns: Mutex::new(Vec::new()), }); - wcm.register_component(specified_ranges.clone(), airgroup_id, air_id); + wcm.register_component(specified_ranges.clone()); specified_ranges } diff --git a/pil2-components/lib/std/rs/src/range_check/std_range_check.rs b/pil2-components/lib/std/rs/src/range_check/std_range_check.rs index 47a92ab6..b2014cb2 100644 --- a/pil2-components/lib/std/rs/src/range_check/std_range_check.rs +++ b/pil2-components/lib/std/rs/src/range_check/std_range_check.rs @@ -86,7 +86,7 @@ impl StdRangeCheck { let std_range_check = Arc::new(Self { mode, ranges: Mutex::new(Vec::new()), u8air, u16air, specified_ranges }); - wcm.register_proxy_component(std_range_check.clone()); + wcm.register_component(std_range_check.clone()); std_range_check } diff --git a/pil2-components/lib/std/rs/src/range_check/u16air.rs b/pil2-components/lib/std/rs/src/range_check/u16air.rs index 07bcbfa1..cdd452d2 100644 --- a/pil2-components/lib/std/rs/src/range_check/u16air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u16air.rs @@ -66,7 +66,7 @@ impl U16Air { mul_column: Mutex::new(HintFieldValue::Field(F::zero())), }); - wcm.register_component(u16air.clone(), airgroup_id, air_id); + wcm.register_component(u16air.clone()); u16air } diff --git a/pil2-components/lib/std/rs/src/range_check/u8air.rs b/pil2-components/lib/std/rs/src/range_check/u8air.rs index f32c37e3..8cd50693 100644 --- a/pil2-components/lib/std/rs/src/range_check/u8air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u8air.rs @@ -65,7 +65,7 @@ impl U8Air { mul_column: Mutex::new(HintFieldValue::Field(F::zero())), }); - wcm.register_component(u8air.clone(), airgroup_id, air_id); + wcm.register_component(u8air.clone()); u8air } diff --git a/pil2-components/lib/std/rs/src/std_prod.rs b/pil2-components/lib/std/rs/src/std_prod.rs index 02a8ade9..2f3aeb49 100644 --- a/pil2-components/lib/std/rs/src/std_prod.rs +++ b/pil2-components/lib/std/rs/src/std_prod.rs @@ -51,7 +51,7 @@ impl StdProd { debug_data: if mode.name == ModeName::Debug { Some(Mutex::new(HashMap::new())) } else { None }, }); - wcm.register_proxy_component(std_prod.clone()); + wcm.register_component(std_prod.clone()); std_prod } @@ -249,7 +249,7 @@ impl WitnessComponent for StdProd { self.decide(sctx); } - fn calculate_witness(&self, stage: u32, _air_instance: Option, pctx: Arc>, sctx: Arc) { + fn calculate_witness(&self, stage: u32, pctx: Arc>, sctx: Arc) { if stage == 2 { let prod_airs = self.prod_airs.lock().unwrap(); diff --git a/pil2-components/lib/std/rs/src/std_sum.rs b/pil2-components/lib/std/rs/src/std_sum.rs index 644329b3..927bc0f4 100644 --- a/pil2-components/lib/std/rs/src/std_sum.rs +++ b/pil2-components/lib/std/rs/src/std_sum.rs @@ -53,7 +53,7 @@ impl StdSum { debug_data: if mode.name == ModeName::Debug { Some(Mutex::new(HashMap::new())) } else { None }, }); - wcm.register_proxy_component(std_sum.clone()); + wcm.register_component(std_sum.clone()); std_sum } @@ -247,7 +247,7 @@ impl WitnessComponent for StdSum { self.decide(sctx); } - fn calculate_witness(&self, stage: u32, _air_instance: Option, pctx: Arc>, sctx: Arc) { + fn calculate_witness(&self, stage: u32, pctx: Arc>, sctx: Arc) { if stage == 2 { let sum_airs = self.sum_airs.lock().unwrap(); diff --git a/pil2-components/test/simple/rs/src/simple_left.rs b/pil2-components/test/simple/rs/src/simple_left.rs index 6b594065..9e912c08 100644 --- a/pil2-components/test/simple/rs/src/simple_left.rs +++ b/pil2-components/test/simple/rs/src/simple_left.rs @@ -21,7 +21,7 @@ where pub fn new(wcm: Arc>) -> Arc { let simple_left = Arc::new(Self { _phantom: std::marker::PhantomData }); - wcm.register_component(simple_left.clone(), SimpleLeftTrace::::AIRGROUP_ID, SimpleLeftTrace::::AIR_ID); + wcm.register_component(simple_left.clone()); simple_left } diff --git a/pil2-components/test/simple/rs/src/simple_right.rs b/pil2-components/test/simple/rs/src/simple_right.rs index 1a53b807..efe02efd 100644 --- a/pil2-components/test/simple/rs/src/simple_right.rs +++ b/pil2-components/test/simple/rs/src/simple_right.rs @@ -21,10 +21,7 @@ where pub fn new(wcm: Arc>) -> Arc { let simple_right = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = SimpleRightTrace::::AIRGROUP_ID; - let air_id = SimpleRightTrace::::AIR_ID; - - wcm.register_component(simple_right.clone(), airgroup_id, air_id); + wcm.register_component(simple_right.clone()); simple_right } diff --git a/pil2-components/test/std/connection/rs/src/connection1.rs b/pil2-components/test/std/connection/rs/src/connection1.rs index 48131dd4..e9af7ccc 100644 --- a/pil2-components/test/std/connection/rs/src/connection1.rs +++ b/pil2-components/test/std/connection/rs/src/connection1.rs @@ -20,11 +20,8 @@ where pub fn new(wcm: Arc>) -> Arc { let connection1 = Arc::new(Self { _phantom: std::marker::PhantomData }); - - let airgroup_id = Connection1Trace::::AIRGROUP_ID; - let air_id = Connection1Trace::::AIR_ID; - - wcm.register_component(connection1.clone(), airgroup_id, air_id); + + wcm.register_component(connection1.clone()); connection1 } diff --git a/pil2-components/test/std/connection/rs/src/connection2.rs b/pil2-components/test/std/connection/rs/src/connection2.rs index eed78fc1..16562914 100644 --- a/pil2-components/test/std/connection/rs/src/connection2.rs +++ b/pil2-components/test/std/connection/rs/src/connection2.rs @@ -21,10 +21,7 @@ where pub fn new(wcm: Arc>) -> Arc { let connection2 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Connection2Trace::::AIRGROUP_ID; - let air_id = Connection2Trace::::AIR_ID; - - wcm.register_component(connection2.clone(), airgroup_id, air_id); + wcm.register_component(connection2.clone()); connection2 } diff --git a/pil2-components/test/std/connection/rs/src/connection_new.rs b/pil2-components/test/std/connection/rs/src/connection_new.rs index 37a21436..18ad98d6 100644 --- a/pil2-components/test/std/connection/rs/src/connection_new.rs +++ b/pil2-components/test/std/connection/rs/src/connection_new.rs @@ -21,10 +21,7 @@ where pub fn new(wcm: Arc>) -> Arc { let connection_new = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = ConnectionNewTrace::::AIRGROUP_ID; - let air_id = ConnectionNewTrace::::AIR_ID; - - wcm.register_component(connection_new.clone(), airgroup_id, air_id); + wcm.register_component(connection_new.clone()); connection_new } diff --git a/pil2-components/test/std/lookup/rs/src/lookup0.rs b/pil2-components/test/std/lookup/rs/src/lookup0.rs index 491512db..4f6626d4 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup0.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup0.rs @@ -21,10 +21,7 @@ where pub fn new(wcm: Arc>) -> Arc { let lookup0 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Lookup0Trace::::AIRGROUP_ID; - let air_id = Lookup0Trace::::AIR_ID; - - wcm.register_component(lookup0.clone(), airgroup_id, air_id); + wcm.register_component(lookup0.clone()); lookup0 } diff --git a/pil2-components/test/std/lookup/rs/src/lookup1.rs b/pil2-components/test/std/lookup/rs/src/lookup1.rs index e0985b0d..fbcb650d 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup1.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup1.rs @@ -21,10 +21,7 @@ where pub fn new(wcm: Arc>) -> Arc { let lookup1 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Lookup1Trace::::AIRGROUP_ID; - let air_id = Lookup1Trace::::AIR_ID; - - wcm.register_component(lookup1.clone(), airgroup_id, air_id); + wcm.register_component(lookup1.clone()); lookup1 } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs index fa4ddd94..ad434ddb 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs @@ -21,10 +21,7 @@ where pub fn new(wcm: Arc>) -> Arc { let lookup2_12 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Lookup2_12Trace::::AIRGROUP_ID; - let air_id = Lookup2_12Trace::::AIR_ID; - - wcm.register_component(lookup2_12.clone(), airgroup_id, air_id); + wcm.register_component(lookup2_12.clone()); lookup2_12 } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs index 0326165c..399a520c 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs @@ -21,10 +21,7 @@ where pub fn new(wcm: Arc>) -> Arc { let lookup2_13 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Lookup2_13Trace::::AIRGROUP_ID; - let air_id = Lookup2_13Trace::::AIR_ID; - - wcm.register_component(lookup2_13.clone(), airgroup_id, air_id); + wcm.register_component(lookup2_13.clone()); lookup2_13 } diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs index 9a34af74..152dbc91 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs @@ -21,10 +21,7 @@ where pub fn new(wcm: Arc>) -> Arc { let lookup2_15 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Lookup2_15Trace::::AIRGROUP_ID; - let air_id = Lookup2_15Trace::::AIR_ID; - - wcm.register_component(lookup2_15.clone(), airgroup_id, air_id); + wcm.register_component(lookup2_15.clone()); lookup2_15 } diff --git a/pil2-components/test/std/lookup/rs/src/lookup3.rs b/pil2-components/test/std/lookup/rs/src/lookup3.rs index 89b60b5c..0ca96c1a 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup3.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup3.rs @@ -17,10 +17,7 @@ impl Lookup3 { pub fn new(wcm: Arc>) -> Arc { let lookup3 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Lookup3Trace::::AIRGROUP_ID; - let air_id = Lookup3Trace::::AIR_ID; - - wcm.register_component(lookup3.clone(), airgroup_id, air_id); + wcm.register_component(lookup3.clone()); lookup3 } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs index 35eb20d5..cc9ca40a 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs @@ -21,10 +21,7 @@ where pub fn new(wcm: Arc>) -> Arc { let permutation1_6 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Permutation1_6Trace::::AIRGROUP_ID; - let air_id = Permutation1_6Trace::::AIR_ID; - - wcm.register_component(permutation1_6.clone(), airgroup_id, air_id); + wcm.register_component(permutation1_6.clone()); permutation1_6 } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs index 4258900b..3be65439 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs @@ -21,10 +21,7 @@ where pub fn new(wcm: Arc>) -> Arc { let permutation1_7 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Permutation1_7Trace::::AIRGROUP_ID; - let air_id = Permutation1_7Trace::::AIR_ID; - - wcm.register_component(permutation1_7.clone(), airgroup_id, air_id); + wcm.register_component(permutation1_7.clone()); permutation1_7 } diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs index e623eaf0..86744c29 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs @@ -21,10 +21,7 @@ where pub fn new(wcm: Arc>) -> Arc { let permutation1_8 = Arc::new(Self { _phantom: std::marker::PhantomData }); - let airgroup_id = Permutation1_8Trace::::AIRGROUP_ID; - let air_id = Permutation1_8Trace::::AIR_ID; - - wcm.register_component(permutation1_8.clone(), airgroup_id, air_id); + wcm.register_component(permutation1_8.clone()); permutation1_8 } diff --git a/pil2-components/test/std/permutation/rs/src/permutation2.rs b/pil2-components/test/std/permutation/rs/src/permutation2.rs index b780d504..60366547 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation2.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation2.rs @@ -16,11 +16,8 @@ impl Permutation2 { pub fn new(wcm: Arc>) -> Arc { let permutation2 = Arc::new(Self { _phantom: std::marker::PhantomData }); - - let airgroup_id = Permutation2_6Trace::::AIRGROUP_ID; - let air_id = Permutation2_6Trace::::AIR_ID; - - wcm.register_component(permutation2.clone(), airgroup_id, air_id); + + wcm.register_component(permutation2.clone()); permutation2 } diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs index 1dc9fabd..70559e09 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs @@ -23,10 +23,7 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let multi_range_check1 = Arc::new(Self { std_lib }); - let airgroup_id = MultiRangeCheck1Trace::::AIRGROUP_ID; - let air_id = MultiRangeCheck1Trace::::AIR_ID; - - wcm.register_component(multi_range_check1.clone(), airgroup_id, air_id); + wcm.register_component(multi_range_check1.clone()); // Register dependency relations multi_range_check1.std_lib.register_predecessor(); diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs index 2f80f350..62b4b072 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs @@ -23,10 +23,7 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let multi_range_check2 = Arc::new(Self { std_lib }); - let airgroup_id = MultiRangeCheck2Trace::::AIRGROUP_ID; - let air_id = MultiRangeCheck2Trace::::AIR_ID; - - wcm.register_component(multi_range_check2.clone(), airgroup_id, air_id); + wcm.register_component(multi_range_check2.clone()); // Register dependency relations multi_range_check2.std_lib.register_predecessor(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check1.rs b/pil2-components/test/std/range_check/rs/src/range_check1.rs index c32d57a6..6463c2c6 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check1.rs @@ -23,10 +23,7 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let range_check1 = Arc::new(Self { std_lib }); - let airgroup_id = RangeCheck1Trace::::AIRGROUP_ID; - let air_id = RangeCheck1Trace::::AIR_ID; - - wcm.register_component(range_check1.clone(), airgroup_id, air_id); + wcm.register_component(range_check1.clone()); // Register dependency relations range_check1.std_lib.register_predecessor(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check2.rs b/pil2-components/test/std/range_check/rs/src/range_check2.rs index 81bbbbc0..03a9e055 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check2.rs @@ -23,10 +23,7 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let range_check2 = Arc::new(Self { std_lib }); - let airgroup_id = RangeCheck2Trace::::AIRGROUP_ID; - let air_id = RangeCheck2Trace::::AIR_ID; - - wcm.register_component(range_check2.clone(), airgroup_id, air_id); + wcm.register_component(range_check2.clone()); // Register dependency relations range_check2.std_lib.register_predecessor(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check3.rs b/pil2-components/test/std/range_check/rs/src/range_check3.rs index 33f69aba..ab80545c 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check3.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check3.rs @@ -23,10 +23,7 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let range_check3 = Arc::new(Self { std_lib }); - let airgroup_id = RangeCheck3Trace::::AIRGROUP_ID; - let air_id = RangeCheck3Trace::::AIR_ID; - - wcm.register_component(range_check3.clone(), airgroup_id, air_id); + wcm.register_component(range_check3.clone()); // Register dependency relations range_check3.std_lib.register_predecessor(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check4.rs b/pil2-components/test/std/range_check/rs/src/range_check4.rs index 8c932605..35e8eb4b 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check4.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check4.rs @@ -24,10 +24,7 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let range_check4 = Arc::new(Self { std_lib }); - let airgroup_id = RangeCheck4Trace::::AIRGROUP_ID; - let air_id = RangeCheck4Trace::::AIR_ID; - - wcm.register_component(range_check4.clone(), airgroup_id, air_id); + wcm.register_component(range_check4.clone()); // Register dependency relations range_check4.std_lib.register_predecessor(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs index c3947165..4a195074 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs @@ -23,10 +23,7 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let range_check_dynamic1 = Arc::new(Self { std_lib }); - let airgroup_id = RangeCheckDynamic1Trace::::AIRGROUP_ID; - let air_id = RangeCheckDynamic1Trace::::AIR_ID; - - wcm.register_component(range_check_dynamic1.clone(), airgroup_id, air_id); + wcm.register_component(range_check_dynamic1.clone()); // Register dependency relations range_check_dynamic1.std_lib.register_predecessor(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs index 929f93b7..60035a4a 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs @@ -24,10 +24,7 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let range_check_dynamic2 = Arc::new(Self { std_lib }); - let airgroup_id = RangeCheckDynamic2Trace::::AIRGROUP_ID; - let air_id = RangeCheckDynamic2Trace::::AIR_ID; - - wcm.register_component(range_check_dynamic2.clone(), airgroup_id, air_id); + wcm.register_component(range_check_dynamic2.clone()); // Register dependency relations range_check_dynamic2.std_lib.register_predecessor(); diff --git a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs index 3f14653f..5f68d27a 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs @@ -24,10 +24,7 @@ where pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { let range_check_mix = Arc::new(Self { std_lib }); - let airgroup_id = RangeCheckMixTrace::::AIRGROUP_ID; - let air_id = RangeCheckMixTrace::::AIR_ID; - - wcm.register_component(range_check_mix.clone(), airgroup_id, air_id); + wcm.register_component(range_check_mix.clone()); // Register dependency relations range_check_mix.std_lib.register_predecessor(); diff --git a/proofman/src/global_constraints.rs b/proofman/src/global_constraints.rs index 5a03b753..cf81d29e 100644 --- a/proofman/src/global_constraints.rs +++ b/proofman/src/global_constraints.rs @@ -84,6 +84,104 @@ pub fn verify_global_constraints_proof( .to_vec() } +pub fn get_hint_field_constant_gc( + sctx: Arc, + hint_id: u64, + hint_field_name: &str, + print_expression: bool, +) -> HintFieldValue { + let raw_ptr = get_hint_field_global_constraints_c( + sctx.get_global_bin(), + std::ptr::null_mut(), + std::ptr::null_mut(), + std::ptr::null_mut(), + std::ptr::null_mut() as *mut *mut u8, + hint_id, + hint_field_name, + print_expression, + ); + + unsafe { + let hint_field_values = &*(raw_ptr as *mut HintFieldInfoValues); + let value = &*(hint_field_values.hint_field_values.add(0)); + if value.matrix_size != 0 { + panic!("get_hint_field can only be called with single expressions, but {} is an array", hint_field_name); + } + HintCol::from_hint_field(value) + } +} + +pub fn get_hint_field_gc_constant_a( + sctx: Arc, + hint_id: u64, + hint_field_name: &str, + print_expression: bool, +) -> HintFieldValuesVec { + let raw_ptr = get_hint_field_global_constraints_c( + sctx.get_global_bin(), + std::ptr::null_mut(), + std::ptr::null_mut(), + std::ptr::null_mut(), + std::ptr::null_mut() as *mut *mut u8, + hint_id, + hint_field_name, + print_expression, + ); + + unsafe { + let mut hint_field_values = Vec::new(); + let hint_field = &*(raw_ptr as *mut HintFieldInfoValues); + for v in 0..hint_field.n_values { + let h = &*(hint_field.hint_field_values.add(v as usize)); + if v == 0 && h.matrix_size != 1 { + panic!("get_hint_field_m can only be called with an array of expressions!"); + } + let hint_value = HintCol::from_hint_field(h); + hint_field_values.push(hint_value); + } + + HintFieldValuesVec { values: hint_field_values } + } +} + +pub fn get_hint_field_constant_gc_m( + sctx: Arc, + hint_id: u64, + hint_field_name: &str, + print_expression: bool, +) -> HintFieldValues { + let raw_ptr = get_hint_field_global_constraints_c( + sctx.get_global_bin(), + std::ptr::null_mut(), + std::ptr::null_mut(), + std::ptr::null_mut(), + std::ptr::null_mut() as *mut *mut u8, + hint_id, + hint_field_name, + print_expression, + ); + + unsafe { + let hint_field = &*(raw_ptr as *mut HintFieldInfoValues); + let mut hint_field_values = HashMap::with_capacity(hint_field.n_values as usize); + + for v in 0..hint_field.n_values { + let h = &*(hint_field.hint_field_values.add(v as usize)); + if v == 0 && h.matrix_size > 2 { + panic!("get_hint_field_m can only be called with a matrix of expressions!",); + } + let hint_value = HintCol::from_hint_field(h); + let mut pos = Vec::new(); + for p in 0..h.matrix_size { + pos.push(h.pos.wrapping_add(p as usize) as u64); + } + hint_field_values.insert(pos, hint_value); + } + + HintFieldValues { values: hint_field_values } + } +} + pub fn get_hint_field_gc( pctx: Arc>, sctx: Arc, diff --git a/proofman/src/lib.rs b/proofman/src/lib.rs index 68e25327..6cd38850 100644 --- a/proofman/src/lib.rs +++ b/proofman/src/lib.rs @@ -1,6 +1,5 @@ mod proofman; mod witness_component; -mod witness_executor; mod witness_library; mod witness_manager; mod constraints; @@ -12,6 +11,5 @@ pub use constraints::*; pub use global_constraints::*; pub use recursion::*; pub use witness_component::*; -pub use witness_executor::*; pub use witness_library::*; pub use witness_manager::*; diff --git a/proofman/src/witness_component.rs b/proofman/src/witness_component.rs index 9381ea66..19ab4a86 100644 --- a/proofman/src/witness_component.rs +++ b/proofman/src/witness_component.rs @@ -5,14 +5,7 @@ use proofman_common::{ProofCtx, SetupCtx}; pub trait WitnessComponent: Send + Sync { fn start_proof(&self, _pctx: Arc>, _sctx: Arc) {} - fn calculate_witness( - &self, - _stage: u32, - _air_instance: Option, - _pctx: Arc>, - _sctx: Arc, - ) { - } + fn calculate_witness(&self, _stage: u32, _pctx: Arc>, _sctx: Arc) {} fn end_proof(&self) {} } diff --git a/proofman/src/witness_executor.rs b/proofman/src/witness_executor.rs deleted file mode 100644 index b84c911f..00000000 --- a/proofman/src/witness_executor.rs +++ /dev/null @@ -1,5 +0,0 @@ -use proofman_common::ProofCtx; - -pub trait WitnessExecutor { - fn execute(&self, pctx: &mut ProofCtx); -} diff --git a/proofman/src/witness_manager.rs b/proofman/src/witness_manager.rs index a85348bb..30eebef7 100644 --- a/proofman/src/witness_manager.rs +++ b/proofman/src/witness_manager.rs @@ -1,21 +1,12 @@ -use std::{ - collections::HashMap, - sync::{Arc, RwLock}, -}; +use std::sync::{Arc, RwLock}; use proofman_common::{ProofCtx, SetupCtx}; use proofman_util::{timer_start_debug, timer_stop_and_log_debug}; use crate::WitnessComponent; -type AirGroupId = usize; -type AirId = usize; - pub struct WitnessManager { components: RwLock>>>, - airs: RwLock>, // First usize is the air_id, second usize is the index of the component in the components vector - pctx: Arc>, - sctx: Arc, } @@ -23,33 +14,11 @@ impl WitnessManager { const MY_NAME: &'static str = "WCMnager"; pub fn new(pctx: Arc>, sctx: Arc) -> Self { - WitnessManager { components: RwLock::new(Vec::new()), airs: RwLock::new(HashMap::new()), pctx, sctx } + WitnessManager { components: RwLock::new(Vec::new()), pctx, sctx } } - pub fn register_component(&self, component: Arc>, airgroup_id: AirGroupId, air_id: AirId) { + pub fn register_component(&self, component: Arc>) { self.components.write().unwrap().push(component); - - let idx = self.components.write().unwrap().len() - 1; - - self.register_air(airgroup_id, air_id, idx); - } - - pub fn register_proxy_component(&self, component: Arc>) { - self.components.write().unwrap().push(component); - } - - pub fn register_airs(&self, airgroup_id: AirGroupId, air_ids: &[AirId], component_idx: usize) { - for air_id in air_ids.iter() { - self.register_air(airgroup_id, *air_id, component_idx); - } - } - - pub fn register_air(&self, airgroup_id: AirGroupId, air_id: AirId, component_idx: usize) { - if self.airs.read().unwrap().contains_key(&(airgroup_id, air_id)) { - panic!("{}: AirGroup ID + Air ID ({},{}) already registered", Self::MY_NAME, airgroup_id, air_id); - } - - self.airs.write().unwrap().insert((airgroup_id, air_id), component_idx); } pub fn start_proof(&self, pctx: Arc>, sctx: Arc) { @@ -74,36 +43,9 @@ impl WitnessManager { timer_start_debug!(CALCULATING_WITNESS); - let air_instances = pctx.air_instance_repo.air_instances.read().unwrap(); - - let mut components = HashMap::new(); - let airs = self.airs.read().unwrap(); - for (air_instance_id, air_instance) in air_instances.iter().enumerate() { - if let Some(component) = airs.get(&(air_instance.airgroup_id, air_instance.air_id)) { - components - .entry((air_instance.airgroup_id, air_instance.air_id)) - .or_insert_with(Vec::new) - .push((component, air_instance_id)); - } - } - drop(air_instances); - - // Call all used components - let mut used_components = Vec::new(); - let self_components = self.components.read().unwrap(); - for component_group in components.values() { - for (component_idx, id) in component_group.iter() { - let component = &self_components[**component_idx]; - component.calculate_witness(stage, Some(*id), pctx.clone(), sctx.clone()); - used_components.push(**component_idx); - } - } - // Call one time all unused components - for component_idx in 0..self.components.read().unwrap().len() { - if !used_components.contains(&component_idx) { - self_components[component_idx].calculate_witness(stage, None, pctx.clone(), sctx.clone()); - } + for component in self.components.read().unwrap().iter() { + component.calculate_witness(stage, pctx.clone(), sctx.clone()); } timer_stop_and_log_debug!(CALCULATING_WITNESS); From d02c37288817e8ea852f04484ff58512ec032b92 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 16 Dec 2024 12:14:21 +0000 Subject: [PATCH 42/64] Simplifying all witness logic --- Cargo.lock | 186 ++++++++++-------- Cargo.toml | 3 + examples/fibonacci-square/Cargo.toml | 5 +- examples/fibonacci-square/src/fibonacci.rs | 24 +-- .../fibonacci-square/src/fibonacci_lib.rs | 69 ++----- examples/fibonacci-square/src/module.rs | 18 +- .../src/global_hints.rs | 46 +---- hints/src/lib.rs | 2 + pil2-components/lib/std/rs/Cargo.toml | 2 +- .../rs/src/range_check/specified_ranges.rs | 28 +-- .../std/rs/src/range_check/std_range_check.rs | 32 ++- .../lib/std/rs/src/range_check/u16air.rs | 37 ++-- .../lib/std/rs/src/range_check/u8air.rs | 35 +--- pil2-components/lib/std/rs/src/std.rs | 53 +++-- pil2-components/lib/std/rs/src/std_prod.rs | 12 +- pil2-components/lib/std/rs/src/std_sum.rs | 12 +- pil2-components/test/simple/rs/Cargo.toml | 1 + .../test/simple/rs/src/simple_left.rs | 30 ++- .../test/simple/rs/src/simple_lib.rs | 82 ++------ .../test/simple/rs/src/simple_right.rs | 30 ++- .../test/std/connection/rs/Cargo.toml | 1 + .../test/std/connection/rs/src/connection1.rs | 27 ++- .../test/std/connection/rs/src/connection2.rs | 27 ++- .../std/connection/rs/src/connection_lib.rs | 112 ++--------- .../std/connection/rs/src/connection_new.rs | 27 ++- pil2-components/test/std/lookup/rs/Cargo.toml | 1 + .../test/std/lookup/rs/src/lookup0.rs | 30 ++- .../test/std/lookup/rs/src/lookup1.rs | 28 ++- .../test/std/lookup/rs/src/lookup2_12.rs | 28 ++- .../test/std/lookup/rs/src/lookup2_13.rs | 28 ++- .../test/std/lookup/rs/src/lookup2_15.rs | 28 ++- .../test/std/lookup/rs/src/lookup3.rs | 26 ++- .../test/std/lookup/rs/src/lookup_lib.rs | 139 ++----------- .../test/std/permutation/rs/Cargo.toml | 1 + .../std/permutation/rs/src/permutation1_6.rs | 29 ++- .../std/permutation/rs/src/permutation1_7.rs | 28 ++- .../std/permutation/rs/src/permutation1_8.rs | 28 ++- .../std/permutation/rs/src/permutation2.rs | 22 +-- .../std/permutation/rs/src/permutation_lib.rs | 120 +---------- .../test/std/range_check/rs/Cargo.toml | 1 + .../range_check/rs/src/multi_range_check1.rs | 18 +- .../range_check/rs/src/multi_range_check2.rs | 18 +- .../std/range_check/rs/src/range_check1.rs | 18 +- .../std/range_check/rs/src/range_check2.rs | 18 +- .../std/range_check/rs/src/range_check3.rs | 18 +- .../std/range_check/rs/src/range_check4.rs | 18 +- .../rs/src/range_check_dynamic1.rs | 18 +- .../rs/src/range_check_dynamic2.rs | 18 +- .../std/range_check/rs/src/range_check_lib.rs | 158 +++------------ .../std/range_check/rs/src/range_check_mix.rs | 18 +- proofman/Cargo.toml | 1 + proofman/src/constraints.rs | 40 +++- proofman/src/lib.rs | 8 - proofman/src/proofman.rs | 50 +++-- proofman/src/witness_library.rs | 19 -- witness/Cargo.toml | 24 +++ witness/src/lib.rs | 7 + .../src/witness_component.rs | 2 + witness/src/witness_library.rs | 36 ++++ {proofman => witness}/src/witness_manager.rs | 38 +++- 60 files changed, 730 insertions(+), 1253 deletions(-) rename proofman/src/global_constraints.rs => hints/src/global_hints.rs (86%) delete mode 100644 proofman/src/witness_library.rs create mode 100644 witness/Cargo.toml create mode 100644 witness/src/lib.rs rename {proofman => witness}/src/witness_component.rs (85%) create mode 100644 witness/src/witness_library.rs rename {proofman => witness}/src/witness_manager.rs (56%) diff --git a/Cargo.lock b/Cargo.lock index fe5e57ed..7aaed7dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.18" +version = "0.6.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" dependencies = [ "anstyle", "anstyle-parse", @@ -28,43 +28,43 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.10" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" [[package]] name = "anstyle-parse" -version = "0.2.6" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.2" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.6" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" dependencies = [ "anstyle", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] name = "anyhow" -version = "1.0.94" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7" +checksum = "c042108f3ed77fd83760a5fd79b53be043192bb3b9dba91d8c574c0ada7850c8" [[package]] name = "autocfg" @@ -119,15 +119,15 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.9.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" +checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" [[package]] name = "cc" -version = "1.2.3" +version = "1.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27f657647bcff5394bf56c7317665bbf790a137a50eaaa5c6bfbb9e27a518f2d" +checksum = "c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f" dependencies = [ "shlex", ] @@ -160,9 +160,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.23" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" +checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" dependencies = [ "clap_builder", "clap_derive", @@ -170,9 +170,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.23" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" +checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" dependencies = [ "anstream", "anstyle", @@ -194,15 +194,15 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.4" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "colorchoice" -version = "1.0.3" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "colored" @@ -306,19 +306,19 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.10" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] name = "fastrand" -version = "2.3.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" [[package]] name = "fibonacci-square" @@ -330,11 +330,11 @@ dependencies = [ "p3-field", "p3-goldilocks", "pil-std-lib", - "proofman", "proofman-common", "proofman-macros", "serde", "serde_json", + "witness", ] [[package]] @@ -395,9 +395,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "indexmap" -version = "2.7.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", "hashbrown", @@ -429,9 +429,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.14" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "lazy_static" @@ -447,9 +447,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.168" +version = "0.2.161" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aaeb2981e0606ca11d79718f8bb01164f1d6ed75080182d3abf017e6d244b6d" +checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "libffi" @@ -472,9 +472,9 @@ dependencies = [ [[package]] name = "libloading" -version = "0.8.6" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", "windows-targets 0.52.6", @@ -729,11 +729,11 @@ dependencies = [ "p3-field", "p3-goldilocks", "pilout", - "proofman", "proofman-common", "proofman-hints", "proofman-util", "rayon", + "witness", ] [[package]] @@ -749,9 +749,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.15" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" [[package]] name = "pkg-config" @@ -770,9 +770,9 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.2.25" +version = "0.2.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" +checksum = "910d41a655dac3b764f1ade94821093d3610248694320cd072303a8eedcf221d" dependencies = [ "proc-macro2", "syn", @@ -780,9 +780,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.92" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" dependencies = [ "unicode-ident", ] @@ -806,6 +806,7 @@ dependencies = [ "serde_json", "stark", "transcript", + "witness", ] [[package]] @@ -882,9 +883,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.13.4" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c0fef6c4230e4ccf618a35c59d7ede15dea37de8427500f50aff708806e42ec" +checksum = "7b0487d90e047de87f984913713b85c601c05609aad5b0df4b4573fbf69aa13f" dependencies = [ "bytes", "prost-derive", @@ -892,10 +893,11 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.13.4" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0f3e5beed80eb580c68e2c600937ac2c4eedabdfd5ef1e5b7ea4f3fba84497b" +checksum = "0c1318b19085f08681016926435853bbf7858f9c082d0999b80550ff5d9abe15" dependencies = [ + "bytes", "heck", "itertools 0.13.0", "log", @@ -912,9 +914,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.13.4" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "157c5a9d7ea5c2ed2d9fb8f495b64759f7816c7eaea54ba3978f0d63000162e3" +checksum = "e9552f850d5f0964a4e4d0bf306459ac29323ddfbae05e35a7c0d35cb0803cc5" dependencies = [ "anyhow", "itertools 0.13.0", @@ -925,9 +927,9 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.13.4" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc2f1e56baa61e93533aebc21af4d2134b70f66275e0fcdf3cbe43d77ff7e8fc" +checksum = "4759aa0d3a6232fb8dbdb97b61de2c20047c68aca932c7ed76da9d788508d670" dependencies = [ "prost", ] @@ -993,9 +995,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.11.1" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" dependencies = [ "aho-corasick", "memchr", @@ -1005,9 +1007,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.9" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", @@ -1028,15 +1030,15 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" -version = "0.38.42" +version = "0.38.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" dependencies = [ "bitflags", "errno", "libc", "linux-raw-sys", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -1047,18 +1049,18 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "serde" -version = "1.0.216" +version = "1.0.213" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" +checksum = "3ea7893ff5e2466df8d720bb615088341b295f849602c6956047f8f80f0e9bc1" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.216" +version = "1.0.213" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" +checksum = "7e85ad2009c50b58e87caa8cd6dac16bdf511bbfb7af6c33df902396aa480fa5" dependencies = [ "proc-macro2", "quote", @@ -1067,9 +1069,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.133" +version = "1.0.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" +checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" dependencies = [ "itoa", "memchr", @@ -1126,9 +1128,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.90" +version = "2.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" +checksum = "83540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021" dependencies = [ "proc-macro2", "quote", @@ -1151,9 +1153,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.14.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" dependencies = [ "cfg-if", "fastrand", @@ -1164,18 +1166,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.69" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.69" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ "proc-macro2", "quote", @@ -1194,9 +1196,9 @@ dependencies = [ [[package]] name = "tracing" -version = "0.1.41" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "pin-project-lite", "tracing-attributes", @@ -1205,9 +1207,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.28" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", @@ -1216,9 +1218,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.33" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", ] @@ -1242,9 +1244,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.14" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-segmentation" @@ -1499,6 +1501,22 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "witness" +version = "0.1.0" +dependencies = [ + "colored", + "env_logger", + "libloading", + "log", + "mpi", + "p3-field", + "p3-goldilocks", + "proofman-common", + "proofman-util", + "serde_json", +] + [[package]] name = "zerocopy" version = "0.7.35" diff --git a/Cargo.toml b/Cargo.toml index 02a3dd7c..45e188aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ members = [ "provers/stark", "provers/starks-lib-c", "transcript", + "witness", "util", "pil2-components/lib/std/rs", # "pil2-components/test/std/range_check/rs", @@ -32,6 +33,8 @@ proofman-common = { path = "common", version = "0.1.0" } proofman-hints = { path = "hints", version = "0.1.0" } proofman-util = { path = "util", version = "0.1.0" } proofman-cli = { path = "cli", version = "0.1.0" } +pil-std-lib = { path = "pil2-components/lib/std/rs", version = "0.1.0" } +witness = { path = "witness", version = "0.1.0" } pilout = { path = "pilout", version = "0.1.0" } log = { version = "0.4", default-features = false } env_logger = "0.11" diff --git a/examples/fibonacci-square/Cargo.toml b/examples/fibonacci-square/Cargo.toml index e6ffb65b..72b9bd27 100644 --- a/examples/fibonacci-square/Cargo.toml +++ b/examples/fibonacci-square/Cargo.toml @@ -9,9 +9,8 @@ crate-type = ["dylib"] [dependencies] proofman-common = { path = "../../common" } proofman-macros.workspace = true -proofman = { path = "../../proofman" } -pil-std-lib = {path = "../../pil2-components/lib/std/rs" } - +witness.workspace = true +pil-std-lib.workspace = true env_logger.workspace = true log.workspace = true p3-goldilocks.workspace = true diff --git a/examples/fibonacci-square/src/fibonacci.rs b/examples/fibonacci-square/src/fibonacci.rs index eddfd490..e8b77136 100644 --- a/examples/fibonacci-square/src/fibonacci.rs +++ b/examples/fibonacci-square/src/fibonacci.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use proofman_common::{add_air_instance, AirInstance, FromTrace, ProofCtx}; -use proofman::{WitnessManager, WitnessComponent}; +use witness::WitnessComponent; use p3_field::PrimeField64; @@ -17,21 +17,13 @@ pub struct FibonacciSquare { impl FibonacciSquare { const MY_NAME: &'static str = "FiboSqre"; - pub fn new(wcm: Arc>, module: Arc>) -> Arc { - let fibonacci = Arc::new(Self { module }); - - wcm.register_component(fibonacci.clone()); - - fibonacci - } - - pub fn execute(&self, pctx: Arc>) { - if let Err(e) = Self::calculate_trace(self, pctx) { - panic!("Failed to calculate fibonacci: {:?}", e); - } + pub fn new(module: Arc>) -> Arc { + Arc::new(Self { module }) } +} - fn calculate_trace(&self, pctx: Arc>) -> Result> { +impl WitnessComponent for FibonacciSquare { + fn execute(&self, pctx: Arc>) { log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let mut publics = BuildPublicValues::from_vec_guard(pctx.get_publics()); @@ -76,9 +68,5 @@ impl FibonacciSquare { FromTrace::new(&mut trace).with_custom_traces(vec![&mut trace_rom]).with_air_values(&mut air_values), ); add_air_instance::(air_instance, pctx.clone()); - - Ok(b) } } - -impl WitnessComponent for FibonacciSquare {} diff --git a/examples/fibonacci-square/src/fibonacci_lib.rs b/examples/fibonacci-square/src/fibonacci_lib.rs index d74a5add..d8cf0992 100644 --- a/examples/fibonacci-square/src/fibonacci_lib.rs +++ b/examples/fibonacci-square/src/fibonacci_lib.rs @@ -1,76 +1,29 @@ use std::sync::Arc; - -use proofman_common::{initialize_logger, load_from_json, ProofCtx, SetupCtx, VerboseMode}; -use proofman::{WitnessLibrary, WitnessManager}; +use proofman_common::load_from_json; +use witness::{witness_library, WitnessLibrary, WitnessManager}; use pil_std_lib::Std; use p3_field::PrimeField64; use p3_goldilocks::Goldilocks; -use std::error::Error; -use std::path::PathBuf; - use crate::{BuildPublics, BuildPublicValues, FibonacciSquare, Module}; -pub struct FibonacciWitness { - public_inputs_path: Option, - wcm: Option>>, - fibonacci: Option>>, - module: Option>>, - std_lib: Option>>, -} - -impl FibonacciWitness { - pub fn new(public_inputs_path: Option) -> Self { - Self { public_inputs_path, wcm: None, fibonacci: None, module: None, std_lib: None } - } -} - -impl WitnessLibrary for FibonacciWitness { - fn start_proof(&mut self, pctx: Arc>, sctx: Arc) { - let wcm = Arc::new(WitnessManager::new(pctx.clone(), sctx.clone())); +witness_library!(WitnessLib, Goldilocks); +impl WitnessLibrary for WitnessLib { + fn register_witness(&mut self, wcm: Arc>) { let std_lib = Std::new(wcm.clone()); - let module = Module::new(wcm.clone(), std_lib.clone()); - let fibonacci = FibonacciSquare::new(wcm.clone(), module.clone()); + let module = Module::new(std_lib.clone()); + let fibonacci = FibonacciSquare::new(module.clone()); - self.wcm = Some(wcm.clone()); - self.fibonacci = Some(fibonacci); - self.module = Some(module); - self.std_lib = Some(std_lib); + wcm.register_component(fibonacci.clone()); + wcm.register_component(module.clone()); - let public_inputs: BuildPublics = load_from_json(&self.public_inputs_path); + let public_inputs: BuildPublics = load_from_json(&wcm.get_public_inputs_path()); - let mut publics = BuildPublicValues::from_vec_guard(pctx.get_publics()); + let mut publics = BuildPublicValues::from_vec_guard(wcm.get_pctx().get_publics()); publics.module = F::from_canonical_u64(public_inputs.module); publics.in1 = F::from_canonical_u64(public_inputs.in1); publics.in2 = F::from_canonical_u64(public_inputs.in2); - - wcm.start_proof(pctx, sctx); } - - fn end_proof(&mut self) { - self.wcm.as_ref().unwrap().end_proof(); - } - - fn execute(&self, pctx: Arc>) { - self.fibonacci.as_ref().unwrap().execute(pctx.clone()); - self.module.as_ref().unwrap().execute(pctx); - } - - fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { - self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, sctx); - } -} - -#[no_mangle] -pub extern "Rust" fn init_library( - _: Option, - public_inputs_path: Option, - verbose_mode: VerboseMode, -) -> Result>, Box> { - initialize_logger(verbose_mode); - - let fibonacci_witness = FibonacciWitness::new(public_inputs_path); - Ok(Box::new(fibonacci_witness)) } diff --git a/examples/fibonacci-square/src/module.rs b/examples/fibonacci-square/src/module.rs index 7d5f59b2..cff2594b 100644 --- a/examples/fibonacci-square/src/module.rs +++ b/examples/fibonacci-square/src/module.rs @@ -1,7 +1,7 @@ use std::sync::{Arc, Mutex}; use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; -use proofman::{WitnessManager, WitnessComponent}; +use witness::WitnessComponent; use pil_std_lib::Std; use p3_field::{AbstractField, PrimeField64}; use num_bigint::BigInt; @@ -16,11 +16,9 @@ pub struct Module { impl Module { const MY_NAME: &'static str = "ModuleSM"; - pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { + pub fn new(std_lib: Arc>) -> Arc { let module = Arc::new(Module { inputs: Mutex::new(Vec::new()), std_lib }); - wcm.register_component(module.clone()); - // Register dependency relations module.std_lib.register_predecessor(); @@ -36,12 +34,10 @@ impl Module< x_mod } +} - pub fn execute(&self, pctx: Arc>) { - self.calculate_trace(pctx); - } - - fn calculate_trace(&self, pctx: Arc>) { +impl WitnessComponent for Module { + fn execute(&self, pctx: Arc>) { log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); let module = F::as_canonical_u64(&pctx.get_public_value("module")); @@ -74,8 +70,6 @@ impl Module< let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - self.std_lib.unregister_predecessor(pctx, None); + self.std_lib.unregister_predecessor(); } } - -impl WitnessComponent for Module {} diff --git a/proofman/src/global_constraints.rs b/hints/src/global_hints.rs similarity index 86% rename from proofman/src/global_constraints.rs rename to hints/src/global_hints.rs index cf81d29e..2561b84a 100644 --- a/proofman/src/global_constraints.rs +++ b/hints/src/global_hints.rs @@ -1,12 +1,10 @@ use p3_field::Field; -use proofman_hints::{HintCol, HintFieldInfoValues, HintFieldOutput, HintFieldValue, HintFieldValues, HintFieldValuesVec}; -use proofman_starks_lib_c::{ - get_hint_field_global_constraints_c, set_hint_field_global_constraints_c, verify_global_constraints_c, -}; +use crate::{HintCol, HintFieldInfoValues, HintFieldOutput, HintFieldValue, HintFieldValues, HintFieldValuesVec}; +use proofman_starks_lib_c::{get_hint_field_global_constraints_c, set_hint_field_global_constraints_c}; use std::{collections::HashMap, sync::Arc}; -use proofman_common::{GlobalConstraintInfo, GlobalConstraintsResults, ExtensionField, ProofCtx, SetupCtx}; +use proofman_common::{ExtensionField, ProofCtx, SetupCtx}; pub fn aggregate_airgroupvals(pctx: Arc>) -> Vec> { const FIELD_EXTENSION: usize = 3; @@ -54,36 +52,6 @@ pub fn aggregate_airgroupvals(pctx: Arc>) -> Vec> { airgroupvalues } -pub fn verify_global_constraints_proof( - pctx: Arc>, - sctx: Arc, -) -> Vec { - const MY_NAME: &str = "GlCstVfy"; - - log::info!("{}: --> Checking global constraints", MY_NAME); - - let mut airgroupvalues = aggregate_airgroupvals(pctx.clone()); - - let mut airgroup_values_ptrs: Vec<*mut F> = airgroupvalues - .iter_mut() // Iterate mutably over the inner Vecs - .map(|inner_vec| inner_vec.as_mut_ptr()) // Get a raw pointer to each inner Vec - .collect(); - - let raw_ptr = verify_global_constraints_c( - sctx.get_global_bin(), - pctx.get_publics_ptr(), - pctx.get_challenges_ptr(), - pctx.get_proof_values_ptr(), - airgroup_values_ptrs.as_mut_ptr() as *mut *mut u8, - ); - - unsafe { - let constraints_result = Box::from_raw(raw_ptr as *mut GlobalConstraintsResults); - std::slice::from_raw_parts(constraints_result.constraints_info, constraints_result.n_constraints as usize) - } - .to_vec() -} - pub fn get_hint_field_constant_gc( sctx: Arc, hint_id: u64, @@ -95,7 +63,7 @@ pub fn get_hint_field_constant_gc( std::ptr::null_mut(), std::ptr::null_mut(), std::ptr::null_mut(), - std::ptr::null_mut() as *mut *mut u8, + std::ptr::null_mut(), hint_id, hint_field_name, print_expression, @@ -122,7 +90,7 @@ pub fn get_hint_field_gc_constant_a( std::ptr::null_mut(), std::ptr::null_mut(), std::ptr::null_mut(), - std::ptr::null_mut() as *mut *mut u8, + std::ptr::null_mut(), hint_id, hint_field_name, print_expression, @@ -155,7 +123,7 @@ pub fn get_hint_field_constant_gc_m( std::ptr::null_mut(), std::ptr::null_mut(), std::ptr::null_mut(), - std::ptr::null_mut() as *mut *mut u8, + std::ptr::null_mut(), hint_id, hint_field_name, print_expression, @@ -301,7 +269,7 @@ pub fn get_hint_field_gc_m( } } -pub fn set_hint_field( +pub fn set_hint_field_gc( pctx: Arc>, sctx: Arc, hint_id: u64, diff --git a/hints/src/lib.rs b/hints/src/lib.rs index 0fe5e2a4..719cb48a 100644 --- a/hints/src/lib.rs +++ b/hints/src/lib.rs @@ -1,3 +1,5 @@ mod hints; +mod global_hints; pub use hints::*; +pub use global_hints::*; diff --git a/pil2-components/lib/std/rs/Cargo.toml b/pil2-components/lib/std/rs/Cargo.toml index 68d35bb8..3e82e340 100644 --- a/pil2-components/lib/std/rs/Cargo.toml +++ b/pil2-components/lib/std/rs/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" edition = "2021" [dependencies] -proofman.workspace = true proofman-common.workspace = true proofman-hints.workspace = true proofman-util.workspace = true @@ -15,3 +14,4 @@ num-traits.workspace = true p3-goldilocks.workspace = true p3-field.workspace = true rayon.workspace = true +witness.workspace = true diff --git a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs index 8d2c292a..bb93732a 100644 --- a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs +++ b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs @@ -4,10 +4,11 @@ use std::sync::{Arc, Mutex}; use num_traits::ToPrimitive; use p3_field::PrimeField; -use proofman::{get_hint_field_gc, WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{AirInstance, DistributionCtx, ProofCtx, SetupCtx, TraceInfo}; use proofman_hints::{ - get_hint_field, get_hint_field_constant, get_hint_ids_by_name, set_hint_field, HintFieldOptions, HintFieldValue, + get_hint_field_gc, get_hint_field, get_hint_field_constant, get_hint_ids_by_name, set_hint_field, HintFieldOptions, + HintFieldValue, }; use proofman_util::create_buffer_fast; @@ -16,8 +17,6 @@ use crate::Range; const PROVE_CHUNK_SIZE: usize = 1 << 5; pub struct SpecifiedRanges { - wcm: Arc>, - // Parameters hints: Mutex>, airgroup_id: usize, @@ -33,10 +32,7 @@ pub struct SpecifiedRanges { impl SpecifiedRanges { const MY_NAME: &'static str = "SpecRang"; - pub fn new(wcm: Arc>) -> Arc { - let pctx = wcm.get_pctx(); - let sctx = wcm.get_sctx(); - + pub fn new(pctx: Arc>, sctx: Arc) -> Arc { // Scan global hints to get the airgroup_id and air_id let hint_global = get_hint_ids_by_name(sctx.get_global_bin(), "specified_ranges"); let airgroup_id = get_hint_field_gc::(pctx.clone(), sctx.clone(), hint_global[0], "airgroup_id", false); @@ -62,8 +58,7 @@ impl SpecifiedRanges { } }; - let specified_ranges = Arc::new(Self { - wcm: wcm.clone(), + Arc::new(Self { hints: Mutex::new(Vec::new()), airgroup_id, air_id, @@ -71,11 +66,7 @@ impl SpecifiedRanges { ranges: Mutex::new(Vec::new()), inputs: Mutex::new(Vec::new()), mul_columns: Mutex::new(Vec::new()), - }); - - wcm.register_component(specified_ranges.clone()); - - specified_ranges + }) } pub fn update_inputs(&self, value: F, range: Range, multiplicity: F) { @@ -91,10 +82,9 @@ impl SpecifiedRanges { } } - pub fn drain_inputs(&self) { + pub fn drain_inputs(&self, pctx: Arc>, sctx: Arc) { let mut inputs = self.inputs.lock().unwrap(); let drained_inputs = inputs.drain(..).collect(); - let pctx = self.wcm.get_pctx(); // Perform the last update self.update_multiplicity(drained_inputs); @@ -123,7 +113,7 @@ impl SpecifiedRanges { // Set the multiplicity columns as done let hints = self.hints.lock().unwrap(); - let air_instance_repo = &self.wcm.get_pctx().air_instance_repo; + let air_instance_repo = &pctx.air_instance_repo; let instance: Vec = air_instance_repo.find_air_instances(self.airgroup_id, self.air_id); let air_instance_id = if !instance.is_empty() { air_instance_repo.find_air_instances(self.airgroup_id, self.air_id)[0] @@ -146,7 +136,7 @@ impl SpecifiedRanges { .collect::>>(); for (index, hint) in hints[1..].iter().enumerate() { - set_hint_field(&self.wcm.get_sctx(), air_instance, *hint, "reference", &mul_columns_2[index]); + set_hint_field(&sctx, air_instance, *hint, "reference", &mul_columns_2[index]); } log::trace!("{}: ··· Drained inputs for AIR '{}'", Self::MY_NAME, "SpecifiedRanges"); diff --git a/pil2-components/lib/std/rs/src/range_check/std_range_check.rs b/pil2-components/lib/std/rs/src/range_check/std_range_check.rs index b2014cb2..2ceb048e 100644 --- a/pil2-components/lib/std/rs/src/range_check/std_range_check.rs +++ b/pil2-components/lib/std/rs/src/range_check/std_range_check.rs @@ -7,10 +7,9 @@ use std::{ use num_bigint::BigInt; use p3_field::PrimeField; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{ProofCtx, SetupCtx, StdMode, ModeName}; use proofman_hints::{get_hint_field_constant, get_hint_ids_by_name, HintFieldOptions, HintFieldValue}; -use rayon::Scope; use crate::{Decider, Range, SpecifiedRanges, U16Air, U8Air}; @@ -71,24 +70,21 @@ impl Decider for StdRangeCheck { impl StdRangeCheck { const _MY_NAME: &'static str = "STD Range Check"; - pub fn new(mode: StdMode, wcm: Arc>) -> Arc { - let sctx = wcm.get_sctx(); - + pub fn new(mode: StdMode, pctx: Arc>, sctx: Arc) -> Arc { // Scan global hints to know which airs are associated with the range check let u8air_hint = get_hint_ids_by_name(sctx.get_global_bin(), "u8air"); let u16air_hint = get_hint_ids_by_name(sctx.get_global_bin(), "u16air"); let specified_ranges_hint = get_hint_ids_by_name(sctx.get_global_bin(), "specified_ranges"); - let u8air = if !u8air_hint.is_empty() { Some(U8Air::new(wcm.clone())) } else { None }; - let u16air = if !u16air_hint.is_empty() { Some(U16Air::new(wcm.clone())) } else { None }; - let specified_ranges = - if !specified_ranges_hint.is_empty() { Some(SpecifiedRanges::new(wcm.clone())) } else { None }; - - let std_range_check = Arc::new(Self { mode, ranges: Mutex::new(Vec::new()), u8air, u16air, specified_ranges }); - - wcm.register_component(std_range_check.clone()); + let u8air = if !u8air_hint.is_empty() { Some(U8Air::new(pctx.clone(), sctx.clone())) } else { None }; + let u16air = if !u16air_hint.is_empty() { Some(U16Air::new(pctx.clone(), sctx.clone())) } else { None }; + let specified_ranges = if !specified_ranges_hint.is_empty() { + Some(SpecifiedRanges::new(pctx.clone(), sctx.clone())) + } else { + None + }; - std_range_check + Arc::new(Self { mode, ranges: Mutex::new(Vec::new()), u8air, u16air, specified_ranges }) } fn register_range(&self, sctx: Arc, airgroup_id: usize, air_id: usize, hint: u64) { @@ -252,15 +248,15 @@ impl StdRangeCheck { } } - pub fn drain_inputs(&self, _pctx: Arc>, _scope: Option<&Scope>) { + pub fn drain_inputs(&self, pctx: Arc>, sctx: Arc) { if let Some(u8air) = self.u8air.as_ref() { - u8air.drain_inputs(); + u8air.drain_inputs(pctx.clone(), sctx.clone()); } if let Some(u16air) = self.u16air.as_ref() { - u16air.drain_inputs(); + u16air.drain_inputs(pctx.clone(), sctx.clone()); } if let Some(specified_ranges) = self.specified_ranges.as_ref() { - specified_ranges.drain_inputs(); + specified_ranges.drain_inputs(pctx.clone(), sctx.clone()); } } diff --git a/pil2-components/lib/std/rs/src/range_check/u16air.rs b/pil2-components/lib/std/rs/src/range_check/u16air.rs index cdd452d2..abfad61c 100644 --- a/pil2-components/lib/std/rs/src/range_check/u16air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u16air.rs @@ -3,10 +3,12 @@ use std::sync::{atomic::AtomicU64, Arc, Mutex}; use num_traits::ToPrimitive; use p3_field::{Field, PrimeField}; -use proofman::{get_hint_field_gc, WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{TraceInfo, AirInstance, ProofCtx, SetupCtx}; -use proofman_hints::{get_hint_field, get_hint_ids_by_name, set_hint_field, HintFieldOptions, HintFieldValue}; +use proofman_hints::{ + get_hint_field_gc, get_hint_field, get_hint_ids_by_name, set_hint_field, HintFieldOptions, HintFieldValue, +}; use proofman_util::create_buffer_fast; use std::sync::atomic::Ordering; @@ -14,8 +16,6 @@ const PROVE_CHUNK_SIZE: usize = 1 << 5; const NUM_ROWS: usize = 1 << 16; pub struct U16Air { - wcm: Arc>, - // Parameters hint: AtomicU64, airgroup_id: usize, @@ -28,10 +28,7 @@ pub struct U16Air { impl U16Air { const MY_NAME: &'static str = "U16Air "; - pub fn new(wcm: Arc>) -> Arc { - let pctx = wcm.get_pctx(); - let sctx = wcm.get_sctx(); - + pub fn new(pctx: Arc>, sctx: Arc) -> Arc { // Scan global hints to get the airgroup_id and air_id let hint_global = get_hint_ids_by_name(sctx.get_global_bin(), "u16air"); let airgroup_id = get_hint_field_gc::(pctx.clone(), sctx.clone(), hint_global[0], "airgroup_id", false); @@ -57,18 +54,13 @@ impl U16Air { } }; - let u16air = Arc::new(Self { - wcm: wcm.clone(), + Arc::new(Self { hint: AtomicU64::new(0), airgroup_id, air_id, inputs: Mutex::new(Vec::new()), mul_column: Mutex::new(HintFieldValue::Field(F::zero())), - }); - - wcm.register_component(u16air.clone()); - - u16air + }) } pub fn update_inputs(&self, value: F, multiplicity: F) { @@ -84,10 +76,9 @@ impl U16Air { } } - pub fn drain_inputs(&self) { + pub fn drain_inputs(&self, pctx: Arc>, sctx: Arc) { let mut inputs = self.inputs.lock().unwrap(); let drained_inputs = inputs.drain(..).collect(); - let pctx = self.wcm.get_pctx(); // Perform the last update self.update_multiplicity(drained_inputs); @@ -106,7 +97,7 @@ impl U16Air { dctx.distribute_multiplicity(&mut multiplicity, owner); if is_mine { - let air_instance_repo = &self.wcm.get_pctx().air_instance_repo; + let air_instance_repo = &pctx.air_instance_repo; let instance: Vec = air_instance_repo.find_air_instances(self.airgroup_id, self.air_id); let air_instance_id = if !instance.is_empty() { air_instance_repo.find_air_instances(self.airgroup_id, self.air_id)[0] @@ -127,13 +118,7 @@ impl U16Air { let mul_column_2 = HintFieldValue::Column(multiplicity.iter().map(|x| F::from_canonical_u64(*x)).collect::>()); - set_hint_field( - &self.wcm.get_sctx(), - air_instance, - self.hint.load(Ordering::Acquire), - "reference", - &mul_column_2, - ); + set_hint_field(&sctx, air_instance, self.hint.load(Ordering::Acquire), "reference", &mul_column_2); log::trace!("{}: ··· Drained inputs for AIR '{}'", Self::MY_NAME, "U16Air"); } @@ -179,7 +164,7 @@ impl WitnessComponent for U16Air { let mut air_instance = AirInstance::new(TraceInfo::new(self.airgroup_id, self.air_id, buffer)); *self.mul_column.lock().unwrap() = get_hint_field::( - &self.wcm.get_sctx(), + &sctx, &pctx, &mut air_instance, u16air_hints[0] as usize, diff --git a/pil2-components/lib/std/rs/src/range_check/u8air.rs b/pil2-components/lib/std/rs/src/range_check/u8air.rs index 8cd50693..fb3b4f9d 100644 --- a/pil2-components/lib/std/rs/src/range_check/u8air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u8air.rs @@ -2,9 +2,11 @@ use std::sync::{atomic::AtomicU64, Arc, Mutex}; use num_traits::ToPrimitive; use p3_field::{Field, PrimeField}; -use proofman::{get_hint_field_gc, WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{TraceInfo, AirInstance, ProofCtx, SetupCtx}; -use proofman_hints::{get_hint_field, get_hint_ids_by_name, set_hint_field, HintFieldOptions, HintFieldValue}; +use proofman_hints::{ + get_hint_field_gc, get_hint_field, get_hint_ids_by_name, set_hint_field, HintFieldOptions, HintFieldValue, +}; use proofman_util::create_buffer_fast; use std::sync::atomic::Ordering; @@ -12,8 +14,6 @@ const PROVE_CHUNK_SIZE: usize = 1 << 5; const NUM_ROWS: usize = 1 << 8; pub struct U8Air { - wcm: Arc>, - // Parameters hint: AtomicU64, airgroup_id: usize, @@ -27,10 +27,7 @@ pub struct U8Air { impl U8Air { const MY_NAME: &'static str = "U8Air "; - pub fn new(wcm: Arc>) -> Arc { - let pctx = wcm.get_pctx(); - let sctx = wcm.get_sctx(); - + pub fn new(pctx: Arc>, sctx: Arc) -> Arc { // Scan global hints to get the airgroup_id and air_id let hint_global = get_hint_ids_by_name(sctx.get_global_bin(), "u8air"); let airgroup_id = get_hint_field_gc::(pctx.clone(), sctx.clone(), hint_global[0], "airgroup_id", false); @@ -56,18 +53,13 @@ impl U8Air { } }; - let u8air = Arc::new(Self { - wcm: wcm.clone(), + Arc::new(Self { hint: AtomicU64::new(0), airgroup_id, air_id, inputs: Mutex::new(Vec::new()), mul_column: Mutex::new(HintFieldValue::Field(F::zero())), - }); - - wcm.register_component(u8air.clone()); - - u8air + }) } pub fn update_inputs(&self, value: F, multiplicity: F) { @@ -83,10 +75,9 @@ impl U8Air { } } - pub fn drain_inputs(&self) { + pub fn drain_inputs(&self, pctx: Arc>, sctx: Arc) { let mut inputs = self.inputs.lock().unwrap(); let drained_inputs = inputs.drain(..).collect(); - let pctx = self.wcm.get_pctx(); // Perform the last update self.update_multiplicity(drained_inputs); @@ -105,7 +96,7 @@ impl U8Air { dctx.distribute_multiplicity(&mut multiplicity, owner); if is_mine { - let air_instance_repo = &self.wcm.get_pctx().air_instance_repo; + let air_instance_repo = &pctx.air_instance_repo; let instance: Vec = air_instance_repo.find_air_instances(self.airgroup_id, self.air_id); let air_instance_id = if !instance.is_empty() { air_instance_repo.find_air_instances(self.airgroup_id, self.air_id)[0] @@ -125,13 +116,7 @@ impl U8Air { let mul_column_2 = HintFieldValue::Column(multiplicity.iter().map(|x| F::from_canonical_u64(*x)).collect::>()); - set_hint_field( - &self.wcm.get_sctx(), - air_instance, - self.hint.load(Ordering::Acquire), - "reference", - &mul_column_2, - ); + set_hint_field(&sctx, air_instance, self.hint.load(Ordering::Acquire), "reference", &mul_column_2); log::trace!("{}: ··· Drained inputs for AIR '{}'", Self::MY_NAME, "U8Air"); } diff --git a/pil2-components/lib/std/rs/src/std.rs b/pil2-components/lib/std/rs/src/std.rs index db0ddc7e..54ce027e 100644 --- a/pil2-components/lib/std/rs/src/std.rs +++ b/pil2-components/lib/std/rs/src/std.rs @@ -5,41 +5,58 @@ use std::sync::{ use num_bigint::BigInt; use p3_field::PrimeField; -use rayon::Scope; -use proofman::WitnessManager; -use proofman_common::ProofCtx; +use witness::WitnessManager; use crate::{StdProd, StdRangeCheck, RangeCheckAir, StdSum}; pub struct Std { - range_check: Arc>, + pub wcm: Arc>, + pub range_check: Arc>, range_check_predecessors: AtomicU32, + pub std_prod: Arc>, + pub std_sum: Arc>, } impl Std { const MY_NAME: &'static str = "STD "; pub fn new(wcm: Arc>) -> Arc { - let mode = wcm.get_pctx().options.std_mode.clone(); - - log::info!("{}: ··· The PIL2 STD library has been initialized on mode {}", Self::MY_NAME, mode.name); + let std_mode = wcm.get_pctx().options.std_mode.clone(); + log::info!("{}: ··· The PIL2 STD library has been initialized on mode {}", Self::MY_NAME, std_mode.name); // Instantiate the STD components - let _ = StdProd::new(mode.clone(), wcm.clone()); - let _ = StdSum::new(mode.clone(), wcm.clone()); - let range_check = StdRangeCheck::new(mode, wcm); + let std_prod = StdProd::new(std_mode.clone()); + let std_sum = StdSum::new(std_mode.clone()); + let range_check = StdRangeCheck::new(std_mode.clone(), wcm.get_pctx(), wcm.get_sctx()); + + wcm.register_component(std_prod.clone()); + wcm.register_component(std_sum.clone()); + + if range_check.u8air.is_some() { + wcm.register_component(range_check.u8air.clone().unwrap()); + } + + if range_check.u16air.is_some() { + wcm.register_component(range_check.u16air.clone().unwrap()); + } + + if range_check.specified_ranges.is_some() { + wcm.register_component(range_check.specified_ranges.clone().unwrap()); + } + + wcm.register_component(range_check.clone()); - Arc::new(Self { range_check, range_check_predecessors: AtomicU32::new(0) }) + Arc::new(Self { wcm, range_check, range_check_predecessors: AtomicU32::new(0), std_prod, std_sum }) } pub fn register_predecessor(&self) { self.range_check_predecessors.fetch_add(1, Ordering::SeqCst); } - pub fn unregister_predecessor(&self, pctx: Arc>, scope: Option<&Scope>) { + pub fn unregister_predecessor(&self) { if self.range_check_predecessors.fetch_sub(1, Ordering::SeqCst) == 1 { - self.range_check.drain_inputs(pctx, scope); + self.range_check.drain_inputs(self.wcm.get_pctx(), self.wcm.get_sctx()); } } @@ -60,13 +77,17 @@ impl Std { pub fn drain_inputs(&self, rc_type: &RangeCheckAir) { match rc_type { RangeCheckAir::U8Air => { - self.range_check.u8air.as_ref().unwrap().drain_inputs(); + self.range_check.u8air.as_ref().unwrap().drain_inputs(self.wcm.get_pctx(), self.wcm.get_sctx()); } RangeCheckAir::U16Air => { - self.range_check.u16air.as_ref().unwrap().drain_inputs(); + self.range_check.u16air.as_ref().unwrap().drain_inputs(self.wcm.get_pctx(), self.wcm.get_sctx()); } RangeCheckAir::SpecifiedRanges => { - self.range_check.specified_ranges.as_ref().unwrap().drain_inputs(); + self.range_check + .specified_ranges + .as_ref() + .unwrap() + .drain_inputs(self.wcm.get_pctx(), self.wcm.get_sctx()); } }; } diff --git a/pil2-components/lib/std/rs/src/std_prod.rs b/pil2-components/lib/std/rs/src/std_prod.rs index 2f3aeb49..87082fe6 100644 --- a/pil2-components/lib/std/rs/src/std_prod.rs +++ b/pil2-components/lib/std/rs/src/std_prod.rs @@ -6,7 +6,7 @@ use std::{ use num_traits::ToPrimitive; use p3_field::PrimeField; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{AirInstance, ModeName, ProofCtx, SetupCtx, StdMode}; use proofman_hints::{ get_hint_field, get_hint_field_a, get_hint_field_constant, get_hint_field_constant_a, get_hint_ids_by_name, @@ -44,16 +44,12 @@ impl Decider for StdProd { impl StdProd { const MY_NAME: &'static str = "STD Prod"; - pub fn new(mode: StdMode, wcm: Arc>) -> Arc { - let std_prod = Arc::new(Self { + pub fn new(mode: StdMode) -> Arc { + Arc::new(Self { mode: mode.clone(), prod_airs: Mutex::new(Vec::new()), debug_data: if mode.name == ModeName::Debug { Some(Mutex::new(HashMap::new())) } else { None }, - }); - - wcm.register_component(std_prod.clone()); - - std_prod + }) } fn debug( diff --git a/pil2-components/lib/std/rs/src/std_sum.rs b/pil2-components/lib/std/rs/src/std_sum.rs index 927bc0f4..3a61a3f5 100644 --- a/pil2-components/lib/std/rs/src/std_sum.rs +++ b/pil2-components/lib/std/rs/src/std_sum.rs @@ -6,7 +6,7 @@ use std::{ use num_traits::ToPrimitive; use p3_field::PrimeField; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{AirInstance, ProofCtx, SetupCtx, StdMode, ModeName}; use proofman_hints::{ get_hint_field, get_hint_field_a, get_hint_field_constant, get_hint_field_constant_a, acc_mul_hint_fields, @@ -46,16 +46,12 @@ impl Decider for StdSum { impl StdSum { const MY_NAME: &'static str = "STD Sum "; - pub fn new(mode: StdMode, wcm: Arc>) -> Arc { - let std_sum = Arc::new(Self { + pub fn new(mode: StdMode) -> Arc { + Arc::new(Self { mode: mode.clone(), sum_airs: Mutex::new(Vec::new()), debug_data: if mode.name == ModeName::Debug { Some(Mutex::new(HashMap::new())) } else { None }, - }); - - wcm.register_component(std_sum.clone()); - - std_sum + }) } fn debug( diff --git a/pil2-components/test/simple/rs/Cargo.toml b/pil2-components/test/simple/rs/Cargo.toml index 2c452ac5..a202ebeb 100644 --- a/pil2-components/test/simple/rs/Cargo.toml +++ b/pil2-components/test/simple/rs/Cargo.toml @@ -12,6 +12,7 @@ proofman-common.workspace = true proofman-macros.workspace = true proofman-cli.workspace = true pilout.workspace = true +witness.workspace = true pil-std-lib = { path = "../../../lib/std/rs" } env_logger.workspace = true diff --git a/pil2-components/test/simple/rs/src/simple_left.rs b/pil2-components/test/simple/rs/src/simple_left.rs index 9e912c08..1859df80 100644 --- a/pil2-components/test/simple/rs/src/simple_left.rs +++ b/pil2-components/test/simple/rs/src/simple_left.rs @@ -1,32 +1,28 @@ use std::sync::Arc; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; -use p3_field::PrimeField; +use p3_field::PrimeField64; use rand::{distributions::Standard, prelude::Distribution, seq::SliceRandom}; use crate::SimpleLeftTrace; -pub struct SimpleLeft { - _phantom: std::marker::PhantomData, -} +pub struct SimpleLeft; -impl SimpleLeft -where - Standard: Distribution, -{ +impl SimpleLeft { const MY_NAME: &'static str = "SimLeft "; - pub fn new(wcm: Arc>) -> Arc { - let simple_left = Arc::new(Self { _phantom: std::marker::PhantomData }); - - wcm.register_component(simple_left.clone()); - - simple_left + pub fn new() -> Arc { + Arc::new(Self) } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for SimpleLeft +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = SimpleLeftTrace::new(); @@ -60,5 +56,3 @@ where add_air_instance::(air_instance, pctx.clone()); } } - -impl WitnessComponent for SimpleLeft where Standard: Distribution {} diff --git a/pil2-components/test/simple/rs/src/simple_lib.rs b/pil2-components/test/simple/rs/src/simple_lib.rs index bc35edfc..c1df9db5 100644 --- a/pil2-components/test/simple/rs/src/simple_lib.rs +++ b/pil2-components/test/simple/rs/src/simple_lib.rs @@ -1,85 +1,25 @@ -use std::{error::Error, path::PathBuf, sync::Arc}; - +use std::sync::Arc; use pil_std_lib::Std; -use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; +use witness::{witness_library, WitnessLibrary, WitnessManager}; -use p3_field::PrimeField; +use p3_field::PrimeField64; use p3_goldilocks::Goldilocks; use rand::{distributions::Standard, prelude::Distribution}; use crate::{SimpleLeft, SimpleRight}; -pub struct SimpleWitness { - pub wcm: Option>>, - pub simple_left: Option>>, - pub simple_right: Option>>, - pub std_lib: Option>>, -} - -impl Default for SimpleWitness -where - Standard: Distribution, -{ - fn default() -> Self { - Self::new() - } -} - -impl SimpleWitness -where - Standard: Distribution, -{ - pub fn new() -> Self { - Self { wcm: None, simple_left: None, simple_right: None, std_lib: None } - } - - pub fn initialize(&mut self, pctx: Arc>, sctx: Arc) { - let wcm = Arc::new(WitnessManager::new(pctx, sctx)); - - let std_lib = Std::new(wcm.clone()); - let simple_left = SimpleLeft::new(wcm.clone()); - let simple_right = SimpleRight::new(wcm.clone()); +witness_library!(WitnessLib, Goldilocks); - self.wcm = Some(wcm); - self.std_lib = Some(std_lib); - self.simple_left = Some(simple_left); - self.simple_right = Some(simple_right); - } -} - -impl WitnessLibrary for SimpleWitness +impl WitnessLibrary for WitnessLib where Standard: Distribution, { - fn start_proof(&mut self, pctx: Arc>, sctx: Arc) { - self.initialize(pctx.clone(), sctx.clone()); - - self.wcm.as_ref().unwrap().start_proof(pctx, sctx); - } + fn register_witness(&mut self, wcm: Arc>) { + Std::new(wcm.clone()); + let simple_left = SimpleLeft::new(); + let simple_right = SimpleRight::new(); - fn end_proof(&mut self) { - self.wcm.as_ref().unwrap().end_proof(); + wcm.register_component(simple_left.clone()); + wcm.register_component(simple_right.clone()); } - - fn execute(&self, pctx: Arc>) { - // Execute those components that need to be executed - self.simple_left.as_ref().unwrap().execute(pctx.clone()); - self.simple_right.as_ref().unwrap().execute(pctx); - } - - fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { - self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, sctx); - } -} - -#[no_mangle] -pub extern "Rust" fn init_library( - _: Option, - _: Option, - verbose_mode: VerboseMode, -) -> Result>, Box> { - initialize_logger(verbose_mode); - let simple_witness = SimpleWitness::new(); - Ok(Box::new(simple_witness)) } diff --git a/pil2-components/test/simple/rs/src/simple_right.rs b/pil2-components/test/simple/rs/src/simple_right.rs index efe02efd..e66c2434 100644 --- a/pil2-components/test/simple/rs/src/simple_right.rs +++ b/pil2-components/test/simple/rs/src/simple_right.rs @@ -1,32 +1,28 @@ use std::sync::Arc; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; -use p3_field::PrimeField; +use p3_field::PrimeField64; use rand::{distributions::Standard, prelude::Distribution}; use crate::SimpleRightTrace; -pub struct SimpleRight { - _phantom: std::marker::PhantomData, -} +pub struct SimpleRight; -impl SimpleRight -where - Standard: Distribution, -{ +impl SimpleRight { const MY_NAME: &'static str = "SimRight"; - pub fn new(wcm: Arc>) -> Arc { - let simple_right = Arc::new(Self { _phantom: std::marker::PhantomData }); - - wcm.register_component(simple_right.clone()); - - simple_right + pub fn new() -> Arc { + Arc::new(Self) } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for SimpleRight +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut trace = SimpleRightTrace::new(); let num_rows = trace.num_rows(); @@ -47,5 +43,3 @@ where add_air_instance::(air_instance, pctx.clone()); } } - -impl WitnessComponent for SimpleRight where Standard: Distribution {} diff --git a/pil2-components/test/std/connection/rs/Cargo.toml b/pil2-components/test/std/connection/rs/Cargo.toml index 901af7a4..35c23887 100644 --- a/pil2-components/test/std/connection/rs/Cargo.toml +++ b/pil2-components/test/std/connection/rs/Cargo.toml @@ -11,6 +11,7 @@ proofman.workspace = true proofman-common.workspace = true proofman-macros.workspace = true proofman-cli.workspace = true +witness.workspace = true pil-std-lib = { path = "../../../../lib/std/rs" } env_logger.workspace = true diff --git a/pil2-components/test/std/connection/rs/src/connection1.rs b/pil2-components/test/std/connection/rs/src/connection1.rs index e9af7ccc..a566a7b5 100644 --- a/pil2-components/test/std/connection/rs/src/connection1.rs +++ b/pil2-components/test/std/connection/rs/src/connection1.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; @@ -8,25 +8,22 @@ use rand::{distributions::Standard, prelude::Distribution, Rng}; use crate::Connection1Trace; -pub struct Connection1 { - _phantom: std::marker::PhantomData, -} +pub struct Connection1; -impl Connection1 -where - Standard: Distribution, +impl Connection1 { const MY_NAME: &'static str = "Connct_1"; - pub fn new(wcm: Arc>) -> Arc { - let connection1 = Arc::new(Self { _phantom: std::marker::PhantomData }); - - wcm.register_component(connection1.clone()); - - connection1 + pub fn new() -> Arc { + Arc::new(Self) } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for Connection1 +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = Connection1Trace::new_zeroes(); @@ -44,5 +41,3 @@ where add_air_instance::(air_instance, pctx.clone()); } } - -impl WitnessComponent for Connection1 where Standard: Distribution {} diff --git a/pil2-components/test/std/connection/rs/src/connection2.rs b/pil2-components/test/std/connection/rs/src/connection2.rs index 16562914..bd3785e1 100644 --- a/pil2-components/test/std/connection/rs/src/connection2.rs +++ b/pil2-components/test/std/connection/rs/src/connection2.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; @@ -8,25 +8,22 @@ use rand::{distributions::Standard, prelude::Distribution, Rng}; use crate::Connection2Trace; -pub struct Connection2 { - _phantom: std::marker::PhantomData, -} +pub struct Connection2; -impl Connection2 -where - Standard: Distribution, +impl Connection2 { const MY_NAME: &'static str = "Connct_2"; - pub fn new(wcm: Arc>) -> Arc { - let connection2 = Arc::new(Self { _phantom: std::marker::PhantomData }); - - wcm.register_component(connection2.clone()); - - connection2 + pub fn new() -> Arc { + Arc::new(Self) } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for Connection2 +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = Connection2Trace::new_zeroes(); @@ -46,5 +43,3 @@ where add_air_instance::(air_instance, pctx.clone()); } } - -impl WitnessComponent for Connection2 where Standard: Distribution {} diff --git a/pil2-components/test/std/connection/rs/src/connection_lib.rs b/pil2-components/test/std/connection/rs/src/connection_lib.rs index 631cda91..cd88f982 100644 --- a/pil2-components/test/std/connection/rs/src/connection_lib.rs +++ b/pil2-components/test/std/connection/rs/src/connection_lib.rs @@ -1,8 +1,7 @@ -use std::{error::Error, path::PathBuf, sync::Arc}; +use std::sync::Arc; use pil_std_lib::Std; -use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; +use witness::{witness_library, WitnessLibrary, WitnessManager}; use p3_field::PrimeField; use p3_goldilocks::Goldilocks; @@ -10,105 +9,20 @@ use rand::{distributions::Standard, prelude::Distribution}; use crate::{Connection1, Connection2, ConnectionNew}; -pub struct ConnectionWitness { - pub wcm: Option>>, - pub connection1: Option>>, - pub connection2: Option>>, - pub connection_new: Option>>, - pub std_lib: Option>>, -} - -impl Default for ConnectionWitness -where - Standard: Distribution, -{ - fn default() -> Self { - Self::new() - } -} - -impl ConnectionWitness -where - Standard: Distribution, -{ - pub fn new() -> Self { - ConnectionWitness { wcm: None, connection1: None, connection2: None, connection_new: None, std_lib: None } - } - - pub fn initialize(&mut self, pctx: Arc>, sctx: Arc) { - let wcm = Arc::new(WitnessManager::new(pctx, sctx)); - - let std_lib = Std::new(wcm.clone()); - let connection1 = Connection1::new(wcm.clone()); - let connection2 = Connection2::new(wcm.clone()); - let connection_new = ConnectionNew::new(wcm.clone()); - - self.wcm = Some(wcm); - self.connection1 = Some(connection1); - self.connection2 = Some(connection2); - self.connection_new = Some(connection_new); - self.std_lib = Some(std_lib); - } -} +witness_library!(WitnessLib, Goldilocks); -impl WitnessLibrary for ConnectionWitness +impl WitnessLibrary for WitnessLib where Standard: Distribution, { - fn start_proof(&mut self, pctx: Arc>, sctx: Arc) { - self.initialize(pctx.clone(), sctx.clone()); - - self.wcm.as_ref().unwrap().start_proof(pctx, sctx); - } - - fn end_proof(&mut self) { - self.wcm.as_ref().unwrap().end_proof(); - } - - fn execute(&self, pctx: Arc>) { - // Execute those components that need to be executed - self.connection1.as_ref().unwrap().execute(pctx.clone()); - self.connection2.as_ref().unwrap().execute(pctx.clone()); - self.connection_new.as_ref().unwrap().execute(pctx); + fn register_witness(&mut self, wcm: Arc>) { + Std::new(wcm.clone()); + let connection1 = Connection1::new(); + let connection2 = Connection2::new(); + let connection_new = ConnectionNew::new(); + + wcm.register_component(connection1.clone()); + wcm.register_component(connection2.clone()); + wcm.register_component(connection_new.clone()); } - - fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { - self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, sctx); - } -} - -#[no_mangle] -pub extern "Rust" fn init_library( - _: Option, - _: Option, - verbose_mode: VerboseMode, -) -> Result>, Box> { - initialize_logger(verbose_mode); - let connection_witness: ConnectionWitness = ConnectionWitness::new(); - Ok(Box::new(connection_witness)) } - -// #[cfg(test)] -// mod tests { -// use proofman_cli::commands::verify_constraints::{Field, VerifyConstraintsCmd}; - -// #[test] -// fn test_verify_constraints() { -// let root_path = std::env::current_dir().expect("Failed to get current directory").join("../../../../"); -// let root_path = std::fs::canonicalize(root_path).expect("Failed to canonicalize root path"); - -// let verify_constraints = VerifyConstraintsCmd { -// witness_lib: root_path.join("target/debug/libconnection.so"), -// rom: None, -// public_inputs: None, -// proving_key: root_path.join("test/std/connection/build/provingKey"), -// field: Field::Goldilocks, -// verbose: 0, -// }; - -// if let Err(e) = verify_constraints.run() { -// eprintln!("Failed to verify constraints: {:?}", e); -// std::process::exit(1); -// } -// } -// } diff --git a/pil2-components/test/std/connection/rs/src/connection_new.rs b/pil2-components/test/std/connection/rs/src/connection_new.rs index 18ad98d6..c9792fd4 100644 --- a/pil2-components/test/std/connection/rs/src/connection_new.rs +++ b/pil2-components/test/std/connection/rs/src/connection_new.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; @@ -8,25 +8,22 @@ use rand::{distributions::Standard, prelude::Distribution, Rng}; use crate::ConnectionNewTrace; -pub struct ConnectionNew { - _phantom: std::marker::PhantomData, -} +pub struct ConnectionNew; -impl ConnectionNew -where - Standard: Distribution, +impl ConnectionNew { const MY_NAME: &'static str = "Connct_N"; - pub fn new(wcm: Arc>) -> Arc { - let connection_new = Arc::new(Self { _phantom: std::marker::PhantomData }); - - wcm.register_component(connection_new.clone()); - - connection_new + pub fn new() -> Arc { + Arc::new(Self) } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for ConnectionNew +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = ConnectionNewTrace::new_zeroes(); let num_rows = trace.num_rows(); @@ -137,5 +134,3 @@ where add_air_instance::(air_instance, pctx.clone()); } } - -impl WitnessComponent for ConnectionNew where Standard: Distribution {} diff --git a/pil2-components/test/std/lookup/rs/Cargo.toml b/pil2-components/test/std/lookup/rs/Cargo.toml index e944886c..ee7be23a 100644 --- a/pil2-components/test/std/lookup/rs/Cargo.toml +++ b/pil2-components/test/std/lookup/rs/Cargo.toml @@ -11,6 +11,7 @@ proofman.workspace = true proofman-common.workspace = true proofman-macros.workspace = true proofman-cli.workspace = true +witness.workspace = true pil-std-lib = { path = "../../../../lib/std/rs" } env_logger.workspace = true diff --git a/pil2-components/test/std/lookup/rs/src/lookup0.rs b/pil2-components/test/std/lookup/rs/src/lookup0.rs index 4f6626d4..493e74ae 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup0.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup0.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; @@ -8,28 +8,24 @@ use rand::{distributions::Standard, prelude::Distribution, Rng}; use crate::Lookup0Trace; -pub struct Lookup0 { - _phantom: std::marker::PhantomData, +pub struct Lookup0; + +impl Lookup0 { + const MY_NAME: &'static str = "Lookup_0"; + + pub fn new() -> Arc { + Arc::new(Self) + } } -impl Lookup0 +impl WitnessComponent for Lookup0 where Standard: Distribution, { - const MY_NAME: &'static str = "Lookup0"; - - pub fn new(wcm: Arc>) -> Arc { - let lookup0 = Arc::new(Self { _phantom: std::marker::PhantomData }); - - wcm.register_component(lookup0.clone()); - - lookup0 - } - - pub fn execute(&self, pctx: Arc>) { + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); - let mut trace = Lookup0Trace::new(); + let mut trace = Lookup0Trace::new_zeroes(); let num_rows = trace.num_rows(); log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); @@ -57,5 +53,3 @@ where add_air_instance::(air_instance, pctx.clone()); } } - -impl WitnessComponent for Lookup0 where Standard: Distribution {} diff --git a/pil2-components/test/std/lookup/rs/src/lookup1.rs b/pil2-components/test/std/lookup/rs/src/lookup1.rs index fbcb650d..19a08962 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup1.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup1.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; @@ -8,25 +8,21 @@ use rand::{distributions::Standard, prelude::Distribution, Rng}; use crate::Lookup1Trace; -pub struct Lookup1 { - _phantom: std::marker::PhantomData, -} +pub struct Lookup1; -impl Lookup1 -where - Standard: Distribution, -{ +impl Lookup1 { const MY_NAME: &'static str = "Lookup_1"; - pub fn new(wcm: Arc>) -> Arc { - let lookup1 = Arc::new(Self { _phantom: std::marker::PhantomData }); - - wcm.register_component(lookup1.clone()); - - lookup1 + pub fn new() -> Arc { + Arc::new(Self) } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for Lookup1 +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = Lookup1Trace::new(); @@ -55,5 +51,3 @@ where add_air_instance::(air_instance, pctx.clone()); } } - -impl WitnessComponent for Lookup1 where Standard: Distribution {} diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs index ad434ddb..66c5d5af 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_12.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_12.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; @@ -8,25 +8,21 @@ use rand::{distributions::Standard, prelude::Distribution, Rng}; use crate::Lookup2_12Trace; -pub struct Lookup2_12 { - _phantom: std::marker::PhantomData, -} +pub struct Lookup2_12; -impl Lookup2_12 -where - Standard: Distribution, -{ +impl Lookup2_12 { const MY_NAME: &'static str = "Lkup2_12"; - pub fn new(wcm: Arc>) -> Arc { - let lookup2_12 = Arc::new(Self { _phantom: std::marker::PhantomData }); - - wcm.register_component(lookup2_12.clone()); - - lookup2_12 + pub fn new() -> Arc { + Arc::new(Self) } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for Lookup2_12 +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = Lookup2_12Trace::new(); @@ -67,5 +63,3 @@ where add_air_instance::(air_instance, pctx.clone()); } } - -impl WitnessComponent for Lookup2_12 where Standard: Distribution {} diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs index 399a520c..7cfb8aab 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_13.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_13.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; @@ -8,25 +8,21 @@ use rand::{distributions::Standard, prelude::Distribution, Rng}; use crate::Lookup2_13Trace; -pub struct Lookup2_13 { - _phantom: std::marker::PhantomData, -} +pub struct Lookup2_13; -impl Lookup2_13 -where - Standard: Distribution, -{ +impl Lookup2_13 { const MY_NAME: &'static str = "Lkup2_13"; - pub fn new(wcm: Arc>) -> Arc { - let lookup2_13 = Arc::new(Self { _phantom: std::marker::PhantomData }); - - wcm.register_component(lookup2_13.clone()); - - lookup2_13 + pub fn new() -> Arc { + Arc::new(Self) } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for Lookup2_13 +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = Lookup2_13Trace::new(); @@ -67,5 +63,3 @@ where add_air_instance::(air_instance, pctx.clone()); } } - -impl WitnessComponent for Lookup2_13 where Standard: Distribution {} diff --git a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs index 152dbc91..20f22cf1 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup2_15.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup2_15.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; @@ -8,25 +8,21 @@ use rand::{distributions::Standard, prelude::Distribution, Rng}; use crate::Lookup2_15Trace; -pub struct Lookup2_15 { - _phantom: std::marker::PhantomData, -} +pub struct Lookup2_15; -impl Lookup2_15 -where - Standard: Distribution, -{ +impl Lookup2_15 { const MY_NAME: &'static str = "Lkup2_15"; - pub fn new(wcm: Arc>) -> Arc { - let lookup2_15 = Arc::new(Self { _phantom: std::marker::PhantomData }); - - wcm.register_component(lookup2_15.clone()); - - lookup2_15 + pub fn new() -> Arc { + Arc::new(Self) } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for Lookup2_15 +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = Lookup2_15Trace::new(); @@ -67,5 +63,3 @@ where add_air_instance::(air_instance, pctx.clone()); } } - -impl WitnessComponent for Lookup2_15 where Standard: Distribution {} diff --git a/pil2-components/test/std/lookup/rs/src/lookup3.rs b/pil2-components/test/std/lookup/rs/src/lookup3.rs index 0ca96c1a..813abee8 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup3.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup3.rs @@ -1,28 +1,28 @@ use std::sync::Arc; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; +use rand::{distributions::Standard, prelude::Distribution}; use p3_field::PrimeField; use crate::Lookup3Trace; -pub struct Lookup3 { - _phantom: std::marker::PhantomData, -} +pub struct Lookup3; -impl Lookup3 { +impl Lookup3 { const MY_NAME: &'static str = "Lookup_3"; - pub fn new(wcm: Arc>) -> Arc { - let lookup3 = Arc::new(Self { _phantom: std::marker::PhantomData }); - - wcm.register_component(lookup3.clone()); - - lookup3 + pub fn new() -> Arc { + Arc::new(Self) } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for Lookup3 +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { // For simplicity, add a single instance of each air let mut trace = Lookup3Trace::new(); let num_rows = trace.num_rows(); @@ -55,5 +55,3 @@ impl Lookup3 { add_air_instance::(air_instance, pctx.clone()); } } - -impl WitnessComponent for Lookup3 {} diff --git a/pil2-components/test/std/lookup/rs/src/lookup_lib.rs b/pil2-components/test/std/lookup/rs/src/lookup_lib.rs index 77a389b9..a3dc27e6 100644 --- a/pil2-components/test/std/lookup/rs/src/lookup_lib.rs +++ b/pil2-components/test/std/lookup/rs/src/lookup_lib.rs @@ -1,8 +1,7 @@ -use std::{error::Error, path::PathBuf, sync::Arc}; +use std::sync::Arc; use pil_std_lib::Std; -use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; +use witness::{witness_library, WitnessLibrary, WitnessManager}; use p3_field::PrimeField; use p3_goldilocks::Goldilocks; @@ -10,126 +9,26 @@ use rand::{distributions::Standard, prelude::Distribution}; use crate::{Lookup0, Lookup1, Lookup2_12, Lookup2_13, Lookup2_15, Lookup3}; -pub struct LookupWitness { - pub wcm: Option>>, - pub lookup0: Option>>, - pub lookup1: Option>>, - pub lookup2_12: Option>>, - pub lookup2_13: Option>>, - pub lookup2_15: Option>>, - pub lookup3: Option>>, - pub std_lib: Option>>, -} - -impl Default for LookupWitness -where - Standard: Distribution, -{ - fn default() -> Self { - Self::new() - } -} - -impl LookupWitness -where - Standard: Distribution, -{ - pub fn new() -> Self { - LookupWitness { - wcm: None, - lookup0: None, - lookup1: None, - lookup2_12: None, - lookup2_13: None, - lookup2_15: None, - lookup3: None, - std_lib: None, - } - } - - pub fn initialize(&mut self, pctx: Arc>, sctx: Arc) { - let wcm = Arc::new(WitnessManager::new(pctx, sctx)); - - let std_lib = Std::new(wcm.clone()); - let lookup0 = Lookup0::new(wcm.clone()); - let lookup1 = Lookup1::new(wcm.clone()); - let lookup2_12 = Lookup2_12::new(wcm.clone()); - let lookup2_13 = Lookup2_13::new(wcm.clone()); - let lookup2_15 = Lookup2_15::new(wcm.clone()); - let lookup3 = Lookup3::new(wcm.clone()); - - self.wcm = Some(wcm); - self.lookup0 = Some(lookup0); - self.lookup1 = Some(lookup1); - self.lookup2_12 = Some(lookup2_12); - self.lookup2_13 = Some(lookup2_13); - self.lookup2_15 = Some(lookup2_15); - self.lookup3 = Some(lookup3); - self.std_lib = Some(std_lib); - } -} +witness_library!(WitnessLib, Goldilocks); -impl WitnessLibrary for LookupWitness +impl WitnessLibrary for WitnessLib where Standard: Distribution, { - fn start_proof(&mut self, pctx: Arc>, sctx: Arc) { - self.initialize(pctx.clone(), sctx.clone()); - - self.wcm.as_ref().unwrap().start_proof(pctx, sctx); - } - - fn end_proof(&mut self) { - self.wcm.as_ref().unwrap().end_proof(); - } - - fn execute(&self, pctx: Arc>) { - // Execute those components that need to be executed - self.lookup0.as_ref().unwrap().execute(pctx.clone()); - self.lookup1.as_ref().unwrap().execute(pctx.clone()); - self.lookup2_12.as_ref().unwrap().execute(pctx.clone()); - self.lookup2_13.as_ref().unwrap().execute(pctx.clone()); - self.lookup2_15.as_ref().unwrap().execute(pctx.clone()); - self.lookup3.as_ref().unwrap().execute(pctx.clone()); + fn register_witness(&mut self, wcm: Arc>) { + Std::new(wcm.clone()); + let lookup0 = Lookup0::new(); + let lookup1 = Lookup1::new(); + let lookup2_12 = Lookup2_12::new(); + let lookup2_13 = Lookup2_13::new(); + let lookup2_15 = Lookup2_15::new(); + let lookup3 = Lookup3::new(); + + wcm.register_component(lookup0.clone()); + wcm.register_component(lookup1.clone()); + wcm.register_component(lookup2_12.clone()); + wcm.register_component(lookup2_13.clone()); + wcm.register_component(lookup2_15.clone()); + wcm.register_component(lookup3.clone()); } - - fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { - self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, sctx); - } -} - -#[no_mangle] -pub extern "Rust" fn init_library( - _: Option, - _: Option, - verbose_mode: VerboseMode, -) -> Result>, Box> { - initialize_logger(verbose_mode); - let lookup_witness = LookupWitness::new(); - Ok(Box::new(lookup_witness)) } - -// #[cfg(test)] -// mod tests { -// use proofman_cli::commands::verify_constraints::{Field, VerifyConstraintsCmd}; - -// #[test] -// fn test_verify_constraints() { -// let root_path = std::env::current_dir().expect("Failed to get current directory").join("../../../../"); -// let root_path = std::fs::canonicalize(root_path).expect("Failed to canonicalize root path"); - -// let verify_constraints = VerifyConstraintsCmd { -// witness_lib: root_path.join("target/debug/liblookup.so"), -// rom: None, -// public_inputs: None, -// proving_key: root_path.join("test/std/lookup/build/provingKey"), -// field: Field::Goldilocks, -// verbose: 0, -// }; - -// if let Err(e) = verify_constraints.run() { -// eprintln!("Failed to verify constraints: {:?}", e); -// std::process::exit(1); -// } -// } -// } diff --git a/pil2-components/test/std/permutation/rs/Cargo.toml b/pil2-components/test/std/permutation/rs/Cargo.toml index 0737b660..14065161 100644 --- a/pil2-components/test/std/permutation/rs/Cargo.toml +++ b/pil2-components/test/std/permutation/rs/Cargo.toml @@ -11,6 +11,7 @@ proofman.workspace = true proofman-common.workspace = true proofman-macros.workspace = true proofman-cli.workspace = true +witness.workspace = true pil-std-lib = { path = "../../../../lib/std/rs" } env_logger.workspace = true diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs index cc9ca40a..cc1f76f7 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_6.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_6.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; @@ -8,25 +8,20 @@ use rand::{distributions::Standard, prelude::Distribution, seq::SliceRandom, Rng use crate::Permutation1_6Trace; -pub struct Permutation1_6 { - _phantom: std::marker::PhantomData, -} +pub struct Permutation1_6; -impl Permutation1_6 -where - Standard: Distribution, -{ +impl Permutation1_6 { const MY_NAME: &'static str = "Perm1_6 "; - pub fn new(wcm: Arc>) -> Arc { - let permutation1_6 = Arc::new(Self { _phantom: std::marker::PhantomData }); - - wcm.register_component(permutation1_6.clone()); - - permutation1_6 + pub fn new() -> Arc { + Arc::new(Self) } - - pub fn execute(&self, pctx: Arc>) { +} +impl WitnessComponent for Permutation1_6 +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = Permutation1_6Trace::new(); @@ -112,5 +107,3 @@ where add_air_instance::(air_instance2, pctx.clone()); } } - -impl WitnessComponent for Permutation1_6 where Standard: Distribution {} diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs index 3be65439..943e12fd 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_7.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_7.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; @@ -8,25 +8,21 @@ use rand::{distributions::Standard, prelude::Distribution, Rng}; use crate::Permutation1_7Trace; -pub struct Permutation1_7 { - _phantom: std::marker::PhantomData, -} +pub struct Permutation1_7; -impl Permutation1_7 -where - Standard: Distribution, -{ +impl Permutation1_7 { const MY_NAME: &'static str = "Perm1_7 "; - pub fn new(wcm: Arc>) -> Arc { - let permutation1_7 = Arc::new(Self { _phantom: std::marker::PhantomData }); - - wcm.register_component(permutation1_7.clone()); - - permutation1_7 + pub fn new() -> Arc { + Arc::new(Self) } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for Permutation1_7 +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = Permutation1_7Trace::new(); let num_rows = trace.num_rows(); @@ -74,5 +70,3 @@ where add_air_instance::(air_instance, pctx.clone()); } } - -impl WitnessComponent for Permutation1_7 where Standard: Distribution {} diff --git a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs index 86744c29..b948bf9a 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation1_8.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation1_8.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; @@ -8,25 +8,21 @@ use rand::{distributions::Standard, prelude::Distribution, Rng}; use crate::Permutation1_8Trace; -pub struct Permutation1_8 { - _phantom: std::marker::PhantomData, -} +pub struct Permutation1_8; -impl Permutation1_8 -where - Standard: Distribution, -{ +impl Permutation1_8 { const MY_NAME: &'static str = "Perm1_8 "; - pub fn new(wcm: Arc>) -> Arc { - let permutation1_8 = Arc::new(Self { _phantom: std::marker::PhantomData }); - - wcm.register_component(permutation1_8.clone()); - - permutation1_8 + pub fn new() -> Arc { + Arc::new(Self) } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for Permutation1_8 +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = Permutation1_8Trace::new(); let num_rows = trace.num_rows(); @@ -74,5 +70,3 @@ where add_air_instance::(air_instance, pctx.clone()); } } - -impl WitnessComponent for Permutation1_8 where Standard: Distribution {} diff --git a/pil2-components/test/std/permutation/rs/src/permutation2.rs b/pil2-components/test/std/permutation/rs/src/permutation2.rs index 60366547..66182dd6 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation2.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation2.rs @@ -1,28 +1,24 @@ use std::sync::Arc; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use p3_field::PrimeField; use crate::Permutation2_6Trace; -pub struct Permutation2 { - _phantom: std::marker::PhantomData, -} +pub struct Permutation2; -impl Permutation2 { +impl Permutation2 { const MY_NAME: &'static str = "Perm2 "; - pub fn new(wcm: Arc>) -> Arc { - let permutation2 = Arc::new(Self { _phantom: std::marker::PhantomData }); - - wcm.register_component(permutation2.clone()); - - permutation2 + pub fn new() -> Arc { + Arc::new(Self) } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for Permutation2 { + fn execute(&self, pctx: Arc>) { let mut trace = Permutation2_6Trace::new(); let num_rows = trace.num_rows(); @@ -46,5 +42,3 @@ impl Permutation2 { add_air_instance::(air_instance, pctx.clone()); } } - -impl WitnessComponent for Permutation2 {} diff --git a/pil2-components/test/std/permutation/rs/src/permutation_lib.rs b/pil2-components/test/std/permutation/rs/src/permutation_lib.rs index 62161cf1..813af882 100644 --- a/pil2-components/test/std/permutation/rs/src/permutation_lib.rs +++ b/pil2-components/test/std/permutation/rs/src/permutation_lib.rs @@ -1,8 +1,7 @@ -use std::{error::Error, path::PathBuf, sync::Arc}; +use std::sync::Arc; use pil_std_lib::Std; -use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; +use witness::{witness_library, WitnessLibrary, WitnessManager}; use p3_field::PrimeField; use p3_goldilocks::Goldilocks; @@ -10,116 +9,17 @@ use rand::{distributions::Standard, prelude::Distribution}; use crate::{Permutation1_6, Permutation1_7, Permutation1_8, Permutation2}; -pub struct PermutationWitness { - pub wcm: Option>>, - pub permutation1_6: Option>>, - pub permutation1_7: Option>>, - pub permutation1_8: Option>>, - pub permutation2: Option>>, - pub std_lib: Option>>, -} - -impl Default for PermutationWitness -where - Standard: Distribution, -{ - fn default() -> Self { - Self::new() - } -} - -impl PermutationWitness -where - Standard: Distribution, -{ - pub fn new() -> Self { - PermutationWitness { - wcm: None, - permutation1_6: None, - permutation1_7: None, - permutation1_8: None, - permutation2: None, - std_lib: None, - } - } - - pub fn initialize(&mut self, pctx: Arc>, sctx: Arc) { - let wcm = Arc::new(WitnessManager::new(pctx, sctx)); - - let std_lib = Std::new(wcm.clone()); - let permutation1_6 = Permutation1_6::new(wcm.clone()); - let permutation1_7 = Permutation1_7::new(wcm.clone()); - let permutation1_8 = Permutation1_8::new(wcm.clone()); - let permutation2 = Permutation2::new(wcm.clone()); - - self.wcm = Some(wcm); - self.permutation1_6 = Some(permutation1_6); - self.permutation1_7 = Some(permutation1_7); - self.permutation1_8 = Some(permutation1_8); - self.permutation2 = Some(permutation2); - self.std_lib = Some(std_lib); - } -} +witness_library!(WitnessLib, Goldilocks); -impl WitnessLibrary for PermutationWitness +impl WitnessLibrary for WitnessLib where Standard: Distribution, { - fn start_proof(&mut self, pctx: Arc>, sctx: Arc) { - self.initialize(pctx.clone(), sctx.clone()); - - self.wcm.as_ref().unwrap().start_proof(pctx, sctx); - } - - fn end_proof(&mut self) { - self.wcm.as_ref().unwrap().end_proof(); - } - - fn execute(&self, pctx: Arc>) { - // Execute those components that need to be executed - self.permutation1_6.as_ref().unwrap().execute(pctx.clone()); - self.permutation1_7.as_ref().unwrap().execute(pctx.clone()); - self.permutation1_8.as_ref().unwrap().execute(pctx.clone()); - self.permutation2.as_ref().unwrap().execute(pctx); + fn register_witness(&mut self, wcm: Arc>) { + Std::new(wcm.clone()); + wcm.register_component(Permutation1_6::new()); + wcm.register_component(Permutation1_7::new()); + wcm.register_component(Permutation1_8::new()); + wcm.register_component(Permutation2::new()); } - - fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { - self.wcm.as_ref().unwrap().calculate_witness(stage, pctx, sctx); - } -} - -#[no_mangle] -pub extern "Rust" fn init_library( - _: Option, - _: Option, - verbose_mode: VerboseMode, -) -> Result>, Box> { - initialize_logger(verbose_mode); - let permutation_witness = PermutationWitness::new(); - Ok(Box::new(permutation_witness)) } - -// #[cfg(test)] -// mod tests { -// use proofman_cli::commands::verify_constraints::{Field, VerifyConstraintsCmd}; - -// #[test] -// fn test_verify_constraints() { -// let root_path = std::env::current_dir().expect("Failed to get current directory").join("../../../../"); -// let root_path = std::fs::canonicalize(root_path).expect("Failed to canonicalize root path"); - -// let verify_constraints = VerifyConstraintsCmd { -// witness_lib: root_path.join("target/debug/libpermutation.so"), -// rom: None, -// public_inputs: None, -// proving_key: root_path.join("test/std/permutation/build/provingKey"), -// field: Field::Goldilocks, -// verbose: 0, -// }; - -// if let Err(e) = verify_constraints.run() { -// eprintln!("Failed to verify constraints: {:?}", e); -// std::process::exit(1); -// } -// } -// } diff --git a/pil2-components/test/std/range_check/rs/Cargo.toml b/pil2-components/test/std/range_check/rs/Cargo.toml index 795f9bae..7e64129e 100644 --- a/pil2-components/test/std/range_check/rs/Cargo.toml +++ b/pil2-components/test/std/range_check/rs/Cargo.toml @@ -11,6 +11,7 @@ proofman.workspace = true proofman-common.workspace = true proofman-macros.workspace = true proofman-cli.workspace = true +witness.workspace = true pil-std-lib = { path = "../../../../lib/std/rs" } env_logger.workspace = true diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs index 70559e09..b571d4f3 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs @@ -1,7 +1,8 @@ use std::sync::Arc; use pil_std_lib::Std; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; + use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use num_bigint::BigInt; @@ -20,18 +21,21 @@ where { const MY_NAME: &'static str = "MtRngCh1"; - pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { + pub fn new(std_lib: Arc>) -> Arc { let multi_range_check1 = Arc::new(Self { std_lib }); - wcm.register_component(multi_range_check1.clone()); - // Register dependency relations multi_range_check1.std_lib.register_predecessor(); multi_range_check1 } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for MultiRangeCheck1 +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = MultiRangeCheck1Trace::new_zeroes(); @@ -100,8 +104,6 @@ where let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - self.std_lib.unregister_predecessor(pctx, None); + self.std_lib.unregister_predecessor(); } } - -impl WitnessComponent for MultiRangeCheck1 where Standard: Distribution {} diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs index 62b4b072..c2e7004b 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs @@ -1,7 +1,8 @@ use std::sync::Arc; use pil_std_lib::Std; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; + use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use num_bigint::BigInt; @@ -20,18 +21,21 @@ where { const MY_NAME: &'static str = "MtRngCh2"; - pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { + pub fn new(std_lib: Arc>) -> Arc { let multi_range_check2 = Arc::new(Self { std_lib }); - wcm.register_component(multi_range_check2.clone()); - // Register dependency relations multi_range_check2.std_lib.register_predecessor(); multi_range_check2 } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for MultiRangeCheck2 +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = MultiRangeCheck2Trace::new_zeroes(); @@ -82,8 +86,6 @@ where let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - self.std_lib.unregister_predecessor(pctx, None); + self.std_lib.unregister_predecessor(); } } - -impl WitnessComponent for MultiRangeCheck2 where Standard: Distribution {} diff --git a/pil2-components/test/std/range_check/rs/src/range_check1.rs b/pil2-components/test/std/range_check/rs/src/range_check1.rs index 6463c2c6..691407f5 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check1.rs @@ -1,7 +1,8 @@ use std::sync::Arc; use pil_std_lib::Std; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; + use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use num_bigint::BigInt; @@ -20,18 +21,21 @@ where { const MY_NAME: &'static str = "RngChck1"; - pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { + pub fn new(std_lib: Arc>) -> Arc { let range_check1 = Arc::new(Self { std_lib }); - wcm.register_component(range_check1.clone()); - // Register dependency relations range_check1.std_lib.register_predecessor(); range_check1 } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for RangeCheck1 +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck1Trace::new_zeroes(); @@ -79,8 +83,6 @@ where let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - self.std_lib.unregister_predecessor(pctx, None); + self.std_lib.unregister_predecessor(); } } - -impl WitnessComponent for RangeCheck1 where Standard: Distribution {} diff --git a/pil2-components/test/std/range_check/rs/src/range_check2.rs b/pil2-components/test/std/range_check/rs/src/range_check2.rs index 03a9e055..3e0c066e 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check2.rs @@ -1,7 +1,8 @@ use std::sync::Arc; use pil_std_lib::Std; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; + use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use num_bigint::BigInt; @@ -20,18 +21,21 @@ where { const MY_NAME: &'static str = "RngChck2"; - pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { + pub fn new(std_lib: Arc>) -> Arc { let range_check2 = Arc::new(Self { std_lib }); - wcm.register_component(range_check2.clone()); - // Register dependency relations range_check2.std_lib.register_predecessor(); range_check2 } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for RangeCheck2 +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck2Trace::new_zeroes(); let num_rows = trace.num_rows(); @@ -54,8 +58,6 @@ where let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - self.std_lib.unregister_predecessor(pctx, None); + self.std_lib.unregister_predecessor(); } } - -impl WitnessComponent for RangeCheck2 where Standard: Distribution {} diff --git a/pil2-components/test/std/range_check/rs/src/range_check3.rs b/pil2-components/test/std/range_check/rs/src/range_check3.rs index ab80545c..7a8b72cd 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check3.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check3.rs @@ -1,7 +1,8 @@ use std::sync::Arc; use pil_std_lib::Std; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; + use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use num_bigint::BigInt; @@ -20,18 +21,21 @@ where { const MY_NAME: &'static str = "RngChck3"; - pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { + pub fn new(std_lib: Arc>) -> Arc { let range_check3 = Arc::new(Self { std_lib }); - wcm.register_component(range_check3.clone()); - // Register dependency relations range_check3.std_lib.register_predecessor(); range_check3 } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for RangeCheck3 +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck3Trace::new_zeroes(); @@ -52,8 +56,6 @@ where let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - self.std_lib.unregister_predecessor(pctx, None); + self.std_lib.unregister_predecessor(); } } - -impl WitnessComponent for RangeCheck3 where Standard: Distribution {} diff --git a/pil2-components/test/std/range_check/rs/src/range_check4.rs b/pil2-components/test/std/range_check/rs/src/range_check4.rs index 35e8eb4b..0b851f74 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check4.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check4.rs @@ -1,7 +1,8 @@ use std::sync::Arc; use pil_std_lib::Std; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; + use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use num_bigint::BigInt; @@ -21,18 +22,21 @@ where { const MY_NAME: &'static str = "RngChck4"; - pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { + pub fn new(std_lib: Arc>) -> Arc { let range_check4 = Arc::new(Self { std_lib }); - wcm.register_component(range_check4.clone()); - // Register dependency relations range_check4.std_lib.register_predecessor(); range_check4 } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for RangeCheck4 +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = RangeCheck4Trace::new_zeroes(); @@ -100,8 +104,6 @@ where let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - self.std_lib.unregister_predecessor(pctx, None); + self.std_lib.unregister_predecessor(); } } - -impl WitnessComponent for RangeCheck4 where Standard: Distribution {} diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs index 4a195074..56036e41 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs @@ -1,7 +1,8 @@ use std::sync::Arc; use pil_std_lib::Std; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; + use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use num_bigint::BigInt; @@ -20,18 +21,21 @@ where { const MY_NAME: &'static str = "RngChDy1"; - pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { + pub fn new(std_lib: Arc>) -> Arc { let range_check_dynamic1 = Arc::new(Self { std_lib }); - wcm.register_component(range_check_dynamic1.clone()); - // Register dependency relations range_check_dynamic1.std_lib.register_predecessor(); range_check_dynamic1 } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for RangeCheckDynamic1 +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = RangeCheckDynamic1Trace::new_zeroes(); @@ -78,8 +82,6 @@ where let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - self.std_lib.unregister_predecessor(pctx, None); + self.std_lib.unregister_predecessor(); } } - -impl WitnessComponent for RangeCheckDynamic1 where Standard: Distribution {} diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs index 60035a4a..a40f6db5 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs @@ -1,7 +1,8 @@ use std::sync::Arc; use pil_std_lib::Std; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; + use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use num_bigint::BigInt; @@ -21,18 +22,21 @@ where { const MY_NAME: &'static str = "RngChDy2"; - pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { + pub fn new(std_lib: Arc>) -> Arc { let range_check_dynamic2 = Arc::new(Self { std_lib }); - wcm.register_component(range_check_dynamic2.clone()); - // Register dependency relations range_check_dynamic2.std_lib.register_predecessor(); range_check_dynamic2 } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for RangeCheckDynamic2 +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = RangeCheckDynamic2Trace::new_zeroes(); @@ -91,8 +95,6 @@ where let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - self.std_lib.unregister_predecessor(pctx, None); + self.std_lib.unregister_predecessor(); } } - -impl WitnessComponent for RangeCheckDynamic2 where Standard: Distribution {} diff --git a/pil2-components/test/std/range_check/rs/src/range_check_lib.rs b/pil2-components/test/std/range_check/rs/src/range_check_lib.rs index bd154aeb..8d5e0550 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_lib.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_lib.rs @@ -1,8 +1,7 @@ -use std::{cell::OnceCell, error::Error, path::PathBuf, sync::Arc}; +use std::sync::Arc; use pil_std_lib::Std; -use proofman::{WitnessLibrary, WitnessManager}; -use proofman_common::{initialize_logger, ProofCtx, SetupCtx, VerboseMode}; +use witness::{witness_library, WitnessLibrary, WitnessManager}; use p3_field::PrimeField; use p3_goldilocks::Goldilocks; @@ -13,141 +12,32 @@ use crate::{ RangeCheck2, RangeCheck3, RangeCheck4, }; -pub struct RangeCheckWitness { - pub wcm: OnceCell>>, - pub range_check1: OnceCell>>, - pub range_check2: OnceCell>>, - pub range_check3: OnceCell>>, - pub range_check4: OnceCell>>, - pub multi_range_check1: OnceCell>>, - pub multi_range_check2: OnceCell>>, - pub range_check_dynamic1: OnceCell>>, - pub range_check_dynamic2: OnceCell>>, - pub range_check_mix: OnceCell>>, - pub std_lib: OnceCell>>, -} - -impl Default for RangeCheckWitness -where - Standard: Distribution, -{ - fn default() -> Self { - Self::new() - } -} +witness_library!(WitnessLib, Goldilocks); -impl RangeCheckWitness +impl WitnessLibrary for WitnessLib where Standard: Distribution, { - pub fn new() -> Self { - RangeCheckWitness { - wcm: OnceCell::new(), - range_check1: OnceCell::new(), - range_check2: OnceCell::new(), - range_check3: OnceCell::new(), - range_check4: OnceCell::new(), - multi_range_check1: OnceCell::new(), - multi_range_check2: OnceCell::new(), - range_check_dynamic1: OnceCell::new(), - range_check_dynamic2: OnceCell::new(), - range_check_mix: OnceCell::new(), - std_lib: OnceCell::new(), - } - } - - fn initialize(&self, pctx: Arc>, sctx: Arc) { - let wcm = Arc::new(WitnessManager::new(pctx, sctx)); - + fn register_witness(&mut self, wcm: Arc>) { let std_lib = Std::new(wcm.clone()); - let range_check1 = RangeCheck1::new(wcm.clone(), std_lib.clone()); - let range_check2 = RangeCheck2::new(wcm.clone(), std_lib.clone()); - let range_check3 = RangeCheck3::new(wcm.clone(), std_lib.clone()); - let range_check4 = RangeCheck4::new(wcm.clone(), std_lib.clone()); - let multi_range_check1 = MultiRangeCheck1::new(wcm.clone(), std_lib.clone()); - let multi_range_check2 = MultiRangeCheck2::new(wcm.clone(), std_lib.clone()); - let range_check_dynamic1 = RangeCheckDynamic1::new(wcm.clone(), std_lib.clone()); - let range_check_dynamic2 = RangeCheckDynamic2::new(wcm.clone(), std_lib.clone()); - let range_check_mix = RangeCheckMix::new(wcm.clone(), std_lib.clone()); - - let _ = self.wcm.set(wcm); - let _ = self.range_check1.set(range_check1); - let _ = self.range_check2.set(range_check2); - let _ = self.range_check3.set(range_check3); - let _ = self.range_check4.set(range_check4); - let _ = self.multi_range_check1.set(multi_range_check1); - let _ = self.multi_range_check2.set(multi_range_check2); - let _ = self.range_check_dynamic1.set(range_check_dynamic1); - let _ = self.range_check_dynamic2.set(range_check_dynamic2); - let _ = self.range_check_mix.set(range_check_mix); - let _ = self.std_lib.set(std_lib); - } -} - -impl WitnessLibrary for RangeCheckWitness -where - Standard: Distribution, -{ - fn start_proof(&mut self, pctx: Arc>, sctx: Arc) { - self.initialize(pctx.clone(), sctx.clone()); - - self.wcm.get().unwrap().start_proof(pctx, sctx); - } - - fn end_proof(&mut self) { - self.wcm.get().unwrap().end_proof(); - } - - fn execute(&self, pctx: Arc>) { - // Execute those components that need to be executed - self.range_check1.get().unwrap().execute(pctx.clone()); - self.range_check2.get().unwrap().execute(pctx.clone()); - self.range_check3.get().unwrap().execute(pctx.clone()); - self.range_check4.get().unwrap().execute(pctx.clone()); - self.multi_range_check1.get().unwrap().execute(pctx.clone()); - self.multi_range_check2.get().unwrap().execute(pctx.clone()); - self.range_check_dynamic1.get().unwrap().execute(pctx.clone()); - self.range_check_dynamic2.get().unwrap().execute(pctx.clone()); - self.range_check_mix.get().unwrap().execute(pctx.clone()); + let range_check1 = RangeCheck1::new(std_lib.clone()); + let range_check2 = RangeCheck2::new(std_lib.clone()); + let range_check3 = RangeCheck3::new(std_lib.clone()); + let range_check4 = RangeCheck4::new(std_lib.clone()); + let multi_range_check1 = MultiRangeCheck1::new(std_lib.clone()); + let multi_range_check2 = MultiRangeCheck2::new(std_lib.clone()); + let range_check_dynamic1 = RangeCheckDynamic1::new(std_lib.clone()); + let range_check_dynamic2 = RangeCheckDynamic2::new(std_lib.clone()); + let range_check_mix = RangeCheckMix::new(std_lib.clone()); + + wcm.register_component(range_check1.clone()); + wcm.register_component(range_check2.clone()); + wcm.register_component(range_check3.clone()); + wcm.register_component(range_check4.clone()); + wcm.register_component(multi_range_check1.clone()); + wcm.register_component(multi_range_check2.clone()); + wcm.register_component(range_check_dynamic1.clone()); + wcm.register_component(range_check_dynamic2.clone()); + wcm.register_component(range_check_mix.clone()); } - - fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc) { - self.wcm.get().unwrap().calculate_witness(stage, pctx, sctx); - } -} - -#[no_mangle] -pub extern "Rust" fn init_library( - _: Option, - _: Option, - verbose_mode: VerboseMode, -) -> Result>, Box> { - initialize_logger(verbose_mode); - let range_check_witness = RangeCheckWitness::new(); - Ok(Box::new(range_check_witness)) } - -// #[cfg(test)] -// mod tests { -// use proofman_cli::commands::verify_constraints::{Field, VerifyConstraintsCmd}; - -// #[test] -// fn test_verify_constraints() { -// let root_path = std::env::current_dir().expect("Failed to get current directory").join("../../../../"); -// let root_path = std::fs::canonicalize(root_path).expect("Failed to canonicalize root path"); - -// let verify_constraints = VerifyConstraintsCmd { -// witness_lib: root_path.join("target/debug/librange_check.so"), -// rom: None, -// public_inputs: None, -// proving_key: root_path.join("test/std/range_check/build/provingKey"), -// field: Field::Goldilocks, -// verbose: 0, -// }; - -// if let Err(e) = verify_constraints.run() { -// eprintln!("Failed to verify constraints: {:?}", e); -// std::process::exit(1); -// } -// } -// } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs index 5f68d27a..b4579160 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs @@ -1,7 +1,8 @@ use std::sync::Arc; use pil_std_lib::Std; -use proofman::{WitnessComponent, WitnessManager}; +use witness::WitnessComponent; + use proofman_common::{add_air_instance, FromTrace, AirInstance, ProofCtx}; use num_bigint::BigInt; @@ -21,18 +22,21 @@ where { const MY_NAME: &'static str = "RngChMix"; - pub fn new(wcm: Arc>, std_lib: Arc>) -> Arc { + pub fn new(std_lib: Arc>) -> Arc { let range_check_mix = Arc::new(Self { std_lib }); - wcm.register_component(range_check_mix.clone()); - // Register dependency relations range_check_mix.std_lib.register_predecessor(); range_check_mix } +} - pub fn execute(&self, pctx: Arc>) { +impl WitnessComponent for RangeCheckMix +where + Standard: Distribution, +{ + fn execute(&self, pctx: Arc>) { let mut rng = rand::thread_rng(); let mut trace = RangeCheckMixTrace::new_zeroes(); @@ -132,8 +136,6 @@ where let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - self.std_lib.unregister_predecessor(pctx, None); + self.std_lib.unregister_predecessor(); } } - -impl WitnessComponent for RangeCheckMix where Standard: Distribution {} diff --git a/proofman/Cargo.toml b/proofman/Cargo.toml index 77335cdc..bef10e04 100644 --- a/proofman/Cargo.toml +++ b/proofman/Cargo.toml @@ -11,6 +11,7 @@ pilout = { path = "../pilout" } stark = { path = "../provers/stark" } proofman-starks-lib-c = { path = "../provers/starks-lib-c" } transcript = { path = "../transcript" } +witness = { path = "../witness" } log.workspace = true env_logger.workspace = true diff --git a/proofman/src/constraints.rs b/proofman/src/constraints.rs index 89036d39..2f44da5a 100644 --- a/proofman/src/constraints.rs +++ b/proofman/src/constraints.rs @@ -1,27 +1,53 @@ use p3_field::Field; +use proofman_hints::aggregate_airgroupvals; +use proofman_starks_lib_c::verify_global_constraints_c; use std::cmp; use std::sync::Arc; -use crate::{verify_global_constraints_proof, WitnessLibrary}; - -use proofman_common::{ProofCtx, Prover, SetupCtx}; +use proofman_common::{GlobalConstraintInfo, GlobalConstraintsResults, ProofCtx, Prover, SetupCtx}; use colored::*; -pub fn verify_constraints_proof( +pub fn verify_global_constraints_proof( pctx: Arc>, + sctx: Arc, +) -> Vec { + const MY_NAME: &str = "GlCstVfy"; + + log::info!("{}: --> Checking global constraints", MY_NAME); + + let mut airgroupvalues = aggregate_airgroupvals(pctx.clone()); + + let mut airgroup_values_ptrs: Vec<*mut F> = airgroupvalues + .iter_mut() // Iterate mutably over the inner Vecs + .map(|inner_vec| inner_vec.as_mut_ptr()) // Get a raw pointer to each inner Vec + .collect(); + + let raw_ptr = verify_global_constraints_c( + sctx.get_global_bin(), + pctx.get_publics_ptr(), + pctx.get_challenges_ptr(), + pctx.get_proof_values_ptr(), + airgroup_values_ptrs.as_mut_ptr() as *mut *mut u8, + ); + unsafe { + let constraints_result = Box::from_raw(raw_ptr as *mut GlobalConstraintsResults); + std::slice::from_raw_parts(constraints_result.constraints_info, constraints_result.n_constraints as usize) + } + .to_vec() +} + +pub fn verify_constraints_proof( + pctx: Arc>, sctx: Arc, provers: &mut [Box>], - witness_lib: &mut Box>, ) -> Result<(), Box> { const MY_NAME: &str = "CstrVrfy"; log::info!("{}: --> Checking constraints", MY_NAME); - witness_lib.debug(pctx.clone()); - let mut constraints = Vec::new(); for prover in provers.iter() { let constraints_prover_info = prover.verify_constraints(sctx.clone(), pctx.clone()); diff --git a/proofman/src/lib.rs b/proofman/src/lib.rs index 6cd38850..bed412ee 100644 --- a/proofman/src/lib.rs +++ b/proofman/src/lib.rs @@ -1,15 +1,7 @@ mod proofman; -mod witness_component; -mod witness_library; -mod witness_manager; mod constraints; mod recursion; -mod global_constraints; pub use proofman::*; pub use constraints::*; -pub use global_constraints::*; pub use recursion::*; -pub use witness_component::*; -pub use witness_library::*; -pub use witness_manager::*; diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index d2dc6cc4..d5814d96 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -1,6 +1,6 @@ use libloading::{Library, Symbol}; use log::{info, trace}; -use p3_field::Field; +use p3_field::PrimeField; use stark::StarkProver; use proofman_starks_lib_c::{save_challenges_c, save_proof_values_c, save_publics_c}; use std::fs; @@ -12,11 +12,11 @@ use std::{collections::HashMap, path::PathBuf, sync::Arc}; use transcript::FFITranscript; -use crate::{WitnessLibInitFn, WitnessLibrary}; -use crate::verify_constraints_proof; +use witness::{WitnessLibInitFn, WitnessManager}; + use crate::{ - generate_vadcop_recursive1_proof, generate_vadcop_final_proof, generate_vadcop_recursive2_proof, - generate_recursivef_proof, generate_fflonk_snark_proof, + verify_constraints_proof, generate_vadcop_recursive1_proof, generate_vadcop_final_proof, + generate_vadcop_recursive2_proof, generate_recursivef_proof, generate_fflonk_snark_proof, }; use proofman_common::{ProofCtx, ProofOptions, ProofType, Prover, SetupCtx, SetupsVadcop}; @@ -31,7 +31,7 @@ pub struct ProofMan { _phantom: std::marker::PhantomData, } -impl ProofMan { +impl ProofMan { const MY_NAME: &'static str = "ProofMan"; pub fn generate_proof( @@ -55,20 +55,15 @@ impl ProofMan { options.verify_constraints, )?; - // Load the witness computation dynamic library - let library = unsafe { Library::new(&witness_lib_path)? }; - - let witness_lib: Symbol> = unsafe { library.get(b"init_library")? }; - - let mut witness_lib = witness_lib(rom_path, public_inputs_path, options.verbose_mode)?; - let pctx = Arc::new(ProofCtx::create_ctx(proving_key_path.clone(), options)); let setups = Arc::new(SetupsVadcop::new(&pctx.global_info, pctx.options.aggregation, pctx.options.final_snark)); let sctx: Arc = setups.sctx.clone(); - Self::initialize_witness(&mut witness_lib, pctx.clone(), sctx.clone()); - witness_lib.calculate_witness(1, pctx.clone(), sctx.clone()); + let wcm = Arc::new(WitnessManager::new(pctx.clone(), sctx.clone(), rom_path, public_inputs_path)); + + Self::initialize_witness(witness_lib_path, wcm.clone())?; + wcm.calculate_witness(1); let mut dctx = pctx.dctx.write().unwrap(); dctx.close(pctx.global_info.air_groups.len()); @@ -100,7 +95,7 @@ impl ProofMan { if stage != 1 { timer_start_debug!(CALCULATING_WITNESS); info!("{}: Calculating witness stage {}", Self::MY_NAME, stage); - witness_lib.calculate_witness(stage, pctx.clone(), sctx.clone()); + wcm.calculate_witness(stage); timer_stop_and_log_debug!(CALCULATING_WITNESS); } @@ -115,10 +110,10 @@ impl ProofMan { } } - witness_lib.end_proof(); + wcm.end_proof(); if pctx.options.verify_constraints { - return verify_constraints_proof(pctx.clone(), sctx.clone(), &mut provers, &mut witness_lib); + return verify_constraints_proof(pctx.clone(), sctx.clone(), &mut provers); } // Compute Quotient polynomial @@ -196,11 +191,23 @@ impl ProofMan { Ok(()) } - fn initialize_witness(witness_lib: &mut Box>, pctx: Arc>, sctx: Arc) { + fn initialize_witness( + witness_lib_path: PathBuf, + wcm: Arc>, + ) -> Result<(), Box> { timer_start_debug!(INITIALIZE_WITNESS); - witness_lib.start_proof(pctx.clone(), sctx.clone()); - witness_lib.execute(pctx.clone()); + // Load the witness computation dynamic library + let library = unsafe { Library::new(&witness_lib_path)? }; + + let witness_lib: Symbol> = unsafe { library.get(b"init_library")? }; + let mut witness_lib = witness_lib(wcm.get_pctx().options.verbose_mode)?; + witness_lib.register_witness(wcm.clone()); + + wcm.start_proof(); + wcm.execute(); + + let pctx = wcm.get_pctx(); // After the execution print the planned instances trace!("{}: --> Air instances: ", Self::MY_NAME); @@ -232,6 +239,7 @@ impl ProofMan { } } timer_stop_and_log_debug!(INITIALIZE_WITNESS); + Ok(()) } fn initialize_provers(sctx: Arc, provers: &mut Vec>>, pctx: Arc>) { diff --git a/proofman/src/witness_library.rs b/proofman/src/witness_library.rs deleted file mode 100644 index eb0eb631..00000000 --- a/proofman/src/witness_library.rs +++ /dev/null @@ -1,19 +0,0 @@ -use std::{error::Error, path::PathBuf, sync::Arc}; - -use proofman_common::{ProofCtx, SetupCtx, VerboseMode}; - -/// This is the type of the function that is used to load a witness library. -pub type WitnessLibInitFn = - fn(Option, Option, VerboseMode) -> Result>, Box>; - -pub trait WitnessLibrary { - fn start_proof(&mut self, pctx: Arc>, sctx: Arc); - - fn end_proof(&mut self); - - fn execute(&self, pctx: Arc>); - - fn calculate_witness(&mut self, stage: u32, pctx: Arc>, sctx: Arc); - - fn debug(&mut self, _pctx: Arc>) {} -} diff --git a/witness/Cargo.toml b/witness/Cargo.toml new file mode 100644 index 00000000..247a3f1d --- /dev/null +++ b/witness/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "witness" +version = "0.1.0" +edition = "2021" + +[dependencies] +proofman-common = { path = "../common" } +proofman-util = { path = "../util" } + +log.workspace = true +env_logger.workspace = true +p3-goldilocks.workspace = true +p3-field.workspace = true + +libloading = "0.8.4" +colored = "2" +mpi = { version = "0.8.0", optional = true } +serde_json = "1.0.68" + + +[features] +default = [] +no_lib_link = [] +distributed = [] diff --git a/witness/src/lib.rs b/witness/src/lib.rs new file mode 100644 index 00000000..b19d4b12 --- /dev/null +++ b/witness/src/lib.rs @@ -0,0 +1,7 @@ +mod witness_component; +mod witness_library; +mod witness_manager; + +pub use witness_component::*; +pub use witness_library::*; +pub use witness_manager::*; diff --git a/proofman/src/witness_component.rs b/witness/src/witness_component.rs similarity index 85% rename from proofman/src/witness_component.rs rename to witness/src/witness_component.rs index 19ab4a86..3d659878 100644 --- a/proofman/src/witness_component.rs +++ b/witness/src/witness_component.rs @@ -5,6 +5,8 @@ use proofman_common::{ProofCtx, SetupCtx}; pub trait WitnessComponent: Send + Sync { fn start_proof(&self, _pctx: Arc>, _sctx: Arc) {} + fn execute(&self, _pctx: Arc>) {} + fn calculate_witness(&self, _stage: u32, _pctx: Arc>, _sctx: Arc) {} fn end_proof(&self) {} diff --git a/witness/src/witness_library.rs b/witness/src/witness_library.rs new file mode 100644 index 00000000..a09fb226 --- /dev/null +++ b/witness/src/witness_library.rs @@ -0,0 +1,36 @@ +use std::{error::Error, sync::Arc}; + +use crate::WitnessManager; +use proofman_common::VerboseMode; + +/// This is the type of the function that is used to load a witness library. +pub type WitnessLibInitFn = fn(VerboseMode) -> Result>, Box>; + +pub trait WitnessLibrary { + fn register_witness(&mut self, wcm: Arc>); +} + +#[macro_export] +macro_rules! witness_library { + ($lib_name:ident, $field_type:ty) => { + // Define the struct + pub struct $lib_name; + + // Implement Default for the struct + impl Default for $lib_name { + fn default() -> Self { + $lib_name + } + } + + // Define the init_library function + #[no_mangle] + pub extern "Rust" fn init_library( + verbose_mode: proofman_common::VerboseMode, + ) -> Result>, Box> { + proofman_common::initialize_logger(verbose_mode); + + Ok(Box::new($lib_name::default())) + } + }; +} diff --git a/proofman/src/witness_manager.rs b/witness/src/witness_manager.rs similarity index 56% rename from proofman/src/witness_manager.rs rename to witness/src/witness_manager.rs index 30eebef7..fc13c345 100644 --- a/proofman/src/witness_manager.rs +++ b/witness/src/witness_manager.rs @@ -1,4 +1,5 @@ use std::sync::{Arc, RwLock}; +use std::path::PathBuf; use proofman_common::{ProofCtx, SetupCtx}; use proofman_util::{timer_start_debug, timer_stop_and_log_debug}; @@ -8,44 +9,59 @@ pub struct WitnessManager { components: RwLock>>>, pctx: Arc>, sctx: Arc, + rom_path: Option, + public_inputs_path: Option, } impl WitnessManager { const MY_NAME: &'static str = "WCMnager"; - pub fn new(pctx: Arc>, sctx: Arc) -> Self { - WitnessManager { components: RwLock::new(Vec::new()), pctx, sctx } + pub fn new( + pctx: Arc>, + sctx: Arc, + rom_path: Option, + public_inputs_path: Option, + ) -> Self { + WitnessManager { components: RwLock::new(Vec::new()), pctx, sctx, rom_path, public_inputs_path } } pub fn register_component(&self, component: Arc>) { self.components.write().unwrap().push(component); } - pub fn start_proof(&self, pctx: Arc>, sctx: Arc) { + pub fn start_proof(&self) { for component in self.components.read().unwrap().iter() { - component.start_proof(pctx.clone(), sctx.clone()); + component.start_proof(self.pctx.clone(), self.sctx.clone()); } } + pub fn execute(&self) { + timer_start_debug!(EXECUTE); + for component in self.components.read().unwrap().iter() { + component.execute(self.pctx.clone()); + } + timer_stop_and_log_debug!(EXECUTE); + } + pub fn end_proof(&self) { for component in self.components.read().unwrap().iter() { component.end_proof(); } } - pub fn calculate_witness(&self, stage: u32, pctx: Arc>, sctx: Arc) { + pub fn calculate_witness(&self, stage: u32) { log::info!( "{}: Calculating witness for stage {} / {}", Self::MY_NAME, stage, - pctx.global_info.n_challenges.len() + self.pctx.global_info.n_challenges.len() ); timer_start_debug!(CALCULATING_WITNESS); // Call one time all unused components for component in self.components.read().unwrap().iter() { - component.calculate_witness(stage, pctx.clone(), sctx.clone()); + component.calculate_witness(stage, self.pctx.clone(), self.sctx.clone()); } timer_stop_and_log_debug!(CALCULATING_WITNESS); @@ -58,4 +74,12 @@ impl WitnessManager { pub fn get_sctx(&self) -> Arc { self.sctx.clone() } + + pub fn get_rom_path(&self) -> Option { + self.rom_path.clone() + } + + pub fn get_public_inputs_path(&self) -> Option { + self.public_inputs_path.clone() + } } From c21166b075d6cbaf93cd8fe81820e35af66847a2 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 16 Dec 2024 13:03:25 +0000 Subject: [PATCH 43/64] Adding custom-commits common --- common/src/custom_commits.rs | 24 ++++++++++++++++++++++++ common/src/lib.rs | 2 ++ 2 files changed, 26 insertions(+) create mode 100644 common/src/custom_commits.rs diff --git a/common/src/custom_commits.rs b/common/src/custom_commits.rs new file mode 100644 index 00000000..471f300a --- /dev/null +++ b/common/src/custom_commits.rs @@ -0,0 +1,24 @@ +use proofman_starks_lib_c::{extend_and_merkelize_custom_commit_c, fri_proof_new_c, starks_new_c}; +use p3_goldilocks::Goldilocks; + +use crate::Setup; + +pub fn get_custom_commit_trace( + commit_id: u64, + step: u64, + setup: &Setup, + buffer: Vec, + buffer_ext: Vec, + buffer_str: &str, +) { + extend_and_merkelize_custom_commit_c( + starks_new_c((&setup.p_setup).into(), std::ptr::null_mut()), + commit_id, + step, + buffer.as_ptr() as *mut u8, + buffer_ext.as_ptr() as *mut u8, + fri_proof_new_c((&setup.p_setup).into()), + std::ptr::null_mut(), + buffer_str, + ); +} diff --git a/common/src/lib.rs b/common/src/lib.rs index cebcb031..8413bcde 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -13,6 +13,7 @@ pub mod trace; pub mod global_info; pub mod stark_info; pub mod utils; +pub mod custom_commits; pub use air_instance::*; pub use air_instances_repository::*; @@ -28,3 +29,4 @@ pub use std_mode::*; pub use publics::*; pub use utils::*; pub use distribution_ctx::*; +pub use custom_commits::*; From 96d872b431a38003c4c52d3858f8c318e4fc9e28 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 16 Dec 2024 18:48:06 +0000 Subject: [PATCH 44/64] Minor changes --- Cargo.lock | 19 +++++++++++ Cargo.toml | 2 +- examples/fibonacci-square/pil/fibonaccisq.pil | 4 +-- .../fibonacci-square/src/fibonacci_lib.rs | 1 + examples/fibonacci-square/src/module.rs | 9 +---- .../rs/src/range_check/specified_ranges.rs | 7 ++-- .../lib/std/rs/src/range_check/u16air.rs | 8 +++-- .../lib/std/rs/src/range_check/u8air.rs | 7 ++-- pil2-components/lib/std/rs/src/std.rs | 34 +++++++------------ .../range_check/rs/src/multi_range_check1.rs | 8 +---- .../range_check/rs/src/multi_range_check2.rs | 8 +---- .../std/range_check/rs/src/range_check1.rs | 8 +---- .../std/range_check/rs/src/range_check2.rs | 8 +---- .../std/range_check/rs/src/range_check3.rs | 8 +---- .../std/range_check/rs/src/range_check4.rs | 8 +---- .../rs/src/range_check_dynamic1.rs | 8 +---- .../rs/src/range_check_dynamic2.rs | 8 +---- .../std/range_check/rs/src/range_check_mix.rs | 8 +---- 18 files changed, 62 insertions(+), 101 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7aaed7dd..8c2f25ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -973,6 +973,25 @@ dependencies = [ "getrandom", ] +[[package]] +name = "range-check" +version = "0.1.0" +dependencies = [ + "env_logger", + "log", + "num-bigint", + "num-traits", + "p3-field", + "p3-goldilocks", + "pil-std-lib", + "proofman", + "proofman-cli", + "proofman-common", + "proofman-macros", + "rand", + "witness", +] + [[package]] name = "rayon" version = "1.10.0" diff --git a/Cargo.toml b/Cargo.toml index 45e188aa..8b21624f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ members = [ "witness", "util", "pil2-components/lib/std/rs", - # "pil2-components/test/std/range_check/rs", + "pil2-components/test/std/range_check/rs", # "pil2-components/test/std/lookup/rs", # "pil2-components/test/std/connection/rs", # "pil2-components/test/std/permutation/rs", diff --git a/examples/fibonacci-square/pil/fibonaccisq.pil b/examples/fibonacci-square/pil/fibonaccisq.pil index 0e37abf1..0fd75514 100644 --- a/examples/fibonacci-square/pil/fibonaccisq.pil +++ b/examples/fibonacci-square/pil/fibonaccisq.pil @@ -6,8 +6,8 @@ public in2; public out; public rom_root[4]; -proofval value1; -proofval value2; +proofval stage(1) value1; +proofval stage(1) value2; private function checkProofValues() { diff --git a/examples/fibonacci-square/src/fibonacci_lib.rs b/examples/fibonacci-square/src/fibonacci_lib.rs index d8cf0992..bb1ae552 100644 --- a/examples/fibonacci-square/src/fibonacci_lib.rs +++ b/examples/fibonacci-square/src/fibonacci_lib.rs @@ -18,6 +18,7 @@ impl WitnessLibrary for WitnessLib { wcm.register_component(fibonacci.clone()); wcm.register_component(module.clone()); + let public_inputs: BuildPublics = load_from_json(&wcm.get_public_inputs_path()); let mut publics = BuildPublicValues::from_vec_guard(wcm.get_pctx().get_publics()); diff --git a/examples/fibonacci-square/src/module.rs b/examples/fibonacci-square/src/module.rs index cff2594b..5809149e 100644 --- a/examples/fibonacci-square/src/module.rs +++ b/examples/fibonacci-square/src/module.rs @@ -17,12 +17,7 @@ impl Module< const MY_NAME: &'static str = "ModuleSM"; pub fn new(std_lib: Arc>) -> Arc { - let module = Arc::new(Module { inputs: Mutex::new(Vec::new()), std_lib }); - - // Register dependency relations - module.std_lib.register_predecessor(); - - module + Arc::new(Module { inputs: Mutex::new(Vec::new()), std_lib }) } pub fn calculate_module(&self, x: u64, module: u64) -> u64 { @@ -69,7 +64,5 @@ impl WitnessComponent for Module { let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - - self.std_lib.unregister_predecessor(); } } diff --git a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs index bb93732a..a29f6559 100644 --- a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs +++ b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs @@ -322,8 +322,11 @@ impl WitnessComponent for SpecifiedRanges { }; *self.num_rows.lock().unwrap() = num_rows.as_canonical_biguint().to_usize().unwrap(); + } - //pctx.air_instance_repo.add_air_instance(air_instance); - // note: there is room for simplification here + fn calculate_witness(&self, stage: u32, pctx: Arc>, sctx: Arc) { + if stage == 1 { + Self::drain_inputs(self, pctx, sctx); + } } } diff --git a/pil2-components/lib/std/rs/src/range_check/u16air.rs b/pil2-components/lib/std/rs/src/range_check/u16air.rs index abfad61c..c13f0ef9 100644 --- a/pil2-components/lib/std/rs/src/range_check/u16air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u16air.rs @@ -172,7 +172,11 @@ impl WitnessComponent for U16Air { HintFieldOptions::dest_with_zeros(), ); - //pctx.air_instance_repo.add_air_instance(air_instance); - //note: there is room for simplification here + } + + fn calculate_witness(&self, stage: u32, pctx: Arc>, sctx: Arc) { + if stage == 1 { + Self::drain_inputs(self, pctx, sctx); + } } } diff --git a/pil2-components/lib/std/rs/src/range_check/u8air.rs b/pil2-components/lib/std/rs/src/range_check/u8air.rs index fb3b4f9d..4e525bda 100644 --- a/pil2-components/lib/std/rs/src/range_check/u8air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u8air.rs @@ -168,8 +168,11 @@ impl WitnessComponent for U8Air { "reference", HintFieldOptions::dest_with_zeros(), ); + } - //pctx.air_instance_repo.add_air_instance(air_instance); - //note: there is room for simplification heres + fn calculate_witness(&self, stage: u32, pctx: Arc>, sctx: Arc) { + if stage == 1 { + Self::drain_inputs(self, pctx, sctx); + } } } diff --git a/pil2-components/lib/std/rs/src/std.rs b/pil2-components/lib/std/rs/src/std.rs index 54ce027e..babaaa80 100644 --- a/pil2-components/lib/std/rs/src/std.rs +++ b/pil2-components/lib/std/rs/src/std.rs @@ -1,19 +1,17 @@ -use std::sync::{ - atomic::{AtomicU32, Ordering}, - Arc, -}; +use std::sync::Arc; use num_bigint::BigInt; use p3_field::PrimeField; +use proofman_common::{ProofCtx, SetupCtx}; use witness::WitnessManager; use crate::{StdProd, StdRangeCheck, RangeCheckAir, StdSum}; pub struct Std { - pub wcm: Arc>, + pub pctx: Arc>, + pub sctx: Arc, pub range_check: Arc>, - range_check_predecessors: AtomicU32, pub std_prod: Arc>, pub std_sum: Arc>, } @@ -30,6 +28,12 @@ impl Std { let std_sum = StdSum::new(std_mode.clone()); let range_check = StdRangeCheck::new(std_mode.clone(), wcm.get_pctx(), wcm.get_sctx()); + Self::register_std(wcm.clone(), std_prod.clone(), std_sum.clone(), range_check.clone()); + + Arc::new(Self { pctx: wcm.get_pctx(), sctx: wcm.get_sctx(), range_check, std_prod, std_sum }) + } + + pub fn register_std(wcm: Arc>, std_prod: Arc>, std_sum: Arc>, range_check: Arc>) { wcm.register_component(std_prod.clone()); wcm.register_component(std_sum.clone()); @@ -46,18 +50,6 @@ impl Std { } wcm.register_component(range_check.clone()); - - Arc::new(Self { wcm, range_check, range_check_predecessors: AtomicU32::new(0), std_prod, std_sum }) - } - - pub fn register_predecessor(&self) { - self.range_check_predecessors.fetch_add(1, Ordering::SeqCst); - } - - pub fn unregister_predecessor(&self) { - if self.range_check_predecessors.fetch_sub(1, Ordering::SeqCst) == 1 { - self.range_check.drain_inputs(self.wcm.get_pctx(), self.wcm.get_sctx()); - } } /// Gets the range for the range check. @@ -77,17 +69,17 @@ impl Std { pub fn drain_inputs(&self, rc_type: &RangeCheckAir) { match rc_type { RangeCheckAir::U8Air => { - self.range_check.u8air.as_ref().unwrap().drain_inputs(self.wcm.get_pctx(), self.wcm.get_sctx()); + self.range_check.u8air.as_ref().unwrap().drain_inputs(self.pctx.clone(), self.sctx.clone()); } RangeCheckAir::U16Air => { - self.range_check.u16air.as_ref().unwrap().drain_inputs(self.wcm.get_pctx(), self.wcm.get_sctx()); + self.range_check.u16air.as_ref().unwrap().drain_inputs(self.pctx.clone(), self.sctx.clone()); } RangeCheckAir::SpecifiedRanges => { self.range_check .specified_ranges .as_ref() .unwrap() - .drain_inputs(self.wcm.get_pctx(), self.wcm.get_sctx()); + .drain_inputs(self.pctx.clone(), self.sctx.clone()); } }; } diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs index b571d4f3..50139d46 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check1.rs @@ -22,12 +22,7 @@ where const MY_NAME: &'static str = "MtRngCh1"; pub fn new(std_lib: Arc>) -> Arc { - let multi_range_check1 = Arc::new(Self { std_lib }); - - // Register dependency relations - multi_range_check1.std_lib.register_predecessor(); - - multi_range_check1 + Arc::new(Self { std_lib }) } } @@ -104,6 +99,5 @@ where let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - self.std_lib.unregister_predecessor(); } } diff --git a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs index c2e7004b..7c3cddf5 100644 --- a/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/multi_range_check2.rs @@ -22,12 +22,7 @@ where const MY_NAME: &'static str = "MtRngCh2"; pub fn new(std_lib: Arc>) -> Arc { - let multi_range_check2 = Arc::new(Self { std_lib }); - - // Register dependency relations - multi_range_check2.std_lib.register_predecessor(); - - multi_range_check2 + Arc::new(Self { std_lib }) } } @@ -86,6 +81,5 @@ where let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - self.std_lib.unregister_predecessor(); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check1.rs b/pil2-components/test/std/range_check/rs/src/range_check1.rs index 691407f5..ad9fee08 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check1.rs @@ -22,12 +22,7 @@ where const MY_NAME: &'static str = "RngChck1"; pub fn new(std_lib: Arc>) -> Arc { - let range_check1 = Arc::new(Self { std_lib }); - - // Register dependency relations - range_check1.std_lib.register_predecessor(); - - range_check1 + Arc::new(Self { std_lib }) } } @@ -83,6 +78,5 @@ where let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - self.std_lib.unregister_predecessor(); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check2.rs b/pil2-components/test/std/range_check/rs/src/range_check2.rs index 3e0c066e..b4f673b5 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check2.rs @@ -22,12 +22,7 @@ where const MY_NAME: &'static str = "RngChck2"; pub fn new(std_lib: Arc>) -> Arc { - let range_check2 = Arc::new(Self { std_lib }); - - // Register dependency relations - range_check2.std_lib.register_predecessor(); - - range_check2 + Arc::new(Self { std_lib }) } } @@ -58,6 +53,5 @@ where let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - self.std_lib.unregister_predecessor(); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check3.rs b/pil2-components/test/std/range_check/rs/src/range_check3.rs index 7a8b72cd..5d92f071 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check3.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check3.rs @@ -22,12 +22,7 @@ where const MY_NAME: &'static str = "RngChck3"; pub fn new(std_lib: Arc>) -> Arc { - let range_check3 = Arc::new(Self { std_lib }); - - // Register dependency relations - range_check3.std_lib.register_predecessor(); - - range_check3 + Arc::new(Self { std_lib }) } } @@ -56,6 +51,5 @@ where let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - self.std_lib.unregister_predecessor(); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check4.rs b/pil2-components/test/std/range_check/rs/src/range_check4.rs index 0b851f74..fc29b242 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check4.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check4.rs @@ -23,12 +23,7 @@ where const MY_NAME: &'static str = "RngChck4"; pub fn new(std_lib: Arc>) -> Arc { - let range_check4 = Arc::new(Self { std_lib }); - - // Register dependency relations - range_check4.std_lib.register_predecessor(); - - range_check4 + Arc::new(Self { std_lib }) } } @@ -104,6 +99,5 @@ where let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - self.std_lib.unregister_predecessor(); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs index 56036e41..82c6eea2 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic1.rs @@ -22,12 +22,7 @@ where const MY_NAME: &'static str = "RngChDy1"; pub fn new(std_lib: Arc>) -> Arc { - let range_check_dynamic1 = Arc::new(Self { std_lib }); - - // Register dependency relations - range_check_dynamic1.std_lib.register_predecessor(); - - range_check_dynamic1 + Arc::new(Self { std_lib }) } } @@ -82,6 +77,5 @@ where let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - self.std_lib.unregister_predecessor(); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs index a40f6db5..2eed62e0 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_dynamic2.rs @@ -23,12 +23,7 @@ where const MY_NAME: &'static str = "RngChDy2"; pub fn new(std_lib: Arc>) -> Arc { - let range_check_dynamic2 = Arc::new(Self { std_lib }); - - // Register dependency relations - range_check_dynamic2.std_lib.register_predecessor(); - - range_check_dynamic2 + Arc::new(Self { std_lib }) } } @@ -95,6 +90,5 @@ where let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - self.std_lib.unregister_predecessor(); } } diff --git a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs index b4579160..25003a85 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check_mix.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check_mix.rs @@ -23,12 +23,7 @@ where const MY_NAME: &'static str = "RngChMix"; pub fn new(std_lib: Arc>) -> Arc { - let range_check_mix = Arc::new(Self { std_lib }); - - // Register dependency relations - range_check_mix.std_lib.register_predecessor(); - - range_check_mix + Arc::new(Self { std_lib }) } } @@ -136,6 +131,5 @@ where let air_instance = AirInstance::new_from_trace(FromTrace::new(&mut trace)); add_air_instance::(air_instance, pctx.clone()); - self.std_lib.unregister_predecessor(); } } From 2c86d0a7d43b1c3fbb5ee7707c02fe7c66a6e54d Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Wed, 18 Dec 2024 11:49:30 +0000 Subject: [PATCH 45/64] Adding proof values to transcript --- .github/workflows/ci.yaml | 8 +- Cargo.lock | 19 -- Cargo.toml | 2 +- cli/src/commands/pil_helpers.rs | 6 +- common/src/global_info.rs | 4 +- common/src/proof_ctx.rs | 110 ++----- common/src/setup_ctx.rs | 10 +- examples/fibonacci-square/src/fibonacci.rs | 4 +- .../fibonacci-square/src/fibonacci_lib.rs | 1 - examples/fibonacci-square/src/module.rs | 5 +- .../src/pil_helpers/traces.rs | 2 +- hints/src/global_hints.rs | 7 + .../lib/std/rs/src/range_check/u16air.rs | 1 - pil2-components/lib/std/rs/src/std.rs | 13 +- pil2-stark/lib/include/starks_lib.h | 8 +- pil2-stark/src/api/starks_api.cpp | 53 ++- pil2-stark/src/api/starks_api.hpp | 8 +- pil2-stark/src/starkpil/expressions_avx.hpp | 305 ++++++++++------- .../src/starkpil/expressions_avx512.hpp | 306 +++++++++++------- pil2-stark/src/starkpil/expressions_pack.hpp | 278 ++++++++++------ .../src/starkpil/global_constraints.hpp | 155 ++++++--- pil2-stark/src/starkpil/hints.hpp | 8 +- pil2-stark/src/starkpil/proof2zkinStark.cpp | 15 +- pil2-stark/src/starkpil/stark_info.cpp | 1 + pilout/src/pilout.proto | 8 +- pilout/src/pilout_proxy.rs | 2 +- proofman/src/constraints.rs | 1 + proofman/src/proofman.rs | 8 +- proofman/src/recursion.rs | 1 + provers/starks-lib-c/bindings_starks.rs | 16 +- provers/starks-lib-c/src/ffi_starks.rs | 30 +- 31 files changed, 865 insertions(+), 530 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 959b4e5b..5694325d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -158,7 +158,7 @@ jobs: uses: actions/checkout@v4 with: repository: 0xPolygonHermez/pil2-proofman-js - ref: 0.0.17 + ref: feature/minor_clean path: pil2-proofman-js - name: Install pil2-proofman-js dependencies @@ -169,7 +169,7 @@ jobs: uses: actions/checkout@v4 with: repository: 0xPolygonHermez/pil2-compiler - ref: feature/on-final-priority + ref: feature/proofval-stage path: pil2-compiler - name: Install pil2-compiler dependencies @@ -260,7 +260,7 @@ jobs: uses: actions/checkout@v4 with: repository: 0xPolygonHermez/pil2-proofman-js - ref: 0.0.17 + ref: feature/minor_clean path: pil2-proofman-js - name: Install pil2-proofman-js dependencies @@ -271,7 +271,7 @@ jobs: uses: actions/checkout@v4 with: repository: 0xPolygonHermez/pil2-compiler - ref: feature/on-final-priority + ref: feature/proofval-stage path: pil2-compiler - name: Install pil2-compiler dependencies diff --git a/Cargo.lock b/Cargo.lock index 8c2f25ca..7aaed7dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -973,25 +973,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "range-check" -version = "0.1.0" -dependencies = [ - "env_logger", - "log", - "num-bigint", - "num-traits", - "p3-field", - "p3-goldilocks", - "pil-std-lib", - "proofman", - "proofman-cli", - "proofman-common", - "proofman-macros", - "rand", - "witness", -] - [[package]] name = "rayon" version = "1.10.0" diff --git a/Cargo.toml b/Cargo.toml index 8b21624f..45e188aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ members = [ "witness", "util", "pil2-components/lib/std/rs", - "pil2-components/test/std/range_check/rs", + # "pil2-components/test/std/range_check/rs", # "pil2-components/test/std/lookup/rs", # "pil2-components/test/std/connection/rs", # "pil2-components/test/std/permutation/rs", diff --git a/cli/src/commands/pil_helpers.rs b/cli/src/commands/pil_helpers.rs index 3b22e151..b6524486 100644 --- a/cli/src/commands/pil_helpers.rs +++ b/cli/src/commands/pil_helpers.rs @@ -187,7 +187,11 @@ impl PilHelpersCmd { if proof_values.is_empty() { proof_values.push(ValuesCtx { values: Vec::new(), values_u64: Vec::new() }); } - proof_values[0].values.push(ColumnCtx { name: name.to_owned(), r#type: ext_type }); + if symbol.stage == Some(1) { + proof_values[0].values.push(ColumnCtx { name: name.to_owned(), r#type }); + } else { + proof_values[0].values.push(ColumnCtx { name: name.to_owned(), r#type: ext_type }); + } } else { if publics.is_empty() { publics.push(ValuesCtx { values: Vec::new(), values_u64: Vec::new() }); diff --git a/common/src/global_info.rs b/common/src/global_info.rs index 8c6469f2..55f87865 100644 --- a/common/src/global_info.rs +++ b/common/src/global_info.rs @@ -11,6 +11,8 @@ pub struct ProofValueMap { pub name: String, #[serde(default)] pub id: u64, + #[serde(default)] + pub stage: u64, } #[derive(Clone, Deserialize)] pub struct PublicMap { @@ -39,7 +41,7 @@ pub struct GlobalInfo { #[serde(rename = "numChallenges")] pub n_challenges: Vec, #[serde(rename = "numProofValues")] - pub n_proof_values: usize, + pub n_proof_values: Vec, #[serde(rename = "proofValuesMap")] pub proof_values_map: Option>, diff --git a/common/src/proof_ctx.rs b/common/src/proof_ctx.rs index 8dfc45fb..4bea405b 100644 --- a/common/src/proof_ctx.rs +++ b/common/src/proof_ctx.rs @@ -62,7 +62,7 @@ impl ProofCtx { let global_info: GlobalInfo = GlobalInfo::new(&proving_key_path); let n_publics = global_info.n_publics; - let n_proof_values = global_info.n_proof_values; + let n_proof_values = global_info.n_proof_values.iter().sum::(); let n_challenges = 4 + global_info.n_challenges.iter().sum::(); Self { @@ -88,50 +88,6 @@ impl ProofCtx { dctx.distribute_multiplicity(multiplicity, owner); } - pub fn set_proof_value(&self, name: &str, value: F) { - let id = (0..self.global_info.n_proof_values) - .find(|&i| { - if let Some(proof_value) = self - .global_info - .proof_values_map - .as_ref() - .expect("global_info.proof_values_map is not initialized") - .get(i) - { - proof_value.name == name - } else { - false - } - }) - .unwrap_or_else(|| panic!("No proof value found with name {}", name)); - - self.proof_values.values.write().unwrap()[3 * id] = value; - self.proof_values.values.write().unwrap()[3 * id + 1] = F::zero(); - self.proof_values.values.write().unwrap()[3 * id + 2] = F::zero(); - } - - pub fn set_proof_value_ext(&self, name: &str, value: Vec) { - let id = (0..self.global_info.n_proof_values) - .find(|&i| { - if let Some(proof_value) = self - .global_info - .proof_values_map - .as_ref() - .expect("global_info.proof_values_map is not initialized") - .get(i) - { - proof_value.name == name - } else { - false - } - }) - .unwrap_or_else(|| panic!("No proof value found with name {}", name)); - - self.proof_values.values.write().unwrap()[3 * id] = value[0]; - self.proof_values.values.write().unwrap()[3 * id + 1] = value[1]; - self.proof_values.values.write().unwrap()[3 * id + 2] = value[2]; - } - pub fn get_proof_values_ptr(&self) -> *mut u8 { let guard = &self.proof_values.values.read().unwrap(); guard.as_ptr() as *mut u8 @@ -141,43 +97,6 @@ impl ProofCtx { self.public_inputs.values.write().unwrap()[public_id] = value; } - pub fn set_public_value_by_name(&self, value: F, public_name: &str, lengths: Option>) { - let n_publics: usize = self.global_info.publics_map.as_ref().expect("REASON").len(); - let public_id = (0..n_publics) - .find(|&i| { - let public = self.global_info.publics_map.as_ref().expect("REASON").get(i).unwrap(); - - // Check if name matches - let name_matches = public.name == public_name; - - // If lengths is provided, check that it matches public.lengths - let lengths_match = if let Some(ref provided_lengths) = lengths { - Some(&public.lengths) == Some(provided_lengths) - } else { - true // If lengths is None, skip the lengths check - }; - - name_matches && lengths_match - }) - .unwrap_or_else(|| { - panic!("Name {} with specified lengths {:?} not found in publics_map", public_name, lengths) - }); - - self.set_public_value(value, public_id); - } - - pub fn get_public_value(&self, public_name: &str) -> F { - let n_publics: usize = self.global_info.publics_map.as_ref().expect("REASON").len(); - let public_id = (0..n_publics) - .find(|&i| { - let public = self.global_info.publics_map.as_ref().expect("REASON").get(i).unwrap(); - public.name == public_name - }) - .unwrap_or_else(|| panic!("Name {} not found in publics_map", public_name)); - - self.public_inputs.values.read().unwrap()[public_id] - } - pub fn get_publics(&self) -> std::sync::RwLockWriteGuard> { self.public_inputs.values.write().unwrap() } @@ -186,6 +105,33 @@ impl ProofCtx { self.proof_values.values.write().unwrap() } + pub fn get_proof_values_by_stage(&self, stage: u32) -> Vec { + let proof_vals = self.proof_values.values.read().unwrap(); + + let mut values = Vec::new(); + let mut p = 0; + for proof_value in self.global_info.proof_values_map.as_ref().unwrap() { + if proof_value.stage > stage as u64 { + break; + } + if proof_value.stage == 1 { + if stage == 1 { + values.push(proof_vals[p]); + } + p += 1; + } else { + if proof_value.stage == stage as u64 { + values.push(proof_vals[p]); + values.push(proof_vals[p + 1]); + values.push(proof_vals[p + 2]); + } + p += 3; + } + } + + values + } + pub fn get_publics_ptr(&self) -> *mut u8 { let guard = &self.public_inputs.values.read().unwrap(); guard.as_ptr() as *mut u8 diff --git a/common/src/setup_ctx.rs b/common/src/setup_ctx.rs index 16fc6110..6647aa82 100644 --- a/common/src/setup_ctx.rs +++ b/common/src/setup_ctx.rs @@ -85,6 +85,7 @@ impl SetupsVadcop { pub struct SetupRepository { setups: HashMap<(usize, usize), Setup>, global_bin: Option<*mut c_void>, + global_info_file: String, } unsafe impl Send for SetupRepository {} @@ -104,6 +105,9 @@ impl SetupRepository { false => None, }; + let global_info_path = &global_info.get_proving_key_path().join("pilout.globalInfo.json"); + let global_info_file = global_info_path.to_str().unwrap().to_string(); + // Initialize Hashmap for each airgroup_id, air_id if setup_type != &ProofType::VadcopFinal { for (airgroup_id, air_group) in global_info.airs.iter().enumerate() { @@ -117,7 +121,7 @@ impl SetupRepository { timer_stop_and_log_debug!(INITIALIZE_SETUPS); - Self { setups, global_bin } + Self { setups, global_bin, global_info_file } } pub fn free(&self) { @@ -160,4 +164,8 @@ impl SetupCtx { pub fn get_global_bin(&self) -> *mut c_void { self.setup_repository.global_bin.unwrap() } + + pub fn get_global_info_file(&self) -> String { + self.setup_repository.global_info_file.clone() + } } diff --git a/examples/fibonacci-square/src/fibonacci.rs b/examples/fibonacci-square/src/fibonacci.rs index e8b77136..88990514 100644 --- a/examples/fibonacci-square/src/fibonacci.rs +++ b/examples/fibonacci-square/src/fibonacci.rs @@ -56,8 +56,8 @@ impl WitnessComponent for FibonacciSquare { } let mut proof_values = BuildProofValues::from_vec_guard(pctx.get_proof_values()); - proof_values.value1[0] = F::from_canonical_u64(5); - proof_values.value2[0] = F::from_canonical_u64(125); + proof_values.value1 = F::from_canonical_u64(5); + proof_values.value2 = F::from_canonical_u64(125); let mut air_values = FibonacciSquareAirValues::::new(); air_values.fibo1[0] = F::from_canonical_u64(1); diff --git a/examples/fibonacci-square/src/fibonacci_lib.rs b/examples/fibonacci-square/src/fibonacci_lib.rs index bb1ae552..d8cf0992 100644 --- a/examples/fibonacci-square/src/fibonacci_lib.rs +++ b/examples/fibonacci-square/src/fibonacci_lib.rs @@ -18,7 +18,6 @@ impl WitnessLibrary for WitnessLib { wcm.register_component(fibonacci.clone()); wcm.register_component(module.clone()); - let public_inputs: BuildPublics = load_from_json(&wcm.get_public_inputs_path()); let mut publics = BuildPublicValues::from_vec_guard(wcm.get_pctx().get_publics()); diff --git a/examples/fibonacci-square/src/module.rs b/examples/fibonacci-square/src/module.rs index 5809149e..facc79cb 100644 --- a/examples/fibonacci-square/src/module.rs +++ b/examples/fibonacci-square/src/module.rs @@ -6,7 +6,7 @@ use pil_std_lib::Std; use p3_field::{AbstractField, PrimeField64}; use num_bigint::BigInt; -use crate::ModuleTrace; +use crate::{BuildPublicValues, ModuleTrace}; pub struct Module { inputs: Mutex>, @@ -35,7 +35,8 @@ impl WitnessComponent for Module { fn execute(&self, pctx: Arc>) { log::debug!("{} ··· Starting witness computation stage {}", Self::MY_NAME, 1); - let module = F::as_canonical_u64(&pctx.get_public_value("module")); + let publics = BuildPublicValues::from_vec_guard(pctx.get_publics()); + let module = F::as_canonical_u64(&publics.module); let mut trace = ModuleTrace::new_zeroes(); diff --git a/examples/fibonacci-square/src/pil_helpers/traces.rs b/examples/fibonacci-square/src/pil_helpers/traces.rs index c537e313..30776fd0 100644 --- a/examples/fibonacci-square/src/pil_helpers/traces.rs +++ b/examples/fibonacci-square/src/pil_helpers/traces.rs @@ -45,7 +45,7 @@ values!(BuildPublicValues { }); values!(BuildProofValues { - value1: FieldExtension, value2: FieldExtension, + value1: F, value2: F, }); trace!(FibonacciSquareTrace { diff --git a/hints/src/global_hints.rs b/hints/src/global_hints.rs index 2561b84a..2757c64d 100644 --- a/hints/src/global_hints.rs +++ b/hints/src/global_hints.rs @@ -59,6 +59,7 @@ pub fn get_hint_field_constant_gc( print_expression: bool, ) -> HintFieldValue { let raw_ptr = get_hint_field_global_constraints_c( + sctx.get_global_info_file().as_str(), sctx.get_global_bin(), std::ptr::null_mut(), std::ptr::null_mut(), @@ -86,6 +87,7 @@ pub fn get_hint_field_gc_constant_a( print_expression: bool, ) -> HintFieldValuesVec { let raw_ptr = get_hint_field_global_constraints_c( + sctx.get_global_info_file().as_str(), sctx.get_global_bin(), std::ptr::null_mut(), std::ptr::null_mut(), @@ -119,6 +121,7 @@ pub fn get_hint_field_constant_gc_m( print_expression: bool, ) -> HintFieldValues { let raw_ptr = get_hint_field_global_constraints_c( + sctx.get_global_info_file().as_str(), sctx.get_global_bin(), std::ptr::null_mut(), std::ptr::null_mut(), @@ -164,6 +167,7 @@ pub fn get_hint_field_gc( .collect(); let raw_ptr = get_hint_field_global_constraints_c( + sctx.get_global_info_file().as_str(), sctx.get_global_bin(), pctx.get_publics_ptr(), pctx.get_challenges_ptr(), @@ -198,6 +202,7 @@ pub fn get_hint_field_gc_a( .collect(); let raw_ptr = get_hint_field_global_constraints_c( + sctx.get_global_info_file().as_str(), sctx.get_global_bin(), pctx.get_publics_ptr(), pctx.get_challenges_ptr(), @@ -238,6 +243,7 @@ pub fn get_hint_field_gc_m( .collect(); let raw_ptr = get_hint_field_global_constraints_c( + sctx.get_global_info_file().as_str(), sctx.get_global_bin(), pctx.get_publics_ptr(), pctx.get_challenges_ptr(), @@ -290,6 +296,7 @@ pub fn set_hint_field_gc( }; set_hint_field_global_constraints_c( + sctx.get_global_info_file().as_str(), sctx.get_global_bin(), pctx.get_proof_values_ptr(), value_array.as_ptr() as *mut u8, diff --git a/pil2-components/lib/std/rs/src/range_check/u16air.rs b/pil2-components/lib/std/rs/src/range_check/u16air.rs index c13f0ef9..71dfbf0c 100644 --- a/pil2-components/lib/std/rs/src/range_check/u16air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u16air.rs @@ -171,7 +171,6 @@ impl WitnessComponent for U16Air { "reference", HintFieldOptions::dest_with_zeros(), ); - } fn calculate_witness(&self, stage: u32, pctx: Arc>, sctx: Arc) { diff --git a/pil2-components/lib/std/rs/src/std.rs b/pil2-components/lib/std/rs/src/std.rs index babaaa80..45b5fc03 100644 --- a/pil2-components/lib/std/rs/src/std.rs +++ b/pil2-components/lib/std/rs/src/std.rs @@ -33,7 +33,12 @@ impl Std { Arc::new(Self { pctx: wcm.get_pctx(), sctx: wcm.get_sctx(), range_check, std_prod, std_sum }) } - pub fn register_std(wcm: Arc>, std_prod: Arc>, std_sum: Arc>, range_check: Arc>) { + pub fn register_std( + wcm: Arc>, + std_prod: Arc>, + std_sum: Arc>, + range_check: Arc>, + ) { wcm.register_component(std_prod.clone()); wcm.register_component(std_sum.clone()); @@ -75,11 +80,7 @@ impl Std { self.range_check.u16air.as_ref().unwrap().drain_inputs(self.pctx.clone(), self.sctx.clone()); } RangeCheckAir::SpecifiedRanges => { - self.range_check - .specified_ranges - .as_ref() - .unwrap() - .drain_inputs(self.pctx.clone(), self.sctx.clone()); + self.range_check.specified_ranges.as_ref().unwrap().drain_inputs(self.pctx.clone(), self.sctx.clone()); } }; } diff --git a/pil2-stark/lib/include/starks_lib.h b/pil2-stark/lib/include/starks_lib.h index b78068cf..2a7b5944 100644 --- a/pil2-stark/lib/include/starks_lib.h +++ b/pil2-stark/lib/include/starks_lib.h @@ -6,7 +6,7 @@ // ======================================================================================== void save_challenges(void *pChallenges, char* globalInfoFile, char *fileDir); void save_publics(unsigned long numPublicInputs, void *pPublicInputs, char *fileDir); - void save_proof_values(unsigned long numProofValues, void *pProofValues, char *fileDir); + void save_proof_values(void *pProofValues, char* globalInfoFile, char *fileDir); // FRIProof // ======================================================================================== @@ -110,9 +110,9 @@ // Global constraints // ================================================================================= - void *verify_global_constraints(void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues); - void *get_hint_field_global_constraints(void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues, uint64_t hintId, char *hintFieldName, bool print_expression); - uint64_t set_hint_field_global_constraints(void* p_globalinfo_bin, void *proofValues, void *values, uint64_t hintId, char *hintFieldName); + void *verify_global_constraints(char* globalInfoFile, void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues); + void *get_hint_field_global_constraints(char* globalInfoFile, void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues, uint64_t hintId, char *hintFieldName, bool print_expression); + uint64_t set_hint_field_global_constraints(char* globalInfoFile, void* p_globalinfo_bin, void *proofValues, void *values, uint64_t hintId, char *hintFieldName); // Debug functions // ================================================================================= diff --git a/pil2-stark/src/api/starks_api.cpp b/pil2-stark/src/api/starks_api.cpp index 5d56f719..3eae330f 100644 --- a/pil2-stark/src/api/starks_api.cpp +++ b/pil2-stark/src/api/starks_api.cpp @@ -44,15 +44,26 @@ void save_publics(unsigned long numPublicInputs, void *pPublicInputs, char *file json2file(publicStarkJson, string(fileDir) + "/publics.json"); } -void save_proof_values(unsigned long numProofValues, void *pProofValues, char *fileDir) { +void save_proof_values(void *pProofValues, char* globalInfoFile, char *fileDir) { Goldilocks::Element* proofValues = (Goldilocks::Element *)pProofValues; + json globalInfo; + file2json(globalInfoFile, globalInfo); + json proofValuesJson; - for(uint64_t i = 0; i < numProofValues; i++) { + uint64_t p = 0; + for(uint64_t i = 0; i < globalInfo["proofValuesMap"].size(); i++) { proofValuesJson[i] = json::array(); - for(uint64_t j = 0; j < FIELD_EXTENSION; ++j) { - proofValuesJson[i][j] = Goldilocks::toString(proofValues[i*FIELD_EXTENSION + j]); + if(globalInfo["proofValuesMap"][i]["stage"] == 1) { + proofValuesJson[i][0] = Goldilocks::toString(proofValues[p++]); + proofValuesJson[i][1] = "0"; + proofValuesJson[i][2] = "0"; + } else { + proofValuesJson[i][0] = Goldilocks::toString(proofValues[p++]); + proofValuesJson[i][1] = Goldilocks::toString(proofValues[p++]); + proofValuesJson[i][2] = Goldilocks::toString(proofValues[p++]); } + } json2file(proofValuesJson, string(fileDir) + "/proof_values.json"); @@ -108,11 +119,18 @@ void *fri_proof_get_zkinproof(void *pFriProof, void* pPublics, void* pChallenges zkin["publics"][i] = Goldilocks::toString(publics[i]); } + uint64_t p = 0; for (uint64_t i = 0; i < starkInfo.proofValuesMap.size(); i++) { - zkin["proofvalues"][i][0] = Goldilocks::toString(proofValues[i*FIELD_EXTENSION]); - zkin["proofvalues"][i][1] = Goldilocks::toString(proofValues[i*FIELD_EXTENSION + 1]); - zkin["proofvalues"][i][2] = Goldilocks::toString(proofValues[i*FIELD_EXTENSION + 2]); + if(starkInfo.proofValuesMap[i].stage == 1) { + zkin["proofvalues"][i][0] = Goldilocks::toString(proofValues[p++]); + zkin["proofvalues"][i][1] = "0"; + zkin["proofvalues"][i][2] = "0"; + } else { + zkin["proofvalues"][i][0] = Goldilocks::toString(proofValues[p++]); + zkin["proofvalues"][i][1] = Goldilocks::toString(proofValues[p++]); + zkin["proofvalues"][i][2] = Goldilocks::toString(proofValues[p++]); + } } json challengesJson = challenges2zkin(globalInfo, challenges); @@ -490,20 +508,29 @@ void *verify_constraints(void *pSetupCtx, void* stepsParams) // Global Constraints // ================================================================================= -void *verify_global_constraints(void* p_globalinfo_bin, void *publics, void *challenges, void *proofValues, void **airgroupValues) { - GlobalConstraintsResults *constraintsInfo = verifyGlobalConstraints(*(ExpressionsBin*)p_globalinfo_bin, (Goldilocks::Element *)publics, (Goldilocks::Element *)challenges, (Goldilocks::Element *)proofValues, (Goldilocks::Element **)airgroupValues); +void *verify_global_constraints(char* globalInfoFile, void* p_globalinfo_bin, void *publics, void *challenges, void *proofValues, void **airgroupValues) { + json globalInfo; + file2json(globalInfoFile, globalInfo); + + GlobalConstraintsResults *constraintsInfo = verifyGlobalConstraints(globalInfo, *(ExpressionsBin*)p_globalinfo_bin, (Goldilocks::Element *)publics, (Goldilocks::Element *)challenges, (Goldilocks::Element *)proofValues, (Goldilocks::Element **)airgroupValues); return constraintsInfo; } -void *get_hint_field_global_constraints(void* p_globalinfo_bin, void *publics, void *challenges, void *proofValues, void **airgroupValues, uint64_t hintId, char *hintFieldName, bool print_expression) +void *get_hint_field_global_constraints(char* globalInfoFile, void* p_globalinfo_bin, void *publics, void *challenges, void *proofValues, void **airgroupValues, uint64_t hintId, char *hintFieldName, bool print_expression) { - HintFieldValues hintFieldValues = getHintFieldGlobalConstraint(*(ExpressionsBin*)p_globalinfo_bin, (Goldilocks::Element *)publics, (Goldilocks::Element *)challenges, (Goldilocks::Element *)proofValues, (Goldilocks::Element **)airgroupValues, hintId, string(hintFieldName), print_expression); + json globalInfo; + file2json(globalInfoFile, globalInfo); + + HintFieldValues hintFieldValues = getHintFieldGlobalConstraint(globalInfo, *(ExpressionsBin*)p_globalinfo_bin, (Goldilocks::Element *)publics, (Goldilocks::Element *)challenges, (Goldilocks::Element *)proofValues, (Goldilocks::Element **)airgroupValues, hintId, string(hintFieldName), print_expression); return new HintFieldValues(hintFieldValues); } -uint64_t set_hint_field_global_constraints(void* p_globalinfo_bin, void *proofValues, void *values, uint64_t hintId, char *hintFieldName) +uint64_t set_hint_field_global_constraints(char* globalInfoFile, void* p_globalinfo_bin, void *proofValues, void *values, uint64_t hintId, char *hintFieldName) { - return setHintFieldGlobalConstraint(*(ExpressionsBin*)p_globalinfo_bin, (Goldilocks::Element *)proofValues, (Goldilocks::Element *)values, hintId, string(hintFieldName)); + json globalInfo; + file2json(globalInfoFile, globalInfo); + + return setHintFieldGlobalConstraint(globalInfo, *(ExpressionsBin*)p_globalinfo_bin, (Goldilocks::Element *)proofValues, (Goldilocks::Element *)values, hintId, string(hintFieldName)); } // Debug functions diff --git a/pil2-stark/src/api/starks_api.hpp b/pil2-stark/src/api/starks_api.hpp index b78068cf..2a7b5944 100644 --- a/pil2-stark/src/api/starks_api.hpp +++ b/pil2-stark/src/api/starks_api.hpp @@ -6,7 +6,7 @@ // ======================================================================================== void save_challenges(void *pChallenges, char* globalInfoFile, char *fileDir); void save_publics(unsigned long numPublicInputs, void *pPublicInputs, char *fileDir); - void save_proof_values(unsigned long numProofValues, void *pProofValues, char *fileDir); + void save_proof_values(void *pProofValues, char* globalInfoFile, char *fileDir); // FRIProof // ======================================================================================== @@ -110,9 +110,9 @@ // Global constraints // ================================================================================= - void *verify_global_constraints(void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues); - void *get_hint_field_global_constraints(void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues, uint64_t hintId, char *hintFieldName, bool print_expression); - uint64_t set_hint_field_global_constraints(void* p_globalinfo_bin, void *proofValues, void *values, uint64_t hintId, char *hintFieldName); + void *verify_global_constraints(char* globalInfoFile, void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues); + void *get_hint_field_global_constraints(char* globalInfoFile, void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues, uint64_t hintId, char *hintFieldName, bool print_expression); + uint64_t set_hint_field_global_constraints(char* globalInfoFile, void* p_globalinfo_bin, void *proofValues, void *values, uint64_t hintId, char *hintFieldName); // Debug functions // ================================================================================= diff --git a/pil2-stark/src/starkpil/expressions_avx.hpp b/pil2-stark/src/starkpil/expressions_avx.hpp index baa3e63c..60795b3d 100644 --- a/pil2-stark/src/starkpil/expressions_avx.hpp +++ b/pil2-stark/src/starkpil/expressions_avx.hpp @@ -129,7 +129,6 @@ class ExpressionsAvx : public ExpressionsCtx { } else { bufferT[nrowsPack*o + j] = params.aux_trace[offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; } - } Goldilocks::load_avx(bufferT_[nColsStagesAcc[ns*o + stage] + (stagePos + d)], &bufferT[nrowsPack*o]); } @@ -222,7 +221,7 @@ class ExpressionsAvx : public ExpressionsCtx { Goldilocks3::op_31_avx(2, (Goldilocks3::Element_avx &)vals3, (Goldilocks3::Element_avx &)destVals[0], destVals[FIELD_EXTENSION]); } else { Goldilocks3::op_31_avx(2, (Goldilocks3::Element_avx &)vals3, (Goldilocks3::Element_avx &)destVals[FIELD_EXTENSION], destVals[0]); - } + } Goldilocks::copy_avx(destVals[0], vals3[0]); Goldilocks::copy_avx(destVals[1], vals3[1]); Goldilocks::copy_avx(destVals[2], vals3[2]); @@ -305,26 +304,35 @@ class ExpressionsAvx : public ExpressionsCtx { publics[i] = _mm256_set1_epi64x(params.publicInputs[i].fe); } + uint64_t p = 0; Goldilocks3::Element_avx proofValues[setupCtx.starkInfo.proofValuesMap.size()]; for(uint64_t i = 0; i < setupCtx.starkInfo.proofValuesMap.size(); ++i) { - proofValues[i][0] = _mm256_set1_epi64x(params.proofValues[i * FIELD_EXTENSION].fe); - proofValues[i][1] = _mm256_set1_epi64x(params.proofValues[i * FIELD_EXTENSION + 1].fe); - proofValues[i][2] = _mm256_set1_epi64x(params.proofValues[i * FIELD_EXTENSION + 2].fe); + if(setupCtx.starkInfo.proofValuesMap[i].stage == 1) { + proofValues[i][0] = _mm256_set1_epi64x(params.proofValues[p].fe); + proofValues[i][1] = _mm256_set1_epi64x(0); + proofValues[i][2] = _mm256_set1_epi64x(0); + p += 1; + } else { + proofValues[i][0] = _mm256_set1_epi64x(params.proofValues[p].fe); + proofValues[i][1] = _mm256_set1_epi64x(params.proofValues[p + 1].fe); + proofValues[i][2] = _mm256_set1_epi64x(params.proofValues[p + 2].fe); + p += 3; + } } Goldilocks3::Element_avx airgroupValues[setupCtx.starkInfo.airgroupValuesMap.size()]; - uint64_t p = 0; + p = 0; for(uint64_t i = 0; i < setupCtx.starkInfo.airgroupValuesMap.size(); ++i) { if(setupCtx.starkInfo.airgroupValuesMap[i].stage == 1) { - airgroupValues[i][0] = _mm256_set1_epi64x(params.airgroupValues[p].fe); - airgroupValues[i][1] = _mm256_set1_epi64x(0); - airgroupValues[i][2] = _mm256_set1_epi64x(0); - p += 1; + airgroupValues[i][0] = _mm256_set1_epi64x(params.airgroupValues[p].fe); + airgroupValues[i][1] = _mm256_set1_epi64x(0); + airgroupValues[i][2] = _mm256_set1_epi64x(0); + p += 1; } else { - airgroupValues[i][0] = _mm256_set1_epi64x(params.airgroupValues[p].fe); - airgroupValues[i][1] = _mm256_set1_epi64x(params.airgroupValues[p + 1].fe); - airgroupValues[i][2] = _mm256_set1_epi64x(params.airgroupValues[p + 2].fe); - p += 3; + airgroupValues[i][0] = _mm256_set1_epi64x(params.airgroupValues[p].fe); + airgroupValues[i][1] = _mm256_set1_epi64x(params.airgroupValues[p+ 1].fe); + airgroupValues[i][2] = _mm256_set1_epi64x(params.airgroupValues[p+ 2].fe); + p += 3; } } @@ -332,15 +340,15 @@ class ExpressionsAvx : public ExpressionsCtx { p = 0; for(uint64_t i = 0; i < setupCtx.starkInfo.airValuesMap.size(); ++i) { if(setupCtx.starkInfo.airValuesMap[i].stage == 1) { - airValues[i][0] = _mm256_set1_epi64x(params.airValues[p].fe); - airValues[i][1] = _mm256_set1_epi64x(0); - airValues[i][2] = _mm256_set1_epi64x(0); - p += 1; + airValues[i][0] = _mm256_set1_epi64x(params.airValues[p].fe); + airValues[i][1] = _mm256_set1_epi64x(0); + airValues[i][2] = _mm256_set1_epi64x(0); + p += 1; } else { - airValues[i][0] = _mm256_set1_epi64x(params.airValues[p].fe); - airValues[i][1] = _mm256_set1_epi64x(params.airValues[p + 1].fe); - airValues[i][2] = _mm256_set1_epi64x(params.airValues[p + 2].fe); - p += 3; + airValues[i][0] = _mm256_set1_epi64x(params.airValues[p].fe); + airValues[i][1] = _mm256_set1_epi64x(params.airValues[p + 1].fe); + airValues[i][2] = _mm256_set1_epi64x(params.airValues[p + 2].fe); + p += 3; } } @@ -368,7 +376,7 @@ class ExpressionsAvx : public ExpressionsCtx { uint64_t openingPointIndex = dests[j].params[k].rowOffsetIndex; uint64_t buffPos = ns*openingPointIndex + dests[j].params[k].stage; uint64_t stagePos = dests[j].params[k].stagePos; - copyPolynomial(&destVals[j][k*FIELD_EXTENSION], dests[j].params[k].inverse, dests[j].params[k].dim, &bufferT_[nColsStagesAcc[buffPos] + stagePos]); + copyPolynomial(&destVals[j][k*FIELD_EXTENSION], dests[j].params[k].inverse,dests[j].params[k].dim, &bufferT_[nColsStagesAcc[buffPos] + stagePos]); continue; } else if(dests[j].params[k].op == opType::number) { destVals[j][k*FIELD_EXTENSION] = _mm256_set1_epi64x(dests[j].params[k].value); @@ -419,456 +427,534 @@ class ExpressionsAvx : public ExpressionsCtx { break; } case 6: { + // OPERATION WITH DEST: tmp1 - SRC0: commit1 - SRC1: proofvalue1 + Goldilocks::op_avx(args[i_args], tmp1[args[i_args + 1]], bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], proofValues[args[i_args + 4]][0]); + i_args += 5; + break; + } + case 7: { // COPY tmp1 to tmp1 Goldilocks::copy_avx(tmp1[args[i_args]], tmp1[args[i_args + 1]]); i_args += 2; break; } - case 7: { + case 8: { // OPERATION WITH DEST: tmp1 - SRC0: tmp1 - SRC1: tmp1 Goldilocks::op_avx(args[i_args], tmp1[args[i_args + 1]], tmp1[args[i_args + 2]], tmp1[args[i_args + 3]]); i_args += 4; break; } - case 8: { + case 9: { // OPERATION WITH DEST: tmp1 - SRC0: tmp1 - SRC1: public Goldilocks::op_avx(args[i_args], tmp1[args[i_args + 1]], tmp1[args[i_args + 2]], publics[args[i_args + 3]]); i_args += 4; break; } - case 9: { + case 10: { // OPERATION WITH DEST: tmp1 - SRC0: tmp1 - SRC1: number Goldilocks::op_avx(args[i_args], tmp1[args[i_args + 1]], tmp1[args[i_args + 2]], numbers_[args[i_args + 3]]); i_args += 4; break; } - case 10: { + case 11: { // OPERATION WITH DEST: tmp1 - SRC0: tmp1 - SRC1: airvalue1 Goldilocks::op_avx(args[i_args], tmp1[args[i_args + 1]], tmp1[args[i_args + 2]], airValues[args[i_args + 3]][0]); i_args += 4; break; } - case 11: { + case 12: { + // OPERATION WITH DEST: tmp1 - SRC0: tmp1 - SRC1: proofvalue1 + Goldilocks::op_avx(args[i_args], tmp1[args[i_args + 1]], tmp1[args[i_args + 2]], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 13: { // COPY public to tmp1 Goldilocks::copy_avx(tmp1[args[i_args]], publics[args[i_args + 1]]); i_args += 2; break; } - case 12: { + case 14: { // OPERATION WITH DEST: tmp1 - SRC0: public - SRC1: public Goldilocks::op_avx(args[i_args], tmp1[args[i_args + 1]], publics[args[i_args + 2]], publics[args[i_args + 3]]); i_args += 4; break; } - case 13: { + case 15: { // OPERATION WITH DEST: tmp1 - SRC0: public - SRC1: number Goldilocks::op_avx(args[i_args], tmp1[args[i_args + 1]], publics[args[i_args + 2]], numbers_[args[i_args + 3]]); i_args += 4; break; } - case 14: { + case 16: { // OPERATION WITH DEST: tmp1 - SRC0: public - SRC1: airvalue1 Goldilocks::op_avx(args[i_args], tmp1[args[i_args + 1]], publics[args[i_args + 2]], airValues[args[i_args + 3]][0]); i_args += 4; break; } - case 15: { + case 17: { + // OPERATION WITH DEST: tmp1 - SRC0: public - SRC1: proofvalue1 + Goldilocks::op_avx(args[i_args], tmp1[args[i_args + 1]], publics[args[i_args + 2]], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 18: { // COPY number to tmp1 Goldilocks::copy_avx(tmp1[args[i_args]], numbers_[args[i_args + 1]]); i_args += 2; break; } - case 16: { + case 19: { // OPERATION WITH DEST: tmp1 - SRC0: number - SRC1: number Goldilocks::op_avx(args[i_args], tmp1[args[i_args + 1]], numbers_[args[i_args + 2]], numbers_[args[i_args + 3]]); i_args += 4; break; } - case 17: { + case 20: { // OPERATION WITH DEST: tmp1 - SRC0: number - SRC1: airvalue1 Goldilocks::op_avx(args[i_args], tmp1[args[i_args + 1]], numbers_[args[i_args + 2]], airValues[args[i_args + 3]][0]); i_args += 4; break; } - case 18: { + case 21: { + // OPERATION WITH DEST: tmp1 - SRC0: number - SRC1: proofvalue1 + Goldilocks::op_avx(args[i_args], tmp1[args[i_args + 1]], numbers_[args[i_args + 2]], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 22: { // COPY airvalue1 to tmp1 Goldilocks::copy_avx(tmp1[args[i_args]], airValues[args[i_args + 1]][0]); i_args += 2; break; } - case 19: { + case 23: { // OPERATION WITH DEST: tmp1 - SRC0: airvalue1 - SRC1: airvalue1 Goldilocks::op_avx(args[i_args], tmp1[args[i_args + 1]], airValues[args[i_args + 2]][0], airValues[args[i_args + 3]][0]); i_args += 4; break; } - case 20: { + case 24: { + // OPERATION WITH DEST: tmp1 - SRC0: airvalue1 - SRC1: proofvalue1 + Goldilocks::op_avx(args[i_args], tmp1[args[i_args + 1]], airValues[args[i_args + 2]][0], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 25: { + // COPY proofvalue1 to tmp1 + Goldilocks::copy_avx(tmp1[args[i_args]], proofValues[args[i_args + 1]][0]); + i_args += 2; + break; + } + case 26: { + // OPERATION WITH DEST: tmp1 - SRC0: proofvalue1 - SRC1: proofvalue1 + Goldilocks::op_avx(args[i_args], tmp1[args[i_args + 1]], proofValues[args[i_args + 2]][0], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 27: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: commit1 Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], bufferT_[nColsStagesAcc[args[i_args + 4]] + args[i_args + 5]]); i_args += 6; break; } - case 21: { + case 28: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: tmp1 Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], tmp1[args[i_args + 4]]); i_args += 5; break; } - case 22: { + case 29: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: public Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], publics[args[i_args + 4]]); i_args += 5; break; } - case 23: { + case 30: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: number Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], numbers_[args[i_args + 4]]); i_args += 5; break; } - case 24: { + case 31: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: airvalue1 Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], airValues[args[i_args + 4]][0]); i_args += 5; break; } - case 25: { + case 32: { + // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: proofvalue1 + Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], proofValues[args[i_args + 4]][0]); + i_args += 5; + break; + } + case 33: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: commit1 Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], bufferT_[nColsStagesAcc[args[i_args + 3]] + args[i_args + 4]]); i_args += 5; break; } - case 26: { + case 34: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: tmp1 Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], tmp1[args[i_args + 3]]); i_args += 4; break; } - case 27: { + case 35: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: public Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], publics[args[i_args + 3]]); i_args += 4; break; } - case 28: { + case 36: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: number Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], numbers_[args[i_args + 3]]); i_args += 4; break; } - case 29: { + case 37: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: airvalue1 Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], airValues[args[i_args + 3]][0]); i_args += 4; break; } - case 30: { + case 38: { + // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: proofvalue1 + Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 39: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: commit1 Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], bufferT_[nColsStagesAcc[args[i_args + 3]] + args[i_args + 4]]); i_args += 5; break; } - case 31: { + case 40: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: tmp1 Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], tmp1[args[i_args + 3]]); i_args += 4; break; } - case 32: { + case 41: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: public Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], publics[args[i_args + 3]]); i_args += 4; break; } - case 33: { + case 42: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: number Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], numbers_[args[i_args + 3]]); i_args += 4; break; } - case 34: { + case 43: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: airvalue1 Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], airValues[args[i_args + 3]][0]); i_args += 4; break; } - case 35: { + case 44: { + // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: proofvalue1 + Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 45: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: commit1 Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], bufferT_[nColsStagesAcc[args[i_args + 3]] + args[i_args + 4]]); i_args += 5; break; } - case 36: { + case 46: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: tmp1 Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], tmp1[args[i_args + 3]]); i_args += 4; break; } - case 37: { + case 47: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: public Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], publics[args[i_args + 3]]); i_args += 4; break; } - case 38: { + case 48: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: number Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], numbers_[args[i_args + 3]]); i_args += 4; break; } - case 39: { + case 49: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: airvalue1 Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], airValues[args[i_args + 3]][0]); i_args += 4; break; } - case 40: { + case 50: { + // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: proofvalue1 + Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 51: { // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: commit1 Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], airValues[args[i_args + 2]], bufferT_[nColsStagesAcc[args[i_args + 3]] + args[i_args + 4]]); i_args += 5; break; } - case 41: { + case 52: { // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: tmp1 Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], airValues[args[i_args + 2]], tmp1[args[i_args + 3]]); i_args += 4; break; } - case 42: { + case 53: { // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: public Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], airValues[args[i_args + 2]], publics[args[i_args + 3]]); i_args += 4; break; } - case 43: { + case 54: { // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: number Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], airValues[args[i_args + 2]], numbers_[args[i_args + 3]]); i_args += 4; break; } - case 44: { + case 55: { // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: airvalue1 Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], airValues[args[i_args + 2]], airValues[args[i_args + 3]][0]); i_args += 4; break; } - case 45: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: commit1 + case 56: { + // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: proofvalue1 + Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], airValues[args[i_args + 2]], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 57: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: commit1 Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], proofValues[args[i_args + 2]], bufferT_[nColsStagesAcc[args[i_args + 3]] + args[i_args + 4]]); i_args += 5; break; } - case 46: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: tmp1 + case 58: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: tmp1 Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], proofValues[args[i_args + 2]], tmp1[args[i_args + 3]]); i_args += 4; break; } - case 47: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: public + case 59: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: public Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], proofValues[args[i_args + 2]], publics[args[i_args + 3]]); i_args += 4; break; } - case 48: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: number + case 60: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: number Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], proofValues[args[i_args + 2]], numbers_[args[i_args + 3]]); i_args += 4; break; } - case 49: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: airvalue1 + case 61: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: airvalue1 Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], proofValues[args[i_args + 2]], airValues[args[i_args + 3]][0]); i_args += 4; break; } - case 50: { + case 62: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: proofvalue1 + Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], proofValues[args[i_args + 2]], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 63: { // COPY commit3 to tmp3 Goldilocks3::copy_avx(tmp3[args[i_args]], (Goldilocks3::Element_avx &)bufferT_[nColsStagesAcc[args[i_args + 1]] + args[i_args + 2]]); i_args += 3; break; } - case 51: { + case 64: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: commit3 Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], (Goldilocks3::Element_avx &)bufferT_[nColsStagesAcc[args[i_args + 4]] + args[i_args + 5]]); i_args += 6; break; } - case 52: { + case 65: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: tmp3 Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], tmp3[args[i_args + 4]]); i_args += 5; break; } - case 53: { + case 66: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: challenge Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], challenges[args[i_args + 4]]); i_args += 5; break; } - case 54: { + case 67: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: airgroupvalue Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], airgroupValues[args[i_args + 4]]); i_args += 5; break; } - case 55: { + case 68: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: airvalue3 Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], airValues[args[i_args + 4]]); i_args += 5; break; } - case 56: { - // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: proofvalue + case 69: { + // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: proofvalue3 Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], proofValues[args[i_args + 4]]); i_args += 5; break; } - case 57: { + case 70: { // COPY tmp3 to tmp3 Goldilocks3::copy_avx(tmp3[args[i_args]], tmp3[args[i_args + 1]]); i_args += 2; break; } - case 58: { + case 71: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: tmp3 Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], tmp3[args[i_args + 3]]); i_args += 4; break; } - case 59: { + case 72: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: challenge Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], challenges[args[i_args + 3]]); i_args += 4; break; } - case 60: { + case 73: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: airgroupvalue Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], airgroupValues[args[i_args + 3]]); i_args += 4; break; } - case 61: { + case 74: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: airvalue3 Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], airValues[args[i_args + 3]]); i_args += 4; break; } - case 62: { - // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: proofvalue + case 75: { + // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: proofvalue3 Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], proofValues[args[i_args + 3]]); i_args += 4; break; } - case 63: { + case 76: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: challenge Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], challenges[args[i_args + 3]]); i_args += 4; break; } - case 64: { + case 77: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: airgroupvalue Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], airgroupValues[args[i_args + 3]]); i_args += 4; break; } - case 65: { + case 78: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: airvalue3 Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], airValues[args[i_args + 3]]); i_args += 4; break; } - case 66: { - // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: proofvalue + case 79: { + // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: proofvalue3 Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], proofValues[args[i_args + 3]]); i_args += 4; break; } - case 67: { + case 80: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: airgroupvalue Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], airgroupValues[args[i_args + 3]]); i_args += 4; break; } - case 68: { + case 81: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: airvalue3 Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], airValues[args[i_args + 3]]); i_args += 4; break; } - case 69: { - // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: proofvalue + case 82: { + // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: proofvalue3 Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], proofValues[args[i_args + 3]]); i_args += 4; break; } - case 70: { + case 83: { // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: airvalue3 Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], airValues[args[i_args + 2]], airValues[args[i_args + 3]]); i_args += 4; break; } - case 71: { - // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: proofvalue + case 84: { + // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: proofvalue3 Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], airValues[args[i_args + 2]], proofValues[args[i_args + 3]]); i_args += 4; break; } - case 72: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: proofvalue + case 85: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: proofvalue3 Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], proofValues[args[i_args + 2]], proofValues[args[i_args + 3]]); i_args += 4; break; } - case 73: { + case 86: { // COPY eval to tmp3 Goldilocks3::copy_avx(tmp3[args[i_args]], evals[args[i_args + 1]]); i_args += 2; break; } - case 74: { + case 87: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: eval Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], evals[args[i_args + 3]]); i_args += 4; break; } - case 75: { + case 88: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: eval Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], evals[args[i_args + 3]]); i_args += 4; break; } - case 76: { + case 89: { // OPERATION WITH DEST: tmp3 - SRC0: eval - SRC1: commit1 Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], evals[args[i_args + 2]], bufferT_[nColsStagesAcc[args[i_args + 3]] + args[i_args + 4]]); i_args += 5; break; } - case 77: { + case 90: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: eval Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], evals[args[i_args + 4]]); i_args += 5; break; } - case 78: { + case 91: { // OPERATION WITH DEST: tmp3 - SRC0: eval - SRC1: eval Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], evals[args[i_args + 2]], evals[args[i_args + 3]]); i_args += 4; break; } - case 79: { + case 92: { // OPERATION WITH DEST: tmp3 - SRC0: eval - SRC1: public Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], evals[args[i_args + 2]], publics[args[i_args + 3]]); i_args += 4; break; } - case 80: { + case 93: { // OPERATION WITH DEST: tmp3 - SRC0: eval - SRC1: number Goldilocks3::op_31_avx(args[i_args], tmp3[args[i_args + 1]], evals[args[i_args + 2]], numbers_[args[i_args + 3]]); i_args += 4; break; } - case 81: { + case 94: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: eval Goldilocks3::op_avx(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], evals[args[i_args + 3]]); i_args += 4; @@ -890,7 +976,6 @@ class ExpressionsAvx : public ExpressionsCtx { copyPolynomial(&destVals[j][k*FIELD_EXTENSION], dests[j].params[k].inverse, dests[j].params[k].parserParams.destDim, tmp3[dests[j].params[k].parserParams.destId]); } } - if(dests[j].params.size() == 2) { multiplyPolynomials(dests[j], destVals[j]); } diff --git a/pil2-stark/src/starkpil/expressions_avx512.hpp b/pil2-stark/src/starkpil/expressions_avx512.hpp index c5eb86b9..58478c11 100644 --- a/pil2-stark/src/starkpil/expressions_avx512.hpp +++ b/pil2-stark/src/starkpil/expressions_avx512.hpp @@ -128,7 +128,7 @@ class ExpressionsAvx512 : public ExpressionsCtx { bufferT[nrowsPack*o + j] = params.trace[l * nColsStages[stage] + stagePos + d]; } else { bufferT[nrowsPack*o + j] = params.aux_trace[offsetsStages[stage] + l * nColsStages[stage] + stagePos + d]; - } + } } Goldilocks::load_avx512(bufferT_[nColsStagesAcc[ns*o + stage] + (stagePos + d)], &bufferT[nrowsPack*o]); } @@ -221,7 +221,7 @@ class ExpressionsAvx512 : public ExpressionsCtx { Goldilocks3::op_31_avx512(2, (Goldilocks3::Element_avx512 &)vals3, (Goldilocks3::Element_avx512 &)destVals[0], destVals[FIELD_EXTENSION]); } else { Goldilocks3::op_31_avx512(2, (Goldilocks3::Element_avx512 &)vals3, (Goldilocks3::Element_avx512 &)destVals[FIELD_EXTENSION], destVals[0]); - } + } Goldilocks::copy_avx512(destVals[0], vals3[0]); Goldilocks::copy_avx512(destVals[1], vals3[1]); Goldilocks::copy_avx512(destVals[2], vals3[2]); @@ -304,26 +304,35 @@ class ExpressionsAvx512 : public ExpressionsCtx { publics[i] = _mm512_set1_epi64(params.publicInputs[i].fe); } + uint64_t p = 0; Goldilocks3::Element_avx512 proofValues[setupCtx.starkInfo.proofValuesMap.size()]; for(uint64_t i = 0; i < setupCtx.starkInfo.proofValuesMap.size(); ++i) { - proofValues[i][0] = _mm512_set1_epi64(params.proofValues[i * FIELD_EXTENSION].fe); - proofValues[i][1] = _mm512_set1_epi64(params.proofValues[i * FIELD_EXTENSION + 1].fe); - proofValues[i][2] = _mm512_set1_epi64(params.proofValues[i * FIELD_EXTENSION + 2].fe); + if(setupCtx.starkInfo.proofValuesMap[i].stage == 1) { + proofValues[i][0] = _mm512_set1_epi64(params.proofValues[p].fe); + proofValues[i][1] = _mm512_set1_epi64(0); + proofValues[i][2] = _mm512_set1_epi64(0); + p += 1; + } else { + proofValues[i][0] = _mm512_set1_epi64(params.proofValues[p].fe); + proofValues[i][1] = _mm512_set1_epi64(params.proofValues[p + 1].fe); + proofValues[i][2] = _mm512_set1_epi64(params.proofValues[p + 2].fe); + p += 3; + } } Goldilocks3::Element_avx512 airgroupValues[setupCtx.starkInfo.airgroupValuesMap.size()]; - uint64_t p = 0; + p = 0; for(uint64_t i = 0; i < setupCtx.starkInfo.airgroupValuesMap.size(); ++i) { if(setupCtx.starkInfo.airgroupValuesMap[i].stage == 1) { - airgroupValues[i][0] = _mm512_set1_epi64x(params.airgroupValues[p].fe); - airgroupValues[i][1] = _mm512_set1_epi64x(0); - airgroupValues[i][2] = _mm512_set1_epi64x(0); - p += 1; + airgroupValues[i][0] = _mm512_set1_epi64(params.airgroupValues[p].fe); + airgroupValues[i][1] = _mm512_set1_epi64(0); + airgroupValues[i][2] = _mm512_set1_epi64(0); + p += 1; } else { - airgroupValues[i][0] = _mm512_set1_epi64x(params.airgroupValues[p].fe); - airgroupValues[i][1] = _mm512_set1_epi64x(params.airgroupValues[p + 1].fe); - airgroupValues[i][2] = _mm512_set1_epi64x(params.airgroupValues[p + 2].fe); - p += 3; + airgroupValues[i][0] = _mm512_set1_epi64(params.airgroupValues[p].fe); + airgroupValues[i][1] = _mm512_set1_epi64(params.airgroupValues[p+ 1].fe); + airgroupValues[i][2] = _mm512_set1_epi64(params.airgroupValues[p+ 2].fe); + p += 3; } } @@ -331,15 +340,15 @@ class ExpressionsAvx512 : public ExpressionsCtx { p = 0; for(uint64_t i = 0; i < setupCtx.starkInfo.airValuesMap.size(); ++i) { if(setupCtx.starkInfo.airValuesMap[i].stage == 1) { - airValues[i][0] = _mm512_set1_epi64x(params.airValues[p].fe); - airValues[i][1] = _mm512_set1_epi64x(0); - airValues[i][2] = _mm512_set1_epi64x(0); - p += 1; + airValues[i][0] = _mm512_set1_epi64(params.airValues[p].fe); + airValues[i][1] = _mm512_set1_epi64(0); + airValues[i][2] = _mm512_set1_epi64(0); + p += 1; } else { - airValues[i][0] = _mm512_set1_epi64x(params.airValues[p].fe); - airValues[i][1] = _mm512_set1_epi64x(params.airValues[p + 1].fe); - airValues[i][2] = _mm512_set1_epi64x(params.airValues[p + 2].fe); - p += 3; + airValues[i][0] = _mm512_set1_epi64(params.airValues[p].fe); + airValues[i][1] = _mm512_set1_epi64(params.airValues[p + 1].fe); + airValues[i][2] = _mm512_set1_epi64(params.airValues[p + 2].fe); + p += 3; } } @@ -365,10 +374,9 @@ class ExpressionsAvx512 : public ExpressionsCtx { if(dests[j].params[k].op == opType::cm || dests[j].params[k].op == opType::const_) { uint64_t openingPointIndex = dests[j].params[k].rowOffsetIndex; - uint64_t buffPos = ns*openingPointIndex + dests[j].params[k].stage; uint64_t stagePos = dests[j].params[k].stagePos; - copyPolynomial(&destVals[j][k*FIELD_EXTENSION], dests[j].params[k].inverse, dests[j].params[k].dim, &bufferT_[nColsStagesAcc[buffPos] + stagePos]); + copyPolynomial(&destVals[j][k*FIELD_EXTENSION], dests[j].params[k].inverse,dests[j].params[k].dim, &bufferT_[nColsStagesAcc[buffPos] + stagePos]); continue; } else if(dests[j].params[k].op == opType::number) { destVals[j][k*FIELD_EXTENSION] = _mm512_set1_epi64(dests[j].params[k].value); @@ -419,456 +427,534 @@ class ExpressionsAvx512 : public ExpressionsCtx { break; } case 6: { + // OPERATION WITH DEST: tmp1 - SRC0: commit1 - SRC1: proofvalue1 + Goldilocks::op_avx512(args[i_args], tmp1[args[i_args + 1]], bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], proofValues[args[i_args + 4]][0]); + i_args += 5; + break; + } + case 7: { // COPY tmp1 to tmp1 Goldilocks::copy_avx512(tmp1[args[i_args]], tmp1[args[i_args + 1]]); i_args += 2; break; } - case 7: { + case 8: { // OPERATION WITH DEST: tmp1 - SRC0: tmp1 - SRC1: tmp1 Goldilocks::op_avx512(args[i_args], tmp1[args[i_args + 1]], tmp1[args[i_args + 2]], tmp1[args[i_args + 3]]); i_args += 4; break; } - case 8: { + case 9: { // OPERATION WITH DEST: tmp1 - SRC0: tmp1 - SRC1: public Goldilocks::op_avx512(args[i_args], tmp1[args[i_args + 1]], tmp1[args[i_args + 2]], publics[args[i_args + 3]]); i_args += 4; break; } - case 9: { + case 10: { // OPERATION WITH DEST: tmp1 - SRC0: tmp1 - SRC1: number Goldilocks::op_avx512(args[i_args], tmp1[args[i_args + 1]], tmp1[args[i_args + 2]], numbers_[args[i_args + 3]]); i_args += 4; break; } - case 10: { + case 11: { // OPERATION WITH DEST: tmp1 - SRC0: tmp1 - SRC1: airvalue1 Goldilocks::op_avx512(args[i_args], tmp1[args[i_args + 1]], tmp1[args[i_args + 2]], airValues[args[i_args + 3]][0]); i_args += 4; break; } - case 11: { + case 12: { + // OPERATION WITH DEST: tmp1 - SRC0: tmp1 - SRC1: proofvalue1 + Goldilocks::op_avx512(args[i_args], tmp1[args[i_args + 1]], tmp1[args[i_args + 2]], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 13: { // COPY public to tmp1 Goldilocks::copy_avx512(tmp1[args[i_args]], publics[args[i_args + 1]]); i_args += 2; break; } - case 12: { + case 14: { // OPERATION WITH DEST: tmp1 - SRC0: public - SRC1: public Goldilocks::op_avx512(args[i_args], tmp1[args[i_args + 1]], publics[args[i_args + 2]], publics[args[i_args + 3]]); i_args += 4; break; } - case 13: { + case 15: { // OPERATION WITH DEST: tmp1 - SRC0: public - SRC1: number Goldilocks::op_avx512(args[i_args], tmp1[args[i_args + 1]], publics[args[i_args + 2]], numbers_[args[i_args + 3]]); i_args += 4; break; } - case 14: { + case 16: { // OPERATION WITH DEST: tmp1 - SRC0: public - SRC1: airvalue1 Goldilocks::op_avx512(args[i_args], tmp1[args[i_args + 1]], publics[args[i_args + 2]], airValues[args[i_args + 3]][0]); i_args += 4; break; } - case 15: { + case 17: { + // OPERATION WITH DEST: tmp1 - SRC0: public - SRC1: proofvalue1 + Goldilocks::op_avx512(args[i_args], tmp1[args[i_args + 1]], publics[args[i_args + 2]], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 18: { // COPY number to tmp1 Goldilocks::copy_avx512(tmp1[args[i_args]], numbers_[args[i_args + 1]]); i_args += 2; break; } - case 16: { + case 19: { // OPERATION WITH DEST: tmp1 - SRC0: number - SRC1: number Goldilocks::op_avx512(args[i_args], tmp1[args[i_args + 1]], numbers_[args[i_args + 2]], numbers_[args[i_args + 3]]); i_args += 4; break; } - case 17: { + case 20: { // OPERATION WITH DEST: tmp1 - SRC0: number - SRC1: airvalue1 Goldilocks::op_avx512(args[i_args], tmp1[args[i_args + 1]], numbers_[args[i_args + 2]], airValues[args[i_args + 3]][0]); i_args += 4; break; } - case 18: { + case 21: { + // OPERATION WITH DEST: tmp1 - SRC0: number - SRC1: proofvalue1 + Goldilocks::op_avx512(args[i_args], tmp1[args[i_args + 1]], numbers_[args[i_args + 2]], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 22: { // COPY airvalue1 to tmp1 Goldilocks::copy_avx512(tmp1[args[i_args]], airValues[args[i_args + 1]][0]); i_args += 2; break; } - case 19: { + case 23: { // OPERATION WITH DEST: tmp1 - SRC0: airvalue1 - SRC1: airvalue1 Goldilocks::op_avx512(args[i_args], tmp1[args[i_args + 1]], airValues[args[i_args + 2]][0], airValues[args[i_args + 3]][0]); i_args += 4; break; } - case 20: { + case 24: { + // OPERATION WITH DEST: tmp1 - SRC0: airvalue1 - SRC1: proofvalue1 + Goldilocks::op_avx512(args[i_args], tmp1[args[i_args + 1]], airValues[args[i_args + 2]][0], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 25: { + // COPY proofvalue1 to tmp1 + Goldilocks::copy_avx512(tmp1[args[i_args]], proofValues[args[i_args + 1]][0]); + i_args += 2; + break; + } + case 26: { + // OPERATION WITH DEST: tmp1 - SRC0: proofvalue1 - SRC1: proofvalue1 + Goldilocks::op_avx512(args[i_args], tmp1[args[i_args + 1]], proofValues[args[i_args + 2]][0], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 27: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: commit1 Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx512 &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], bufferT_[nColsStagesAcc[args[i_args + 4]] + args[i_args + 5]]); i_args += 6; break; } - case 21: { + case 28: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: tmp1 Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx512 &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], tmp1[args[i_args + 4]]); i_args += 5; break; } - case 22: { + case 29: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: public Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx512 &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], publics[args[i_args + 4]]); i_args += 5; break; } - case 23: { + case 30: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: number Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx512 &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], numbers_[args[i_args + 4]]); i_args += 5; break; } - case 24: { + case 31: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: airvalue1 Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx512 &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], airValues[args[i_args + 4]][0]); i_args += 5; break; } - case 25: { + case 32: { + // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: proofvalue1 + Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx512 &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], proofValues[args[i_args + 4]][0]); + i_args += 5; + break; + } + case 33: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: commit1 Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], bufferT_[nColsStagesAcc[args[i_args + 3]] + args[i_args + 4]]); i_args += 5; break; } - case 26: { + case 34: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: tmp1 Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], tmp1[args[i_args + 3]]); i_args += 4; break; } - case 27: { + case 35: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: public Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], publics[args[i_args + 3]]); i_args += 4; break; } - case 28: { + case 36: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: number Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], numbers_[args[i_args + 3]]); i_args += 4; break; } - case 29: { + case 37: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: airvalue1 Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], airValues[args[i_args + 3]][0]); i_args += 4; break; } - case 30: { + case 38: { + // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: proofvalue1 + Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 39: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: commit1 Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], bufferT_[nColsStagesAcc[args[i_args + 3]] + args[i_args + 4]]); i_args += 5; break; } - case 31: { + case 40: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: tmp1 Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], tmp1[args[i_args + 3]]); i_args += 4; break; } - case 32: { + case 41: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: public Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], publics[args[i_args + 3]]); i_args += 4; break; } - case 33: { + case 42: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: number Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], numbers_[args[i_args + 3]]); i_args += 4; break; } - case 34: { + case 43: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: airvalue1 Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], airValues[args[i_args + 3]][0]); i_args += 4; break; } - case 35: { + case 44: { + // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: proofvalue1 + Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 45: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: commit1 Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], bufferT_[nColsStagesAcc[args[i_args + 3]] + args[i_args + 4]]); i_args += 5; break; } - case 36: { + case 46: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: tmp1 Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], tmp1[args[i_args + 3]]); i_args += 4; break; } - case 37: { + case 47: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: public Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], publics[args[i_args + 3]]); i_args += 4; break; } - case 38: { + case 48: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: number Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], numbers_[args[i_args + 3]]); i_args += 4; break; } - case 39: { + case 49: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: airvalue1 Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], airValues[args[i_args + 3]][0]); i_args += 4; break; } - case 40: { + case 50: { + // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: proofvalue1 + Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 51: { // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: commit1 Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], airValues[args[i_args + 2]], bufferT_[nColsStagesAcc[args[i_args + 3]] + args[i_args + 4]]); i_args += 5; break; } - case 41: { + case 52: { // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: tmp1 Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], airValues[args[i_args + 2]], tmp1[args[i_args + 3]]); i_args += 4; break; } - case 42: { + case 53: { // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: public Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], airValues[args[i_args + 2]], publics[args[i_args + 3]]); i_args += 4; break; } - case 43: { + case 54: { // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: number Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], airValues[args[i_args + 2]], numbers_[args[i_args + 3]]); i_args += 4; break; } - case 44: { + case 55: { // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: airvalue1 Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], airValues[args[i_args + 2]], airValues[args[i_args + 3]][0]); i_args += 4; break; } - case 45: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: commit1 + case 56: { + // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: proofvalue1 + Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], airValues[args[i_args + 2]], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 57: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: commit1 Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], proofValues[args[i_args + 2]], bufferT_[nColsStagesAcc[args[i_args + 3]] + args[i_args + 4]]); i_args += 5; break; } - case 46: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: tmp1 + case 58: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: tmp1 Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], proofValues[args[i_args + 2]], tmp1[args[i_args + 3]]); i_args += 4; break; } - case 47: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: public + case 59: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: public Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], proofValues[args[i_args + 2]], publics[args[i_args + 3]]); i_args += 4; break; } - case 48: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: number + case 60: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: number Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], proofValues[args[i_args + 2]], numbers_[args[i_args + 3]]); i_args += 4; break; } - case 49: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: airvalue1 + case 61: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: airvalue1 Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], proofValues[args[i_args + 2]], airValues[args[i_args + 3]][0]); i_args += 4; break; } - case 50: { + case 62: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: proofvalue1 + Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], proofValues[args[i_args + 2]], proofValues[args[i_args + 3]][0]); + i_args += 4; + break; + } + case 63: { // COPY commit3 to tmp3 Goldilocks3::copy_avx512(tmp3[args[i_args]], (Goldilocks3::Element_avx512 &)bufferT_[nColsStagesAcc[args[i_args + 1]] + args[i_args + 2]]); i_args += 3; break; } - case 51: { + case 64: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: commit3 Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx512 &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], (Goldilocks3::Element_avx512 &)bufferT_[nColsStagesAcc[args[i_args + 4]] + args[i_args + 5]]); i_args += 6; break; } - case 52: { + case 65: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: tmp3 Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx512 &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], tmp3[args[i_args + 4]]); i_args += 5; break; } - case 53: { + case 66: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: challenge Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx512 &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], challenges[args[i_args + 4]]); i_args += 5; break; } - case 54: { + case 67: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: airgroupvalue Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx512 &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], airgroupValues[args[i_args + 4]]); i_args += 5; break; } - case 55: { + case 68: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: airvalue3 Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx512 &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], airValues[args[i_args + 4]]); i_args += 5; break; } - case 56: { - // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: proofvalue + case 69: { + // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: proofvalue3 Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx512 &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], proofValues[args[i_args + 4]]); i_args += 5; break; } - case 57: { + case 70: { // COPY tmp3 to tmp3 Goldilocks3::copy_avx512(tmp3[args[i_args]], tmp3[args[i_args + 1]]); i_args += 2; break; } - case 58: { + case 71: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: tmp3 Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], tmp3[args[i_args + 3]]); i_args += 4; break; } - case 59: { + case 72: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: challenge Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], challenges[args[i_args + 3]]); i_args += 4; break; } - case 60: { + case 73: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: airgroupvalue Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], airgroupValues[args[i_args + 3]]); i_args += 4; break; } - case 61: { + case 74: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: airvalue3 Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], airValues[args[i_args + 3]]); i_args += 4; break; } - case 62: { - // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: proofvalue + case 75: { + // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: proofvalue3 Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], proofValues[args[i_args + 3]]); i_args += 4; break; } - case 63: { + case 76: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: challenge Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], challenges[args[i_args + 3]]); i_args += 4; break; } - case 64: { + case 77: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: airgroupvalue Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], airgroupValues[args[i_args + 3]]); i_args += 4; break; } - case 65: { + case 78: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: airvalue3 Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], airValues[args[i_args + 3]]); i_args += 4; break; } - case 66: { - // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: proofvalue + case 79: { + // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: proofvalue3 Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], proofValues[args[i_args + 3]]); i_args += 4; break; } - case 67: { + case 80: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: airgroupvalue Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], airgroupValues[args[i_args + 3]]); i_args += 4; break; } - case 68: { + case 81: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: airvalue3 Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], airValues[args[i_args + 3]]); i_args += 4; break; } - case 69: { - // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: proofvalue + case 82: { + // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: proofvalue3 Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], proofValues[args[i_args + 3]]); i_args += 4; break; } - case 70: { + case 83: { // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: airvalue3 Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], airValues[args[i_args + 2]], airValues[args[i_args + 3]]); i_args += 4; break; } - case 71: { - // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: proofvalue + case 84: { + // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: proofvalue3 Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], airValues[args[i_args + 2]], proofValues[args[i_args + 3]]); i_args += 4; break; } - case 72: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: proofvalue + case 85: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: proofvalue3 Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], proofValues[args[i_args + 2]], proofValues[args[i_args + 3]]); i_args += 4; break; } - case 73: { + case 86: { // COPY eval to tmp3 Goldilocks3::copy_avx512(tmp3[args[i_args]], evals[args[i_args + 1]]); i_args += 2; break; } - case 74: { + case 87: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: eval Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], challenges[args[i_args + 2]], evals[args[i_args + 3]]); i_args += 4; break; } - case 75: { + case 88: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: eval Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], tmp3[args[i_args + 2]], evals[args[i_args + 3]]); i_args += 4; break; } - case 76: { + case 89: { // OPERATION WITH DEST: tmp3 - SRC0: eval - SRC1: commit1 Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], evals[args[i_args + 2]], bufferT_[nColsStagesAcc[args[i_args + 3]] + args[i_args + 4]]); i_args += 5; break; } - case 77: { + case 90: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: eval Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], (Goldilocks3::Element_avx512 &)bufferT_[nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]], evals[args[i_args + 4]]); i_args += 5; break; } - case 78: { + case 91: { // OPERATION WITH DEST: tmp3 - SRC0: eval - SRC1: eval Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], evals[args[i_args + 2]], evals[args[i_args + 3]]); i_args += 4; break; } - case 79: { + case 92: { // OPERATION WITH DEST: tmp3 - SRC0: eval - SRC1: public Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], evals[args[i_args + 2]], publics[args[i_args + 3]]); i_args += 4; break; } - case 80: { + case 93: { // OPERATION WITH DEST: tmp3 - SRC0: eval - SRC1: number Goldilocks3::op_31_avx512(args[i_args], tmp3[args[i_args + 1]], evals[args[i_args + 2]], numbers_[args[i_args + 3]]); i_args += 4; break; } - case 81: { + case 94: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: eval Goldilocks3::op_avx512(args[i_args], tmp3[args[i_args + 1]], airgroupValues[args[i_args + 2]], evals[args[i_args + 3]]); i_args += 4; diff --git a/pil2-stark/src/starkpil/expressions_pack.hpp b/pil2-stark/src/starkpil/expressions_pack.hpp index 5e9a3b41..84371e14 100644 --- a/pil2-stark/src/starkpil/expressions_pack.hpp +++ b/pil2-stark/src/starkpil/expressions_pack.hpp @@ -219,7 +219,7 @@ class ExpressionsPack : public ExpressionsCtx { Goldilocks3::op_31_pack(nrowsPack, 2, &vals[0], &destVals[0], &destVals[FIELD_EXTENSION*nrowsPack]); } else { Goldilocks3::op_31_pack(nrowsPack, 2, &vals[0], &destVals[FIELD_EXTENSION*nrowsPack], &destVals[0]); - } + } Goldilocks::copy_pack(nrowsPack, &destVals[0], &vals[0]); Goldilocks::copy_pack(nrowsPack, &destVals[nrowsPack], &vals[nrowsPack]); Goldilocks::copy_pack(nrowsPack, &destVals[2*nrowsPack], &vals[2*nrowsPack]); @@ -319,8 +319,8 @@ class ExpressionsPack : public ExpressionsCtx { } Goldilocks::Element airgroupValues[setupCtx.starkInfo.airgroupValuesMap.size()*FIELD_EXTENSION*nrowsPack]; - uint64_t p = 0; if(!compilation_time) { + uint64_t p = 0; for(uint64_t i = 0; i < setupCtx.starkInfo.airgroupValuesMap.size(); ++i) { for(uint64_t j = 0; j < nrowsPack; ++j) { if(setupCtx.starkInfo.airgroupValuesMap[i].stage == 1) { @@ -340,18 +340,27 @@ class ExpressionsPack : public ExpressionsCtx { Goldilocks::Element proofValues[setupCtx.starkInfo.proofValuesMap.size()*FIELD_EXTENSION*nrowsPack]; if(!compilation_time) { + uint64_t p = 0; for(uint64_t i = 0; i < setupCtx.starkInfo.proofValuesMap.size(); ++i) { for(uint64_t j = 0; j < nrowsPack; ++j) { - proofValues[(i*FIELD_EXTENSION)*nrowsPack + j] = params.proofValues[i * FIELD_EXTENSION]; - proofValues[(i*FIELD_EXTENSION + 1)*nrowsPack + j] = params.proofValues[i * FIELD_EXTENSION + 1]; - proofValues[(i*FIELD_EXTENSION + 2)*nrowsPack + j] = params.proofValues[i * FIELD_EXTENSION + 2]; + if(setupCtx.starkInfo.proofValuesMap[i].stage == 1) { + proofValues[(i*FIELD_EXTENSION)*nrowsPack + j] = params.proofValues[p]; + proofValues[(i*FIELD_EXTENSION + 1)*nrowsPack + j] = Goldilocks::zero(); + proofValues[(i*FIELD_EXTENSION + 2)*nrowsPack + j] = Goldilocks::zero(); + p += 1; + } else { + proofValues[(i*FIELD_EXTENSION)*nrowsPack + j] = params.proofValues[p]; + proofValues[(i*FIELD_EXTENSION + 1)*nrowsPack + j] = params.proofValues[p + 1]; + proofValues[(i*FIELD_EXTENSION + 2)*nrowsPack + j] = params.proofValues[p + 2]; + p += 3; + } } } } Goldilocks::Element airValues[setupCtx.starkInfo.airValuesMap.size()*FIELD_EXTENSION*nrowsPack]; - p = 0; if(!compilation_time) { + uint64_t p = 0; for(uint64_t i = 0; i < setupCtx.starkInfo.airValuesMap.size(); ++i) { for(uint64_t j = 0; j < nrowsPack; ++j) { if(setupCtx.starkInfo.airValuesMap[i].stage == 1) { @@ -386,7 +395,7 @@ class ExpressionsPack : public ExpressionsCtx { uint64_t openingPointIndex = dests[j].params[k].rowOffsetIndex; uint64_t buffPos = ns*openingPointIndex + dests[j].params[k].stage; uint64_t stagePos = dests[j].params[k].stagePos; - copyPolynomial(&destVals[j][k*FIELD_EXTENSION*nrowsPack], dests[j].params[k].inverse, dests[j].params[k].batch, dests[j].params[k].dim, &bufferT_[(nColsStagesAcc[buffPos] + stagePos)*nrowsPack]); + copyPolynomial(&destVals[j][k*FIELD_EXTENSION*nrowsPack], dests[j].params[k].inverse,dests[j].params[k].batch,dests[j].params[k].dim, &bufferT_[(nColsStagesAcc[buffPos] + stagePos)*nrowsPack]); continue; } else if(dests[j].params[k].op == opType::number) { for(uint64_t r = 0; r < nrowsPack; ++r) { @@ -439,456 +448,534 @@ class ExpressionsPack : public ExpressionsCtx { break; } case 6: { + // OPERATION WITH DEST: tmp1 - SRC0: commit1 - SRC1: proofvalue1 + Goldilocks::op_pack(nrowsPack, args[i_args], &tmp1[args[i_args + 1] * nrowsPack], &bufferT_[(nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]) * nrowsPack], &proofValues[args[i_args + 4] * nrowsPack * FIELD_EXTENSION]); + i_args += 5; + break; + } + case 7: { // COPY tmp1 to tmp1 Goldilocks::copy_pack(nrowsPack, &tmp1[args[i_args] * nrowsPack], &tmp1[args[i_args + 1] * nrowsPack]); i_args += 2; break; } - case 7: { + case 8: { // OPERATION WITH DEST: tmp1 - SRC0: tmp1 - SRC1: tmp1 Goldilocks::op_pack(nrowsPack, args[i_args], &tmp1[args[i_args + 1] * nrowsPack], &tmp1[args[i_args + 2] * nrowsPack], &tmp1[args[i_args + 3] * nrowsPack]); i_args += 4; break; } - case 8: { + case 9: { // OPERATION WITH DEST: tmp1 - SRC0: tmp1 - SRC1: public Goldilocks::op_pack(nrowsPack, args[i_args], &tmp1[args[i_args + 1] * nrowsPack], &tmp1[args[i_args + 2] * nrowsPack], &publics[args[i_args + 3] * nrowsPack]); i_args += 4; break; } - case 9: { + case 10: { // OPERATION WITH DEST: tmp1 - SRC0: tmp1 - SRC1: number Goldilocks::op_pack(nrowsPack, args[i_args], &tmp1[args[i_args + 1] * nrowsPack], &tmp1[args[i_args + 2] * nrowsPack], &numbers_[args[i_args + 3]*nrowsPack]); i_args += 4; break; } - case 10: { + case 11: { // OPERATION WITH DEST: tmp1 - SRC0: tmp1 - SRC1: airvalue1 Goldilocks::op_pack(nrowsPack, args[i_args], &tmp1[args[i_args + 1] * nrowsPack], &tmp1[args[i_args + 2] * nrowsPack], &airValues[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 11: { + case 12: { + // OPERATION WITH DEST: tmp1 - SRC0: tmp1 - SRC1: proofvalue1 + Goldilocks::op_pack(nrowsPack, args[i_args], &tmp1[args[i_args + 1] * nrowsPack], &tmp1[args[i_args + 2] * nrowsPack], &proofValues[args[i_args + 3] * nrowsPack * FIELD_EXTENSION]); + i_args += 4; + break; + } + case 13: { // COPY public to tmp1 Goldilocks::copy_pack(nrowsPack, &tmp1[args[i_args] * nrowsPack], &publics[args[i_args + 1] * nrowsPack]); i_args += 2; break; } - case 12: { + case 14: { // OPERATION WITH DEST: tmp1 - SRC0: public - SRC1: public Goldilocks::op_pack(nrowsPack, args[i_args], &tmp1[args[i_args + 1] * nrowsPack], &publics[args[i_args + 2] * nrowsPack], &publics[args[i_args + 3] * nrowsPack]); i_args += 4; break; } - case 13: { + case 15: { // OPERATION WITH DEST: tmp1 - SRC0: public - SRC1: number Goldilocks::op_pack(nrowsPack, args[i_args], &tmp1[args[i_args + 1] * nrowsPack], &publics[args[i_args + 2] * nrowsPack], &numbers_[args[i_args + 3]*nrowsPack]); i_args += 4; break; } - case 14: { + case 16: { // OPERATION WITH DEST: tmp1 - SRC0: public - SRC1: airvalue1 Goldilocks::op_pack(nrowsPack, args[i_args], &tmp1[args[i_args + 1] * nrowsPack], &publics[args[i_args + 2] * nrowsPack], &airValues[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 15: { + case 17: { + // OPERATION WITH DEST: tmp1 - SRC0: public - SRC1: proofvalue1 + Goldilocks::op_pack(nrowsPack, args[i_args], &tmp1[args[i_args + 1] * nrowsPack], &publics[args[i_args + 2] * nrowsPack], &proofValues[args[i_args + 3] * nrowsPack * FIELD_EXTENSION]); + i_args += 4; + break; + } + case 18: { // COPY number to tmp1 Goldilocks::copy_pack(nrowsPack, &tmp1[args[i_args] * nrowsPack], &numbers_[args[i_args + 1]*nrowsPack]); i_args += 2; break; } - case 16: { + case 19: { // OPERATION WITH DEST: tmp1 - SRC0: number - SRC1: number Goldilocks::op_pack(nrowsPack, args[i_args], &tmp1[args[i_args + 1] * nrowsPack], &numbers_[args[i_args + 2]*nrowsPack], &numbers_[args[i_args + 3]*nrowsPack]); i_args += 4; break; } - case 17: { + case 20: { // OPERATION WITH DEST: tmp1 - SRC0: number - SRC1: airvalue1 Goldilocks::op_pack(nrowsPack, args[i_args], &tmp1[args[i_args + 1] * nrowsPack], &numbers_[args[i_args + 2]*nrowsPack], &airValues[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 18: { + case 21: { + // OPERATION WITH DEST: tmp1 - SRC0: number - SRC1: proofvalue1 + Goldilocks::op_pack(nrowsPack, args[i_args], &tmp1[args[i_args + 1] * nrowsPack], &numbers_[args[i_args + 2]*nrowsPack], &proofValues[args[i_args + 3] * nrowsPack * FIELD_EXTENSION]); + i_args += 4; + break; + } + case 22: { // COPY airvalue1 to tmp1 Goldilocks::copy_pack(nrowsPack, &tmp1[args[i_args] * nrowsPack], &airValues[args[i_args + 1]*FIELD_EXTENSION*nrowsPack]); i_args += 2; break; } - case 19: { + case 23: { // OPERATION WITH DEST: tmp1 - SRC0: airvalue1 - SRC1: airvalue1 Goldilocks::op_pack(nrowsPack, args[i_args], &tmp1[args[i_args + 1] * nrowsPack], &airValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &airValues[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 20: { + case 24: { + // OPERATION WITH DEST: tmp1 - SRC0: airvalue1 - SRC1: proofvalue1 + Goldilocks::op_pack(nrowsPack, args[i_args], &tmp1[args[i_args + 1] * nrowsPack], &airValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &proofValues[args[i_args + 3] * nrowsPack * FIELD_EXTENSION]); + i_args += 4; + break; + } + case 25: { + // COPY proofvalue1 to tmp1 + Goldilocks::copy_pack(nrowsPack, &tmp1[args[i_args] * nrowsPack], &proofValues[args[i_args + 1] * nrowsPack * FIELD_EXTENSION]); + i_args += 2; + break; + } + case 26: { + // OPERATION WITH DEST: tmp1 - SRC0: proofvalue1 - SRC1: proofvalue1 + Goldilocks::op_pack(nrowsPack, args[i_args], &tmp1[args[i_args + 1] * nrowsPack], &proofValues[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &proofValues[args[i_args + 3] * nrowsPack * FIELD_EXTENSION]); + i_args += 4; + break; + } + case 27: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: commit1 Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &bufferT_[(nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]) * nrowsPack], &bufferT_[(nColsStagesAcc[args[i_args + 4]] + args[i_args + 5]) * nrowsPack]); i_args += 6; break; } - case 21: { + case 28: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: tmp1 Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &bufferT_[(nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]) * nrowsPack], &tmp1[args[i_args + 4] * nrowsPack]); i_args += 5; break; } - case 22: { + case 29: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: public Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &bufferT_[(nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]) * nrowsPack], &publics[args[i_args + 4] * nrowsPack]); i_args += 5; break; } - case 23: { + case 30: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: number Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &bufferT_[(nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]) * nrowsPack], &numbers_[args[i_args + 4]*nrowsPack]); i_args += 5; break; } - case 24: { + case 31: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: airvalue1 Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &bufferT_[(nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]) * nrowsPack], &airValues[args[i_args + 4]*FIELD_EXTENSION*nrowsPack]); i_args += 5; break; } - case 25: { + case 32: { + // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: proofvalue1 + Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &bufferT_[(nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]) * nrowsPack], &proofValues[args[i_args + 4] * nrowsPack * FIELD_EXTENSION]); + i_args += 5; + break; + } + case 33: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: commit1 Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &tmp3[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &bufferT_[(nColsStagesAcc[args[i_args + 3]] + args[i_args + 4]) * nrowsPack]); i_args += 5; break; } - case 26: { + case 34: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: tmp1 Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &tmp3[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &tmp1[args[i_args + 3] * nrowsPack]); i_args += 4; break; } - case 27: { + case 35: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: public Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &tmp3[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &publics[args[i_args + 3] * nrowsPack]); i_args += 4; break; } - case 28: { + case 36: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: number Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &tmp3[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &numbers_[args[i_args + 3]*nrowsPack]); i_args += 4; break; } - case 29: { + case 37: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: airvalue1 Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &tmp3[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &airValues[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 30: { + case 38: { + // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: proofvalue1 + Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &tmp3[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &proofValues[args[i_args + 3] * nrowsPack * FIELD_EXTENSION]); + i_args += 4; + break; + } + case 39: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: commit1 Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &challenges[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &bufferT_[(nColsStagesAcc[args[i_args + 3]] + args[i_args + 4]) * nrowsPack]); i_args += 5; break; } - case 31: { + case 40: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: tmp1 Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &challenges[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &tmp1[args[i_args + 3] * nrowsPack]); i_args += 4; break; } - case 32: { + case 41: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: public Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &challenges[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &publics[args[i_args + 3] * nrowsPack]); i_args += 4; break; } - case 33: { + case 42: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: number Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &challenges[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &numbers_[args[i_args + 3]*nrowsPack]); i_args += 4; break; } - case 34: { + case 43: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: airvalue1 Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &challenges[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &airValues[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 35: { + case 44: { + // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: proofvalue1 + Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &challenges[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &proofValues[args[i_args + 3] * nrowsPack * FIELD_EXTENSION]); + i_args += 4; + break; + } + case 45: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: commit1 Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &airgroupValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &bufferT_[(nColsStagesAcc[args[i_args + 3]] + args[i_args + 4]) * nrowsPack]); i_args += 5; break; } - case 36: { + case 46: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: tmp1 Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &airgroupValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &tmp1[args[i_args + 3] * nrowsPack]); i_args += 4; break; } - case 37: { + case 47: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: public Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &airgroupValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &publics[args[i_args + 3] * nrowsPack]); i_args += 4; break; } - case 38: { + case 48: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: number Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &airgroupValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &numbers_[args[i_args + 3]*nrowsPack]); i_args += 4; break; } - case 39: { + case 49: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: airvalue1 Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &airgroupValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &airValues[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 40: { + case 50: { + // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: proofvalue1 + Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &airgroupValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &proofValues[args[i_args + 3] * nrowsPack * FIELD_EXTENSION]); + i_args += 4; + break; + } + case 51: { // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: commit1 Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &airValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &bufferT_[(nColsStagesAcc[args[i_args + 3]] + args[i_args + 4]) * nrowsPack]); i_args += 5; break; } - case 41: { + case 52: { // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: tmp1 Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &airValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &tmp1[args[i_args + 3] * nrowsPack]); i_args += 4; break; } - case 42: { + case 53: { // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: public Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &airValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &publics[args[i_args + 3] * nrowsPack]); i_args += 4; break; } - case 43: { + case 54: { // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: number Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &airValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &numbers_[args[i_args + 3]*nrowsPack]); i_args += 4; break; } - case 44: { + case 55: { // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: airvalue1 Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &airValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &airValues[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 45: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: commit1 + case 56: { + // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: proofvalue1 + Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &airValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &proofValues[args[i_args + 3] * nrowsPack * FIELD_EXTENSION]); + i_args += 4; + break; + } + case 57: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: commit1 Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &proofValues[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &bufferT_[(nColsStagesAcc[args[i_args + 3]] + args[i_args + 4]) * nrowsPack]); i_args += 5; break; } - case 46: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: tmp1 + case 58: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: tmp1 Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &proofValues[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &tmp1[args[i_args + 3] * nrowsPack]); i_args += 4; break; } - case 47: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: public + case 59: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: public Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &proofValues[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &publics[args[i_args + 3] * nrowsPack]); i_args += 4; break; } - case 48: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: number + case 60: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: number Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &proofValues[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &numbers_[args[i_args + 3]*nrowsPack]); i_args += 4; break; } - case 49: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: airvalue1 + case 61: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: airvalue1 Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &proofValues[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &airValues[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 50: { + case 62: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: proofvalue1 + Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &proofValues[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &proofValues[args[i_args + 3] * nrowsPack * FIELD_EXTENSION]); + i_args += 4; + break; + } + case 63: { // COPY commit3 to tmp3 Goldilocks3::copy_pack(nrowsPack, &tmp3[args[i_args] * nrowsPack * FIELD_EXTENSION], &bufferT_[(nColsStagesAcc[args[i_args + 1]] + args[i_args + 2]) * nrowsPack]); i_args += 3; break; } - case 51: { + case 64: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: commit3 Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &bufferT_[(nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]) * nrowsPack], &bufferT_[(nColsStagesAcc[args[i_args + 4]] + args[i_args + 5]) * nrowsPack]); i_args += 6; break; } - case 52: { + case 65: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: tmp3 Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &bufferT_[(nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]) * nrowsPack], &tmp3[args[i_args + 4] * nrowsPack * FIELD_EXTENSION]); i_args += 5; break; } - case 53: { + case 66: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: challenge Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &bufferT_[(nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]) * nrowsPack], &challenges[args[i_args + 4]*FIELD_EXTENSION*nrowsPack]); i_args += 5; break; } - case 54: { + case 67: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: airgroupvalue Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &bufferT_[(nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]) * nrowsPack], &airgroupValues[args[i_args + 4]*FIELD_EXTENSION*nrowsPack]); i_args += 5; break; } - case 55: { + case 68: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: airvalue3 Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &bufferT_[(nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]) * nrowsPack], &airValues[args[i_args + 4]*FIELD_EXTENSION*nrowsPack]); i_args += 5; break; } - case 56: { - // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: proofvalue + case 69: { + // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: proofvalue3 Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &bufferT_[(nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]) * nrowsPack], &proofValues[args[i_args + 4] * nrowsPack * FIELD_EXTENSION]); i_args += 5; break; } - case 57: { + case 70: { // COPY tmp3 to tmp3 Goldilocks3::copy_pack(nrowsPack, &tmp3[args[i_args] * nrowsPack * FIELD_EXTENSION], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION]); i_args += 2; break; } - case 58: { + case 71: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: tmp3 Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &tmp3[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &tmp3[args[i_args + 3] * nrowsPack * FIELD_EXTENSION]); i_args += 4; break; } - case 59: { + case 72: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: challenge Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &tmp3[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &challenges[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 60: { + case 73: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: airgroupvalue Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &tmp3[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &airgroupValues[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 61: { + case 74: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: airvalue3 Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &tmp3[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &airValues[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 62: { - // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: proofvalue + case 75: { + // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: proofvalue3 Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &tmp3[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &proofValues[args[i_args + 3] * nrowsPack * FIELD_EXTENSION]); i_args += 4; break; } - case 63: { + case 76: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: challenge Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &challenges[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &challenges[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 64: { + case 77: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: airgroupvalue Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &challenges[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &airgroupValues[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 65: { + case 78: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: airvalue3 Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &challenges[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &airValues[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 66: { - // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: proofvalue + case 79: { + // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: proofvalue3 Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &challenges[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &proofValues[args[i_args + 3] * nrowsPack * FIELD_EXTENSION]); i_args += 4; break; } - case 67: { + case 80: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: airgroupvalue Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &airgroupValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &airgroupValues[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 68: { + case 81: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: airvalue3 Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &airgroupValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &airValues[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 69: { - // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: proofvalue + case 82: { + // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: proofvalue3 Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &airgroupValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &proofValues[args[i_args + 3] * nrowsPack * FIELD_EXTENSION]); i_args += 4; break; } - case 70: { + case 83: { // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: airvalue3 Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &airValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &airValues[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 71: { - // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: proofvalue + case 84: { + // OPERATION WITH DEST: tmp3 - SRC0: airvalue3 - SRC1: proofvalue3 Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &airValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &proofValues[args[i_args + 3] * nrowsPack * FIELD_EXTENSION]); i_args += 4; break; } - case 72: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: proofvalue + case 85: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: proofvalue3 Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &proofValues[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &proofValues[args[i_args + 3] * nrowsPack * FIELD_EXTENSION]); i_args += 4; break; } - case 73: { + case 86: { // COPY eval to tmp3 Goldilocks3::copy_pack(nrowsPack, &tmp3[args[i_args] * nrowsPack * FIELD_EXTENSION], &evals[args[i_args + 1]*FIELD_EXTENSION*nrowsPack]); i_args += 2; break; } - case 74: { + case 87: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: eval Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &challenges[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &evals[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 75: { + case 88: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: eval Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &tmp3[args[i_args + 2] * nrowsPack * FIELD_EXTENSION], &evals[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 76: { + case 89: { // OPERATION WITH DEST: tmp3 - SRC0: eval - SRC1: commit1 Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &evals[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &bufferT_[(nColsStagesAcc[args[i_args + 3]] + args[i_args + 4]) * nrowsPack]); i_args += 5; break; } - case 77: { + case 90: { // OPERATION WITH DEST: tmp3 - SRC0: commit3 - SRC1: eval Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &bufferT_[(nColsStagesAcc[args[i_args + 2]] + args[i_args + 3]) * nrowsPack], &evals[args[i_args + 4]*FIELD_EXTENSION*nrowsPack]); i_args += 5; break; } - case 78: { + case 91: { // OPERATION WITH DEST: tmp3 - SRC0: eval - SRC1: eval Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &evals[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &evals[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; break; } - case 79: { + case 92: { // OPERATION WITH DEST: tmp3 - SRC0: eval - SRC1: public Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &evals[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &publics[args[i_args + 3] * nrowsPack]); i_args += 4; break; } - case 80: { + case 93: { // OPERATION WITH DEST: tmp3 - SRC0: eval - SRC1: number Goldilocks3::op_31_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &evals[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &numbers_[args[i_args + 3]*nrowsPack]); i_args += 4; break; } - case 81: { + case 94: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: eval Goldilocks3::op_pack(nrowsPack, args[i_args], &tmp3[args[i_args + 1] * nrowsPack * FIELD_EXTENSION], &airgroupValues[args[i_args + 2]*FIELD_EXTENSION*nrowsPack], &evals[args[i_args + 3]*FIELD_EXTENSION*nrowsPack]); i_args += 4; @@ -905,12 +992,11 @@ class ExpressionsPack : public ExpressionsCtx { assert(i_args == dests[j].params[k].parserParams.nArgs); if(dests[j].params[k].parserParams.destDim == 1) { - copyPolynomial(&destVals[j][k*FIELD_EXTENSION*nrowsPack], dests[j].params[k].inverse, dests[j].params[k].batch, dests[j].params[k].parserParams.destDim, &tmp1[dests[j].params[k].parserParams.destId*nrowsPack]); + copyPolynomial(&destVals[j][k*FIELD_EXTENSION*nrowsPack], dests[j].params[k].inverse,dests[j].params[k].batch, dests[j].params[k].parserParams.destDim, &tmp1[dests[j].params[k].parserParams.destId*nrowsPack]); } else { - copyPolynomial(&destVals[j][k*FIELD_EXTENSION*nrowsPack], dests[j].params[k].inverse, dests[j].params[k].batch, dests[j].params[k].parserParams.destDim, &tmp3[dests[j].params[k].parserParams.destId*FIELD_EXTENSION*nrowsPack]); + copyPolynomial(&destVals[j][k*FIELD_EXTENSION*nrowsPack], dests[j].params[k].inverse,dests[j].params[k].batch, dests[j].params[k].parserParams.destDim, &tmp3[dests[j].params[k].parserParams.destId*FIELD_EXTENSION*nrowsPack]); } } - if(dests[j].params.size() == 2) { multiplyPolynomials(dests[j], destVals[j]); } diff --git a/pil2-stark/src/starkpil/global_constraints.hpp b/pil2-stark/src/starkpil/global_constraints.hpp index 5da82d87..1e4a15d7 100644 --- a/pil2-stark/src/starkpil/global_constraints.hpp +++ b/pil2-stark/src/starkpil/global_constraints.hpp @@ -19,7 +19,7 @@ struct GlobalConstraintsResults { GlobalConstraintInfo* constraintInfo; }; -void calculateGlobalExpression(Goldilocks::Element* dest, Goldilocks::Element* publics, Goldilocks::Element* challenges, Goldilocks::Element* proofValues, Goldilocks::Element** airgroupValues, ParserArgs &parserArgs, ParserParams &parserParams) { +void calculateGlobalExpression(json& globalInfo, Goldilocks::Element* dest, Goldilocks::Element* publics, Goldilocks::Element* challenges, Goldilocks::Element* proofValues_, Goldilocks::Element** airgroupValues, ParserArgs &parserArgs, ParserParams &parserParams) { uint8_t* ops = &parserArgs.ops[parserParams.opsOffset]; uint16_t* args = &parserArgs.args[parserParams.argsOffset]; @@ -29,6 +29,22 @@ void calculateGlobalExpression(Goldilocks::Element* dest, Goldilocks::Element* p Goldilocks::Element tmp1[parserParams.nTemp1]; Goldilocks::Element tmp3[parserParams.nTemp3*FIELD_EXTENSION]; + Goldilocks::Element proofValues[globalInfo["proofValuesMap"].size()*FIELD_EXTENSION]; + uint64_t p = 0; + for(uint64_t i = 0; i < globalInfo["proofValuesMap"].size(); ++i) { + if(globalInfo["proofValuesMap"][i]["stage"] == 1) { + proofValues[i*FIELD_EXTENSION] = proofValues_[p]; + proofValues[i*FIELD_EXTENSION + 1] = Goldilocks::zero(); + proofValues[i*FIELD_EXTENSION + 2] = Goldilocks::zero(); + p += 1; + } else { + proofValues[i*FIELD_EXTENSION] = proofValues_[p]; + proofValues[i*FIELD_EXTENSION + 1] = proofValues_[p + 1]; + proofValues[i*FIELD_EXTENSION + 2] = proofValues_[p + 2]; + p += 3; + } + } + Goldilocks::Element numbers_[parserArgs.nNumbers]; for(uint64_t i = 0; i < parserArgs.nNumbers; ++i) { numbers_[i] = Goldilocks::fromU64(parserArgs.numbers[i]); @@ -55,159 +71,203 @@ void calculateGlobalExpression(Goldilocks::Element* dest, Goldilocks::Element* p break; } case 3: { + // OPERATION WITH DEST: tmp1 - SRC0: tmp1 - SRC1: proofvalue1 + Goldilocks::op_pack(1, args[i_args], &tmp1[args[i_args + 1]], &tmp1[args[i_args + 2]], &proofValues[args[i_args + 3] * FIELD_EXTENSION]); + i_args += 4; + break; + } + case 4: { // OPERATION WITH DEST: tmp1 - SRC0: public - SRC1: public Goldilocks::op_pack(1, args[i_args], &tmp1[args[i_args + 1]], &publics[args[i_args + 2]], &publics[args[i_args + 3]]); i_args += 4; break; } - case 4: { + case 5: { // OPERATION WITH DEST: tmp1 - SRC0: public - SRC1: number Goldilocks::op_pack(1, args[i_args], &tmp1[args[i_args + 1]], &publics[args[i_args + 2]], &numbers_[args[i_args + 3]]); i_args += 4; break; } - case 5: { + case 6: { + // OPERATION WITH DEST: tmp1 - SRC0: public - SRC1: proofvalue1 + Goldilocks::op_pack(1, args[i_args], &tmp1[args[i_args + 1]], &publics[args[i_args + 2]], &proofValues[args[i_args + 3] * FIELD_EXTENSION]); + i_args += 4; + break; + } + case 7: { // OPERATION WITH DEST: tmp1 - SRC0: number - SRC1: number Goldilocks::op_pack(1, args[i_args], &tmp1[args[i_args + 1]], &numbers_[args[i_args + 2]], &numbers_[args[i_args + 3]]); i_args += 4; break; } - case 6: { + case 8: { + // OPERATION WITH DEST: tmp1 - SRC0: number - SRC1: proofvalue1 + Goldilocks::op_pack(1, args[i_args], &tmp1[args[i_args + 1]], &numbers_[args[i_args + 2]], &proofValues[args[i_args + 3] * FIELD_EXTENSION]); + i_args += 4; + break; + } + case 9: { + // OPERATION WITH DEST: tmp1 - SRC0: proofvalue1 - SRC1: proofvalue1 + Goldilocks::op_pack(1, args[i_args], &tmp1[args[i_args + 1]], &proofValues[args[i_args + 2] * FIELD_EXTENSION], &proofValues[args[i_args + 3] * FIELD_EXTENSION]); + i_args += 4; + break; + } + case 10: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: tmp1 Goldilocks3::op_31_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &tmp3[args[i_args + 2] * FIELD_EXTENSION], &tmp1[args[i_args + 3]]); i_args += 4; break; } - case 7: { + case 11: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: public Goldilocks3::op_31_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &tmp3[args[i_args + 2] * FIELD_EXTENSION], &publics[args[i_args + 3]]); i_args += 4; break; } - case 8: { + case 12: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: number Goldilocks3::op_31_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &tmp3[args[i_args + 2] * FIELD_EXTENSION], &numbers_[args[i_args + 3]]); i_args += 4; break; } - case 9: { + case 13: { + // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: proofvalue1 + Goldilocks3::op_31_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &tmp3[args[i_args + 2] * FIELD_EXTENSION], &proofValues[args[i_args + 3] * FIELD_EXTENSION]); + i_args += 4; + break; + } + case 14: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: tmp1 Goldilocks3::op_31_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &airgroupValues[args[i_args + 2]][args[i_args + 3] * FIELD_EXTENSION], &tmp1[args[i_args + 4]]); i_args += 5; break; } - case 10: { + case 15: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: public Goldilocks3::op_31_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &airgroupValues[args[i_args + 2]][args[i_args + 3] * FIELD_EXTENSION], &publics[args[i_args + 4]]); i_args += 5; break; } - case 11: { + case 16: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: number Goldilocks3::op_31_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &airgroupValues[args[i_args + 2]][args[i_args + 3] * FIELD_EXTENSION], &numbers_[args[i_args + 4]]); i_args += 5; break; } - case 12: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: tmp1 + case 17: { + // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: proofvalue1 + Goldilocks3::op_31_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &airgroupValues[args[i_args + 2]][args[i_args + 3] * FIELD_EXTENSION], &proofValues[args[i_args + 4] * FIELD_EXTENSION]); + i_args += 5; + break; + } + case 18: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: tmp1 Goldilocks3::op_31_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &proofValues[args[i_args + 2] * FIELD_EXTENSION], &tmp1[args[i_args + 3]]); i_args += 4; break; } - case 13: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: public + case 19: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: public Goldilocks3::op_31_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &proofValues[args[i_args + 2] * FIELD_EXTENSION], &publics[args[i_args + 3]]); i_args += 4; break; } - case 14: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: number + case 20: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: number Goldilocks3::op_31_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &proofValues[args[i_args + 2] * FIELD_EXTENSION], &numbers_[args[i_args + 3]]); i_args += 4; break; } - case 15: { + case 21: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: proofvalue1 + Goldilocks3::op_31_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &proofValues[args[i_args + 2] * FIELD_EXTENSION], &proofValues[args[i_args + 3] * FIELD_EXTENSION]); + i_args += 4; + break; + } + case 22: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: tmp1 Goldilocks3::op_31_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &challenges[args[i_args + 2]*FIELD_EXTENSION], &tmp1[args[i_args + 3]]); i_args += 4; break; } - case 16: { + case 23: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: public Goldilocks3::op_31_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &challenges[args[i_args + 2]*FIELD_EXTENSION], &publics[args[i_args + 3]]); i_args += 4; break; } - case 17: { + case 24: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: number Goldilocks3::op_31_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &challenges[args[i_args + 2]*FIELD_EXTENSION], &numbers_[args[i_args + 3]]); i_args += 4; break; } - case 18: { + case 25: { + // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: proofvalue1 + Goldilocks3::op_31_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &challenges[args[i_args + 2]*FIELD_EXTENSION], &proofValues[args[i_args + 3] * FIELD_EXTENSION]); + i_args += 4; + break; + } + case 26: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: tmp3 Goldilocks3::op_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &tmp3[args[i_args + 2] * FIELD_EXTENSION], &tmp3[args[i_args + 3] * FIELD_EXTENSION]); i_args += 4; break; } - case 19: { + case 27: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: airgroupvalue Goldilocks3::op_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &tmp3[args[i_args + 2] * FIELD_EXTENSION], &airgroupValues[args[i_args + 3]][args[i_args + 4] * FIELD_EXTENSION]); i_args += 5; break; } - case 20: { - // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: proofvalue + case 28: { + // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: proofvalue3 Goldilocks3::op_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &tmp3[args[i_args + 2] * FIELD_EXTENSION], &proofValues[args[i_args + 3] * FIELD_EXTENSION]); i_args += 4; break; } - case 21: { + case 29: { // OPERATION WITH DEST: tmp3 - SRC0: tmp3 - SRC1: challenge Goldilocks3::op_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &tmp3[args[i_args + 2] * FIELD_EXTENSION], &challenges[args[i_args + 3]*FIELD_EXTENSION]); i_args += 4; break; } - case 22: { + case 30: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: airgroupvalue Goldilocks3::op_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &airgroupValues[args[i_args + 2]][args[i_args + 3] * FIELD_EXTENSION], &airgroupValues[args[i_args + 4]][args[i_args + 5] * FIELD_EXTENSION]); i_args += 6; break; } - case 23: { - // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: proofvalue + case 31: { + // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: proofvalue3 Goldilocks3::op_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &airgroupValues[args[i_args + 2]][args[i_args + 3] * FIELD_EXTENSION], &proofValues[args[i_args + 4] * FIELD_EXTENSION]); i_args += 5; break; } - case 24: { + case 32: { // OPERATION WITH DEST: tmp3 - SRC0: airgroupvalue - SRC1: challenge Goldilocks3::op_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &airgroupValues[args[i_args + 2]][args[i_args + 3] * FIELD_EXTENSION], &challenges[args[i_args + 4]*FIELD_EXTENSION]); i_args += 5; break; } - case 25: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: proofvalue + case 33: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: proofvalue3 Goldilocks3::op_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &proofValues[args[i_args + 2] * FIELD_EXTENSION], &proofValues[args[i_args + 3] * FIELD_EXTENSION]); i_args += 4; break; } - case 26: { - // OPERATION WITH DEST: tmp3 - SRC0: proofvalue - SRC1: challenge + case 34: { + // OPERATION WITH DEST: tmp3 - SRC0: proofvalue3 - SRC1: challenge Goldilocks3::op_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &proofValues[args[i_args + 2] * FIELD_EXTENSION], &challenges[args[i_args + 3]*FIELD_EXTENSION]); i_args += 4; break; } - case 27: { + case 35: { // OPERATION WITH DEST: tmp3 - SRC0: challenge - SRC1: challenge Goldilocks3::op_pack(1, args[i_args], &tmp3[args[i_args + 1] * FIELD_EXTENSION], &challenges[args[i_args + 2]*FIELD_EXTENSION], &challenges[args[i_args + 3]*FIELD_EXTENSION]); i_args += 4; break; } - default: { - std::cout << " Wrong operation!" << std::endl; - exit(1); - } } } @@ -222,7 +282,7 @@ void calculateGlobalExpression(Goldilocks::Element* dest, Goldilocks::Element* p } -GlobalConstraintInfo verifyGlobalConstraint(uint64_t constraintId, Goldilocks::Element* publics, Goldilocks::Element* challenges, Goldilocks::Element* proofValues, Goldilocks::Element** airgroupValues, ParserArgs &parserArgs, ParserParams &parserParams) { +GlobalConstraintInfo verifyGlobalConstraint(json& globalInfo, uint64_t constraintId, Goldilocks::Element* publics, Goldilocks::Element* challenges, Goldilocks::Element* proofValues, Goldilocks::Element** airgroupValues, ParserArgs &parserArgs, ParserParams &parserParams) { GlobalConstraintInfo constraintInfo; constraintInfo.id = constraintId; @@ -233,7 +293,7 @@ GlobalConstraintInfo verifyGlobalConstraint(uint64_t constraintId, Goldilocks::E Goldilocks::Element dest[parserParams.destDim]; - calculateGlobalExpression(dest, publics, challenges, proofValues, airgroupValues, parserArgs, parserParams); + calculateGlobalExpression(globalInfo, dest, publics, challenges, proofValues, airgroupValues, parserArgs, parserParams); if(parserParams.destDim == 1) { constraintInfo.dim = parserParams.destDim; @@ -253,9 +313,10 @@ GlobalConstraintInfo verifyGlobalConstraint(uint64_t constraintId, Goldilocks::E } -GlobalConstraintsResults * verifyGlobalConstraints(ExpressionsBin &globalConstraintsBin, Goldilocks::Element* publicInputs, Goldilocks::Element* challenges, Goldilocks::Element* proofValues, Goldilocks::Element** airgroupValues) +GlobalConstraintsResults * verifyGlobalConstraints(json& globalInfo, ExpressionsBin &globalConstraintsBin, Goldilocks::Element* publicInputs, Goldilocks::Element* challenges, Goldilocks::Element* proofValues, Goldilocks::Element** airgroupValues) { + std::vector globalConstraintsInfo = globalConstraintsBin.constraintsInfoDebug; GlobalConstraintsResults *constraintsInfo = new GlobalConstraintsResults(); @@ -263,7 +324,7 @@ GlobalConstraintsResults * verifyGlobalConstraints(ExpressionsBin &globalConstra constraintsInfo->constraintInfo = new GlobalConstraintInfo[constraintsInfo->nConstraints]; for(uint64_t i = 0; i < globalConstraintsInfo.size(); ++i) { - auto constraintInfo = verifyGlobalConstraint(i, publicInputs, challenges, proofValues, airgroupValues, globalConstraintsBin.expressionsBinArgsConstraints, globalConstraintsInfo[i]); + auto constraintInfo = verifyGlobalConstraint(globalInfo, i, publicInputs, challenges, proofValues, airgroupValues, globalConstraintsBin.expressionsBinArgsConstraints, globalConstraintsInfo[i]); constraintsInfo->constraintInfo[i] = constraintInfo; } @@ -271,7 +332,7 @@ GlobalConstraintsResults * verifyGlobalConstraints(ExpressionsBin &globalConstra } -HintFieldValues getHintFieldGlobalConstraint(ExpressionsBin &globalConstraintsBin, Goldilocks::Element* publicInputs, Goldilocks::Element* challenges, Goldilocks::Element* proofValues, Goldilocks::Element** airgroupValues, uint64_t hintId, std::string hintFieldName, bool print_expression) { +HintFieldValues getHintFieldGlobalConstraint(json& globalInfo, ExpressionsBin &globalConstraintsBin, Goldilocks::Element* publicInputs, Goldilocks::Element* challenges, Goldilocks::Element* proofValues, Goldilocks::Element** airgroupValues, uint64_t hintId, std::string hintFieldName, bool print_expression) { if(globalConstraintsBin.hints.size() == 0) { @@ -315,7 +376,7 @@ HintFieldValues getHintFieldGlobalConstraint(ExpressionsBin &globalConstraintsBi cout << "the expression with id: " << hintFieldVal.id << " " << globalConstraintsBin.expressionsInfo[hintFieldVal.id].line << endl; } - calculateGlobalExpression(hintFieldInfo.values, publicInputs, challenges, proofValues, airgroupValues, globalConstraintsBin.expressionsBinArgsExpressions, globalConstraintsBin.expressionsInfo[hintFieldVal.id]); + calculateGlobalExpression(globalInfo, hintFieldInfo.values, publicInputs, challenges, proofValues, airgroupValues, globalConstraintsBin.expressionsBinArgsExpressions, globalConstraintsBin.expressionsInfo[hintFieldVal.id]); } else if (hintFieldVal.operand == opType::public_) { hintFieldInfo.size = 1; hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; @@ -336,12 +397,12 @@ HintFieldValues getHintFieldGlobalConstraint(ExpressionsBin &globalConstraintsBi hintFieldInfo.offset = FIELD_EXTENSION; std::memcpy(hintFieldInfo.values, &airgroupValues[hintFieldVal.dim][FIELD_EXTENSION*hintFieldVal.id], FIELD_EXTENSION * sizeof(Goldilocks::Element)); } else if (hintFieldVal.operand == opType::proofvalue) { - hintFieldInfo.size = FIELD_EXTENSION; - hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; + uint64_t dim = globalInfo["proofValuesMap"][hintFieldVal.id]["stage"] == 1 ? 1 : FIELD_EXTENSION; + hintFieldInfo.size = dim; hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; - hintFieldInfo.fieldType = HintFieldType::FieldExtended; + hintFieldInfo.fieldType = dim == 1 ? HintFieldType::Field : HintFieldType::FieldExtended; hintFieldInfo.offset = FIELD_EXTENSION; - std::memcpy(hintFieldInfo.values, &proofValues[FIELD_EXTENSION*hintFieldVal.id], FIELD_EXTENSION * sizeof(Goldilocks::Element)); + std::memcpy(hintFieldInfo.values, &proofValues[FIELD_EXTENSION*hintFieldVal.id], hintFieldInfo.size * sizeof(Goldilocks::Element)); } else if (hintFieldVal.operand == opType::string_) { hintFieldInfo.values = nullptr; hintFieldInfo.fieldType = HintFieldType::String; @@ -370,7 +431,7 @@ HintFieldValues getHintFieldGlobalConstraint(ExpressionsBin &globalConstraintsBi } -uint64_t setHintFieldGlobalConstraint(ExpressionsBin &globalConstraintsBin, Goldilocks::Element* proofValues, Goldilocks::Element* values, uint64_t hintId, std::string hintFieldName) { +uint64_t setHintFieldGlobalConstraint(json& globalInfo, ExpressionsBin &globalConstraintsBin, Goldilocks::Element* proofValues, Goldilocks::Element* values, uint64_t hintId, std::string hintFieldName) { Hint hint = globalConstraintsBin.hints[hintId]; auto hintField = std::find_if(hint.fields.begin(), hint.fields.end(), [hintFieldName](const HintField& hintField) { diff --git a/pil2-stark/src/starkpil/hints.hpp b/pil2-stark/src/starkpil/hints.hpp index 23972991..65ca17a6 100644 --- a/pil2-stark/src/starkpil/hints.hpp +++ b/pil2-stark/src/starkpil/hints.hpp @@ -289,7 +289,7 @@ HintFieldValues getHintField( hintFieldInfo.size = dim; hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; hintFieldInfo.fieldType = dim == 1 ? HintFieldType::Field : HintFieldType::FieldExtended; - hintFieldInfo.offset = FIELD_EXTENSION; + hintFieldInfo.offset = dim; if(!hintOptions.dest) { if(hintOptions.inverse) { Goldilocks3::inv((Goldilocks3::Element *)hintFieldInfo.values, (Goldilocks3::Element *)¶ms.airgroupValues[FIELD_EXTENSION*hintFieldVal.id]); @@ -302,7 +302,7 @@ HintFieldValues getHintField( hintFieldInfo.size = dim; hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; hintFieldInfo.fieldType = dim == 1 ? HintFieldType::Field : HintFieldType::FieldExtended; - hintFieldInfo.offset = FIELD_EXTENSION; + hintFieldInfo.offset = dim; if(!hintOptions.dest) { if(hintOptions.inverse) { Goldilocks3::inv((Goldilocks3::Element *)hintFieldInfo.values, (Goldilocks3::Element *)¶ms.airValues[FIELD_EXTENSION*hintFieldVal.id]); @@ -311,11 +311,11 @@ HintFieldValues getHintField( } } } else if (hintFieldVal.operand == opType::proofvalue) { - uint64_t dim = 1; + uint64_t dim = setupCtx.starkInfo.proofValuesMap[hintFieldVal.id].stage == 1 ? 1 : FIELD_EXTENSION; hintFieldInfo.size = dim; hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; hintFieldInfo.fieldType = dim == 1 ? HintFieldType::Field : HintFieldType::FieldExtended; - hintFieldInfo.offset = FIELD_EXTENSION; + hintFieldInfo.offset = dim; if(!hintOptions.dest) { if(hintOptions.inverse) { Goldilocks3::inv((Goldilocks3::Element *)hintFieldInfo.values, (Goldilocks3::Element *)¶ms.proofValues[FIELD_EXTENSION*hintFieldVal.id]); diff --git a/pil2-stark/src/starkpil/proof2zkinStark.cpp b/pil2-stark/src/starkpil/proof2zkinStark.cpp index 54c641df..388ad979 100644 --- a/pil2-stark/src/starkpil/proof2zkinStark.cpp +++ b/pil2-stark/src/starkpil/proof2zkinStark.cpp @@ -387,13 +387,20 @@ json joinzkinfinal(json& globalInfo, Goldilocks::Element* publics, Goldilocks::E } } - if(globalInfo["numProofValues"] > 0) { + if(globalInfo["proofValuesMap"].size() > 0) { + uint64_t p = 0; zkinFinal["proofValues"] = json::array(); - for (uint64_t i = 0; i < globalInfo["numProofValues"]; i++) + for (uint64_t i = 0; i < globalInfo["proofValuesMap"].size(); i++) { zkinFinal["proofValues"][i] = json::array(); - for(uint64_t j = 0; j < FIELD_EXTENSION; ++j) { - zkinFinal["proofValues"][i][j] = Goldilocks::toString(proofValues[i*FIELD_EXTENSION + j]); + if(globalInfo["proofValuesMap"][i]["stage"] == 1) { + zkinFinal["proofValues"][i][0] = Goldilocks::toString(proofValues[p++]); + zkinFinal["proofValues"][i][1] = "0"; + zkinFinal["proofValues"][i][2] = "0"; + } else { + zkinFinal["proofValues"][i][0] = Goldilocks::toString(proofValues[p++]); + zkinFinal["proofValues"][i][1] = Goldilocks::toString(proofValues[p++]); + zkinFinal["proofValues"][i][2] = Goldilocks::toString(proofValues[p++]); } } } diff --git a/pil2-stark/src/starkpil/stark_info.cpp b/pil2-stark/src/starkpil/stark_info.cpp index f1caa656..95c15878 100644 --- a/pil2-stark/src/starkpil/stark_info.cpp +++ b/pil2-stark/src/starkpil/stark_info.cpp @@ -126,6 +126,7 @@ void StarkInfo::load(json j) { PolMap map; map.name = j["proofValuesMap"][i]["name"]; + map.stage = j["proofValuesMap"][i]["stage"]; proofValuesMap.push_back(map); } diff --git a/pilout/src/pilout.proto b/pilout/src/pilout.proto index 042b86a2..7b25bf8c 100644 --- a/pilout/src/pilout.proto +++ b/pilout/src/pilout.proto @@ -6,7 +6,7 @@ message PilOut { bytes baseField = 2; // base field characteristic repeated AirGroup airGroups = 3; repeated uint32 numChallenges = 4; // number of challenges per stage - uint32 numProofValues = 5; + repeated uint32 numProofValues = 5; uint32 numPublicValues = 6; repeated PublicTable publicTables = 7; repeated GlobalExpression expressions = 8; @@ -82,7 +82,8 @@ message GlobalOperand { } message ProofValue { - uint32 idx = 1; + uint32 stage = 1; + uint32 idx = 2; } message AirGroupValue { @@ -192,7 +193,8 @@ message Operand { } message ProofValue { - uint32 idx = 1; + uint32 stage = 1; + uint32 idx = 2; } message AirGroupValue { diff --git a/pilout/src/pilout_proxy.rs b/pilout/src/pilout_proxy.rs index 2d4a3ddc..7e619bea 100644 --- a/pilout/src/pilout_proxy.rs +++ b/pilout/src/pilout_proxy.rs @@ -120,7 +120,7 @@ impl PilOutProxy { trace!( "{}: #Proof values: {}, #Public values: {}, #Global expressions: {}, #Global constraints: {}", Self::MY_NAME, - self.pilout.num_proof_values, + self.pilout.num_proof_values.len(), self.pilout.num_public_values, self.pilout.expressions.len(), self.pilout.constraints.len() diff --git a/proofman/src/constraints.rs b/proofman/src/constraints.rs index 2f44da5a..402b93a4 100644 --- a/proofman/src/constraints.rs +++ b/proofman/src/constraints.rs @@ -25,6 +25,7 @@ pub fn verify_global_constraints_proof( .collect(); let raw_ptr = verify_global_constraints_c( + sctx.get_global_info_file().as_str(), sctx.get_global_bin(), pctx.get_publics_ptr(), pctx.get_challenges_ptr(), diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index d5814d96..30d58e96 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -445,6 +445,11 @@ impl ProofMan { transcript.add_elements(pctx.get_publics_ptr(), pctx.global_info.n_publics); } + let proof_values_stage = pctx.get_proof_values_by_stage(stage); + if !proof_values_stage.is_empty() { + transcript.add_elements(proof_values_stage.as_ptr() as *mut u8, proof_values_stage.len()); + } + // TODO: ACTIVATE DCTX BACK // let dctx = pctx.dctx.read().unwrap(); @@ -627,14 +632,13 @@ impl ProofMan { } let n_publics = proof_ctx.global_info.n_publics as u64; - let n_proof_values = proof_ctx.global_info.n_proof_values as u64; let global_info_path = proof_ctx.global_info.get_proving_key_path().join("pilout.globalInfo.json"); let global_info_file: &str = global_info_path.to_str().unwrap(); save_publics_c(n_publics, proof_ctx.get_publics_ptr(), output_dir); - save_proof_values_c(n_proof_values, proof_ctx.get_proof_values_ptr(), output_dir); + save_proof_values_c(proof_ctx.get_proof_values_ptr(), global_info_file, output_dir); save_challenges_c(proof_ctx.get_challenges_ptr(), global_info_file, output_dir); diff --git a/proofman/src/recursion.rs b/proofman/src/recursion.rs index 2d20c79d..5ec3e28a 100644 --- a/proofman/src/recursion.rs +++ b/proofman/src/recursion.rs @@ -310,6 +310,7 @@ pub fn generate_vadcop_recursive2_proof( break; } } + // if dctx.rank == 0 { let mut proofs_recursive2: Vec<*mut c_void> = Vec::with_capacity(n_airgroups); for proofs in airgroup_proofs { diff --git a/provers/starks-lib-c/bindings_starks.rs b/provers/starks-lib-c/bindings_starks.rs index b8cccf39..a19b15f6 100644 --- a/provers/starks-lib-c/bindings_starks.rs +++ b/provers/starks-lib-c/bindings_starks.rs @@ -15,10 +15,10 @@ extern "C" { ); } extern "C" { - #[link_name = "\u{1}_Z17save_proof_valuesmPvPc"] + #[link_name = "\u{1}_Z17save_proof_valuesPvPcS0_"] pub fn save_proof_values( - numProofValues: ::std::os::raw::c_ulong, pProofValues: *mut ::std::os::raw::c_void, + globalInfoFile: *mut ::std::os::raw::c_char, fileDir: *mut ::std::os::raw::c_char, ); } @@ -81,7 +81,6 @@ extern "C" { #[link_name = "\u{1}_Z15get_map_total_nPv"] pub fn get_map_total_n(pStarkInfo: *mut ::std::os::raw::c_void) -> u64; } - extern "C" { #[link_name = "\u{1}_Z15stark_info_freePv"] pub fn stark_info_free(pStarkInfo: *mut ::std::os::raw::c_void); @@ -293,7 +292,7 @@ extern "C" { pStarks: *mut ::std::os::raw::c_void, elementType: u32, step: u64, - witness: *mut ::std::os::raw::c_void, + trace: *mut ::std::os::raw::c_void, buffer: *mut ::std::os::raw::c_void, pProof: *mut ::std::os::raw::c_void, pBuffHelper: *mut ::std::os::raw::c_void, @@ -419,8 +418,9 @@ extern "C" { ) -> *mut ::std::os::raw::c_void; } extern "C" { - #[link_name = "\u{1}_Z25verify_global_constraintsPvS_S_S_PS_"] + #[link_name = "\u{1}_Z25verify_global_constraintsPcPvS0_S0_S0_PS0_"] pub fn verify_global_constraints( + globalInfoFile: *mut ::std::os::raw::c_char, globalBin: *mut ::std::os::raw::c_void, publics: *mut ::std::os::raw::c_void, challenges: *mut ::std::os::raw::c_void, @@ -429,8 +429,9 @@ extern "C" { ) -> *mut ::std::os::raw::c_void; } extern "C" { - #[link_name = "\u{1}_Z33get_hint_field_global_constraintsPvS_S_S_PS_mPcb"] + #[link_name = "\u{1}_Z33get_hint_field_global_constraintsPcPvS0_S0_S0_PS0_mS_b"] pub fn get_hint_field_global_constraints( + globalInfoFile: *mut ::std::os::raw::c_char, globalBin: *mut ::std::os::raw::c_void, publics: *mut ::std::os::raw::c_void, challenges: *mut ::std::os::raw::c_void, @@ -442,8 +443,9 @@ extern "C" { ) -> *mut ::std::os::raw::c_void; } extern "C" { - #[link_name = "\u{1}_Z33set_hint_field_global_constraintsPvS_S_mPc"] + #[link_name = "\u{1}_Z33set_hint_field_global_constraintsPcPvS0_S0_mS_"] pub fn set_hint_field_global_constraints( + globalInfoFile: *mut ::std::os::raw::c_char, p_globalinfo_bin: *mut ::std::os::raw::c_void, proofValues: *mut ::std::os::raw::c_void, values: *mut ::std::os::raw::c_void, diff --git a/provers/starks-lib-c/src/ffi_starks.rs b/provers/starks-lib-c/src/ffi_starks.rs index 3100f96f..4ad6d3ce 100644 --- a/provers/starks-lib-c/src/ffi_starks.rs +++ b/provers/starks-lib-c/src/ffi_starks.rs @@ -45,12 +45,16 @@ pub fn save_publics_c(n_publics: u64, public_inputs: *mut u8, output_dir: &str) } #[cfg(not(feature = "no_lib_link"))] -pub fn save_proof_values_c(n_proof_values: u64, proof_values: *mut u8, output_dir: &str) { +pub fn save_proof_values_c(proof_values: *mut u8, global_info_file: &str, output_dir: &str) { let file_dir: CString = CString::new(output_dir).unwrap(); + + let global_info_file_name = CString::new(global_info_file).unwrap(); + let global_info_file_ptr = global_info_file_name.as_ptr() as *mut std::os::raw::c_char; + unsafe { save_proof_values( - n_proof_values, proof_values as *mut std::os::raw::c_void, + global_info_file_ptr, file_dir.as_ptr() as *mut std::os::raw::c_char, ); } @@ -683,14 +687,19 @@ pub fn verify_constraints_c(p_setup: *mut c_void, p_steps_params: *mut u8) -> *m #[cfg(not(feature = "no_lib_link"))] pub fn verify_global_constraints_c( + global_info_file: &str, p_global_constraints_bin: *mut c_void, publics: *mut u8, challenges: *mut u8, proof_values: *mut u8, airgroupvalues: *mut *mut u8, ) -> *mut c_void { + let global_info_file_name = CString::new(global_info_file).unwrap(); + let global_info_file_ptr = global_info_file_name.as_ptr() as *mut std::os::raw::c_char; + unsafe { verify_global_constraints( + global_info_file_ptr, p_global_constraints_bin, publics as *mut std::os::raw::c_void, challenges as *mut std::os::raw::c_void, @@ -703,6 +712,7 @@ pub fn verify_global_constraints_c( #[cfg(not(feature = "no_lib_link"))] #[allow(clippy::too_many_arguments)] pub fn get_hint_field_global_constraints_c( + global_info_file: &str, p_global_constraints_bin: *mut c_void, publics: *mut u8, challenges: *mut u8, @@ -713,8 +723,13 @@ pub fn get_hint_field_global_constraints_c( print_expression: bool, ) -> *mut c_void { let field_name = CString::new(hint_field_name).unwrap(); + + let global_info_file_name = CString::new(global_info_file).unwrap(); + let global_info_file_ptr = global_info_file_name.as_ptr() as *mut std::os::raw::c_char; + unsafe { get_hint_field_global_constraints( + global_info_file_ptr, p_global_constraints_bin, publics as *mut std::os::raw::c_void, challenges as *mut std::os::raw::c_void, @@ -729,6 +744,7 @@ pub fn get_hint_field_global_constraints_c( #[cfg(not(feature = "no_lib_link"))] pub fn set_hint_field_global_constraints_c( + global_info_file: &str, p_global_constraints_bin: *mut c_void, proof_values: *mut u8, values: *mut u8, @@ -736,8 +752,13 @@ pub fn set_hint_field_global_constraints_c( hint_field_name: &str, ) -> u64 { let field_name = CString::new(hint_field_name).unwrap(); + + let global_info_file_name = CString::new(global_info_file).unwrap(); + let global_info_file_ptr = global_info_file_name.as_ptr() as *mut std::os::raw::c_char; + unsafe { set_hint_field_global_constraints( + global_info_file_ptr, p_global_constraints_bin, proof_values as *mut std::os::raw::c_void, values as *mut std::os::raw::c_void, @@ -948,7 +969,7 @@ pub fn save_publics_c(_n_publics: u64, _public_inputs: *mut u8, _output_dir: &st } #[cfg(feature = "no_lib_link")] -pub fn save_proof_values_c(_n_proof_values: u64, _proof_values: *mut u8, _output_dir: &str) { +pub fn save_proof_values_c(_proof_values: *mut u8, _global_info_file: &str, _output_dir: &str) { trace!("{}: ··· {}", "ffi ", "save_proof_values: This is a mock call because there is no linked library"); } @@ -1396,6 +1417,7 @@ pub fn verify_constraints_c(_p_setup: *mut c_void, _p_steps_params: *mut u8) -> #[cfg(feature = "no_lib_link")] pub fn verify_global_constraints_c( + _global_info_file: &str, _p_global_constraints_bin: *mut c_void, _publics: *mut u8, _challenges: *mut u8, @@ -1413,6 +1435,7 @@ pub fn verify_global_constraints_c( #[cfg(feature = "no_lib_link")] #[allow(clippy::too_many_arguments)] pub fn get_hint_field_global_constraints_c( + _global_info_file: &str, _p_global_constraints_bin: *mut c_void, _publics: *mut u8, _challenges: *mut u8, @@ -1432,6 +1455,7 @@ pub fn get_hint_field_global_constraints_c( #[cfg(feature = "no_lib_link")] pub fn set_hint_field_global_constraints_c( + _global_info_file: &str, _p_global_constraints_bin: *mut c_void, _proof_values: *mut u8, _values: *mut u8, From b63bd31d7bbfd75f7b438181ad1c98fb5e06f869 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Wed, 18 Dec 2024 11:55:33 +0000 Subject: [PATCH 46/64] Fixing global info json --- common/src/global_info.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/common/src/global_info.rs b/common/src/global_info.rs index 55f87865..8445a944 100644 --- a/common/src/global_info.rs +++ b/common/src/global_info.rs @@ -40,8 +40,6 @@ pub struct GlobalInfo { pub n_publics: usize, #[serde(rename = "numChallenges")] pub n_challenges: Vec, - #[serde(rename = "numProofValues")] - pub n_proof_values: Vec, #[serde(rename = "proofValuesMap")] pub proof_values_map: Option>, From 0321ecb60ad24de41ed1a561b260ef480071bc11 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Wed, 18 Dec 2024 13:23:40 +0000 Subject: [PATCH 47/64] Fix pctx --- common/src/proof_ctx.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/proof_ctx.rs b/common/src/proof_ctx.rs index 4bea405b..12995f4e 100644 --- a/common/src/proof_ctx.rs +++ b/common/src/proof_ctx.rs @@ -62,7 +62,7 @@ impl ProofCtx { let global_info: GlobalInfo = GlobalInfo::new(&proving_key_path); let n_publics = global_info.n_publics; - let n_proof_values = global_info.n_proof_values.iter().sum::(); + let n_proof_values = global_info.proof_values_map.as_ref().unwrap().len(); let n_challenges = 4 + global_info.n_challenges.iter().sum::(); Self { From 60b1ca4554b26a802d0749e3b442af1ac5517792 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Thu, 19 Dec 2024 08:13:55 +0000 Subject: [PATCH 48/64] Adding some information to print_summary --- common/src/setup.rs | 10 ++++-- common/src/trace.rs | 1 + macros/src/lib.rs | 4 +++ .../src/starkpil/gen_recursive_proof.hpp | 2 ++ pil2-stark/src/starkpil/stark_info.cpp | 31 ++++++++--------- proofman/src/proofman.rs | 33 +++++++++++++++---- 6 files changed, 53 insertions(+), 28 deletions(-) diff --git a/common/src/setup.rs b/common/src/setup.rs index b5c565e1..86317d65 100644 --- a/common/src/setup.rs +++ b/common/src/setup.rs @@ -2,6 +2,7 @@ use std::os::raw::c_void; use std::path::PathBuf; use std::sync::RwLock; +use proofman_starks_lib_c::get_map_totaln_c; use proofman_starks_lib_c::{ get_const_tree_size_c, get_const_size_c, prover_helpers_new_c, expressions_bin_new_c, stark_info_new_c, load_const_tree_c, load_const_pols_c, calculate_const_tree_c, stark_info_free_c, expressions_bin_free_c, @@ -51,6 +52,7 @@ pub struct Setup { pub stark_info: StarkInfo, pub const_pols: Pols, pub const_tree: Pols, + pub prover_buffer_size: u64, } impl Setup { @@ -66,20 +68,21 @@ impl Setup { let stark_info_path = setup_path.display().to_string() + ".starkinfo.json"; let expressions_bin_path = setup_path.display().to_string() + ".bin"; - let (stark_info, p_stark_info, p_expressions_bin, p_prover_helpers) = + let (stark_info, p_stark_info, p_expressions_bin, p_prover_helpers, prover_buffer_size) = if setup_type == &ProofType::Compressor && !global_info.get_air_has_compressor(airgroup_id, air_id) { // If the condition is met, use None for each pointer - (StarkInfo::default(), std::ptr::null_mut(), std::ptr::null_mut(), std::ptr::null_mut()) + (StarkInfo::default(), std::ptr::null_mut(), std::ptr::null_mut(), std::ptr::null_mut(), 0) } else { // Otherwise, initialize the pointers with their respective values let stark_info_json = std::fs::read_to_string(&stark_info_path) .unwrap_or_else(|_| panic!("Failed to read file {}", &stark_info_path)); let stark_info = StarkInfo::from_json(&stark_info_json); let p_stark_info = stark_info_new_c(stark_info_path.as_str()); + let prover_buffer_size = get_map_totaln_c(p_stark_info); let expressions_bin = expressions_bin_new_c(expressions_bin_path.as_str(), false); let prover_helpers = prover_helpers_new_c(p_stark_info); - (stark_info, p_stark_info, expressions_bin, prover_helpers) + (stark_info, p_stark_info, expressions_bin, prover_helpers, prover_buffer_size) }; Self { @@ -89,6 +92,7 @@ impl Setup { p_setup: SetupC { p_stark_info, p_expressions_bin, p_prover_helpers }, const_pols: Pols::default(), const_tree: Pols::default(), + prover_buffer_size, } } diff --git a/common/src/trace.rs b/common/src/trace.rs index 59f84458..9a3bc9f4 100644 --- a/common/src/trace.rs +++ b/common/src/trace.rs @@ -1,5 +1,6 @@ pub trait Trace: Send { fn num_rows(&self) -> usize; + fn n_cols(&self) -> usize; fn airgroup_id(&self) -> usize; fn air_id(&self) -> usize; fn commit_id(&self) -> Option; diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 36ad45b2..853de4bd 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -153,6 +153,10 @@ fn trace_impl(input: TokenStream2) -> Result { self.num_rows } + fn n_cols(&self) -> usize { + self.row_size + } + fn airgroup_id(&self) -> usize { self.airgroup_id } diff --git a/pil2-stark/src/starkpil/gen_recursive_proof.hpp b/pil2-stark/src/starkpil/gen_recursive_proof.hpp index bef8d728..53f00e76 100644 --- a/pil2-stark/src/starkpil/gen_recursive_proof.hpp +++ b/pil2-stark/src/starkpil/gen_recursive_proof.hpp @@ -10,6 +10,8 @@ void *genRecursiveProof(SetupCtx& setupCtx, json& globalInfo, uint64_t airgroupI Starks starks(setupCtx, pConstTree); + setupCtx.starkInfo.addMemoryRecursive(); + Goldilocks::Element *trace = new Goldilocks::Element[setupCtx.starkInfo.mapTotalN]; #ifdef __AVX512__ diff --git a/pil2-stark/src/starkpil/stark_info.cpp b/pil2-stark/src/starkpil/stark_info.cpp index 95c15878..d7ec6bde 100644 --- a/pil2-stark/src/starkpil/stark_info.cpp +++ b/pil2-stark/src/starkpil/stark_info.cpp @@ -245,7 +245,7 @@ void StarkInfo::setMapOffsets() { mapTotalN = 0; - for(uint64_t stage = 2; stage <= nStages; stage++) { + for(uint64_t stage = nStages; stage >= 2; stage--) { mapOffsets[std::make_pair("cm" + to_string(stage), false)] = mapTotalN; mapTotalN += N * mapSectionsN["cm" + to_string(stage)]; } @@ -260,26 +260,21 @@ void StarkInfo::setMapOffsets() { mapTotalN += NExtended * mapSectionsN["cm" + to_string(stage)]; } - mapOffsets[std::make_pair("q", true)] = mapTotalN; - mapTotalN += NExtended * qDim; + mapOffsets[std::make_pair("f", true)] = mapTotalN; + mapTotalN += NExtended * FIELD_EXTENSION; - // Stage FRIPolynomial - uint64_t offsetPolsFRI = mapOffsets[std::make_pair("q", true)]; - mapOffsets[std::make_pair("xDivXSubXi", true)] = offsetPolsFRI; - offsetPolsFRI += openingPoints.size() * NExtended * FIELD_EXTENSION; - - mapOffsets[std::make_pair("f", true)] = offsetPolsFRI; - offsetPolsFRI += NExtended * FIELD_EXTENSION; + mapOffsets[std::make_pair("q", true)] = mapOffsets[std::make_pair("f", true)]; - if(offsetPolsFRI > mapTotalN) mapTotalN = offsetPolsFRI; + mapOffsets[std::make_pair("evals", true)] = mapTotalN; + mapTotalN += evMap.size() * omp_get_max_threads() * FIELD_EXTENSION; +} - uint64_t offsetPolsEvals = mapOffsets[std::make_pair("q", true)]; - mapOffsets[std::make_pair("LEv", true)] = offsetPolsEvals; - offsetPolsEvals += N * openingPoints.size() * FIELD_EXTENSION; - - mapOffsets[std::make_pair("evals", true)] = offsetPolsEvals; - offsetPolsEvals += evMap.size() * omp_get_max_threads() * FIELD_EXTENSION; - if(offsetPolsEvals > mapTotalN) mapTotalN = offsetPolsEvals; +void StarkInfo::addMemoryRecursive() { + uint64_t offsetFRI = mapOffsets[std::make_pair("f", true)]; + mapOffsets[std::make_pair("xDivXSubXi", true)] = offsetFRI; + mapOffsets[std::make_pair("LEv", true)] = offsetFRI; + offsetFRI += openingPoints.size() * NExtended * FIELD_EXTENSION; + if(offsetPolsFRI > mapTotalN) mapTotalN = offsetPolsFRI; } void StarkInfo::getPolynomial(Polinomial &pol, Goldilocks::Element *pAddress, string type, PolMap& polInfo, bool domainExtended) { diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index 30d58e96..4a05aeac 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -2,7 +2,7 @@ use libloading::{Library, Symbol}; use log::{info, trace}; use p3_field::PrimeField; use stark::StarkProver; -use proofman_starks_lib_c::{save_challenges_c, save_proof_values_c, save_publics_c}; +use proofman_starks_lib_c::{save_challenges_c, save_proof_values_c, save_publics_c, get_map_totaln_c}; use std::fs; use std::error::Error; @@ -70,7 +70,7 @@ impl ProofMan { let mpi_rank = dctx.rank; drop(dctx); if mpi_rank == 0 { - Self::print_summary(pctx.clone()); + Self::print_summary(pctx.clone(), setups.sctx.clone()); } Self::initialize_fixed_pols(setups.clone(), pctx.clone()); @@ -646,17 +646,26 @@ impl ProofMan { proves } - fn print_summary(pctx: Arc>) { + fn print_summary(pctx: Arc>, sctx: Arc) { let air_instances_repo = pctx.air_instance_repo.air_instances.read().unwrap(); let air_instances_repo = &*air_instances_repo; + let mut air_info = HashMap::new(); + let mut air_instances = HashMap::new(); for air_instance in air_instances_repo.iter() { let air_name = pctx.global_info.airs[air_instance.airgroup_id][air_instance.air_id].clone().name; let air_group_name = pctx.global_info.air_groups[air_instance.airgroup_id].clone(); - let air_instance = air_instances.entry(air_group_name).or_insert_with(HashMap::new); - let air_instance = air_instance.entry(air_name).or_insert(0); - *air_instance += 1; + let air_instance_map = air_instances.entry(air_group_name).or_insert_with(HashMap::new); + if !air_instance_map.contains_key(&air_name.clone()) { + let setup = sctx.get_setup(air_instance.airgroup_id, air_instance.air_id); + let n_cols = setup.stark_info.map_sections_n.get("cm1").unwrap(); + let n_bits = setup.stark_info.stark_struct.n_bits; + let total_mem = get_map_totaln_c(setup.p_setup.p_stark_info) as f64 * 8.0 / (1024.0 * 1024.0 * 1024.0); + air_info.insert(air_name.clone(), (n_cols, n_bits, total_mem)); + } + let air_instance_map_key = air_instance_map.entry(air_name).or_insert(0); + *air_instance_map_key += 1; } let mut air_groups: Vec<_> = air_instances.keys().collect(); @@ -672,7 +681,17 @@ impl ProofMan { info!("{}: Air Group [{}]", Self::MY_NAME, air_group); for air_name in air_names { let count = air_group_instances.get(air_name).unwrap(); - info!("{}: {}", Self::MY_NAME, format!("· {} x Air [{}]", count, air_name).bright_white().bold()); + let (n_cols, n_bits, total_memory) = air_info.get(air_name).unwrap(); + info!( + "{}: {}", + Self::MY_NAME, + format!( + "· {} x Air [{}] ({} x 2^{}) ({:.2} GB each)", + count, air_name, n_cols, n_bits, total_memory + ) + .bright_white() + .bold() + ); } } info!("{}: --- PROOF INSTANCES SUMMARY ------------------------", Self::MY_NAME); From a2773ea2c6b7c75cbc91b8ad3736d13c075bf764 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Thu, 19 Dec 2024 08:15:54 +0000 Subject: [PATCH 49/64] Fix --- pil2-stark/src/starkpil/stark_info.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pil2-stark/src/starkpil/stark_info.hpp b/pil2-stark/src/starkpil/stark_info.hpp index 97705303..52f8c9d7 100644 --- a/pil2-stark/src/starkpil/stark_info.hpp +++ b/pil2-stark/src/starkpil/stark_info.hpp @@ -164,6 +164,8 @@ class StarkInfo void setMapOffsets(); + void addMemoryRecursive(); + /* Returns a polynomial specified by its ID */ void getPolynomial(Polinomial &pol, Goldilocks::Element *pAddress, string type, PolMap& polInfo, bool domainExtended); }; From 25422c3b5511a33e3c88afc3f2e177c632645150 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Thu, 19 Dec 2024 08:20:57 +0000 Subject: [PATCH 50/64] Typo --- pil2-stark/src/starkpil/stark_info.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pil2-stark/src/starkpil/stark_info.cpp b/pil2-stark/src/starkpil/stark_info.cpp index d7ec6bde..a80b8f41 100644 --- a/pil2-stark/src/starkpil/stark_info.cpp +++ b/pil2-stark/src/starkpil/stark_info.cpp @@ -274,7 +274,7 @@ void StarkInfo::addMemoryRecursive() { mapOffsets[std::make_pair("xDivXSubXi", true)] = offsetFRI; mapOffsets[std::make_pair("LEv", true)] = offsetFRI; offsetFRI += openingPoints.size() * NExtended * FIELD_EXTENSION; - if(offsetPolsFRI > mapTotalN) mapTotalN = offsetPolsFRI; + if(offsetFRI > mapTotalN) mapTotalN = offsetFRI; } void StarkInfo::getPolynomial(Polinomial &pol, Goldilocks::Element *pAddress, string type, PolMap& polInfo, bool domainExtended) { From 4b7a50672e16bda26b2cf5ea20ca204a73a5d42f Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Thu, 19 Dec 2024 08:24:56 +0000 Subject: [PATCH 51/64] Typo --- pil2-stark/src/starkpil/stark_info.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/pil2-stark/src/starkpil/stark_info.cpp b/pil2-stark/src/starkpil/stark_info.cpp index a80b8f41..64f95d21 100644 --- a/pil2-stark/src/starkpil/stark_info.cpp +++ b/pil2-stark/src/starkpil/stark_info.cpp @@ -270,6 +270,7 @@ void StarkInfo::setMapOffsets() { } void StarkInfo::addMemoryRecursive() { + uint64_t NExtended = (1 << starkStruct.nBitsExt); uint64_t offsetFRI = mapOffsets[std::make_pair("f", true)]; mapOffsets[std::make_pair("xDivXSubXi", true)] = offsetFRI; mapOffsets[std::make_pair("LEv", true)] = offsetFRI; From 49d58ee69a567bd855851c56f6306b5e93676189 Mon Sep 17 00:00:00 2001 From: Xavier Pinsach <10213118+xavi-pinsach@users.noreply.github.com> Date: Fri, 20 Dec 2024 15:20:08 +0000 Subject: [PATCH 52/64] cleaning Cargo.toml(s) --- Cargo.lock | 299 +++++++++----------------- common/Cargo.toml | 1 - pil2-components/lib/std/rs/Cargo.toml | 1 - pilout/Cargo.toml | 3 - proofman/Cargo.toml | 1 - provers/stark/Cargo.toml | 1 - provers/starks-lib-c/Cargo.toml | 1 - util/Cargo.toml | 2 +- witness/Cargo.toml | 1 - 9 files changed, 108 insertions(+), 202 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7aaed7dd..b2e86f56 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.15" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" dependencies = [ "anstyle", "anstyle-parse", @@ -28,43 +28,43 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.8" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" [[package]] name = "anstyle-parse" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" dependencies = [ - "windows-sys 0.52.0", + "windows-sys", ] [[package]] name = "anstyle-wincon" -version = "3.0.4" +version = "3.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" dependencies = [ "anstyle", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] name = "anyhow" -version = "1.0.91" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c042108f3ed77fd83760a5fd79b53be043192bb3b9dba91d8c574c0ada7850c8" +checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7" [[package]] name = "autocfg" @@ -119,15 +119,15 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" +checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" [[package]] name = "cc" -version = "1.1.31" +version = "1.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f" +checksum = "c31a0499c1dc64f458ad13872de75c0eb7e3fdb0e67964610c914b034fc5956e" dependencies = [ "shlex", ] @@ -160,9 +160,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.20" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" +checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" dependencies = [ "clap_builder", "clap_derive", @@ -170,9 +170,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.20" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" +checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" dependencies = [ "anstream", "anstyle", @@ -194,24 +194,24 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "colorchoice" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" [[package]] name = "colored" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" +checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" dependencies = [ "lazy_static", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -240,9 +240,9 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "crossbeam-deque" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" dependencies = [ "crossbeam-epoch", "crossbeam-utils", @@ -259,9 +259,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.20" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "custom_derive" @@ -306,19 +306,19 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.9" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] name = "fastrand" -version = "2.1.1" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "fibonacci-square" @@ -380,11 +380,11 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "home" -version = "0.5.9" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" dependencies = [ - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -395,9 +395,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "indexmap" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" dependencies = [ "equivalent", "hashbrown", @@ -429,9 +429,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.11" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" [[package]] name = "lazy_static" @@ -447,9 +447,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.161" +version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" [[package]] name = "libffi" @@ -472,12 +472,12 @@ dependencies = [ [[package]] name = "libloading" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", - "windows-targets 0.52.6", + "windows-targets", ] [[package]] @@ -728,7 +728,6 @@ dependencies = [ "num-traits", "p3-field", "p3-goldilocks", - "pilout", "proofman-common", "proofman-hints", "proofman-util", @@ -742,16 +741,15 @@ version = "0.1.0" dependencies = [ "bytes", "log", - "proofman-util", "prost", "prost-build", ] [[package]] name = "pin-project-lite" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" [[package]] name = "pkg-config" @@ -770,9 +768,9 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.2.24" +version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "910d41a655dac3b764f1ade94821093d3610248694320cd072303a8eedcf221d" +checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" dependencies = [ "proc-macro2", "syn", @@ -780,9 +778,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.89" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -798,7 +796,6 @@ dependencies = [ "mpi", "p3-field", "p3-goldilocks", - "pilout", "proofman-common", "proofman-hints", "proofman-starks-lib-c", @@ -837,7 +834,6 @@ dependencies = [ "mpi", "p3-field", "p3-goldilocks", - "pilout", "proofman-macros", "proofman-starks-lib-c", "proofman-util", @@ -869,9 +865,6 @@ dependencies = [ [[package]] name = "proofman-starks-lib-c" version = "0.1.0" -dependencies = [ - "log", -] [[package]] name = "proofman-util" @@ -883,9 +876,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0487d90e047de87f984913713b85c601c05609aad5b0df4b4573fbf69aa13f" +checksum = "2c0fef6c4230e4ccf618a35c59d7ede15dea37de8427500f50aff708806e42ec" dependencies = [ "bytes", "prost-derive", @@ -893,11 +886,10 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c1318b19085f08681016926435853bbf7858f9c082d0999b80550ff5d9abe15" +checksum = "d0f3e5beed80eb580c68e2c600937ac2c4eedabdfd5ef1e5b7ea4f3fba84497b" dependencies = [ - "bytes", "heck", "itertools 0.13.0", "log", @@ -914,9 +906,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9552f850d5f0964a4e4d0bf306459ac29323ddfbae05e35a7c0d35cb0803cc5" +checksum = "157c5a9d7ea5c2ed2d9fb8f495b64759f7816c7eaea54ba3978f0d63000162e3" dependencies = [ "anyhow", "itertools 0.13.0", @@ -927,9 +919,9 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4759aa0d3a6232fb8dbdb97b61de2c20047c68aca932c7ed76da9d788508d670" +checksum = "cc2f1e56baa61e93533aebc21af4d2134b70f66275e0fcdf3cbe43d77ff7e8fc" dependencies = [ "prost", ] @@ -995,9 +987,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", @@ -1007,9 +999,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -1030,15 +1022,15 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" -version = "0.38.37" +version = "0.38.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85" dependencies = [ "bitflags", "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1049,18 +1041,18 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "serde" -version = "1.0.213" +version = "1.0.216" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ea7893ff5e2466df8d720bb615088341b295f849602c6956047f8f80f0e9bc1" +checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.213" +version = "1.0.216" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e85ad2009c50b58e87caa8cd6dac16bdf511bbfb7af6c33df902396aa480fa5" +checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" dependencies = [ "proc-macro2", "quote", @@ -1069,9 +1061,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.132" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" dependencies = [ "itoa", "memchr", @@ -1105,7 +1097,6 @@ dependencies = [ "p3-field", "p3-goldilocks", "proofman-common", - "proofman-hints", "proofman-starks-lib-c", "proofman-util", "serde", @@ -1128,9 +1119,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.82" +version = "2.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021" +checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" dependencies = [ "proc-macro2", "quote", @@ -1139,9 +1130,9 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.31.4" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "355dbe4f8799b304b05e1b0f05fc59b2a18d36645cf169607da45bde2f69a1be" +checksum = "948512566b1895f93b1592c7574baeb2de842f224f2aab158799ecadb8ebbb46" dependencies = [ "core-foundation-sys", "libc", @@ -1153,31 +1144,31 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.13.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" +checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" dependencies = [ "cfg-if", "fastrand", "once_cell", "rustix", - "windows-sys 0.59.0", + "windows-sys", ] [[package]] name = "thiserror" -version = "1.0.65" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.65" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", @@ -1196,9 +1187,9 @@ dependencies = [ [[package]] name = "tracing" -version = "0.1.40" +version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" dependencies = [ "pin-project-lite", "tracing-attributes", @@ -1207,9 +1198,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.27" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2", "quote", @@ -1218,9 +1209,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.32" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" dependencies = [ "once_cell", ] @@ -1244,9 +1235,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "unicode-segmentation" @@ -1307,7 +1298,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" dependencies = [ "windows-core", - "windows-targets 0.52.6", + "windows-targets", ] [[package]] @@ -1319,7 +1310,7 @@ dependencies = [ "windows-implement", "windows-interface", "windows-result", - "windows-targets 0.52.6", + "windows-targets", ] [[package]] @@ -1350,25 +1341,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" dependencies = [ - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.6", + "windows-targets", ] [[package]] @@ -1377,22 +1350,7 @@ version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows-targets", ] [[package]] @@ -1401,46 +1359,28 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.6", - "windows_aarch64_msvc 0.52.6", - "windows_i686_gnu 0.52.6", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.6", - "windows_x86_64_gnu 0.52.6", - "windows_x86_64_gnullvm 0.52.6", - "windows_x86_64_msvc 0.52.6", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -1453,48 +1393,24 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - [[package]] name = "windows_x86_64_msvc" version = "0.52.6" @@ -1507,7 +1423,6 @@ version = "0.1.0" dependencies = [ "colored", "env_logger", - "libloading", "log", "mpi", "p3-field", diff --git a/common/Cargo.toml b/common/Cargo.toml index b78db2db..7c02c067 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" serde = { version = "1.0.130", features = ["derive"] } serde_json = "1.0.68" serde_derive = "1.0.196" -pilout = { path = "../pilout" } log.workspace = true transcript = { path = "../transcript" } p3-field.workspace = true diff --git a/pil2-components/lib/std/rs/Cargo.toml b/pil2-components/lib/std/rs/Cargo.toml index 3e82e340..aa58e2cd 100644 --- a/pil2-components/lib/std/rs/Cargo.toml +++ b/pil2-components/lib/std/rs/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" proofman-common.workspace = true proofman-hints.workspace = true proofman-util.workspace = true -pilout.workspace = true log.workspace = true num-bigint.workspace = true num-traits.workspace = true diff --git a/pilout/Cargo.toml b/pilout/Cargo.toml index 1d0cc1c7..eb7da2b0 100644 --- a/pilout/Cargo.toml +++ b/pilout/Cargo.toml @@ -3,13 +3,10 @@ name = "pilout" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] bytes.workspace = true prost.workspace = true log.workspace = true -proofman-util.workspace = true [build-dependencies] prost-build.workspace = true diff --git a/proofman/Cargo.toml b/proofman/Cargo.toml index bef10e04..9306f320 100644 --- a/proofman/Cargo.toml +++ b/proofman/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" proofman-common = { path = "../common" } proofman-hints = { path = "../hints" } proofman-util = { path = "../util" } -pilout = { path = "../pilout" } stark = { path = "../provers/stark" } proofman-starks-lib-c = { path = "../provers/starks-lib-c" } transcript = { path = "../transcript" } diff --git a/provers/stark/Cargo.toml b/provers/stark/Cargo.toml index a1a4138f..94345121 100644 --- a/provers/stark/Cargo.toml +++ b/provers/stark/Cargo.toml @@ -13,7 +13,6 @@ proofman-util = { path = "../../util" } proofman-starks-lib-c = { path = "../starks-lib-c" } transcript = { path = "../../transcript" } proofman-common = { path = "../../common" } -proofman-hints = { path = "../../hints" } log.workspace = true p3-goldilocks.workspace = true diff --git a/provers/starks-lib-c/Cargo.toml b/provers/starks-lib-c/Cargo.toml index 457e4c96..7f982e2a 100644 --- a/provers/starks-lib-c/Cargo.toml +++ b/provers/starks-lib-c/Cargo.toml @@ -6,7 +6,6 @@ edition = "2021" build = "build.rs" [dependencies] -log.workspace = true [features] default = [] diff --git a/util/Cargo.toml b/util/Cargo.toml index 178956d5..f22b206a 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -4,5 +4,5 @@ version = "0.1.0" edition = "2021" [dependencies] -sysinfo = "0.31.2" +sysinfo = "0.33" colored = "2" \ No newline at end of file diff --git a/witness/Cargo.toml b/witness/Cargo.toml index 247a3f1d..c9795116 100644 --- a/witness/Cargo.toml +++ b/witness/Cargo.toml @@ -12,7 +12,6 @@ env_logger.workspace = true p3-goldilocks.workspace = true p3-field.workspace = true -libloading = "0.8.4" colored = "2" mpi = { version = "0.8.0", optional = true } serde_json = "1.0.68" From 100b2f09d3c86e766a04daa91bccdd055f2cf19b Mon Sep 17 00:00:00 2001 From: Xavier Pinsach <10213118+xavi-pinsach@users.noreply.github.com> Date: Fri, 20 Dec 2024 15:24:46 +0000 Subject: [PATCH 53/64] add log create to starks-lib-c --- Cargo.lock | 3 +++ provers/starks-lib-c/Cargo.toml | 1 + 2 files changed, 4 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index b2e86f56..9da28b62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -865,6 +865,9 @@ dependencies = [ [[package]] name = "proofman-starks-lib-c" version = "0.1.0" +dependencies = [ + "log", +] [[package]] name = "proofman-util" diff --git a/provers/starks-lib-c/Cargo.toml b/provers/starks-lib-c/Cargo.toml index 7f982e2a..457e4c96 100644 --- a/provers/starks-lib-c/Cargo.toml +++ b/provers/starks-lib-c/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" build = "build.rs" [dependencies] +log.workspace = true [features] default = [] From 95eb57fa1a53f0cbcf478c5239a0834c5c78aa6e Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Fri, 20 Dec 2024 17:24:15 +0000 Subject: [PATCH 54/64] Removing all unsafes from hints --- Cargo.lock | 2 + common/src/air_instance.rs | 4 + common/src/prover.rs | 2 +- common/src/stark_info.rs | 20 + examples/fibonacci-square/Cargo.toml | 1 + hints/Cargo.toml | 1 + hints/src/global_hints.rs | 287 +++++----- hints/src/hints.rs | 535 ++++++++++-------- .../lib/std/rs/src/range_check/u16air.rs | 2 +- .../lib/std/rs/src/range_check/u8air.rs | 2 +- pil2-stark/lib/include/starks_lib.h | 18 +- pil2-stark/src/api/starks_api.cpp | 58 +- pil2-stark/src/api/starks_api.hpp | 18 +- pil2-stark/src/starkpil/expressions_bin.cpp | 20 +- pil2-stark/src/starkpil/expressions_bin.hpp | 9 +- .../src/starkpil/global_constraints.hpp | 164 ++++-- pil2-stark/src/starkpil/hints.hpp | 264 +++++---- pil2-stark/src/starkpil/stark_info.cpp | 3 +- proofman/src/proofman.rs | 69 ++- provers/stark/src/stark_prover.rs | 32 +- provers/starks-lib-c/bindings_starks.rs | 73 ++- provers/starks-lib-c/src/ffi_starks.rs | 192 ++++++- witness/src/witness_manager.rs | 10 +- 23 files changed, 1107 insertions(+), 679 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9da28b62..1eeafb43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -332,6 +332,7 @@ dependencies = [ "pil-std-lib", "proofman-common", "proofman-macros", + "rayon", "serde", "serde_json", "witness", @@ -851,6 +852,7 @@ dependencies = [ "p3-field", "proofman-common", "proofman-starks-lib-c", + "proofman-util", ] [[package]] diff --git a/common/src/air_instance.rs b/common/src/air_instance.rs index ca7f7790..1475da86 100644 --- a/common/src/air_instance.rs +++ b/common/src/air_instance.rs @@ -257,4 +257,8 @@ impl AirInstance { self.air_instance_id = Some(air_instance_id); self.idx = Some(idx); } + + pub fn clear_trace(&mut self) { + self.trace = Vec::new(); + } } diff --git a/common/src/prover.rs b/common/src/prover.rs index f3ff8582..edd2d594 100644 --- a/common/src/prover.rs +++ b/common/src/prover.rs @@ -88,7 +88,7 @@ pub trait Prover { fn opening_stage(&mut self, opening_id: u32, setup_ctx: Arc, proof_ctx: Arc>) -> ProverStatus; - fn get_buff_helper_size(&self) -> usize; + fn get_buff_helper_size(&self, proof_ctx: Arc>) -> usize; fn get_proof(&self) -> *mut c_void; fn get_prover_info(&self) -> ProverInfo; fn get_zkin_proof(&self, proof_ctx: Arc>, output_dir: &str) -> *mut c_void; diff --git a/common/src/stark_info.rs b/common/src/stark_info.rs index 4e08115e..48589632 100644 --- a/common/src/stark_info.rs +++ b/common/src/stark_info.rs @@ -221,4 +221,24 @@ impl StarkInfo { pub fn from_json(stark_info_json: &str) -> Self { serde_json::from_str(stark_info_json).expect("Failed to parse JSON file") } + + pub fn get_buff_helper_size(&self) -> usize { + let mut max_cols = 0; + for stage in 1..=self.n_stages + 1 { + let n_cols = *self.map_sections_n.get(&format!("cm{}", stage)).unwrap() as usize; + if n_cols > max_cols { + max_cols = n_cols; + } + } + + let n_extended = (1 << self.stark_struct.n_bits_ext) as usize; + let buff_size_stages = max_cols * n_extended; + + let buff_size_xdivxsub = self.opening_points.len() * 3 * n_extended; + + match buff_size_stages > buff_size_xdivxsub { + true => buff_size_stages, + false => buff_size_xdivxsub, + } + } } diff --git a/examples/fibonacci-square/Cargo.toml b/examples/fibonacci-square/Cargo.toml index 72b9bd27..a23033da 100644 --- a/examples/fibonacci-square/Cargo.toml +++ b/examples/fibonacci-square/Cargo.toml @@ -15,6 +15,7 @@ env_logger.workspace = true log.workspace = true p3-goldilocks.workspace = true p3-field.workspace = true +rayon = "1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.68" diff --git a/hints/Cargo.toml b/hints/Cargo.toml index 10a208e7..8da7a9ea 100644 --- a/hints/Cargo.toml +++ b/hints/Cargo.toml @@ -6,5 +6,6 @@ edition = "2021" [dependencies] proofman-starks-lib-c = { path = "../provers/starks-lib-c" } proofman-common = { path = "../common" } +proofman-util = { path = "../util" } p3-field.workspace = true log.workspace = true \ No newline at end of file diff --git a/hints/src/global_hints.rs b/hints/src/global_hints.rs index 2757c64d..e1522475 100644 --- a/hints/src/global_hints.rs +++ b/hints/src/global_hints.rs @@ -1,6 +1,10 @@ use p3_field::Field; -use crate::{HintCol, HintFieldInfoValues, HintFieldOutput, HintFieldValue, HintFieldValues, HintFieldValuesVec}; -use proofman_starks_lib_c::{get_hint_field_global_constraints_c, set_hint_field_global_constraints_c}; +use crate::{HintCol, HintFieldInfoC, HintFieldInfo, HintFieldOutput, HintFieldValue, HintFieldValues, HintFieldValuesVec}; +use proofman_starks_lib_c::{ + get_hint_field_global_constraints_values_c, get_hint_field_global_constraints_sizes_c, + get_hint_field_global_constraints_c, set_hint_field_global_constraints_c, +}; +use std::ffi::c_void; use std::{collections::HashMap, sync::Arc}; @@ -52,32 +56,84 @@ pub fn aggregate_airgroupvals(pctx: Arc>) -> Vec> { airgroupvalues } -pub fn get_hint_field_constant_gc( +fn get_global_hint_f( + pctx: Option>>, sctx: Arc, hint_id: u64, hint_field_name: &str, print_expression: bool, -) -> HintFieldValue { - let raw_ptr = get_hint_field_global_constraints_c( +) -> Vec> { + let n_hints_values = get_hint_field_global_constraints_values_c(sctx.get_global_bin(), hint_id, hint_field_name); + + let mut hint_field_values: Vec> = vec![HintFieldInfo::default(); n_hints_values as usize]; + + let mut hint_field_values_c = HintFieldInfoC::::from_hint_field_info_vec(&mut hint_field_values); + let mut hint_field_values_c_ptr = hint_field_values_c.as_mut_ptr() as *mut c_void; + + get_hint_field_global_constraints_sizes_c( sctx.get_global_info_file().as_str(), sctx.get_global_bin(), - std::ptr::null_mut(), - std::ptr::null_mut(), - std::ptr::null_mut(), - std::ptr::null_mut(), + hint_field_values_c_ptr, hint_id, hint_field_name, print_expression, ); - unsafe { - let hint_field_values = &*(raw_ptr as *mut HintFieldInfoValues); - let value = &*(hint_field_values.hint_field_values.add(0)); - if value.matrix_size != 0 { - panic!("get_hint_field can only be called with single expressions, but {} is an array", hint_field_name); - } - HintCol::from_hint_field(value) + HintFieldInfoC::::sync_to_hint_field_info(&mut hint_field_values, &hint_field_values_c); + + for hint_field_value in hint_field_values.iter_mut() { + hint_field_value.init_buffers(true); + } + + hint_field_values_c = HintFieldInfoC::::from_hint_field_info_vec(&mut hint_field_values); + hint_field_values_c_ptr = hint_field_values_c.as_mut_ptr() as *mut c_void; + + let publics = if let Some(ref pctx) = pctx { pctx.get_publics_ptr() } else { std::ptr::null_mut() }; + let challenges = if let Some(ref pctx) = pctx { pctx.get_challenges_ptr() } else { std::ptr::null_mut() }; + let proof_values = if let Some(ref pctx) = pctx { pctx.get_proof_values_ptr() } else { std::ptr::null_mut() }; + let airgroup_values = if let Some(ref pctx) = pctx { + let mut airgroupvals = aggregate_airgroupvals(pctx.clone()); + let mut airgroup_values_ptrs: Vec<*mut F> = airgroupvals + .iter_mut() // Iterate mutably over the inner Vecs + .map(|inner_vec| inner_vec.as_mut_ptr()) // Get a raw pointer to each inner Vec + .collect(); + airgroup_values_ptrs.as_mut_ptr() as *mut *mut u8 + } else { + std::ptr::null_mut() + }; + + get_hint_field_global_constraints_c( + sctx.get_global_info_file().as_str(), + sctx.get_global_bin(), + hint_field_values_c_ptr, + publics, + challenges, + proof_values, + airgroup_values, + hint_id, + hint_field_name, + print_expression, + ); + + hint_field_values +} +pub fn get_hint_field_constant_gc( + sctx: Arc, + hint_id: u64, + hint_field_name: &str, + print_expression: bool, +) -> HintFieldValue { + let hint_info = get_global_hint_f(None, sctx, hint_id, hint_field_name, print_expression); + + if hint_info[0].matrix_size != 0 { + panic!("get_hint_field can only be called with single expressions, but {} is an array", hint_field_name); } + + if print_expression { + log::info!("HintsInf: {}", std::str::from_utf8(&hint_info[0].expression_line).unwrap()); + } + + HintCol::from_hint_field(&hint_info[0]) } pub fn get_hint_field_gc_constant_a( @@ -86,32 +142,21 @@ pub fn get_hint_field_gc_constant_a( hint_field_name: &str, print_expression: bool, ) -> HintFieldValuesVec { - let raw_ptr = get_hint_field_global_constraints_c( - sctx.get_global_info_file().as_str(), - sctx.get_global_bin(), - std::ptr::null_mut(), - std::ptr::null_mut(), - std::ptr::null_mut(), - std::ptr::null_mut(), - hint_id, - hint_field_name, - print_expression, - ); + let hint_infos: Vec> = get_global_hint_f(None, sctx, hint_id, hint_field_name, print_expression); - unsafe { - let mut hint_field_values = Vec::new(); - let hint_field = &*(raw_ptr as *mut HintFieldInfoValues); - for v in 0..hint_field.n_values { - let h = &*(hint_field.hint_field_values.add(v as usize)); - if v == 0 && h.matrix_size != 1 { - panic!("get_hint_field_m can only be called with an array of expressions!"); - } - let hint_value = HintCol::from_hint_field(h); - hint_field_values.push(hint_value); + let mut hint_field_values = Vec::new(); + for (v, hint_info) in hint_infos.iter().enumerate() { + if v == 0 && hint_info.matrix_size != 1 { + panic!("get_hint_field_m can only be called with an array of expressions!"); } - - HintFieldValuesVec { values: hint_field_values } + if print_expression { + log::info!("HintsInf: {}", std::str::from_utf8(&hint_info.expression_line).unwrap()); + } + let hint_value = HintCol::from_hint_field(hint_info); + hint_field_values.push(hint_value); } + + HintFieldValuesVec { values: hint_field_values } } pub fn get_hint_field_constant_gc_m( @@ -120,37 +165,26 @@ pub fn get_hint_field_constant_gc_m( hint_field_name: &str, print_expression: bool, ) -> HintFieldValues { - let raw_ptr = get_hint_field_global_constraints_c( - sctx.get_global_info_file().as_str(), - sctx.get_global_bin(), - std::ptr::null_mut(), - std::ptr::null_mut(), - std::ptr::null_mut(), - std::ptr::null_mut(), - hint_id, - hint_field_name, - print_expression, - ); + let hint_infos = get_global_hint_f(None, sctx, hint_id, hint_field_name, print_expression); - unsafe { - let hint_field = &*(raw_ptr as *mut HintFieldInfoValues); - let mut hint_field_values = HashMap::with_capacity(hint_field.n_values as usize); + let mut hint_field_values = HashMap::with_capacity(hint_infos.len() as usize); - for v in 0..hint_field.n_values { - let h = &*(hint_field.hint_field_values.add(v as usize)); - if v == 0 && h.matrix_size > 2 { - panic!("get_hint_field_m can only be called with a matrix of expressions!",); - } - let hint_value = HintCol::from_hint_field(h); - let mut pos = Vec::new(); - for p in 0..h.matrix_size { - pos.push(h.pos.wrapping_add(p as usize) as u64); - } - hint_field_values.insert(pos, hint_value); + for (v, hint_info) in hint_infos.iter().enumerate() { + if v == 0 && hint_info.matrix_size > 2 { + panic!("get_hint_field_m can only be called with a matrix of expressions!",); } - - HintFieldValues { values: hint_field_values } + let hint_value = HintCol::from_hint_field(hint_info); + let mut pos = Vec::new(); + for p in 0..hint_info.matrix_size { + pos.push(hint_info.pos[p as usize]); + } + if print_expression { + log::info!("HintsInf: {}", std::str::from_utf8(&hint_info.expression_line).unwrap()); + } + hint_field_values.insert(pos, hint_value); } + + HintFieldValues { values: hint_field_values } } pub fn get_hint_field_gc( @@ -160,32 +194,17 @@ pub fn get_hint_field_gc( hint_field_name: &str, print_expression: bool, ) -> HintFieldValue { - let mut airgroupvalues = aggregate_airgroupvals(pctx.clone()); - let mut airgroup_values_ptrs: Vec<*mut F> = airgroupvalues - .iter_mut() // Iterate mutably over the inner Vecs - .map(|inner_vec| inner_vec.as_mut_ptr()) // Get a raw pointer to each inner Vec - .collect(); + let hint_info = get_global_hint_f(Some(pctx), sctx, hint_id, hint_field_name, print_expression); - let raw_ptr = get_hint_field_global_constraints_c( - sctx.get_global_info_file().as_str(), - sctx.get_global_bin(), - pctx.get_publics_ptr(), - pctx.get_challenges_ptr(), - pctx.get_proof_values_ptr(), - airgroup_values_ptrs.as_mut_ptr() as *mut *mut u8, - hint_id, - hint_field_name, - print_expression, - ); + if hint_info[0].matrix_size != 0 { + panic!("get_hint_field can only be called with single expressions, but {} is an array", hint_field_name); + } - unsafe { - let hint_field_values = &*(raw_ptr as *mut HintFieldInfoValues); - let value = &*(hint_field_values.hint_field_values.add(0)); - if value.matrix_size != 0 { - panic!("get_hint_field can only be called with single expressions, but {} is an array", hint_field_name); - } - HintCol::from_hint_field(value) + if print_expression { + log::info!("HintsInf: {}", std::str::from_utf8(&hint_info[0].expression_line).unwrap()); } + + HintCol::from_hint_field(&hint_info[0]) } pub fn get_hint_field_gc_a( @@ -195,38 +214,21 @@ pub fn get_hint_field_gc_a( hint_field_name: &str, print_expression: bool, ) -> HintFieldValuesVec { - let mut airgroupvalues = aggregate_airgroupvals(pctx.clone()); - let mut airgroup_values_ptrs: Vec<*mut F> = airgroupvalues - .iter_mut() // Iterate mutably over the inner Vecs - .map(|inner_vec| inner_vec.as_mut_ptr()) // Get a raw pointer to each inner Vec - .collect(); + let hint_infos: Vec> = + get_global_hint_f(Some(pctx), sctx, hint_id, hint_field_name, print_expression); - let raw_ptr = get_hint_field_global_constraints_c( - sctx.get_global_info_file().as_str(), - sctx.get_global_bin(), - pctx.get_publics_ptr(), - pctx.get_challenges_ptr(), - pctx.get_proof_values_ptr(), - airgroup_values_ptrs.as_mut_ptr() as *mut *mut u8, - hint_id, - hint_field_name, - print_expression, - ); - - unsafe { - let mut hint_field_values = Vec::new(); - let hint_field = &*(raw_ptr as *mut HintFieldInfoValues); - for v in 0..hint_field.n_values { - let h = &*(hint_field.hint_field_values.add(v as usize)); - if v == 0 && h.matrix_size != 1 { - panic!("get_hint_field_m can only be called with an array of expressions!"); - } - let hint_value = HintCol::from_hint_field(h); - hint_field_values.push(hint_value); + let mut hint_field_values = Vec::new(); + for (v, hint_info) in hint_infos.iter().enumerate() { + if v == 0 && hint_info.matrix_size != 1 { + panic!("get_hint_field_m can only be called with an array of expressions!"); } - - HintFieldValuesVec { values: hint_field_values } + if print_expression { + log::info!("HintsInf: {}", std::str::from_utf8(&hint_info.expression_line).unwrap()); + } + let hint_value = HintCol::from_hint_field(hint_info); + hint_field_values.push(hint_value); } + HintFieldValuesVec { values: hint_field_values } } pub fn get_hint_field_gc_m( @@ -236,43 +238,26 @@ pub fn get_hint_field_gc_m( hint_field_name: &str, print_expression: bool, ) -> HintFieldValues { - let mut airgroupvalues = aggregate_airgroupvals(pctx.clone()); - let mut airgroup_values_ptrs: Vec<*mut F> = airgroupvalues - .iter_mut() // Iterate mutably over the inner Vecs - .map(|inner_vec| inner_vec.as_mut_ptr()) // Get a raw pointer to each inner Vec - .collect(); + let hint_infos = get_global_hint_f(Some(pctx), sctx, hint_id, hint_field_name, print_expression); - let raw_ptr = get_hint_field_global_constraints_c( - sctx.get_global_info_file().as_str(), - sctx.get_global_bin(), - pctx.get_publics_ptr(), - pctx.get_challenges_ptr(), - pctx.get_proof_values_ptr(), - airgroup_values_ptrs.as_mut_ptr() as *mut *mut u8, - hint_id, - hint_field_name, - print_expression, - ); + let mut hint_field_values = HashMap::with_capacity(hint_infos.len() as usize); - unsafe { - let hint_field = &*(raw_ptr as *mut HintFieldInfoValues); - let mut hint_field_values = HashMap::with_capacity(hint_field.n_values as usize); - - for v in 0..hint_field.n_values { - let h = &*(hint_field.hint_field_values.add(v as usize)); - if v == 0 && h.matrix_size > 2 { - panic!("get_hint_field_m can only be called with a matrix of expressions!",); - } - let hint_value = HintCol::from_hint_field(h); - let mut pos = Vec::new(); - for p in 0..h.matrix_size { - pos.push(h.pos.wrapping_add(p as usize) as u64); - } - hint_field_values.insert(pos, hint_value); + for (v, hint_info) in hint_infos.iter().enumerate() { + if v == 0 && hint_info.matrix_size > 2 { + panic!("get_hint_field_m can only be called with a matrix of expressions!",); } - - HintFieldValues { values: hint_field_values } + let hint_value = HintCol::from_hint_field(hint_info); + let mut pos = Vec::new(); + for p in 0..hint_info.matrix_size { + pos.push(hint_info.pos[p as usize]); + } + if print_expression { + log::info!("HintsInf: {}", std::str::from_utf8(&hint_info.expression_line).unwrap()); + } + hint_field_values.insert(pos, hint_value); } + + HintFieldValues { values: hint_field_values } } pub fn set_hint_field_gc( diff --git a/hints/src/hints.rs b/hints/src/hints.rs index 436728d0..d2c8e9e4 100644 --- a/hints/src/hints.rs +++ b/hints/src/hints.rs @@ -1,12 +1,15 @@ use proofman_starks_lib_c::{ - acc_hint_field_c, acc_mul_hint_fields_c, get_hint_field_c, get_hint_ids_by_name_c, mul_hint_fields_c, print_row_c, - set_hint_field_c, update_airgroupvalue_c, VecU64Result, + get_hint_field_id_c, acc_hint_field_c, acc_mul_hint_fields_c, get_hint_field_c, get_hint_field_sizes_c, + get_hint_field_values_c, get_hint_ids_by_name_c, mul_hint_fields_c, print_row_c, set_hint_field_c, + update_airgroupvalue_c, n_hint_ids_by_name_c, }; use std::collections::HashMap; +use std::ffi::c_void; use p3_field::Field; use proofman_common::{AirInstance, ExtensionField, ProofCtx, SetupCtx, StepsParams}; +use proofman_util::create_buffer_fast; use std::ops::{Add, Div, Mul, Sub, AddAssign, DivAssign, MulAssign, SubAssign}; @@ -23,19 +26,110 @@ pub enum HintFieldType { } #[repr(C)] -#[allow(dead_code)] -pub struct HintFieldInfo { +#[derive(Debug)] +pub struct HintFieldInfoC { size: u64, + string_size: u64, offset: u8, // 1 or 3cd field_type: HintFieldType, values: *mut F, string_value: *mut u8, pub matrix_size: u64, pub pos: *mut u64, - expression_line: *mut u8, + pub expression_line: *mut u8, + expression_line_size: u64, +} + +impl HintFieldInfoC { + pub fn from_hint_field_info_vec(hint_field_values: &mut [HintFieldInfo]) -> Vec> { + hint_field_values + .iter_mut() + .map(|info| HintFieldInfoC { + size: info.size, + string_size: info.string_size, + offset: info.offset, + field_type: info.field_type, + values: info.values.as_mut_ptr(), + string_value: info.string_value.as_mut_ptr(), + matrix_size: info.matrix_size, + pos: info.pos.as_mut_ptr(), + expression_line: info.expression_line.as_mut_ptr(), + expression_line_size: info.expression_line_size, + }) + .collect() + } + + pub fn sync_to_hint_field_info( + hint_field_values: &mut [HintFieldInfo], + hint_field_values_c: &Vec>, + ) { + for (original, updated) in hint_field_values.iter_mut().zip(hint_field_values_c) { + original.size = updated.size; + original.string_size = updated.string_size; + original.matrix_size = updated.matrix_size; + original.expression_line_size = updated.expression_line_size; + original.offset = updated.offset; + original.field_type = updated.field_type; + } + } +} + +#[derive(Clone, Debug)] +#[repr(C)] +pub struct HintFieldInfo { + size: u64, + string_size: u64, + offset: u8, // 1 or 3cd + field_type: HintFieldType, + values: Vec, + string_value: Vec, + pub matrix_size: u64, + pub pos: Vec, + pub expression_line: Vec, expression_line_size: u64, } +impl Default for HintFieldInfo { + fn default() -> Self { + HintFieldInfo { + size: 0, + string_size: 0, + offset: 0, + field_type: HintFieldType::Field, + values: Vec::new(), + string_value: Vec::new(), + matrix_size: 0, + pos: Vec::new(), + expression_line: Vec::new(), + expression_line_size: 0, + } + } +} + +impl HintFieldInfo { + pub fn init_buffers(&mut self, initialize_zeros: bool) { + if self.size > 0 { + if initialize_zeros { + self.values = vec![F::zero(); self.size as usize]; + } else { + self.values = create_buffer_fast(self.size as usize); + } + } + + if self.matrix_size > 0 { + self.pos = vec![0; self.matrix_size as usize]; + } + + if self.string_size > 0 { + self.string_value = vec![0; self.string_size as usize]; + } + + if self.expression_line_size > 0 { + self.expression_line = vec![0; self.expression_line_size as usize] + } + } +} + #[repr(C)] pub struct HintFieldInfoValues { pub n_values: u64, @@ -43,7 +137,7 @@ pub struct HintFieldInfoValues { } #[repr(C)] -#[derive(Default)] +#[derive(Clone, Default)] pub struct HintFieldOptions { pub dest: bool, pub inverse: bool, @@ -622,48 +716,36 @@ pub struct HintCol; impl HintCol { pub fn from_hint_field(hint_field: &HintFieldInfo) -> HintFieldValue { - let values_slice = match hint_field.field_type { - HintFieldType::String => &[], - _ => unsafe { std::slice::from_raw_parts(hint_field.values, hint_field.size as usize) }, - }; - match hint_field.field_type { - HintFieldType::Field => HintFieldValue::Field(values_slice[0]), + HintFieldType::Field => HintFieldValue::Field(hint_field.values[0]), HintFieldType::FieldExtended => { - let array = [values_slice[0], values_slice[1], values_slice[2]]; + let array = [hint_field.values[0], hint_field.values[1], hint_field.values[2]]; HintFieldValue::FieldExtended(ExtensionField { value: array }) } - HintFieldType::Column => HintFieldValue::Column(values_slice.to_vec()), + HintFieldType::Column => HintFieldValue::Column(hint_field.values.to_vec()), HintFieldType::ColumnExtended => { let mut extended_vec: Vec> = Vec::with_capacity(hint_field.size as usize / 3); - for chunk in values_slice.chunks(3) { + for chunk in hint_field.values.chunks(3) { extended_vec.push(ExtensionField { value: [chunk[0], chunk[1], chunk[2]] }); } HintFieldValue::ColumnExtended(extended_vec) } - HintFieldType::String => { - let str_slice = - unsafe { std::slice::from_raw_parts(hint_field.string_value, hint_field.size as usize) }; - - match std::str::from_utf8(str_slice) { - Ok(value) => HintFieldValue::String(value.to_string()), - Err(_) => HintFieldValue::String(String::new()), - } - } + HintFieldType::String => match std::str::from_utf8(&hint_field.string_value) { + Ok(value) => HintFieldValue::String(value.to_string()), + Err(_) => HintFieldValue::String(String::new()), + }, } } } pub fn get_hint_ids_by_name(p_expressions_bin: *mut std::os::raw::c_void, name: &str) -> Vec { - let raw_ptr = get_hint_ids_by_name_c(p_expressions_bin, name); + let n_hints = n_hint_ids_by_name_c(p_expressions_bin, name); - let hint_ids_result = unsafe { Box::from_raw(raw_ptr as *mut VecU64Result) }; + let mut hint_ids = vec![0; n_hints as usize]; - let slice = unsafe { std::slice::from_raw_parts(hint_ids_result.values, hint_ids_result.n_values as usize) }; + get_hint_ids_by_name_c(p_expressions_bin, hint_ids.as_mut_ptr(), name); - // Copy the contents of the slice into a Vec - - slice.to_vec() + hint_ids } #[allow(clippy::too_many_arguments)] @@ -737,7 +819,7 @@ pub fn acc_hint_field( custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; - let raw_ptr = acc_hint_field_c( + acc_hint_field_c( (&setup.p_setup).into(), (&steps_params).into(), hint_id as u64, @@ -747,11 +829,10 @@ pub fn acc_hint_field( add, ); - let hint_ids_result = unsafe { Box::from_raw(raw_ptr as *mut VecU64Result) }; - - let slice = unsafe { std::slice::from_raw_parts(hint_ids_result.values, hint_ids_result.n_values as usize) }; + let dest_id = get_hint_field_id_c((&setup.p_setup).into(), hint_id as u64, hint_field_dest); + let airgroup_value_id = get_hint_field_id_c((&setup.p_setup).into(), hint_id as u64, hint_field_airgroupvalue); - (slice[0], slice[1]) + (dest_id, airgroup_value_id) } #[allow(clippy::too_many_arguments)] @@ -786,7 +867,7 @@ pub fn acc_mul_hint_fields( custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; - let raw_ptr = acc_mul_hint_fields_c( + acc_mul_hint_fields_c( (&setup.p_setup).into(), (&steps_params).into(), hint_id as u64, @@ -799,11 +880,10 @@ pub fn acc_mul_hint_fields( add, ); - let hint_ids_result = unsafe { Box::from_raw(raw_ptr as *mut VecU64Result) }; + let dest_id = get_hint_field_id_c((&setup.p_setup).into(), hint_id as u64, hint_field_dest); + let airgroup_value_id = get_hint_field_id_c((&setup.p_setup).into(), hint_id as u64, hint_field_airgroupvalue); - let slice = unsafe { std::slice::from_raw_parts(hint_ids_result.values, hint_ids_result.n_values as usize) }; - - (slice[0], slice[1]) + (dest_id, airgroup_value_id) } #[allow(clippy::too_many_arguments)] @@ -837,7 +917,7 @@ pub fn update_airgroupvalue( custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), }; - let raw_ptr = update_airgroupvalue_c( + update_airgroupvalue_c( (&setup.p_setup).into(), (&steps_params).into(), hint_id as u64, @@ -847,62 +927,105 @@ pub fn update_airgroupvalue( (&options1).into(), (&options2).into(), add, - ); - - let hint_ids_result = unsafe { Box::from_raw(raw_ptr as *mut VecU64Result) }; - - let slice = unsafe { std::slice::from_raw_parts(hint_ids_result.values, hint_ids_result.n_values as usize) }; - - slice[0] + ) } -pub fn get_hint_field( +#[allow(clippy::too_many_arguments)] +fn get_hint_f( setup_ctx: &SetupCtx, - proof_ctx: &ProofCtx, - air_instance: &mut AirInstance, + proof_ctx: Option<&ProofCtx>, + airgroup_id: usize, + air_id: usize, + air_instance: Option<&mut AirInstance>, hint_id: usize, hint_field_name: &str, options: HintFieldOptions, -) -> HintFieldValue { - let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); +) -> Vec> { + let setup = setup_ctx.get_setup(airgroup_id, air_id); - let steps_params = StepsParams { - trace: air_instance.get_trace_ptr(), - aux_trace: air_instance.get_aux_trace_ptr(), - public_inputs: proof_ctx.get_publics_ptr(), - proof_values: proof_ctx.get_proof_values_ptr(), - challenges: proof_ctx.get_challenges_ptr(), - airgroup_values: air_instance.get_airgroup_values_ptr(), - airvalues: air_instance.get_airvalues_ptr(), - evals: air_instance.get_evals_ptr(), - xdivxsub: std::ptr::null_mut(), - p_const_pols: setup.get_const_ptr(), - p_const_tree: setup.get_const_tree_ptr(), - custom_commits: air_instance.get_custom_commits_ptr(), - custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), + let steps_params = if let Some(air_instance) = air_instance { + StepsParams { + trace: air_instance.get_trace_ptr(), + aux_trace: air_instance.get_aux_trace_ptr(), + public_inputs: proof_ctx.unwrap().get_publics_ptr(), + proof_values: proof_ctx.unwrap().get_proof_values_ptr(), + challenges: proof_ctx.unwrap().get_challenges_ptr(), + airgroup_values: air_instance.get_airgroup_values_ptr(), + airvalues: air_instance.get_airvalues_ptr(), + evals: air_instance.get_evals_ptr(), + xdivxsub: std::ptr::null_mut(), + p_const_pols: setup.get_const_ptr(), + p_const_tree: setup.get_const_tree_ptr(), + custom_commits: air_instance.get_custom_commits_ptr(), + custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), + } + } else { + StepsParams::default() }; - let raw_ptr = get_hint_field_c( + let n_hints_values = get_hint_field_values_c((&setup.p_setup).into(), hint_id as u64, hint_field_name); + + let mut hint_field_values: Vec> = vec![HintFieldInfo::default(); n_hints_values as usize]; + + let mut hint_field_values_c = HintFieldInfoC::::from_hint_field_info_vec(&mut hint_field_values); + let mut hint_field_values_c_ptr = hint_field_values_c.as_mut_ptr() as *mut c_void; + + get_hint_field_sizes_c( + (&setup.p_setup).into(), + hint_field_values_c_ptr, + hint_id as u64, + hint_field_name, + (&options).into(), + ); + + HintFieldInfoC::::sync_to_hint_field_info(&mut hint_field_values, &hint_field_values_c); + + for hint_field_value in hint_field_values.iter_mut() { + hint_field_value.init_buffers(options.initialize_zeros); + } + + hint_field_values_c = HintFieldInfoC::::from_hint_field_info_vec(&mut hint_field_values); + hint_field_values_c_ptr = hint_field_values_c.as_mut_ptr() as *mut c_void; + + get_hint_field_c( (&setup.p_setup).into(), (&steps_params).into(), + hint_field_values_c_ptr, hint_id as u64, hint_field_name, (&options).into(), ); - unsafe { - let hint_field_values = &*(raw_ptr as *mut HintFieldInfoValues); - let value = &*(hint_field_values.hint_field_values.add(0)); - if value.matrix_size != 0 { - panic!("get_hint_field can only be called with single expressions, but {} is an array", hint_field_name); - } - if options.print_expression { - let str_slice = std::slice::from_raw_parts(value.expression_line, value.expression_line_size as usize); - let str_line = std::str::from_utf8(str_slice).unwrap(); - log::info!("HintsInf: {}", str_line); - } - HintCol::from_hint_field(value) + hint_field_values +} +pub fn get_hint_field( + setup_ctx: &SetupCtx, + proof_ctx: &ProofCtx, + air_instance: &mut AirInstance, + hint_id: usize, + hint_field_name: &str, + options: HintFieldOptions, +) -> HintFieldValue { + let hint_info = get_hint_f( + setup_ctx, + Some(proof_ctx), + air_instance.airgroup_id, + air_instance.air_id, + Some(air_instance), + hint_id, + hint_field_name, + options.clone(), + ); + + if hint_info[0].matrix_size != 0 { + panic!("get_hint_field can only be called with single expressions, but {} is an array", hint_field_name); + } + + if options.print_expression { + log::info!("HintsInf: {}", std::str::from_utf8(&hint_info[0].expression_line).unwrap()); } + + HintCol::from_hint_field(&hint_info[0]) } pub fn get_hint_field_a( @@ -913,51 +1036,30 @@ pub fn get_hint_field_a( hint_field_name: &str, options: HintFieldOptions, ) -> HintFieldValuesVec { - let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); - - let steps_params = StepsParams { - trace: air_instance.get_trace_ptr(), - aux_trace: air_instance.get_aux_trace_ptr(), - public_inputs: proof_ctx.get_publics_ptr(), - proof_values: proof_ctx.get_proof_values_ptr(), - challenges: proof_ctx.get_challenges_ptr(), - airgroup_values: air_instance.get_airgroup_values_ptr(), - airvalues: air_instance.get_airvalues_ptr(), - evals: air_instance.get_evals_ptr(), - xdivxsub: std::ptr::null_mut(), - p_const_pols: setup.get_const_ptr(), - p_const_tree: setup.get_const_tree_ptr(), - custom_commits: air_instance.get_custom_commits_ptr(), - custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), - }; - - let raw_ptr = get_hint_field_c( - (&setup.p_setup).into(), - (&steps_params).into(), - hint_id as u64, + let hint_infos: Vec> = get_hint_f( + setup_ctx, + Some(proof_ctx), + air_instance.airgroup_id, + air_instance.air_id, + Some(air_instance), + hint_id, hint_field_name, - (&options).into(), + options.clone(), ); - unsafe { - let mut hint_field_values = Vec::new(); - let hint_field = &*(raw_ptr as *mut HintFieldInfoValues); - for v in 0..hint_field.n_values { - let h = &*(hint_field.hint_field_values.add(v as usize)); - if v == 0 && h.matrix_size != 1 { - panic!("get_hint_field_m can only be called with an array of expressions!"); - } - if options.print_expression { - let str_slice = std::slice::from_raw_parts(h.expression_line, h.expression_line_size as usize); - let str_line = std::str::from_utf8(str_slice).unwrap(); - log::info!("HintsInf: {}", str_line); - } - let hint_value = HintCol::from_hint_field(h); - hint_field_values.push(hint_value); + let mut hint_field_values = Vec::new(); + for (v, hint_info) in hint_infos.iter().enumerate() { + if v == 0 && hint_info.matrix_size != 1 { + panic!("get_hint_field_m can only be called with an array of expressions!"); } - - HintFieldValuesVec { values: hint_field_values } + if options.print_expression { + log::info!("HintsInf: {}", std::str::from_utf8(&hint_info.expression_line).unwrap()); + } + let hint_value = HintCol::from_hint_field(hint_info); + hint_field_values.push(hint_value); } + + HintFieldValuesVec { values: hint_field_values } } pub fn get_hint_field_m( @@ -968,56 +1070,35 @@ pub fn get_hint_field_m( hint_field_name: &str, options: HintFieldOptions, ) -> HintFieldValues { - let setup = setup_ctx.get_setup(air_instance.airgroup_id, air_instance.air_id); - - let steps_params = StepsParams { - trace: air_instance.get_trace_ptr(), - aux_trace: air_instance.get_aux_trace_ptr(), - public_inputs: proof_ctx.get_publics_ptr(), - proof_values: proof_ctx.get_proof_values_ptr(), - challenges: proof_ctx.get_challenges_ptr(), - airgroup_values: air_instance.get_airgroup_values_ptr(), - airvalues: air_instance.get_airvalues_ptr(), - evals: air_instance.get_evals_ptr(), - xdivxsub: std::ptr::null_mut(), - p_const_pols: setup.get_const_ptr(), - p_const_tree: setup.get_const_tree_ptr(), - custom_commits: air_instance.get_custom_commits_ptr(), - custom_commits_extended: air_instance.get_custom_commits_extended_ptr(), - }; - - let raw_ptr = get_hint_field_c( - (&setup.p_setup).into(), - (&steps_params).into(), - hint_id as u64, + let hint_infos: Vec> = get_hint_f( + setup_ctx, + Some(proof_ctx), + air_instance.airgroup_id, + air_instance.air_id, + Some(air_instance), + hint_id, hint_field_name, - (&options).into(), + options.clone(), ); - unsafe { - let hint_field = &*(raw_ptr as *mut HintFieldInfoValues); - let mut hint_field_values = HashMap::with_capacity(hint_field.n_values as usize); + let mut hint_field_values = HashMap::with_capacity(hint_infos.len() as usize); - for v in 0..hint_field.n_values { - let h = &*(hint_field.hint_field_values.add(v as usize)); - if v == 0 && h.matrix_size > 2 { - panic!("get_hint_field_m can only be called with a matrix of expressions!",); - } - let hint_value = HintCol::from_hint_field(h); - let mut pos = Vec::new(); - for p in 0..h.matrix_size { - pos.push(h.pos.wrapping_add(p as usize) as u64); - } - if options.print_expression { - let str_slice = std::slice::from_raw_parts(h.expression_line, h.expression_line_size as usize); - let str_line = std::str::from_utf8(str_slice).unwrap(); - log::info!("HintsInf: {}", str_line); - } - hint_field_values.insert(pos, hint_value); + for (v, hint_info) in hint_infos.iter().enumerate() { + if v == 0 && hint_info.matrix_size > 2 { + panic!("get_hint_field_m can only be called with a matrix of expressions!",); } - - HintFieldValues { values: hint_field_values } + let hint_value = HintCol::from_hint_field(hint_info); + let mut pos = Vec::new(); + for p in 0..hint_info.matrix_size { + pos.push(hint_info.pos[p as usize]); + } + if options.print_expression { + log::info!("HintsInf: {}", std::str::from_utf8(&hint_info.expression_line).unwrap()); + } + hint_field_values.insert(pos, hint_value); } + + HintFieldValues { values: hint_field_values } } pub fn get_hint_field_constant( @@ -1030,31 +1111,18 @@ pub fn get_hint_field_constant( ) -> HintFieldValue { options.compilation_time = true; - let setup = setup_ctx.get_setup(airgroup_id, air_id); - - let steps_params = StepsParams::default(); + let hint_info: Vec> = + get_hint_f(setup_ctx, None, airgroup_id, air_id, None, hint_id, hint_field_name, options.clone()); - let raw_ptr = get_hint_field_c( - (&setup.p_setup).into(), - (&steps_params).into(), - hint_id as u64, - hint_field_name, - (&options).into(), - ); + if hint_info[0].matrix_size != 0 { + panic!("get_hint_field can only be called with single expressions, but {} is an array", hint_field_name); + } - unsafe { - let hint_field_values = &*(raw_ptr as *mut HintFieldInfoValues); - let value = &*(hint_field_values.hint_field_values.add(0)); - if options.print_expression { - let str_slice = std::slice::from_raw_parts(value.expression_line, value.expression_line_size as usize); - let str_line = std::str::from_utf8(str_slice).unwrap(); - log::info!("HintsInf: {}", str_line); - } - if value.matrix_size != 0 { - panic!("get_hint_field can only be called with single expressions, but {} is an array", hint_field_name); - } - HintCol::from_hint_field(value) + if options.print_expression { + log::info!("HintsInf: {}", std::str::from_utf8(&hint_info[0].expression_line).unwrap()); } + + HintCol::from_hint_field(&hint_info[0]) } pub fn get_hint_field_constant_a( @@ -1064,40 +1132,25 @@ pub fn get_hint_field_constant_a( hint_id: usize, hint_field_name: &str, mut options: HintFieldOptions, -) -> Vec> { +) -> HintFieldValuesVec { options.compilation_time = true; - let setup = setup_ctx.get_setup(airgroup_id, air_id); + let hint_infos: Vec> = + get_hint_f(setup_ctx, None, airgroup_id, air_id, None, hint_id, hint_field_name, options.clone()); - let steps_params = StepsParams::default(); - - let raw_ptr = get_hint_field_c( - (&setup.p_setup).into(), - (&steps_params).into(), - hint_id as u64, - hint_field_name, - (&options).into(), - ); - - unsafe { - let mut hint_field_values = Vec::new(); - let hint_field = &*(raw_ptr as *mut HintFieldInfoValues); - for v in 0..hint_field.n_values { - let h = &*(hint_field.hint_field_values.add(v as usize)); - if v == 0 && h.matrix_size != 1 { - panic!("get_hint_field_m can only be called with an array of expressions!"); - } - if options.print_expression { - let str_slice = std::slice::from_raw_parts(h.expression_line, h.expression_line_size as usize); - let str_line = std::str::from_utf8(str_slice).unwrap(); - log::info!("HintsInf: {}", str_line); - } - let hint_value = HintCol::from_hint_field(h); - hint_field_values.push(hint_value); + let mut hint_field_values = Vec::new(); + for (v, hint_info) in hint_infos.iter().enumerate() { + if v == 0 && hint_info.matrix_size != 1 { + panic!("get_hint_field_m can only be called with an array of expressions!"); } - - hint_field_values + if options.print_expression { + log::info!("HintsInf: {}", std::str::from_utf8(&hint_info.expression_line).unwrap()); + } + let hint_value = HintCol::from_hint_field(hint_info); + hint_field_values.push(hint_value); } + + HintFieldValuesVec { values: hint_field_values } } pub fn get_hint_field_constant_m( @@ -1110,45 +1163,27 @@ pub fn get_hint_field_constant_m( ) -> HintFieldValues { options.compilation_time = true; - let setup = setup_ctx.get_setup(airgroup_id, air_id); + let hint_infos: Vec> = + get_hint_f(setup_ctx, None, airgroup_id, air_id, None, hint_id, hint_field_name, options.clone()); - let steps_params = StepsParams::default(); + let mut hint_field_values = HashMap::with_capacity(hint_infos.len() as usize); - let raw_ptr = get_hint_field_c( - (&setup.p_setup).into(), - (&steps_params).into(), - hint_id as u64, - hint_field_name, - (&options).into(), - ); - - unsafe { - let hint_field = &*(raw_ptr as *mut HintFieldInfoValues); - let mut hint_field_values = HashMap::with_capacity(hint_field.n_values as usize); - - for v in 0..hint_field.n_values { - let h = &*(hint_field.hint_field_values.add(v as usize)); - if v == 0 && h.matrix_size != 0 { - panic!( - "get_hint_field_m can only be called with arrays of expressions, but {} is a single one", - hint_field_name - ); - } - if options.print_expression { - let str_slice = std::slice::from_raw_parts(h.expression_line, h.expression_line_size as usize); - let str_line = std::str::from_utf8(str_slice).unwrap(); - log::info!("HintsInf: {}", str_line); - } - let hint_value = HintCol::from_hint_field(h); - let mut pos = Vec::new(); - for p in 0..h.matrix_size { - pos.push(h.pos.wrapping_add(p as usize) as u64); - } - hint_field_values.insert(pos, hint_value); + for (v, hint_info) in hint_infos.iter().enumerate() { + if v == 0 && hint_info.matrix_size > 2 { + panic!("get_hint_field_m can only be called with a matrix of expressions!",); } - - HintFieldValues { values: hint_field_values } + let hint_value = HintCol::from_hint_field(hint_info); + let mut pos = Vec::new(); + for p in 0..hint_info.matrix_size { + pos.push(hint_info.pos[p as usize]); + } + if options.print_expression { + log::info!("HintsInf: {}", std::str::from_utf8(&hint_info.expression_line).unwrap()); + } + hint_field_values.insert(pos, hint_value); } + + HintFieldValues { values: hint_field_values } } pub fn set_hint_field( diff --git a/pil2-components/lib/std/rs/src/range_check/u16air.rs b/pil2-components/lib/std/rs/src/range_check/u16air.rs index 71dfbf0c..834f5269 100644 --- a/pil2-components/lib/std/rs/src/range_check/u16air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u16air.rs @@ -126,12 +126,12 @@ impl U16Air { fn update_multiplicity(&self, drained_inputs: Vec<(F, F)>) { // TODO! Do it in parallel + let mut mul_column = self.mul_column.lock().unwrap(); for (input, mul) in &drained_inputs { let value = input.as_canonical_biguint().to_usize().expect("Cannot convert to usize"); // Note: to avoid non-expected panics, we perform a reduction to the value // In debug mode, this is, in fact, checked before let index = value % NUM_ROWS; - let mut mul_column = self.mul_column.lock().unwrap(); mul_column.add(index, *mul); } } diff --git a/pil2-components/lib/std/rs/src/range_check/u8air.rs b/pil2-components/lib/std/rs/src/range_check/u8air.rs index 4e525bda..27f3b631 100644 --- a/pil2-components/lib/std/rs/src/range_check/u8air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u8air.rs @@ -123,12 +123,12 @@ impl U8Air { } fn update_multiplicity(&self, drained_inputs: Vec<(F, F)>) { + let mut mul_column = self.mul_column.lock().unwrap(); for (input, mul) in &drained_inputs { let value = input.as_canonical_biguint().to_usize().expect("Cannot convert to usize"); // Note: to avoid non-expected panics, we perform a reduction to the value // In debug mode, this is, in fact, checked before let index = value % NUM_ROWS; - let mut mul_column = self.mul_column.lock().unwrap(); mul_column.add(index, *mul); } } diff --git a/pil2-stark/lib/include/starks_lib.h b/pil2-stark/lib/include/starks_lib.h index 2a7b5944..8fa2e3f4 100644 --- a/pil2-stark/lib/include/starks_lib.h +++ b/pil2-stark/lib/include/starks_lib.h @@ -20,7 +20,8 @@ // SetupCtx // ======================================================================================== - void *get_hint_ids_by_name(void *p_expression_bin, char* hintName); + uint64_t n_hints_by_name(void *p_expression_bin, char* hintName); + void get_hint_ids_by_name(void *p_expression_bin, uint64_t* hintIds, char* hintName); // Stark Info // ======================================================================================== @@ -48,12 +49,15 @@ // Hints // ======================================================================================== - void *get_hint_field(void *pSetupCtx, void* stepsParams, uint64_t hintId, char* hintFieldName, void* hintOptions); + void get_hint_field(void *pSetupCtx, void* stepsParams, void* hintFieldValues, uint64_t hintId, char* hintFieldName, void* hintOptions); + uint64_t get_hint_field_values(void *pSetupCtx, uint64_t hintId, char* hintFieldName); + void get_hint_field_sizes(void *pSetupCtx, void* hintFieldValues, uint64_t hintId, char* hintFieldName, void* hintOptions); uint64_t mul_hint_fields(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameDest, char *hintFieldName1, char *hintFieldName2, void* hintOptions1, void *hintOptions2); - void *acc_hint_field(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameDest, char *hintFieldNameAirgroupVal, char *hintFieldName, bool add); - void *acc_mul_hint_fields(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameDest, char *hintFieldNameAirgroupVal, char *hintFieldName1, char *hintFieldName2, void* hintOptions1, void *hintOptions2, bool add); - void *update_airgroupvalue(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameAirgroupVal, char *hintFieldName1, char *hintFieldName2, void* hintOptions1, void *hintOptions2, bool add); + void acc_hint_field(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameDest, char *hintFieldNameAirgroupVal, char *hintFieldName, bool add); + void acc_mul_hint_fields(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameDest, char *hintFieldNameAirgroupVal, char *hintFieldName1, char *hintFieldName2, void* hintOptions1, void *hintOptions2, bool add); + uint64_t update_airgroupvalue(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameAirgroupVal, char *hintFieldName1, char *hintFieldName2, void* hintOptions1, void *hintOptions2, bool add); uint64_t set_hint_field(void *pSetupCtx, void* stepsParams, void *values, uint64_t hintId, char* hintFieldName); + uint64_t get_hint_id(void *pSetupCtx, uint64_t hintId, char * hintFieldName); // Starks // ======================================================================================== @@ -111,7 +115,9 @@ // Global constraints // ================================================================================= void *verify_global_constraints(char* globalInfoFile, void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues); - void *get_hint_field_global_constraints(char* globalInfoFile, void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues, uint64_t hintId, char *hintFieldName, bool print_expression); + uint64_t get_hint_field_global_constraints_values(void* p_globalinfo_bin, uint64_t hintId, char* hintFieldName); + void get_hint_field_global_constraints_sizes(char* globalInfoFile, void* p_globalinfo_bin, void* hintFieldValues, uint64_t hintId, char *hintFieldName, bool print_expression); + void get_hint_field_global_constraints(char* globalInfoFile, void* p_globalinfo_bin, void* hintFieldValues, void *publics, void *challenges, void *proofValues, void **airgroupValues, uint64_t hintId, char *hintFieldName, bool print_expression); uint64_t set_hint_field_global_constraints(char* globalInfoFile, void* p_globalinfo_bin, void *proofValues, void *values, uint64_t hintId, char *hintFieldName); // Debug functions diff --git a/pil2-stark/src/api/starks_api.cpp b/pil2-stark/src/api/starks_api.cpp index 3eae330f..c2132d20 100644 --- a/pil2-stark/src/api/starks_api.cpp +++ b/pil2-stark/src/api/starks_api.cpp @@ -165,12 +165,15 @@ void fri_proof_free(void *pFriProof) // SetupCtx // ======================================================================================== -void* get_hint_ids_by_name(void *p_expression_bin, char* hintName) -{ +uint64_t n_hints_by_name(void *p_expression_bin, char* hintName) { ExpressionsBin *expressionsBin = (ExpressionsBin*)p_expression_bin; + return expressionsBin->getNumberHintIdsByName(string(hintName)); +} - VecU64Result hintIds = expressionsBin->getHintIdsByName(string(hintName)); - return new VecU64Result(hintIds); +void get_hint_ids_by_name(void *p_expression_bin, uint64_t* hintIds, char* hintName) +{ + ExpressionsBin *expressionsBin = (ExpressionsBin*)p_expression_bin; + expressionsBin->getHintIdsByName(hintIds, string(hintName)); } // StarkInfo @@ -261,10 +264,18 @@ void expressions_bin_free(void *pExpressionsBin) // Hints // ======================================================================================== -void *get_hint_field(void *pSetupCtx, void* stepsParams, uint64_t hintId, char* hintFieldName, void* hintOptions) +void get_hint_field(void *pSetupCtx, void* stepsParams, void* hintFieldValues, uint64_t hintId, char* hintFieldName, void* hintOptions) +{ + getHintField(*(SetupCtx *)pSetupCtx, *(StepsParams *)stepsParams, (HintFieldInfo *) hintFieldValues, hintId, string(hintFieldName), *(HintFieldOptions *) hintOptions); +} + +uint64_t get_hint_field_values(void *pSetupCtx, uint64_t hintId, char* hintFieldName) { + return getHintFieldValues(*(SetupCtx *)pSetupCtx, hintId, string(hintFieldName)); +} + +void get_hint_field_sizes(void *pSetupCtx, void* hintFieldValues, uint64_t hintId, char* hintFieldName, void* hintOptions) { - HintFieldValues hintFieldValues = getHintField(*(SetupCtx *)pSetupCtx, *(StepsParams *)stepsParams, hintId, string(hintFieldName), *(HintFieldOptions *) hintOptions); - return new HintFieldValues(hintFieldValues); + getHintFieldSizes(*(SetupCtx *)pSetupCtx, (HintFieldInfo *) hintFieldValues, hintId, string(hintFieldName), *(HintFieldOptions *) hintOptions); } uint64_t mul_hint_fields(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameDest, char *hintFieldName1, char *hintFieldName2, void* hintOptions1, void *hintOptions2) @@ -272,18 +283,21 @@ uint64_t mul_hint_fields(void *pSetupCtx, void* stepsParams, uint64_t hintId, ch return multiplyHintFields(*(SetupCtx *)pSetupCtx, *(StepsParams *)stepsParams, hintId, string(hintFieldNameDest), string(hintFieldName1), string(hintFieldName2), *(HintFieldOptions *)hintOptions1, *(HintFieldOptions *)hintOptions2); } -void *acc_hint_field(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameDest, char *hintFieldNameAirgroupVal, char *hintFieldName, bool add) { - return new VecU64Result(accHintField(*(SetupCtx *)pSetupCtx, *(StepsParams *)stepsParams, hintId, string(hintFieldNameDest), string(hintFieldNameAirgroupVal), string(hintFieldName), add)); +void acc_hint_field(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameDest, char *hintFieldNameAirgroupVal, char *hintFieldName, bool add) { + accHintField(*(SetupCtx *)pSetupCtx, *(StepsParams *)stepsParams, hintId, string(hintFieldNameDest), string(hintFieldNameAirgroupVal), string(hintFieldName), add); } -void *acc_mul_hint_fields(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameDest, char *hintFieldNameAirgroupVal, char *hintFieldName1, char *hintFieldName2, void* hintOptions1, void *hintOptions2, bool add) { - return new VecU64Result(accMulHintFields(*(SetupCtx *)pSetupCtx, *(StepsParams *)stepsParams, hintId, string(hintFieldNameDest), string(hintFieldNameAirgroupVal), string(hintFieldName1), string(hintFieldName2),*(HintFieldOptions *)hintOptions1, *(HintFieldOptions *)hintOptions2, add)); +void acc_mul_hint_fields(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameDest, char *hintFieldNameAirgroupVal, char *hintFieldName1, char *hintFieldName2, void* hintOptions1, void *hintOptions2, bool add) { + accMulHintFields(*(SetupCtx *)pSetupCtx, *(StepsParams *)stepsParams, hintId, string(hintFieldNameDest), string(hintFieldNameAirgroupVal), string(hintFieldName1), string(hintFieldName2),*(HintFieldOptions *)hintOptions1, *(HintFieldOptions *)hintOptions2, add); } -void *update_airgroupvalue(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameAirgroupVal, char *hintFieldName1, char *hintFieldName2, void* hintOptions1, void *hintOptions2, bool add) { - return new VecU64Result(updateAirgroupValue(*(SetupCtx *)pSetupCtx, *(StepsParams *)stepsParams, hintId, string(hintFieldNameAirgroupVal), string(hintFieldName1), string(hintFieldName2),*(HintFieldOptions *)hintOptions1, *(HintFieldOptions *)hintOptions2, add)); +uint64_t update_airgroupvalue(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameAirgroupVal, char *hintFieldName1, char *hintFieldName2, void* hintOptions1, void *hintOptions2, bool add) { + return updateAirgroupValue(*(SetupCtx *)pSetupCtx, *(StepsParams *)stepsParams, hintId, string(hintFieldNameAirgroupVal), string(hintFieldName1), string(hintFieldName2),*(HintFieldOptions *)hintOptions1, *(HintFieldOptions *)hintOptions2, add); } +uint64_t get_hint_id(void *pSetupCtx, uint64_t hintId, char * hintFieldName) { + return getHintId(*(SetupCtx *)pSetupCtx, hintId, string(hintFieldName)); +} uint64_t set_hint_field(void *pSetupCtx, void* params, void *values, uint64_t hintId, char * hintFieldName) { @@ -516,13 +530,25 @@ void *verify_global_constraints(char* globalInfoFile, void* p_globalinfo_bin, vo return constraintsInfo; } -void *get_hint_field_global_constraints(char* globalInfoFile, void* p_globalinfo_bin, void *publics, void *challenges, void *proofValues, void **airgroupValues, uint64_t hintId, char *hintFieldName, bool print_expression) +uint64_t get_hint_field_global_constraints_values(void* p_globalinfo_bin, uint64_t hintId, char* hintFieldName) { + return getHintFieldGlobalConstraintValues(*(ExpressionsBin*)p_globalinfo_bin, hintId, string(hintFieldName)); +} + +void get_hint_field_global_constraints_sizes(char* globalInfoFile, void* p_globalinfo_bin, void* hintFieldValues, uint64_t hintId, char *hintFieldName, bool print_expression) +{ + json globalInfo; + file2json(globalInfoFile, globalInfo); + + getHintFieldGlobalConstraintSizes(globalInfo, *(ExpressionsBin*)p_globalinfo_bin, (HintFieldInfo *)hintFieldValues, hintId, string(hintFieldName), print_expression); +} + + +void get_hint_field_global_constraints(char* globalInfoFile, void* p_globalinfo_bin, void* hintFieldValues, void *publics, void *challenges, void *proofValues, void **airgroupValues, uint64_t hintId, char *hintFieldName, bool print_expression) { json globalInfo; file2json(globalInfoFile, globalInfo); - HintFieldValues hintFieldValues = getHintFieldGlobalConstraint(globalInfo, *(ExpressionsBin*)p_globalinfo_bin, (Goldilocks::Element *)publics, (Goldilocks::Element *)challenges, (Goldilocks::Element *)proofValues, (Goldilocks::Element **)airgroupValues, hintId, string(hintFieldName), print_expression); - return new HintFieldValues(hintFieldValues); + getHintFieldGlobalConstraint(globalInfo, *(ExpressionsBin*)p_globalinfo_bin, (HintFieldInfo *)hintFieldValues, (Goldilocks::Element *)publics, (Goldilocks::Element *)challenges, (Goldilocks::Element *)proofValues, (Goldilocks::Element **)airgroupValues, hintId, string(hintFieldName), print_expression); } uint64_t set_hint_field_global_constraints(char* globalInfoFile, void* p_globalinfo_bin, void *proofValues, void *values, uint64_t hintId, char *hintFieldName) diff --git a/pil2-stark/src/api/starks_api.hpp b/pil2-stark/src/api/starks_api.hpp index 2a7b5944..8fa2e3f4 100644 --- a/pil2-stark/src/api/starks_api.hpp +++ b/pil2-stark/src/api/starks_api.hpp @@ -20,7 +20,8 @@ // SetupCtx // ======================================================================================== - void *get_hint_ids_by_name(void *p_expression_bin, char* hintName); + uint64_t n_hints_by_name(void *p_expression_bin, char* hintName); + void get_hint_ids_by_name(void *p_expression_bin, uint64_t* hintIds, char* hintName); // Stark Info // ======================================================================================== @@ -48,12 +49,15 @@ // Hints // ======================================================================================== - void *get_hint_field(void *pSetupCtx, void* stepsParams, uint64_t hintId, char* hintFieldName, void* hintOptions); + void get_hint_field(void *pSetupCtx, void* stepsParams, void* hintFieldValues, uint64_t hintId, char* hintFieldName, void* hintOptions); + uint64_t get_hint_field_values(void *pSetupCtx, uint64_t hintId, char* hintFieldName); + void get_hint_field_sizes(void *pSetupCtx, void* hintFieldValues, uint64_t hintId, char* hintFieldName, void* hintOptions); uint64_t mul_hint_fields(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameDest, char *hintFieldName1, char *hintFieldName2, void* hintOptions1, void *hintOptions2); - void *acc_hint_field(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameDest, char *hintFieldNameAirgroupVal, char *hintFieldName, bool add); - void *acc_mul_hint_fields(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameDest, char *hintFieldNameAirgroupVal, char *hintFieldName1, char *hintFieldName2, void* hintOptions1, void *hintOptions2, bool add); - void *update_airgroupvalue(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameAirgroupVal, char *hintFieldName1, char *hintFieldName2, void* hintOptions1, void *hintOptions2, bool add); + void acc_hint_field(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameDest, char *hintFieldNameAirgroupVal, char *hintFieldName, bool add); + void acc_mul_hint_fields(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameDest, char *hintFieldNameAirgroupVal, char *hintFieldName1, char *hintFieldName2, void* hintOptions1, void *hintOptions2, bool add); + uint64_t update_airgroupvalue(void *pSetupCtx, void* stepsParams, uint64_t hintId, char *hintFieldNameAirgroupVal, char *hintFieldName1, char *hintFieldName2, void* hintOptions1, void *hintOptions2, bool add); uint64_t set_hint_field(void *pSetupCtx, void* stepsParams, void *values, uint64_t hintId, char* hintFieldName); + uint64_t get_hint_id(void *pSetupCtx, uint64_t hintId, char * hintFieldName); // Starks // ======================================================================================== @@ -111,7 +115,9 @@ // Global constraints // ================================================================================= void *verify_global_constraints(char* globalInfoFile, void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues); - void *get_hint_field_global_constraints(char* globalInfoFile, void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues, uint64_t hintId, char *hintFieldName, bool print_expression); + uint64_t get_hint_field_global_constraints_values(void* p_globalinfo_bin, uint64_t hintId, char* hintFieldName); + void get_hint_field_global_constraints_sizes(char* globalInfoFile, void* p_globalinfo_bin, void* hintFieldValues, uint64_t hintId, char *hintFieldName, bool print_expression); + void get_hint_field_global_constraints(char* globalInfoFile, void* p_globalinfo_bin, void* hintFieldValues, void *publics, void *challenges, void *proofValues, void **airgroupValues, uint64_t hintId, char *hintFieldName, bool print_expression); uint64_t set_hint_field_global_constraints(char* globalInfoFile, void* p_globalinfo_bin, void *proofValues, void *values, uint64_t hintId, char *hintFieldName); // Debug functions diff --git a/pil2-stark/src/starkpil/expressions_bin.cpp b/pil2-stark/src/starkpil/expressions_bin.cpp index 308fa0e8..e6187647 100644 --- a/pil2-stark/src/starkpil/expressions_bin.cpp +++ b/pil2-stark/src/starkpil/expressions_bin.cpp @@ -407,24 +407,24 @@ void ExpressionsBin::loadGlobalBin(BinFileUtils::BinFile *globalBin) { } - -VecU64Result ExpressionsBin::getHintIdsByName(std::string name) { - VecU64Result hintIds; - - hintIds.nElements = 0; +void ExpressionsBin::getHintIdsByName(uint64_t* hintIds, std::string name) { + uint64_t c = 0; for (uint64_t i = 0; i < hints.size(); ++i) { if (hints[i].name == name) { - hintIds.nElements++; + hintIds[c++] = i; } } +} - uint64_t c = 0; - hintIds.ids = new uint64_t[hintIds.nElements]; + +uint64_t ExpressionsBin::getNumberHintIdsByName(std::string name) { + + uint64_t nHints = 0; for (uint64_t i = 0; i < hints.size(); ++i) { if (hints[i].name == name) { - hintIds.ids[c++] = i; + nHints++; } } - return hintIds; + return nHints; } \ No newline at end of file diff --git a/pil2-stark/src/starkpil/expressions_bin.hpp b/pil2-stark/src/starkpil/expressions_bin.hpp index b1cc6f7e..90ad6fce 100644 --- a/pil2-stark/src/starkpil/expressions_bin.hpp +++ b/pil2-stark/src/starkpil/expressions_bin.hpp @@ -47,11 +47,6 @@ struct Hint std::vector fields; }; -struct VecU64Result { - uint64_t nElements; - uint64_t* ids; -}; - struct ParserParams { uint32_t stage = 0; @@ -143,7 +138,9 @@ class ExpressionsBin void loadGlobalBin(BinFileUtils::BinFile *globalBin); - VecU64Result getHintIdsByName(std::string name); + uint64_t getNumberHintIdsByName(std::string name); + + void getHintIdsByName(uint64_t* hintIds, std::string name); }; diff --git a/pil2-stark/src/starkpil/global_constraints.hpp b/pil2-stark/src/starkpil/global_constraints.hpp index 1e4a15d7..98beb4f1 100644 --- a/pil2-stark/src/starkpil/global_constraints.hpp +++ b/pil2-stark/src/starkpil/global_constraints.hpp @@ -331,10 +331,32 @@ GlobalConstraintsResults * verifyGlobalConstraints(json& globalInfo, Expressions return constraintsInfo; } +std::string getExpressionDebug(json& globalInfo, ExpressionsBin &globalConstraintsBin, uint64_t hintId, std::string hintFieldName, HintFieldValue hintFieldVal) { + std::string debug = "Hint name " + hintFieldName + " for hint id " + to_string(hintId) + " is "; + if (hintFieldVal.operand == opType::tmp) { + if(globalConstraintsBin.expressionsInfo[hintFieldVal.id].line != "") { + debug += "the expression with id: " + to_string(hintFieldVal.id) + " " + globalConstraintsBin.expressionsInfo[hintFieldVal.id].line; + } + } else if (hintFieldVal.operand == opType::public_) { + debug += "public input " + to_string(globalInfo["publicsMap"][hintFieldVal.id]["name"]); + } else if (hintFieldVal.operand == opType::number) { + debug += "number " + to_string(hintFieldVal.value); + } else if (hintFieldVal.operand == opType::airgroupvalue) { + debug += "airgroupvalue "; + } else if (hintFieldVal.operand == opType::proofvalue) { + debug += "proof value " + to_string(globalInfo["proofValuesMap"][hintFieldVal.id]["name"]); + } else if (hintFieldVal.operand == opType::string_) { + debug += "string " + hintFieldVal.stringValue; + } else { + zklog.error("Unknown HintFieldType"); + exitProcess(); + exit(-1); + } -HintFieldValues getHintFieldGlobalConstraint(json& globalInfo, ExpressionsBin &globalConstraintsBin, Goldilocks::Element* publicInputs, Goldilocks::Element* challenges, Goldilocks::Element* proofValues, Goldilocks::Element** airgroupValues, uint64_t hintId, std::string hintFieldName, bool print_expression) { - + return debug; +} +uint64_t getHintFieldGlobalConstraintValues(ExpressionsBin &globalConstraintsBin, uint64_t hintId, std::string hintFieldName) { if(globalConstraintsBin.hints.size() == 0) { zklog.error("No hints were found."); exitProcess(); @@ -353,81 +375,129 @@ HintFieldValues getHintFieldGlobalConstraint(json& globalInfo, ExpressionsBin &g exit(-1); } - HintFieldValues hintFieldValues; - hintFieldValues.nValues = hintField->values.size(); - hintFieldValues.values = new HintFieldInfo[hintField->values.size()]; + return hintField->values.size(); +} + +void getHintFieldGlobalConstraintSizes(json& globalInfo, ExpressionsBin &globalConstraintsBin, HintFieldInfo *hintFieldValues, uint64_t hintId, std::string hintFieldName, bool print_expression) { + if(globalConstraintsBin.hints.size() == 0) { + zklog.error("No hints were found."); + exitProcess(); + exit(-1); + } + + Hint hint = globalConstraintsBin.hints[hintId]; + + auto hintField = std::find_if(hint.fields.begin(), hint.fields.end(), [hintFieldName](const HintField& hintField) { + return hintField.name == hintFieldName; + }); + + if(hintField == hint.fields.end()) { + zklog.error("Hint field " + hintFieldName + " not found in hint " + hint.name + "."); + exitProcess(); + exit(-1); + } for(uint64_t i = 0; i < hintField->values.size(); ++i) { HintFieldValue hintFieldVal = hintField->values[i]; - - HintFieldInfo hintFieldInfo; if(print_expression) { - cout << "--------------------------------------------------------" << endl; - cout << "Hint name " << hintFieldName << " for hint id " << hintId << " is "; + std::string expression_line = getExpressionDebug(globalInfo, globalConstraintsBin, hintId, hintFieldName, hintFieldVal); + hintFieldValues[i].expression_line_size = expression_line.size(); } + if (hintFieldVal.operand == opType::tmp) { uint64_t dim = globalConstraintsBin.expressionsInfo[hintFieldVal.id].destDim; - hintFieldInfo.size = dim; - hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; - hintFieldInfo.fieldType = dim == 1 ? HintFieldType::Column : HintFieldType::ColumnExtended; - hintFieldInfo.offset = dim; - if(print_expression && globalConstraintsBin.expressionsInfo[hintFieldVal.id].line != "") { - cout << "the expression with id: " << hintFieldVal.id << " " << globalConstraintsBin.expressionsInfo[hintFieldVal.id].line << endl; - } - + hintFieldValues[i].fieldType = dim == 1 ? HintFieldType::Column : HintFieldType::ColumnExtended; + hintFieldValues[i].offset = dim; + hintFieldValues[i].size = dim; + } else if (hintFieldVal.operand == opType::public_) { + hintFieldValues[i].size = 1; + hintFieldValues[i].fieldType = HintFieldType::Field; + hintFieldValues[i].offset = 1; + } else if (hintFieldVal.operand == opType::number) { + hintFieldValues[i].size = 1; + hintFieldValues[i].fieldType = HintFieldType::Field; + hintFieldValues[i].offset = 1; + } else if (hintFieldVal.operand == opType::airgroupvalue) { + hintFieldValues[i].size = FIELD_EXTENSION; + hintFieldValues[i].fieldType = HintFieldType::FieldExtended; + hintFieldValues[i].offset = FIELD_EXTENSION; + } else if (hintFieldVal.operand == opType::proofvalue) { + uint64_t dim = globalInfo["proofValuesMap"][hintFieldVal.id]["stage"] == 1 ? 1 : FIELD_EXTENSION; + hintFieldValues[i].size = dim; + hintFieldValues[i].fieldType = dim == 1 ? HintFieldType::Field : HintFieldType::FieldExtended; + hintFieldValues[i].offset = FIELD_EXTENSION; + } else if (hintFieldVal.operand == opType::string_) { + hintFieldValues[i].fieldType = HintFieldType::String; + hintFieldValues[i].size = hintFieldVal.stringValue.size(); + hintFieldValues[i].offset = 0; + } else { + zklog.error("Unknown HintFieldType"); + exitProcess(); + exit(-1); + } + + hintFieldValues[i].matrix_size = hintFieldVal.pos.size(); + } + + return; +} + +void getHintFieldGlobalConstraint(json& globalInfo, ExpressionsBin &globalConstraintsBin, HintFieldInfo *hintFieldValues, Goldilocks::Element* publicInputs, Goldilocks::Element* challenges, Goldilocks::Element* proofValues, Goldilocks::Element** airgroupValues, uint64_t hintId, std::string hintFieldName, bool print_expression) { + + + if(globalConstraintsBin.hints.size() == 0) { + zklog.error("No hints were found."); + exitProcess(); + exit(-1); + } + + Hint hint = globalConstraintsBin.hints[hintId]; + + auto hintField = std::find_if(hint.fields.begin(), hint.fields.end(), [hintFieldName](const HintField& hintField) { + return hintField.name == hintFieldName; + }); + + if(hintField == hint.fields.end()) { + zklog.error("Hint field " + hintFieldName + " not found in hint " + hint.name + "."); + exitProcess(); + exit(-1); + } + + for(uint64_t i = 0; i < hintField->values.size(); ++i) { + HintFieldValue hintFieldVal = hintField->values[i]; + + HintFieldInfo hintFieldInfo = hintFieldValues[i]; + + if(print_expression) { + std::string expression_line = getExpressionDebug(globalInfo, globalConstraintsBin, hintId, hintFieldName, hintFieldVal); + hintFieldValues[i].expression_line_size = expression_line.size(); + } + + if (hintFieldVal.operand == opType::tmp) { calculateGlobalExpression(globalInfo, hintFieldInfo.values, publicInputs, challenges, proofValues, airgroupValues, globalConstraintsBin.expressionsBinArgsExpressions, globalConstraintsBin.expressionsInfo[hintFieldVal.id]); } else if (hintFieldVal.operand == opType::public_) { - hintFieldInfo.size = 1; - hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; hintFieldInfo.values[0] = publicInputs[hintFieldVal.id]; - hintFieldInfo.fieldType = HintFieldType::Field; - hintFieldInfo.offset = 1; } else if (hintFieldVal.operand == opType::number) { - hintFieldInfo.size = 1; - hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; hintFieldInfo.values[0] = Goldilocks::fromU64(hintFieldVal.value); - hintFieldInfo.fieldType = HintFieldType::Field; - hintFieldInfo.offset = 1; - if(print_expression) cout << "number " << hintFieldVal.value << endl; } else if (hintFieldVal.operand == opType::airgroupvalue) { - hintFieldInfo.size = FIELD_EXTENSION; - hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; - hintFieldInfo.fieldType = HintFieldType::FieldExtended; - hintFieldInfo.offset = FIELD_EXTENSION; std::memcpy(hintFieldInfo.values, &airgroupValues[hintFieldVal.dim][FIELD_EXTENSION*hintFieldVal.id], FIELD_EXTENSION * sizeof(Goldilocks::Element)); } else if (hintFieldVal.operand == opType::proofvalue) { - uint64_t dim = globalInfo["proofValuesMap"][hintFieldVal.id]["stage"] == 1 ? 1 : FIELD_EXTENSION; - hintFieldInfo.size = dim; - hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; - hintFieldInfo.fieldType = dim == 1 ? HintFieldType::Field : HintFieldType::FieldExtended; - hintFieldInfo.offset = FIELD_EXTENSION; std::memcpy(hintFieldInfo.values, &proofValues[FIELD_EXTENSION*hintFieldVal.id], hintFieldInfo.size * sizeof(Goldilocks::Element)); } else if (hintFieldVal.operand == opType::string_) { - hintFieldInfo.values = nullptr; - hintFieldInfo.fieldType = HintFieldType::String; - hintFieldInfo.size = hintFieldVal.stringValue.size(); - hintFieldInfo.stringValue = new uint8_t[hintFieldVal.stringValue.size()]; std::memcpy(hintFieldInfo.stringValue, hintFieldVal.stringValue.data(), hintFieldVal.stringValue.size()); - hintFieldInfo.offset = 0; - if(print_expression) cout << "string " << hintFieldVal.stringValue << endl; } else { zklog.error("Unknown HintFieldType"); exitProcess(); exit(-1); } - if(print_expression) cout << "--------------------------------------------------------" << endl; - - hintFieldInfo.matrix_size = hintFieldVal.pos.size(); - hintFieldInfo.pos = new uint64_t[hintFieldInfo.matrix_size]; for(uint64_t i = 0; i < hintFieldInfo.matrix_size; ++i) { hintFieldInfo.pos[i] = hintFieldVal.pos[i]; } - hintFieldValues.values[i] = hintFieldInfo; } - return hintFieldValues; + return; } diff --git a/pil2-stark/src/starkpil/hints.hpp b/pil2-stark/src/starkpil/hints.hpp index 65ca17a6..b7e3c8c0 100644 --- a/pil2-stark/src/starkpil/hints.hpp +++ b/pil2-stark/src/starkpil/hints.hpp @@ -9,7 +9,8 @@ typedef enum { } HintFieldType; struct HintFieldInfo { - uint64_t size; // Destination size (in Goldilocks elements) + uint64_t size; + uint64_t string_size; uint8_t offset; HintFieldType fieldType; Goldilocks::Element* values; @@ -20,11 +21,6 @@ struct HintFieldInfo { uint64_t expression_line_size; }; -struct HintFieldValues { - uint64_t nValues; - HintFieldInfo* values; -}; - struct HintFieldArgs { std::string name; bool inverse = false; @@ -163,11 +159,27 @@ std::string getExpressionDebug(SetupCtx& setupCtx, uint64_t hintId, std::string return debug; } -HintFieldValues getHintField( +uint64_t getHintFieldValues(SetupCtx& setupCtx, uint64_t hintId, std::string hintFieldName) { + Hint hint = setupCtx.expressionsBin.hints[hintId]; + + auto hintField = std::find_if(hint.fields.begin(), hint.fields.end(), [hintFieldName](const HintField& hintField) { + return hintField.name == hintFieldName; + }); + + if(hintField == hint.fields.end()) { + zklog.error("Hint field " + hintFieldName + " not found in hint " + hint.name + "."); + exitProcess(); + exit(-1); + } + + return hintField->values.size(); +} + +void getHintFieldSizes( SetupCtx& setupCtx, - StepsParams ¶ms, + HintFieldInfo *hintFieldValues, uint64_t hintId, - std::string hintFieldName, + std::string hintFieldName, HintFieldOptions& hintOptions ) { @@ -191,9 +203,108 @@ HintFieldValues getHintField( exit(-1); } - HintFieldValues hintFieldValues; - hintFieldValues.nValues = hintField->values.size(); - hintFieldValues.values = new HintFieldInfo[hintField->values.size()]; + for(uint64_t i = 0; i < hintField->values.size(); ++i) { + HintFieldValue hintFieldVal = hintField->values[i]; + + if(hintOptions.print_expression) { + std::string expression_line = getExpressionDebug(setupCtx, hintId, hintFieldName, hintFieldVal); + hintFieldValues[i].expression_line_size = expression_line.size(); + } + if(hintFieldVal.operand == opType::cm) { + uint64_t dim = setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].dim; + hintFieldValues[i].size = deg*dim; + hintFieldValues[i].fieldType = dim == 1 ? HintFieldType::Column : HintFieldType::ColumnExtended; + hintFieldValues[i].offset = dim; + } else if(hintFieldVal.operand == opType::custom) { + uint64_t dim = setupCtx.starkInfo.customCommitsMap[hintFieldVal.commitId][hintFieldVal.id].dim; + hintFieldValues[i].size = deg*dim; + hintFieldValues[i].fieldType = dim == 1 ? HintFieldType::Column : HintFieldType::ColumnExtended; + hintFieldValues[i].offset = dim; + } else if(hintFieldVal.operand == opType::const_) { + uint64_t dim = setupCtx.starkInfo.constPolsMap[hintFieldVal.id].dim; + hintFieldValues[i].size = deg*dim; + hintFieldValues[i].fieldType = dim == 1 ? HintFieldType::Column : HintFieldType::ColumnExtended; + hintFieldValues[i].offset = dim; + } else if (hintFieldVal.operand == opType::tmp) { + if(hintOptions.compilation_time) { + hintFieldValues[i].size = 1; + hintFieldValues[i].fieldType = HintFieldType::Field; + hintFieldValues[i].offset = 1; + } else { + uint64_t dim = setupCtx.expressionsBin.expressionsInfo[hintFieldVal.id].destDim; + hintFieldValues[i].size = deg*dim; + hintFieldValues[i].fieldType = dim == 1 ? HintFieldType::Column : HintFieldType::ColumnExtended; + hintFieldValues[i].offset = dim; + } + } else if (hintFieldVal.operand == opType::public_) { + hintFieldValues[i].size = 1; + hintFieldValues[i].fieldType = HintFieldType::Field; + hintFieldValues[i].offset = 1; + } else if (hintFieldVal.operand == opType::number) { + hintFieldValues[i].size = 1; + hintFieldValues[i].fieldType = HintFieldType::Field; + hintFieldValues[i].offset = 1; + } else if (hintFieldVal.operand == opType::airgroupvalue) { + uint64_t dim = setupCtx.starkInfo.airgroupValuesMap[hintFieldVal.id].stage == 1 ? 1 : FIELD_EXTENSION; + hintFieldValues[i].size = dim; + hintFieldValues[i].fieldType = dim == 1 ? HintFieldType::Field : HintFieldType::FieldExtended; + hintFieldValues[i].offset = dim; + } else if (hintFieldVal.operand == opType::airvalue) { + uint64_t dim = setupCtx.starkInfo.airValuesMap[hintFieldVal.id].stage == 1 ? 1 : FIELD_EXTENSION; + hintFieldValues[i].size = dim; + hintFieldValues[i].fieldType = dim == 1 ? HintFieldType::Field : HintFieldType::FieldExtended; + hintFieldValues[i].offset = dim; + } else if (hintFieldVal.operand == opType::proofvalue) { + uint64_t dim = setupCtx.starkInfo.proofValuesMap[hintFieldVal.id].stage == 1 ? 1 : FIELD_EXTENSION; + hintFieldValues[i].size = dim; + hintFieldValues[i].fieldType = dim == 1 ? HintFieldType::Field : HintFieldType::FieldExtended; + hintFieldValues[i].offset = dim; + } else if (hintFieldVal.operand == opType::challenge) { + hintFieldValues[i].size = FIELD_EXTENSION; + hintFieldValues[i].fieldType = HintFieldType::FieldExtended; + hintFieldValues[i].offset = FIELD_EXTENSION; + } else if (hintFieldVal.operand == opType::string_) { + hintFieldValues[i].string_size = hintFieldVal.stringValue.size(); + hintFieldValues[i].fieldType = HintFieldType::String; + hintFieldValues[i].offset = 0; + } else { + zklog.error("Unknown HintFieldType"); + exitProcess(); + exit(-1); + } + + hintFieldValues[i].matrix_size = hintFieldVal.pos.size(); + } + + return; +} + +void getHintField( + SetupCtx& setupCtx, + StepsParams ¶ms, + HintFieldInfo *hintFieldValues, + uint64_t hintId, + std::string hintFieldName, + HintFieldOptions& hintOptions +) { + + if(setupCtx.expressionsBin.hints.size() == 0) { + zklog.error("No hints were found."); + exitProcess(); + exit(-1); + } + + Hint hint = setupCtx.expressionsBin.hints[hintId]; + + auto hintField = std::find_if(hint.fields.begin(), hint.fields.end(), [hintFieldName](const HintField& hintField) { + return hintField.name == hintFieldName; + }); + + if(hintField == hint.fields.end()) { + zklog.error("Hint field " + hintFieldName + " not found in hint " + hint.name + "."); + exitProcess(); + exit(-1); + } for(uint64_t i = 0; i < hintField->values.size(); ++i) { HintFieldValue hintFieldVal = hintField->values[i]; @@ -203,20 +314,14 @@ HintFieldValues getHintField( exit(-1); } - HintFieldInfo hintFieldInfo; + HintFieldInfo hintFieldInfo = hintFieldValues[i]; if(hintOptions.print_expression) { std::string expression_line = getExpressionDebug(setupCtx, hintId, hintFieldName, hintFieldVal); - hintFieldInfo.expression_line = new uint8_t[expression_line.size()]; std::memcpy(hintFieldInfo.expression_line, expression_line.data(), expression_line.size()); hintFieldInfo.expression_line_size = expression_line.size(); } if(hintFieldVal.operand == opType::cm) { - uint64_t dim = setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].dim; - hintFieldInfo.size = deg*dim; - hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; - hintFieldInfo.fieldType = dim == 1 ? HintFieldType::Column : HintFieldType::ColumnExtended; - hintFieldInfo.offset = dim; if(!hintOptions.dest) { Goldilocks::Element *pAddress = setupCtx.starkInfo.cmPolsMap[hintFieldVal.id].stage == 1 ? params.trace : params.aux_trace; getPolynomial(setupCtx, pAddress, hintFieldInfo.values, setupCtx.starkInfo.cmPolsMap[hintFieldVal.id], hintFieldVal.rowOffsetIndex, "cm"); @@ -228,22 +333,12 @@ HintFieldValues getHintField( memset((uint8_t *)hintFieldInfo.values, 0, hintFieldInfo.size * sizeof(Goldilocks::Element)); } } else if(hintFieldVal.operand == opType::custom) { - uint64_t dim = setupCtx.starkInfo.customCommitsMap[hintFieldVal.commitId][hintFieldVal.id].dim; - hintFieldInfo.size = deg*dim; - hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; - hintFieldInfo.fieldType = dim == 1 ? HintFieldType::Column : HintFieldType::ColumnExtended; - hintFieldInfo.offset = dim; getPolynomial(setupCtx, params.pCustomCommits[hintFieldVal.commitId], hintFieldInfo.values, setupCtx.starkInfo.customCommitsMap[hintFieldVal.commitId][hintFieldVal.id], hintFieldVal.rowOffsetIndex, "custom"); if(hintOptions.inverse) { zklog.error("Inverse not supported still for polynomials"); exitProcess(); } } else if(hintFieldVal.operand == opType::const_) { - uint64_t dim = setupCtx.starkInfo.constPolsMap[hintFieldVal.id].dim; - hintFieldInfo.size = deg*dim; - hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; - hintFieldInfo.fieldType = dim == 1 ? HintFieldType::Column : HintFieldType::ColumnExtended; - hintFieldInfo.offset = dim; getPolynomial(setupCtx, params.pConstPolsAddress, hintFieldInfo.values, setupCtx.starkInfo.constPolsMap[hintFieldVal.id], hintFieldVal.rowOffsetIndex, "const"); if(hintOptions.inverse) { zklog.error("Inverse not supported still for polynomials"); @@ -251,18 +346,9 @@ HintFieldValues getHintField( } } else if (hintFieldVal.operand == opType::tmp) { if(hintOptions.compilation_time) { - hintFieldInfo.size = 1; - hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; - hintFieldInfo.fieldType = HintFieldType::Field; - hintFieldInfo.offset = 1; ExpressionsPack expressionsCtx(setupCtx, 1); expressionsCtx.calculateExpression(params, hintFieldInfo.values, hintFieldVal.id, hintOptions.inverse, true); } else { - uint64_t dim = setupCtx.expressionsBin.expressionsInfo[hintFieldVal.id].destDim; - hintFieldInfo.size = deg*dim; - hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; - hintFieldInfo.fieldType = dim == 1 ? HintFieldType::Column : HintFieldType::ColumnExtended; - hintFieldInfo.offset = dim; #ifdef __AVX512__ ExpressionsAvx512 expressionsCtx(setupCtx); #elif defined(__AVX2__) @@ -273,23 +359,10 @@ HintFieldValues getHintField( expressionsCtx.calculateExpression(params, hintFieldInfo.values, hintFieldVal.id, hintOptions.inverse, false); } } else if (hintFieldVal.operand == opType::public_) { - hintFieldInfo.size = 1; - hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; hintFieldInfo.values[0] = hintOptions.inverse ? Goldilocks::inv(params.publicInputs[hintFieldVal.id]) : params.publicInputs[hintFieldVal.id]; - hintFieldInfo.fieldType = HintFieldType::Field; - hintFieldInfo.offset = 1; } else if (hintFieldVal.operand == opType::number) { - hintFieldInfo.size = 1; - hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; hintFieldInfo.values[0] = hintOptions.inverse ? Goldilocks::inv(Goldilocks::fromU64(hintFieldVal.value)) : Goldilocks::fromU64(hintFieldVal.value); - hintFieldInfo.fieldType = HintFieldType::Field; - hintFieldInfo.offset = 1; } else if (hintFieldVal.operand == opType::airgroupvalue) { - uint64_t dim = setupCtx.starkInfo.airgroupValuesMap[hintFieldVal.id].stage == 1 ? 1 : FIELD_EXTENSION; - hintFieldInfo.size = dim; - hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; - hintFieldInfo.fieldType = dim == 1 ? HintFieldType::Field : HintFieldType::FieldExtended; - hintFieldInfo.offset = dim; if(!hintOptions.dest) { if(hintOptions.inverse) { Goldilocks3::inv((Goldilocks3::Element *)hintFieldInfo.values, (Goldilocks3::Element *)¶ms.airgroupValues[FIELD_EXTENSION*hintFieldVal.id]); @@ -298,11 +371,6 @@ HintFieldValues getHintField( } } } else if (hintFieldVal.operand == opType::airvalue) { - uint64_t dim = setupCtx.starkInfo.airValuesMap[hintFieldVal.id].stage == 1 ? 1 : FIELD_EXTENSION; - hintFieldInfo.size = dim; - hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; - hintFieldInfo.fieldType = dim == 1 ? HintFieldType::Field : HintFieldType::FieldExtended; - hintFieldInfo.offset = dim; if(!hintOptions.dest) { if(hintOptions.inverse) { Goldilocks3::inv((Goldilocks3::Element *)hintFieldInfo.values, (Goldilocks3::Element *)¶ms.airValues[FIELD_EXTENSION*hintFieldVal.id]); @@ -311,11 +379,6 @@ HintFieldValues getHintField( } } } else if (hintFieldVal.operand == opType::proofvalue) { - uint64_t dim = setupCtx.starkInfo.proofValuesMap[hintFieldVal.id].stage == 1 ? 1 : FIELD_EXTENSION; - hintFieldInfo.size = dim; - hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; - hintFieldInfo.fieldType = dim == 1 ? HintFieldType::Field : HintFieldType::FieldExtended; - hintFieldInfo.offset = dim; if(!hintOptions.dest) { if(hintOptions.inverse) { Goldilocks3::inv((Goldilocks3::Element *)hintFieldInfo.values, (Goldilocks3::Element *)¶ms.proofValues[FIELD_EXTENSION*hintFieldVal.id]); @@ -324,37 +387,25 @@ HintFieldValues getHintField( } } } else if (hintFieldVal.operand == opType::challenge) { - hintFieldInfo.size = FIELD_EXTENSION; - hintFieldInfo.values = new Goldilocks::Element[hintFieldInfo.size]; - hintFieldInfo.fieldType = HintFieldType::FieldExtended; - hintFieldInfo.offset = FIELD_EXTENSION; if(hintOptions.inverse) { Goldilocks3::inv((Goldilocks3::Element *)hintFieldInfo.values, (Goldilocks3::Element *)¶ms.challenges[FIELD_EXTENSION*hintFieldVal.id]); } else { std::memcpy(hintFieldInfo.values, ¶ms.challenges[FIELD_EXTENSION*hintFieldVal.id], hintFieldInfo.size * sizeof(Goldilocks::Element)); } } else if (hintFieldVal.operand == opType::string_) { - hintFieldInfo.values = nullptr; - hintFieldInfo.fieldType = HintFieldType::String; - hintFieldInfo.size = hintFieldVal.stringValue.size(); - hintFieldInfo.stringValue = new uint8_t[hintFieldVal.stringValue.size()]; - std::memcpy(hintFieldInfo.stringValue, hintFieldVal.stringValue.data(), hintFieldVal.stringValue.size()); - hintFieldInfo.offset = 0; + std::memcpy(hintFieldInfo.stringValue, hintFieldVal.stringValue.data(), hintFieldVal.stringValue.size()); } else { zklog.error("Unknown HintFieldType"); exitProcess(); exit(-1); } - hintFieldInfo.matrix_size = hintFieldVal.pos.size(); - hintFieldInfo.pos = new uint64_t[hintFieldInfo.matrix_size]; for(uint64_t i = 0; i < hintFieldInfo.matrix_size; ++i) { hintFieldInfo.pos[i] = hintFieldVal.pos[i]; } - hintFieldValues.values[i] = hintFieldInfo; } - return hintFieldValues; + return; } uint64_t setHintField(SetupCtx& setupCtx, StepsParams& params, Goldilocks::Element* values, uint64_t hintId, std::string hintFieldName) { @@ -417,7 +468,6 @@ void addHintField(SetupCtx& setupCtx, StepsParams& params, uint64_t hintId, Dest if(hintFieldOptions.print_expression) { std::string expression_line = getExpressionDebug(setupCtx, hintId, hintFieldName, hintFieldVal); - cout << expression_line << endl; } if(hintFieldVal.operand == opType::cm) { destStruct.addCmPol(setupCtx.starkInfo.cmPolsMap[hintFieldVal.id], hintFieldVal.rowOffsetIndex, hintFieldOptions.inverse); @@ -476,22 +526,28 @@ uint64_t multiplyHintFields(SetupCtx& setupCtx, StepsParams ¶ms, uint64_t hi return hintFieldDestVal.id; } -VecU64Result accHintField(SetupCtx& setupCtx, StepsParams ¶ms, uint64_t hintId, std::string hintFieldNameDest, std::string hintFieldNameAirgroupVal, std::string hintFieldName, bool add) { +void accHintField(SetupCtx& setupCtx, StepsParams ¶ms, uint64_t hintId, std::string hintFieldNameDest, std::string hintFieldNameAirgroupVal, std::string hintFieldName, bool add) { + uint64_t N = 1 << setupCtx.starkInfo.starkStruct.nBits; + Hint hint = setupCtx.expressionsBin.hints[hintId]; auto hintFieldDest = std::find_if(hint.fields.begin(), hint.fields.end(), [hintFieldNameDest](const HintField& hintField) { return hintField.name == hintFieldNameDest; }); + + HintFieldOptions hintOptions; HintFieldValue hintFieldDestVal = hintFieldDest->values[0]; + + uint64_t dim = setupCtx.starkInfo.cmPolsMap[hintFieldDestVal.id].dim; + Goldilocks::Element *vals = new Goldilocks::Element[dim * N]; - HintFieldOptions hintOptions; - HintFieldValues hintValues = getHintField(setupCtx, params, hintId, hintFieldName, hintOptions); + Dest destStruct(vals, 0); + addHintField(setupCtx, params, hintId, destStruct, hintFieldName, hintOptions); - Goldilocks::Element *vals = &hintValues.values[0].values[0]; + std::vector dests = {destStruct}; - uint64_t dim = setupCtx.starkInfo.cmPolsMap[hintFieldDestVal.id].dim; + opHintFields(setupCtx, params, dests); - uint64_t N = 1 << setupCtx.starkInfo.starkStruct.nBits; for(uint64_t i = 1; i < N; ++i) { if(add) { if(dim == 1) { @@ -508,18 +564,22 @@ VecU64Result accHintField(SetupCtx& setupCtx, StepsParams ¶ms, uint64_t hint } } - VecU64Result hintIds; - hintIds.nElements = 2; - hintIds.ids = new uint64_t[hintIds.nElements]; - hintIds.ids[0] = setHintField(setupCtx, params, vals, hintId, hintFieldNameDest); - hintIds.ids[1] = setHintField(setupCtx, params, &vals[(N - 1)*FIELD_EXTENSION], hintId, hintFieldNameAirgroupVal); + setHintField(setupCtx, params, vals, hintId, hintFieldNameDest); + setHintField(setupCtx, params, &vals[(N - 1)*FIELD_EXTENSION], hintId, hintFieldNameAirgroupVal); - delete[] hintValues.values; + delete[] vals; +} + +uint64_t getHintId(SetupCtx& setupCtx, uint64_t hintId, std::string name) { + Hint hint = setupCtx.expressionsBin.hints[hintId]; - return hintIds; + auto hintField = std::find_if(hint.fields.begin(), hint.fields.end(), [name](const HintField& hintField) { + return hintField.name == name; + }); + return hintField->values[0].id; } -VecU64Result accMulHintFields(SetupCtx& setupCtx, StepsParams ¶ms, uint64_t hintId, std::string hintFieldNameDest, std::string hintFieldNameAirgroupVal, std::string hintFieldName1, std::string hintFieldName2, HintFieldOptions &hintOptions1, HintFieldOptions &hintOptions2, bool add) { +void accMulHintFields(SetupCtx& setupCtx, StepsParams ¶ms, uint64_t hintId, std::string hintFieldNameDest, std::string hintFieldNameAirgroupVal, std::string hintFieldName1, std::string hintFieldName2, HintFieldOptions &hintOptions1, HintFieldOptions &hintOptions2, bool add) { uint64_t N = 1 << setupCtx.starkInfo.starkStruct.nBits; Hint hint = setupCtx.expressionsBin.hints[hintId]; @@ -556,18 +616,13 @@ VecU64Result accMulHintFields(SetupCtx& setupCtx, StepsParams ¶ms, uint64_t } } - VecU64Result hintIds; - hintIds.nElements = 2; - hintIds.ids = new uint64_t[hintIds.nElements]; - hintIds.ids[0] = setHintField(setupCtx, params, vals, hintId, hintFieldNameDest); - hintIds.ids[1] = setHintField(setupCtx, params, &vals[(N - 1)*FIELD_EXTENSION], hintId, hintFieldNameAirgroupVal); - + setHintField(setupCtx, params, vals, hintId, hintFieldNameDest); + setHintField(setupCtx, params, &vals[(N - 1)*FIELD_EXTENSION], hintId, hintFieldNameAirgroupVal); + delete[] vals; - - return hintIds; } -VecU64Result updateAirgroupValue(SetupCtx& setupCtx, StepsParams ¶ms, uint64_t hintId, std::string hintFieldNameAirgroupVal, std::string hintFieldName1, std::string hintFieldName2, HintFieldOptions &hintOptions1, HintFieldOptions &hintOptions2, bool add) { +uint64_t updateAirgroupValue(SetupCtx& setupCtx, StepsParams ¶ms, uint64_t hintId, std::string hintFieldNameAirgroupVal, std::string hintFieldName1, std::string hintFieldName2, HintFieldOptions &hintOptions1, HintFieldOptions &hintOptions2, bool add) { Hint hint = setupCtx.expressionsBin.hints[hintId]; @@ -576,7 +631,7 @@ VecU64Result updateAirgroupValue(SetupCtx& setupCtx, StepsParams ¶ms, uint64 }); HintFieldValue hintFieldAirgroupVal = hintFieldAirgroup->values[0]; - Goldilocks::Element *vals = new Goldilocks::Element[3]; + Goldilocks::Element vals[3]; Dest destStruct(vals, 0); addHintField(setupCtx, params, hintId, destStruct, hintFieldName1, hintOptions1); @@ -602,12 +657,5 @@ VecU64Result updateAirgroupValue(SetupCtx& setupCtx, StepsParams ¶ms, uint64 } } - VecU64Result hintIds; - hintIds.nElements = 1; - hintIds.ids = new uint64_t[1]; - hintIds.ids[0] = hintFieldAirgroupVal.id; - - delete[] vals; - - return hintIds; + return hintFieldAirgroupVal.id; } diff --git a/pil2-stark/src/starkpil/stark_info.cpp b/pil2-stark/src/starkpil/stark_info.cpp index 64f95d21..c2e9d756 100644 --- a/pil2-stark/src/starkpil/stark_info.cpp +++ b/pil2-stark/src/starkpil/stark_info.cpp @@ -224,8 +224,7 @@ void StarkInfo::load(json j) mapSectionsN[it.key()] = it.value(); } - setMapOffsets(); - + setMapOffsets(); } void StarkInfo::setMapOffsets() { diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index 4a05aeac..be98b6ae 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -264,8 +264,9 @@ impl ProofMan { } let mut buff_helper_size = 0_usize; + for prover in provers.iter_mut() { - let buff_helper_prover_size = prover.get_buff_helper_size(); + let buff_helper_prover_size = prover.get_buff_helper_size(pctx.clone()); if buff_helper_prover_size > buff_helper_size { buff_helper_size = buff_helper_prover_size; } @@ -659,10 +660,23 @@ impl ProofMan { let air_instance_map = air_instances.entry(air_group_name).or_insert_with(HashMap::new); if !air_instance_map.contains_key(&air_name.clone()) { let setup = sctx.get_setup(air_instance.airgroup_id, air_instance.air_id); - let n_cols = setup.stark_info.map_sections_n.get("cm1").unwrap(); let n_bits = setup.stark_info.stark_struct.n_bits; - let total_mem = get_map_totaln_c(setup.p_setup.p_stark_info) as f64 * 8.0 / (1024.0 * 1024.0 * 1024.0); - air_info.insert(air_name.clone(), (n_cols, n_bits, total_mem)); + let memory_instance = + get_map_totaln_c(setup.p_setup.p_stark_info) as f64 * 8.0 / (1024.0 * 1024.0 * 1024.0); + let memory_fixed = (setup.stark_info.n_constants * (1 << (setup.stark_info.stark_struct.n_bits)) + + setup.stark_info.n_constants * (1 << (setup.stark_info.stark_struct.n_bits_ext))) + as f64 + * 8.0 + / (1024.0 * 1024.0 * 1024.0); + let memory_helpers = setup.stark_info.get_buff_helper_size() as f64; + let total_cols: u64 = setup + .stark_info + .map_sections_n + .iter() + .filter(|(key, _)| *key != "const") + .map(|(_, value)| *value) + .sum(); + air_info.insert(air_name.clone(), (n_bits, total_cols, memory_fixed, memory_helpers, memory_instance)); } let air_instance_map_key = air_instance_map.entry(air_name).or_insert(0); *air_instance_map_key += 1; @@ -673,7 +687,7 @@ impl ProofMan { info!("{}: --- PROOF INSTANCES SUMMARY ------------------------", Self::MY_NAME); info!("{}: ► {} Air instances found:", Self::MY_NAME, air_instances_repo.len()); - for air_group in air_groups { + for air_group in air_groups.clone() { let air_group_instances = air_instances.get(air_group).unwrap(); let mut air_names: Vec<_> = air_group_instances.keys().collect(); air_names.sort(); @@ -681,20 +695,57 @@ impl ProofMan { info!("{}: Air Group [{}]", Self::MY_NAME, air_group); for air_name in air_names { let count = air_group_instances.get(air_name).unwrap(); - let (n_cols, n_bits, total_memory) = air_info.get(air_name).unwrap(); + let (n_bits, total_cols, _, _, _) = air_info.get(air_name).unwrap(); + info!( + "{}: {}", + Self::MY_NAME, + format!("· {} x Air [{}] ({} x 2^{})", count, air_name, total_cols, n_bits).bright_white().bold() + ); + } + } + info!("{}: --- PROOF INSTANCES SUMMARY ------------------------", Self::MY_NAME); + info!("{}: --- PROVER MEMORY USAGE ------------------------", Self::MY_NAME); + info!("{}: ► {} Air instances found:", Self::MY_NAME, air_instances_repo.len()); + let mut total_memory = 0f64; + let mut memory_helper_size = 0f64; + for air_group in air_groups { + let air_group_instances = air_instances.get(air_group).unwrap(); + let mut air_names: Vec<_> = air_group_instances.keys().collect(); + air_names.sort(); + + for air_name in air_names { + let count = air_group_instances.get(air_name).unwrap(); + let (_, _, memory_fixed, memory_helper_instance_size, memory_instance) = + air_info.get(air_name).unwrap(); + let total_memory_instance = memory_fixed + memory_instance * *count as f64; + total_memory += total_memory_instance; + if *memory_helper_instance_size > memory_helper_size { + memory_helper_size = *memory_helper_instance_size; + } info!( "{}: {}", Self::MY_NAME, format!( - "· {} x Air [{}] ({} x 2^{}) ({:.2} GB each)", - count, air_name, n_cols, n_bits, total_memory + "· {}: {:.2} GB fixed cols | {:.2} GB per each of {} instance | Total {:.2} GB", + air_name, memory_fixed, memory_instance, count, total_memory_instance ) .bright_white() .bold() ); } } - info!("{}: --- PROOF INSTANCES SUMMARY ------------------------", Self::MY_NAME); + memory_helper_size = memory_helper_size * 8.0 / (1024.0 * 1024.0 * 1024.0); + info!( + "{}: {}", + Self::MY_NAME, + format!("Extra helper memory: {:.2} GB", memory_helper_size).bright_white().bold() + ); + info!( + "{}: {}", + Self::MY_NAME, + format!("Total prover memory required: {:.2} GB", total_memory).bright_white().bold() + ); + info!("{}: --- PROVER MEMORY USAGE ------------------------", Self::MY_NAME); } fn check_paths( diff --git a/provers/stark/src/stark_prover.rs b/provers/stark/src/stark_prover.rs index 4ebfd282..efc4f782 100644 --- a/provers/stark/src/stark_prover.rs +++ b/provers/stark/src/stark_prover.rs @@ -21,12 +21,6 @@ use p3_field::PrimeField64; use std::os::raw::c_void; use std::marker::PhantomData; -#[repr(C)] -pub struct VecU64Result { - pub n_elements: u64, - pub ids: *mut u64, -} - #[allow(dead_code)] pub struct StarkProver { prover_idx: usize, @@ -226,6 +220,10 @@ impl Prover for StarkProver { fn commit_stage(&mut self, stage_id: u32, proof_ctx: Arc>) -> ProverStatus { let air_instance = &mut proof_ctx.air_instance_repo.air_instances.write().unwrap()[self.prover_idx]; + if stage_id == self.num_stages() { + air_instance.clear_trace(); + } + let p_stark = self.p_stark; let p_proof = self.p_proof; @@ -378,24 +376,12 @@ impl Prover for StarkProver { compute_lev_c(self.p_stark, xi_challenge, proof_ctx.get_buff_helper_ptr()); } - fn get_buff_helper_size(&self) -> usize { - let mut max_cols = 0; - for stage in 1..=Self::num_stages(self) + 1 { - let n_cols = *self.stark_info.map_sections_n.get(&format!("cm{}", stage)).unwrap() as usize; - if n_cols > max_cols { - max_cols = n_cols; - } - } - - let n_extended = (1 << self.stark_info.stark_struct.n_bits_ext) as usize; - let buff_size_stages = max_cols * n_extended; + fn get_buff_helper_size(&self, _proof_ctx: Arc>) -> usize { + // if proof_ctx.options.verify_constraints { - let buff_size_xdivxsub = self.stark_info.opening_points.len() * 3 * n_extended; - - match buff_size_stages > buff_size_xdivxsub { - true => buff_size_stages, - false => buff_size_xdivxsub, - } + // } else { + self.stark_info.get_buff_helper_size() + // } } fn calculate_hash(&self, values: Vec) -> Vec { diff --git a/provers/starks-lib-c/bindings_starks.rs b/provers/starks-lib-c/bindings_starks.rs index a19b15f6..82394942 100644 --- a/provers/starks-lib-c/bindings_starks.rs +++ b/provers/starks-lib-c/bindings_starks.rs @@ -67,11 +67,17 @@ extern "C" { pub fn fri_proof_free(pFriProof: *mut ::std::os::raw::c_void); } extern "C" { - #[link_name = "\u{1}_Z20get_hint_ids_by_namePvPc"] + #[link_name = "\u{1}_Z15n_hints_by_namePvPc"] + pub fn n_hints_by_name(p_expression_bin: *mut ::std::os::raw::c_void, hintName: *mut ::std::os::raw::c_char) + -> u64; +} +extern "C" { + #[link_name = "\u{1}_Z20get_hint_ids_by_namePvPmPc"] pub fn get_hint_ids_by_name( p_expression_bin: *mut ::std::os::raw::c_void, + hintIds: *mut u64, hintName: *mut ::std::os::raw::c_char, - ) -> *mut ::std::os::raw::c_void; + ); } extern "C" { #[link_name = "\u{1}_Z14stark_info_newPc"] @@ -135,14 +141,33 @@ extern "C" { pub fn expressions_bin_free(pExpressionsBin: *mut ::std::os::raw::c_void); } extern "C" { - #[link_name = "\u{1}_Z14get_hint_fieldPvS_mPcS_"] + #[link_name = "\u{1}_Z14get_hint_fieldPvS_S_mPcS_"] pub fn get_hint_field( pSetupCtx: *mut ::std::os::raw::c_void, stepsParams: *mut ::std::os::raw::c_void, + hintFieldValues: *mut ::std::os::raw::c_void, hintId: u64, hintFieldName: *mut ::std::os::raw::c_char, hintOptions: *mut ::std::os::raw::c_void, - ) -> *mut ::std::os::raw::c_void; + ); +} +extern "C" { + #[link_name = "\u{1}_Z21get_hint_field_valuesPvmPc"] + pub fn get_hint_field_values( + pSetupCtx: *mut ::std::os::raw::c_void, + hintId: u64, + hintFieldName: *mut ::std::os::raw::c_char, + ) -> u64; +} +extern "C" { + #[link_name = "\u{1}_Z20get_hint_field_sizesPvS_mPcS_"] + pub fn get_hint_field_sizes( + pSetupCtx: *mut ::std::os::raw::c_void, + hintFieldValues: *mut ::std::os::raw::c_void, + hintId: u64, + hintFieldName: *mut ::std::os::raw::c_char, + hintOptions: *mut ::std::os::raw::c_void, + ); } extern "C" { #[link_name = "\u{1}_Z15mul_hint_fieldsPvS_mPcS0_S0_S_S_"] @@ -167,7 +192,7 @@ extern "C" { hintFieldNameAirgroupVal: *mut ::std::os::raw::c_char, hintFieldName: *mut ::std::os::raw::c_char, add: bool, - ) -> *mut ::std::os::raw::c_void; + ); } extern "C" { #[link_name = "\u{1}_Z19acc_mul_hint_fieldsPvS_mPcS0_S0_S0_S_S_b"] @@ -182,7 +207,7 @@ extern "C" { hintOptions1: *mut ::std::os::raw::c_void, hintOptions2: *mut ::std::os::raw::c_void, add: bool, - ) -> *mut ::std::os::raw::c_void; + ); } extern "C" { #[link_name = "\u{1}_Z20update_airgroupvaluePvS_mPcS0_S0_S_S_b"] @@ -196,7 +221,7 @@ extern "C" { hintOptions1: *mut ::std::os::raw::c_void, hintOptions2: *mut ::std::os::raw::c_void, add: bool, - ) -> *mut ::std::os::raw::c_void; + ) -> u64; } extern "C" { #[link_name = "\u{1}_Z14set_hint_fieldPvS_S_mPc"] @@ -208,6 +233,14 @@ extern "C" { hintFieldName: *mut ::std::os::raw::c_char, ) -> u64; } +extern "C" { + #[link_name = "\u{1}_Z11get_hint_idPvmPc"] + pub fn get_hint_id( + pSetupCtx: *mut ::std::os::raw::c_void, + hintId: u64, + hintFieldName: *mut ::std::os::raw::c_char, + ) -> u64; +} extern "C" { #[link_name = "\u{1}_Z10starks_newPvS_"] pub fn starks_new( @@ -429,10 +462,30 @@ extern "C" { ) -> *mut ::std::os::raw::c_void; } extern "C" { - #[link_name = "\u{1}_Z33get_hint_field_global_constraintsPcPvS0_S0_S0_PS0_mS_b"] + #[link_name = "\u{1}_Z40get_hint_field_global_constraints_valuesPvmPc"] + pub fn get_hint_field_global_constraints_values( + p_globalinfo_bin: *mut ::std::os::raw::c_void, + hintId: u64, + hintFieldName: *mut ::std::os::raw::c_char, + ) -> u64; +} +extern "C" { + #[link_name = "\u{1}_Z39get_hint_field_global_constraints_sizesPcPvS0_mS_b"] + pub fn get_hint_field_global_constraints_sizes( + globalInfoFile: *mut ::std::os::raw::c_char, + p_globalinfo_bin: *mut ::std::os::raw::c_void, + hintFieldValues: *mut ::std::os::raw::c_void, + hintId: u64, + hintFieldName: *mut ::std::os::raw::c_char, + print_expression: bool, + ); +} +extern "C" { + #[link_name = "\u{1}_Z33get_hint_field_global_constraintsPcPvS0_S0_S0_S0_PS0_mS_b"] pub fn get_hint_field_global_constraints( globalInfoFile: *mut ::std::os::raw::c_char, - globalBin: *mut ::std::os::raw::c_void, + p_globalinfo_bin: *mut ::std::os::raw::c_void, + hintFieldValues: *mut ::std::os::raw::c_void, publics: *mut ::std::os::raw::c_void, challenges: *mut ::std::os::raw::c_void, proofValues: *mut ::std::os::raw::c_void, @@ -440,7 +493,7 @@ extern "C" { hintId: u64, hintFieldName: *mut ::std::os::raw::c_char, print_expression: bool, - ) -> *mut ::std::os::raw::c_void; + ); } extern "C" { #[link_name = "\u{1}_Z33set_hint_field_global_constraintsPcPvS0_S0_mS_"] diff --git a/provers/starks-lib-c/src/ffi_starks.rs b/provers/starks-lib-c/src/ffi_starks.rs index 4ad6d3ce..6e9bb34d 100644 --- a/provers/starks-lib-c/src/ffi_starks.rs +++ b/provers/starks-lib-c/src/ffi_starks.rs @@ -4,12 +4,6 @@ use ::std::os::raw::c_void; -#[repr(C)] -pub struct VecU64Result { - pub n_values: u64, - pub values: *mut u64, -} - #[cfg(feature = "no_lib_link")] use log::trace; @@ -236,24 +230,34 @@ pub fn expressions_bin_free_c(p_expressions_bin: *mut c_void) { } #[cfg(not(feature = "no_lib_link"))] -pub fn get_hint_ids_by_name_c(p_expressions_bin: *mut c_void, hint_name: &str) -> *mut c_void { +pub fn n_hint_ids_by_name_c(p_expressions_bin: *mut c_void, hint_name: &str) -> u64 { + let name = CString::new(hint_name).unwrap(); + unsafe { n_hints_by_name(p_expressions_bin, name.as_ptr() as *mut std::os::raw::c_char) } +} + +#[cfg(not(feature = "no_lib_link"))] +pub fn get_hint_ids_by_name_c(p_expressions_bin: *mut c_void, hint_ids: *mut u64, hint_name: &str) { let name = CString::new(hint_name).unwrap(); - unsafe { get_hint_ids_by_name(p_expressions_bin, name.as_ptr() as *mut std::os::raw::c_char) } + unsafe { + get_hint_ids_by_name(p_expressions_bin, hint_ids, name.as_ptr() as *mut std::os::raw::c_char); + } } #[cfg(not(feature = "no_lib_link"))] pub fn get_hint_field_c( p_setup_ctx: *mut c_void, p_steps_params: *mut u8, + hint_field_values: *mut c_void, hint_id: u64, hint_field_name: &str, hint_options: *mut u8, -) -> *mut c_void { +) { let field_name = CString::new(hint_field_name).unwrap(); unsafe { get_hint_field( p_setup_ctx, p_steps_params as *mut std::os::raw::c_void, + hint_field_values, hint_id, field_name.as_ptr() as *mut std::os::raw::c_char, hint_options as *mut std::os::raw::c_void, @@ -261,6 +265,32 @@ pub fn get_hint_field_c( } } +#[cfg(not(feature = "no_lib_link"))] +pub fn get_hint_field_values_c(p_setup_ctx: *mut c_void, hint_id: u64, hint_field_name: &str) -> u64 { + let field_name = CString::new(hint_field_name).unwrap(); + unsafe { get_hint_field_values(p_setup_ctx, hint_id, field_name.as_ptr() as *mut std::os::raw::c_char) } +} + +#[cfg(not(feature = "no_lib_link"))] +pub fn get_hint_field_sizes_c( + p_setup_ctx: *mut c_void, + hint_field_values: *mut c_void, + hint_id: u64, + hint_field_name: &str, + hint_options: *mut u8, +) { + let field_name = CString::new(hint_field_name).unwrap(); + unsafe { + get_hint_field_sizes( + p_setup_ctx, + hint_field_values, + hint_id, + field_name.as_ptr() as *mut std::os::raw::c_char, + hint_options as *mut std::os::raw::c_void, + ); + } +} + #[cfg(not(feature = "no_lib_link"))] #[allow(clippy::too_many_arguments)] pub fn mul_hint_fields_c( @@ -300,7 +330,7 @@ pub fn acc_hint_field_c( hint_field_airgroupvalue: &str, hint_field_name: &str, add: bool, -) -> *mut c_void { +) { let field_dest = CString::new(hint_field_dest).unwrap(); let field_airgroupvalue = CString::new(hint_field_airgroupvalue).unwrap(); let field_name = CString::new(hint_field_name).unwrap(); @@ -314,7 +344,7 @@ pub fn acc_hint_field_c( field_airgroupvalue.as_ptr() as *mut std::os::raw::c_char, field_name.as_ptr() as *mut std::os::raw::c_char, add, - ) + ); } } @@ -331,7 +361,7 @@ pub fn acc_mul_hint_fields_c( hint_options1: *mut u8, hint_options2: *mut u8, add: bool, -) -> *mut c_void { +) { let field_dest = CString::new(hint_field_dest).unwrap(); let field_airgroupvalue = CString::new(hint_field_airgroupvalue).unwrap(); let field_name1 = CString::new(hint_field_name1).unwrap(); @@ -349,7 +379,7 @@ pub fn acc_mul_hint_fields_c( hint_options1 as *mut std::os::raw::c_void, hint_options2 as *mut std::os::raw::c_void, add, - ) + ); } } @@ -365,7 +395,7 @@ pub fn update_airgroupvalue_c( hint_options1: *mut u8, hint_options2: *mut u8, add: bool, -) -> *mut c_void { +) -> u64 { let field_airgroupvalue = CString::new(hint_field_airgroupvalue).unwrap(); let field_name1 = CString::new(hint_field_name1).unwrap(); let field_name2: CString = CString::new(hint_field_name2).unwrap(); @@ -405,6 +435,14 @@ pub fn set_hint_field_c( } } +#[cfg(not(feature = "no_lib_link"))] +pub fn get_hint_field_id_c(p_setup_ctx: *mut c_void, hint_id: u64, hint_field_name: &str) -> u64 { + unsafe { + let field_name = CString::new(hint_field_name).unwrap(); + get_hint_id(p_setup_ctx, hint_id, field_name.as_ptr() as *mut std::os::raw::c_char) + } +} + #[cfg(not(feature = "no_lib_link"))] pub fn starks_new_c(p_setup_ctx: *mut c_void, p_const_tree: *mut u8) -> *mut c_void { unsafe { starks_new(p_setup_ctx, p_const_tree as *mut std::os::raw::c_void) } @@ -714,6 +752,7 @@ pub fn verify_global_constraints_c( pub fn get_hint_field_global_constraints_c( global_info_file: &str, p_global_constraints_bin: *mut c_void, + hint_field_values: *mut c_void, publics: *mut u8, challenges: *mut u8, proof_values: *mut u8, @@ -721,7 +760,7 @@ pub fn get_hint_field_global_constraints_c( hint_id: u64, hint_field_name: &str, print_expression: bool, -) -> *mut c_void { +) { let field_name = CString::new(hint_field_name).unwrap(); let global_info_file_name = CString::new(global_info_file).unwrap(); @@ -731,6 +770,7 @@ pub fn get_hint_field_global_constraints_c( get_hint_field_global_constraints( global_info_file_ptr, p_global_constraints_bin, + hint_field_values, publics as *mut std::os::raw::c_void, challenges as *mut std::os::raw::c_void, proof_values as *mut std::os::raw::c_void, @@ -738,10 +778,52 @@ pub fn get_hint_field_global_constraints_c( hint_id, field_name.as_ptr() as *mut std::os::raw::c_char, print_expression, + ); + } +} + +#[cfg(not(feature = "no_lib_link"))] +pub fn get_hint_field_global_constraints_values_c( + p_global_constraints_bin: *mut c_void, + hint_id: u64, + hint_field_name: &str, +) -> u64 { + let field_name = CString::new(hint_field_name).unwrap(); + unsafe { + get_hint_field_global_constraints_values( + p_global_constraints_bin, + hint_id, + field_name.as_ptr() as *mut std::os::raw::c_char, ) } } +#[cfg(not(feature = "no_lib_link"))] +pub fn get_hint_field_global_constraints_sizes_c( + global_info_file: &str, + p_global_constraints_bin: *mut c_void, + hint_field_values: *mut c_void, + hint_id: u64, + hint_field_name: &str, + print_expression: bool, +) { + let field_name = CString::new(hint_field_name).unwrap(); + + let global_info_file_name = CString::new(global_info_file).unwrap(); + let global_info_file_ptr = global_info_file_name.as_ptr() as *mut std::os::raw::c_char; + + unsafe { + get_hint_field_global_constraints_sizes( + global_info_file_ptr, + p_global_constraints_bin, + hint_field_values, + hint_id, + field_name.as_ptr() as *mut std::os::raw::c_char, + print_expression, + ); + } +} + #[cfg(not(feature = "no_lib_link"))] pub fn set_hint_field_global_constraints_c( global_info_file: &str, @@ -1106,21 +1188,43 @@ pub fn expressions_bin_new_c(_filename: &str, _global: bool) -> *mut c_void { pub fn expressions_bin_free_c(_p_expressions_bin: *mut c_void) {} #[cfg(feature = "no_lib_link")] -pub fn get_hint_ids_by_name_c(_p_expressions_bin: *mut c_void, _hint_name: &str) -> *mut c_void { +pub fn n_hint_ids_by_name_c(_p_expressions_bin: *mut c_void, _hint_name: &str) -> u64 { + trace!("{}: ··· {}", "ffi ", "n_hint_ids_by_name: This is a mock call because there is no linked library"); + 0 +} + +#[cfg(feature = "no_lib_link")] +pub fn get_hint_ids_by_name_c(_p_expressions_bin: *mut c_void, _hint_ids: *mut u64, _hint_name: &str) { trace!("{}: ··· {}", "ffi ", "get_hint_ids_by_name: This is a mock call because there is no linked library"); - std::ptr::null_mut() } #[cfg(feature = "no_lib_link")] pub fn get_hint_field_c( _p_setup_ctx: *mut c_void, _p_steps_params: *mut u8, + _hint_field_values: *mut c_void, _hint_id: u64, _hint_field_name: &str, _hint_options: *mut u8, -) -> *mut c_void { +) { trace!("{}: ··· {}", "ffi ", "get_hint_field: This is a mock call because there is no linked library"); - std::ptr::null_mut() +} + +#[cfg(feature = "no_lib_link")] +pub fn get_hint_field_sizes_c( + _p_setup_ctx: *mut c_void, + _hint_field_values: *mut c_void, + _hint_id: u64, + _hint_field_name: &str, + _hint_options: *mut u8, +) { + trace!("{}: ··· {}", "ffi ", "get_hint_field_sizes: This is a mock call because there is no linked library"); +} + +#[cfg(feature = "no_lib_link")] +pub fn get_hint_field_values_c(_p_setup_ctx: *mut c_void, _hint_id: u64, _hint_field_name: &str) -> u64 { + trace!("{}: ··· {}", "ffi ", "get_hint_field: This is a mock call because there is no linked library"); + 0 } #[cfg(feature = "no_lib_link")] @@ -1148,9 +1252,8 @@ pub fn acc_hint_field_c( _hint_field_airgroupvalue: &str, _hint_field_name: &str, _add: bool, -) -> *mut c_void { +) { trace!("{}: ··· {}", "ffi ", "acc_hint_fields: This is a mock call because there is no linked library"); - std::ptr::null_mut() } #[cfg(feature = "no_lib_link")] @@ -1166,9 +1269,8 @@ pub fn acc_mul_hint_fields_c( _hint_options1: *mut u8, _hint_options2: *mut u8, _add: bool, -) -> *mut c_void { +) { trace!("{}: ··· {}", "ffi ", "acc_mul_hint_fields: This is a mock call because there is no linked library"); - std::ptr::null_mut() } #[cfg(feature = "no_lib_link")] @@ -1183,9 +1285,9 @@ pub fn update_airgroupvalue_c( _hint_options1: *mut u8, _hint_options2: *mut u8, _add: bool, -) -> *mut c_void { +) -> u64 { trace!("{}: ··· {}", "ffi ", "update_airgroupvalue: This is a mock call because there is no linked library"); - std::ptr::null_mut() + 10000 } #[cfg(feature = "no_lib_link")] @@ -1200,6 +1302,12 @@ pub fn set_hint_field_c( 0 } +#[cfg(feature = "no_lib_link")] +pub fn get_hint_field_id_c(_p_setup_ctx: *mut c_void, _hint_id: u64, _hint_field_name: &str) -> u64 { + trace!("{}: ··· {}", "ffi ", "get_hint_field_id: This is a mock call because there is no linked library"); + 0 +} + #[cfg(feature = "no_lib_link")] pub fn starks_new_c(_p_setup: *mut c_void, _p_const_tree: *mut u8) -> *mut c_void { trace!("{}: ··· {}", "ffi ", "starks_new: This is a mock call because there is no linked library"); @@ -1437,6 +1545,7 @@ pub fn verify_global_constraints_c( pub fn get_hint_field_global_constraints_c( _global_info_file: &str, _p_global_constraints_bin: *mut c_void, + _hint_field_values: *mut c_void, _publics: *mut u8, _challenges: *mut u8, _proof_values: *mut u8, @@ -1444,13 +1553,42 @@ pub fn get_hint_field_global_constraints_c( _hint_id: u64, _hint_field_name: &str, _print_expression: bool, -) -> *mut c_void { +) { trace!( "{}: ··· {}", "ffi ", "get_hint_field_global_constraints: This is a mock call because there is no linked library" ); - std::ptr::null_mut() +} + +#[cfg(feature = "no_lib_link")] +pub fn get_hint_field_global_constraints_values_c( + _p_global_constraints_bin: *mut c_void, + _hint_id: u64, + _hint_field_name: &str, +) -> u64 { + trace!( + "{}: ··· {}", + "ffi ", + "get_hint_field_global_constraints_values: This is a mock call because there is no linked library" + ); + 0 +} + +#[cfg(feature = "no_lib_link")] +pub fn get_hint_field_global_constraints_sizes_c( + _global_info_file: &str, + _p_global_constraints_bin: *mut c_void, + _hint_field_values: *mut c_void, + _hint_id: u64, + _hint_field_name: &str, + _print_expression: bool, +) { + trace!( + "{}: ··· {}", + "ffi ", + "get_hint_field_global_constraints_sizes: This is a mock call because there is no linked library" + ); } #[cfg(feature = "no_lib_link")] diff --git a/witness/src/witness_manager.rs b/witness/src/witness_manager.rs index fc13c345..a4ff3e3e 100644 --- a/witness/src/witness_manager.rs +++ b/witness/src/witness_manager.rs @@ -2,7 +2,7 @@ use std::sync::{Arc, RwLock}; use std::path::PathBuf; use proofman_common::{ProofCtx, SetupCtx}; -use proofman_util::{timer_start_debug, timer_stop_and_log_debug}; +use proofman_util::{timer_start_info, timer_stop_and_log_info}; use crate::WitnessComponent; pub struct WitnessManager { @@ -36,11 +36,11 @@ impl WitnessManager { } pub fn execute(&self) { - timer_start_debug!(EXECUTE); + timer_start_info!(EXECUTE); for component in self.components.read().unwrap().iter() { component.execute(self.pctx.clone()); } - timer_stop_and_log_debug!(EXECUTE); + timer_stop_and_log_info!(EXECUTE); } pub fn end_proof(&self) { @@ -57,14 +57,14 @@ impl WitnessManager { self.pctx.global_info.n_challenges.len() ); - timer_start_debug!(CALCULATING_WITNESS); + timer_start_info!(CALCULATING_WITNESS); // Call one time all unused components for component in self.components.read().unwrap().iter() { component.calculate_witness(stage, self.pctx.clone(), self.sctx.clone()); } - timer_stop_and_log_debug!(CALCULATING_WITNESS); + timer_stop_and_log_info!(CALCULATING_WITNESS); } pub fn get_pctx(&self) -> Arc> { From b90c886962addbe7ce9e8a5774887c2ed3aad504 Mon Sep 17 00:00:00 2001 From: Xavier Pinsach <10213118+xavi-pinsach@users.noreply.github.com> Date: Mon, 23 Dec 2024 09:01:59 +0000 Subject: [PATCH 55/64] add with_capacity function to Trace macro --- macros/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 853de4bd..c4f955ef 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -70,7 +70,10 @@ fn trace_impl(input: TokenStream2) -> Result { pub const AIR_ID: usize = #air_id; pub fn new() -> Self { - let num_rows = Self::NUM_ROWS; + #trace_struct_name::with_capacity(Self::NUM_ROWS) + } + + pub fn with_capacity(num_rows: usize) -> Self { assert!(num_rows >= 2); assert!(num_rows & (num_rows - 1) == 0); From d94c07f6f253b7dbe146d8d0422c90f65dee274c Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 23 Dec 2024 11:53:03 +0000 Subject: [PATCH 56/64] Removing unsafes from verify constraints --- common/src/constraints.rs | 89 +++++++++++++++ common/src/lib.rs | 2 + common/src/prover.rs | 46 +------- common/src/utils.rs | 15 +++ .../test/std/connection/rs/src/connection1.rs | 3 +- .../test/std/connection/rs/src/connection2.rs | 3 +- .../std/connection/rs/src/connection_new.rs | 3 +- .../std/range_check/rs/src/range_check4.rs | 2 +- pil2-stark/lib/include/starks_lib.h | 10 +- pil2-stark/src/api/starks_api.cpp | 58 ++++++++-- pil2-stark/src/api/starks_api.hpp | 10 +- pil2-stark/src/starkpil/fri/fri.cpp | 2 +- .../src/starkpil/global_constraints.hpp | 56 +++------ .../src/starkpil/verify_constraints.hpp | 27 +---- proofman/src/lib.rs | 4 +- proofman/src/proofman.rs | 24 ++-- .../{constraints.rs => verify_constraints.rs} | 40 ++++--- provers/stark/src/stark_prover.rs | 17 +-- provers/starks-lib-c/bindings_starks.rs | 38 +++++- provers/starks-lib-c/src/ffi_starks.rs | 108 ++++++++++++++++-- 20 files changed, 382 insertions(+), 175 deletions(-) create mode 100644 common/src/constraints.rs rename proofman/src/{constraints.rs => verify_constraints.rs} (85%) diff --git a/common/src/constraints.rs b/common/src/constraints.rs new file mode 100644 index 00000000..b5c63b3e --- /dev/null +++ b/common/src/constraints.rs @@ -0,0 +1,89 @@ +use std::sync::Arc; + +use proofman_starks_lib_c::{ + get_n_constraints_c, get_constraints_lines_sizes_c, get_constraints_lines_c, get_n_global_constraints_c, + get_global_constraints_lines_sizes_c, get_global_constraints_lines_c, +}; + +use crate::SetupCtx; + +#[derive(Default, Debug, Clone, Copy)] +#[repr(C)] +pub struct ConstraintRowInfo { + pub row: u64, + pub dim: u64, + pub value: [u64; 3usize], +} + + +#[derive(Default, Debug, Clone, Copy)] +#[repr(C)] +pub struct ConstraintInfo { +pub id: u64, + pub stage: u64, + pub im_pol: bool, + pub n_rows: u64, + pub rows: [ConstraintRowInfo; 10usize], +} + +#[derive(Default, Debug, Clone, Copy)] +#[repr(C)] +pub struct GlobalConstraintInfo { + pub id: u64, + pub dim: u64, + pub valid: bool, + pub value: [u64; 3usize], +} + +pub fn get_constraints_lines_str(sctx: Arc, airgroup_id: usize, air_id: usize) -> Vec { + let setup = sctx.get_setup(airgroup_id, air_id); + + let p_setup = (&setup.p_setup).into(); + let n_constraints = get_n_constraints_c(p_setup); + + let mut constraints_sizes = vec![0u64; n_constraints as usize]; + + get_constraints_lines_sizes_c(p_setup, constraints_sizes.as_mut_ptr()); + + let mut constraints_lines = vec![Vec::new(); n_constraints as usize]; + for i in 0..n_constraints as usize { + constraints_lines[i] = vec![0u8; constraints_sizes[i] as usize]; + } + + get_constraints_lines_c( + p_setup, + constraints_lines.iter_mut().map(|v| v.as_mut_ptr()).collect::>().as_mut_ptr(), + ); + + let mut constraints_lines_str = Vec::new(); + for constraint_line in constraints_lines { + constraints_lines_str.push(std::str::from_utf8(&constraint_line).unwrap().to_string()); + } + + constraints_lines_str +} + +pub fn get_global_constraints_lines_str(sctx: Arc) -> Vec { + let n_global_constraints = get_n_global_constraints_c(sctx.get_global_bin()); + + let mut global_constraints_sizes = vec![0u64; n_global_constraints as usize]; + + get_global_constraints_lines_sizes_c(sctx.get_global_bin(), global_constraints_sizes.as_mut_ptr()); + + let mut global_constraints_lines = vec![Vec::new(); n_global_constraints as usize]; + for i in 0..n_global_constraints as usize { + global_constraints_lines[i] = vec![0u8; global_constraints_sizes[i] as usize]; + } + + get_global_constraints_lines_c( + sctx.get_global_bin(), + global_constraints_lines.iter_mut().map(|v| v.as_mut_ptr()).collect::>().as_mut_ptr(), + ); + + let mut global_constraints_lines_str = Vec::new(); + for global_constraint_line in global_constraints_lines { + global_constraints_lines_str.push(std::str::from_utf8(&global_constraint_line).unwrap().to_string()); + } + + global_constraints_lines_str +} diff --git a/common/src/lib.rs b/common/src/lib.rs index 8413bcde..14d27fb5 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -14,6 +14,7 @@ pub mod global_info; pub mod stark_info; pub mod utils; pub mod custom_commits; +pub mod constraints; pub use air_instance::*; pub use air_instances_repository::*; @@ -30,3 +31,4 @@ pub use publics::*; pub use utils::*; pub use distribution_ctx::*; pub use custom_commits::*; +pub use constraints::*; diff --git a/common/src/prover.rs b/common/src/prover.rs index edd2d594..ea08f47d 100644 --- a/common/src/prover.rs +++ b/common/src/prover.rs @@ -4,6 +4,7 @@ use std::sync::Arc; use p3_field::Field; use transcript::FFITranscript; +use crate::ConstraintInfo; use crate::ProofCtx; use crate::SetupCtx; @@ -30,51 +31,6 @@ pub struct ProverInfo { pub instance_id: usize, } -#[derive(Debug, Clone, Copy)] -#[repr(C)] -pub struct ConstraintRowInfo { - pub row: u64, - pub dim: u64, - pub value: [u64; 3usize], -} - -#[derive(Debug, Clone, Copy)] -#[repr(C)] -pub struct ConstraintInfo { - pub id: u64, - pub stage: u64, - pub im_pol: bool, - pub line: *mut u8, - pub line_size: u64, - pub n_rows: u64, - pub rows: [ConstraintRowInfo; 10usize], -} - -#[derive(Debug, Clone, Copy)] -#[repr(C)] -pub struct ConstraintsResults { - pub n_constraints: u64, - pub constraints_info: *mut ConstraintInfo, -} - -#[derive(Debug, Clone, Copy)] -#[repr(C)] -pub struct GlobalConstraintInfo { - pub id: u64, - pub dim: u64, - pub valid: bool, - pub value: [u64; 3usize], - pub line: *mut u8, - pub line_size: u64, -} - -#[derive(Debug, Clone, Copy)] -#[repr(C)] -pub struct GlobalConstraintsResults { - pub n_constraints: u64, - pub constraints_info: *mut GlobalConstraintInfo, -} - pub trait Prover { fn build(&mut self, proof_ctx: Arc>); fn free(&mut self); diff --git a/common/src/utils.rs b/common/src/utils.rs index 956e38a2..d07fe950 100644 --- a/common/src/utils.rs +++ b/common/src/utils.rs @@ -20,3 +20,18 @@ pub fn initialize_logger(verbose_mode: VerboseMode) { .init(); set_log_level_c(verbose_mode.into()); } + +pub fn format_bytes(mut num_bytes: f64) -> String { + let units = ["Bytes", "KB", "MB", "GB"]; + let mut unit_index = 0; + + while num_bytes >= 0.01 && unit_index < units.len() - 1 { + if num_bytes < 1024.0 { + break; + } + num_bytes /= 1024.0; + unit_index += 1; + } + + format!("{:.2} {}", num_bytes, units[unit_index]) +} diff --git a/pil2-components/test/std/connection/rs/src/connection1.rs b/pil2-components/test/std/connection/rs/src/connection1.rs index a566a7b5..9749d33a 100644 --- a/pil2-components/test/std/connection/rs/src/connection1.rs +++ b/pil2-components/test/std/connection/rs/src/connection1.rs @@ -10,8 +10,7 @@ use crate::Connection1Trace; pub struct Connection1; -impl Connection1 -{ +impl Connection1 { const MY_NAME: &'static str = "Connct_1"; pub fn new() -> Arc { diff --git a/pil2-components/test/std/connection/rs/src/connection2.rs b/pil2-components/test/std/connection/rs/src/connection2.rs index bd3785e1..0cf0c005 100644 --- a/pil2-components/test/std/connection/rs/src/connection2.rs +++ b/pil2-components/test/std/connection/rs/src/connection2.rs @@ -10,8 +10,7 @@ use crate::Connection2Trace; pub struct Connection2; -impl Connection2 -{ +impl Connection2 { const MY_NAME: &'static str = "Connct_2"; pub fn new() -> Arc { diff --git a/pil2-components/test/std/connection/rs/src/connection_new.rs b/pil2-components/test/std/connection/rs/src/connection_new.rs index c9792fd4..b4c2fbf1 100644 --- a/pil2-components/test/std/connection/rs/src/connection_new.rs +++ b/pil2-components/test/std/connection/rs/src/connection_new.rs @@ -10,8 +10,7 @@ use crate::ConnectionNewTrace; pub struct ConnectionNew; -impl ConnectionNew -{ +impl ConnectionNew { const MY_NAME: &'static str = "Connct_N"; pub fn new() -> Arc { diff --git a/pil2-components/test/std/range_check/rs/src/range_check4.rs b/pil2-components/test/std/range_check/rs/src/range_check4.rs index fc29b242..0430c315 100644 --- a/pil2-components/test/std/range_check/rs/src/range_check4.rs +++ b/pil2-components/test/std/range_check/rs/src/range_check4.rs @@ -23,7 +23,7 @@ where const MY_NAME: &'static str = "RngChck4"; pub fn new(std_lib: Arc>) -> Arc { - Arc::new(Self { std_lib }) + Arc::new(Self { std_lib }) } } diff --git a/pil2-stark/lib/include/starks_lib.h b/pil2-stark/lib/include/starks_lib.h index 8fa2e3f4..0712cb4f 100644 --- a/pil2-stark/lib/include/starks_lib.h +++ b/pil2-stark/lib/include/starks_lib.h @@ -110,11 +110,17 @@ // Constraints // ================================================================================= - void *verify_constraints(void *pSetupCtx, void* stepsParams); + uint64_t get_n_constraints(void *pSetupCtx); + void get_constraints_lines_sizes(void* pSetupCtx, uint64_t *constraintsLinesSizes); + void get_constraints_lines(void* pSetupCtx, uint8_t **constraintsLines); + void verify_constraints(void *pSetupCtx, void* stepsParams, void* constraintsInfo); // Global constraints // ================================================================================= - void *verify_global_constraints(char* globalInfoFile, void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues); + uint64_t get_n_global_constraints(void* p_globalinfo_bin); + void get_global_constraints_lines_sizes(void* p_globalinfo_bin, uint64_t *constraintsLinesSizes); + void get_global_constraints_lines(void* p_globalinfo_bin, uint8_t **constraintsLines); + void verify_global_constraints(char* globalInfoFile, void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues, void* globalConstraintsInfo); uint64_t get_hint_field_global_constraints_values(void* p_globalinfo_bin, uint64_t hintId, char* hintFieldName); void get_hint_field_global_constraints_sizes(char* globalInfoFile, void* p_globalinfo_bin, void* hintFieldValues, uint64_t hintId, char *hintFieldName, bool print_expression); void get_hint_field_global_constraints(char* globalInfoFile, void* p_globalinfo_bin, void* hintFieldValues, void *publics, void *challenges, void *proofValues, void **airgroupValues, uint64_t hintId, char *hintFieldName, bool print_expression); diff --git a/pil2-stark/src/api/starks_api.cpp b/pil2-stark/src/api/starks_api.cpp index c2132d20..364f3a91 100644 --- a/pil2-stark/src/api/starks_api.cpp +++ b/pil2-stark/src/api/starks_api.cpp @@ -514,22 +514,66 @@ void get_permutations(void *pTranscript, uint64_t *res, uint64_t n, uint64_t nBi // Constraints // ================================================================================= -void *verify_constraints(void *pSetupCtx, void* stepsParams) +uint64_t get_n_constraints(void *pSetupCtx) { - ConstraintsResults *constraintsInfo = verifyConstraints(*(SetupCtx *)pSetupCtx, *(StepsParams *)stepsParams); - return constraintsInfo; + auto setupCtx = *(SetupCtx *)pSetupCtx; + return setupCtx.expressionsBin.constraintsInfoDebug.size(); +} + +void get_constraints_lines_sizes(void* pSetupCtx, uint64_t *constraintsLinesSizes) +{ + auto setupCtx = *(SetupCtx *)pSetupCtx; + for(uint64_t i = 0; i < setupCtx.expressionsBin.constraintsInfoDebug.size(); ++i) { + constraintsLinesSizes[i] = setupCtx.expressionsBin.constraintsInfoDebug[i].line.size(); + } +} + +void get_constraints_lines(void* pSetupCtx, uint8_t **constraintsLines) +{ + auto setupCtx = *(SetupCtx *)pSetupCtx; + for(uint64_t i = 0; i < setupCtx.expressionsBin.constraintsInfoDebug.size(); ++i) { + std::memcpy(constraintsLines[i], setupCtx.expressionsBin.constraintsInfoDebug[i].line.data(), setupCtx.expressionsBin.constraintsInfoDebug[i].line.size()); + } +} + +void verify_constraints(void *pSetupCtx, void* stepsParams, void* constraintsInfo) +{ + verifyConstraints(*(SetupCtx *)pSetupCtx, *(StepsParams *)stepsParams, (ConstraintInfo *)constraintsInfo); } // Global Constraints // ================================================================================= -void *verify_global_constraints(char* globalInfoFile, void* p_globalinfo_bin, void *publics, void *challenges, void *proofValues, void **airgroupValues) { +uint64_t get_n_global_constraints(void* p_globalinfo_bin) +{ + auto globalConstraintsBin = *(ExpressionsBin*)p_globalinfo_bin; + return globalConstraintsBin.constraintsInfoDebug.size(); +} + +void get_global_constraints_lines_sizes(void* p_globalinfo_bin, uint64_t *constraintsLinesSizes) +{ + auto globalConstraintsBin = *(ExpressionsBin*)p_globalinfo_bin; + cout << "HOLA " << endl; + for(uint64_t i = 0; i < globalConstraintsBin.constraintsInfoDebug.size(); ++i) { + cout << globalConstraintsBin.constraintsInfoDebug[i].line << endl; + constraintsLinesSizes[i] = globalConstraintsBin.constraintsInfoDebug[i].line.size(); + } +} + +void get_global_constraints_lines(void* p_globalinfo_bin, uint8_t **constraintsLines) +{ + auto globalConstraintsBin = *(ExpressionsBin*)p_globalinfo_bin; + for(uint64_t i = 0; i < globalConstraintsBin.constraintsInfoDebug.size(); ++i) { + std::memcpy(constraintsLines[i], globalConstraintsBin.constraintsInfoDebug[i].line.data(), globalConstraintsBin.constraintsInfoDebug[i].line.size()); + } +} + +void verify_global_constraints(char* globalInfoFile, void* p_globalinfo_bin, void *publics, void *challenges, void *proofValues, void **airgroupValues, void *globalConstraintsInfo) { json globalInfo; file2json(globalInfoFile, globalInfo); - GlobalConstraintsResults *constraintsInfo = verifyGlobalConstraints(globalInfo, *(ExpressionsBin*)p_globalinfo_bin, (Goldilocks::Element *)publics, (Goldilocks::Element *)challenges, (Goldilocks::Element *)proofValues, (Goldilocks::Element **)airgroupValues); - return constraintsInfo; + verifyGlobalConstraints(globalInfo, *(ExpressionsBin*)p_globalinfo_bin, (Goldilocks::Element *)publics, (Goldilocks::Element *)challenges, (Goldilocks::Element *)proofValues, (Goldilocks::Element **)airgroupValues, (GlobalConstraintInfo *)globalConstraintsInfo); } - + uint64_t get_hint_field_global_constraints_values(void* p_globalinfo_bin, uint64_t hintId, char* hintFieldName) { return getHintFieldGlobalConstraintValues(*(ExpressionsBin*)p_globalinfo_bin, hintId, string(hintFieldName)); } diff --git a/pil2-stark/src/api/starks_api.hpp b/pil2-stark/src/api/starks_api.hpp index 8fa2e3f4..0712cb4f 100644 --- a/pil2-stark/src/api/starks_api.hpp +++ b/pil2-stark/src/api/starks_api.hpp @@ -110,11 +110,17 @@ // Constraints // ================================================================================= - void *verify_constraints(void *pSetupCtx, void* stepsParams); + uint64_t get_n_constraints(void *pSetupCtx); + void get_constraints_lines_sizes(void* pSetupCtx, uint64_t *constraintsLinesSizes); + void get_constraints_lines(void* pSetupCtx, uint8_t **constraintsLines); + void verify_constraints(void *pSetupCtx, void* stepsParams, void* constraintsInfo); // Global constraints // ================================================================================= - void *verify_global_constraints(char* globalInfoFile, void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues); + uint64_t get_n_global_constraints(void* p_globalinfo_bin); + void get_global_constraints_lines_sizes(void* p_globalinfo_bin, uint64_t *constraintsLinesSizes); + void get_global_constraints_lines(void* p_globalinfo_bin, uint8_t **constraintsLines); + void verify_global_constraints(char* globalInfoFile, void *globalBin, void *publics, void* challenges, void *proofValues, void **airgroupValues, void* globalConstraintsInfo); uint64_t get_hint_field_global_constraints_values(void* p_globalinfo_bin, uint64_t hintId, char* hintFieldName); void get_hint_field_global_constraints_sizes(char* globalInfoFile, void* p_globalinfo_bin, void* hintFieldValues, uint64_t hintId, char *hintFieldName, bool print_expression); void get_hint_field_global_constraints(char* globalInfoFile, void* p_globalinfo_bin, void* hintFieldValues, void *publics, void *challenges, void *proofValues, void **airgroupValues, uint64_t hintId, char *hintFieldName, bool print_expression); diff --git a/pil2-stark/src/starkpil/fri/fri.cpp b/pil2-stark/src/starkpil/fri/fri.cpp index dd41da77..a7c0543c 100644 --- a/pil2-stark/src/starkpil/fri/fri.cpp +++ b/pil2-stark/src/starkpil/fri/fri.cpp @@ -86,7 +86,7 @@ void FRI::merkelize(uint64_t step, FRIProof &proof, Go treeFRI->merkelize(); treeFRI->getRoot(&proof.proof.fri.treesFRI[step].root[0]); - delete aux; + delete[] aux; } template diff --git a/pil2-stark/src/starkpil/global_constraints.hpp b/pil2-stark/src/starkpil/global_constraints.hpp index 98beb4f1..b399c35f 100644 --- a/pil2-stark/src/starkpil/global_constraints.hpp +++ b/pil2-stark/src/starkpil/global_constraints.hpp @@ -10,13 +10,6 @@ struct GlobalConstraintInfo { uint64_t dim; bool valid; uint64_t value[3]; - uint8_t* line; - uint64_t line_size; -}; - -struct GlobalConstraintsResults { - uint64_t nConstraints; - GlobalConstraintInfo* constraintInfo; }; void calculateGlobalExpression(json& globalInfo, Goldilocks::Element* dest, Goldilocks::Element* publics, Goldilocks::Element* challenges, Goldilocks::Element* proofValues_, Goldilocks::Element** airgroupValues, ParserArgs &parserArgs, ParserParams &parserParams) { @@ -282,53 +275,38 @@ void calculateGlobalExpression(json& globalInfo, Goldilocks::Element* dest, Gold } -GlobalConstraintInfo verifyGlobalConstraint(json& globalInfo, uint64_t constraintId, Goldilocks::Element* publics, Goldilocks::Element* challenges, Goldilocks::Element* proofValues, Goldilocks::Element** airgroupValues, ParserArgs &parserArgs, ParserParams &parserParams) { +void verifyGlobalConstraint(json& globalInfo, uint64_t constraintId, Goldilocks::Element* publics, Goldilocks::Element* challenges, Goldilocks::Element* proofValues, Goldilocks::Element** airgroupValues, ParserArgs &parserArgs, ParserParams &parserParams, GlobalConstraintInfo& globalConstraintInfo) { - GlobalConstraintInfo constraintInfo; - constraintInfo.id = constraintId; - constraintInfo.valid = true; - constraintInfo.line = new uint8_t[parserParams.line.size()]; - constraintInfo.line_size = parserParams.line.size(); - std::memcpy(constraintInfo.line, parserParams.line.data(), parserParams.line.size()); + globalConstraintInfo.id = constraintId; + globalConstraintInfo.valid = true; Goldilocks::Element dest[parserParams.destDim]; calculateGlobalExpression(globalInfo, dest, publics, challenges, proofValues, airgroupValues, parserArgs, parserParams); if(parserParams.destDim == 1) { - constraintInfo.dim = parserParams.destDim; - constraintInfo.value[0] = Goldilocks::toU64(dest[0]); - constraintInfo.value[1] = 0; - constraintInfo.value[2] = 0; - if(constraintInfo.value[0] != 0) constraintInfo.valid = false; + globalConstraintInfo.dim = parserParams.destDim; + globalConstraintInfo.value[0] = Goldilocks::toU64(dest[0]); + globalConstraintInfo.value[1] = 0; + globalConstraintInfo.value[2] = 0; + if(globalConstraintInfo.value[0] != 0) globalConstraintInfo.valid = false; } else { - constraintInfo.dim = parserParams.destDim; - constraintInfo.value[0] = Goldilocks::toU64(dest[0]); - constraintInfo.value[1] = Goldilocks::toU64(dest[1]); - constraintInfo.value[2] = Goldilocks::toU64(dest[2]); - if(constraintInfo.value[0] != 0 || constraintInfo.value[1] != 0 || constraintInfo.value[2] != 0) constraintInfo.valid = false; + globalConstraintInfo.dim = parserParams.destDim; + globalConstraintInfo.value[0] = Goldilocks::toU64(dest[0]); + globalConstraintInfo.value[1] = Goldilocks::toU64(dest[1]); + globalConstraintInfo.value[2] = Goldilocks::toU64(dest[2]); + if(globalConstraintInfo.value[0] != 0 || globalConstraintInfo.value[1] != 0 || globalConstraintInfo.value[2] != 0) globalConstraintInfo.valid = false; } - - return constraintInfo; } -GlobalConstraintsResults * verifyGlobalConstraints(json& globalInfo, ExpressionsBin &globalConstraintsBin, Goldilocks::Element* publicInputs, Goldilocks::Element* challenges, Goldilocks::Element* proofValues, Goldilocks::Element** airgroupValues) +void verifyGlobalConstraints(json& globalInfo, ExpressionsBin &globalConstraintsBin, Goldilocks::Element* publicInputs, Goldilocks::Element* challenges, Goldilocks::Element* proofValues, Goldilocks::Element** airgroupValues, GlobalConstraintInfo *globalConstraintsInfo) { + std::vector globalConstraints = globalConstraintsBin.constraintsInfoDebug; - - std::vector globalConstraintsInfo = globalConstraintsBin.constraintsInfoDebug; - - GlobalConstraintsResults *constraintsInfo = new GlobalConstraintsResults(); - constraintsInfo->nConstraints = globalConstraintsInfo.size(); - constraintsInfo->constraintInfo = new GlobalConstraintInfo[constraintsInfo->nConstraints]; - - for(uint64_t i = 0; i < globalConstraintsInfo.size(); ++i) { - auto constraintInfo = verifyGlobalConstraint(globalInfo, i, publicInputs, challenges, proofValues, airgroupValues, globalConstraintsBin.expressionsBinArgsConstraints, globalConstraintsInfo[i]); - constraintsInfo->constraintInfo[i] = constraintInfo; + for(uint64_t i = 0; i < globalConstraints.size(); ++i) { + verifyGlobalConstraint(globalInfo, i, publicInputs, challenges, proofValues, airgroupValues, globalConstraintsBin.expressionsBinArgsConstraints, globalConstraints[i], globalConstraintsInfo[i]); } - - return constraintsInfo; } std::string getExpressionDebug(json& globalInfo, ExpressionsBin &globalConstraintsBin, uint64_t hintId, std::string hintFieldName, HintFieldValue hintFieldVal) { diff --git a/pil2-stark/src/starkpil/verify_constraints.hpp b/pil2-stark/src/starkpil/verify_constraints.hpp index efa631c1..ea3677ab 100644 --- a/pil2-stark/src/starkpil/verify_constraints.hpp +++ b/pil2-stark/src/starkpil/verify_constraints.hpp @@ -10,17 +10,10 @@ struct ConstraintInfo { uint64_t id; uint64_t stage; bool imPol; - uint8_t* line; - uint64_t line_size; uint64_t nrows; ConstraintRowInfo rows[10]; }; -struct ConstraintsResults { - uint64_t nConstraints; - ConstraintInfo* constraintInfo; -}; - std::tuple checkConstraint(Goldilocks::Element* dest, ParserParams& parserParams, uint64_t row) { bool isValid = true; ConstraintRowInfo rowInfo; @@ -52,14 +45,10 @@ std::tuple checkConstraint(Goldilocks::Element* dest, P } -ConstraintInfo verifyConstraint(SetupCtx& setupCtx, Goldilocks::Element* dest, uint64_t constraintId) { - ConstraintInfo constraintInfo; +void verifyConstraint(SetupCtx& setupCtx, Goldilocks::Element* dest, uint64_t constraintId, ConstraintInfo& constraintInfo) { constraintInfo.id = constraintId; constraintInfo.stage = setupCtx.expressionsBin.constraintsInfoDebug[constraintId].stage; constraintInfo.imPol = setupCtx.expressionsBin.constraintsInfoDebug[constraintId].imPol; - constraintInfo.line = new uint8_t[setupCtx.expressionsBin.constraintsInfoDebug[constraintId].line.size()]; - constraintInfo.line_size = setupCtx.expressionsBin.constraintsInfoDebug[constraintId].line.size(); - std::memcpy(constraintInfo.line, setupCtx.expressionsBin.constraintsInfoDebug[constraintId].line.data(), setupCtx.expressionsBin.constraintsInfoDebug[constraintId].line.size()); constraintInfo.nrows = 0; uint64_t N = (1 << setupCtx.starkInfo.starkStruct.nBits); @@ -86,16 +75,10 @@ ConstraintInfo verifyConstraint(SetupCtx& setupCtx, Goldilocks::Element* dest, u constraintInfo.rows[i] = constraintInvalidRows[i]; } } - - return constraintInfo; } -ConstraintsResults *verifyConstraints(SetupCtx& setupCtx, StepsParams ¶ms) { +void verifyConstraints(SetupCtx& setupCtx, StepsParams ¶ms, ConstraintInfo *constraintsInfo) { - ConstraintsResults *constraintsInfo = new ConstraintsResults(); - constraintsInfo->nConstraints = setupCtx.expressionsBin.constraintsInfoDebug.size(); - constraintsInfo->constraintInfo = new ConstraintInfo[constraintsInfo->nConstraints]; - uint64_t N = (1 << setupCtx.starkInfo.starkStruct.nBits); uint64_t nPols = 0; @@ -125,10 +108,8 @@ ConstraintsResults *verifyConstraints(SetupCtx& setupCtx, StepsParams ¶ms) { #pragma omp parallel for for (uint64_t i = 0; i < setupCtx.expressionsBin.constraintsInfoDebug.size(); i++) { - auto constraintInfo = verifyConstraint(setupCtx, dests[i].dest, i); - constraintsInfo->constraintInfo[i] = constraintInfo; + verifyConstraint(setupCtx, dests[i].dest, i, constraintsInfo[i]); } - delete pBuffer; - return constraintsInfo; + delete[] pBuffer; } diff --git a/proofman/src/lib.rs b/proofman/src/lib.rs index bed412ee..8e6a82fb 100644 --- a/proofman/src/lib.rs +++ b/proofman/src/lib.rs @@ -1,7 +1,7 @@ mod proofman; -mod constraints; +mod verify_constraints; mod recursion; pub use proofman::*; -pub use constraints::*; +pub use verify_constraints::*; pub use recursion::*; diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index be98b6ae..09623762 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -19,7 +19,7 @@ use crate::{ generate_vadcop_recursive2_proof, generate_recursivef_proof, generate_fflonk_snark_proof, }; -use proofman_common::{ProofCtx, ProofOptions, ProofType, Prover, SetupCtx, SetupsVadcop}; +use proofman_common::{format_bytes, ProofCtx, ProofOptions, ProofType, Prover, SetupCtx, SetupsVadcop}; use std::os::raw::c_void; @@ -661,14 +661,12 @@ impl ProofMan { if !air_instance_map.contains_key(&air_name.clone()) { let setup = sctx.get_setup(air_instance.airgroup_id, air_instance.air_id); let n_bits = setup.stark_info.stark_struct.n_bits; - let memory_instance = - get_map_totaln_c(setup.p_setup.p_stark_info) as f64 * 8.0 / (1024.0 * 1024.0 * 1024.0); + let memory_instance = get_map_totaln_c(setup.p_setup.p_stark_info) as f64 * 8.0; let memory_fixed = (setup.stark_info.n_constants * (1 << (setup.stark_info.stark_struct.n_bits)) + setup.stark_info.n_constants * (1 << (setup.stark_info.stark_struct.n_bits_ext))) as f64 - * 8.0 - / (1024.0 * 1024.0 * 1024.0); - let memory_helpers = setup.stark_info.get_buff_helper_size() as f64; + * 8.0; + let memory_helpers = setup.stark_info.get_buff_helper_size() as f64 * 8.0; let total_cols: u64 = setup .stark_info .map_sections_n @@ -726,24 +724,28 @@ impl ProofMan { "{}: {}", Self::MY_NAME, format!( - "· {}: {:.2} GB fixed cols | {:.2} GB per each of {} instance | Total {:.2} GB", - air_name, memory_fixed, memory_instance, count, total_memory_instance + "· {}: {} fixed cols | {} per each of {} instance | Total {}", + air_name, + format_bytes(*memory_fixed), + format_bytes(*memory_instance), + count, + format_bytes(total_memory_instance) ) .bright_white() .bold() ); } } - memory_helper_size = memory_helper_size * 8.0 / (1024.0 * 1024.0 * 1024.0); + total_memory += memory_helper_size; info!( "{}: {}", Self::MY_NAME, - format!("Extra helper memory: {:.2} GB", memory_helper_size).bright_white().bold() + format!("Extra helper memory: {}", format_bytes(memory_helper_size)).bright_white().bold() ); info!( "{}: {}", Self::MY_NAME, - format!("Total prover memory required: {:.2} GB", total_memory).bright_white().bold() + format!("Total prover memory required: {}", format_bytes(total_memory)).bright_white().bold() ); info!("{}: --- PROVER MEMORY USAGE ------------------------", Self::MY_NAME); } diff --git a/proofman/src/constraints.rs b/proofman/src/verify_constraints.rs similarity index 85% rename from proofman/src/constraints.rs rename to proofman/src/verify_constraints.rs index 402b93a4..856b145c 100644 --- a/proofman/src/constraints.rs +++ b/proofman/src/verify_constraints.rs @@ -1,11 +1,15 @@ use p3_field::Field; use proofman_hints::aggregate_airgroupvals; -use proofman_starks_lib_c::verify_global_constraints_c; +use proofman_starks_lib_c::{get_n_global_constraints_c, verify_global_constraints_c}; use std::cmp; use std::sync::Arc; -use proofman_common::{GlobalConstraintInfo, GlobalConstraintsResults, ProofCtx, Prover, SetupCtx}; +use proofman_common::{ + get_constraints_lines_str, get_global_constraints_lines_str, GlobalConstraintInfo, ProofCtx, Prover, + SetupCtx, +}; +use std::os::raw::c_void; use colored::*; @@ -24,20 +28,20 @@ pub fn verify_global_constraints_proof( .map(|inner_vec| inner_vec.as_mut_ptr()) // Get a raw pointer to each inner Vec .collect(); - let raw_ptr = verify_global_constraints_c( + let n_global_constraints = get_n_global_constraints_c(sctx.get_global_bin()); + let mut global_constraints_info = vec![GlobalConstraintInfo::default(); n_global_constraints as usize]; + + verify_global_constraints_c( sctx.get_global_info_file().as_str(), sctx.get_global_bin(), pctx.get_publics_ptr(), pctx.get_challenges_ptr(), pctx.get_proof_values_ptr(), airgroup_values_ptrs.as_mut_ptr() as *mut *mut u8, + global_constraints_info.as_mut_ptr() as *mut c_void, ); - unsafe { - let constraints_result = Box::from_raw(raw_ptr as *mut GlobalConstraintsResults); - std::slice::from_raw_parts(constraints_result.constraints_info, constraints_result.n_constraints as usize) - } - .to_vec() + global_constraints_info } pub fn verify_constraints_proof( @@ -58,6 +62,9 @@ pub fn verify_constraints_proof( let mut valid_constraints = true; for (air_instance_index, air_instance) in pctx.air_instance_repo.air_instances.read().unwrap().iter().enumerate() { let air_name = &pctx.global_info.airs[air_instance.airgroup_id][air_instance.air_id].name; + + let constraints_lines = get_constraints_lines_str(sctx.clone(), air_instance.airgroup_id, air_instance.air_id); + let mut valid_constraints_prover = true; log::info!( "{}: ► Instance #{}: Air [{}:{}] {}", @@ -68,8 +75,6 @@ pub fn verify_constraints_proof( air_name, ); for constraint in &constraints[air_instance_index] { - let str_slice = unsafe { std::slice::from_raw_parts(constraint.line, constraint.line_size as usize) }; - let line_str = std::str::from_utf8(str_slice).unwrap(); let valid = if constraint.n_rows > 0 { format!("has {} invalid rows", constraint.n_rows).bright_red() } else { @@ -81,7 +86,7 @@ pub fn verify_constraints_proof( MY_NAME, constraint.stage, valid, - line_str + constraints_lines[constraint.id as usize] ); } else if constraint.n_rows == 0 { log::debug!( @@ -90,7 +95,7 @@ pub fn verify_constraints_proof( constraint.id, constraint.stage, valid, - line_str + constraints_lines[constraint.id as usize] ); } else { log::info!( @@ -99,7 +104,7 @@ pub fn verify_constraints_proof( constraint.id, constraint.stage, valid, - line_str + constraints_lines[constraint.id as usize] ); } if constraint.n_rows > 0 { @@ -153,9 +158,12 @@ pub fn verify_constraints_proof( let global_constraints = verify_global_constraints_proof(pctx.clone(), sctx.clone()); let mut valid_global_constraints = true; - for constraint in &global_constraints { - let str_slice = unsafe { std::slice::from_raw_parts(constraint.line, constraint.line_size as usize) }; - let line_str = std::str::from_utf8(str_slice).unwrap(); + + let global_constraints_lines = get_global_constraints_lines_str(sctx.clone()); + + for idx in 0..global_constraints.len() { + let constraint = global_constraints[idx]; + let line_str = &global_constraints_lines[idx]; let valid = if !constraint.valid { "is invalid".bright_red() } else { "is valid".bright_green() }; if constraint.valid { diff --git a/provers/stark/src/stark_prover.rs b/provers/stark/src/stark_prover.rs index efc4f782..409c875e 100644 --- a/provers/stark/src/stark_prover.rs +++ b/provers/stark/src/stark_prover.rs @@ -6,8 +6,7 @@ use std::any::type_name; use std::sync::Arc; use proofman_common::{ - ConstraintInfo, ConstraintsResults, ProofCtx, ProofType, Prover, ProverInfo, ProverStatus, StepsParams, SetupCtx, - StarkInfo, + ConstraintInfo, ProofCtx, ProofType, Prover, ProverInfo, ProverStatus, StepsParams, SetupCtx, StarkInfo, }; use log::{debug, trace}; use transcript::FFITranscript; @@ -150,13 +149,15 @@ impl Prover for StarkProver { custom_commits_extended: [std::ptr::null_mut(); 10], }; - let raw_ptr = verify_constraints_c((&setup.p_setup).into(), (&steps_params).into()); + let p_setup = (&setup.p_setup).into(); - unsafe { - let constraints_result = Box::from_raw(raw_ptr as *mut ConstraintsResults); - std::slice::from_raw_parts(constraints_result.constraints_info, constraints_result.n_constraints as usize) - } - .to_vec() + let n_constraints = get_n_constraints_c(p_setup); + + let mut constraints_info = vec![ConstraintInfo::default(); n_constraints as usize]; + + verify_constraints_c(p_setup, (&steps_params).into(), constraints_info.as_mut_ptr() as *mut c_void); + + constraints_info } fn calculate_stage(&mut self, stage_id: u32, setup_ctx: Arc, proof_ctx: Arc>) { diff --git a/provers/starks-lib-c/bindings_starks.rs b/provers/starks-lib-c/bindings_starks.rs index 82394942..0e09ccae 100644 --- a/provers/starks-lib-c/bindings_starks.rs +++ b/provers/starks-lib-c/bindings_starks.rs @@ -444,14 +444,43 @@ extern "C" { pub fn get_permutations(pTranscript: *mut ::std::os::raw::c_void, res: *mut u64, n: u64, nBits: u64); } extern "C" { - #[link_name = "\u{1}_Z18verify_constraintsPvS_"] + #[link_name = "\u{1}_Z17get_n_constraintsPv"] + pub fn get_n_constraints(pSetupCtx: *mut ::std::os::raw::c_void) -> u64; +} +extern "C" { + #[link_name = "\u{1}_Z27get_constraints_lines_sizesPvPm"] + pub fn get_constraints_lines_sizes(pSetupCtx: *mut ::std::os::raw::c_void, constraintsLinesSizes: *mut u64); +} +extern "C" { + #[link_name = "\u{1}_Z21get_constraints_linesPvPPh"] + pub fn get_constraints_lines(pSetupCtx: *mut ::std::os::raw::c_void, constraintsLines: *mut *mut u8); +} +extern "C" { + #[link_name = "\u{1}_Z18verify_constraintsPvS_S_"] pub fn verify_constraints( pSetupCtx: *mut ::std::os::raw::c_void, stepsParams: *mut ::std::os::raw::c_void, - ) -> *mut ::std::os::raw::c_void; + constraintsInfo: *mut ::std::os::raw::c_void, + ); +} +extern "C" { + #[link_name = "\u{1}_Z24get_n_global_constraintsPv"] + pub fn get_n_global_constraints(p_globalinfo_bin: *mut ::std::os::raw::c_void) -> u64; +} + +extern "C" { + #[link_name = "\u{1}_Z34get_global_constraints_lines_sizesPvPm"] + pub fn get_global_constraints_lines_sizes( + p_globalinfo_bin: *mut ::std::os::raw::c_void, + constraintsLinesSizes: *mut u64, + ); } extern "C" { - #[link_name = "\u{1}_Z25verify_global_constraintsPcPvS0_S0_S0_PS0_"] + #[link_name = "\u{1}_Z28get_global_constraints_linesPvPPh"] + pub fn get_global_constraints_lines(p_globalinfo_bin: *mut ::std::os::raw::c_void, constraintsLines: *mut *mut u8); +} +extern "C" { + #[link_name = "\u{1}_Z25verify_global_constraintsPcPvS0_S0_S0_PS0_S0_"] pub fn verify_global_constraints( globalInfoFile: *mut ::std::os::raw::c_char, globalBin: *mut ::std::os::raw::c_void, @@ -459,7 +488,8 @@ extern "C" { challenges: *mut ::std::os::raw::c_void, proofValues: *mut ::std::os::raw::c_void, airgroupValues: *mut *mut ::std::os::raw::c_void, - ) -> *mut ::std::os::raw::c_void; + globalConstraintsInfo: *mut ::std::os::raw::c_void, + ); } extern "C" { #[link_name = "\u{1}_Z40get_hint_field_global_constraints_valuesPvmPc"] diff --git a/provers/starks-lib-c/src/ffi_starks.rs b/provers/starks-lib-c/src/ffi_starks.rs index 6e9bb34d..4c604cf6 100644 --- a/provers/starks-lib-c/src/ffi_starks.rs +++ b/provers/starks-lib-c/src/ffi_starks.rs @@ -719,8 +719,48 @@ pub fn get_permutations_c(p_transcript: *mut c_void, res: *mut u64, n: u64, n_bi } #[cfg(not(feature = "no_lib_link"))] -pub fn verify_constraints_c(p_setup: *mut c_void, p_steps_params: *mut u8) -> *mut c_void { - unsafe { verify_constraints(p_setup, p_steps_params as *mut std::os::raw::c_void) } +pub fn get_n_constraints_c(p_setup: *mut c_void) -> u64 { + unsafe { get_n_constraints(p_setup) } +} + +#[cfg(not(feature = "no_lib_link"))] +pub fn get_constraints_lines_sizes_c(p_setup: *mut c_void, constraints_sizes: *mut u64) { + unsafe { + get_constraints_lines_sizes(p_setup, constraints_sizes); + } +} + +#[cfg(not(feature = "no_lib_link"))] +pub fn get_constraints_lines_c(p_setup: *mut c_void, constraints_lines: *mut *mut u8) { + unsafe { + get_constraints_lines(p_setup, constraints_lines); + } +} + +#[cfg(not(feature = "no_lib_link"))] +pub fn verify_constraints_c(p_setup: *mut c_void, p_steps_params: *mut u8, constraints_info: *mut c_void) { + unsafe { + verify_constraints(p_setup, p_steps_params as *mut std::os::raw::c_void, constraints_info); + } +} + +#[cfg(not(feature = "no_lib_link"))] +pub fn get_n_global_constraints_c(p_global_constraints_bin: *mut c_void) -> u64 { + unsafe { get_n_global_constraints(p_global_constraints_bin) } +} + +#[cfg(not(feature = "no_lib_link"))] +pub fn get_global_constraints_lines_sizes_c(p_global_constraints_bin: *mut c_void, global_constraints_sizes: *mut u64) { + unsafe { + get_global_constraints_lines_sizes(p_global_constraints_bin, global_constraints_sizes); + } +} + +#[cfg(not(feature = "no_lib_link"))] +pub fn get_global_constraints_lines_c(p_global_constraints_bin: *mut c_void, global_constraints_lines: *mut *mut u8) { + unsafe { + get_global_constraints_lines(p_global_constraints_bin, global_constraints_lines); + } } #[cfg(not(feature = "no_lib_link"))] @@ -731,7 +771,8 @@ pub fn verify_global_constraints_c( challenges: *mut u8, proof_values: *mut u8, airgroupvalues: *mut *mut u8, -) -> *mut c_void { + global_constraints_info: *mut c_void, +) { let global_info_file_name = CString::new(global_info_file).unwrap(); let global_info_file_ptr = global_info_file_name.as_ptr() as *mut std::os::raw::c_char; @@ -743,7 +784,8 @@ pub fn verify_global_constraints_c( challenges as *mut std::os::raw::c_void, proof_values as *mut std::os::raw::c_void, airgroupvalues as *mut *mut std::os::raw::c_void, - ) + global_constraints_info, + ); } } @@ -1518,9 +1560,59 @@ pub fn get_permutations_c(_p_transcript: *mut c_void, _res: *mut u64, _n: u64, _ } #[cfg(feature = "no_lib_link")] -pub fn verify_constraints_c(_p_setup: *mut c_void, _p_steps_params: *mut u8) -> *mut c_void { +pub fn get_n_constraints_c(_p_setup: *mut c_void) -> u64 { + trace!("{}: ··· {}", "ffi ", "get_n_constraints: This is a mock call because there is no linked library"); + 0 +} + +#[cfg(feature = "no_lib_link")] +pub fn get_constraints_lines_sizes_c(_p_setup: *mut c_void, _constraints_sizes: *mut u64) { + trace!( + "{}: ··· {}", + "ffi ", + "get_constraints_lines_sizes: This is a mock call because there is no linked library" + ); +} + +#[cfg(feature = "no_lib_link")] +pub fn get_constraints_lines_c(_p_setup: *mut c_void, _constraints_lines: *mut *mut u8) { + trace!("{}: ··· {}", "ffi ", "get_constraints_lines: This is a mock call because there is no linked library"); +} + +#[cfg(feature = "no_lib_link")] +pub fn verify_constraints_c(_p_setup: *mut c_void, _p_steps_params: *mut u8, _constraints_info: *mut c_void) { trace!("{}: ··· {}", "ffi ", "verify_constraints: This is a mock call because there is no linked library"); - std::ptr::null_mut() +} + +#[cfg(feature = "no_lib_link")] +pub fn get_n_global_constraints_c(_p_global_constraints_bin: *mut c_void) -> u64 { + trace!( + "{}: ··· {}", + "ffi ", + "get_n_global_constraints: This is a mock call because there is no linked library" + ); + 0 +} + +#[cfg(feature = "no_lib_link")] +pub fn get_global_constraints_lines_sizes_c( + _p_global_constraints_bin: *mut c_void, + _global_constraints_sizes: *mut u64, +) { + trace!( + "{}: ··· {}", + "ffi ", + "get_global_constraints_lines_sizes: This is a mock call because there is no linked library" + ); +} + +#[cfg(feature = "no_lib_link")] +pub fn get_global_constraints_lines_c(_p_global_constraints_bin: *mut c_void, _global_constraints_lines: *mut *mut u8) { + trace!( + "{}: ··· {}", + "ffi ", + "get_global_constraints_lines: This is a mock call because there is no linked library" + ); } #[cfg(feature = "no_lib_link")] @@ -1531,13 +1623,13 @@ pub fn verify_global_constraints_c( _challenges: *mut u8, _proof_values: *mut u8, _airgroupvalues: *mut *mut u8, -) -> *mut c_void { + _global_constraints_info: *mut c_void, +) { trace!( "{}: ··· {}", "ffi ", "verify_global_constraints: This is a mock call because there is no linked library" ); - std::ptr::null_mut() } #[cfg(feature = "no_lib_link")] From b41483e8dc60db5a19f865765640abdff982b0b6 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 23 Dec 2024 12:48:56 +0000 Subject: [PATCH 57/64] Activating back distributed mode and adding test to CI --- .github/workflows/ci.yaml | 12 +++ common/src/constraints.rs | 3 +- proofman/src/proofman.rs | 122 ++++++++++------------------- proofman/src/recursion.rs | 95 ++++++++++------------ proofman/src/verify_constraints.rs | 3 +- 5 files changed, 97 insertions(+), 138 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5694325d..6eb4a8e5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -224,6 +224,18 @@ jobs: - name: Verify proof Fibonacci Square run: | node pil2-proofman-js/src/main_verify -k examples/fibonacci-square/build/provingKey -p examples/fibonacci-square/build/proofs -t vadcop_final + + - name: Clean proof dir + run: | + rm -rf examples/fibonacci-square/build/proofs + + - name: Generate proof Fibonacci Square distributed + run: | + mpirun --bind-to none -np 3 -x OMP_NUM_THREADS=32 target/release/proofman-cli prove --witness-lib ./target/debug/libfibonacci_square.so --public-inputs examples/fibonacci-square/src/inputs.json --proving-key examples/fibonacci-square/build/provingKey/ --output-dir examples/fibonacci-square/build/proofs -a + + - name: Verify proof Fibonacci Square distributed + run: | + node pil2-proofman-js/src/main_verify -k examples/fibonacci-square/build/provingKey -p examples/fibonacci-square/build/proofs -t vadcop_final test-std: name: Test STD runs-on: ubuntu-latest diff --git a/common/src/constraints.rs b/common/src/constraints.rs index b5c63b3e..cd6abccf 100644 --- a/common/src/constraints.rs +++ b/common/src/constraints.rs @@ -15,11 +15,10 @@ pub struct ConstraintRowInfo { pub value: [u64; 3usize], } - #[derive(Default, Debug, Clone, Copy)] #[repr(C)] pub struct ConstraintInfo { -pub id: u64, + pub id: u64, pub stage: u64, pub im_pol: bool, pub n_rows: u64, diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index 09623762..27b9909e 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -451,66 +451,44 @@ impl ProofMan { transcript.add_elements(proof_values_stage.as_ptr() as *mut u8, proof_values_stage.len()); } - // TODO: ACTIVATE DCTX BACK - // let dctx = pctx.dctx.read().unwrap(); - - // // calculate my roots - // let mut roots: Vec = vec![0; 4 * provers.len()]; - // for (i, prover) in provers.iter_mut().enumerate() { - // // Important we need the roots in u64 in order to distribute them - // let values = prover.get_transcript_values_u64(stage as u64, pctx.clone()); - // if values.is_empty() { - // panic!("No transcript values found for prover {}", i); - // } - // roots[i * 4..(i + 1) * 4].copy_from_slice(&values) - // } - // // get all roots - // let all_roots = dctx.distribute_roots(roots); - - // // add challenges to transcript in order - // for group_idxs in dctx.my_groups.iter() { - // if verify_constraints { - // let dummy_elements = [F::zero(), F::one(), F::two(), F::neg_one()]; - // transcript.add_elements(dummy_elements.as_ptr() as *mut c_void, 4); - // } else { - // let mut values = Vec::new(); - // for idx in group_idxs.iter() { - // let value = vec![ - // F::from_wrapped_u64(all_roots[*idx]), - // F::from_wrapped_u64(all_roots[*idx + 1]), - // F::from_wrapped_u64(all_roots[*idx + 2]), - // F::from_wrapped_u64(all_roots[*idx + 3]), - // ]; - // values.push(value); - // } - // if !values.is_empty() { - // let value = Self::hash_b_tree(&*provers[0], values); - // transcript.add_elements(value.as_ptr() as *mut c_void, value.len()); - // } - // } - // } - // drop(dctx); - let airgroups = pctx.global_info.air_groups.clone(); - for (airgroup_id, _airgroup) in airgroups.iter().enumerate() { + let dctx = pctx.dctx.read().unwrap(); + + // calculate my roots + let mut roots: Vec = vec![0; 4 * provers.len()]; + for (i, prover) in provers.iter_mut().enumerate() { + // Important we need the roots in u64 in order to distribute them + let values = prover.get_transcript_values_u64(stage as u64, pctx.clone()); + if values.is_empty() { + panic!("No transcript values found for prover {}", i); + } + roots[i * 4..(i + 1) * 4].copy_from_slice(&values) + } + // get all roots + let all_roots = dctx.distribute_roots(roots); + + // add challenges to transcript in order + for group_idxs in dctx.my_groups.iter() { if pctx.options.verify_constraints { let dummy_elements = [F::zero(), F::one(), F::two(), F::neg_one()]; transcript.add_elements(dummy_elements.as_ptr() as *mut u8, 4); } else { - let airgroup_instances = pctx.air_instance_repo.find_airgroup_instances(airgroup_id); - - if !airgroup_instances.is_empty() { - let mut values = Vec::new(); - for prover_idx in airgroup_instances.iter() { - let value = provers[*prover_idx].get_transcript_values(stage as u64, pctx.clone()); - values.push(value); - } - if !values.is_empty() { - let value = Self::hash_b_tree(&*provers[airgroup_instances[0]], values); - transcript.add_elements(value.as_ptr() as *mut u8, value.len()); - } + let mut values = Vec::new(); + for idx in group_idxs.iter() { + let value = vec![ + F::from_wrapped_u64(all_roots[*idx]), + F::from_wrapped_u64(all_roots[*idx + 1]), + F::from_wrapped_u64(all_roots[*idx + 2]), + F::from_wrapped_u64(all_roots[*idx + 3]), + ]; + values.push(value); + } + if !values.is_empty() { + let value = Self::hash_b_tree(&*provers[0], values); + transcript.add_elements(value.as_ptr() as *mut u8, value.len()); } } } + drop(dctx); } fn get_challenges( @@ -531,23 +509,15 @@ impl ProofMan { ) { let num_commit_stages = pctx.global_info.n_challenges.len() as u32; + let dctx = pctx.dctx.read().unwrap(); + // Calculate evals timer_start_debug!(CALCULATING_EVALS); Self::get_challenges(pctx.global_info.n_challenges.len() as u32 + 2, provers, pctx.clone(), transcript); - // TODO: ACTIVATE DCTX BACK - // for group_idx in dctx.my_air_groups.iter() { - // provers[group_idx[0]].calculate_lev(pctx.clone()); - // for idx in group_idx.iter() { - // provers[*idx].opening_stage(1, sctx.clone(), pctx.clone()); - // } - // } - for airgroup_id in 0..pctx.global_info.air_groups.len() { - for air_id in 0..pctx.global_info.airs[airgroup_id].len() { - let instances = pctx.air_instance_repo.find_air_instances(airgroup_id, air_id); - for instance in instances { - provers[instance].calculate_lev(pctx.clone()); - provers[instance].opening_stage(1, sctx.clone(), pctx.clone()); - } + for group_idx in dctx.my_air_groups.iter() { + provers[group_idx[0]].calculate_lev(pctx.clone()); + for idx in group_idx.iter() { + provers[*idx].opening_stage(1, sctx.clone(), pctx.clone()); } } @@ -558,20 +528,10 @@ impl ProofMan { Self::get_challenges(pctx.global_info.n_challenges.len() as u32 + 3, provers, pctx.clone(), transcript); info!("{}: Calculating FRI Polynomials", Self::MY_NAME); timer_start_debug!(CALCULATING_FRI_POLINOMIAL); - // TODO: ACTIVATE DCTX BACK - // for group_idx in dctx.my_air_groups.iter() { - // provers[group_idx[0]].calculate_xdivxsub(pctx.clone()); - // for idx in group_idx.iter() { - // provers[*idx].opening_stage(2, sctx.clone(), pctx.clone()); - // } - // } - for airgroup_id in 0..pctx.global_info.air_groups.len() { - for air_id in 0..pctx.global_info.airs[airgroup_id].len() { - let instances = pctx.air_instance_repo.find_air_instances(airgroup_id, air_id); - for instance in instances { - provers[instance].calculate_xdivxsub(pctx.clone()); - provers[instance].opening_stage(2, sctx.clone(), pctx.clone()); - } + for group_idx in dctx.my_air_groups.iter() { + provers[group_idx[0]].calculate_xdivxsub(pctx.clone()); + for idx in group_idx.iter() { + provers[*idx].opening_stage(2, sctx.clone(), pctx.clone()); } } timer_stop_and_log_debug!(CALCULATING_FRI_POLINOMIAL); diff --git a/proofman/src/recursion.rs b/proofman/src/recursion.rs index 5ec3e28a..d8df2f51 100644 --- a/proofman/src/recursion.rs +++ b/proofman/src/recursion.rs @@ -164,54 +164,43 @@ pub fn generate_vadcop_recursive2_proof( let global_info_path = pctx.global_info.get_proving_key_path().join("pilout.globalInfo.json"); let global_info_file: &str = global_info_path.to_str().unwrap(); - // let mut dctx = pctx.dctx.write().unwrap(); + let mut dctx = pctx.dctx.write().unwrap(); let n_airgroups = pctx.global_info.air_groups.len(); let mut alives = Vec::with_capacity(n_airgroups); let mut airgroup_proofs: Vec>> = Vec::with_capacity(n_airgroups); - // TODO: ACTIVATE DCTX BACK - // let mut null_zkin: Option<*mut c_void> = None; - // let mut zkin_final = std::ptr::null_mut(); + let mut null_zkin: Option<*mut c_void> = None; + let mut zkin_final = std::ptr::null_mut(); // Pre-process data before starting recursion loop for airgroup in 0..n_airgroups { - let setup_path = pctx.global_info.get_air_setup_path(airgroup, 0, &ProofType::Recursive2); - // let instances = &dctx.airgroup_instances[airgroup]; - let instances = pctx.air_instance_repo.find_airgroup_instances(airgroup); + let instances = &dctx.airgroup_instances[airgroup]; airgroup_proofs.push(Vec::with_capacity(instances.len().max(1))); - if instances.is_empty() { - let zkin_file = setup_path.display().to_string() + ".null_zkin.json"; - airgroup_proofs[airgroup].push(Some(get_zkin_ptr_c(&zkin_file))); - } else { + if !instances.is_empty() { for instance in instances.iter() { - airgroup_proofs[airgroup].push(Some(proofs[*instance])); + let local_instance = dctx.glob2loc[*instance]; + let proof = local_instance.map(|idx| proofs[idx]); + airgroup_proofs[airgroup].push(proof); + } + } else { + // If there are no instances, we need to add a null proof (only rank 0) + if dctx.rank == 0 { + if null_zkin.is_none() { + let setup_path = pctx.global_info.get_air_setup_path(airgroup, 0, &ProofType::Recursive2); + let zkin_file = setup_path.display().to_string() + ".null_zkin.json"; + null_zkin = Some(get_zkin_ptr_c(&zkin_file)); + } + airgroup_proofs[airgroup].push(Some(null_zkin.unwrap())); + } else { + airgroup_proofs[airgroup].push(None); } } - // if !instances.is_empty() { - // for instance in instances.iter() { - // let local_instance = dctx.glob2loc[*instance]; - // let proof = local_instance.map(|idx| proofs[idx]); - // airgroup_proofs[airgroup].push(proof); - // } - // } else { - // If there are no instances, we need to add a null proof (only rank 0) - // if dctx.rank == 0 { - // if null_zkin.is_none() { - // let setup_path = pctx.global_info.get_air_setup_path(airgroup, 0, &ProofType::Recursive2); - // let zkin_file = setup_path.display().to_string() + ".null_zkin.json"; - // null_zkin = Some(get_zkin_ptr_c(&zkin_file)); - // } - // airgroup_proofs[airgroup].push(Some(null_zkin.unwrap())); - // } else { - // airgroup_proofs[airgroup].push(None); - // } - // } alives.push(airgroup_proofs[airgroup].len()); } // agregation loop loop { - // dctx.barrier(); - // dctx.distribute_recursive2_proofs(&alives, &mut airgroup_proofs); + dctx.barrier(); + dctx.distribute_recursive2_proofs(&alives, &mut airgroup_proofs); let mut pending_agregations = false; for airgroup in 0..n_airgroups { //create a vector of sice indices length @@ -311,30 +300,30 @@ pub fn generate_vadcop_recursive2_proof( } } - // if dctx.rank == 0 { - let mut proofs_recursive2: Vec<*mut c_void> = Vec::with_capacity(n_airgroups); - for proofs in airgroup_proofs { - proofs_recursive2.push(proofs[0].unwrap()); - } + if dctx.rank == 0 { + let mut proofs_recursive2: Vec<*mut c_void> = Vec::with_capacity(n_airgroups); + for proofs in airgroup_proofs { + proofs_recursive2.push(proofs[0].unwrap()); + } - let mut stark_infos_recursive2 = Vec::new(); - for (idx, _) in pctx.global_info.air_groups.iter().enumerate() { - stark_infos_recursive2.push(sctx.get_setup(idx, 0).p_setup.p_stark_info); - } + let mut stark_infos_recursive2 = Vec::new(); + for (idx, _) in pctx.global_info.air_groups.iter().enumerate() { + stark_infos_recursive2.push(sctx.get_setup(idx, 0).p_setup.p_stark_info); + } - let proofs_recursive2_ptr = proofs_recursive2.as_mut_ptr(); + let proofs_recursive2_ptr = proofs_recursive2.as_mut_ptr(); - let stark_infos_recursive2_ptr = stark_infos_recursive2.as_mut_ptr(); + let stark_infos_recursive2_ptr = stark_infos_recursive2.as_mut_ptr(); - let zkin_final = join_zkin_final_c( - pctx.get_publics_ptr(), - pctx.get_proof_values_ptr(), - pctx.get_challenges_ptr(), - global_info_file, - proofs_recursive2_ptr, - stark_infos_recursive2_ptr, - ); - // } + zkin_final = join_zkin_final_c( + pctx.get_publics_ptr(), + pctx.get_proof_values_ptr(), + pctx.get_challenges_ptr(), + global_info_file, + proofs_recursive2_ptr, + stark_infos_recursive2_ptr, + ); + } Ok(zkin_final) } diff --git a/proofman/src/verify_constraints.rs b/proofman/src/verify_constraints.rs index 856b145c..bd4e0b79 100644 --- a/proofman/src/verify_constraints.rs +++ b/proofman/src/verify_constraints.rs @@ -6,8 +6,7 @@ use std::cmp; use std::sync::Arc; use proofman_common::{ - get_constraints_lines_str, get_global_constraints_lines_str, GlobalConstraintInfo, ProofCtx, Prover, - SetupCtx, + get_constraints_lines_str, get_global_constraints_lines_str, GlobalConstraintInfo, ProofCtx, Prover, SetupCtx, }; use std::os::raw::c_void; From 5c667b4bbd59c2c1ba4a0ed89440ae217cbf47db Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 23 Dec 2024 13:15:32 +0000 Subject: [PATCH 58/64] Fixing test --- pil2-stark/src/api/starks_api.cpp | 15 +++---------- .../src/starkpil/global_constraints.hpp | 21 ++++++++++++++++++- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/pil2-stark/src/api/starks_api.cpp b/pil2-stark/src/api/starks_api.cpp index 364f3a91..342e7452 100644 --- a/pil2-stark/src/api/starks_api.cpp +++ b/pil2-stark/src/api/starks_api.cpp @@ -545,26 +545,17 @@ void verify_constraints(void *pSetupCtx, void* stepsParams, void* constraintsInf // ================================================================================= uint64_t get_n_global_constraints(void* p_globalinfo_bin) { - auto globalConstraintsBin = *(ExpressionsBin*)p_globalinfo_bin; - return globalConstraintsBin.constraintsInfoDebug.size(); + return getNumberGlobalConstraints(*(ExpressionsBin*)p_globalinfo_bin); } void get_global_constraints_lines_sizes(void* p_globalinfo_bin, uint64_t *constraintsLinesSizes) { - auto globalConstraintsBin = *(ExpressionsBin*)p_globalinfo_bin; - cout << "HOLA " << endl; - for(uint64_t i = 0; i < globalConstraintsBin.constraintsInfoDebug.size(); ++i) { - cout << globalConstraintsBin.constraintsInfoDebug[i].line << endl; - constraintsLinesSizes[i] = globalConstraintsBin.constraintsInfoDebug[i].line.size(); - } + return getGlobalConstraintsLinesSizes(*(ExpressionsBin*)p_globalinfo_bin, constraintsLinesSizes); } void get_global_constraints_lines(void* p_globalinfo_bin, uint8_t **constraintsLines) { - auto globalConstraintsBin = *(ExpressionsBin*)p_globalinfo_bin; - for(uint64_t i = 0; i < globalConstraintsBin.constraintsInfoDebug.size(); ++i) { - std::memcpy(constraintsLines[i], globalConstraintsBin.constraintsInfoDebug[i].line.data(), globalConstraintsBin.constraintsInfoDebug[i].line.size()); - } + return getGlobalConstraintsLines(*(ExpressionsBin*)p_globalinfo_bin, constraintsLines); } void verify_global_constraints(char* globalInfoFile, void* p_globalinfo_bin, void *publics, void *challenges, void *proofValues, void **airgroupValues, void *globalConstraintsInfo) { diff --git a/pil2-stark/src/starkpil/global_constraints.hpp b/pil2-stark/src/starkpil/global_constraints.hpp index b399c35f..a46165d9 100644 --- a/pil2-stark/src/starkpil/global_constraints.hpp +++ b/pil2-stark/src/starkpil/global_constraints.hpp @@ -299,7 +299,26 @@ void verifyGlobalConstraint(json& globalInfo, uint64_t constraintId, Goldilocks: } } - +uint64_t getNumberGlobalConstraints(ExpressionsBin &globalConstraintsBin) { + std::vector globalConstraints = globalConstraintsBin.constraintsInfoDebug; + return globalConstraints.size(); +} + +void getGlobalConstraintsLinesSizes(ExpressionsBin &globalConstraintsBin, uint64_t* constraintsLinesSizes) { + std::vector globalConstraints = globalConstraintsBin.constraintsInfoDebug; + for(uint64_t i = 0; i globalConstraints = globalConstraintsBin.constraintsInfoDebug; + for(uint64_t i = 0; i < globalConstraintsBin.constraintsInfoDebug.size(); ++i) { + std::memcpy(constraintsLines[i], globalConstraints[i].line.data(), globalConstraints[i].line.size()); + } +} + + void verifyGlobalConstraints(json& globalInfo, ExpressionsBin &globalConstraintsBin, Goldilocks::Element* publicInputs, Goldilocks::Element* challenges, Goldilocks::Element* proofValues, Goldilocks::Element** airgroupValues, GlobalConstraintInfo *globalConstraintsInfo) { std::vector globalConstraints = globalConstraintsBin.constraintsInfoDebug; From d97ed1214e64507970119796e2abd8aafec52ee0 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 23 Dec 2024 14:19:20 +0000 Subject: [PATCH 59/64] Adding get constraints method and fix ci --- .github/workflows/ci.yaml | 3 ++ cli/src/commands/get_constraints.rs | 62 +++++++++++++++++++++++++++++ cli/src/commands/mod.rs | 1 + cli/src/main.rs | 3 ++ 4 files changed, 69 insertions(+) create mode 100644 cli/src/commands/get_constraints.rs diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6eb4a8e5..1b492397 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -148,6 +148,9 @@ jobs: repository: iden3/circom path: circom-repo + - name: Install MPI + run: sudo apt-get update && sudo apt-get install -y mpich + - name: Build and install Circom working-directory: circom-repo run: | diff --git a/cli/src/commands/get_constraints.rs b/cli/src/commands/get_constraints.rs new file mode 100644 index 00000000..ebac50a1 --- /dev/null +++ b/cli/src/commands/get_constraints.rs @@ -0,0 +1,62 @@ +// extern crate env_logger; +use clap::Parser; +use proofman_common::initialize_logger; +use std::path::PathBuf; +use colored::Colorize; +use std::sync::Arc; + +use proofman_common::{get_global_constraints_lines_str, get_constraints_lines_str, GlobalInfo, SetupsVadcop, SetupCtx}; + +#[derive(Parser)] +#[command(version, about, long_about = None)] +#[command(propagate_version = true)] +pub struct GetConstraintsCmd { + /// Setup folder path + #[clap(long)] + pub proving_key: PathBuf, +} + +impl GetConstraintsCmd { + const MY_NAME: &str = "Cnstrnts"; + + pub fn run(&self) -> Result<(), Box> { + println!("{} GetConstraints", format!("{: >12}", "Command").bright_green().bold()); + println!(); + + let global_info = GlobalInfo::new(&self.proving_key); + let setups = Arc::new(SetupsVadcop::new(&global_info, false, false)); + let sctx: Arc = setups.sctx.clone(); + + initialize_logger(proofman_common::VerboseMode::Info); + + for airgroup_id in 0..global_info.air_groups.len() { + for air_id in 0..global_info.airs[airgroup_id].len() { + log::info!( + "{}", + format!( + "{}: ► Constraints of {} - {}", + Self::MY_NAME, + global_info.air_groups[airgroup_id], + global_info.airs[airgroup_id][air_id].name, + ) + .bright_white() + .bold() + ); + let constraints_lines: Vec = get_constraints_lines_str(sctx.clone(), airgroup_id, air_id); + for (idx, line) in constraints_lines.iter().enumerate() { + log::info!("{}: · Constraint #{} : {}", Self::MY_NAME, idx, line); + } + } + } + + let global_constraints_lines = get_global_constraints_lines_str(sctx.clone()); + + log::info!("{}", format!("{}: ► Global Constraints", Self::MY_NAME,).bright_white().bold()); + for idx in 0..global_constraints_lines.len() { + let line_str = &global_constraints_lines[idx]; + log::info!("{}: · Global Constraint #{} -> {}", Self::MY_NAME, idx, line_str); + } + + Ok(()) + } +} diff --git a/cli/src/commands/mod.rs b/cli/src/commands/mod.rs index 5b13463b..22e08004 100644 --- a/cli/src/commands/mod.rs +++ b/cli/src/commands/mod.rs @@ -5,3 +5,4 @@ pub mod new; pub mod pil_helpers; pub mod prove; pub mod verify_constraints; +pub mod get_constraints; diff --git a/cli/src/main.rs b/cli/src/main.rs index e05d7991..1a7ff34d 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -2,6 +2,7 @@ use std::process::exit; use clap::{Parser, Subcommand}; mod commands; +use commands::get_constraints::GetConstraintsCmd; use commands::pil_helpers::PilHelpersCmd; // use commands::new::NewCmd; use commands::prove::ProveCmd; @@ -26,6 +27,7 @@ pub enum Commands { Prove(ProveCmd), PilHelpers(PilHelpersCmd), VerifyConstraints(VerifyConstraintsCmd), + GetConstraints(GetConstraintsCmd), } fn main() { @@ -48,6 +50,7 @@ fn main() { Commands::Prove(args) => args.run(), Commands::PilHelpers(args) => args.run(), Commands::VerifyConstraints(args) => args.run(), + Commands::GetConstraints(args) => args.run(), }; if let Err(e) = result { From f2142579ef6b4d9f50609048ed1d0f71fa15cb50 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 23 Dec 2024 16:21:41 +0000 Subject: [PATCH 60/64] Minor changes --- .github/workflows/ci.yaml | 8 +- cli/src/commands/get_constraints.rs | 5 +- proofman/src/proofman.rs | 150 ++++++++++++++++++++++++---- 3 files changed, 135 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1b492397..5cb84a12 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -148,8 +148,6 @@ jobs: repository: iden3/circom path: circom-repo - - name: Install MPI - run: sudo apt-get update && sudo apt-get install -y mpich - name: Build and install Circom working-directory: circom-repo @@ -184,6 +182,7 @@ jobs: sudo apt-get update sudo apt-get install -y protobuf-compiler sudo apt install -y build-essential libbenchmark-dev libomp-dev libgmp-dev nlohmann-json3-dev nasm libsodium-dev cmake + sudo apt-get install -y openmpi-bin libopenmpi-dev - name: Install pil2-stark working-directory: pil2-stark @@ -232,9 +231,12 @@ jobs: run: | rm -rf examples/fibonacci-square/build/proofs + - name: Cargo build distributed + run: RUST_BACKTRACE=1 cargo build --features distributed -v + - name: Generate proof Fibonacci Square distributed run: | - mpirun --bind-to none -np 3 -x OMP_NUM_THREADS=32 target/release/proofman-cli prove --witness-lib ./target/debug/libfibonacci_square.so --public-inputs examples/fibonacci-square/src/inputs.json --proving-key examples/fibonacci-square/build/provingKey/ --output-dir examples/fibonacci-square/build/proofs -a + mpirun --bind-to none -np 3 -x OMP_NUM_THREADS=32 target/debug/proofman-cli prove --witness-lib ./target/debug/libfibonacci_square.so --public-inputs examples/fibonacci-square/src/inputs.json --proving-key examples/fibonacci-square/build/provingKey/ --output-dir examples/fibonacci-square/build/proofs -a - name: Verify proof Fibonacci Square distributed run: | diff --git a/cli/src/commands/get_constraints.rs b/cli/src/commands/get_constraints.rs index ebac50a1..a7fc198f 100644 --- a/cli/src/commands/get_constraints.rs +++ b/cli/src/commands/get_constraints.rs @@ -52,9 +52,8 @@ impl GetConstraintsCmd { let global_constraints_lines = get_global_constraints_lines_str(sctx.clone()); log::info!("{}", format!("{}: ► Global Constraints", Self::MY_NAME,).bright_white().bold()); - for idx in 0..global_constraints_lines.len() { - let line_str = &global_constraints_lines[idx]; - log::info!("{}: · Global Constraint #{} -> {}", Self::MY_NAME, idx, line_str); + for (idx, line) in global_constraints_lines.iter().enumerate() { + log::info!("{}: · Global Constraint #{} -> {}", Self::MY_NAME, idx, line); } Ok(()) diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index 27b9909e..94b5393a 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -68,8 +68,14 @@ impl ProofMan { let mut dctx = pctx.dctx.write().unwrap(); dctx.close(pctx.global_info.air_groups.len()); let mpi_rank = dctx.rank; + let n_processes = dctx.n_processes; drop(dctx); + if mpi_rank == 0 { + Self::print_global_summary(pctx.clone(), setups.sctx.clone()); + } + + if n_processes > 1 { Self::print_summary(pctx.clone(), setups.sctx.clone()); } @@ -346,19 +352,22 @@ impl ProofMan { } timer_stop_and_log_debug!(INITIALIZE_CONST_POLS_RECURSIVE2); - timer_start_debug!(INITIALIZE_CONST_POLS_VADCOP_FINAL); - info!("{}: ··· Initializing setup fixed pols vadcop final", Self::MY_NAME); - setup_vadcop_final.load_const_pols(&pctx.global_info, &ProofType::VadcopFinal); - setup_vadcop_final.load_const_pols_tree(&pctx.global_info, &ProofType::VadcopFinal, false); - timer_stop_and_log_debug!(INITIALIZE_CONST_POLS_VADCOP_FINAL); - - if pctx.options.final_snark { - let setup_recursivef = setups.setup_recursivef.as_ref().unwrap().clone(); - timer_start_debug!(INITIALIZE_CONST_POLS_RECURSIVE_FINAL); - info!("{}: ··· Initializing setup fixed pols recursive final", Self::MY_NAME); - setup_recursivef.load_const_pols(&pctx.global_info, &ProofType::RecursiveF); - setup_recursivef.load_const_pols_tree(&pctx.global_info, &ProofType::RecursiveF, false); - timer_stop_and_log_debug!(INITIALIZE_CONST_POLS_RECURSIVE_FINAL); + let dctx = pctx.dctx.read().unwrap(); + if dctx.rank == 0 { + timer_start_debug!(INITIALIZE_CONST_POLS_VADCOP_FINAL); + info!("{}: ··· Initializing setup fixed pols vadcop final", Self::MY_NAME); + setup_vadcop_final.load_const_pols(&pctx.global_info, &ProofType::VadcopFinal); + setup_vadcop_final.load_const_pols_tree(&pctx.global_info, &ProofType::VadcopFinal, false); + timer_stop_and_log_debug!(INITIALIZE_CONST_POLS_VADCOP_FINAL); + + if pctx.options.final_snark { + let setup_recursivef = setups.setup_recursivef.as_ref().unwrap().clone(); + timer_start_debug!(INITIALIZE_CONST_POLS_RECURSIVE_FINAL); + info!("{}: ··· Initializing setup fixed pols recursive final", Self::MY_NAME); + setup_recursivef.load_const_pols(&pctx.global_info, &ProofType::RecursiveF); + setup_recursivef.load_const_pols_tree(&pctx.global_info, &ProofType::RecursiveF, false); + timer_stop_and_log_debug!(INITIALIZE_CONST_POLS_RECURSIVE_FINAL); + } } } timer_stop_and_log_debug!(INITIALIZE_SETUP); @@ -607,6 +616,109 @@ impl ProofMan { proves } + fn print_global_summary(pctx: Arc>, sctx: Arc) { + let dctx = pctx.dctx.read().unwrap(); + + let mut air_info = HashMap::new(); + + let mut air_instances = HashMap::new(); + for (airgroup_id, air_id) in &dctx.instances { + let air_name = pctx.global_info.airs[*airgroup_id][*air_id].clone().name; + let air_group_name = pctx.global_info.air_groups[*airgroup_id].clone(); + let air_instance_map = air_instances.entry(air_group_name).or_insert_with(HashMap::new); + if !air_instance_map.contains_key(&air_name.clone()) { + let setup = sctx.get_setup(*airgroup_id, *air_id); + let n_bits = setup.stark_info.stark_struct.n_bits; + let memory_instance = get_map_totaln_c(setup.p_setup.p_stark_info) as f64 * 8.0; + let memory_fixed = (setup.stark_info.n_constants * (1 << (setup.stark_info.stark_struct.n_bits)) + + setup.stark_info.n_constants * (1 << (setup.stark_info.stark_struct.n_bits_ext))) + as f64 + * 8.0; + let memory_helpers = setup.stark_info.get_buff_helper_size() as f64 * 8.0; + let total_cols: u64 = setup + .stark_info + .map_sections_n + .iter() + .filter(|(key, _)| *key != "const") + .map(|(_, value)| *value) + .sum(); + air_info.insert(air_name.clone(), (n_bits, total_cols, memory_fixed, memory_helpers, memory_instance)); + } + let air_instance_map_key = air_instance_map.entry(air_name).or_insert(0); + *air_instance_map_key += 1; + } + + let mut air_groups: Vec<_> = air_instances.keys().collect(); + air_groups.sort(); + + info!( + "{}", + format!("{}: --- TOTAL PROOF INSTANCES SUMMARY ------------------------", Self::MY_NAME) + .bright_white() + .bold() + ); + info!("{}: ► {} Air instances found:", Self::MY_NAME, dctx.instances.len()); + for air_group in air_groups.clone() { + let air_group_instances = air_instances.get(air_group).unwrap(); + let mut air_names: Vec<_> = air_group_instances.keys().collect(); + air_names.sort(); + + info!("{}: Air Group [{}]", Self::MY_NAME, air_group); + for air_name in air_names { + let count = air_group_instances.get(air_name).unwrap(); + let (n_bits, total_cols, _, _, _) = air_info.get(air_name).unwrap(); + info!( + "{}: {}", + Self::MY_NAME, + format!("· {} x Air [{}] ({} x 2^{})", count, air_name, total_cols, n_bits).bright_white().bold() + ); + } + } + info!("{}: ----------------------------------------------------------", Self::MY_NAME); + info!( + "{}", + format!("{}: --- TOTAL PROVER MEMORY USAGE ----------------------------", Self::MY_NAME).bright_white().bold() + ); + let mut total_memory = 0f64; + let mut memory_helper_size = 0f64; + for air_group in air_groups { + let air_group_instances = air_instances.get(air_group).unwrap(); + let mut air_names: Vec<_> = air_group_instances.keys().collect(); + air_names.sort(); + + for air_name in air_names { + let count = air_group_instances.get(air_name).unwrap(); + let (_, _, memory_fixed, memory_helper_instance_size, memory_instance) = + air_info.get(air_name).unwrap(); + let total_memory_instance = memory_fixed + memory_instance * *count as f64; + total_memory += total_memory_instance; + if *memory_helper_instance_size > memory_helper_size { + memory_helper_size = *memory_helper_instance_size; + } + info!( + "{}: {}", + Self::MY_NAME, + format!( + "· {}: {} fixed cols | {} per each of {} instance | Total {}", + air_name, + format_bytes(*memory_fixed), + format_bytes(*memory_instance), + count, + format_bytes(total_memory_instance) + ) + ); + } + } + total_memory += memory_helper_size; + info!("{}: {}", Self::MY_NAME, format!("Extra helper memory: {}", format_bytes(memory_helper_size))); + info!( + "{}: {}", + Self::MY_NAME, + format!("Total prover memory required: {}", format_bytes(total_memory)).bright_white().bold() + ); + info!("{}: ----------------------------------------------------------", Self::MY_NAME); + } + fn print_summary(pctx: Arc>, sctx: Arc) { let air_instances_repo = pctx.air_instance_repo.air_instances.read().unwrap(); let air_instances_repo = &*air_instances_repo; @@ -661,7 +773,7 @@ impl ProofMan { ); } } - info!("{}: --- PROOF INSTANCES SUMMARY ------------------------", Self::MY_NAME); + info!("{}: ------------------------------------------------", Self::MY_NAME); info!("{}: --- PROVER MEMORY USAGE ------------------------", Self::MY_NAME); info!("{}: ► {} Air instances found:", Self::MY_NAME, air_instances_repo.len()); let mut total_memory = 0f64; @@ -691,23 +803,17 @@ impl ProofMan { count, format_bytes(total_memory_instance) ) - .bright_white() - .bold() ); } } total_memory += memory_helper_size; - info!( - "{}: {}", - Self::MY_NAME, - format!("Extra helper memory: {}", format_bytes(memory_helper_size)).bright_white().bold() - ); + info!("{}: {}", Self::MY_NAME, format!("Extra helper memory: {}", format_bytes(memory_helper_size))); info!( "{}: {}", Self::MY_NAME, format!("Total prover memory required: {}", format_bytes(total_memory)).bright_white().bold() ); - info!("{}: --- PROVER MEMORY USAGE ------------------------", Self::MY_NAME); + info!("{}: ------------------------------------------------", Self::MY_NAME); } fn check_paths( From 5e6d6715717edfb21f5c2b96039e427d1c841434 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 23 Dec 2024 18:01:42 +0000 Subject: [PATCH 61/64] Minor improvements, prepare for debugging mode --- cli/assets/templates/pil_helpers_trace.rs.tt | 6 +++ cli/src/commands/pil_helpers.rs | 29 ++++++++---- common/src/air_instance.rs | 28 ++++++++++++ common/src/air_instances_repository.rs | 35 ++++++++++++++- common/src/constraints.rs | 2 + common/src/proof_ctx.rs | 41 +++++++++++++++++ examples/fibonacci-square/src/fibonacci.rs | 17 ++++++- .../src/pil_helpers/traces.rs | 14 ++++++ macros/src/lib.rs | 22 +++++++++ .../src/starkpil/global_constraints.hpp | 5 ++- .../src/starkpil/verify_constraints.hpp | 17 ++++--- proofman/src/proofman.rs | 5 ++- proofman/src/verify_constraints.rs | 45 ++++++++++--------- provers/stark/src/stark_prover.rs | 2 + witness/src/witness_component.rs | 2 + witness/src/witness_manager.rs | 6 +++ 16 files changed, 237 insertions(+), 39 deletions(-) diff --git a/cli/assets/templates/pil_helpers_trace.rs.tt b/cli/assets/templates/pil_helpers_trace.rs.tt index 445d7b78..ee6e7147 100644 --- a/cli/assets/templates/pil_helpers_trace.rs.tt +++ b/cli/assets/templates/pil_helpers_trace.rs.tt @@ -4,6 +4,8 @@ use proofman_common as common; pub use proofman_macros::trace; pub use proofman_macros::values; +use std::fmt; + #[allow(dead_code)] type FieldExtension = [F; 3]; @@ -47,4 +49,8 @@ trace!({ air.name }{custom_commit.name}Trace \{ values!({ air.name }AirValues \{ {{ for column in air_values.values }} { column.name }: { column.type },{{ endfor }} }); +{{ endfor }}{{ endfor }}{{ endfor }}{{ for air_group in air_groups }}{{ for air in air_group.airs }}{{ for air_groupvalues in air.airgroup_values }} +values!({ air.name }AirGroupValues \{ +{{ for column in air_groupvalues.values }} { column.name }: { column.type },{{ endfor }} +}); {{ endfor }}{{ endfor }}{{ endfor }} \ No newline at end of file diff --git a/cli/src/commands/pil_helpers.rs b/cli/src/commands/pil_helpers.rs index b6524486..cb560fa3 100644 --- a/cli/src/commands/pil_helpers.rs +++ b/cli/src/commands/pil_helpers.rs @@ -26,7 +26,7 @@ pub struct PilHelpersCmd { pub verbose: u8, // Using u8 to hold the number of `-v` } -#[derive(Serialize)] +#[derive(Clone, Serialize)] struct ProofCtx { project_name: String, num_stages: u32, @@ -38,7 +38,7 @@ struct ProofCtx { publics: Vec, } -#[derive(Debug, Serialize)] +#[derive(Clone, Debug, Serialize)] struct AirGroupsCtx { airgroup_id: usize, name: String, @@ -46,35 +46,42 @@ struct AirGroupsCtx { airs: Vec, } -#[derive(Debug, Serialize)] +#[derive(Clone, Debug, Serialize)] struct AirCtx { id: usize, name: String, num_rows: u32, columns: Vec, + stages_columns: Vec, custom_columns: Vec, air_values: Vec, airgroup_values: Vec, } -#[derive(Debug, Serialize)] +#[derive(Clone, Debug, Serialize)] struct ValuesCtx { values: Vec, values_u64: Vec, } -#[derive(Debug, Serialize)] +#[derive(Clone, Debug, Serialize)] struct CustomCommitsCtx { name: String, commit_id: usize, custom_columns: Vec, } -#[derive(Debug, Serialize)] +#[derive(Clone, Debug, Serialize)] struct ColumnCtx { name: String, r#type: String, } +#[derive(Default, Clone, Debug, Serialize)] +struct StageColumnCtx { + stage_id: usize, + columns: Vec, +} + impl PilHelpersCmd { pub fn run(&self) -> Result<(), Box> { println!("{} Pil-helpers", format!("{: >12}", "Command").bright_green().bold()); @@ -128,6 +135,7 @@ impl PilHelpersCmd { name: air.name.as_ref().unwrap().clone(), num_rows: air.num_rows.unwrap(), columns: Vec::new(), + stages_columns: vec![StageColumnCtx::default(); pilout.num_challenges.len() - 1], custom_columns: Vec::new(), air_values: Vec::new(), airgroup_values: Vec::new(), @@ -236,7 +244,7 @@ impl PilHelpersCmd { && ((symbol.air_id.is_some() && symbol.air_id.unwrap() == air_id as u32) || symbol.r#type == SymbolType::AirGroupValue as i32) && symbol.stage.is_some() - && ((symbol.r#type == SymbolType::WitnessCol as i32 && symbol.stage.unwrap() == 1) + && ((symbol.r#type == SymbolType::WitnessCol as i32) || (symbol.r#type == SymbolType::AirValue as i32) || (symbol.r#type == SymbolType::AirGroupValue as i32) || (symbol.r#type == SymbolType::CustomCol as i32 && symbol.stage.unwrap() == 0)) @@ -264,7 +272,12 @@ impl PilHelpersCmd { }) }; if symbol.r#type == SymbolType::WitnessCol as i32 { - air.columns.push(ColumnCtx { name: name.to_owned(), r#type }); + if symbol.stage.unwrap() == 1 { + air.columns.push(ColumnCtx { name: name.to_owned(), r#type }); + } else { + air.stages_columns[symbol.stage.unwrap() as usize - 2].stage_id = symbol.stage.unwrap() as usize; + air.stages_columns[symbol.stage.unwrap() as usize - 2].columns.push(ColumnCtx { name: name.to_owned(), r#type: ext_type }); + } } else if symbol.r#type == SymbolType::AirValue as i32 { if air.air_values.is_empty() { air.air_values.push(ValuesCtx { values: Vec::new(), values_u64: Vec::new() }); diff --git a/common/src/air_instance.rs b/common/src/air_instance.rs index 1475da86..d4053755 100644 --- a/common/src/air_instance.rs +++ b/common/src/air_instance.rs @@ -127,6 +127,7 @@ pub struct AirInstance { pub airgroup_values: Vec, pub airvalues: Vec, pub evals: Vec, + pub prover_initialized: bool, } impl AirInstance { @@ -153,6 +154,7 @@ impl AirInstance { airgroup_values, airvalues, evals: Vec::new(), + prover_initialized: false, } } @@ -190,6 +192,20 @@ impl AirInstance { } } + pub fn get_trace(&self) -> Vec { + self.trace.clone() + } + + pub fn get_trace_stage(&self, stage: usize) -> Vec { + if stage < 2 { + panic!("Stage must be 2 or higher"); + } + + //TODO! + + Vec::new() + } + pub fn get_trace_ptr(&self) -> *mut u8 { self.trace.as_ptr() as *mut u8 } @@ -202,6 +218,14 @@ impl AirInstance { self.airgroup_values.as_ptr() as *mut u8 } + pub fn get_air_values(&self) -> Vec { + self.airvalues.clone() + } + + pub fn get_airgroup_values(&self) -> Vec { + self.airgroup_values.clone() + } + pub fn get_airvalues_ptr(&self) -> *mut u8 { self.airvalues.as_ptr() as *mut u8 } @@ -258,6 +282,10 @@ impl AirInstance { self.idx = Some(idx); } + pub fn set_prover_initialized(&mut self) { + self.prover_initialized = true; + } + pub fn clear_trace(&mut self) { self.trace = Vec::new(); } diff --git a/common/src/air_instances_repository.rs b/common/src/air_instances_repository.rs index 893db2fa..53655399 100644 --- a/common/src/air_instances_repository.rs +++ b/common/src/air_instances_repository.rs @@ -46,12 +46,24 @@ impl AirInstancesRepository { air_instances.push(air_instance); } + pub fn get_air_instances(&self) -> Vec { + let air_instances = self.air_instances.read().unwrap(); + + let mut indices = Vec::new(); + for (index, air_instance) in air_instances.iter().enumerate() { + if air_instance.prover_initialized { + indices.push(index); + } + } + indices + } + pub fn find_airgroup_instances(&self, airgroup_id: usize) -> Vec { let air_instances = self.air_instances.read().unwrap(); let mut indices = Vec::new(); for (index, air_instance) in air_instances.iter().enumerate() { - if air_instance.airgroup_id == airgroup_id { + if air_instance.airgroup_id == airgroup_id && air_instance.prover_initialized { indices.push(index); } } @@ -63,7 +75,10 @@ impl AirInstancesRepository { let mut indices = Vec::new(); for (index, air_instance) in air_instances.iter().enumerate() { - if air_instance.airgroup_id == airgroup_id && air_instance.air_id == air_id { + if air_instance.airgroup_id == airgroup_id + && air_instance.air_id == air_id + && air_instance.prover_initialized + { indices.push(index); } } @@ -71,6 +86,22 @@ impl AirInstancesRepository { indices } + pub fn find_instance(&self, airgroup_id: usize, air_id: usize, air_instance_id: usize) -> Option { + let air_instances = self.air_instances.read().unwrap(); + + for (index, air_instance) in air_instances.iter().enumerate() { + if air_instance.airgroup_id == airgroup_id + && air_instance.air_id == air_id + && air_instance.air_instance_id.unwrap() == air_instance_id + && air_instance.prover_initialized + { + return Some(index); + } + } + + None + } + // pub fn calculate_my_groups(&self) { // let mut group_indices: BTreeMap> = BTreeMap::new(); diff --git a/common/src/constraints.rs b/common/src/constraints.rs index cd6abccf..31520811 100644 --- a/common/src/constraints.rs +++ b/common/src/constraints.rs @@ -22,6 +22,7 @@ pub struct ConstraintInfo { pub stage: u64, pub im_pol: bool, pub n_rows: u64, + pub skip: bool, pub rows: [ConstraintRowInfo; 10usize], } @@ -31,6 +32,7 @@ pub struct GlobalConstraintInfo { pub id: u64, pub dim: u64, pub valid: bool, + pub skip: bool, pub value: [u64; 3usize], } diff --git a/common/src/proof_ctx.rs b/common/src/proof_ctx.rs index 12995f4e..fd0aff1f 100644 --- a/common/src/proof_ctx.rs +++ b/common/src/proof_ctx.rs @@ -146,4 +146,45 @@ impl ProofCtx { let guard = &self.buff_helper.values.read().unwrap(); guard.as_ptr() as *mut u8 } + + pub fn get_air_instance_trace(&self, airgroup_id: usize, air_id: usize, air_instance_id: usize) -> Vec { + let index = self.air_instance_repo.find_instance(airgroup_id, air_id, air_instance_id); + if let Some(index) = index { + return self.air_instance_repo.air_instances.read().unwrap()[index].get_trace(); + } else { + panic!( + "Air Instance with id {} for airgroup {} and air {} not found", + air_instance_id, airgroup_id, air_id + ); + } + } + + pub fn get_air_instance_air_values(&self, airgroup_id: usize, air_id: usize, air_instance_id: usize) -> Vec { + let index = self.air_instance_repo.find_instance(airgroup_id, air_id, air_instance_id); + if let Some(index) = index { + return self.air_instance_repo.air_instances.read().unwrap()[index].get_air_values(); + } else { + panic!( + "Air Instance with id {} for airgroup {} and air {} not found", + air_instance_id, airgroup_id, air_id + ); + } + } + + pub fn get_air_instance_airgroup_values( + &self, + airgroup_id: usize, + air_id: usize, + air_instance_id: usize, + ) -> Vec { + let index = self.air_instance_repo.find_instance(airgroup_id, air_id, air_instance_id); + if let Some(index) = index { + return self.air_instance_repo.air_instances.read().unwrap()[index].get_airgroup_values(); + } else { + panic!( + "Air Instance with id {} for airgroup {} and air {} not found", + air_instance_id, airgroup_id, air_id + ); + } + } } diff --git a/examples/fibonacci-square/src/fibonacci.rs b/examples/fibonacci-square/src/fibonacci.rs index 88990514..0db093fa 100644 --- a/examples/fibonacci-square/src/fibonacci.rs +++ b/examples/fibonacci-square/src/fibonacci.rs @@ -7,7 +7,7 @@ use p3_field::PrimeField64; use crate::{ FibonacciSquareRomTrace, BuildPublicValues, BuildProofValues, FibonacciSquareAirValues, FibonacciSquareTrace, - Module, + FibonacciSquareAirGroupValues, Module, }; pub struct FibonacciSquare { @@ -69,4 +69,19 @@ impl WitnessComponent for FibonacciSquare { ); add_air_instance::(air_instance, pctx.clone()); } + + fn debug(&self, pctx: Arc>) { + let trace = FibonacciSquareTrace::from_vec(pctx.get_air_instance_trace(0, 0, 0)); + let air_values = FibonacciSquareAirValues::from_vec(pctx.get_air_instance_air_values(0, 0, 0)); + let airgroup_values = FibonacciSquareAirGroupValues::from_vec(pctx.get_air_instance_airgroup_values(0, 0, 0)); + + let publics = BuildPublicValues::from_vec_guard(pctx.get_publics()); + let proof_values = BuildProofValues::from_vec_guard(pctx.get_proof_values()); + + log::info!("{} First row 1: {:?}", Self::MY_NAME, trace[1]); + log::info!("{} Air values: {:?}", Self::MY_NAME, air_values); + log::info!("{} Airgroup values: {:?}", Self::MY_NAME, airgroup_values); + log::info!("{} Publics: {:?}", Self::MY_NAME, publics); + log::info!("{} Proof values: {:?}", Self::MY_NAME, proof_values); + } } diff --git a/examples/fibonacci-square/src/pil_helpers/traces.rs b/examples/fibonacci-square/src/pil_helpers/traces.rs index 30776fd0..56b69df7 100644 --- a/examples/fibonacci-square/src/pil_helpers/traces.rs +++ b/examples/fibonacci-square/src/pil_helpers/traces.rs @@ -4,6 +4,8 @@ use proofman_common as common; pub use proofman_macros::trace; pub use proofman_macros::values; +use std::fmt; + #[allow(dead_code)] type FieldExtension = [F; 3]; @@ -67,3 +69,15 @@ trace!(FibonacciSquareRomTrace { values!(FibonacciSquareAirValues { fibo1: [F; 2], fibo3: FieldExtension, }); + +values!(FibonacciSquareAirGroupValues { + gsum_result: FieldExtension, +}); + +values!(ModuleAirGroupValues { + gsum_result: FieldExtension, +}); + +values!(U8AirAirGroupValues { + gsum_result: FieldExtension, +}); diff --git a/macros/src/lib.rs b/macros/src/lib.rs index c4f955ef..32289ce9 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -111,6 +111,21 @@ fn trace_impl(input: TokenStream2) -> Result { } } + pub fn from_vec( + mut external_buffer: Vec<#generics>, + ) -> Self { + let num_rows = Self::NUM_ROWS; + let buffer: Vec<#row_struct_name::<#generics>> = unsafe { std::mem::transmute(external_buffer) }; + #trace_struct_name { + buffer, + num_rows, + row_size: #row_struct_name::<#generics>::ROW_SIZE, + airgroup_id: Self::AIRGROUP_ID, + air_id: Self::AIR_ID, + commit_id: #commit_id, + } + } + pub fn num_rows(&self) -> usize { self.num_rows } @@ -373,6 +388,13 @@ fn values_impl(input: TokenStream2) -> Result { } } + impl<'a, #generics> std::fmt::Debug for #values_struct_name<'a, #generics> + where #generics: std::fmt::Debug { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Debug::fmt(&self.slice_values, f) + } + } + impl<'a, #generics> std::ops::DerefMut for #values_struct_name<'a, #generics> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.slice_values diff --git a/pil2-stark/src/starkpil/global_constraints.hpp b/pil2-stark/src/starkpil/global_constraints.hpp index a46165d9..aa3ca4d7 100644 --- a/pil2-stark/src/starkpil/global_constraints.hpp +++ b/pil2-stark/src/starkpil/global_constraints.hpp @@ -9,6 +9,7 @@ struct GlobalConstraintInfo { uint64_t id; uint64_t dim; bool valid; + bool skip; uint64_t value[3]; }; @@ -324,7 +325,9 @@ void verifyGlobalConstraints(json& globalInfo, ExpressionsBin &globalConstraints std::vector globalConstraints = globalConstraintsBin.constraintsInfoDebug; for(uint64_t i = 0; i < globalConstraints.size(); ++i) { - verifyGlobalConstraint(globalInfo, i, publicInputs, challenges, proofValues, airgroupValues, globalConstraintsBin.expressionsBinArgsConstraints, globalConstraints[i], globalConstraintsInfo[i]); + if(!globalConstraintsInfo[i].skip) { + verifyGlobalConstraint(globalInfo, i, publicInputs, challenges, proofValues, airgroupValues, globalConstraintsBin.expressionsBinArgsConstraints, globalConstraints[i], globalConstraintsInfo[i]); + } } } diff --git a/pil2-stark/src/starkpil/verify_constraints.hpp b/pil2-stark/src/starkpil/verify_constraints.hpp index ea3677ab..69fae1fd 100644 --- a/pil2-stark/src/starkpil/verify_constraints.hpp +++ b/pil2-stark/src/starkpil/verify_constraints.hpp @@ -11,6 +11,7 @@ struct ConstraintInfo { uint64_t stage; bool imPol; uint64_t nrows; + bool skip; ConstraintRowInfo rows[10]; }; @@ -89,11 +90,16 @@ void verifyConstraints(SetupCtx& setupCtx, StepsParams ¶ms, ConstraintInfo * // TODO: REUSE MEMORY Goldilocks::Element* pBuffer = new Goldilocks::Element[setupCtx.expressionsBin.constraintsInfoDebug.size() * N * FIELD_EXTENSION]; + std::vector destToConstraintIndex; + std::vector dests; for (uint64_t i = 0; i < setupCtx.expressionsBin.constraintsInfoDebug.size(); i++) { - Dest constraintDest(&pBuffer[i*FIELD_EXTENSION*N]); - constraintDest.addParams(setupCtx.expressionsBin.constraintsInfoDebug[i]); - dests.push_back(constraintDest); + if(!constraintsInfo[i].skip) { + Dest constraintDest(&pBuffer[i*FIELD_EXTENSION*N]); + constraintDest.addParams(setupCtx.expressionsBin.constraintsInfoDebug[i]); + dests.push_back(constraintDest); + destToConstraintIndex.push_back(i); + } } #ifdef __AVX512__ @@ -107,8 +113,9 @@ void verifyConstraints(SetupCtx& setupCtx, StepsParams ¶ms, ConstraintInfo * expressionsCtx.calculateExpressions(params, setupCtx.expressionsBin.expressionsBinArgsConstraints, dests, uint64_t(1 << setupCtx.starkInfo.starkStruct.nBits), false); #pragma omp parallel for - for (uint64_t i = 0; i < setupCtx.expressionsBin.constraintsInfoDebug.size(); i++) { - verifyConstraint(setupCtx, dests[i].dest, i, constraintsInfo[i]); + for (uint64_t i = 0; i < dests.size(); i++) { + uint64_t constraintIndex = destToConstraintIndex[i]; + verifyConstraint(setupCtx, dests[i].dest, constraintIndex, constraintsInfo[constraintIndex]); } delete[] pBuffer; diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index 94b5393a..11f8e5cb 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -119,6 +119,7 @@ impl ProofMan { wcm.end_proof(); if pctx.options.verify_constraints { + wcm.debug(); return verify_constraints_proof(pctx.clone(), sctx.clone(), &mut provers); } @@ -677,7 +678,9 @@ impl ProofMan { info!("{}: ----------------------------------------------------------", Self::MY_NAME); info!( "{}", - format!("{}: --- TOTAL PROVER MEMORY USAGE ----------------------------", Self::MY_NAME).bright_white().bold() + format!("{}: --- TOTAL PROVER MEMORY USAGE ----------------------------", Self::MY_NAME) + .bright_white() + .bold() ); let mut total_memory = 0f64; let mut memory_helper_size = 0f64; diff --git a/proofman/src/verify_constraints.rs b/proofman/src/verify_constraints.rs index 8b382cc0..dc8d481e 100644 --- a/proofman/src/verify_constraints.rs +++ b/proofman/src/verify_constraints.rs @@ -59,21 +59,29 @@ pub fn verify_constraints_proof( } let mut valid_constraints = true; - for (air_instance_index, air_instance) in pctx.air_instance_repo.air_instances.read().unwrap().iter().enumerate() { - let air_name = &pctx.global_info.airs[air_instance.airgroup_id][air_instance.air_id].name; - let constraints_lines = get_constraints_lines_str(sctx.clone(), air_instance.airgroup_id, air_instance.air_id); + for (idx, prover) in provers.iter().enumerate() { + let prover_info = prover.get_prover_info(); + let (airgroup_id, air_id, air_instance_id) = + (prover_info.airgroup_id, prover_info.air_id, prover_info.instance_id); + + let air_name = &pctx.global_info.airs[airgroup_id][air_id].name; + + let constraints_lines = get_constraints_lines_str(sctx.clone(), airgroup_id, air_id); let mut valid_constraints_prover = true; log::info!( "{}: ► Instance #{} of {} (Airgroup {} - Air {})", MY_NAME, - air_instance.air_instance_id.unwrap(), + air_instance_id, air_name, - air_instance.airgroup_id, - air_instance.air_id, + airgroup_id, + air_id, ); - for constraint in &constraints[air_instance_index] { + for constraint in &constraints[idx] { + if constraint.skip { + continue; + } let valid = if constraint.n_rows > 0 { format!("has {} invalid rows", constraint.n_rows).bright_red() } else { @@ -136,25 +144,17 @@ pub fn verify_constraints_proof( log::info!( "{}: ··· {}", MY_NAME, - format!( - "\u{2717} Not all constraints for Instance #{} of {} were verified", - air_instance.air_instance_id.unwrap(), - air_name - ) - .bright_red() - .bold() + format!("\u{2717} Not all constraints for Instance #{} of {} were verified", air_instance_id, air_name) + .bright_red() + .bold() ); } else { log::info!( "{}: {}", MY_NAME, - format!( - "\u{2713} All constraints for Instance #{} of {} were verified", - air_instance.air_instance_id.unwrap(), - air_name - ) - .bright_green() - .bold() + format!("\u{2713} All constraints for Instance #{} of {} were verified", air_instance_id, air_name) + .bright_green() + .bold() ); } @@ -170,6 +170,9 @@ pub fn verify_constraints_proof( for idx in 0..global_constraints.len() { let constraint = global_constraints[idx]; + if constraint.skip { + continue; + } let line_str = &global_constraints_lines[idx]; let valid = if !constraint.valid { "is invalid".bright_red() } else { "is valid".bright_green() }; diff --git a/provers/stark/src/stark_prover.rs b/provers/stark/src/stark_prover.rs index 409c875e..a20cc6bf 100644 --- a/provers/stark/src/stark_prover.rs +++ b/provers/stark/src/stark_prover.rs @@ -109,6 +109,8 @@ impl Prover for StarkProver { if n_airgroup_values > 0 && air_instance.airgroup_values.is_empty() { air_instance.init_airgroup_values(n_airgroup_values * Self::FIELD_EXTENSION); } + + air_instance.set_prover_initialized(); } fn free(&mut self) { diff --git a/witness/src/witness_component.rs b/witness/src/witness_component.rs index 3d659878..d587fb03 100644 --- a/witness/src/witness_component.rs +++ b/witness/src/witness_component.rs @@ -7,6 +7,8 @@ pub trait WitnessComponent: Send + Sync { fn execute(&self, _pctx: Arc>) {} + fn debug(&self, _pctx: Arc>) {} + fn calculate_witness(&self, _stage: u32, _pctx: Arc>, _sctx: Arc) {} fn end_proof(&self) {} diff --git a/witness/src/witness_manager.rs b/witness/src/witness_manager.rs index a4ff3e3e..51bf8a39 100644 --- a/witness/src/witness_manager.rs +++ b/witness/src/witness_manager.rs @@ -43,6 +43,12 @@ impl WitnessManager { timer_stop_and_log_info!(EXECUTE); } + pub fn debug(&self) { + for component in self.components.read().unwrap().iter() { + component.debug(self.pctx.clone()); + } + } + pub fn end_proof(&self) { for component in self.components.read().unwrap().iter() { component.end_proof(); From 0c35e2ad586670358e19fe157002c164de6816aa Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Mon, 23 Dec 2024 18:14:41 +0000 Subject: [PATCH 62/64] Cargo fmt --- cli/src/commands/pil_helpers.rs | 7 +++++-- common/src/air_instance.rs | 2 -- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cli/src/commands/pil_helpers.rs b/cli/src/commands/pil_helpers.rs index cb560fa3..460b6c48 100644 --- a/cli/src/commands/pil_helpers.rs +++ b/cli/src/commands/pil_helpers.rs @@ -275,8 +275,11 @@ impl PilHelpersCmd { if symbol.stage.unwrap() == 1 { air.columns.push(ColumnCtx { name: name.to_owned(), r#type }); } else { - air.stages_columns[symbol.stage.unwrap() as usize - 2].stage_id = symbol.stage.unwrap() as usize; - air.stages_columns[symbol.stage.unwrap() as usize - 2].columns.push(ColumnCtx { name: name.to_owned(), r#type: ext_type }); + air.stages_columns[symbol.stage.unwrap() as usize - 2].stage_id = + symbol.stage.unwrap() as usize; + air.stages_columns[symbol.stage.unwrap() as usize - 2] + .columns + .push(ColumnCtx { name: name.to_owned(), r#type: ext_type }); } } else if symbol.r#type == SymbolType::AirValue as i32 { if air.air_values.is_empty() { diff --git a/common/src/air_instance.rs b/common/src/air_instance.rs index d4053755..4fe803bb 100644 --- a/common/src/air_instance.rs +++ b/common/src/air_instance.rs @@ -201,8 +201,6 @@ impl AirInstance { panic!("Stage must be 2 or higher"); } - //TODO! - Vec::new() } From 6e9640244903dc854ed9824a09ee1ceb5dc8f5d0 Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Tue, 24 Dec 2024 12:03:01 +0000 Subject: [PATCH 63/64] Distributed working, missing verify constraints and recursion --- common/src/air_instances_repository.rs | 23 +---- common/src/distribution_ctx.rs | 21 +++- common/src/proof_ctx.rs | 6 ++ common/src/utils.rs | 6 +- .../rs/src/range_check/specified_ranges.rs | 16 +++- .../lib/std/rs/src/range_check/u16air.rs | 14 ++- .../lib/std/rs/src/range_check/u8air.rs | 14 ++- pil2-components/lib/std/rs/src/std_prod.rs | 4 + pil2-components/lib/std/rs/src/std_sum.rs | 4 + proofman/src/proofman.rs | 1 + proofman/src/verify_constraints.rs | 95 +++++++++++-------- provers/starks-lib-c/src/ffi_starks.rs | 4 +- 12 files changed, 128 insertions(+), 80 deletions(-) diff --git a/common/src/air_instances_repository.rs b/common/src/air_instances_repository.rs index 53655399..0af8e749 100644 --- a/common/src/air_instances_repository.rs +++ b/common/src/air_instances_repository.rs @@ -30,7 +30,7 @@ impl AirInstancesRepository { } } - pub fn add_air_instance(&self, mut air_instance: AirInstance, global_idx: Option) { + pub fn add_air_instance(&self, mut air_instance: AirInstance, global_idx: Option) -> usize { let mut air_instances = self.air_instances.write().unwrap(); let n_air_instances = air_instances.len(); @@ -44,18 +44,7 @@ impl AirInstancesRepository { } *instance_id += 1; air_instances.push(air_instance); - } - - pub fn get_air_instances(&self) -> Vec { - let air_instances = self.air_instances.read().unwrap(); - - let mut indices = Vec::new(); - for (index, air_instance) in air_instances.iter().enumerate() { - if air_instance.prover_initialized { - indices.push(index); - } - } - indices + air_instances.len() - 1 } pub fn find_airgroup_instances(&self, airgroup_id: usize) -> Vec { @@ -63,7 +52,7 @@ impl AirInstancesRepository { let mut indices = Vec::new(); for (index, air_instance) in air_instances.iter().enumerate() { - if air_instance.airgroup_id == airgroup_id && air_instance.prover_initialized { + if air_instance.airgroup_id == airgroup_id { indices.push(index); } } @@ -75,10 +64,7 @@ impl AirInstancesRepository { let mut indices = Vec::new(); for (index, air_instance) in air_instances.iter().enumerate() { - if air_instance.airgroup_id == airgroup_id - && air_instance.air_id == air_id - && air_instance.prover_initialized - { + if air_instance.airgroup_id == airgroup_id && air_instance.air_id == air_id { indices.push(index); } } @@ -93,7 +79,6 @@ impl AirInstancesRepository { if air_instance.airgroup_id == airgroup_id && air_instance.air_id == air_id && air_instance.air_instance_id.unwrap() == air_instance_id - && air_instance.prover_initialized { return Some(index); } diff --git a/common/src/distribution_ctx.rs b/common/src/distribution_ctx.rs index cf333622..31c4ef09 100644 --- a/common/src/distribution_ctx.rs +++ b/common/src/distribution_ctx.rs @@ -107,6 +107,15 @@ impl DistributionCtx { self.instances_owner[instance_idx].0 } + #[inline] + pub fn find_instance(&self, airgroup_id: usize, air_id: usize) -> (bool, usize) { + if let Some(index) = self.instances.iter().position(|&(x, y)| x == airgroup_id && y == air_id) { + (true, index) + } else { + (false, 0) + } + } + #[inline] pub fn add_instance(&mut self, airgroup_id: usize, air_id: usize, weight: usize) -> (bool, usize) { let mut is_mine = false; @@ -197,19 +206,21 @@ impl DistributionCtx { } } + pub fn distribute_airgroupvalues(&self, _airgroupvalues: &mut [u64], _owner: usize) {} + pub fn distribute_multiplicity(&self, _multiplicity: &mut [u64], _owner: usize) { #[cfg(feature = "distributed")] { //assert that I can operate with u32 - assert!(_multiplicity.len() < std::u32::MAX as usize); + assert!(_multiplicity.len() < u32::MAX as usize); if _owner != self.rank as usize { //pack multiplicities in a sparce vector let mut packed_multiplicity = Vec::new(); - packed_multiplicity.push(0 as u32); //this will be the counter + packed_multiplicity.push(0u32); //this will be the counter for (idx, &m) in _multiplicity.iter().enumerate() { if m != 0 { - assert!(m < std::u32::MAX as u64); + assert!(m < u32::MAX as u64); packed_multiplicity.push(idx as u32); packed_multiplicity.push(m as u32); packed_multiplicity[0] += 2; @@ -238,7 +249,7 @@ impl DistributionCtx { // Ensure that each multiplicity vector can be operated with u32 let mut buff_size = 0; for multiplicity in _multiplicities.iter() { - assert!(multiplicity.len() < std::u32::MAX as usize); + assert!(multiplicity.len() < u32::MAX as usize); buff_size += multiplicity.len() + 1; } @@ -249,7 +260,7 @@ impl DistributionCtx { for (col_idx, multiplicity) in _multiplicities.iter().enumerate() { for (idx, &m) in multiplicity.iter().enumerate() { if m != 0 { - assert!(m < std::u32::MAX as u64); + assert!(m < u32::MAX as u64); packed_multiplicities[col_idx] += 1; packed_multiplicities.push(idx as u32); packed_multiplicities.push(m as u32); diff --git a/common/src/proof_ctx.rs b/common/src/proof_ctx.rs index fd0aff1f..675465f9 100644 --- a/common/src/proof_ctx.rs +++ b/common/src/proof_ctx.rs @@ -88,6 +88,12 @@ impl ProofCtx { dctx.distribute_multiplicity(multiplicity, owner); } + pub fn dctx_distribute_airgroupvalues(&self, airgroup_values: &mut [u64], instance_idx: usize) { + let dctx = self.dctx.read().unwrap(); + let owner = dctx.owner(instance_idx); + dctx.distribute_airgroupvalues(airgroup_values, owner); + } + pub fn get_proof_values_ptr(&self) -> *mut u8 { let guard = &self.proof_values.values.read().unwrap(); guard.as_ptr() as *mut u8 diff --git a/common/src/utils.rs b/common/src/utils.rs index d07fe950..637b36cf 100644 --- a/common/src/utils.rs +++ b/common/src/utils.rs @@ -3,12 +3,14 @@ use proofman_starks_lib_c::set_log_level_c; use std::sync::Arc; use p3_field::Field; -pub fn add_air_instance(air_instance: AirInstance, pctx: Arc>) { +pub fn add_air_instance(air_instance: AirInstance, pctx: Arc>) -> Option { let (is_mine, gid) = pctx.dctx.write().unwrap().add_instance(air_instance.airgroup_id, air_instance.air_id, 1); if is_mine { - pctx.air_instance_repo.add_air_instance(air_instance, Some(gid)); + return Some(pctx.air_instance_repo.add_air_instance(air_instance, Some(gid))); } + + None } pub fn initialize_logger(verbose_mode: VerboseMode) { diff --git a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs index a29f6559..7cb06f8a 100644 --- a/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs +++ b/pil2-components/lib/std/rs/src/range_check/specified_ranges.rs @@ -91,8 +91,6 @@ impl SpecifiedRanges { let mut dctx: std::sync::RwLockWriteGuard<'_, DistributionCtx> = pctx.dctx.write().unwrap(); - let (is_mine, global_idx) = dctx.add_instance(self.airgroup_id, self.air_id, 1); - let mut multiplicities = self .mul_columns .lock() @@ -105,6 +103,15 @@ impl SpecifiedRanges { _ => panic!("Multiplicities must be columns"), }) .collect::>>(); + + let (instance_found, instance_idx) = dctx.find_instance(self.airgroup_id, self.air_id); + + let (is_mine, global_idx) = if instance_found { + (dctx.is_my_instance(instance_idx), instance_idx) + } else { + dctx.add_instance(self.airgroup_id, self.air_id, 1) + }; + let owner = dctx.owner(global_idx); dctx.distribute_multiplicities(&mut multiplicities, owner); @@ -116,14 +123,13 @@ impl SpecifiedRanges { let air_instance_repo = &pctx.air_instance_repo; let instance: Vec = air_instance_repo.find_air_instances(self.airgroup_id, self.air_id); let air_instance_id = if !instance.is_empty() { - air_instance_repo.find_air_instances(self.airgroup_id, self.air_id)[0] + instance[0] } else { let num_rows = pctx.global_info.airs[self.airgroup_id][self.air_id].num_rows; let buffer_size = multiplicities.len() * num_rows; let buffer: Vec = create_buffer_fast(buffer_size); let air_instance = AirInstance::new(TraceInfo::new(self.airgroup_id, self.air_id, buffer)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)); - pctx.air_instance_repo.air_instances.read().unwrap().len() - 1 + pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)) }; let mut air_instance_rw = air_instance_repo.air_instances.write().unwrap(); let air_instance = &mut air_instance_rw[air_instance_id]; diff --git a/pil2-components/lib/std/rs/src/range_check/u16air.rs b/pil2-components/lib/std/rs/src/range_check/u16air.rs index 834f5269..72d6101e 100644 --- a/pil2-components/lib/std/rs/src/range_check/u16air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u16air.rs @@ -85,7 +85,6 @@ impl U16Air { let mut dctx: std::sync::RwLockWriteGuard<'_, proofman_common::DistributionCtx> = pctx.dctx.write().unwrap(); - let (is_mine, global_idx) = dctx.add_instance(self.airgroup_id, self.air_id, 1); let mut multiplicity = match &*self.mul_column.lock().unwrap() { HintFieldValue::Column(values) => { values.iter().map(|x| x.as_canonical_biguint().to_u64().unwrap()).collect::>() @@ -93,6 +92,14 @@ impl U16Air { _ => panic!("Multiplicities must be a column"), }; + let (instance_found, instance_idx) = dctx.find_instance(self.airgroup_id, self.air_id); + + let (is_mine, global_idx) = if instance_found { + (dctx.is_my_instance(instance_idx), instance_idx) + } else { + dctx.add_instance(self.airgroup_id, self.air_id, 1) + }; + let owner = dctx.owner(global_idx); dctx.distribute_multiplicity(&mut multiplicity, owner); @@ -100,15 +107,14 @@ impl U16Air { let air_instance_repo = &pctx.air_instance_repo; let instance: Vec = air_instance_repo.find_air_instances(self.airgroup_id, self.air_id); let air_instance_id = if !instance.is_empty() { - air_instance_repo.find_air_instances(self.airgroup_id, self.air_id)[0] + instance[0] } else { // create instance let num_rows = pctx.global_info.airs[self.airgroup_id][self.air_id].num_rows; let buffer_size = num_rows; let buffer: Vec = create_buffer_fast(buffer_size); let air_instance = AirInstance::new(TraceInfo::new(self.airgroup_id, self.air_id, buffer)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)); - pctx.air_instance_repo.air_instances.read().unwrap().len() - 1 + pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)) }; let mut air_instance_rw = air_instance_repo.air_instances.write().unwrap(); diff --git a/pil2-components/lib/std/rs/src/range_check/u8air.rs b/pil2-components/lib/std/rs/src/range_check/u8air.rs index 27f3b631..adf46d5f 100644 --- a/pil2-components/lib/std/rs/src/range_check/u8air.rs +++ b/pil2-components/lib/std/rs/src/range_check/u8air.rs @@ -84,7 +84,6 @@ impl U8Air { let mut dctx: std::sync::RwLockWriteGuard<'_, proofman_common::DistributionCtx> = pctx.dctx.write().unwrap(); - let (is_mine, global_idx) = dctx.add_instance(self.airgroup_id, self.air_id, 1); let mut multiplicity = match &*self.mul_column.lock().unwrap() { HintFieldValue::Column(values) => { values.iter().map(|x| x.as_canonical_biguint().to_u64().unwrap()).collect::>() @@ -92,6 +91,14 @@ impl U8Air { _ => panic!("Multiplicities must be a column"), }; + let (instance_found, instance_idx) = dctx.find_instance(self.airgroup_id, self.air_id); + + let (is_mine, global_idx) = if instance_found { + (dctx.is_my_instance(instance_idx), instance_idx) + } else { + dctx.add_instance(self.airgroup_id, self.air_id, 1) + }; + let owner = dctx.owner(global_idx); dctx.distribute_multiplicity(&mut multiplicity, owner); @@ -99,14 +106,13 @@ impl U8Air { let air_instance_repo = &pctx.air_instance_repo; let instance: Vec = air_instance_repo.find_air_instances(self.airgroup_id, self.air_id); let air_instance_id = if !instance.is_empty() { - air_instance_repo.find_air_instances(self.airgroup_id, self.air_id)[0] + instance[0] } else { let num_rows = pctx.global_info.airs[self.airgroup_id][self.air_id].num_rows; let buffer_size = num_rows; let buffer: Vec = create_buffer_fast(buffer_size); let air_instance = AirInstance::new(TraceInfo::new(self.airgroup_id, self.air_id, buffer)); - pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)); - pctx.air_instance_repo.air_instances.read().unwrap().len() - 1 + pctx.air_instance_repo.add_air_instance(air_instance, Some(global_idx)) }; let mut air_instance_rw = air_instance_repo.air_instances.write().unwrap(); diff --git a/pil2-components/lib/std/rs/src/std_prod.rs b/pil2-components/lib/std/rs/src/std_prod.rs index 87082fe6..20174a9a 100644 --- a/pil2-components/lib/std/rs/src/std_prod.rs +++ b/pil2-components/lib/std/rs/src/std_prod.rs @@ -256,6 +256,10 @@ impl WitnessComponent for StdProd { let air_instances_vec = &mut pctx.air_instance_repo.air_instances.write().unwrap(); let air_instance = &mut air_instances_vec[air_instance_id]; + if !air_instance.prover_initialized { + continue; + } + // Get the air associated with the air_instance let airgroup_id = air_instance.airgroup_id; let air_id = air_instance.air_id; diff --git a/pil2-components/lib/std/rs/src/std_sum.rs b/pil2-components/lib/std/rs/src/std_sum.rs index 3a61a3f5..f33ef5a4 100644 --- a/pil2-components/lib/std/rs/src/std_sum.rs +++ b/pil2-components/lib/std/rs/src/std_sum.rs @@ -255,6 +255,10 @@ impl WitnessComponent for StdSum { let air_instance = &mut air_instaces_vec[air_instance_id]; + if !air_instance.prover_initialized { + continue; + } + // Get the air associated with the air_instance let airgroup_id = air_instance.airgroup_id; let air_id = air_instance.air_id; diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index 11f8e5cb..fe214f71 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -623,6 +623,7 @@ impl ProofMan { let mut air_info = HashMap::new(); let mut air_instances = HashMap::new(); + for (airgroup_id, air_id) in &dctx.instances { let air_name = pctx.global_info.airs[*airgroup_id][*air_id].clone().name; let air_group_name = pctx.global_info.air_groups[*airgroup_id].clone(); diff --git a/proofman/src/verify_constraints.rs b/proofman/src/verify_constraints.rs index dc8d481e..9303850a 100644 --- a/proofman/src/verify_constraints.rs +++ b/proofman/src/verify_constraints.rs @@ -15,13 +15,12 @@ use colored::*; pub fn verify_global_constraints_proof( pctx: Arc>, sctx: Arc, + mut airgroupvalues: Vec>, ) -> Vec { const MY_NAME: &str = "GlCstVfy"; log::info!("{}: --> Checking global constraints", MY_NAME); - let mut airgroupvalues = aggregate_airgroupvals(pctx.clone()); - let mut airgroup_values_ptrs: Vec<*mut F> = airgroupvalues .iter_mut() // Iterate mutably over the inner Vecs .map(|inner_vec| inner_vec.as_mut_ptr()) // Get a raw pointer to each inner Vec @@ -163,51 +162,69 @@ pub fn verify_constraints_proof( } } - let global_constraints = verify_global_constraints_proof(pctx.clone(), sctx.clone()); - let mut valid_global_constraints = true; + let dctx = pctx.dctx.read().unwrap(); - let global_constraints_lines = get_global_constraints_lines_str(sctx.clone()); + let airgroupvalues = aggregate_airgroupvals(pctx.clone()); - for idx in 0..global_constraints.len() { - let constraint = global_constraints[idx]; - if constraint.skip { - continue; - } - let line_str = &global_constraints_lines[idx]; + if dctx.rank == 0 { + // TODO: Distribute airgroupvalues - let valid = if !constraint.valid { "is invalid".bright_red() } else { "is valid".bright_green() }; - if constraint.valid { - log::debug!("{}: · Global Constraint #{} {} -> {}", MY_NAME, constraint.id, valid, line_str); - } else { - log::info!("{}: · Global Constraint #{} {} -> {}", MY_NAME, constraint.id, valid, line_str); - } - if !constraint.valid { - valid_global_constraints = false; - if constraint.dim == 1 { - log::info!("{}: ··· \u{2717} Failed with value: {}", MY_NAME, constraint.value[0]); + let global_constraints = verify_global_constraints_proof(pctx.clone(), sctx.clone(), airgroupvalues); + let mut valid_global_constraints = true; + + let global_constraints_lines = get_global_constraints_lines_str(sctx.clone()); + + for idx in 0..global_constraints.len() { + let constraint = global_constraints[idx]; + if constraint.skip { + continue; + } + let line_str = &global_constraints_lines[idx]; + + let valid = if !constraint.valid { "is invalid".bright_red() } else { "is valid".bright_green() }; + if constraint.valid { + log::debug!("{}: · Global Constraint #{} {} -> {}", MY_NAME, constraint.id, valid, line_str); } else { - log::info!( - "{}: ··· \u{2717} Failed with value: [{}, {}, {}]", - MY_NAME, - constraint.value[0], - constraint.value[1], - constraint.value[2] - ); + log::info!("{}: · Global Constraint #{} {} -> {}", MY_NAME, constraint.id, valid, line_str); + } + if !constraint.valid { + valid_global_constraints = false; + if constraint.dim == 1 { + log::info!("{}: ··· \u{2717} Failed with value: {}", MY_NAME, constraint.value[0]); + } else { + log::info!( + "{}: ··· \u{2717} Failed with value: [{}, {}, {}]", + MY_NAME, + constraint.value[0], + constraint.value[1], + constraint.value[2] + ); + } } } - } - if valid_global_constraints { - log::info!( - "{}: ··· {}", - MY_NAME, - "\u{2713} All global constraints were successfully verified".bright_green().bold() - ); - } else { - log::info!("{}: ··· {}", MY_NAME, "\u{2717} Not all global constraints were verified".bright_red().bold()); - } + if valid_global_constraints { + log::info!( + "{}: ··· {}", + MY_NAME, + "\u{2713} All global constraints were successfully verified".bright_green().bold() + ); + } else { + log::info!("{}: ··· {}", MY_NAME, "\u{2717} Not all global constraints were verified".bright_red().bold()); + } - if valid_constraints && valid_global_constraints { + if valid_constraints && valid_global_constraints { + log::info!("{}: ··· {}", MY_NAME, "\u{2713} All constraints were verified".bright_green().bold()); + Ok(()) + } else { + log::info!("{}: ··· {}", MY_NAME, "\u{2717} Not all constraints were verified.".bright_red().bold()); + Err(Box::new(std::io::Error::new( + // <-- Return a boxed error + std::io::ErrorKind::Other, + format!("{}: Not all constraints were verified.", MY_NAME), + ))) + } + } else if valid_constraints { log::info!("{}: ··· {}", MY_NAME, "\u{2713} All constraints were verified".bright_green().bold()); Ok(()) } else { diff --git a/provers/starks-lib-c/src/ffi_starks.rs b/provers/starks-lib-c/src/ffi_starks.rs index 4c604cf6..1239e84a 100644 --- a/provers/starks-lib-c/src/ffi_starks.rs +++ b/provers/starks-lib-c/src/ffi_starks.rs @@ -1762,9 +1762,9 @@ pub fn join_zkin_final_c( } #[cfg(feature = "no_lib_link")] -pub fn get_serialized_proof_c(_zkin: *mut c_void, _size: *mut u64) -> *mut std::os::raw::c_char { +pub fn get_serialized_proof_c(_zkin: *mut c_void) -> (*mut std::os::raw::c_char, u64) { trace!("{}: ··· {}", "ffi ", "get_serialized_proof: This is a mock call because there is no linked library"); - std::ptr::null_mut() + (std::ptr::null_mut(), 0) } #[cfg(feature = "no_lib_link")] From fa968a230172d537d081fd93e44a7f4feccbb8bc Mon Sep 17 00:00:00 2001 From: RogerTaule Date: Tue, 24 Dec 2024 12:52:00 +0000 Subject: [PATCH 64/64] Improving debugging --- cli/src/commands/prove.rs | 42 ++------ cli/src/commands/verify_constraints.rs | 48 +++------ common/src/proof_ctx.rs | 31 +++++- common/src/std_mode.rs | 8 +- common/src/utils.rs | 128 ++++++++++++++++++++++- examples/fibonacci-square/src/debug.json | 3 + pil2-components/lib/std/rs/src/std.rs | 2 +- proofman/src/proofman.rs | 14 ++- proofman/src/verify_constraints.rs | 55 ++++++---- provers/stark/src/stark_prover.rs | 18 +++- 10 files changed, 258 insertions(+), 91 deletions(-) create mode 100644 examples/fibonacci-square/src/debug.json diff --git a/cli/src/commands/prove.rs b/cli/src/commands/prove.rs index d18fac36..a2e368b2 100644 --- a/cli/src/commands/prove.rs +++ b/cli/src/commands/prove.rs @@ -1,6 +1,6 @@ // extern crate env_logger; use clap::Parser; -use proofman_common::{initialize_logger, StdMode, DEFAULT_PRINT_VALS}; +use proofman_common::{initialize_logger, json_to_debug_instances_map, DebugInfo}; use std::path::PathBuf; use colored::Colorize; use crate::commands::field::Field; @@ -51,17 +51,8 @@ pub struct ProveCmd { #[arg(short, long, action = clap::ArgAction::Count, help = "Increase verbosity level")] pub verbose: u8, // Using u8 to hold the number of `-v` - #[clap(short = 'd', long, action = clap::ArgAction::Count)] - pub debug: u8, - - #[clap(long)] - pub print: Option, - - #[clap(long, action = clap::ArgAction::SetTrue)] - pub print_to_file: bool, - - #[clap(long, action = clap::ArgAction::Append)] - pub opids: Option>, + #[clap(short = 'd', long)] + pub debug: Option, } impl ProveCmd { @@ -77,25 +68,14 @@ impl ProveCmd { fs::create_dir_all(self.output_dir.join("proofs")).expect("Failed to create the proofs directory"); - let std_mode: StdMode = if self.debug == 1 { - let op_ids = self.opids.as_ref().map_or_else( - Vec::new, // Provide an empty Vec if self.opids is None - |ids| { - ids.iter() - .flat_map(|id| { - id.split(',') - .map(|s| s.trim()) // Trim any surrounding whitespace - .filter_map(|s| s.parse::().ok()) // Try parsing as u64 - }) - .collect::>() // Collect the entire iterator into a Vec - }, - ); - - let n_values = self.print.unwrap_or(DEFAULT_PRINT_VALS); - let print_to_file = self.print_to_file; - StdMode::new(proofman_common::ModeName::Debug, op_ids, n_values, print_to_file) + let debug_info = if let Some(debug_value) = &self.debug { + if debug_value.is_empty() || debug_value == "false" { + DebugInfo::new() + } else { + json_to_debug_instances_map(debug_value.clone()) + } } else { - self.debug.into() + DebugInfo::new() }; match self.field { @@ -105,7 +85,7 @@ impl ProveCmd { self.public_inputs.clone(), self.proving_key.clone(), self.output_dir.clone(), - ProofOptions::new(false, self.verbose.into(), std_mode, self.aggregation, self.final_snark), + ProofOptions::new(false, self.verbose.into(), self.aggregation, self.final_snark, debug_info), )?, }; diff --git a/cli/src/commands/verify_constraints.rs b/cli/src/commands/verify_constraints.rs index 75ae8390..14cadee1 100644 --- a/cli/src/commands/verify_constraints.rs +++ b/cli/src/commands/verify_constraints.rs @@ -1,6 +1,6 @@ // extern crate env_logger; use clap::Parser; -use proofman_common::{initialize_logger, StdMode, DEFAULT_PRINT_VALS}; +use proofman_common::{initialize_logger, json_to_debug_instances_map, DebugInfo}; use std::path::PathBuf; use colored::Colorize; use crate::commands::field::Field; @@ -39,17 +39,8 @@ pub struct VerifyConstraintsCmd { #[arg(short, long, action = clap::ArgAction::Count, help = "Increase verbosity level")] pub verbose: u8, // Using u8 to hold the number of `-v` - #[clap(short = 'd', long, action = clap::ArgAction::Count)] - pub debug: u8, - - #[clap(long)] - pub print: Option, - - #[clap(long, action = clap::ArgAction::SetTrue)] - pub print_to_file: bool, - - #[clap(long, action = clap::ArgAction::Append)] - pub opids: Option>, + #[clap(short = 'd', long)] + pub debug: Option, } impl VerifyConstraintsCmd { @@ -59,25 +50,14 @@ impl VerifyConstraintsCmd { initialize_logger(self.verbose.into()); - let std_mode: StdMode = if self.debug == 1 { - let op_ids = self.opids.as_ref().map_or_else( - Vec::new, // Provide an empty Vec if self.opids is None - |ids| { - ids.iter() - .flat_map(|id| { - id.split(',') - .map(|s| s.trim()) // Trim any surrounding whitespace - .filter_map(|s| s.parse::().ok()) // Try parsing as u64 - }) - .collect::>() // Collect the entire iterator into a Vec - }, - ); - - let n_values = self.print.unwrap_or(DEFAULT_PRINT_VALS); - let print_to_file = self.print_to_file; - StdMode::new(proofman_common::ModeName::Debug, op_ids, n_values, print_to_file) + let debug_info = if let Some(debug_value) = &self.debug { + if debug_value.is_empty() || debug_value == "false" { + DebugInfo::new() + } else { + json_to_debug_instances_map(debug_value.clone()) + } } else { - self.debug.into() + DebugInfo::new() }; match self.field { @@ -87,7 +67,13 @@ impl VerifyConstraintsCmd { self.public_inputs.clone(), self.proving_key.clone(), PathBuf::new(), - ProofOptions::new(true, self.verbose.into(), std_mode, false, false), + ProofOptions::new( + true, + self.verbose.into(), + false, + false, + debug_info + ), )?, }; diff --git a/common/src/proof_ctx.rs b/common/src/proof_ctx.rs index 675465f9..54e45ffd 100644 --- a/common/src/proof_ctx.rs +++ b/common/src/proof_ctx.rs @@ -1,9 +1,9 @@ -use std::sync::RwLock; +use std::{collections::HashMap, sync::RwLock}; use std::path::PathBuf; use p3_field::Field; -use crate::{distribution_ctx::DistributionCtx, AirInstancesRepository, GlobalInfo, StdMode, VerboseMode}; +use crate::{ModeName, distribution_ctx::DistributionCtx, AirInstancesRepository, GlobalInfo, StdMode, VerboseMode}; pub struct Values { pub values: RwLock>, @@ -21,24 +21,45 @@ impl Default for Values { } } +pub type AirGroupMap = HashMap; +pub type AirIdMap = HashMap; +pub type InstanceMap = HashMap>; + #[derive(Clone)] pub struct ProofOptions { pub verify_constraints: bool, pub verbose_mode: VerboseMode, - pub std_mode: StdMode, pub aggregation: bool, pub final_snark: bool, + pub debug_info: DebugInfo, +} + +#[derive(Clone)] +pub struct DebugInfo { + pub debug_instances: AirGroupMap, + pub debug_global_instances: Vec, + pub std_mode: StdMode, +} + +impl DebugInfo { + pub fn new() -> Self { + Self { + std_mode: StdMode::new(ModeName::Standard, Vec::new(), 0, false), + debug_instances: HashMap::new(), + debug_global_instances: Vec::new(), + } + } } impl ProofOptions { pub fn new( verify_constraints: bool, verbose_mode: VerboseMode, - std_mode: StdMode, aggregation: bool, final_snark: bool, + debug_info: DebugInfo, ) -> Self { - Self { verify_constraints, verbose_mode, std_mode, aggregation, final_snark } + Self { verify_constraints, verbose_mode, aggregation, final_snark, debug_info } } } diff --git a/common/src/std_mode.rs b/common/src/std_mode.rs index 0022e83f..e0f71829 100644 --- a/common/src/std_mode.rs +++ b/common/src/std_mode.rs @@ -14,7 +14,7 @@ pub struct StdMode { impl StdMode { pub const fn new(name: ModeName, opids: Vec, n_vals: usize, print_to_file: bool) -> Self { - if n_vals == 0 { + if name.as_usize() != ModeName::Standard.as_usize() && n_vals == 0 { panic!("n_vals must be greater than 0"); } @@ -65,3 +65,9 @@ impl PartialEq for usize { *self == (*other as usize) } } + +impl ModeName { + const fn as_usize(&self) -> usize { + *self as usize + } +} diff --git a/common/src/utils.rs b/common/src/utils.rs index 637b36cf..d9f60f74 100644 --- a/common/src/utils.rs +++ b/common/src/utils.rs @@ -1,7 +1,13 @@ -use crate::{AirInstance, ProofCtx, VerboseMode}; +use crate::{ + AirGroupMap, AirIdMap, AirInstance, DebugInfo, InstanceMap, ModeName, ProofCtx, ProofOptions, StdMode, VerboseMode, + DEFAULT_PRINT_VALS, +}; use proofman_starks_lib_c::set_log_level_c; use std::sync::Arc; +use std::collections::HashMap; use p3_field::Field; +use serde::Deserialize; +use std::fs; pub fn add_air_instance(air_instance: AirInstance, pctx: Arc>) -> Option { let (is_mine, gid) = pctx.dctx.write().unwrap().add_instance(air_instance.airgroup_id, air_instance.air_id, 1); @@ -37,3 +43,123 @@ pub fn format_bytes(mut num_bytes: f64) -> String { format!("{:.2} {}", num_bytes, units[unit_index]) } + +pub fn skip_prover_instance( + options: ProofOptions, + airgroup_id: usize, + air_id: usize, + instance_id: usize, +) -> (bool, Vec) { + if options.debug_info.debug_instances.is_empty() { + return (false, Vec::new()); + } else if let Some(airgroup_id_map) = options.debug_info.debug_instances.get(&airgroup_id) { + if airgroup_id_map.is_empty() { + return (false, Vec::new()); + } else if let Some(air_id_map) = airgroup_id_map.get(&air_id) { + if air_id_map.is_empty() { + return (false, Vec::new()); + } else if let Some(instance_id_map) = air_id_map.get(&instance_id) { + return (false, instance_id_map.clone()); + } + } + } + + (true, Vec::new()) +} + +#[derive(Default, Deserialize)] +struct StdDebugMode { + #[serde(default)] + opids: Option>, + #[serde(default)] + n_print: Option, + #[serde(default)] + print_to_file: bool, +} + +#[derive(Deserialize)] +struct DebugJson { + #[serde(default)] + constraints: Option>, + #[serde(default)] + global_constraints: Option>, + #[serde(default)] + std_mode: Option, +} + +#[derive(Deserialize)] +struct AirGroupJson { + #[serde(default)] + airgroup_id: Option, + #[serde(default)] + air_ids: Option>, +} + +#[derive(Deserialize)] +struct AirIdJson { + #[serde(default)] + air_id: Option, + #[serde(default)] + instances_ids: Option>, +} + +#[derive(Deserialize)] +struct InstanceJson { + #[serde(default)] + instance_id: Option, + #[serde(default)] + constraints: Option>, +} + +pub fn json_to_debug_instances_map(json_path: String) -> DebugInfo { + // Read the file contents + let debug_json = fs::read_to_string(&json_path).unwrap_or_else(|_| panic!("Failed to read file {}", json_path)); + + // Deserialize the JSON into the `DebugJson` struct + let json: DebugJson = serde_json::from_str(&debug_json) + .unwrap_or_else(|err| panic!("Failed to parse JSON file: {}: {}", json_path, err)); + + // Initialize the airgroup map + let mut airgroup_map: AirGroupMap = HashMap::new(); + + // Populate the airgroup map using the deserialized data + if let Some(constraints) = json.constraints { + for airgroup in constraints { + let mut air_id_map: AirIdMap = HashMap::new(); + + if let Some(air_ids) = airgroup.air_ids { + for air_id in air_ids { + let mut instance_map: InstanceMap = HashMap::new(); + + if let Some(instances) = air_id.instances_ids { + for instance in instances { + let instance_constraints = instance.constraints.unwrap_or_default(); + instance_map.insert(instance.instance_id.unwrap_or_default(), instance_constraints); + } + } + + air_id_map.insert(air_id.air_id.unwrap_or_default(), instance_map); + } + } + + airgroup_map.insert(airgroup.airgroup_id.unwrap_or_default(), air_id_map); + } + } + + // Default global_constraints to an empty Vec if None + let global_constraints = json.global_constraints.unwrap_or_default(); + + let std_mode = if !airgroup_map.is_empty() { + StdMode::new(ModeName::Standard, Vec::new(), 0, false) + } else { + let mode = json.std_mode.unwrap_or_default(); + StdMode::new( + ModeName::Debug, + mode.opids.unwrap_or_default(), + mode.n_print.unwrap_or(DEFAULT_PRINT_VALS), + mode.print_to_file, + ) + }; + + DebugInfo { debug_instances: airgroup_map.clone(), debug_global_instances: global_constraints, std_mode } +} diff --git a/examples/fibonacci-square/src/debug.json b/examples/fibonacci-square/src/debug.json new file mode 100644 index 00000000..446065a2 --- /dev/null +++ b/examples/fibonacci-square/src/debug.json @@ -0,0 +1,3 @@ +{ + "global_constraints": [0] +} \ No newline at end of file diff --git a/pil2-components/lib/std/rs/src/std.rs b/pil2-components/lib/std/rs/src/std.rs index 45b5fc03..ad5f3557 100644 --- a/pil2-components/lib/std/rs/src/std.rs +++ b/pil2-components/lib/std/rs/src/std.rs @@ -20,7 +20,7 @@ impl Std { const MY_NAME: &'static str = "STD "; pub fn new(wcm: Arc>) -> Arc { - let std_mode = wcm.get_pctx().options.std_mode.clone(); + let std_mode = wcm.get_pctx().options.debug_info.std_mode.clone(); log::info!("{}: ··· The PIL2 STD library has been initialized on mode {}", Self::MY_NAME, std_mode.name); // Instantiate the STD components diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index fe214f71..f8870ff5 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -19,7 +19,9 @@ use crate::{ generate_vadcop_recursive2_proof, generate_recursivef_proof, generate_fflonk_snark_proof, }; -use proofman_common::{format_bytes, ProofCtx, ProofOptions, ProofType, Prover, SetupCtx, SetupsVadcop}; +use proofman_common::{ + format_bytes, skip_prover_instance, ProofCtx, ProofOptions, ProofType, Prover, SetupCtx, SetupsVadcop, +}; use std::os::raw::c_void; @@ -255,12 +257,22 @@ impl ProofMan { for air_instance in pctx.air_instance_repo.air_instances.read().unwrap().iter() { let air_name = &pctx.global_info.airs[air_instance.airgroup_id][air_instance.air_id].name; log::debug!("{}: Initializing prover for air instance {}", Self::MY_NAME, air_name); + let (skip, constraints_skip) = skip_prover_instance( + pctx.options.clone(), + air_instance.airgroup_id, + air_instance.air_id, + air_instance.air_instance_id.unwrap(), + ); + if skip { + continue; + }; let prover = Box::new(StarkProver::new( sctx.clone(), air_instance.airgroup_id, air_instance.air_id, air_instance.air_instance_id.unwrap(), air_instance.idx.unwrap(), + constraints_skip, )); provers.push(prover); diff --git a/proofman/src/verify_constraints.rs b/proofman/src/verify_constraints.rs index 9303850a..af21811a 100644 --- a/proofman/src/verify_constraints.rs +++ b/proofman/src/verify_constraints.rs @@ -29,6 +29,12 @@ pub fn verify_global_constraints_proof( let n_global_constraints = get_n_global_constraints_c(sctx.get_global_bin()); let mut global_constraints_info = vec![GlobalConstraintInfo::default(); n_global_constraints as usize]; + if !pctx.options.debug_info.debug_global_instances.is_empty() { + global_constraints_info.iter_mut().for_each(|constraint| constraint.skip = true); + for constraint_id in &pctx.options.debug_info.debug_global_instances { + global_constraints_info[*constraint_id].skip = false; + } + } verify_global_constraints_c( sctx.get_global_info_file().as_str(), sctx.get_global_bin(), @@ -69,16 +75,16 @@ pub fn verify_constraints_proof( let constraints_lines = get_constraints_lines_str(sctx.clone(), airgroup_id, air_id); let mut valid_constraints_prover = true; - log::info!( - "{}: ► Instance #{} of {} (Airgroup {} - Air {})", - MY_NAME, - air_instance_id, - air_name, - airgroup_id, - air_id, - ); + log::info!("{}: ► Instance #{} of {} [{}:{}]", MY_NAME, air_instance_id, air_name, airgroup_id, air_id,); for constraint in &constraints[idx] { if constraint.skip { + log::debug!( + "{}: · Skipping Constraint #{} (stage {}) -> {}", + MY_NAME, + constraint.id, + constraint.stage, + constraints_lines[constraint.id as usize] + ); continue; } let valid = if constraint.n_rows > 0 { @@ -166,7 +172,7 @@ pub fn verify_constraints_proof( let airgroupvalues = aggregate_airgroupvals(pctx.clone()); - if dctx.rank == 0 { + if dctx.rank == 0 && pctx.options.debug_info.debug_instances.is_empty() { // TODO: Distribute airgroupvalues let global_constraints = verify_global_constraints_proof(pctx.clone(), sctx.clone(), airgroupvalues); @@ -176,10 +182,12 @@ pub fn verify_constraints_proof( for idx in 0..global_constraints.len() { let constraint = global_constraints[idx]; + let line_str = &global_constraints_lines[idx]; + if constraint.skip { + log::debug!("{}: · Skipping Global Constraint #{} -> {}", MY_NAME, idx, line_str,); continue; } - let line_str = &global_constraints_lines[idx]; let valid = if !constraint.valid { "is invalid".bright_red() } else { "is valid".bright_green() }; if constraint.valid { @@ -224,15 +232,24 @@ pub fn verify_constraints_proof( format!("{}: Not all constraints were verified.", MY_NAME), ))) } - } else if valid_constraints { - log::info!("{}: ··· {}", MY_NAME, "\u{2713} All constraints were verified".bright_green().bold()); - Ok(()) } else { - log::info!("{}: ··· {}", MY_NAME, "\u{2717} Not all constraints were verified.".bright_red().bold()); - Err(Box::new(std::io::Error::new( - // <-- Return a boxed error - std::io::ErrorKind::Other, - format!("{}: Not all constraints were verified.", MY_NAME), - ))) + if !pctx.options.debug_info.debug_instances.is_empty() { + log::info!( + "{}: ··· {}", + MY_NAME, + "\u{2713} Skipping global constraints verification".bright_yellow().bold() + ); + } + if valid_constraints { + log::info!("{}: ··· {}", MY_NAME, "\u{2713} All constraints were verified".bright_green().bold()); + Ok(()) + } else { + log::info!("{}: ··· {}", MY_NAME, "\u{2717} Not all constraints were verified.".bright_red().bold()); + Err(Box::new(std::io::Error::new( + // <-- Return a boxed error + std::io::ErrorKind::Other, + format!("{}: Not all constraints were verified.", MY_NAME), + ))) + } } } diff --git a/provers/stark/src/stark_prover.rs b/provers/stark/src/stark_prover.rs index a20cc6bf..158a891c 100644 --- a/provers/stark/src/stark_prover.rs +++ b/provers/stark/src/stark_prover.rs @@ -33,6 +33,7 @@ pub struct StarkProver { merkle_tree_arity: u64, merkle_tree_custom: bool, p_proof: *mut c_void, + constraints_to_check: Vec, _marker: PhantomData, // Add PhantomData to track the type F } @@ -42,7 +43,14 @@ impl StarkProver { const HASH_SIZE: usize = 4; const FIELD_EXTENSION: usize = 3; - pub fn new(sctx: Arc, airgroup_id: usize, air_id: usize, instance_id: usize, prover_idx: usize) -> Self { + pub fn new( + sctx: Arc, + airgroup_id: usize, + air_id: usize, + instance_id: usize, + prover_idx: usize, + constraints_to_check: Vec, + ) -> Self { let setup = sctx.get_setup(airgroup_id, air_id); let p_stark = starks_new_c((&setup.p_setup).into(), setup.get_const_tree_ptr()); @@ -72,6 +80,7 @@ impl StarkProver { n_field_elements, merkle_tree_arity, merkle_tree_custom, + constraints_to_check, _marker: PhantomData, } } @@ -157,6 +166,13 @@ impl Prover for StarkProver { let mut constraints_info = vec![ConstraintInfo::default(); n_constraints as usize]; + if !self.constraints_to_check.is_empty() { + constraints_info.iter_mut().for_each(|constraint| constraint.skip = true); + for constraint_id in &self.constraints_to_check { + constraints_info[*constraint_id].skip = false; + } + } + verify_constraints_c(p_setup, (&steps_params).into(), constraints_info.as_mut_ptr() as *mut c_void); constraints_info