Skip to content

Commit

Permalink
fix modexp
Browse files Browse the repository at this point in the history
  • Loading branch information
laisolizq committed Feb 20, 2024
1 parent e07cfa7 commit eaf817d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions main/precompiled/pre-modexp.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ VAR GLOBAL modexp_returnFirstIndex
VAR GLOBAL modexp_returnIndexRem
VAR GLOBAL expLenBits
VAR GLOBAL retCopyLen
VAR GLOBAL lastBytesModexp

funcModexp:

Expand Down Expand Up @@ -282,14 +281,15 @@ finalMODEXPreturn:
32 :MSTORE(arithB), CALL(divARITH)
$ => E :MLOAD(arithRes1)
E :MSTORE(modexp_returnFirstIndex)
$ => A :MLOAD(arithRes2),JMPZ(memoryLoop)

$ => A :MLOAD(arithRes2)
A :MSTORE(modexp_returnIndexRem),JMPZ(memoryLoop)

; if Msize % 32 > 0, copy last bytes, else --> memoryLoop
A => C
$ => A :MLOAD(modexp_out+E)
32 - C => D :CALL(SHLarith)
A :MSTORE(bytesToStore)
A :MSTORE(lastBytesModexp)
A :MSTORE(modexp_out+E)
B => E
:CALL(MSTOREX) ; in: [bytesToStore, E: offset, C: length] out: [E: new offset]
E => B
Expand Down Expand Up @@ -332,7 +332,11 @@ modexpReturn:
32 :MSTORE(arithB), CALL(divARITH)
$ => A :MLOAD(arithRes2), JMPZ(returnLoop)
A => C
$ => A :MLOAD(lastBytesModexp)
$ => A :MLOAD(modexp_returnIndexRem),JMPNZ(returnInit)
E - 1 => E

returnInit:
$ => A :MLOAD(modexp_out+E)
A :MSTORE(bytesToStore)
B => E
:CALL(MSTOREX) ; in: [bytesToStore, E: offset, C: length] out: [E: new offset]
Expand Down

0 comments on commit eaf817d

Please sign in to comment.