Skip to content

Commit

Permalink
Merge branch 'develop-eldelberry' into feature/mstorex-optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
zkronos73 authored Feb 11, 2024
2 parents b9e2411 + e6bef57 commit d3bbb56
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 133 deletions.
28 changes: 14 additions & 14 deletions counters/countersConstants.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CONST %SHRARITHBIT_CNT_PADDING_PG = 0 + %DIVARITH_CNT_PADDING_PG
CONST %SHRARITHBIT_CNT_POSEIDON_G = 0 + %DIVARITH_CNT_POSEIDON_G
;offsetUtil
CONST %OFFSETUTIL_STEP = 20
CONST %OFFSETUTIL_CNT_BINARY = 1
CONST %OFFSETUTIL_CNT_BINARY = 0
CONST %OFFSETUTIL_CNT_ARITH = 0
CONST %OFFSETUTIL_CNT_KECCAK_F = 0
CONST %OFFSETUTIL_CNT_MEM_ALIGN = 0
Expand Down Expand Up @@ -55,7 +55,7 @@ CONST %MLOADX_CNT_MEM_ALIGN = 1 + %SHRARITH_CNT_MEM_ALIGN + %SHLARITH_CNT_MEM_AL
CONST %MLOADX_CNT_PADDING_PG = 0 + %SHRARITH_CNT_PADDING_PG + %SHLARITH_CNT_PADDING_PG + %OFFSETUTIL_CNT_PADDING_PG
CONST %MLOADX_CNT_POSEIDON_G = 0 + %SHRARITH_CNT_POSEIDON_G + %SHLARITH_CNT_POSEIDON_G + %OFFSETUTIL_CNT_POSEIDON_G
; MLOAD32
CONST %MLOAD32_STEP = 100 + %OFFSETUTIL_STEP
CONST %MLOAD32_STEP = 50 + %OFFSETUTIL_STEP
CONST %MLOAD32_CNT_BINARY = 1 + %OFFSETUTIL_CNT_BINARY
CONST %MLOAD32_CNT_ARITH = 0 + %OFFSETUTIL_CNT_ARITH
CONST %MLOAD32_CNT_KECCAK_F = 0 + %OFFSETUTIL_CNT_KECCAK_F
Expand Down Expand Up @@ -201,7 +201,7 @@ CONST %OPBLOCKHASH_CNT_PADDING_PG = 0
CONST %OPBLOCKHASH_CNT_POSEIDON_G = 2
; opCALLDATALOAD
CONST %OPCALLDATALOAD_STEP = 100 + %SHLARITH_STEP + %SHRARITH_STEP + %DIVARITH_STEP
CONST %OPCALLDATALOAD_CNT_BINARY = 3
CONST %OPCALLDATALOAD_CNT_BINARY = 2
CONST %OPCALLDATALOAD_CNT_ARITH = 0
CONST %OPCALLDATALOAD_CNT_KECCAK_F = 0 + %SHLARITH_CNT_KECCAK_F + %SHRARITH_CNT_KECCAK_F + %DIVARITH_CNT_KECCAK_F
CONST %OPCALLDATALOAD_CNT_MEM_ALIGN = 1
Expand All @@ -225,47 +225,47 @@ CONST %OPRETURNDATACOPY_CNT_PADDING_PG = 0
CONST %OPRETURNDATACOPY_CNT_POSEIDON_G = 0
; opCODECOPY - COMPLEX - hardcoded values at test
CONST %OPCODECOPY_STEP = 1700
CONST %OPCODECOPY_CNT_BINARY = 100
CONST %OPCODECOPY_CNT_BINARY = 55
CONST %OPCODECOPY_CNT_ARITH = 4
CONST %OPCODECOPY_CNT_KECCAK_F = 0
CONST %OPCODECOPY_CNT_MEM_ALIGN = 43
CONST %OPCODECOPY_CNT_PADDING_PG = 0
CONST %OPCODECOPY_CNT_POSEIDON_G = 0
; opEXTCODECOPY - COMPLEX - hardcoded values at test
CONST %OPEXTCODECOPY_STEP = 2000
CONST %OPEXTCODECOPY_CNT_BINARY = 104
CONST %OPEXTCODECOPY_CNT_BINARY = 59
CONST %OPEXTCODECOPY_CNT_ARITH = 4
CONST %OPEXTCODECOPY_CNT_KECCAK_F = 0
CONST %OPEXTCODECOPY_CNT_MEM_ALIGN = 43
CONST %OPEXTCODECOPY_CNT_PADDING_PG = 0
CONST %OPEXTCODECOPY_CNT_POSEIDON_G = 8
; opCREATE - COMPLEX - hardcoded values at test
CONST %OPCREATE_STEP = 400
CONST %OPCREATE_CNT_BINARY = 16
CONST %OPCREATE_CNT_BINARY = 13
CONST %OPCREATE_CNT_ARITH = 1
CONST %OPCREATE_CNT_KECCAK_F = 0
CONST %OPCREATE_CNT_MEM_ALIGN = 0
CONST %OPCREATE_CNT_PADDING_PG = 0
CONST %OPCREATE_CNT_POSEIDON_G = 23
; opCREATE2 - COMPLEX - hardcoded values at test
CONST %OPCREATE2_STEP = 400
CONST %OPCREATE2_CNT_BINARY = 21
CONST %OPCREATE2_CNT_BINARY = 18
CONST %OPCREATE2_CNT_ARITH = 2
CONST %OPCREATE2_CNT_KECCAK_F = 0
CONST %OPCREATE2_CNT_MEM_ALIGN = 0
CONST %OPCREATE2_CNT_PADDING_PG = 0
CONST %OPCREATE2_CNT_POSEIDON_G = 27
; opCALL - COMPLEX - hardcoded values at test
CONST %OPCALL_STEP = 600
CONST %OPCALL_CNT_BINARY = 27
CONST %OPCALL_CNT_BINARY = 22
CONST %OPCALL_CNT_ARITH = 3
CONST %OPCALL_CNT_KECCAK_F = 0
CONST %OPCALL_CNT_MEM_ALIGN = 0
CONST %OPCALL_CNT_PADDING_PG = 0
CONST %OPCALL_CNT_POSEIDON_G = 14
; opCALLCODE - COMPLEX - hardcoded values at test
CONST %OPCALLCODE_STEP = 600
CONST %OPCALLCODE_CNT_BINARY = 26
CONST %OPCALLCODE_CNT_BINARY = 21
CONST %OPCALLCODE_CNT_ARITH = 3
CONST %OPCALLCODE_CNT_KECCAK_F = 0
CONST %OPCALLCODE_CNT_MEM_ALIGN = 0
Expand All @@ -289,23 +289,23 @@ CONST %OPREVERT_CNT_PADDING_PG = 0
CONST %OPREVERT_CNT_POSEIDON_G = 0
; opDELEGATECALL - COMPLEX - hardcoded values at test
CONST %OPDELEGATECALL_STEP = 600
CONST %OPDELEGATECALL_CNT_BINARY = 23
CONST %OPDELEGATECALL_CNT_BINARY = 18
CONST %OPDELEGATECALL_CNT_ARITH = 3
CONST %OPDELEGATECALL_CNT_KECCAK_F = 0
CONST %OPDELEGATECALL_CNT_MEM_ALIGN = 0
CONST %OPDELEGATECALL_CNT_PADDING_PG = 0
CONST %OPDELEGATECALL_CNT_POSEIDON_G = 6
; opSTATICCALL - COMPLEX - hardcoded values at test
CONST %OPSTATICCALL_STEP = 600
CONST %OPSTATICCALL_CNT_BINARY = 23
CONST %OPSTATICCALL_CNT_BINARY = 18
CONST %OPSTATICCALL_CNT_ARITH = 3
CONST %OPSTATICCALL_CNT_KECCAK_F = 0
CONST %OPSTATICCALL_CNT_MEM_ALIGN = 0
CONST %OPSTATICCALL_CNT_PADDING_PG = 0
CONST %OPSTATICCALL_CNT_POSEIDON_G = 6
; opSHA3 - COMPLEX - hardcoded values at test
CONST %OPSHA3_STEP = 3300
CONST %OPSHA3_CNT_BINARY = 146
CONST %OPSHA3_CNT_BINARY = 81
CONST %OPSHA3_CNT_ARITH = 9
CONST %OPSHA3_CNT_KECCAK_F = 15
CONST %OPSHA3_CNT_MEM_ALIGN = 63
Expand Down Expand Up @@ -337,15 +337,15 @@ CONST %ISEMPTYACCOUNT_CNT_PADDING_PG = 0
CONST %ISEMPTYACCOUNT_CNT_POSEIDON_G = 6
; computeGasSendCall
CONST %COMPUTEGASSENDCALL_STEP = 30
CONST %COMPUTEGASSENDCALL_CNT_BINARY = 2
CONST %COMPUTEGASSENDCALL_CNT_BINARY = 1
CONST %COMPUTEGASSENDCALL_CNT_ARITH = 0
CONST %COMPUTEGASSENDCALL_CNT_KECCAK_F = 0
CONST %COMPUTEGASSENDCALL_CNT_MEM_ALIGN = 0
CONST %COMPUTEGASSENDCALL_CNT_PADDING_PG = 0
CONST %COMPUTEGASSENDCALL_CNT_POSEIDON_G = 0
; saveMem
CONST %SAVEMEM_STEP = 100 + %MULARITH_STEP + %DIVARITH_STEP
CONST %SAVEMEM_CNT_BINARY = 5 + %MULARITH_CNT_BINARY + %DIVARITH_CNT_BINARY
CONST %SAVEMEM_CNT_BINARY = 3 + %MULARITH_CNT_BINARY + %DIVARITH_CNT_BINARY
CONST %SAVEMEM_CNT_ARITH = 0 + %MULARITH_CNT_ARITH + %DIVARITH_CNT_ARITH
CONST %SAVEMEM_CNT_KECCAK_F = 0 + %MULARITH_CNT_KECCAK_F + %DIVARITH_CNT_KECCAK_F
CONST %SAVEMEM_CNT_MEM_ALIGN = 0 + %MULARITH_CNT_MEM_ALIGN + %DIVARITH_CNT_MEM_ALIGN
Expand Down
2 changes: 1 addition & 1 deletion counters/tests/MLOADX.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ operation:
:CALL(MLOADX)

