Skip to content

Commit 071f17e

Browse files
authored
Merge pull request #8 from distributed-lab/feat/circom-2.1.9
circom 2.1.9
2 parents 041b0b1 + c9abf21 commit 071f17e

File tree

75 files changed

+3697
-174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+3697
-174
lines changed

Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RELEASES.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Release notes
2+
## April 23, 2024 circom 2.1.9
23

4+
#### Extensions
5+
- Improvement of error messages: providing more descriptive messages.
6+
- Improvement of documentation and new sections: detailed explanation of the applied simplification techniques and precise description of constraint-related output formats.
7+
- Allowing arbitrary number of different input names in the main component.
8+
9+
#### Fixed bugs
10+
- Removing non-determinism in R1CS generation: fixing assignment order of anonymous components inputs.
11+
- Fixing an error when computing array accesses involving complex expressions in multidimensional arrays.
12+
- Improving known/unknown analysis: arrays of vars combining known/unknown positions.
13+
- Fixing minor panics: main component not calling to a template, anonymous component with wrong number of arguments, log messages containing line breaks.
14+
15+
316
## Jan 17, 2024 circom 2.1.8
417

518
#### Extensions

circom/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "circom"
3-
version = "2.1.8"
3+
version = "2.1.9"
44
authors = ["Costa Group UCM","iden3"]
55
edition = "2018"
66

circom_algebra/src/algebra.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,13 +554,13 @@ impl<C: Default + Clone + Display + Hash + Eq> ArithmeticExpression<C> {
554554
}
555555

