Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/small optimizations #332

Merged
merged 4 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 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,15 +201,15 @@ 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
CONST %OPCALLDATALOAD_CNT_PADDING_PG = 0 + %SHLARITH_CNT_PADDING_PG + %SHRARITH_CNT_PADDING_PG + %DIVARITH_CNT_PADDING_PG
CONST %OPCALLDATALOAD_CNT_POSEIDON_G = 0 + %SHLARITH_CNT_POSEIDON_G + %SHRARITH_CNT_POSEIDON_G + %DIVARITH_CNT_POSEIDON_G
; opCALLDATACOPY - COMPLEX - hardcoded values at test
CONST %OPCALLDATACOPY_STEP = 500
CONST %OPCALLDATACOPY_CNT_BINARY = 21
CONST %OPCALLDATACOPY_CNT_BINARY = 16
CONST %OPCALLDATACOPY_CNT_ARITH = 8
CONST %OPCALLDATACOPY_CNT_KECCAK_F = 0
CONST %OPCALLDATACOPY_CNT_MEM_ALIGN = 2
Expand All @@ -225,87 +225,87 @@ 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
CONST %OPCALLCODE_CNT_PADDING_PG = 0
CONST %OPCALLCODE_CNT_POSEIDON_G = 10
; opRETURN - COMPLEX - hardcoded values at test
CONST %OPRETURN_STEP = 700
CONST %OPRETURN_CNT_BINARY = 35
CONST %OPRETURN_CNT_BINARY = 25
CONST %OPRETURN_CNT_ARITH = 11
CONST %OPRETURN_CNT_KECCAK_F = 0
CONST %OPRETURN_CNT_MEM_ALIGN = 4
CONST %OPRETURN_CNT_PADDING_PG = 0
CONST %OPRETURN_CNT_POSEIDON_G = 0
; opREVERT - COMPLEX - hardcoded values at test
CONST %OPREVERT_STEP = 700
CONST %OPREVERT_CNT_BINARY = 35
CONST %OPREVERT_CNT_BINARY = 25
CONST %OPREVERT_CNT_ARITH = 11
CONST %OPREVERT_CNT_KECCAK_F = 0
CONST %OPREVERT_CNT_MEM_ALIGN = 4
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
2 changes: 1 addition & 1 deletion counters/tests/MSTOREX.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ operation:
:CALL(MSTOREX)

%MSTOREX_STEP - STEP:JMPN(failedCounters)
12 - CNT_BINARY :JMPNZ(failedCounters)
11 - CNT_BINARY :JMPNZ(failedCounters)
;%MSTOREX_CNT_BINARY - CNT_BINARY :JMPNZ(failedCounters)
7 - CNT_ARITH :JMPNZ(failedCounters)
;%MSTOREX_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
Loading
Loading