%MLOADX_STEP - STEP :JMPN(failedCounters)
5 - CNT_BINARY :JMPNZ(failedCounters)
4 - CNT_BINARY :JMPNZ(failedCounters)
;%MLOADX_CNT_BINARY - CNT_BINARY :JMPNZ(failedCounters)
3 - CNT_ARITH :JMPNZ(failedCounters)
;%MLOADX_CNT_ARITH - CNT_ARITH :JMPNZ(failedCounters)
Expand Down
7 changes: 0 additions & 7 deletions counters/tests/opCREATE2.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ operation:
1000 :MSTORE(SP++)
:JMP(opCREATE2)
checkCounters:
%OPCREATE2_STEP - STEP:JMPN(failedCounters)
%OPCREATE2_CNT_BINARY - CNT_BINARY :JMPNZ(failedCounters)
%OPCREATE2_CNT_ARITH - CNT_ARITH :JMPNZ(failedCounters)
%OPCREATE2_CNT_KECCAK_F - CNT_KECCAK_F :JMPNZ(failedCounters)
%OPCREATE2_CNT_MEM_ALIGN - CNT_MEM_ALIGN :JMPNZ(failedCounters)
%OPCREATE2_CNT_PADDING_PG - CNT_PADDING_PG :JMPNZ(failedCounters)
%OPCREATE2_CNT_POSEIDON_G - CNT_POSEIDON_G :JMPNZ(failedCounters)

