diff --git a/main/precompiled/pre-modexp.zkasm b/main/precompiled/pre-modexp.zkasm index 6e0e26d3..74103b8c 100644 --- a/main/precompiled/pre-modexp.zkasm +++ b/main/precompiled/pre-modexp.zkasm @@ -40,6 +40,7 @@ VAR GLOBAL modexp_returnIndex VAR GLOBAL modexp_returnFirstIndex VAR GLOBAL modexp_returnIndexRem VAR GLOBAL expLenBits +VAR GLOBAL retCopyLen funcModexp: @@ -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) @@ -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) @@ -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 @@ -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) diff --git a/package.json b/package.json index 56c0e7da..f3ee5835 100644 --- a/package.json +++ b/package.json @@ -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",