diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index ed4e69b8..725ed920 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -6,7 +6,7 @@ name: Test executor inputs on: workflow_dispatch: pull_request: - branches: [main, develop, develop-etrog, feature/fork-etrog, feature/l1-info-tree] + branches: [main, develop, develop-no-opt, develop-feijoa] jobs: build: @@ -32,7 +32,7 @@ jobs: npm run test:zkasm - name: Generate tests run: | - npm run test:gen + node tools/parallel-testing/gen-parallel-tests.js - name: Run tests run: | export NUM_CPUS=31 diff --git a/main/constants.zkasm b/main/constants.zkasm index 2d6b650a..d177f2df 100644 --- a/main/constants.zkasm +++ b/main/constants.zkasm @@ -4,9 +4,9 @@ CONSTL %ADDRESS_SYSTEM = 0x000000000000000000000000000000005ca1ab1en CONST %MAX_STACK_SIZE = 1024 CONST %BATCH_DIFFICULTY = 0 CONST %TX_GAS_LIMIT = 30000000 -CONSTL %BLOCK_GAS_LIMIT = 2**64-1 +CONSTL %BLOCK_GAS_LIMIT = 2**50 CONST %MAX_MEM_EXPANSION_BYTES = 0x3fffe0 -CONST %FORK_ID = 7 +CONST %FORK_ID = 8 CONST %L1INFO_TREE_LEVELS = 32 CONST %CALLDATA_RESERVED_CTX = 1 CONSTL %FOUR_GOLDILOCKS = 0xffffffff00000001ffffffff00000001ffffffff00000001ffffffff00000001n diff --git a/main/load-tx-rlp.zkasm b/main/load-tx-rlp.zkasm index b7f846bf..18e4e2e8 100644 --- a/main/load-tx-rlp.zkasm +++ b/main/load-tx-rlp.zkasm @@ -58,7 +58,7 @@ loadTx_rlp_continue: ; A new hash with position 0 is started 0 => HASHPOS A :HASHK(E) - A - 0xc0 :JMPN(invalidTxRLP) + A - 0xc1 :JMPN(invalidTxRLP) A - 0xf8 :JMPN(shortList) ; do not allow lists over 2**24 bytes length ; Transaction could not have more than 120.000 due to smart contract limitation (keccaks counters) diff --git a/main/map-opcodes.zkasm b/main/map-opcodes.zkasm index 720c41fa..f4479165 100644 --- a/main/map-opcodes.zkasm +++ b/main/map-opcodes.zkasm @@ -112,38 +112,38 @@ mapping_opcodes: :JMP(opINVALID) ; 0x5D :JMP(opINVALID) ; 0x5E :JMP(opPUSH0) ; 0x5F - :JMP(opPUSH1) ; 0x60 - :JMP(opPUSH2) ; 0x61 - :JMP(opPUSH3) ; 0x62 - :JMP(opPUSH4) ; 0x63 - :JMP(opPUSH5) ; 0x64 - :JMP(opPUSH6) ; 0x65 - :JMP(opPUSH7) ; 0x66 - :JMP(opPUSH8) ; 0x67 - :JMP(opPUSH9) ; 0x68 - :JMP(opPUSH10) ; 0x69 - :JMP(opPUSH11) ; 0x6a - :JMP(opPUSH12) ; 0x6b - :JMP(opPUSH13) ; 0x6c - :JMP(opPUSH14) ; 0x6d - :JMP(opPUSH15) ; 0x6e - :JMP(opPUSH16) ; 0x6f - :JMP(opPUSH17) ; 0x70 - :JMP(opPUSH18) ; 0x71 - :JMP(opPUSH19) ; 0x72 - :JMP(opPUSH20) ; 0x73 - :JMP(opPUSH21) ; 0x74 - :JMP(opPUSH22) ; 0x75 - :JMP(opPUSH23) ; 0x76 - :JMP(opPUSH24) ; 0x77 - :JMP(opPUSH25) ; 0x78 - :JMP(opPUSH26) ; 0x79 - :JMP(opPUSH27) ; 0x7a - :JMP(opPUSH28) ; 0x7b - :JMP(opPUSH29) ; 0x7c - :JMP(opPUSH30) ; 0x7d - :JMP(opPUSH31) ; 0x7e - :JMP(opPUSH32) ; 0x7f + 1 => D :JMP(opPUSH1) ; 0x60 + 2 => D :JMP(opPUSH2) ; 0x61 + 3 => D :JMP(opPUSH3) ; 0x62 + 4 => D :JMP(opPUSH4) ; 0x63 + 5 => D :JMP(opPUSH5) ; 0x64 + 6 => D :JMP(opPUSH6) ; 0x65 + 7 => D :JMP(opPUSH7) ; 0x66 + 8 => D :JMP(opPUSH8) ; 0x67 + 9 => D :JMP(opPUSH9) ; 0x68 + 10 => D :JMP(opPUSH10) ; 0x69 + 11 => D :JMP(opPUSH11) ; 0x6a + 12 => D :JMP(opPUSH12) ; 0x6b + 13 => D :JMP(opPUSH13) ; 0x6c + 14 => D :JMP(opPUSH14) ; 0x6d + 15 => D :JMP(opPUSH15) ; 0x6e + 16 => D :JMP(opPUSH16) ; 0x6f + 17 => D :JMP(opPUSH17) ; 0x70 + 18 => D :JMP(opPUSH18) ; 0x71 + 19 => D :JMP(opPUSH19) ; 0x72 + 20 => D :JMP(opPUSH20) ; 0x73 + 21 => D :JMP(opPUSH21) ; 0x74 + 22 => D :JMP(opPUSH22) ; 0x75 + 23 => D :JMP(opPUSH23) ; 0x76 + 24 => D :JMP(opPUSH24) ; 0x77 + 25 => D :JMP(opPUSH25) ; 0x78 + 26 => D :JMP(opPUSH26) ; 0x79 + 27 => D :JMP(opPUSH27) ; 0x7a + 28 => D :JMP(opPUSH28) ; 0x7b + 29 => D :JMP(opPUSH29) ; 0x7c + 30 => D :JMP(opPUSH30) ; 0x7d + 31 => D :JMP(opPUSH31) ; 0x7e + 32 => D :JMP(opPUSH32) ; 0x7f :JMP(opDUP1) ; 0x80 :JMP(opDUP2) ; 0x81 :JMP(opDUP3) ; 0x82 diff --git a/main/opcodes/calldata-returndata-code.zkasm b/main/opcodes/calldata-returndata-code.zkasm index 2514b80a..2bb9ab7b 100644 --- a/main/opcodes/calldata-returndata-code.zkasm +++ b/main/opcodes/calldata-returndata-code.zkasm @@ -448,7 +448,7 @@ opEXTCODECOPYLoadBytecode: $ => RR :MLOAD(tmpZkPCext) $ => B :MLOAD(arithRes1) %MAX_CNT_POSEIDON_G - CNT_POSEIDON_G - %MAX_CNT_POSEIDON_SLOAD_SSTORE - 1 - B :JMPN(outOfCountersPoseidon) - %MAX_CNT_PADDING_PG_LIMIT - CNT_PADDING_PG - 1 - B :JMPN(outOfCountersPadding) + %MAX_CNT_PADDING_PG - CNT_PADDING_PG - 1 - B :JMPN(outOfCountersPadding) ; set key for smt smart contract code query %SMT_KEY_SC_CODE => B diff --git a/main/opcodes/logs.zkasm b/main/opcodes/logs.zkasm index ca8f75fa..4c0a5901 100644 --- a/main/opcodes/logs.zkasm +++ b/main/opcodes/logs.zkasm @@ -8,7 +8,7 @@ * - stack output: none */ VAR GLOBAL opLogAux - + VAR GLOBAL logNextHashPIdAux opLOG0: ; checks zk-counters %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep) @@ -45,7 +45,7 @@ opLOG1: %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep) %MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary) SP - 3 :JMPN(stackUnderflow) - GAS - %LOG_GAS => GAS :JMPN(outOfGas) + GAS - %LOG_GAS - %LOG_TOPIC_GAS => GAS :JMPN(outOfGas) $ => A :MLOAD(isStaticCall), JMPNZ(invalidStaticTx) SP - 1 => SP $ => E :MLOAD(SP--) @@ -53,7 +53,7 @@ opLOG1: E :MSTORE(lastMemOffset) C :MSTORE(lastMemLength), CALL(saveMem) 1 :MSTORE(numTopics) - 8 :MSTORE(arithA) + %LOG_DATA_GAS :MSTORE(arithA) C :MSTORE(arithB), CALL(mulARITH) $ => B :MLOAD(arithRes1) GAS => A @@ -66,7 +66,7 @@ opLOG2: %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep) %MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary) SP - 4 :JMPN(stackUnderflow) - GAS - %LOG_GAS => GAS :JMPN(outOfGas) + GAS - %LOG_GAS - %LOG_TOPIC_GAS*2 => GAS :JMPN(outOfGas) $ => A :MLOAD(isStaticCall), JMPNZ(invalidStaticTx) SP - 1 => SP $ => E :MLOAD(SP--) @@ -74,7 +74,7 @@ opLOG2: E :MSTORE(lastMemOffset) C :MSTORE(lastMemLength), CALL(saveMem) 2 :MSTORE(numTopics) - 8 :MSTORE(arithA) + %LOG_DATA_GAS :MSTORE(arithA) C :MSTORE(arithB), CALL(mulARITH) $ => B :MLOAD(arithRes1) GAS => A @@ -87,7 +87,7 @@ opLOG3: %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep) %MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary) SP - 5 :JMPN(stackUnderflow) - GAS - %LOG_GAS => GAS :JMPN(outOfGas) + GAS - %LOG_GAS - %LOG_TOPIC_GAS*3 => GAS :JMPN(outOfGas) $ => A :MLOAD(isStaticCall), JMPNZ(invalidStaticTx) SP - 1 => SP $ => E :MLOAD(SP--) @@ -95,7 +95,7 @@ opLOG3: E :MSTORE(lastMemOffset) C :MSTORE(lastMemLength), CALL(saveMem) 3 :MSTORE(numTopics) - 8 :MSTORE(arithA) + %LOG_DATA_GAS :MSTORE(arithA) C :MSTORE(arithB), CALL(mulARITH) $ => B :MLOAD(arithRes1) GAS => A @@ -108,7 +108,7 @@ opLOG4: %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep) %MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary) SP - 6 :JMPN(stackUnderflow) - GAS - %LOG_GAS => GAS :JMPN(outOfGas) + GAS - %LOG_GAS - %LOG_TOPIC_GAS*4 => GAS :JMPN(outOfGas) $ => A :MLOAD(isStaticCall), JMPNZ(invalidStaticTx) SP - 1 => SP $ => E :MLOAD(SP--) @@ -116,7 +116,7 @@ opLOG4: E :MSTORE(lastMemOffset) C :MSTORE(lastMemLength), CALL(saveMem) 4 :MSTORE(numTopics) - 8 :MSTORE(arithA) + %LOG_DATA_GAS :MSTORE(arithA) C :MSTORE(arithB), CALL(mulARITH) $ => B :MLOAD(arithRes1) GAS => A @@ -132,10 +132,16 @@ initLogLoop: $ => B :MLOAD(arithRes1) ; We count B and also the number of topics, as max is 4 topics of 32 bytes each 32*4/56 = 2.2 -> 3 %MAX_CNT_POSEIDON_G - CNT_POSEIDON_G - 4 - B :JMPN(outOfCountersPoseidon) - %MAX_CNT_PADDING_PG_LIMIT - CNT_PADDING_PG - 4 - B :JMPN(outOfCountersPadding) + %MAX_CNT_PADDING_PG - CNT_PADDING_PG - 4 - B :JMPN(outOfCountersPadding) 0 => HASHPOS 32 => D $ => B :MLOAD(currentLogIndex) + $ => A :MLOAD(nextHashPId) + ; Update nextHashPId + A + 1 :MSTORE(nextHashPId) + ; store nextHashPId to aux variable + A :MSTORE(logNextHashPIdAux) + logLoop: ; checks zk-counters %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep) @@ -144,7 +150,7 @@ logLoop: C - 32 :JMPN(opLogFinal) :CALL(MLOAD32); in: [E: offset] out: [A: value] E :MSTORE(opLogAux) - $ => E :MLOAD(nextHashPId) + $ => E :MLOAD(logNextHashPIdAux) A :HASHP(E) $ => E :MLOAD(opLogAux) $${storeLog(B, 0, A)} ; storeLog(indexLog, isTopic, bytesToStore) @@ -156,14 +162,14 @@ opLogFinal: $${storeLog(B, 0, A)}; storeLog(indexLog, isTopic, bytesToStore) 32 - C => D :CALL(SHRarith); in: [A: value, D: #bytes to right shift] out: [A: shifted result] C => D - $ => E :MLOAD(nextHashPId) + $ => E :MLOAD(logNextHashPIdAux) A :HASHP(E) :JMP(opSaveTopicsInit) ; instruction added to allow executing $$ function opSaveTopicsInit: ; save topics $ => A :MLOAD(numTopics) - $ => E :MLOAD(nextHashPId) + $ => E :MLOAD(logNextHashPIdAux) 32 => D opSaveTopicsLoop: @@ -174,7 +180,6 @@ opSaveTopicsLoop: ; check stack underflow SP - 1 => SP ; check out-of-gas - GAS - %LOG_TOPIC_GAS => GAS :JMPN(outOfGas) $ => C :MLOAD(SP) ; [topic => C] C :HASHP(E) $${storeLog(B, 1, C)} ; storeLog(indexLog, isTopic, bytesToStore) @@ -182,8 +187,6 @@ opSaveTopicsLoop: finishSaveTopics: %MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary) - ; Update nextHashPId - E + 1 :MSTORE(nextHashPId) ; Compute hash of the log HASHPOS :HASHPLEN(E) $ => D :HASHPDIGEST(E), CALL(fillBlockInfoTreeWithLog); in: [D: linearPoseidon(log_data + log_topics)] diff --git a/main/opcodes/stack-operations.zkasm b/main/opcodes/stack-operations.zkasm index 5bd3af0b..c7b419c4 100644 --- a/main/opcodes/stack-operations.zkasm +++ b/main/opcodes/stack-operations.zkasm @@ -27,134 +27,101 @@ opPUSH0: * - stack output: [pushed_value] */ opPUSH1: - ; number of bytes to push to D - 1 => D ; check is a deploy ; if is a deploy, get bytes from memory else, get bytes from stack $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH2: - 2 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH3: - 3 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH4: - 4 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH5: - 5 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH6: - 6 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH7: - 7 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH8: - 8 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH9: - 9 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH10: - 10 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH11: - 11 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH12: - 12 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH13: - 13 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH14: - 14 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH15: - 15 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH16: - 16 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH17: - 17 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH18: - 18 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH19: - 19 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH20: - 20 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH21: - 21 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH22: - 22 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH23: - 23 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH24: - 24 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH25: - 25 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH26: - 26 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH27: - 27 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH28: - 28 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH29: - 29 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH30: - 30 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH31: - 31 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opPUSH32: - 32 => D $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA) opAuxPUSHA: @@ -169,7 +136,7 @@ opAuxPUSHA2: ; check out-of-gas GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas) ; read bytes from calldata - :CALL(readPush); in: [D: bytes to read] out: [E: value read] + D => E :CALL(readPush); in: [D,E: bytes to read] out: [E: value read] ; store stack output E :MSTORE(SP++); [pushed_value(E) => SP] ; check stack overflow diff --git a/main/pairings/FPBN254/subFpBN254.zkasm b/main/pairings/FPBN254/subFpBN254.zkasm index 517bcb58..51a76959 100644 --- a/main/pairings/FPBN254/subFpBN254.zkasm +++ b/main/pairings/FPBN254/subFpBN254.zkasm @@ -8,10 +8,16 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; subFpBN254: + ; 0] Negate C + A => D + %BN254_P => A + C => B + $ => C :SUB + D => A + ; 1] Compute and check the sub over Z ; A·[1] + [BN254_P-C] = [D]·2²⁵⁶ + [E] 1 => B - ${const.BN254_P - C} => C $${var _subFpBN254_AC = A + C} ${_subFpBN254_AC >> 256} => D ${_subFpBN254_AC} => E :ARITH diff --git a/main/precompiled/pre-ecAdd.zkasm b/main/precompiled/pre-ecAdd.zkasm index eaaf7a16..affda74e 100644 --- a/main/precompiled/pre-ecAdd.zkasm +++ b/main/precompiled/pre-ecAdd.zkasm @@ -1,16 +1,16 @@ /** * @link [https://www.evm.codes/precompiled#0x06?fork=berlin] * @zk-counters - * - dynamic steps: 500 + * - dynamic steps: 800 * - dynamic arith: 50 - * - dynamic binary: 10 + * - dynamic binary: 50 * @process-precompiled * - stack input: [x1, y1, x2, y2] * - stack output: [x, y] */ funcEcAdd: - %MAX_CNT_ARITH - CNT_ARITH - 50 :JMPN(outOfCountersArith) %MAX_CNT_BINARY - CNT_BINARY - 50 :JMPN(outOfCountersBinary) + %MAX_CNT_ARITH - CNT_ARITH - 50 :JMPN(outOfCountersArith) %MAX_CNT_STEPS - STEP - 800 :JMPN(outOfCountersStep) ; Move balances if value > 0 just before executing the contract CALL @@ -35,7 +35,7 @@ funcEcAdd: A :MSTORE(ecAdd_P2_x) E + 32 => E :MSTORE(readXFromCalldataOffset), CALL(readFromCalldataOffset); in: [readXFromCalldataOffset: offset value, readXFromCalldataLength: length value], out: [readXFromCalldataResult: result value] $ => A :MLOAD(readXFromCalldataResult) ; y2 - A :MSTORE(ecAdd_P2_y),CALL(ecAdd) + A :MSTORE(ecAdd_P2_y), CALL(ecAdd) ; check error B :JMPNZ(preEndFail) diff --git a/main/precompiled/pre-ecMul.zkasm b/main/precompiled/pre-ecMul.zkasm index 2c143390..e4d2c556 100644 --- a/main/precompiled/pre-ecMul.zkasm +++ b/main/precompiled/pre-ecMul.zkasm @@ -1,18 +1,18 @@ /** * @link [https://www.evm.codes/precompiled#0x07?fork=berlin] * @zk-counters - * - dynamic steps: 130000 + * - dynamic steps: 175000 * - dynamic arith: 20000 - * - dynamic binary: 4000 + * - dynamic binary: 20000 * @process-precompiled * - stack input: [x1, y1, s] * - stack output: [x, y] */ funcEcMul: - %MAX_CNT_BINARY - CNT_BINARY - 4000 :JMPN(outOfCountersBinary) + %MAX_CNT_BINARY - CNT_BINARY - 20000 :JMPN(outOfCountersBinary) %MAX_CNT_ARITH - CNT_ARITH - 20000 :JMPN(outOfCountersArith) - %MAX_CNT_STEPS - STEP - 130000 :JMPN(outOfCountersStep) + %MAX_CNT_STEPS - STEP - 175000 :JMPN(outOfCountersStep) ; Move balances if value > 0 just before executing the contract CALL $ => B :MLOAD(txValue) @@ -33,7 +33,7 @@ funcEcMul: A :MSTORE(ecMul_P_y) E + 32 => E :MSTORE(readXFromCalldataOffset), CALL(readFromCalldataOffset); in: [readXFromCalldataOffset: offset value, readXFromCalldataLength: length value], out: [readXFromCalldataResult: result value] $ => A :MLOAD(readXFromCalldataResult) ; k - A :MSTORE(ecMul_k),CALL(ecMul) + A :MSTORE(ecMul_k), CALL(ecMul) ; check error B :JMPNZ(preEndFail) diff --git a/main/precompiled/pre-ecPairing.zkasm b/main/precompiled/pre-ecPairing.zkasm index b3319509..5ca575ed 100644 --- a/main/precompiled/pre-ecPairing.zkasm +++ b/main/precompiled/pre-ecPairing.zkasm @@ -1,9 +1,9 @@ /** * @link [https://www.evm.codes/precompiled#0x08?fork=berlin] * @zk-counters - * - dynamic steps: 50000, 550000, 700000,... - * - dynamic arith: 4000, 43000, 56000,... - * - dynamic binary: 400, 700, 1100,... + * - dynamic steps: 200000 * nInputs + 175000 + * - dynamic arith: 15000 * nInputs + 17500 + * - dynamic binary: 4100 * nInputs + 750 * @process-precompiled * - stack input: [x1, y1, x2, y2, ..., xk, yk] * - stack output: [success] @@ -28,21 +28,11 @@ funcEcPairing: A :MSTORE(ecPairing_ninputs) GAS - 34000*A => GAS :JMPN(outOfGas) ; gas = 34000 * inputsLength - A - 1 :JMPZ(counters6) - A - 2 => A - %MAX_CNT_BINARY - CNT_BINARY - 700 - 400*A :JMPN(outOfCountersBinary) - %MAX_CNT_ARITH - CNT_ARITH - 45000 - 14000*A :JMPN(outOfCountersArith) - %MAX_CNT_STEPS - STEP - 550000 - 200000*A :JMPN(outOfCountersStep) - :JMP(afterCounts) + %MAX_CNT_BINARY - CNT_BINARY - 750 - 4100*A :JMPN(outOfCountersBinary) + %MAX_CNT_ARITH - CNT_ARITH - 17500 - 15000*A :JMPN(outOfCountersArith) + %MAX_CNT_STEPS - STEP - 175000 - 200000*A :JMPN(outOfCountersStep) -counters6: - - %MAX_CNT_BINARY - CNT_BINARY - 400 :JMPN(outOfCountersBinary) - %MAX_CNT_ARITH - CNT_ARITH - 4000 :JMPN(outOfCountersArith) - %MAX_CNT_STEPS - STEP - 50000 :JMPN(outOfCountersStep) - -afterCounts: -32 :MSTORE(readXFromCalldataOffset),CALL(ecPairing) B :JMPNZ(preEndFail) $ => C :MLOAD(ecPairing_result) diff --git a/main/precompiled/pre-modexp.zkasm b/main/precompiled/pre-modexp.zkasm index 6e0e26d3..7bcd9271 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) + A - B :JMPN(finalMODEXPreturn) + B => A + +finalMODEXPreturn: ; write data into memory + A :MSTORE(retCopyLen) 0 => B $ => C :MLOAD(modexp_Msize) C :MSTORE(arithA) @@ -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) @@ -332,6 +342,7 @@ returnLoop: %MAX_CNT_STEPS - STEP - 50 :JMPN(outOfCountersStep) E - 1 => E :MSTORE(modexp_returnIndex) + C - 32 :JMPN(returnLoopFinal) $ => A :MLOAD(modexp_out+E) A :MSTORE(bytesToStore) B => E @@ -340,6 +351,14 @@ returnLoop: $ => E :MLOAD(modexp_returnIndex) C - 32 => C :JMPZ(endMODEXP, returnLoop) +returnLoopFinal: + $ => A :MLOAD(modexp_out+E) + 32 - C => D :CALL(SHLarith) + A :MSTORE(bytesToStore) + B => E + :CALL(MSTOREX) ; in: [bytesToStore, E: offset, C: length] out: [E: new offset] + :JMP(endMODEXP) + preEndMODEXP: $ => A :MLOAD(originCTX), JMPZ(handleGas) A => CTX diff --git a/main/precompiled/revert-precompiled.zkasm b/main/precompiled/revert-precompiled.zkasm index dc7b7cf4..67dfc88b 100644 --- a/main/precompiled/revert-precompiled.zkasm +++ b/main/precompiled/revert-precompiled.zkasm @@ -7,7 +7,7 @@ revertPrecompiled: $${eventLog(onError, revert)} :CALL(revertBlockInfoTree) ; check if it is the first context - $ => A :MLOAD(originCTX), JMPZ(handleGas) ; first context + $ => A :MLOAD(originCTX), JMPZ(handleGasFromError) ; first context A => CTX :MSTORE(currentCTX) ; clear retDataCTX, no return data in revert precompiled diff --git a/main/precompiled/selector.zkasm b/main/precompiled/selector.zkasm index c81a55e0..0bd3047b 100644 --- a/main/precompiled/selector.zkasm +++ b/main/precompiled/selector.zkasm @@ -70,7 +70,7 @@ selectorPrecompiled: A - 3 :JMPN(funcSHA256) A - 4 :JMPN(revertPrecompiled) ;:JMPN(RIPEMD160) A - 5 :JMPN(IDENTITY) - A - 6 :JMPN(funcModexp) + A - 6 :JMPN(revertPrecompiled) ;:JMPN(funcModexp) A - 7 :JMPN(funcEcAdd) A - 8 :JMPN(funcEcMul) A - 9 :JMPN(funcEcPairing) diff --git a/main/process-tx.zkasm b/main/process-tx.zkasm index 07dc98dd..72766493 100644 --- a/main/process-tx.zkasm +++ b/main/process-tx.zkasm @@ -424,7 +424,7 @@ callContract: 56 :MSTORE(arithB), CALL(divARITH); in: [arithA, arithB] out: [arithRes1: arithA/arithB, arithRes2: arithA%arithB] $ => B :MLOAD(arithRes1) %MAX_CNT_POSEIDON_G - CNT_POSEIDON_G - 1 - B :JMPN(outOfCountersPoseidon) - %MAX_CNT_PADDING_PG_LIMIT - CNT_PADDING_PG - 1 - B :JMPN(outOfCountersPadding) + %MAX_CNT_PADDING_PG - CNT_PADDING_PG - 1 - B :JMPN(outOfCountersPadding) ; get hash contract $ => A :MLOAD(txDestAddr) diff --git a/main/utils.zkasm b/main/utils.zkasm index 45d5637a..4b1dab16 100644 --- a/main/utils.zkasm +++ b/main/utils.zkasm @@ -991,122 +991,292 @@ invalidCall: 0 :MSTORE(SP++), JMP(readCode) VAR GLOBAL pushBytes -VAR GLOBAL numBlocks -VAR GLOBAL leftBytes -VAR GLOBAL accumulator +VAR GLOBAL pushBytes_RR ; @info Read bytes opcode PUSHX ; @internalParam {numBlocks} 4 bytes blocks to read ; @internalParam {leftBytes} remaining bytes -; @in D => bytes to read +; @in D,E => bytes to read (1..32) ; @out E => value read + readPush: - %MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep) - %MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary) - D :MSTORE(pushBytes) - D => A - 0 :MSTORE(accumulator) - PC + D - 1 => HASHPOS - - ; B = [b7, b6, ..., b0] - ; JMPN instruction assures b0 is within the range [0, 2**32 - 1] - ${A >> 2} => B :JMPN(failAssert) - B :MSTORE(numBlocks) - ${A & 0x03} => D - D :MSTORE(leftBytes) - - ; since D is assured to be less than 0x04 - ; it is enforced that [b7, b6, ..., b1] are 0 since there is no value multiplied by 4 - ; that equals the field - ; Since b0 is assured to be less than 32 bits, b0 * 4 + d0 could not overflow the field - B * 4 + D :ASSERT - D => A - 0x04 => B - $ :LT,JMPNC(failAssert) - 0 => B + :JMP(@readPush+E) ;0 +readPush1: + PC => HASHPOS :JMP(_readPush1) ;1 +readPush2: + PC => HASHPOS :JMP(_readPush2) ;2 +readPush3: + PC => HASHPOS :JMP(_readPush3) ;3 +readPush4: + PC => HASHPOS :JMP(_readPush4) ;4 +readPush5: + PC => HASHPOS :JMP(_readPushX) ;5 +readPush6: + PC => HASHPOS :JMP(_readPushX) ;6 +readPush7: + PC => HASHPOS :JMP(_readPushX) ;7 +readPush8: + PC => HASHPOS :JMP(_readPushX) ;8 +readPush9: + PC => HASHPOS :JMP(_readPushX) ;9 +readPush10: + PC => HASHPOS :JMP(_readPushX) ;10 +readPush11: + PC => HASHPOS :JMP(_readPushX) ;11 +readPush12: + PC => HASHPOS :JMP(_readPushX) ;12 +readPush13: + PC => HASHPOS :JMP(_readPushX) ;13 +readPush14: + PC => HASHPOS :JMP(_readPushX) ;14 +readPush15: + PC => HASHPOS :JMP(_readPushX) ;15 +readPush16: + PC => HASHPOS :JMP(_readPushX) ;16 +readPush17: + PC => HASHPOS :JMP(_readPushX) ;17 +readPush18: + PC => HASHPOS :JMP(_readPushX) ;18 +readPush19: + PC => HASHPOS :JMP(_readPushX) ;19 +readPush20: + PC => HASHPOS :JMP(_readPushX) ;20 +readPush21: + PC => HASHPOS :JMP(_readPushX) ;21 +readPush22: + PC => HASHPOS :JMP(_readPushX) ;22 +readPush23: + PC => HASHPOS :JMP(_readPushX) ;23 +readPush24: + PC => HASHPOS :JMP(_readPushX) ;24 +readPush25: + PC => HASHPOS :JMP(_readPushX) ;25 +readPush26: + PC => HASHPOS :JMP(_readPushX) ;26 +readPush27: + PC => HASHPOS :JMP(_readPushX) ;27 +readPush28: + PC => HASHPOS :JMP(_readPushX) ;28 +readPush29: + PC => HASHPOS :JMP(_readPushX) ;29 +readPush30: + PC => HASHPOS :JMP(_readPushX) ;30 +readPush31: + PC => HASHPOS :JMP(_readPushX) ;31 +readPush32: + PC => HASHPOS :JMP(_readPush32) ;32 + +_readPush1: + $ => E :MLOAD(contractHashId) + $ => E :HASHP1(E),RETURN -readPushBlock: - %MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep) - %MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary) - ; load hash contract identifier +_readPush2: $ => E :MLOAD(contractHashId) - $ => A :MLOAD(numBlocks) - $ :EQ, JMPC(endPushInit) - ; read bytes $ => C :HASHP1(E) - HASHPOS - 2 => HASHPOS + $ => E :HASHP1(E) + C * 256 + E => E :RETURN +_readPush3: + $ => E :MLOAD(contractHashId) $ => A :HASHP1(E) - HASHPOS - 2 => HASHPOS - A*256 + C => C + $ => C :HASHP1(E) + $ => E :HASHP1(E) + A * 2**16 + C * 2**8 + E => E :RETURN +_readPush4: + $ => E :MLOAD(contractHashId) $ => A :HASHP1(E) - HASHPOS - 2 => HASHPOS - A*65536 + C => C + $ => B :HASHP1(E) + $ => C :HASHP1(E) + $ => E :HASHP1(E) + A * 2**24 + B * 2**16 + C * 2**8 + E => E :RETURN +_readPush32: + $ => E :MLOAD(contractHashId) + + $ => B :HASHP1(E) + $ => RCX :HASHP1(E) + $ => D :HASHP1(E) $ => A :HASHP1(E) - HASHPOS - 2 => HASHPOS - A*16777216 + C => C + 2**24 * B + 2**16 * RCX + 2**8 * D + A => C -doRotate: - B - 1 => A + ; 28 bytes -doRotateLoop: - %MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep) - A :JMPN(endRotate) - ROTL_C => C - A - 1 => A :JMP(doRotateLoop) + $ => B :HASHP1(E) + $ => RCX :HASHP1(E) + $ => D :HASHP1(E) + $ => A :HASHP1(E) + ROTL_C + 2**24 * B + 2**16 * RCX + 2**8 * D + A => C -endRotate: - $ => D :MLOAD(accumulator) - C + D => D - D :MSTORE(accumulator) - B + 1 => B :JMP(readPushBlock) + ; 24 bytes -endPushInit: - $ => A :MLOAD(leftBytes), JMPZ(finalPush) - 0 => C - 0 => B :JMP(endPushLoop) + $ => B :HASHP1(E) + $ => RCX :HASHP1(E) + $ => D :HASHP1(E) + $ => A :HASHP1(E) + ROTL_C + 2**24 * B + 2**16 * RCX + 2**8 * D + A => C -endPushLoop: - %MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep) - %MAX_CNT_BINARY - CNT_BINARY - 4 :JMPN(outOfCountersBinary) + ; 20 bytes - $ => A :MLOAD(leftBytes) - $ :EQ, JMPC(endPushFinal) + $ => B :HASHP1(E) + $ => RCX :HASHP1(E) + $ => D :HASHP1(E) + $ => A :HASHP1(E) + ROTL_C + 2**24 * B + 2**16 * RCX + 2**8 * D + A => C - $ => D :HASHP1(E) - HASHPOS - 2 => HASHPOS - B - 1 => A :JMP(computeFactorLoop) + ; 16 bytes -computeFactorLoop: - %MAX_CNT_STEPS - STEP - 10 :JMPN(outOfCountersStep) - A :JMPN(computeFactorEnd) - 256*D => D - A - 1 => A :JMP(computeFactorLoop) + $ => B :HASHP1(E) + $ => RCX :HASHP1(E) + $ => D :HASHP1(E) + $ => A :HASHP1(E) + ROTL_C + 2**24 * B + 2**16 * RCX + 2**8 * D + A => C -computeFactorEnd: - B + 1 => B - D + C => C :JMP(endPushLoop) + ; 12 bytes -endPushFinal: - $ => B :MLOAD(numBlocks), JMP(doRotate2) + $ => B :HASHP1(E) + $ => RCX :HASHP1(E) + $ => D :HASHP1(E) + $ => A :HASHP1(E) + ROTL_C + 2**24 * B + 2**16 * RCX + 2**8 * D + A => C -doRotate2: - B - 1 => A :JMP(doRotateLoop2) + ; 8 bytes -doRotateLoop2: - %MAX_CNT_STEPS - STEP - 10 :JMPN(outOfCountersStep) - A :JMPN(endRotate2) - ROTL_C => C - A - 1 => A :JMP(doRotateLoop2) + $ => B :HASHP1(E) + $ => RCX :HASHP1(E) + $ => D :HASHP1(E) + $ => A :HASHP1(E) + ROTL_C + 2**24 * B + 2**16 * RCX + 2**8 * D + A => C -endRotate2: - $ => D :MLOAD(accumulator) - C + D => D - D :MSTORE(accumulator), JMP(finalPush) + ; 4 bytes + + $ => B :HASHP1(E) + $ => RCX :HASHP1(E) + $ => D :HASHP1(E) + $ => A :HASHP1(E) + ROTL_C + 2**24 * B + 2**16 * RCX + 2**8 * D + A => E + + 32 => D :RETURN + +_readPushX: + D :MSTORE(pushBytes) + $ => B :MLOAD(contractHashId) + +readPushBytes: + B => E :JMP(@readPushBytes + E) + + 0 => RCX, B, D, A, C :JMP(readPushBytes_1) + 0 => RCX, B, D, A, C :JMP(readPushBytes_2) + 0 => RCX, B, D, A, C :JMP(readPushBytes_3) + 0 => RCX, B, D, A, C :JMP(readPushBytes_4) + 0 => RCX, B, D, A, C :JMP(readPushBytes_5) + 0 => RCX, B, D, A, C :JMP(readPushBytes_6) + 0 => RCX, B, D, A, C :JMP(readPushBytes_7) + 0 => RCX, B, D, A, C :JMP(readPushBytes_8) + 0 => RCX, B, D, A, C :JMP(readPushBytes_9) + 0 => RCX, B, D, A, C :JMP(readPushBytes_10) + 0 => RCX, B, D, A, C :JMP(readPushBytes_11) + 0 => RCX, B, D, A, C :JMP(readPushBytes_12) + 0 => RCX, B, D, A, C :JMP(readPushBytes_13) + 0 => RCX, B, D, A, C :JMP(readPushBytes_14) + 0 => RCX, B, D, A, C :JMP(readPushBytes_15) + 0 => RCX, B, D, A, C :JMP(readPushBytes_16) + 0 => RCX, B, D, A, C :JMP(readPushBytes_17) + 0 => RCX, B, D, A, C :JMP(readPushBytes_18) + 0 => RCX, B, D, A, C :JMP(readPushBytes_19) + 0 => RCX, B, D, A, C :JMP(readPushBytes_20) + 0 => RCX, B, D, A, C :JMP(readPushBytes_21) + 0 => RCX, B, D, A, C :JMP(readPushBytes_22) + 0 => RCX, B, D, A, C :JMP(readPushBytes_23) + 0 => RCX, B, D, A, C :JMP(readPushBytes_24) + 0 => RCX, B, D, A, C :JMP(readPushBytes_25) + 0 => RCX, B, D, A, C :JMP(readPushBytes_26) + 0 => RCX, B, D, A, C :JMP(readPushBytes_27) + 0 => RCX, B, D, A, C :JMP(readPushBytes_28) + 0 => RCX, B, D, A, C :JMP(readPushBytes_29) + 0 => RCX, B, D, A, C :JMP(readPushBytes_30) + 0 => RCX, B, D, A, C :JMP(readPushBytes_31) + 0 => RCX, B, D, A, C :JMP(readPushBytes_32) + +readPushBytes_32: + $ => B :HASHP1(E) +readPushBytes_31: + $ => RCX :HASHP1(E) +readPushBytes_30: + $ => D :HASHP1(E) +readPushBytes_29: + $ => A :HASHP1(E) + 2**24 * B + 2**16 * RCX + 2**8 * D + A => C + +readPushBytes_28: + $ => B :HASHP1(E) +readPushBytes_27: + $ => RCX :HASHP1(E) +readPushBytes_26: + $ => D :HASHP1(E) +readPushBytes_25: + $ => A :HASHP1(E) + ROTL_C + 2**24 * B + 2**16 * RCX + 2**8 * D + A => C + +readPushBytes_24: + $ => B :HASHP1(E) +readPushBytes_23: + $ => RCX :HASHP1(E) +readPushBytes_22: + $ => D :HASHP1(E) +readPushBytes_21: + $ => A :HASHP1(E) + ROTL_C + 2**24 * B + 2**16 * RCX + 2**8 * D + A => C + +readPushBytes_20: + $ => B :HASHP1(E) +readPushBytes_19: + $ => RCX :HASHP1(E) +readPushBytes_18: + $ => D :HASHP1(E) +readPushBytes_17: + $ => A :HASHP1(E) + ROTL_C + 2**24 * B + 2**16 * RCX + 2**8 * D + A => C + +readPushBytes_16: + $ => B :HASHP1(E) +readPushBytes_15: + $ => RCX :HASHP1(E) +readPushBytes_14: + $ => D :HASHP1(E) +readPushBytes_13: + $ => A :HASHP1(E) + ROTL_C + 2**24 * B + 2**16 * RCX + 2**8 * D + A => C + +readPushBytes_12: + $ => B :HASHP1(E) +readPushBytes_11: + $ => RCX :HASHP1(E) +readPushBytes_10: + $ => D :HASHP1(E) +readPushBytes_9: + $ => A :HASHP1(E) + ROTL_C + 2**24 * B + 2**16 * RCX + 2**8 * D + A => C + +readPushBytes_8: + $ => B :HASHP1(E) +readPushBytes_7: + $ => RCX :HASHP1(E) +readPushBytes_6: + $ => D :HASHP1(E) +readPushBytes_5: + $ => A :HASHP1(E) + ROTL_C + 2**24 * B + 2**16 * RCX + 2**8 * D + A => C + +readPushBytes_4: + $ => B :HASHP1(E) +readPushBytes_3: + $ => RCX :HASHP1(E) +readPushBytes_2: + $ => D :HASHP1(E) +readPushBytes_1: + $ => A :HASHP1(E) + ROTL_C + 2**24 * B + 2**16 * RCX + 2**8 * D + A => E -finalPush: - $ => E :MLOAD(accumulator) $ => D :MLOAD(pushBytes), RETURN VAR GLOBAL tmpVarDaddB @@ -1221,7 +1391,7 @@ hashPoseidonLinearFromMemory: 56 :MSTORE(arithB), CALL(divARITH); in: [arithA, arithB] out: [arithRes1: arithA/arithB, arithRes2: arithA%arithB] $ => B :MLOAD(arithRes1) %MAX_CNT_POSEIDON_G - CNT_POSEIDON_G - 1 - B :JMPN(outOfCountersPoseidon) - %MAX_CNT_PADDING_PG_LIMIT - CNT_PADDING_PG - 1 - B :JMPN(outOfCountersPadding) + %MAX_CNT_PADDING_PG - CNT_PADDING_PG - 1 - B :JMPN(outOfCountersPadding) ; get a new hashPId $ => B :MLOAD(nextHashPId) diff --git a/package.json b/package.json index be762e4e..18618387 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@0xpolygonhermez/zkevm-rom", - "version": "4.0.0", + "version": "5.0.0", "description": "zkROM source code", "main": "index.js", "scripts": { @@ -39,13 +39,13 @@ "url": "https://github.com/0xPolygonHermez/zkevm-rom.git" }, "dependencies": { - "@0xpolygonhermez/zkasmcom": "https://github.com/0xPolygonHermez/zkasmcom.git#v2.0.0-rc.2-fork.7", + "@0xpolygonhermez/zkasmcom": "https://github.com/0xPolygonHermez/zkasmcom.git#v5.0.0-fork.8", "yargs": "^17.5.1" }, "devDependencies": { - "@0xpolygonhermez/zkevm-commonjs": "github:0xPolygonHermez/zkevm-commonjs#v4.0.0-fork.7", - "@0xpolygonhermez/zkevm-proverjs": "github:0xPolygonHermez/zkevm-proverjs#b1540abf1fd1306e5eb11817abe40145b27a48ae", - "@0xpolygonhermez/zkevm-testvectors": "github:0xPolygonHermez/zkevm-testvectors#v4.0.0-fork.7", + "@0xpolygonhermez/zkevm-commonjs": "github:0xPolygonHermez/zkevm-commonjs#v5.0.0-fork.8", + "@0xpolygonhermez/zkevm-proverjs": "github:0xPolygonHermez/zkevm-proverjs#493569b08869a496e5de379c83263e4a10d5e585", + "@0xpolygonhermez/zkevm-testvectors": "github:0xPolygonHermez/zkevm-testvectors#v5.0.0-fork.8", "chai": "^4.3.6", "chalk": "^3.0.0", "eslint": "^8.25.0", diff --git a/test/read-push.zkasm b/test/read-push.zkasm index 2dd66de7..32358b8f 100644 --- a/test/read-push.zkasm +++ b/test/read-push.zkasm @@ -35,254 +35,254 @@ start: ;; Start test PUSH1 ; PUSH1 reading 1 byte at position 0 in the bytecode 0 => PC - 1 => D :CALL(readPush) + 1 => D,E :CALL(readPush) 0x01 => A E :ASSERT ; PUSH1 reading 1 byte at position 20 in the bytecode 20 => PC - 1 => D :CALL(readPush) + 1 => D,E :CALL(readPush) 0x15 => A E :ASSERT ; PUSH1 reading 1 byte at position 31 in the bytecode 31 => PC - 1 => D :CALL(readPush) + 1 => D,E :CALL(readPush) 0x20 => A E :ASSERT ; PUSH1 reading 1 byte at position 32 in the bytecode 32 => PC - 1 => D :CALL(readPush) + 1 => D,E :CALL(readPush) 0x21 => A E :ASSERT ; PUSH1 reading 1 byte at position 33 in the bytecode 33 => PC - 1 => D :CALL(readPush) + 1 => D,E :CALL(readPush) 0x22 => A E :ASSERT ;; Start test PUSH2 ; PUSH2 reading 2 byte at position 4 in the bytecode 4 => PC - 2 => D :CALL(readPush) + 2 => D,E :CALL(readPush) 0x0506 => A E :ASSERT ; PUSH2 reading 2 byte at position 34 in the bytecode 34 => PC - 2 => D :CALL(readPush) + 2 => D,E :CALL(readPush) 0x2324 => A E :ASSERT ;; Start test PUSH3 ; PUSH3 reading 3 byte at position 60 in the bytecode 60 => PC - 3 => D :CALL(readPush) + 3 => D,E :CALL(readPush) 0x3d3e3f => A E :ASSERT ;; Start test PUSH4 ; PUSH4 reading 4 byte at position 72 in the bytecode 72 => PC - 4 => D :CALL(readPush) + 4 => D,E :CALL(readPush) 0x494a4b4c => A E :ASSERT ;; Start test PUSH5 ; PUSH5 reading 5 byte at position 42 in the bytecode 42 => PC - 5 => D :CALL(readPush) + 5 => D,E :CALL(readPush) 0x2B2C2D2E2Fn => A E :ASSERT ;; Start test PUSH6 ; PUSH6 reading 6 byte at position 42 in the bytecode 42 => PC - 6 => D :CALL(readPush) + 6 => D,E :CALL(readPush) 0x2B2C2D2E2F30n => A E :ASSERT ;; Start test PUSH7 ; PUSH7 reading 7 byte at position 42 in the bytecode 42 => PC - 7 => D :CALL(readPush) + 7 => D,E :CALL(readPush) 0x2B2C2D2E2F3031n => A E :ASSERT ;; Start test PUSH8 ; PUSH8 reading 8 byte at position 42 in the bytecode 42 => PC - 8 => D :CALL(readPush) + 8 => D,E :CALL(readPush) 0x2B2C2D2E2F303132n => A E :ASSERT ;; Start test PUSH9 ; PUSH9 reading 9 byte at position 42 in the bytecode 42 => PC - 9 => D :CALL(readPush) + 9 => D,E :CALL(readPush) 0x2B2C2D2E2F30313233n => A E :ASSERT ;; Start test PUSH10 ; PUSH10 reading 10 byte at position 42 in the bytecode 42 => PC - 10 => D :CALL(readPush) + 10 => D,E :CALL(readPush) 0x2B2C2D2E2F3031323334n => A E :ASSERT ;; Start test PUSH11 ; PUSH11 reading 11 byte at position 42 in the bytecode 42 => PC - 11 => D :CALL(readPush) + 11 => D,E :CALL(readPush) 0x2B2C2D2E2F303132333435n => A E :ASSERT ;; Start test PUSH12 ; PUSH12 reading 12 byte at position 42 in the bytecode 42 => PC - 12 => D :CALL(readPush) + 12 => D,E :CALL(readPush) 0x2B2C2D2E2F30313233343536n => A E :ASSERT ;; Start test PUSH13 ; PUSH13 reading 13 byte at position 42 in the bytecode 42 => PC - 13 => D :CALL(readPush) + 13 => D,E :CALL(readPush) 0x2B2C2D2E2F3031323334353637n => A E :ASSERT ;; Start test PUSH14 ; PUSH14 reading 14 byte at position 42 in the bytecode 42 => PC - 14 => D :CALL(readPush) + 14 => D,E :CALL(readPush) 0x2B2C2D2E2F303132333435363738n => A E :ASSERT ;; Start test PUSH15 ; PUSH15 reading 15 byte at position 42 in the bytecode 42 => PC - 15 => D :CALL(readPush) + 15 => D,E :CALL(readPush) 0x2B2C2D2E2F30313233343536373839n => A E :ASSERT ;; Start test PUSH16 ; PUSH16 reading 16 byte at position 42 in the bytecode 42 => PC - 16 => D :CALL(readPush) + 16 => D,E :CALL(readPush) 0x2B2C2D2E2F303132333435363738393An => A E :ASSERT ;; Start test PUSH17 ; PUSH17 reading 17 byte at position 42 in the bytecode 42 => PC - 17 => D :CALL(readPush) + 17 => D,E :CALL(readPush) 0x2B2C2D2E2F303132333435363738393A3Bn => A E :ASSERT ;; Start test PUSH18 ; PUSH18 reading 18 byte at position 42 in the bytecode 42 => PC - 18 => D :CALL(readPush) + 18 => D,E :CALL(readPush) 0x2B2C2D2E2F303132333435363738393A3B3Cn => A E :ASSERT ;; Start test PUSH19 ; PUSH19 reading 19 byte at position 42 in the bytecode 42 => PC - 19 => D :CALL(readPush) + 19 => D,E :CALL(readPush) 0x2B2C2D2E2F303132333435363738393A3B3C3Dn => A E :ASSERT ;; Start test PUSH20 ; PUSH20 reading 20 byte at position 42 in the bytecode 42 => PC - 20 => D :CALL(readPush) + 20 => D,E :CALL(readPush) 0x2B2C2D2E2F303132333435363738393A3B3C3D3En => A E :ASSERT ;; Start test PUSH21 ; PUSH21 reading 21 byte at position 42 in the bytecode 42 => PC - 21 => D :CALL(readPush) + 21 => D,E :CALL(readPush) 0x2B2C2D2E2F303132333435363738393A3B3C3D3E3Fn => A E :ASSERT ;; Start test PUSH22 ; PUSH22 reading 22 byte at position 42 in the bytecode 42 => PC - 22 => D :CALL(readPush) + 22 => D,E :CALL(readPush) 0x2B2C2D2E2F303132333435363738393A3B3C3D3E3F40n => A E :ASSERT ;; Start test PUSH23 ; PUSH23 reading 23 byte at position 42 in the bytecode 42 => PC - 23 => D :CALL(readPush) + 23 => D,E :CALL(readPush) 0x2B2C2D2E2F303132333435363738393A3B3C3D3E3F4041n => A E :ASSERT ;; Start test PUSH24 ; PUSH24 reading 24 byte at position 42 in the bytecode 42 => PC - 24 => D :CALL(readPush) + 24 => D,E :CALL(readPush) 0x2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142n => A E :ASSERT ;; Start test PUSH25 ; PUSH25 reading 25 byte at position 42 in the bytecode 42 => PC - 25 => D :CALL(readPush) + 25 => D,E :CALL(readPush) 0x2B2C2D2E2F303132333435363738393A3B3C3D3E3F40414243n => A E :ASSERT ;; Start test PUSH26 ; PUSH26 reading 26 byte at position 42 in the bytecode 42 => PC - 26 => D :CALL(readPush) + 26 => D,E :CALL(readPush) 0x2B2C2D2E2F303132333435363738393A3B3C3D3E3F4041424344n => A E :ASSERT ;; Start test PUSH27 ; PUSH27 reading 27 byte at position 42 in the bytecode 42 => PC - 27 => D :CALL(readPush) + 27 => D,E :CALL(readPush) 0x2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445n => A E :ASSERT ;; Start test PUSH28 ; PUSH28 reading 28 byte at position 42 in the bytecode 42 => PC - 28 => D :CALL(readPush) + 28 => D,E :CALL(readPush) 0x2B2C2D2E2F303132333435363738393A3B3C3D3E3F40414243444546n => A E :ASSERT ;; Start test PUSH29 ; PUSH29 reading 29 byte at position 42 in the bytecode 42 => PC - 29 => D :CALL(readPush) + 29 => D,E :CALL(readPush) 0x2B2C2D2E2F303132333435363738393A3B3C3D3E3F4041424344454647n => A E :ASSERT ;; Start test PUSH30 ; PUSH30 reading 30 byte at position 42 in the bytecode 42 => PC - 30 => D :CALL(readPush) + 30 => D,E :CALL(readPush) 0x2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748n => A E :ASSERT ;; Start test PUSH31 ; PUSH31 reading 31 byte at position 42 in the bytecode 42 => PC - 31 => D :CALL(readPush) + 31 => D,E :CALL(readPush) 0x2B2C2D2E2F303132333435363738393A3B3C3D3E3F40414243444546474849n => A E :ASSERT ;; Start test PUSH32 ; PUSH32 reading 32 byte at position 42 in the bytecode 42 => PC - 32 => D :CALL(readPush) + 32 => D,E :CALL(readPush) 0x2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494An => A E :ASSERT diff --git a/tools/parallel-testing/gen-parallel-tests.js b/tools/parallel-testing/gen-parallel-tests.js index 56a986fa..7d81888a 100644 --- a/tools/parallel-testing/gen-parallel-tests.js +++ b/tools/parallel-testing/gen-parallel-tests.js @@ -18,6 +18,7 @@ const pathMainPil = path.join(__dirname, '../../node_modules/@0xpolygonhermez/zk const inputs = []; const testsFolder = path.join(__dirname, 'parallel-tests'); const sampleDir = path.join(__dirname, 'parallel-tests-sample/sample.test.js'); +const { argv } = require('yargs'); async function genTestsFiles() { if (!fs.existsSync(testsFolder)) { @@ -26,7 +27,11 @@ async function genTestsFiles() { for (const inputPath of inputs) { const name = inputPath.split('/').slice(-1)[0].replace('json', 'test.js'); const sample = fs.readFileSync(sampleDir, 'utf-8'); - const test = sample.replace('%%INPUT_PATH%%', `${inputPath}`); + let test = sample.replace('%%INPUT_PATH%%', `${inputPath}`); + // Replace skip vcounters flag + if (argv.skipVCounters) { + test = test.replace('%%SKIP_VCOUNTERS%%', 'yes'); + } fs.writeFileSync(`${testsFolder}/${name}`, test); } expect(true).to.be.equal(true); diff --git a/tools/parallel-testing/parallel-tests-sample/sample.test.js b/tools/parallel-testing/parallel-tests-sample/sample.test.js index a52d3f5d..fbc55079 100644 --- a/tools/parallel-testing/parallel-tests-sample/sample.test.js +++ b/tools/parallel-testing/parallel-tests-sample/sample.test.js @@ -23,6 +23,7 @@ const checkerDir = path.join(__dirname, 'checker.txt'); const inputPath = '%%INPUT_PATH%%'; const nameFile = path.basename(inputPath); const input = JSON.parse(fs.readFileSync(inputPath, 'utf8')); +const skipVcounters = '%%SKIP_VCOUNTERS%%'; it(`${nameFile}`, async () => { if (fs.existsSync(checkerDir)) { @@ -55,7 +56,9 @@ async function runTest(cmPols, steps) { }; const res = await smMain.execute(cmPols.Main, input, rom, config); - compareCounters(input.virtualCounters, res.counters); + if (skipVcounters !== 'yes') { + compareCounters(input.virtualCounters, res.counters); + } } catch (err) { fs.writeFileSync(checkerDir, `Failed test ${inputPath} - ${err}}`); throw err;