0 => A,B,C,D,E,CTX, SP, PC, GAS, SR, HASHPOS, RR ; Set all registers to 0
finalizeExecution:
Expand Down
64 changes: 32 additions & 32 deletions main/map-opcodes.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions main/opcodes/calldata-returndata-code.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,9 @@ opRETURNDATASIZE:
; check out-of-gas
GAS - %GAS_QUICK_STEP => GAS :JMPN(outOfGas)
; Load ret data length from last ctx
$ => B :MLOAD(retDataCTX)
; if no retDataCTX(0), retDataLength = 0
0 => A
$ :EQ, JMPC(endOpRETURNDATASIZE)
B => CTX
$ => A :MLOAD(retDataCTX), JMPZ(endOpRETURNDATASIZE)
A => CTX
$ => A :MLOAD(retDataLength)
; Restore current context
$ => CTX :MLOAD(currentCTX)
Expand Down Expand Up @@ -522,10 +520,7 @@ opRETURNDATACOPY:
; store lastMemLength for memory expansion gas cost
C :MSTORE(lastMemLength), CALL(saveMem); in: [lastMemOffset, lastMemLength]
; if retDataCTX is 0, end opcode execution
$ => B :MLOAD(retDataCTX)
0 => A
$ :EQ, JMPC(opRETURNDATACOPYEmpty)

$ => B :MLOAD(retDataCTX), JMPZ(opRETURNDATACOPYEmpty)
; Load ret data length from last ctx
B => CTX
E => B
Expand Down
4 changes: 1 addition & 3 deletions main/opcodes/flow-control.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ checkJumpDest:
$ => B :MLOAD(isCreateContract), JMPNZ(checkJumpDestDeployment)
$ => B :MLOAD(bytecodeLength)
$ :LT,JMPNC(invalidJump)
A => B
B => PC
B => HASHPOS
A => PC, HASHPOS
; get hashP address pointer where contract bytecode is stored
$ => E :MLOAD(contractHashId)
$ => A :HASHP1(E)
Expand Down
32 changes: 0 additions & 32 deletions main/opcodes/stack-operations.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -28,133 +28,101 @@ opPUSH0:
*/
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:
Expand Down
Loading

0 comments on commit d3bbb56

Please sign in to comment.