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

develop 0.4.1 to main #58

Merged
merged 3 commits into from
Oct 9, 2022
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@0xpolygonhermez/zkevm-proverjs",
"version": "0.4.0",
"version": "0.4.1",
"description": "JS version of the zkProver.",
"main": "index.js",
"scripts": {
Expand Down
14 changes: 8 additions & 6 deletions src/sm/sm_main/sm_main_exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1200,17 +1200,19 @@ module.exports = async function execute(pols, input, rom, config = {}) {
pols.carry[i] = (a < b) ? 1n: 0n;
required.Binary.push({a: a, b: b, c: c, opcode: 2});
} else if (l.binOpcode == 3) { // SLT
let a = Scalar.e(fea2scalar(Fr, ctx.A));
if (Scalar.geq(a, twoTo255)) a = Scalar.sub(a, twoTo256);
let b = Scalar.e(fea2scalar(Fr, ctx.B));
if (Scalar.geq(b, twoTo255)) b = Scalar.sub(b, twoTo256);
const a = Scalar.e(fea2scalar(Fr, ctx.A));
const b = Scalar.e(fea2scalar(Fr, ctx.B));
const c = fea2scalar(Fr, [op0, op1, op2, op3, op4, op5, op6, op7]);
const expectedC = Scalar.lt(a, b);

const signedA = Scalar.geq(a, twoTo255) ? Scalar.sub(a, twoTo256): a;
const signedB = Scalar.geq(b, twoTo255) ? Scalar.sub(b, twoTo256): b;
const expectedC = Scalar.lt(signedA, signedB);

if (!Scalar.eq(c, expectedC)) {
throw new Error("SLT does not match");
}
pols.binOpcode[i] = 3n;
pols.carry[i] = (a < b) ? 1n : 0n;
pols.carry[i] = (signedA < signedB) ? 1n : 0n;
required.Binary.push({a: a, b: b, c: c, opcode: 3});
} else if (l.binOpcode == 4) { // EQ
const a = fea2scalar(Fr, ctx.A);
Expand Down
19 changes: 19 additions & 0 deletions test/fix/main_slt_fix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const chai = require("chai");
const assert = chai.assert;
const fs = require("fs");
const path = require("path");

const {verifyZkasm} = require("../verify_zkasm");

describe("Test Binary Counter", async function () {
this.timeout(10000000000);

it("Verify Binary SLT Fix Test", async () => {
await verifyZkasm("../zkasm/fix/main_slt_fix.zkasm", true,
{ defines: {N: 2 ** 21},
namespaces: ['Global', 'Main', 'Rom', 'Byte4', 'Binary'],
verbose: true,
color: true,
disableUnusedError: true});
});
});
25 changes: 25 additions & 0 deletions test/zkasm/fix/main_slt_fix.zkasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
start:

STEP => A
0 :ASSERT

0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFn => A
0 => B

$ :SLT,JMPC(ok_case)
fail_case:
1 => A
:JMP(check_assert)
ok_case:
2 => A
check_assert:
2 :ASSERT

end:
0 => A,B,C,D,E,CTX, SP, PC, GAS, MAXMEM, SR

finalWait:
${beforeLast()} : JMPN(finalWait)

: JMP(start)
opINVALID: