Skip to content

Commit

Permalink
fix incCounter constraint on paddings and add one specific test.
Browse files Browse the repository at this point in the history
  • Loading branch information
zkronos73 committed Dec 20, 2023
1 parent 6162488 commit 36aba2f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 7 deletions.
3 changes: 1 addition & 2 deletions pil/padding_kk.pil
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ namespace PaddingKK(%N);
// if lastHash=0 && lastBLock=1 then incCounter'=incCounter+1
// if lastHash=1 && lastBlock=1 then incCounter'=1
incCounter' = incCounter*(1-lastBlock) + (incCounter +1)*(lastBlock-lastHash) + lastHash;
incCounter * Global.L1 = 0;

(incCounter - 1) * Global.L1 = 0;

// chunkReader generator

Expand Down
4 changes: 1 addition & 3 deletions pil/padding_pg.pil
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ namespace PaddingPG(%N);
// if lastHash=0 && lastBLock=1 then incCounter'=incCounter+1
// if lastHash=1 && lastBlock=1 then incCounter'=1
incCounter' = incCounter*(1-lastBlock) + (incCounter +1)*(lastBlock-lastHash) + lastHash;
incCounter * Global.L1 = 0;


(incCounter - 1) * Global.L1 = 0;

pol commit len;
len' * lastHash = rem' * lastHash;
Expand Down
3 changes: 1 addition & 2 deletions pil/padding_sha256.pil
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ namespace PaddingSha256(%N);
// if lastHash=0 && lastBLock=1 then incCounter'=incCounter+1
// if lastHash=1 && lastBlock=1 then incCounter'=1
incCounter' = incCounter*(1-lastBlock) + (incCounter +1)*(lastBlock-lastHash) + lastHash;
incCounter * Global.L1 = 0;

(incCounter - 1) * Global.L1 = 0;

// chunkReader generator

Expand Down
57 changes: 57 additions & 0 deletions test/sm/sm_paddings_empty.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const chai = require('chai');

const { assert } = chai;
const { F1Field } = require('ffjavascript');

const {
newConstantPolsArray, newCommitPolsArray, compile, verifyPil,
} = require('pilcom');

const smPaddingSha256 = require('../../src/sm/sm_padding_sha256');
const smPaddingPG = require('../../src/sm/sm_padding_pg');
const smPaddingKK = require('../../src/sm/sm_padding_kk');
const smGlobal = require('../../src/sm/sm_global');

// input = [];

const input = [];

describe('test paddings (poseidon, keccak, sha256) empty', async function () {
this.timeout(10000000);
it('no hash test', async () => {
const Fr = new F1Field('0xFFFFFFFF00000001');
const pil = await compile(Fr, 'pil/main.pil', null, {
defines: { N: 2 ** 18 },
namespaces: ['Global','PaddingPG','PaddingKK','PaddingSha256']
});
const constPols = newConstantPolsArray(pil);
const cmPols = newCommitPolsArray(pil);
await smPaddingPG.buildConstants(constPols.PaddingPG);
await smPaddingKK.buildConstants(constPols.PaddingKK);
await smPaddingSha256.buildConstants(constPols.PaddingSha256);
await smGlobal.buildConstants(constPols.Global);

await smPaddingPG.execute(cmPols.PaddingPG, []);
await smPaddingKK.execute(cmPols.PaddingKK, []);
await smPaddingSha256.execute(cmPols.PaddingSha256, []);

for (let i = 0; i < cmPols.$$array.length; i++) {
const arr = cmPols.$$array[i];
for (let j = 0; j < arr.length; j++) {
assert(typeof (arr[j]) === 'bigint', `pol: ${i} w: ${j} desc: ${JSON.stringify(cmPols.$$defArray[i], null, 1)}`);
}
}

const res = await verifyPil(Fr, pil, cmPols, constPols);

if (res.length !== 0) {
// eslint-disable-next-line no-console
console.log('Pil does not pass');
for (let i = 0; i < res.length; i++) {
// eslint-disable-next-line no-console
console.log(res[i]);
}
assert(0);
}
});
});

0 comments on commit 36aba2f

Please sign in to comment.