Skip to content

Commit

Permalink
Fixing cargo clippy, cargo fmt, cargo check
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerTaule committed Sep 6, 2024
1 parent 23329ee commit d66aee2
Show file tree
Hide file tree
Showing 16 changed files with 366 additions and 252 deletions.
47 changes: 8 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ members = [
# the box with `cargo check --workspace` or CI will
# break and dev experience will be bad since repo
# won't build with a fresh clone
"examples/fibonacci-square",
#"examples/fibonacci-square",
]

resolver = "2"
Expand Down
8 changes: 7 additions & 1 deletion cli/src/commands/verify_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ impl VerifyConstraintsCmd {

type GL = Goldilocks;

let debug_mode = if self.extended_im_pols { 3 } else if self.extended { 2 } else { 1 };
let debug_mode = if self.extended_im_pols {
3
} else if self.extended {
2
} else {
1
};
let _valid_constraints = match self.field {
Field::Goldilocks => ProofMan::<GL>::generate_proof(
self.witness_lib.clone(),
Expand Down
14 changes: 11 additions & 3 deletions common/src/air_instance_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@ pub struct AirInstanceCtx<F> {

impl<F> AirInstanceCtx<F> {
pub fn new(air_group_id: usize, air_id: usize, prover_idx: usize, buffer: Option<Vec<F>>) -> Self {
AirInstanceCtx { air_group_id, air_id, prover_idx, buffer, params: None, commits_calculated: Vec::new(), subproofvalue_calculated: Vec::new() }
AirInstanceCtx {
air_group_id,
air_id,
prover_idx,
buffer,
params: None,
commits_calculated: Vec::new(),
subproofvalue_calculated: Vec::new(),
}
}

pub fn get_buffer_ptr(&mut self) -> *mut u8 {
println!("Air_group_id: {}, Air_id: {}", self.air_group_id, self.air_id);
if self.buffer.is_some() {
self.buffer.as_mut().unwrap().as_mut_ptr() as *mut u8
} else {
self.buffer.as_mut().unwrap().as_mut_ptr() as *mut u8
} else {
panic!("Buffer not initialized");
}
}
Expand Down
7 changes: 4 additions & 3 deletions common/src/global_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ impl GlobalInfo {
}

pub fn get_air_group_id(&self, air_group_name: &str) -> usize {
self.subproofs.iter().position(|name| name == air_group_name).unwrap_or_else(|| {
panic!("Air group '{}' not found", air_group_name)
})
self.subproofs
.iter()
.position(|name| name == air_group_name)
.unwrap_or_else(|| panic!("Air group '{}' not found", air_group_name))
}

pub fn get_air_name(&self, air_group_id: usize, air_id: usize) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ pub use prover::*;
pub use extended_field::*;
pub use global_info::*;
pub use setup::*;
pub use setup_ctx::*;
pub use setup_ctx::*;
1 change: 0 additions & 1 deletion common/src/proof_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use log::info;

use crate::{AirInstanceCtx, WitnessPilout};


#[allow(dead_code)]
pub struct ProofCtx<F> {
pub public_inputs: Vec<u8>,
Expand Down
19 changes: 9 additions & 10 deletions common/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,23 @@ pub struct ProverInfo {
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct ConstraintRowInfo {
pub row: u64,
pub dim: u64,
pub value: [u64; 3usize],
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: *const c_char,
pub n_rows: u64,
pub rows: [ConstraintRowInfo; 10usize],
pub id: u64,
pub stage: u64,
pub im_pol: bool,
pub line: *const c_char,
pub n_rows: u64,
pub rows: [ConstraintRowInfo; 10usize],
}

#[derive(Debug, Clone, Copy)]

#[repr(C)]
pub struct ConstraintsResults {
pub n_constraints: u64,
Expand Down
2 changes: 1 addition & 1 deletion common/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Setup {
let p_stark_info = stark_info_new_c(stark_info_path.as_str());
let p_expressions_bin = expressions_bin_new_c(expressions_bin_path.as_str());
let p_const_pols = const_pols_new_c(const_pols_path.as_str(), p_stark_info);

let p_setup = setup_ctx_new_c(p_stark_info, p_expressions_bin, p_const_pols);

Self { air_id, air_group_id, p_setup, p_stark_info }
Expand Down
44 changes: 22 additions & 22 deletions common/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub trait Trace: Send {

#[macro_export]
macro_rules! trace {
($row_struct_name:ident, $trace_struct_name:ident<$generic:ident> {
($row_struct_name:ident, $trace_struct_name:ident<$generic:ident> {
$( $field_name:ident : $field_type:ty ),* $(,)?
}) => {
// Define the row structure (Main0RowTrace)
Expand All @@ -15,7 +15,7 @@ macro_rules! trace {
$( pub $field_name: $field_type ),*
}


impl<$generic: Copy> $row_struct_name<$generic> {
// The size of each row in terms of the number of fields
pub const ROW_SIZE: usize = 0 $(+ trace!(@count_elements $field_type))*;
Expand Down Expand Up @@ -170,7 +170,7 @@ macro_rules! trace {
}
}
result

} else {
0
}
Expand All @@ -185,25 +185,25 @@ mod tests {
const OFFSET: usize = 1;
let num_rows = 8;

trace!(TraceRow, MyTrace<F> { a: F, b:[F; 2], c: [F; 2]});

assert_eq!( TraceRow::<usize>::ROW_SIZE, 4);
// let mut buffer = vec![0usize; num_rows * TraceRow::<usize>::ROW_SIZE + OFFSET];
// let trace = MyTrace::map_buffer(&mut buffer, num_rows, OFFSET);
// let mut trace = trace.unwrap();

// // Set values
// for i in 0..num_rows {
// trace[i].a = i;
// trace[i].b = i * 10;
// }

// // Check values
// for i in 0..num_rows {
// assert_eq!(trace[i].a, i);
// assert_eq!(trace[i].b, i * 10);
// }
trace!(TraceRow, MyTrace<F> { a: F, b:F});

assert_eq!(TraceRow::<usize>::ROW_SIZE, 2);

let mut buffer = vec![0usize; num_rows * TraceRow::<usize>::ROW_SIZE + OFFSET];
let trace = MyTrace::map_buffer(&mut buffer, num_rows, OFFSET);
let mut trace = trace.unwrap();

// Set values
for i in 0..num_rows {
trace[i].a = i;
trace[i].b = i * 10;
}

// Check values
for i in 0..num_rows {
assert_eq!(trace[i].a, i);
assert_eq!(trace[i].b, i * 10);
}
}

#[test]
Expand Down
39 changes: 23 additions & 16 deletions hints/src/hints.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use proofman_starks_lib_c::{get_hint_field_c, get_hint_ids_by_name_c, print_expression_c, print_by_name_c, set_hint_field_c};
use proofman_starks_lib_c::{
get_hint_field_c, get_hint_ids_by_name_c, print_expression_c, print_by_name_c, set_hint_field_c,
};

use p3_field::Field;
use proofman_common::{ExtensionField, AirInstanceCtx, SetupCtx};
Expand Down Expand Up @@ -241,13 +243,13 @@ pub fn get_hint_field<F: Clone + Copy>(
inverse: bool,
print_expression: bool,
) -> HintFieldValue<F> {

let params = air_instance_ctx.params.unwrap();

let setup = setup_ctx.get_setup(air_instance_ctx.air_group_id, air_instance_ctx.air_id).expect("REASON");

let raw_ptr = get_hint_field_c(setup.p_setup, params, hint_id as u64, hint_field_name, dest, inverse, print_expression);

let raw_ptr =
get_hint_field_c(setup.p_setup, params, hint_id as u64, hint_field_name, dest, inverse, print_expression);

let hint_field = unsafe { Box::from_raw(raw_ptr as *mut HintFieldInfo<F>) };

HintCol::from_hint_field(hint_field.as_ref())
Expand All @@ -262,11 +264,18 @@ pub fn get_hint_field_constant<F: Clone + Copy>(
dest: bool,
print_expression: bool,
) -> HintFieldValue<F> {

let setup = setup_ctx.get_setup(air_group_id, air_id).expect("REASON");

let raw_ptr = get_hint_field_c(setup.p_setup, std::ptr::null_mut(), hint_id as u64, hint_field_name, dest, false, print_expression);

let raw_ptr = get_hint_field_c(
setup.p_setup,
std::ptr::null_mut(),
hint_id as u64,
hint_field_name,
dest,
false,
print_expression,
);

let hint_field = unsafe { Box::from_raw(raw_ptr as *mut HintFieldInfo<F>) };

HintCol::from_hint_field(hint_field.as_ref())
Expand All @@ -279,7 +288,6 @@ pub fn set_hint_field<F: Copy + core::fmt::Debug>(
hint_field_name: &str,
values: &HintFieldValue<F>,
) {

let params = air_instance_ctx.params.unwrap();

let setup = setup_ctx.get_setup(air_instance_ctx.air_group_id, air_instance_ctx.air_id).expect("REASON");
Expand Down Expand Up @@ -320,7 +328,7 @@ pub fn set_hint_field_val<F: Clone + Copy + std::fmt::Debug>(
};

let values_ptr = value_array.as_mut_ptr() as *mut c_void;

let id = set_hint_field_c(setup.p_setup, params, values_ptr, hint_id, hint_field_name);

air_instance_ctx.set_subproofvalue_calculated(id as usize);
Expand All @@ -332,13 +340,13 @@ pub fn print_expression<F: Clone + Copy + Debug>(
expr: &HintFieldValue<F>,
first_print_value: u64,
last_print_value: u64,
) {
) {
let setup = setup_ctx.get_setup(air_instance_ctx.air_group_id, air_instance_ctx.air_id).expect("REASON");

match expr {
HintFieldValue::Column(vec) => {
print_expression_c(setup.p_setup, vec.as_ptr() as *mut c_void, 1, first_print_value, last_print_value);
}
}
HintFieldValue::ColumnExtended(vec) => {
print_expression_c(setup.p_setup, vec.as_ptr() as *mut c_void, 3, first_print_value, last_print_value);
}
Expand All @@ -349,7 +357,6 @@ pub fn print_expression<F: Clone + Copy + Debug>(
println!("FieldExtended values: {:?}", val);
}
}

}

pub fn print_by_name<F: Clone + Copy>(
Expand All @@ -367,18 +374,18 @@ pub fn print_by_name<F: Clone + Copy>(
let lengths_ptr = lengths.as_ref().map(|lengths| lengths.clone().as_mut_ptr()).unwrap_or(std::ptr::null_mut());

// TODO: CHECK WHAT IS WRONG WITH RETURN VALUES
let _raw_ptr = print_by_name_c(setup.p_setup, params, name, lengths_ptr, first_print_value, last_print_value, false);
let _raw_ptr =
print_by_name_c(setup.p_setup, params, name, lengths_ptr, first_print_value, last_print_value, false);

// if return_values {
// let field = unsafe { Box::from_raw(raw_ptr as *mut HintFieldInfo<F>) };

// Some(HintCol::from_hint_field(field.as_ref()))
// } else {
None
None
// }
}


#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading

0 comments on commit d66aee2

Please sign in to comment.