Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions bberg/src/relation_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ impl RelationBuilder for BBFiles {
// Group relations per file
let grouped_relations: HashMap<String, Vec<Identity<AlgebraicExpression<F>>>> =
group_relations_per_file(analyzed_identities);
let relations = grouped_relations.keys().cloned().collect_vec();
let mut relations = grouped_relations.keys().cloned().collect_vec();
relations.sort();

// Contains all of the rows in each relation, will be useful for creating composite builder types
let mut all_rows: HashMap<String, String> = HashMap::new();
Expand Down Expand Up @@ -113,6 +114,9 @@ impl RelationBuilder for BBFiles {
);
}

shifted_polys.sort();
relations.sort();

RelationOutput {
relations,
shifted_polys,
Expand Down Expand Up @@ -460,8 +464,8 @@ pub(crate) fn create_identities<F: FieldElement>(
println!("Public Identities: {:?}", collected_public_identities);
}

let collected_cols: Vec<String> = collected_cols.drain().collect();
let collected_shifts: Vec<String> = collected_cols
let mut collected_cols: Vec<String> = collected_cols.drain().collect();
let mut collected_shifts: Vec<String> = collected_cols
.clone()
.iter()
.filter_map(|col| {
Expand All @@ -473,6 +477,9 @@ pub(crate) fn create_identities<F: FieldElement>(
})
.collect();

collected_cols.sort();
collected_shifts.sort();

IdentitiesOutput {
subrelations,
identities,
Expand All @@ -490,6 +497,7 @@ pub(crate) fn create_identities<F: FieldElement>(
/// Note: this mapping will never be that big, so we are quite naive in implementation
/// It should be able to be called from else where with relation_name::get_relation_label
fn create_relation_labels(relation_name: &str, labels: HashMap<usize, String>) -> String {
// Sort labels by the index
let label_transformation = |(index, label)| {
format!(
"case {index}:
Expand All @@ -498,7 +506,11 @@ fn create_relation_labels(relation_name: &str, labels: HashMap<usize, String>) -
)
};

let switch_statement: String = labels
// Sort the labels by their index
let mut sorted_labels: Vec<(usize, String)> = labels.into_iter().collect();
sorted_labels.sort_by(|a, b| a.0.cmp(&b.0));

let switch_statement: String = sorted_labels
.into_iter()
.map(label_transformation)
.collect::<Vec<String>>()
Expand Down
6 changes: 6 additions & 0 deletions bberg/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,9 @@ pub fn snake_case(input: &str) -> String {

result
}

pub fn sort_cols<F: FieldElement>(cols: &[(String, Vec<F>)]) -> Vec<(String, Vec<F>)> {
let mut cols = cols.to_vec();
cols.sort_by(|a, b| a.0.cmp(&b.0));
cols
}
9 changes: 8 additions & 1 deletion bberg/src/vm_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::relation_builder::RelationOutput;
use crate::utils::collect_col;
use crate::utils::flatten;
use crate::utils::sanitize_name;
use crate::utils::sort_cols;
use crate::utils::transform_map;
use crate::verifier_builder::VerifierBuilder;

Expand Down Expand Up @@ -51,11 +52,16 @@ pub(crate) fn analyzed_to_cpp<F: FieldElement>(
witness: &[(String, Vec<F>)],
name: Option<String>,
) {
// Sort fixed and witness to ensure consistent ordering
let fixed = &sort_cols(fixed);
let witness = &sort_cols(witness);

let file_name: &str = &name.unwrap_or("Example".to_owned());
let mut bb_files = BBFiles::default(file_name.to_owned());

// Inlining step to remove the intermediate poly definitions
let analyzed_identities = analyzed.identities_with_inlined_intermediate_polynomials();
let mut analyzed_identities = analyzed.identities_with_inlined_intermediate_polynomials();
analyzed_identities.sort_by(|a, b| a.id.cmp(&b.id));

// ----------------------- Handle Standard Relation Identities -----------------------
// We collect all references to shifts as we traverse all identities and create relation files
Expand Down Expand Up @@ -153,6 +159,7 @@ fn get_all_col_names<F: FieldElement>(
// Gather sanitized column names
let fixed_names = collect_col(fixed, sanitize);
let witness_names = collect_col(witness, sanitize);

let inverses = flatten(&[perm_inverses, lookup_inverses]);
let witness_names = flatten(&[witness_names, inverses.clone(), lookup_counts]);

Expand Down