Skip to content

Commit

Permalink
Merge pull request #285 from 0xPolygonHermez/feature/push-tests
Browse files Browse the repository at this point in the history
add full test read-push
  • Loading branch information
krlosMata authored Apr 13, 2023
2 parents f2d6c10 + 81ab5d5 commit 9c6f55f
Show file tree
Hide file tree
Showing 4 changed files with 376 additions and 66 deletions.
71 changes: 71 additions & 0 deletions test/performance/read-push.zkasm
Original file line number Diff line number Diff line change
@@ -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"
304 changes: 304 additions & 0 deletions test/read-push.zkasm
Original file line number Diff line number Diff line change
@@ -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"
Loading

0 comments on commit 9c6f55f

Please sign in to comment.