Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circuit Abstraction #1

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,473 changes: 0 additions & 4,473 deletions package-lock.json

This file was deleted.

42 changes: 23 additions & 19 deletions src/main_templates/assign_stark_inputs.circom.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,69 @@
<% if(starkInfo.airgroupId !== undefined) { -%>
<% airgroupId = starkInfo.airgroupId; -%>
<% } -%>

-%>
<% let prefix_ = prefix !== "" ? `${prefix}_` : ""; -%>

-%>
<% if(!options.final && !isNaN(airgroupId)) { -%>
component <%- componentName %> = StarkVerifier<%- airgroupId %>();
<% } else { -%>
component <%- componentName %> = StarkVerifier();
<% } -%>

// --> Assign the previous STARK proof data
<% if(options.addPublics && nPublics > 0) { -%>
for (var i=0; i< <%- nPublics %>; i++) {
<%- componentName %>.publics[i] <== <%- prefix_ %>publics[i];
<%- componentName %>.publics[i] <== <%- prefix_ %>publics[i];

}
<% } -%>

<% if(starkInfo.airgroupValuesMap.length > 0) { -%>
<%- componentName %>.airgroupvalues <== <%- prefix_ %>airgroupvalues;
<% } -%>

-%>
<% if(starkInfo.airValuesMap.length > 0) { -%>
<%- componentName %>.airvalues <== <%- prefix_ %>airvalues;
<% } -%>

-%>
<% if(starkInfo.airgroupValuesMap.length > 0) { -%>
<%- componentName %>.airgroupValues <== <%- prefix_ %>airgroupValues;
<% } -%>
-%>
<% if(starkInfo.proofValuesMap.length > 0) { -%>
<%- componentName %>.proofvalues <== <%- prefix_ %>proofvalues;
<% } -%>

-%>
<% for (let s=1; s<=starkInfo.nStages + 1; ++s) { -%>
<%- componentName %>.root<%- s %> <== <%- prefix_ %>root<%- s %>;
<% } -%>

<%- componentName %>.evals <== <%- prefix_ %>evals;

<% for (let s=1; s<starkInfo.starkStruct.steps.length; s++) { -%>
<%- componentName %>.s<%- s %>_root <== <%- prefix_ %>s<%- s %>_root;
<% } -%>

<%- componentName %>.finalPol <== <%- prefix_ %>finalPol;

<%- componentName %>.s0_valsC <== <%- prefix_ %>s0_valsC;
<%- componentName %>.s0_siblingsC <== <%- prefix_ %>s0_siblingsC;

<% for(let i = 0; i < starkInfo.customCommits.length; ++i) { -%>
<%- componentName %>.s0_vals_<%- starkInfo.customCommits[i].name %>_0 <== <%- prefix_ %>s0_vals_<%- starkInfo.customCommits[i].name %>_0;
<%- componentName %>.s0_siblings_<%- starkInfo.customCommits[i].name %>_0 <== <%- prefix_ %>s0_siblings_<%- starkInfo.customCommits[i].name %>_0;
<% } -%>

-%>
<% for (let s=1; s<=starkInfo.nStages + 1; ++s) { -%>
<% if (starkInfo.mapSectionsN[`cm${s}`] > 0) { -%>
<%- componentName %>.s0_vals<%- s %> <== <%- prefix_ %>s0_vals<%- s %>;
<%- componentName %>.s0_siblings<%- s %> <== <%- prefix_ %>s0_siblings<%- s %>;
<% } -%>
<% } -%>

<% for (let s=1; s<starkInfo.starkStruct.steps.length; s++) { -%>
<%- componentName %>.s<%- s %>_root <== <%- prefix_ %>s<%- s %>_root;
<% } -%>
<% for (let s=1; s<starkInfo.starkStruct.steps.length; s++) { -%>
<%- componentName %>.s<%- s %>_vals <== <%- prefix_ %>s<%- s %>_vals;
<%- componentName %>.s<%- s %>_siblings <== <%- prefix_ %>s<%- s %>_siblings;
<% } -%>

<%- componentName %>.finalPol <== <%- prefix_ %>finalPol;

