Skip to content

Commit

Permalink
Merge pull request iden3#119 from iden3/anonymous-tags
Browse files Browse the repository at this point in the history
Circom 2.1: adding anonymous components and tags
  • Loading branch information
clararod9 authored Oct 11, 2022
2 parents a714807 + 8926ddc commit b7ad01b
Show file tree
Hide file tree
Showing 60 changed files with 3,618 additions and 698 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

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

25 changes: 16 additions & 9 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
# Release notes
## October 11, 2022 circom 2.1.0
#### New features
- Tags: more information [here](https://github.com/iden3/circom/blob/master/mkdocs/docs/circom-language/tags.md).
- Anonymous Components: more information [here](https://github.com/iden3/circom/blob/master/mkdocs/docs/circom-language/anonymous-components-and-tuples.md).

#### Extensions
- Improving the memory consumption during the C++ witness generation.

## September 21, 2022 circom 2.0.9
#### Extension
- Adding a warning if the programmer is using the operator <-- when it is possible to use <== instead (if the right side is a quadratic expression and the instruction is not contained in a custom template).
- Signal ids in custom templates changed to 64 bits.
- Array sizes are expected to be usize. Now, we throw an error in other case.
- Separating optimization option -O2 in two different options: --O2 and --O2rounds. Explanation can be found [here](https://github.com/iden3/circom/blob/master/mkdocs/docs/getting-started/compilation-options.md). The default option is currently --O2.
#### Extensions
- Adding a warning if the programmer is using the operator <-- when it is possible to use <== instead (if the right side is a quadratic expression and the instruction is not contained in a custom template).
- Signal ids in custom templates changed to 64 bits.
- Array sizes are expected to be usize. Now, we throw an error in other case.
- Separating optimization option -O2 in two different options: --O2 and --O2rounds. Explanation can be found [here](https://github.com/iden3/circom/blob/master/mkdocs/docs/circom-language/include.md). The default option is currently --O2.
- Writing Sections 4 and 5 of the r1cs file, only if "pragma custom_templates" is used (which is needed if custom templates are present).
- Improving --O1 optimization.
- Adding a new documentation section about the different compilation options and flags.
- Improving --O1 optimization.
- Adding a new documentation section about the different compilation options and flags.

#### Fixed bugs
- Fixing -l option to disallow several values for one option: each value must have its own -l option.
#### Fixed bugs
- Fixing -l option to disallow several values for one option: each value must have its own -l option.

## August 26, 2022 circom 2.0.8

Expand Down
2 changes: 1 addition & 1 deletion circom/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "circom"
version = "2.0.9"
version = "2.1.0"
authors = ["Costa Group UCM","iden3"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion code_producers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "code_producers"
version = "2.0.8"
version = "2.1.0"
authors = ["Costa Group UCM","iden3"]
edition = "2018"

Expand Down
2 changes: 2 additions & 0 deletions code_producers/src/c_elements/c_code_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,13 +729,15 @@ pub fn generate_message_list_def(_producer: &CProducer, message_list: &MessageLi
pub fn generate_function_release_memory_component() -> Vec<String>{
let mut instructions = vec![];
instructions.push("void release_memory_component(Circom_CalcWit* ctx, uint pos) {{\n".to_string());
instructions.push("if (pos != 0){{\n".to_string());
instructions.push("delete ctx->componentMemory[pos].subcomponents;\n".to_string());
instructions.push("delete ctx->componentMemory[pos].subcomponentsParallel;\n".to_string());
instructions.push("delete ctx->componentMemory[pos].outputIsSet;\n".to_string());
instructions.push("delete ctx->componentMemory[pos].mutexes;\n".to_string());
instructions.push("delete ctx->componentMemory[pos].cvs;\n".to_string());
instructions.push("delete ctx->componentMemory[pos].sbct;\n".to_string());
instructions.push("}}\n\n".to_string());
instructions.push("}}\n\n".to_string());
instructions
}

Expand Down
20 changes: 20 additions & 0 deletions code_producers/src/wasm_elements/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ pub struct WASMProducer {
call_lvar_tag: String,
expaux_tag: String,
temp_tag: String,
aux_0_tag: String,
aux_1_tag: String,
aux_2_tag: String,
counter_tag: String,
store_aux_1_tag: String,
store_aux_2_tag: String,
copy_counter_tag: String,
Expand Down Expand Up @@ -103,6 +107,10 @@ impl Default for WASMProducer {
call_lvar_tag: "$calllvar".to_string(),
expaux_tag: "$expaux".to_string(),
temp_tag: "$temp".to_string(),
aux_0_tag: "$aux0".to_string(),
aux_1_tag: "$aux1".to_string(),
aux_2_tag: "$aux2".to_string(),
counter_tag: "$counter".to_string(),
store_aux_1_tag: "$storeaux1".to_string(),
store_aux_2_tag: "$storeaux2".to_string(),
copy_counter_tag: "$copycounter".to_string(),
Expand Down Expand Up @@ -362,6 +370,18 @@ impl WASMProducer {
pub fn get_temp_tag(&self) -> &str {
&self.temp_tag
}
pub fn get_aux_0_tag(&self) -> &str {
&self.aux_0_tag
}
pub fn get_aux_1_tag(&self) -> &str {
&self.aux_1_tag
}
pub fn get_aux_2_tag(&self) -> &str {
&self.aux_2_tag
}
pub fn get_counter_tag(&self) -> &str {
&self.counter_tag
}
pub fn get_store_aux_1_tag(&self) -> &str {
&self.store_aux_1_tag
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "compiler"
version = "2.0.8"
version = "2.1.0"
authors = ["Costa Group UCM","iden3"]
edition = "2018"

Expand Down
6 changes: 4 additions & 2 deletions compiler/src/circuit_design/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ fn build_template_instances(
components: template.components,
template_database: &c_info.template_database,
string_table : string_table,
signals_to_tags: template.signals_to_tags,
};
let mut template_info = TemplateCodeInfo {
name,
Expand Down Expand Up @@ -159,7 +160,8 @@ fn build_function_instances(
cmp_to_type: HashMap::with_capacity(0),
component_to_parallel: HashMap::with_capacity(0),
template_database: &c_info.template_database,
string_table : string_table
string_table : string_table,
signals_to_tags: BTreeMap::new(),
};
let mut function_info = FunctionCodeInfo {
name,
Expand Down Expand Up @@ -401,4 +403,4 @@ pub fn create_table_usize_to_string( string_table : HashMap<String,usize>) -> Ve
table_usize_to_string[us] = string;
}
table_usize_to_string
}
}
6 changes: 3 additions & 3 deletions compiler/src/circuit_design/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ impl WriteC for Circuit {
producer.get_io_map().len()
));
//code.append(&mut generate_message_list_def(producer, producer.get_message_list()));

// Function to release the memory of a component
// Functions to release the memory
let mut release_component_code = generate_function_release_memory_component();
code.append(&mut release_component_code);

Expand All @@ -376,6 +376,7 @@ impl WriteC for Circuit {
code.append(&mut t_code);
}


// Epilogue
let run_circuit = "void run".to_string();
let run_circuit_args = vec![declare_circom_calc_wit()];
Expand Down Expand Up @@ -403,7 +404,6 @@ impl WriteC for Circuit {
run_args.push(CIRCOM_CALC_WIT.to_string());
let run_call = format!("{};", build_call(main_template_run, run_args.clone()));

//let main_run_body = vec![start_msg, ctx_index, run_call, end_msg];
let main_run_body = vec![ctx_index, run_call];
code.push(build_callable(run_circuit, run_circuit_args, main_run_body));
(code, "".to_string())
Expand Down
4 changes: 4 additions & 0 deletions compiler/src/circuit_design/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ impl WriteWasm for FunctionCodeInfo {
instructions.push(format!("(local {} i32)", producer.get_lvar_tag()));
instructions.push(format!("(local {} i32)", producer.get_expaux_tag()));
instructions.push(format!("(local {} i32)", producer.get_temp_tag()));
instructions.push(format!("(local {} i32)", producer.get_aux_0_tag()));
instructions.push(format!("(local {} i32)", producer.get_aux_1_tag()));
instructions.push(format!("(local {} i32)", producer.get_aux_2_tag()));
instructions.push(format!("(local {} i32)", producer.get_counter_tag()));
instructions.push(format!("(local {} i32)", producer.get_store_aux_1_tag()));
instructions.push(format!("(local {} i32)", producer.get_store_aux_2_tag()));
instructions.push(format!("(local {} i32)", producer.get_copy_counter_tag()));
Expand Down
8 changes: 6 additions & 2 deletions compiler/src/circuit_design/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ impl WriteWasm for TemplateCodeInfo {
instructions.push(format!(" (local {} i32)", producer.get_lvar_tag()));
instructions.push(format!(" (local {} i32)", producer.get_expaux_tag()));
instructions.push(format!(" (local {} i32)", producer.get_temp_tag()));
instructions.push(format!(" (local {} i32)", producer.get_aux_0_tag()));
instructions.push(format!(" (local {} i32)", producer.get_aux_1_tag()));
instructions.push(format!(" (local {} i32)", producer.get_aux_2_tag()));
instructions.push(format!(" (local {} i32)", producer.get_counter_tag()));
instructions.push(format!(" (local {} i32)", producer.get_store_aux_1_tag()));
instructions.push(format!(" (local {} i32)", producer.get_store_aux_2_tag()));
instructions.push(format!(" (local {} i32)", producer.get_copy_counter_tag()));
Expand Down Expand Up @@ -309,13 +313,13 @@ impl TemplateCodeInfo {
"release_memory_component".to_string(),
vec![CIRCOM_CALC_WIT.to_string(), "index_subc".to_string()]
)));

run_body.push(format!("}}"));

let run_fun = build_callable(run_header, run_params, run_body);
vec![create_fun, run_fun]
}

pub fn wrap(self) -> TemplateCode {
TemplateCode::new(self)
}
}
}
18 changes: 15 additions & 3 deletions compiler/src/hir/component_preprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,22 @@ fn rm_init(stmt: &mut Statement) {
if let InitializationBlock { initializations, xtype, .. } = stmt {
if let Signal(..) = xtype {
let work = std::mem::take(initializations);
for i in work {
for mut i in work {
if i.is_substitution() {
initializations.push(i);
}
else if i.is_block(){
rm_block(&mut i);
initializations.push(i);
}
}
} else {
let filter = std::mem::take(initializations);
for mut s in filter {
rm_statement(&mut s);
if !should_be_removed(&s) {
initializations.push(s);
}
}
}
} else {
Expand All @@ -90,9 +102,9 @@ fn should_be_removed(stmt: &Statement) -> bool {
use Statement::{InitializationBlock, Substitution};
use VariableType::*;
if let InitializationBlock { xtype, .. } = stmt {
Component == *xtype
Component == *xtype || AnonymousComponent == *xtype
} else if let Substitution { meta, .. } = stmt {
meta.get_type_knowledge().is_component()
meta.get_type_knowledge().is_component() || meta.get_type_knowledge().is_tag()
} else {
false
}
Expand Down
Loading

0 comments on commit b7ad01b

Please sign in to comment.