Comments (6)
functions are only for calculus of things that do not involve signals. In your case you should create a component using template instead of function.
In that case, you will not have any problem. (You need to define the size of the array).
from circom.
Some comments:
private is no longer used in circom 2.0 (https://docs.circom.io/circom-language/signals/)
What do you want to do with
out_array[length] <-- result[length]; ?
As it is written, it is an assignment of one position that is out of range.
If you were willing to do an assignment of the full array of var "result" into the array of signals "out_array", this is not allowed.
An array of signals should be assigned one by one. And recall that if you use <-- no constraint is generated.
out_array[i] = c.out_array[i];
should be
out_array[i] <== c.out_array[i];
from circom.
(1) Now it is fine, but you have to remove the "private" and "inter".
Moreover , depending on what you do temp could also be an array of var, as you had before.
(2) Sorry, you are right. I was confused with the out_array of the above template where it was an array of signals.
Since here it is an array of vars out_array[i] = c.out_array[i]; is ok
The weird thing in the second template is that you are not defining the value of the output signal.
from circom.
Wow, thanks for all of you are so accommodating and willing to give me a lot of helpful comments.👍❤
Here are some conclusions (no question anymore). I hope this could help other Circom newcomers.
(1) A very important rule!
An array of signals should be assigned one by one.
(2) Functions vs templates
Functions are only for calculating of things that do not involve signals.
In your case, you should create a component using template instead of function.
(3) Some combinations and their validities about signal
, var
, <==
, and =
.
signal
is assigned by "<==" and can be assigned only once.var
is assigned by "=".
signal a;
signal b;
var var_a;
var var_b;
a <== 123; // Valid
a <== b; // Valid
a <== var_a; // Valid
a = 123; // Invalid, please use "<=="
a = b; // Invalid, please use "<=="
a = var_a; // Invalid, please use "<=="
var_a = 123; // Valid
var_a = var_b; // Valid
var_a = a; // Valid
var_a <== 123; // Invalid, please use "="
var_a <== a; // Invalid, please use "="
var_a <== var_b; // Invalid, please use "="
(4) The revised pseudo-code which performs passing and retrieving array.
template foo(length) {
signal input in_array_foo[length];
signal temp[length]; // Store temporary results and can be assigned only once
signal output out_array_foo[length];
// Do something
for(var i = 0; i<length; i++) {
out_array_foo[i] <== temp[i];
}
}
template mainFunc(length) {
signal input in_array[length];
signal output out_array[length];
component bar = foo(length);
// Pass input array
for(var i = 0; i < length; i++) {
bar.in_array_foo[i] <== in_array[i];
}
// Retrieve output array
for(var i = 0; i < length; i++) {
out_array[i] <== bar.out_array_foo[i];
}
}
component main = mainFunc(NUMBER_DEFINED_STATICLY);
from circom.
Okay, I see.🙏
Therefore, if I use template for implementation. Would It be something like this?
template myFunc(length) {
signal private input in_array[length];
signal output out_array[length];
var result[length];
// Some calculations
out_array[length] <-- result[length];
}
template mainFunc(length) {
signal private input in_array[length];
signal private input b;
signal output out;
component c = myFunc(length);
// Pass input array
for(var i = 0; i < length; i++) {
c.in_array[i] <== in_array[i];
}
// Retrieve output array
var out_array[length];
for(var i = 0; i < length; i++) {
out_array[i] = c.out_array[i];
}
}
component main = mainFunc(A_NUMBER);
from circom.
(1)
If you were willing to do an assignment of the full array of var "result" into the array of signals "out_array", this is not allowed.
Because I will apply some arithmetic operation onto in_array
and get them back by storing values in the out_array
, how could I write codes to achieve this?
// My comprehension so far
template myFunc(length) {
signal private input in_array[length];
signal inter temp[length];
signal output out_array[length];
// Do something and store temporary results in temp[length]
for(var i = 0; i < length; i++) {
out_array[i] <== temp[i];
}
}
(2) It's my bad that I didn't know "<==" can be use in the assignment of a var
, so I used "=" to treat out_array[i] = c.out_array[i]
Precisely speaking, is it valid that write a line of code: var
<== signal
from circom.
Related Issues (20)
- Different Results for Complement Bitwise Operator HOT 1
- The problem of circom compiler bottom layer algorithm
- Add lookups via Ultragroth?
- aarch64 binary
- [ERROR] Something wrong in fr.asm
- Docs: Undefined {**} operator HOT 2
- [ERROR] snarkJS: Error: Scalar size does not match HOT 1
- [about license] used in closed-source commercial software HOT 1
- witness file compatibility
- Build faild on macos m2max cmd :circom fibonacci.circom --r1cs --wasm --sym HOT 1
- toolchain: Crates
- Different Results for Complement Bitwise Operator of Zero HOT 1
- signal a; a === 1 is a constraint or not ? HOT 1
- Insufficient memory allocation in C++ generated code
- Inconsistent Bitwise Evaluation for Field Prime HOT 1
- Error: Scalar size does not match
- Publish arm64 binary
- Add way to read more than one value at a time from WASM memory
- Circom Public Inputs Example not working, Snarkjs 0.7.4, Circom 2.1.9
- Is there any community for circom? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from circom.