<% } -%>
-%>
<% if(options.setEnableInput) { -%>
<% let enableInput = options.setEnableInput === true ? 1 : options.setEnableInput -%>
<%- componentName %>.enable <== <%- enableInput %>;
<% } -%>
<% } -%>
-%>
50 changes: 31 additions & 19 deletions src/main_templates/define_stark_inputs.circom.ejs
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
<% let prefix_ = prefix !== "" ? `${prefix}_` : ""; -%>
<% if(options.addPublics && nPublics > 0) { -%>
signal input <%- prefix_ %>publics[<%- nPublics %>];

<% } -%>
<% if(starkInfo.airgroupValuesMap && starkInfo.airgroupValuesMap.length > 0) { -%>
signal input <%- prefix_ %>airgroupvalues[<%- starkInfo.airgroupValuesMap.length %>][3];
-%>
<% if((starkInfo.airValuesMap && starkInfo.airValuesMap.length > 0) || (starkInfo.airgroupValuesMap && starkInfo.airgroupValuesMap.length > 0) || (starkInfo.proofValuesMap && starkInfo.proofValuesMap.length > 0)) { -%>
// One-dimensional elements
<% } -%>

<% if(starkInfo.airValuesMap && starkInfo.airValuesMap.length > 0) { -%>
signal input <%- prefix_ %>airvalues[<%- starkInfo.airValuesMap.length %>][3];
<% } -%>

-%>
<% if(starkInfo.airgroupValuesMap && starkInfo.airgroupValuesMap.length > 0) { -%>
signal input <%- prefix_ %>airgroupValues[<%- starkInfo.airgroupValuesMap.length %>][3];
<% } -%>
-%>
<% if(starkInfo.proofValuesMap && starkInfo.proofValuesMap.length > 0) { -%>
signal input <%- prefix_ %>proofvalues[<%- starkInfo.proofValuesMap.length %>][3];
<% } -%>

-%>
// Merkle tree roots of the witness columns at each stage
<% for (let s=1; s<=starkInfo.nStages + 1; ++s) { -%>
<% if(starkInfo.starkStruct.verificationHashType === "BN128") { -%>
signal input <%- prefix_ %>root<%- s %>;
Expand All @@ -22,8 +28,23 @@
<% } -%>
<% } -%>

signal input <%- prefix_ %>evals[<%- starkInfo.evMap.length %>][3]; // Evaluations of the set polynomials at a challenge value z and gz
// Set of evaluations around the out-of-domain sample
signal input <%- prefix_ %>evals[<%- starkInfo.evMap.length %>][3];

// Merkle tree roots of the polynomials for each of the <%- starkInfo.starkStruct.steps.length %> layers of the FRI commit phase, except the last one
<% for (let s=1; s<starkInfo.starkStruct.steps.length; s++) { -%>
<% if(starkInfo.starkStruct.verificationHashType === "BN128") { -%>
signal input <%- prefix_ %>s<%- s %>_root;
<% } else { -%>
signal input <%- prefix_ %>s<%- s %>_root[4];
<% } -%>
<% } -%>

// Polynomial sent in clear at layer <%- starkInfo.starkStruct.steps.length %> of the FRI commit phase
signal input <%- prefix_ %>finalPol[<%- 1 << parseInt(starkInfo.starkStruct.steps[starkInfo.starkStruct.steps.length-1].nBits) %>][3];

// Set of evaluations "vals" and Merkle proofs "siblings" of all involved polynomials,
// for each of the <%- starkInfo.starkStruct.nQueries %> queries performed during the FRI query phase
signal input <%- prefix_ %>s0_valsC[<%- starkInfo.starkStruct.nQueries %>][<%- starkInfo.nConstants %>];
<% if(starkInfo.starkStruct.verificationHashType === "BN128") { -%>
signal input <%- prefix_ %>s0_siblingsC[<%- starkInfo.starkStruct.nQueries %>][<%- Math.floor((parseInt(starkInfo.starkStruct.steps[0].nBits) - 1)/Math.log2(starkInfo.starkStruct.merkleTreeArity))+1 %>][<%- starkInfo.starkStruct.merkleTreeArity %>];
Expand All @@ -39,7 +60,7 @@
signal input <%- prefix_ %>s0_siblings_<%- starkInfo.customCommits[i].name %>_0[<%- starkInfo.starkStruct.nQueries %>][<%- starkInfo.starkStruct.steps[0].nBits %>][4];
<% } -%>
<% } -%>

