Skip to content

Commit

Permalink
fix pre-modexp retCallLength
Browse files Browse the repository at this point in the history
  • Loading branch information
laisolizq committed Feb 13, 2024
1 parent e6bef57 commit 71a552c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions main/precompiled/pre-modexp.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ VAR GLOBAL modexp_returnIndex
VAR GLOBAL modexp_returnFirstIndex
VAR GLOBAL modexp_returnIndexRem
VAR GLOBAL expLenBits
VAR GLOBAL retCopyLen

funcModexp:

Expand Down Expand Up @@ -265,7 +266,15 @@ save0outMod0:
finalMODEXP:
%MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)

; Get lower between retCallLength and modexp_Msize
$ => A :MLOAD(modexp_Msize)
$ => B :MLOAD(retCallLength)
$ :LT,JMPC(finalMODEXPreturn)
B => A

finalMODEXPreturn:
; write data into memory
A :MSTORE(retCopyLen)
0 => B
$ => C :MLOAD(modexp_Msize)
C :MSTORE(arithA)
Expand All @@ -282,7 +291,7 @@ finalMODEXP:
B => E
:CALL(MSTOREX) ; in: [bytesToStore, E: offset, C: length] out: [E: new offset]
E => B
$ => A :MLOAD(modexp_Msize)
$ => A :MLOAD(retCopyLen)
A - C => C :JMPZ(modexpReturn)
$ => E :MLOAD(modexp_returnFirstIndex)

Expand Down Expand Up @@ -314,6 +323,7 @@ modexpReturn:
A => CTX
E :MSTORE(retDataCTX)

$ => C :MLOAD(retCopyLen)
$ => E :MLOAD(modexp_returnFirstIndex)
$ => A :MLOAD(modexp_returnIndexRem), JMPZ(returnLoop)
A => C
Expand All @@ -323,7 +333,7 @@ modexpReturn:
B => E
:CALL(MSTOREX) ; in: [bytesToStore, E: offset, C: length] out: [E: new offset]
E => B
$ => A :MLOAD(modexp_Msize)
$ => A :MLOAD(retCopyLen)
A - C => C :JMPZ(endMODEXP)
$ => E :MLOAD(modexp_returnFirstIndex)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"devDependencies": {
"@0xpolygonhermez/zkevm-commonjs": "github:0xPolygonHermez/zkevm-commonjs#v4.0.0-fork.7",
"@0xpolygonhermez/zkevm-proverjs": "github:0xPolygonHermez/zkevm-proverjs#develop-eldelberry",
"@0xpolygonhermez/zkevm-testvectors": "github:0xPolygonHermez/zkevm-testvectors#feature/change-block-gas-limit",
"@0xpolygonhermez/zkevm-testvectors": "github:0xPolygonHermez/zkevm-testvectors#feature/test-return",
"chai": "^4.3.6",
"chalk": "^3.0.0",
"eslint": "^8.25.0",
Expand Down

0 comments on commit 71a552c

Please sign in to comment.