556556
// Bit operations
557-
pub fn complement_256(
557+
pub fn complement_254(
558558
elem: &ArithmeticExpression<C>,
559559
field: &BigInt,
560560
) -> ArithmeticExpression<C> {
561561
use ArithmeticExpression::*;
562562
if let Number { value } = elem {
563-
Number { value: modular_arithmetic::complement_256(value, field) }
563+
Number { value: modular_arithmetic::complement_254(value, field) }
564564
} else {
565565
NonQuadratic
566566
}

circom_algebra/src/modular_arithmetic.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ pub fn multi_inv(values: &Vec<BigInt>, field: &BigInt) -> Vec<BigInt>{
9292

9393
//Bit operations
9494

95-
// 256 bit complement
96-
pub fn complement_256(elem: &BigInt, field: &BigInt) -> BigInt {
95+
// 254 bit complement
96+
pub fn complement_254(elem: &BigInt, field: &BigInt) -> BigInt {
9797
let (sign, mut bit_repr) = bit_representation(elem);
98-
while bit_repr.len() > 256 {
98+
while bit_repr.len() > 254 {
9999
bit_repr.pop();
100100
}
101-
for _i in bit_repr.len()..256 {
101+
for _i in bit_repr.len()..254 {
102102
bit_repr.push(0);
103103
}
104104
for bit in &mut bit_repr {
@@ -252,8 +252,8 @@ mod tests {
252252
.expect("generating the big int was not possible");
253253
let big_num = BigInt::parse_bytes("1234".as_bytes(), 10)
254254
.expect("generating the big int was not possible");
255-
let big_num_complement = complement_256(&big_num, &field);
256-
let big_num_complement_complement = complement_256(&big_num_complement, &field);
255+
let big_num_complement = complement_254(&big_num, &field);
256+
let big_num_complement_complement = complement_254(&big_num_complement, &field);
257257
let big_num_modulus = modulus(&big_num, &field);
258258
assert_eq!(big_num_complement_complement, big_num_modulus);
259259
}

code_producers/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "code_producers"
3-
version = "2.1.8"
3+
version = "2.1.9"
44
authors = ["Costa Group UCM","iden3"]
55
edition = "2018"
66

code_producers/src/c_elements/c_code_generator.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ const S_IO_DEF: &str = "IODef";
2222
const IO_DEF_FIELDS: [&str; 2] = ["offset", "lengths"];
2323

2424
// Global variables
25-
pub const SIZE_INPUT_HASHMAP: usize = 256;
26-
const G_INPUT_HASHMAP: &str = "inputHashMap"; // type HashSignalInfo[256]
25+
//pub const SIZE_INPUT_HASHMAP: usize = 256;
26+
const G_INPUT_HASHMAP: &str = "inputHashMap"; // type HashSignalInfo[max(256,needed)]
2727
const G_RM_INPUT_SIGNAL_COUNTER: &str = "remainingInputSignalCounter"; // type u32
2828
const G_INPUT_SIGNAL_SET: &str = "inputSignalSetMap"; // type bool[M]
2929
const G_WITNESS_TO_SIGNAL: &str = "witness2signalList"; // type u64[W]
@@ -469,15 +469,14 @@ pub fn collect_function_headers(functions: Vec<String>) -> Vec<String> {
469469

470470
//--------------- generate all kinds of Data for the .dat file ---------------
471471

472-
pub fn generate_hash_map(signal_name_list: &Vec<(String, usize, usize)>) -> Vec<(u64, u64, u64)> {
473-
assert!(signal_name_list.len() <= 256);
474-
let len = 256;
475-
let mut hash_map = vec![(0, 0, 0); len];
472+
pub fn generate_hash_map(signal_name_list: &Vec<(String, usize, usize)>, size: usize) -> Vec<(u64, u64, u64)> {
473+
assert!(signal_name_list.len() <= size);
474+
let mut hash_map = vec![(0, 0, 0); size];
476475
for i in 0..signal_name_list.len() {
477476
let h = hasher(&signal_name_list[i].0);
478-
let mut p = (h % 256) as usize;
477+
let mut p = h as usize % size;
479478
while hash_map[p].1 != 0 {
480-
p = (p + 1) % 256;
479+
p = (p + 1) % size;
481480
}
482481
hash_map[p] = (h, signal_name_list[i].1 as u64, signal_name_list[i].2 as u64);
483482
}
@@ -653,9 +652,9 @@ pub fn generate_dat_file(dat_file: &mut dyn Write, producer: &CProducer) -> std:
653652
//dfile.flush()?;
654653

655654
let aux = producer.get_main_input_list();
656-
let map = generate_hash_map(&aux);
655+
let map = generate_hash_map(&aux,producer.get_input_hash_map_entry_size());
657656
let hashmap = generate_dat_from_hash_map(&map); //bytes u64 --> u64
658-
//let hml = 256 as u32;
657+
//let hml = producer.get_input_hash_map_entry_size() as u32;
659658
//dfile.write_all(&hml.to_be_bytes())?;
660659
dat_file.write_all(&hashmap)?;
661660
//dat_file.flush()?;
@@ -946,7 +945,7 @@ pub fn generate_c_file(name: String, producer: &CProducer) -> std::io::Result<()
946945
let full_name = name + ".cpp";
947946
let mut cfile = File::create(full_name)?;
948947
let mut code = vec![];
949-
let len = 256;
948+
let len = producer.get_input_hash_map_entry_size();
950949
code.push("#include <stdio.h>".to_string());
951950
code.push("#include <iostream>".to_string());
952951
code.push("#include <assert.h>".to_string());

code_producers/src/c_elements/common/calcwit.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ uint Circom_CalcWit::getInputSignalHashPosition(u64 h) {
5252
uint pos = (uint)(h % (u64)n);
5353
if (circuit->InputHashMap[pos].hash!=h){
5454
uint inipos = pos;
55-
pos++;
55+
pos = (pos+1)%n;
5656
while (pos != inipos) {
57-
if (circuit->InputHashMap[pos].hash==h) return pos;
58-
if (circuit->InputHashMap[pos].hash==0) {
57+
if (circuit->InputHashMap[pos].hash == h) return pos;
58+
if (circuit->InputHashMap[pos].signalid == 0) {
5959
fprintf(stderr, "Signal not found\n");
6060
assert(false);
6161
}

code_producers/src/c_elements/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ impl CProducer {
134134
pub fn get_main_input_list(&self) -> &InputList {
135135
&self.main_input_list
136136
}
137+
pub fn get_input_hash_map_entry_size(&self) -> usize {
138+
std::cmp::max(usize::pow(2,(self.main_input_list.len() as f32).log2().ceil() as u32),256)
139+
}
137140
pub fn get_number_of_witness(&self) -> usize {
138141
self.signals_in_witness
139142
}

code_producers/src/wasm_elements/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ impl WASMProducer {
179179
pub fn get_main_input_list(&self) -> &InputList {
180180
&self.main_input_list
181181
}
182+
pub fn get_input_hash_map_entry_size(&self) -> usize {
183+
std::cmp::max(usize::pow(2,(self.main_input_list.len() as f32).log2().ceil() as u32),256)
184+
}
182185
pub fn get_number_of_witness(&self) -> usize {
183186
self.signals_in_witness
184187
}
@@ -261,7 +264,7 @@ impl WASMProducer {
261264
(4 * self.size_32_bit) + 8 + self.get_shared_rw_memory_start()
262265
}
263266
pub fn get_remaining_input_signal_counter(&self) -> usize {
264-
self.get_input_signals_hashmap_start() + 4096 // 256*(8(h)+4(pos)+4(size))
267+
self.get_input_signals_hashmap_start() + self.get_input_hash_map_entry_size()*16 // input_hash_map_entry_size*(8(h)+4(pos)+4(size))
265268
}
266269
pub fn get_input_signal_set_map_start(&self) -> usize {
267270
self.get_remaining_input_signal_counter() + 4

code_producers/src/wasm_elements/wasm_code_generator.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,14 @@ pub fn get_initial_size_of_memory(producer: &WASMProducer) -> usize {
226226

227227
//------------------- generate all kinds of Data ------------------
228228

229-
pub fn generate_hash_map(signal_name_list: &Vec<(String, usize, usize)>) -> Vec<(u64, usize, usize)> {
230-
assert!(signal_name_list.len() <= 256);
231-
let len = 256;
232-
let mut hash_map = vec![(0, 0, 0); len];
229+
pub fn generate_hash_map(signal_name_list: &Vec<(String, usize, usize)>, size: usize) -> Vec<(u64, usize, usize)> {
230+
assert!(signal_name_list.len() <= size);
231+
let mut hash_map = vec![(0, 0, 0); size];
233232
for i in 0..signal_name_list.len() {
234233
let h = hasher(&signal_name_list[i].0);
235-
let mut p = (h % 256) as usize;
234+
let mut p = h as usize % size;
236235
while hash_map[p].1 != 0 {
237-
p = (p + 1) % 256;
236+
p = (p + 1) % size;
238237
}
239238
hash_map[p] = (h, signal_name_list[i].1, signal_name_list[i].2);
240239
}
@@ -567,7 +566,7 @@ pub fn generate_data_list(producer: &WASMProducer) -> Vec<WasmInstruction> {
567566
producer.get_shared_rw_memory_start() - 8,
568567
"\\00\\00\\00\\00\\00\\00\\00\\80"
569568
));
570-
let map = generate_hash_map(&producer.get_main_input_list());
569+
let map = generate_hash_map(&producer.get_main_input_list(),producer.get_input_hash_map_entry_size());
571570
wdata.push(format!(
572571
"(data (i32.const {}) \"{}\")",
573572
producer.get_input_signals_hashmap_start(),
@@ -852,6 +851,7 @@ pub fn init_generator(producer: &WASMProducer) -> Vec<WasmInstruction> {
852851
pub fn get_input_signal_map_position_generator(producer: &WASMProducer) -> Vec<WasmInstruction> {
853852
let mut instructions = vec![];
854853
let header = "(func $getInputSignalMapPosition (type $_t_i64ri32)".to_string();
854+
let sizeones = producer.get_input_hash_map_entry_size()-1;
855855
instructions.push(header);
856856
instructions.push(" (param $hn i64)".to_string());
857857
instructions.push("(result i32)".to_string());
@@ -860,7 +860,7 @@ pub fn get_input_signal_map_position_generator(producer: &WASMProducer) -> Vec<W
860860
instructions.push(" (local $aux i32)".to_string());
861861
instructions.push(get_local("$hn"));
862862
instructions.push(wrap_i6432());
863-
instructions.push(set_constant("255"));
863+
instructions.push(set_constant(&sizeones.to_string()));
864864
instructions.push(and32());
865865
instructions.push(set_local("$ini"));
866866
instructions.push(get_local("$ini"));
@@ -891,7 +891,7 @@ pub fn get_input_signal_map_position_generator(producer: &WASMProducer) -> Vec<W
891891
instructions.push(get_local("$i"));
892892
instructions.push(set_constant("1"));
893893
instructions.push(add32());
894-
instructions.push(set_constant("255"));
894+
instructions.push(set_constant(&sizeones.to_string()));
895895
instructions.push(and32());
896896
instructions.push(set_local("$i"));
897897
instructions.push(get_local("$i"));

compiler/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "compiler"
3-
version = "2.1.8"
3+
version = "2.1.9"
44
authors = ["Costa Group UCM","iden3"]
55
edition = "2018"
66

compiler/src/circuit_design/circuit.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ impl WriteC for Circuit {
346346
"uint get_number_of_components() {{return {};}}\n",
347347
producer.get_number_of_components()
348348
));
349-
code.push(format!("uint get_size_of_input_hashmap() {{return {};}}\n", SIZE_INPUT_HASHMAP));
349+
//code.push(format!("uint get_size_of_input_hashmap() {{return {};}}\n", SIZE_INPUT_HASHMAP));
350+
code.push(format!("uint get_size_of_input_hashmap() {{return {};}}\n", producer.get_input_hash_map_entry_size()));
350351
code.push(format!(
351352
"uint get_size_of_witness() {{return {};}}\n",
352353
producer.get_witness_to_signal_list().len()
@@ -464,7 +465,8 @@ impl WriteC for Circuit {
464465
"uint get_number_of_components() {{return {};}}\n",
465466
producer.get_number_of_components()
466467
));
467-
code.push(format!("uint get_size_of_input_hashmap() {{return {};}}\n", SIZE_INPUT_HASHMAP));
468+
//code.push(format!("uint get_size_of_input_hashmap() {{return {};}}\n", SIZE_INPUT_HASHMAP));
469+
code.push(format!("uint get_size_of_input_hashmap() {{return {};}}\n", producer.get_input_hash_map_entry_size()));
468470
code.push(format!(
469471
"uint get_size_of_witness() {{return {};}}\n",
470472
producer.get_witness_to_signal_list().len()

compiler/src/intermediate_representation/create_component_bucket.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl WriteC for CreateCmpBucket {
232232
}
233233
}
234234
// generate array with the positions that are actually created if there are empty components
235-
// if not only traverse the defined positions, but i gets the value of the indexed accesed position
235+
// if not only traverse the defined positions, but i gets the value of the indexed accessed position
236236
else{
237237
instructions.push(format!("uint aux_positions [{}]= {};", self.defined_positions.len(), set_list(self.defined_positions.iter().map(|(x, _y)| *x).collect())));
238238
instructions.push(format!("for (uint i_aux = 0; i_aux < {}; i_aux++) {{", self.defined_positions.len()));
@@ -302,4 +302,4 @@ impl WriteC for CreateCmpBucket {
302302
instructions.push("}".to_string());
303303
(instructions, "".to_string())
304304
}
305-
}
305+
}

compiler/src/intermediate_representation/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ mod value_bucket;
1515

1616
pub mod ir_interface;
1717
pub mod translate;
18-
pub use ir_interface::{Instruction, InstructionList, InstructionPointer};
18+
pub use ir_interface::InstructionList;

0 commit comments

Comments
 (0)