Skip to content

Commit

Permalink
Fixed the optimization. Moved an unused folder
Browse files Browse the repository at this point in the history
  • Loading branch information
hecmas committed Nov 29, 2023
1 parent db93ed5 commit 3d8d880
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 29 deletions.
24 changes: 8 additions & 16 deletions main/modexp/array_lib/array_div_mod_long.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,15 @@ array_div_mod_long_inALTinB_before_end:
; End of edge cases

array_div_mod_long_prepare_mul_quo_inB:
${receiveLenQuotient()} => C :JMPN(failAssert)
$0{receiveLenQuotient()} => C

; ensure C0 > 0
C - 1 :JMPN(failAssert)
; if C > %ARRAY_MAX_LEN --> does not jump to `continue_xx` label
C - %ARRAY_MAX_LEN_PLUS_ONE :JMPN(continue_array_div_mod_long_prepare_mul_quo_inB, failAssert)

continue_array_div_mod_long_prepare_mul_quo_inB:
; The received length must be between 1 and %ARRAY_MAX_LEN
C - 1 => RR :JMPN(failAssert) ; If C = 0, then fail
%ARRAY_MAX_LEN - C :JMPN(failAssert) ; If C > %ARRAY_MAX_LEN, then fail
; From here, 1 <= C <= %ARRAY_MAX_LEN

; To avoid non-determinism, we must ensure that the quotient is trimmed
; i.e., that its last chunk is not 0
C - 1 => RR
${receiveQuotientChunk(RR)} => A
0 => B
0 :EQ
Expand Down Expand Up @@ -201,19 +197,15 @@ array_div_mod_long_mul_quo_inB:
%MAX_CNT_STEPS - STEP - 14 :JMPN(outOfCountersStep)

; Check the remainder
${receiveLenRemainder()} => D
$0{receiveLenRemainder()} => D

; 1] The received length must be between 1 and %ARRAY_MAX_LEN
D => A
0 => B
0 :EQ
%ARRAY_MAX_LEN_PLUS_ONE => B
1 :LT
; From here, 1 <= C <= %ARRAY_MAX_LEN
D - 1 => E :JMPN(failAssert) ; If D = 0, then fail
%ARRAY_MAX_LEN - D :JMPN(failAssert) ; If D > %ARRAY_MAX_LEN, then fail
; From here, 1 <= D <= %ARRAY_MAX_LEN

; 2] To avoid non-determinism, we must ensure that the remainder is trimmed
; i.e., that its last chunk is not 0
D - 1 => E
${receiveRemainderChunk(E)} => A
0 => B
0 :EQ
Expand Down
15 changes: 4 additions & 11 deletions main/modexp/array_lib/array_div_mod_short.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -134,28 +134,21 @@ array_div_mod_short_inALTinB:
; End of edge cases

array_div_mod_short_prepare_mul_quo_inB:
; C = [c7, c6, ..., c0]
; JMPN instruction assures c0 is within the range [0, 2**32 - 1]
${receiveLenQuotient_short()} => C :JMPN(failAssert)
$0{receiveLenQuotient_short()} => C

; ensure C0 > 0
C - 1 :JMPN(failAssert)
; if C > %ARRAY_MAX_LEN --> does not jump to `continue_xx` label
C - %ARRAY_MAX_LEN_PLUS_ONE :JMPN(continue_array_div_mod_short_prepare_mul_quo_inB, failAssert)

continue_array_div_mod_short_prepare_mul_quo_inB:
; The received length must be between 1 and %ARRAY_MAX_LEN
C - 1 => RR :JMPN(failAssert) ; If C = 0, then fail
%ARRAY_MAX_LEN - C :JMPN(failAssert) ; If C > %ARRAY_MAX_LEN, then fail
; From here, 1 <= C <= %ARRAY_MAX_LEN

; To avoid non-determinism, we must ensure that the quotient is trimmed
; i.e., that its last chunk is not 0
C - 1 => RR
${receiveQuotientChunk_short(RR)} => A
0 => B
0 :EQ
; From here, the quotient is trimmed

C :MSTORE(array_div_mod_short_len_quo)

C => RR

%MAX_CNT_STEPS - STEP - 5*%ARRAY_MAX_LEN - 4 :JMPN(outOfCountersStep)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
"url": "https://github.com/0xPolygonHermez/zkevm-rom.git"
},
"dependencies": {
"@0xpolygonhermez/zkasmcom": "https://github.com/0xPolygonHermez/zkasmcom.git#feature/fork-etrog",
"@0xpolygonhermez/zkasmcom": "https://github.com/0xPolygonHermez/zkasmcom.git#feature/infree0",
"yargs": "^17.5.1"
},
"devDependencies": {
"@0xpolygonhermez/zkevm-commonjs": "github:0xPolygonHermez/zkevm-commonjs#feature/fork-etrog",
"@0xpolygonhermez/zkevm-proverjs": "github:0xPolygonHermez/zkevm-proverjs-internal#feature/fork-etrog",
"@0xpolygonhermez/zkevm-proverjs": "github:0xPolygonHermez/zkevm-proverjs-internal#feature/infree0",
"@0xpolygonhermez/zkevm-testvectors": "github:0xPolygonHermez/zkevm-testvectors-internal#feature/fork-etrog",
"chai": "^4.3.6",
"chalk": "^3.0.0",
Expand Down
5 changes: 5 additions & 0 deletions test/testArrayArith.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,11 @@ outOfCountersStep:
outOfCountersArith:
${dump(CNT_ARITH)} :JMP(end)

;@info function to force a failed assert
failAssert:
1 => A
2 :ASSERT

end:

$ => A :MLOAD(initial_A)
Expand Down
5 changes: 5 additions & 0 deletions test/testModExp.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,11 @@ outOfCountersStep:
outOfCountersArith:
${dump(CNT_ARITH)} :JMP(end)

;@info function to force a failed assert
failAssert:
1 => A
2 :ASSERT

end:

$ => A :MLOAD(initial_A)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 3d8d880

Please sign in to comment.