-%>
<% for (let s=1; s<=starkInfo.nStages + 1; ++s) { -%>
<% if (starkInfo.mapSectionsN[`cm${s}`] > 0) { -%>
signal input <%- prefix_ %>s0_vals<%- s %>[<%- starkInfo.starkStruct.nQueries %>][<%- starkInfo.mapSectionsN[`cm${s}`] %>];
Expand All @@ -50,22 +71,13 @@
<% } -%>
<% } -%>
<% } -%>

<% for (let s=1; s<starkInfo.starkStruct.steps.length; s++) { -%>
<% if(starkInfo.starkStruct.verificationHashType === "BN128") { -%>
signal input <%- prefix_ %>s<%- s %>_root;
<% } else { -%>
signal input <%- prefix_ %>s<%- s %>_root[4];
<% } -%>
<% } -%>

-%>
<% for (let s=1; s< starkInfo.starkStruct.steps.length; s++) { -%>
signal input <%- prefix_ %>s<%- s %>_vals[<%- starkInfo.starkStruct.nQueries %>][<%- (1 << parseInt(starkInfo.starkStruct.steps[s-1].nBits - starkInfo.starkStruct.steps[s].nBits))*3 %>];
<% if(starkInfo.starkStruct.verificationHashType === "BN128") { -%>
signal input <%- prefix_ %>s<%- s %>_siblings[<%- starkInfo.starkStruct.nQueries %>][<%- Math.floor((parseInt(starkInfo.starkStruct.steps[s].nBits) -1) /Math.log2(starkInfo.starkStruct.merkleTreeArity)) +1 %>][<%- starkInfo.starkStruct.merkleTreeArity %>];
<% } else { -%>
signal input <%- prefix_ %>s<%- s %>_siblings[<%- starkInfo.starkStruct.nQueries %>][<%- starkInfo.starkStruct.steps[s].nBits %>][4];
<% } -%>
<% } -%>

signal input <%- prefix_ %>finalPol[<%- 1 << parseInt(starkInfo.starkStruct.steps[starkInfo.starkStruct.steps.length-1].nBits) %>][3];
<% } -%>
-%>
25 changes: 25 additions & 0 deletions src/main_templates/vadcop/acc_vadcop_inputs.circom.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<% if(vadcopInfo.air_groups.length > 1 || vadcopInfo.airs[0].length > 1) { -%>
<% for (let i = 0; i < vadcopInfo.numChallenges.length + 1; ++i) { -%>
<%- prefix %>_root<%- i+1 %> <== AccumulateValuesNull()(<%- prefix1 %>_root<%- i+1 %>, <%- prefix2 %>_root<%- i+1 %>, <%- prefix1%>_isNull, <%- prefix2%>_isNull);
<% } -%>

<%- prefix %>_evalsHash <== AccumulateValuesNull()(<%- prefix1 %>_evalsHash, <%- prefix2 %>_evalsHash, <%- prefix1%>_isNull, <%- prefix2%>_isNull);

<% for(let i = 1; i < vadcopInfo.stepsFRI.length; i++) { -%>
<%- prefix %>_s<%- i %>_root <== AccumulateValuesNull()(<%- prefix1 %>_s<%- i %>_root, <%- prefix2 %>_s<%- i %>_root, <%- prefix1%>_isNull, <%- prefix2%>_isNull);
<% } -%>

<%- prefix %>_finalPolHash <== AccumulateValuesNull()(<%- prefix1 %>_finalPolHash, <%- prefix2 %>_finalPolHash, <%- prefix1%>_isNull, <%- prefix2%>_isNull);
<% } else { -%>
<% for (let i = 0; i < vadcopInfo.numChallenges.length + 1; ++i) { -%>
<%- prefix %>_root<%- i+1 %> <== AccumulateValues()(<%- prefix1 %>_root<%- i+1 %>, <%- prefix2 %>_root<%- i+1 %>);
<% } -%>

<%- prefix %>_evalsHash <== AccumulateValues()(<%- prefix1 %>_evalsHash, <%- prefix2 %>_evalsHash);

<% for(let i = 1; i < vadcopInfo.stepsFRI.length; i++) { -%>
<%- prefix %>_s<%- i %>_root <== AccumulateValues()(<%- prefix1 %>_s<%- i %>_root, <%- prefix2 %>_s<%- i %>_root);
<% } -%>

<%- prefix %>_finalPolHash <== AccumulateValues()(<%- prefix1 %>_finalPolHash, <%- prefix2 %>_finalPolHash);
<% } -%>
24 changes: 24 additions & 0 deletions src/main_templates/vadcop/agg_airgroup_values.circom.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<%- prefix %>_circuitType <== <%- (vadcopInfo.air_groups.length > 1 || vadcopInfo.airs[0].length > 1) ? 1 : 0 %>;

