From 81ab5d5188a5e719b1fdd635fdc0ad31efa9e1f6 Mon Sep 17 00:00:00 2001 From: krlosMata Date: Wed, 5 Apr 2023 13:26:51 +0200 Subject: [PATCH] add full test read-push --- test/performance/read-push.zkasm | 71 ++++++++ test/read-push.zkasm | 304 +++++++++++++++++++++++++++++++ test/rotate.zkasm | 61 ------- tools/run-tests-zkasm.js | 6 +- 4 files changed, 376 insertions(+), 66 deletions(-) create mode 100644 test/performance/read-push.zkasm create mode 100644 test/read-push.zkasm delete mode 100644 test/rotate.zkasm diff --git a/test/performance/read-push.zkasm b/test/performance/read-push.zkasm new file mode 100644 index 00000000..81d57f44 --- /dev/null +++ b/test/performance/read-push.zkasm @@ -0,0 +1,71 @@ +VAR GLOBAL test + +;; Comments 'readPush' function +; @info Read bytes opcode PUSHX +; @internalParam {numBlocks} 4 bytes blocks to read +; @internalParam {leftBytes} remaining bytes +; @in D => bytes to read +; @out E => value read + +start: + ; init vars + 0 => HASHPOS + 1 => D + $${var rounds} + + ; add bytes one by one + 0x0102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F20n => A :CALL(initLoop) + 0x2122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F40n => A :CALL(initLoop) + 0x4142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F60n => A :CALL(initLoop) + + ; close hash + HASHPOS :HASHPLEN(0) + $ :HASHPDIGEST(0) + 0 :MSTORE(contractHashId) + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ;;;;; INIT TESTS ;;;;; + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ; log init counters + CNT_BINARY => A + ; ${log(A, binaryCouners)} ; result: 1 + STEP => A + ; ${log(A, stepCounter)} ; result: 202 + + ; Start test PUSH1 + + ; PUSH1 reading 1 byte at position 0 in the bytecode + 0 => PC + 1 => D :CALL(readPush) + 0x01 => A + E :ASSERT + + ; PUSH1 reading 1 byte at position 1 in the bytecode + 20 => PC + 1 => D :CALL(readPush) + 0x02 => A + E :ASSERT + + ; PUSH1 reading 1 byte at position 2 in the bytecode + 2 => PC + 1 => D :CALL(readPush) + 0x03 => A + E :ASSERT + + + 0 => A,B,C,D,E,CTX, SP, PC, GAS, SR, HASHPOS, RR ; Set all registers to 0 + :JMP(finalizeExecution) + +initLoop: + $${rounds = 31} + 0 => B ; to allow $$ + +loopAdd32Byte: + ${(A >> (rounds * 8)) & 0xFF} :HASHP1(0) + $${rounds = rounds - 1} + ${rounds} :JMPZ(endLoop, loopAdd32Byte) + +endLoop: + :RETURN + +INCLUDE "../../main/main.zkasm" diff --git a/test/read-push.zkasm b/test/read-push.zkasm new file mode 100644 index 00000000..2dd66de7 --- /dev/null +++ b/test/read-push.zkasm @@ -0,0 +1,304 @@ +VAR GLOBAL test + +;; Comments 'readPush' function +; @info Read bytes opcode PUSHX +; @internalParam {numBlocks} 4 bytes blocks to read +; @internalParam {leftBytes} remaining bytes +; @in D => bytes to read +; @out E => value read + +start: + ; init vars + 0 => HASHPOS + 1 => D + $${var rounds} + + ; add bytes one by one + 0x0102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F20n => A :CALL(initLoop) + 0x2122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F40n => A :CALL(initLoop) + 0x4142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F60n => A :CALL(initLoop) + + ; close hash + HASHPOS :HASHPLEN(0) + $ :HASHPDIGEST(0) + 0 :MSTORE(contractHashId) + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ;;;;; INIT TESTS ;;;;; + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ; log init counters + CNT_BINARY => A + ; ${log(A, binaryCouners)} ; result: 1 + STEP => A + ; ${log(A, stepCounter)} ; result: 202 + + ;; Start test PUSH1 + ; PUSH1 reading 1 byte at position 0 in the bytecode + 0 => PC + 1 => D :CALL(readPush) + 0x01 => A + E :ASSERT + + ; PUSH1 reading 1 byte at position 20 in the bytecode + 20 => PC + 1 => D :CALL(readPush) + 0x15 => A + E :ASSERT + + ; PUSH1 reading 1 byte at position 31 in the bytecode + 31 => PC + 1 => D :CALL(readPush) + 0x20 => A + E :ASSERT + + ; PUSH1 reading 1 byte at position 32 in the bytecode + 32 => PC + 1 => D :CALL(readPush) + 0x21 => A + E :ASSERT + + ; PUSH1 reading 1 byte at position 33 in the bytecode + 33 => PC + 1 => D :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) + 0x0506 => A + E :ASSERT + + ; PUSH2 reading 2 byte at position 34 in the bytecode + 34 => PC + 2 => D :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) + 0x3d3e3f => A + E :ASSERT + + ;; Start test PUSH4 + ; PUSH4 reading 4 byte at position 72 in the bytecode + 72 => PC + 4 => D :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) + 0x2B2C2D2E2Fn => A + E :ASSERT + + ;; Start test PUSH6 + ; PUSH6 reading 6 byte at position 42 in the bytecode + 42 => PC + 6 => D :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) + 0x2B2C2D2E2F3031n => A + E :ASSERT + + ;; Start test PUSH8 + ; PUSH8 reading 8 byte at position 42 in the bytecode + 42 => PC + 8 => D :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) + 0x2B2C2D2E2F30313233n => A + E :ASSERT + + ;; Start test PUSH10 + ; PUSH10 reading 10 byte at position 42 in the bytecode + 42 => PC + 10 => D :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) + 0x2B2C2D2E2F303132333435n => A + E :ASSERT + + ;; Start test PUSH12 + ; PUSH12 reading 12 byte at position 42 in the bytecode + 42 => PC + 12 => D :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) + 0x2B2C2D2E2F3031323334353637n => A + E :ASSERT + + ;; Start test PUSH14 + ; PUSH14 reading 14 byte at position 42 in the bytecode + 42 => PC + 14 => D :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) + 0x2B2C2D2E2F30313233343536373839n => A + E :ASSERT + + ;; Start test PUSH16 + ; PUSH16 reading 16 byte at position 42 in the bytecode + 42 => PC + 16 => D :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) + 0x2B2C2D2E2F303132333435363738393A3Bn => A + E :ASSERT + + ;; Start test PUSH18 + ; PUSH18 reading 18 byte at position 42 in the bytecode + 42 => PC + 18 => D :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) + 0x2B2C2D2E2F303132333435363738393A3B3C3Dn => A + E :ASSERT + + ;; Start test PUSH20 + ; PUSH20 reading 20 byte at position 42 in the bytecode + 42 => PC + 20 => D :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) + 0x2B2C2D2E2F303132333435363738393A3B3C3D3E3Fn => A + E :ASSERT + + ;; Start test PUSH22 + ; PUSH22 reading 22 byte at position 42 in the bytecode + 42 => PC + 22 => D :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) + 0x2B2C2D2E2F303132333435363738393A3B3C3D3E3F4041n => A + E :ASSERT + + ;; Start test PUSH24 + ; PUSH24 reading 24 byte at position 42 in the bytecode + 42 => PC + 24 => D :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) + 0x2B2C2D2E2F303132333435363738393A3B3C3D3E3F40414243n => A + E :ASSERT + + ;; Start test PUSH26 + ; PUSH26 reading 26 byte at position 42 in the bytecode + 42 => PC + 26 => D :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) + 0x2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445n => A + E :ASSERT + + ;; Start test PUSH28 + ; PUSH28 reading 28 byte at position 42 in the bytecode + 42 => PC + 28 => D :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) + 0x2B2C2D2E2F303132333435363738393A3B3C3D3E3F4041424344454647n => A + E :ASSERT + + ;; Start test PUSH30 + ; PUSH30 reading 30 byte at position 42 in the bytecode + 42 => PC + 30 => D :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) + 0x2B2C2D2E2F303132333435363738393A3B3C3D3E3F40414243444546474849n => A + E :ASSERT + + ;; Start test PUSH32 + ; PUSH32 reading 32 byte at position 42 in the bytecode + 42 => PC + 32 => D :CALL(readPush) + 0x2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494An => A + E :ASSERT + + 0 => A,B,C,D,E,CTX, SP, PC, GAS, SR, HASHPOS, RR ; Set all registers to 0 + :JMP(finalizeExecution) + +initLoop: + $${rounds = 32} + 0 => B ; to allow $$ + +loopAdd32Byte: + $${rounds = rounds - 1} + ${(A >> (rounds * 8)) & 0xFF} => E :HASHP1(0) + ${rounds} :JMPZ(endLoop, loopAdd32Byte) + +endLoop: + :RETURN + +INCLUDE "../main/main.zkasm" diff --git a/test/rotate.zkasm b/test/rotate.zkasm deleted file mode 100644 index f14f3af9..00000000 --- a/test/rotate.zkasm +++ /dev/null @@ -1,61 +0,0 @@ -VAR GLOBAL test -; test valid for op-arith-final_0.json input -start: - 0 => E - 0x270b206cd7f7637a125ddc55aef59e54ef3ea0898dbc9b9094e5665fcd937bedn => A - ; "0x270b206cd7f7637a125ddc55aef59e54ef3ea0898dbc9b9094e5665fcd937bed": - ;"0x608060405234801561001057600080fd5b50600436106100885760003560e01c - ; 806364fbb77c1161005b57806364fbb77c146100c75780636664f730146100d1 - ; 578063bfb371c2146100ed578063c68f6d1a146100f757610088565b80630e4d - ; 2d021461008d5780631592781914610097578063242e46d2146100a157806339 - ; 31a6b3146100bd575b600080fd5b610095610101565b005b61009f61010d565b - ; 005b6100bb60048036038101906100b69190610180565b610119565b005b6100 - ; c561012f565b005b6100cf61013b565b005b6100eb60048036038101906100e6 - ; 9190610180565b61013d565b005b6100f5610153565b005b6100ff61015f565b - ; 005b6002600a048060005550565b60026001018060005550565b808261012591 - ; 90610216565b6000819055505050565b60046003028060005550565b005b8082 - ; 61014991906101c0565b6000819055505050565b6002600a058060005550565b - ; 60056006038060005550565b60008135905061017a816102b4565b9291505056 - ; 5b60008060408385031215610197576101966102af565b5b60006101a5858286 - ; 0161016b565b92505060206101b68582860161016b565b915050925092905056 - ; 5b60006101cb82610247565b91506101d683610247565b9250827fffffffffff - ; ffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561 - ; 020b5761020a610251565b5b828201905092915050565b600061022182610247 - ; 565b915061022c83610247565b92508261023c5761023b610280565b5b828204 - ; 905092915050565b6000819050919050565b7f4e487b71000000000000000000 - ; 00000000000000000000000000000000000000600052601160045260246000fd - ; 5b7f4e487b710000000000000000000000000000000000000000000000000000 - ; 0000600052601260045260246000fd5b600080fd5b6102bd81610247565b8114 - ; 6102c857600080fd5b5056fea264697066735822122046eacdba7371636f1207 - ; 79f19da9f157d18a1c0bb321f5f890873de82d15f6ca64736f6c634300080700 - ; 33", - - ; load contract bytecode - A :HASHPDIGEST(E) - - 1 => D - 0 :MSTORE(contractHashId) - 1 => PC - 0x80 :MSTORE(test) - :CALL(readPush); in: [D: bytes to read] out: [E: value read] - E :MLOAD(test) - - 31 => PC - 0x1c :MSTORE(test) - :CALL(readPush); in: [D: bytes to read] out: [E: value read] - E :MLOAD(test) - - 480 => PC - 0xff :MSTORE(test) - :CALL(readPush); in: [D: bytes to read] out: [E: value read] - E :MLOAD(test) - - 768 => PC - 0x33 :MSTORE(test) - :CALL(readPush); in: [D: bytes to read] out: [E: value read] - E :MLOAD(test) - -0 => A,B,C,D,E,CTX, SP, PC, GAS, SR, HASHPOS, RR ; Set all registers to 0 - :JMP(finalizeExecution) - -INCLUDE "../main/main.zkasm" diff --git a/tools/run-tests-zkasm.js b/tools/run-tests-zkasm.js index 550cf5cd..21d5984a 100644 --- a/tools/run-tests-zkasm.js +++ b/tools/run-tests-zkasm.js @@ -6,7 +6,6 @@ const chalk = require('chalk'); const zkasm = require('@0xpolygonhermez/zkasmcom'); const smMain = require('@0xpolygonhermez/zkevm-proverjs/src/sm/sm_main/sm_main'); -const nonEmptyInput = require('@0xpolygonhermez/zkevm-testvectors/inputs-executor/calldata/op-arith-final_0.json'); const emptyInput = require('@0xpolygonhermez/zkevm-proverjs/test/inputs/empty_input.json'); const { argv } = require('yargs') @@ -46,12 +45,9 @@ async function runTest(pathTest, cmPols) { assertOutputs: false, }; - // list test that needs a non empty input - const input = pathTest.includes('rotate.zkasm') ? nonEmptyInput : emptyInput; - // execute zkasm tests try { - const result = await smMain.execute(cmPols.Main, input, rom, config); + const result = await smMain.execute(cmPols.Main, emptyInput, rom, config); console.log(chalk.green(' --> pass'), pathTest); if (argv.verbose) { console.log(chalk.blue(' --> verbose'));