Skip to content

Commit

Permalink
Merge pull request #344 from 0xPolygonHermez/develop-no-opt
Browse files Browse the repository at this point in the history
Develop no opt
  • Loading branch information
krlosMata authored Mar 4, 2024
2 parents af93940 + 51b9c86 commit e80542f
Show file tree
Hide file tree
Showing 20 changed files with 414 additions and 251 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions main/constants.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion main/load-tx-rlp.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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
2 changes: 1 addition & 1 deletion main/opcodes/calldata-returndata-code.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 19 additions & 16 deletions main/opcodes/logs.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* - stack output: none
*/
VAR GLOBAL opLogAux

VAR GLOBAL logNextHashPIdAux
opLOG0:
; checks zk-counters
%MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
Expand Down Expand Up @@ -45,15 +45,15 @@ 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--)
$ => C :MLOAD(SP)
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
Expand All @@ -66,15 +66,15 @@ 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--)
$ => C :MLOAD(SP)
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
Expand All @@ -87,15 +87,15 @@ 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--)
$ => C :MLOAD(SP)
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
Expand All @@ -108,15 +108,15 @@ 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--)
$ => C :MLOAD(SP)
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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -174,16 +180,13 @@ 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)
A - 1 => A :JMP(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)]
Expand Down
Loading

0 comments on commit e80542f

Please sign in to comment.