Skip to content

Commit

Permalink
Updating starkinfo so that sectionPos are all ordered
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerTaule committed Jul 3, 2024
1 parent ffceb07 commit 73d3887
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 14 deletions.
11 changes: 11 additions & 0 deletions src/pil_info/imPolsCalculation/imPolynomials.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,27 @@ module.exports.addIntermediatePolynomials = function addIntermediatePolynomials(
res.nImPols = res.imExpsList.length;
res.nConstraints += res.nImPols;

let nImPolsDim1 = 0;
let nImPolsDim3 = 0;
console.log("Checking that intermediate polynomials have degree less than qDeg + 1");
for (let i=0; i<imExps.length; i++) {
const expId = imExps[i];

if(expressions[expId].dim === 3) {
nImPolsDim3 += 1;
} else {
nImPolsDim1 += 1;
}
const imPolDeg = module.exports.calculateExpDeg(expressions, expressions[expId], imExps);
if(imPolDeg > qDeg + 1) {
throw new Error(`Intermediate polynomial with id: ${expId} has a higher degree (${imPolDeg}) than the maximum allowed degree (${qDeg + 1})`);
}
}

console.log(`nImPols in the basefield: ${nImPolsDim1}`)
console.log(`nImPols in the extended field: ${nImPolsDim3}`)
console.log(`Total imPols columns in the base field: ${nImPolsDim1 + 3*nImPolsDim3}`);

console.log("Adding intermediate polynomials to the expressions and constraints.");
for (let i=0; i<imExps.length; i++) {
res.imExp2cm[res.imExpsList[i]] = res.nCommitments++;
Expand Down
4 changes: 2 additions & 2 deletions src/pil_info/libs/grandProductConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ module.exports.grandProductConnection = function grandProductConnection(res, pil
const c1 = E.mul(l1, E.sub(z, E.number(1)));
c1.deg=2;
ciCtx.c1Id = pil.expressions.length;
c1.stage = 3;
c1.stage = 4;
pil.expressions.push(c1);
pil.polIdentities.push({e: ciCtx.c1Id});

const c2 = E.sub( E.mul(zp, E.exp( ciCtx.denId )), E.mul(z, E.exp( ciCtx.numId )));
c2.deg=2;
c2.stage = 3;
c2.stage = 4;
ciCtx.c2Id = pil.expressions.length;
pil.expressions.push(c2);
pil.polIdentities.push({e: ciCtx.c2Id});
Expand Down
2 changes: 1 addition & 1 deletion src/pil_info/libs/grandProductPermutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module.exports.grandProductPermutation = function grandProductPermutation(res,pi

const c2 = E.sub( E.mul(zp, E.exp( peCtx.denId )), E.mul(z, E.exp( peCtx.numId )));
c2.deg=2;
c2.stage = 3;
c2.stage = 4;
peCtx.c2Id = pil.expressions.length;
pil.expressions.push(c2);
pil.polIdentities.push({e: peCtx.c2Id});
Expand Down
4 changes: 2 additions & 2 deletions src/pil_info/libs/grandProductPlookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module.exports.grandProductPlookup = function grandProductPlookup(res, pil) {

const c1 = E.mul(l1, E.sub(z, E.number(1)));
c1.deg=2;
c1.stage = 3;
c1.stage = 4;
puCtx.c1Id = pil.expressions.length;
pil.expressions.push(c1);
pil.polIdentities.push({e: puCtx.c1Id});
Expand Down Expand Up @@ -144,7 +144,7 @@ module.exports.grandProductPlookup = function grandProductPlookup(res, pil) {

const c2 = E.sub( E.mul(zp, den), E.mul(z, num) );
c2.deg=2;
c2.stage = 3;
c2.stage = 4;
puCtx.c2Id = pil.expressions.length;
pil.expressions.push(c2);
pil.polIdentities.push({e: puCtx.c2Id});
Expand Down
22 changes: 13 additions & 9 deletions src/pil_info/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,18 +335,22 @@ module.exports = function map(res, expressions) {
function mapSections(res) {
Object.keys(res.mapSections).forEach((s) => {
let p = 0;
for (let e of [1,3]) {
for (let i=0; i<res.varPolMap.length; i++) {
const pp = res.varPolMap[i];
if ((pp.section == s) && (pp.dim==e)) {
pp.sectionPos = p;
p += e;
res.mapSectionsN1[s] = 0;
res.mapSectionsN3[s] = 0
for (let i=0; i<res.varPolMap.length; i++) {
const pp = res.varPolMap[i];
if(pp.section === s) {
pp.sectionPos = p;
if(pp.dim == 1) {
res.mapSectionsN1[s] += 1;
p += 1;
} else {
res.mapSectionsN3[s] += 3;
p += 3;
}
}
if (e==1) res.mapSectionsN1[s] = p;
if (e==3) res.mapSectionsN[s] = p;
}
res.mapSectionsN3[s] = (res.mapSectionsN[s] - res.mapSectionsN1[s] ) / 3;
res.mapSectionsN[s] = p;
});
}

Expand Down
1 change: 1 addition & 0 deletions test/stark/stark_permutation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe("test plookup sm", async function () {

const setup = await starkSetup(constPols, pil, starkStruct);

buildCHelpers(setup.starkInfo,"tmp/holi.hpp", "test", "tmp/holi.bin");
const resP = await starkGen(cmPols, constPols, setup.constTree, setup.starkInfo);

const resV = await starkVerify(resP.proof, resP.publics, setup.constRoot, setup.starkInfo);
Expand Down

0 comments on commit 73d3887

Please sign in to comment.