Skip to content

Commit

Permalink
Merge pull request iden3#101 from iden3/extensions-log-arrays
Browse files Browse the repository at this point in the history
Extensions log arrays
  • Loading branch information
clararod9 authored Aug 19, 2022
2 parents 348386c + fc742cd commit 12f2fe3
Show file tree
Hide file tree
Showing 61 changed files with 1,115 additions and 286 deletions.
12 changes: 9 additions & 3 deletions circom/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
[package]
name = "circom"
version = "2.0.6"
authors = ["Costa Group UCM & iden3"]
edition = "2021"
authors = ["Costa Group UCM","iden3"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
description = "circom is a zkSnark circuit compiler"
homepage = "https://iden3.io/circom"
documentation = "https://docs.circom.io"
repository = "https://github.com/iden3/circom"
readme = "README.md"
keywords = ["zkproofs", "zksanrks","circuits","compiler"]
categories = ["compilers"]

[dependencies]
parser = {path = "../parser"}
Expand Down
6 changes: 2 additions & 4 deletions circom_algebra/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
[package]
name = "circom_algebra"
version = "2.0.0"
authors = ["hermeGarcia <[email protected]>"]
version = "2.0.4"
authors = ["Costa Group UCM","iden3"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
num-bigint-dig = "0.6.0"
num-traits = "0.2.6"
Expand Down
6 changes: 2 additions & 4 deletions code_producers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
[package]
name = "code_producers"
version = "2.0.1"
authors = ["hermeGarcia <[email protected]>"]
version = "2.0.4"
authors = ["Costa Group UCM","iden3"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
handlebars = "4.1.3"
lz_fnv = "0.1.2"
Expand Down
11 changes: 11 additions & 0 deletions code_producers/src/c_elements/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod c_code_generator;

pub use crate::components::*;

pub type CInstruction = String;
Expand All @@ -25,6 +26,7 @@ pub struct CProducer {
pub field_tracking: Vec<String>,
version: usize,
name_tag: String,
string_table: Vec<String>,
}

impl Default for CProducer {
Expand Down Expand Up @@ -88,6 +90,7 @@ impl Default for CProducer {
// fix values
version: 2,
name_tag: "name".to_string(),
string_table : Vec::new(),
}
}
}
Expand Down Expand Up @@ -150,4 +153,12 @@ impl CProducer {
pub fn get_size_32_bit(&self) -> usize {
self.size_32_bit
}

pub fn get_string_table(&self) -> &Vec<String> {
&self.string_table
}

pub fn set_string_table(&mut self, string_table: Vec<String>) {
self.string_table = string_table;
}
}
38 changes: 18 additions & 20 deletions code_producers/src/wasm_elements/bls12381/witness_calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,34 @@ module.exports = async function builder(code, options) {

let wc;

let errStr = "";

const instance = await WebAssembly.instantiate(wasmModule, {
runtime: {
exceptionHandler : function(code) {
let errStr;
let err;
if (code == 1) {
errStr= "Signal not found. ";
err = "Signal not found.\n";
} else if (code == 2) {
errStr= "Too many signals set. ";
err = "Too many signals set.\n";
} else if (code == 3) {
errStr= "Signal already set. ";
err = "Signal already set.\n";
} else if (code == 4) {
errStr= "Assert Failed. ";
err = "Assert Failed.\n";
} else if (code == 5) {
errStr= "Not enough memory. ";
err = "Not enough memory.\n";
} else if (code == 6) {
errStr= "Input signal array access exceeds the size";
err = "Input signal array access exceeds the size.\n";
} else {
errStr= "Unknown error\n";
err = "Unknown error.\n";
}
// get error message from wasm
errStr += getMessage();
throw new Error(errStr);
throw new Error(err + errStr);
},
showSharedRWMemory: function() {
printErrorMessage : function() {
errStr += getMessage() + "\n";
// console.error(getMessage());
},
showSharedRWMemory : function() {
printSharedRWMemory ();
}

Expand Down Expand Up @@ -75,12 +78,7 @@ module.exports = async function builder(code, options) {
for (let j=0; j<shared_rw_memory_size; j++) {
arr[shared_rw_memory_size-1-j] = instance.exports.readSharedRWMemory(j);
}
const label = getMessage();
if(label){
console.log(label + ':', fromArray32(arr));
}else{
console.log(fromArray32(arr));
}
console.log(fromArray32(arr));

}

Expand Down Expand Up @@ -130,8 +128,8 @@ class WitnessCalculator {
throw new Error(`Too many values for input signal ${k}\n`);
}
for (let i=0; i<fArr.length; i++) {
const arrFr = toArray32(BigInt(fArr[i])%this.prime,this.n32)
for (let j=0; j<this.n32; j++) {
const arrFr = toArray32(BigInt(fArr[i])%this.prime,this.n32)
for (let j=0; j<this.n32; j++) {
this.instance.exports.writeSharedRWMemory(j,arrFr[this.n32-1-j]);
}
try {
Expand Down
39 changes: 21 additions & 18 deletions code_producers/src/wasm_elements/bn128/witness_calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,37 @@ module.exports = async function builder(code, options) {

let wc;

let errStr = "";

const instance = await WebAssembly.instantiate(wasmModule, {
runtime: {
exceptionHandler : function(code) {
let errStr;
let err;
if (code == 1) {
errStr= "Signal not found. ";
err = "Signal not found.\n";
} else if (code == 2) {
errStr= "Too many signals set. ";
err = "Too many signals set.\n";
} else if (code == 3) {
errStr= "Signal already set. ";
err = "Signal already set.\n";
} else if (code == 4) {
errStr= "Assert Failed. ";
err = "Assert Failed.\n";
} else if (code == 5) {
errStr= "Not enough memory. ";
err = "Not enough memory.\n";
} else if (code == 6) {
errStr= "Input signal array access exceeds the size";
err = "Input signal array access exceeds the size.\n";
} else {
errStr= "Unknown error\n";
err = "Unknown error.\n";
}
// get error message from wasm
errStr += getMessage();
throw new Error(errStr);
throw new Error(err + errStr);
},
showSharedRWMemory: function() {
printErrorMessage : function() {
errStr += getMessage() + "\n";
// console.error(getMessage());
},
writeBufferMessage : function() {
process.stdout.write(getMessage());
},
showSharedRWMemory : function() {
printSharedRWMemory ();
}

Expand Down Expand Up @@ -75,12 +81,9 @@ module.exports = async function builder(code, options) {
for (let j=0; j<shared_rw_memory_size; j++) {
arr[shared_rw_memory_size-1-j] = instance.exports.readSharedRWMemory(j);
}
const label = getMessage();
if(label){
console.log(label + ':', fromArray32(arr));
}else{
console.log(fromArray32(arr));
}

process.stdout.write(fromArray32(arr).toString());
//console.log(fromArray32(arr));
}

};
Expand Down
34 changes: 16 additions & 18 deletions code_producers/src/wasm_elements/goldilocks/witness_calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,34 @@ module.exports = async function builder(code, options) {

let wc;

let errStr = "";

const instance = await WebAssembly.instantiate(wasmModule, {
runtime: {
exceptionHandler : function(code) {
let errStr;
let err;
if (code == 1) {
errStr= "Signal not found. ";
err = "Signal not found.\n";
} else if (code == 2) {
errStr= "Too many signals set. ";
err = "Too many signals set.\n";
} else if (code == 3) {
errStr= "Signal already set. ";
err = "Signal already set.\n";
} else if (code == 4) {
errStr= "Assert Failed. ";
err = "Assert Failed.\n";
} else if (code == 5) {
errStr= "Not enough memory. ";
err = "Not enough memory.\n";
} else if (code == 6) {
errStr= "Input signal array access exceeds the size";
err = "Input signal array access exceeds the size.\n";
} else {
errStr= "Unknown error\n";
err = "Unknown error.\n";
}
// get error message from wasm
errStr += getMessage();
throw new Error(errStr);
throw new Error(err + errStr);
},
showSharedRWMemory: function() {
printErrorMessage : function() {
errStr += getMessage() + "\n";
// console.error(getMessage());
},
showSharedRWMemory : function() {
printSharedRWMemory ();
}

Expand Down Expand Up @@ -75,12 +78,7 @@ module.exports = async function builder(code, options) {
for (let j=0; j<shared_rw_memory_size; j++) {
arr[shared_rw_memory_size-1-j] = instance.exports.readSharedRWMemory(j);
}
const label = getMessage();
if(label){
console.log(label + ':', fromArray32(arr));
}else{
console.log(fromArray32(arr));
}
console.log(fromArray32(arr));
}

};
Expand Down
23 changes: 22 additions & 1 deletion code_producers/src/wasm_elements/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod wasm_code_generator;

use crate::components::*;

type WasmInstruction = String;
Expand Down Expand Up @@ -48,6 +49,8 @@ pub struct WASMProducer {
create_loop_sub_cmp_tag: String,
create_loop_offset_tag: String,
create_loop_counter_tag: String,
merror_tag: String,
string_table: Vec<String>,
}

impl Default for WASMProducer {
Expand Down Expand Up @@ -103,6 +106,8 @@ impl Default for WASMProducer {
create_loop_sub_cmp_tag: "$createloopsubcmp".to_string(),
create_loop_offset_tag: "$createloopoffset".to_string(),
create_loop_counter_tag: "$createloopcounter".to_string(),
merror_tag: "$merror".to_string(),
string_table: Vec::new(),
}
}
}
Expand Down Expand Up @@ -295,9 +300,14 @@ impl WASMProducer {
pub fn get_message_list_start(&self) -> usize {
self.get_message_buffer_start() + self.size_of_message_buffer_in_bytes
}
pub fn get_constant_numbers_start(&self) -> usize {
pub fn get_string_list_start(&self) -> usize {
self.get_message_list_start() + self.size_of_message_in_bytes * self.message_list.len()
}

pub fn get_constant_numbers_start(&self) -> usize {
self.get_string_list_start() + self.size_of_message_in_bytes * self.string_table.len()
}

pub fn get_var_stack_memory_start(&self) -> usize {
self.get_constant_numbers_start() + (self.size_32_bit + 2) * 4 * self.field_tracking.len()
}
Expand Down Expand Up @@ -361,7 +371,18 @@ impl WASMProducer {
pub fn get_create_loop_counter_tag(&self) -> &str {
&self.create_loop_counter_tag
}
pub fn get_merror_tag(&self) -> &str {
&self.merror_tag
}
pub fn needs_comments(&self) -> bool{
self.wat_flag
}

pub fn get_string_table(&self) -> &Vec<String> {
&self.string_table
}

pub fn set_string_table(&mut self, string_table: Vec<String>) {
self.string_table = string_table;
}
}
Loading

0 comments on commit 12f2fe3

Please sign in to comment.