<% if(vadcopInfo.aggTypes[airgroupId].length > 0) { -%>
<%- prefix %>_aggregationTypes <== aggregationTypes;
signal {binary} aggTypes[<%- vadcopInfo.aggTypes[airgroupId].length %>];
for(var i = 0; i < <%- vadcopInfo.aggTypes[airgroupId].length %>; i++) {
<%- prefix %>_aggregationTypes[i] * (<%- prefix %>_aggregationTypes[i] - 1) === 0;
aggTypes[i] <== <%- prefix %>_aggregationTypes[i];
}
<% } -%>

<% if(vadcopInfo.air_groups.length > 1 || vadcopInfo.airs[0].length > 1) { -%>
<% if(vadcopInfo.aggTypes[airgroupId].length > 0) { -%>
for(var i = 0; i < <%- vadcopInfo.aggTypes[airgroupId].length %>; i++) {
<%- prefix %>_airgroupValues[i] <== AggregateAirgroupValuesNull()(<%- prefix1 %>_airgroupValues[i], <%- prefix2 %>_airgroupValues[i], aggTypes[i], <%- prefix1%>_isNull, <%- prefix2%>_isNull);
}
<% } -%>
<% } else { -%>
<% if(vadcopInfo.aggTypes[airgroupId].length > 0) { -%>
for(var i = 0; i < <%- vadcopInfo.aggTypes[airgroupId].length %>; i++) {
<%- prefix %>_airgroupValues[i] <== AggregateAirgroupValues()(<%- prefix1 %>_airgroupValues[i], <%- prefix2 %>_airgroupValues[i], aggTypes[i]);
}
<% } -%>
<% } -%>
43 changes: 0 additions & 43 deletions src/main_templates/vadcop/agg_vadcop_inputs.circom.ejs

This file was deleted.

15 changes: 8 additions & 7 deletions src/main_templates/vadcop/assign_vadcop_inputs.circom.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<% let prefix_ = prefix ? `${prefix}_` : ""; -%>
<% let prefixStark_ = prefixStark ? `${prefixStark}_` : ""; -%>
<% let nPublicsInps = 0; -%>

-%>
// --> Assign the VADCOP proof data
<%- componentName %>.publics[<%- nPublicsInps++ %>] <== <%- prefix_ %>circuitType;

<% if(vadcopInfo.aggTypes[airgroupId].length > 0) { -%>
Expand All @@ -11,19 +12,17 @@
<% nPublicsInps += vadcopInfo.aggTypes[airgroupId].length ; -%>

for(var i = 0; i < <%- vadcopInfo.aggTypes[airgroupId].length %>; i++) {
<%- componentName %>.publics[<%- nPublicsInps %> + 3*i] <== <%- prefix_ %>airgroupvalues[i][0];
<%- componentName %>.publics[<%- nPublicsInps %> + 3*i + 1] <== <%- prefix_ %>airgroupvalues[i][1];
<%- componentName %>.publics[<%- nPublicsInps %> + 3*i + 2] <== <%- prefix_ %>airgroupvalues[i][2];
<%- componentName %>.publics[<%- nPublicsInps %> + 3*i] <== <%- prefix_ %>airgroupValues[i][0];
<%- componentName %>.publics[<%- nPublicsInps %> + 3*i + 1] <== <%- prefix_ %>airgroupValues[i][1];
<%- componentName %>.publics[<%- nPublicsInps %> + 3*i + 2] <== <%- prefix_ %>airgroupValues[i][2];
}
<% nPublicsInps += 3*vadcopInfo.aggTypes[airgroupId].length ; -%>
<% } -%>


