iden3 / circom

zkSnark circuit compiler
GNU General Public License v3.0
1.28k stars 244 forks source link

Why does generated cpp never use return values #198

Open tim-hoffman opened 1 year ago

tim-hoffman commented 1 year ago

Instead of using the return value directly, there is a pre-allocated array (passed into the function via a pointer) where the return value is stored. What is the purpose of generating code in this way?

Sample Circom:

function identity(n) {
   return n;
}

Generated cpp:

void identity_2(Circom_CalcWit *ctx, FrElement *lvar, uint componentFather,
                FrElement *destination, int destination_size) {
  FrElement *circuitConstants = ctx->circuitConstants;
  FrElement expaux[1];
  std::string myTemplateName = "identity";
  u64 myId = componentFather;
  // return bucket
  Fr_copy(destination, &lvar[0]);
  return;
}