<% for (let i = 0; i < vadcopInfo.numChallenges.length + 1; i++) { -%>
for(var i = 0; i < 4; i++) {
<%- componentName %>.publics[<%- nPublicsInps %> + i] <== <%- prefix_ %>root<%- i+1 %>[i];
}

<% nPublicsInps += 4 -%>
<% } -%>

Expand All @@ -45,12 +44,14 @@
<% nPublicsInps += 4 -%>

<% if(vadcopInfo.nPublics > 0) { -%>
// --> Assign the public inputs
for(var i = 0; i < <%- vadcopInfo.nPublics %>; i++) {
<%- componentName %>.publics[<%- nPublicsInps %> + i] <== publics[i];
}
<% nPublicsInps += vadcopInfo.nPublics -%>
<% } -%>

// --> Assign the VADCOP data
for(var i = 0; i < <%- vadcopInfo.numChallenges.reduce((nc, acc) => nc + acc, 0) + 4 %>; i++) {
<%- componentName %>.publics[<%- nPublicsInps %> + 3*i] <== challenges[i][0];
<%- componentName %>.publics[<%- nPublicsInps %> + 3*i+1] <== challenges[i][1];
Expand All @@ -64,7 +65,7 @@
<%- componentName %>.publics[<%- nPublicsInps %> + 3*i+2] <== challengesFRISteps[i][2];
}
<% nPublicsInps += 3*(vadcopInfo.stepsFRI.length); -%>

-%>
<% if(options.setEnableInput) { -%>
signal {binary} <%- prefix_ %>isNull <== IsZero()(<%- prefix_ %>circuitType);

Expand Down
9 changes: 5 additions & 4 deletions src/main_templates/vadcop/define_vadcop_inputs.circom.ejs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<% let signalType = options.isInput ? "input" : "output" -%>
<% let prefix_ = prefix ? `${prefix}_` : ""; -%>

-%>
signal <%- signalType %> <%- prefix_ %>circuitType;
<% if(Array.isArray(options.publicsNames)) options.publicsNames.push(`${prefix_}circuitType`) -%>

<% if(vadcopInfo.aggTypes[airgroupId].length > 0) { -%>
<% if(!options.isAggregation) { -%>
signal <%- signalType %> <%- prefix_ %>aggregationTypes[<%- vadcopInfo.aggTypes[airgroupId].length %>];
<% if(Array.isArray(options.publicsNames)) options.publicsNames.push(`${prefix_}aggregationTypes`) -%>
<% } -%>
signal <%- signalType %> <%- prefix_ %>airgroupvalues[<%- vadcopInfo.aggTypes[airgroupId].length %>][3];
<% if(Array.isArray(options.publicsNames)) options.publicsNames.push(`${prefix_}airgroupvalues`) -%>
<% } -%>

signal <%- signalType %> <%- prefix_ %>airgroupValues[<%- vadcopInfo.aggTypes[airgroupId].length %>][3];
<% if(Array.isArray(options.publicsNames)) options.publicsNames.push(`${prefix_}airgroupValues`) -%>
<% } -%>

<% for (let i = 0; i < vadcopInfo.numChallenges.length + 1; ++i) { -%>
signal <%- signalType %> <%- prefix_ %>root<%- i + 1 %>[4];
Expand All @@ -29,3 +29,4 @@

signal <%- signalType %> <%- prefix_ %>finalPolHash[4];
<% if(Array.isArray(options.publicsNames)) options.publicsNames.push(`${prefix_}finalPolHash`) -%>
-%>
Loading