Skip to content

Commit 78157f7

Browse files
EIP 7823 and 7883 --- Osaka MODEXP changes (#823)
Signed-off-by: F Bojarski <[email protected]> Co-authored-by: F Bojarski <[email protected]>
1 parent da4dcd9 commit 78157f7

File tree

38 files changed

+1223
-454
lines changed

38 files changed

+1223
-454
lines changed

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ ALU := alu/add/add.zkasm alu/ext alu/mod alu/mul
1212

1313
BIN := bin/bin.zkasm
1414

15-
BLAKE2f_MODEXP_DATA := blake2fmodexpdata
15+
BLAKE2f_MODEXP_DATA_LONDON := blake2fmodexpdata/london
16+
BLAKE2f_MODEXP_DATA_OSAKA := blake2fmodexpdata/osaka
1617

1718
# constraints used in prod for LINEA, with linea block gas limit
1819
BLOCKDATA_LONDON := blockdata/london
@@ -53,8 +54,6 @@ LOG_DATA := logdata
5354
LOG_INFO_LONDON := loginfo/london
5455
LOG_INFO_CANCUN := loginfo/cancun
5556

56-
MMU := mmu
57-
5857
MMIO_LONDON := mmio/london
5958
MMIO_CANCUN := mmio/cancun
6059

@@ -118,7 +117,6 @@ endef
118117
ZKEVM_MODULES_COMMON := ${CONSTANTS} \
119118
${ALU} \
120119
${BIN} \
121-
${BLAKE2f_MODEXP_DATA} \
122120
${BLOCKHASH} \
123121
${EUC} \
124122
${EXP} \
@@ -136,6 +134,7 @@ ZKEVM_MODULES_COMMON := ${CONSTANTS} \
136134
ZKEVM_MODULES_LONDON := ${ZKEVM_MODULES_COMMON} \
137135
${CONSTANTS_LONDON} \
138136
${TABLES_LONDON} \
137+
${BLAKE2f_MODEXP_DATA_LONDON} \
139138
${BLOCKDATA_LONDON} \
140139
${EC_DATA_LONDON} \
141140
${HUB_LONDON} \
@@ -155,6 +154,7 @@ ZKEVM_MODULES_LONDON := ${ZKEVM_MODULES_COMMON} \
155154
ZKEVM_MODULES_SHANGHAI := ${ZKEVM_MODULES_COMMON} \
156155
${CONSTANTS_LONDON} \
157156
${TABLES_LONDON} \
157+
${BLAKE2f_MODEXP_DATA_LONDON} \
158158
${BLOCKDATA_PARIS} \
159159
${EC_DATA_LONDON} \
160160
${HUB_SHANGHAI} \
@@ -169,8 +169,9 @@ ZKEVM_MODULES_SHANGHAI := ${ZKEVM_MODULES_COMMON} \
169169
${TXN_DATA_SHANGHAI}
170170

171171
ZKEVM_MODULES_CANCUN := ${ZKEVM_MODULES_COMMON} \
172-
${CONSTANTS_CANCUN} \
172+
${CONSTANTS_CANCUN} \
173173
${TABLES_CANCUN} \
174+
${BLAKE2f_MODEXP_DATA_LONDON} \
174175
${BLOCKDATA_CANCUN} \
175176
${BLS_CANCUN} \
176177
${EC_DATA_LONDON} \
@@ -189,6 +190,7 @@ ZKEVM_MODULES_CANCUN := ${ZKEVM_MODULES_COMMON} \
189190
ZKEVM_MODULES_PRAGUE := ${ZKEVM_MODULES_COMMON} \
190191
${CONSTANTS_PRAGUE} \
191192
${TABLES_PRAGUE} \
193+
${BLAKE2f_MODEXP_DATA_LONDON} \
192194
${BLOCKDATA_CANCUN} \
193195
${BLS_PRAGUE} \
194196
${EC_DATA_LONDON} \
@@ -207,6 +209,7 @@ ZKEVM_MODULES_PRAGUE := ${ZKEVM_MODULES_COMMON} \
207209
ZKEVM_MODULES_OSAKA := ${ZKEVM_MODULES_COMMON} \
208210
${CONSTANTS_OSAKA} \
209211
${TABLES_PRAGUE} \
212+
${BLAKE2f_MODEXP_DATA_OSAKA} \
210213
${BLOCKDATA_CANCUN} \
211214
${BLS_PRAGUE} \
212215
${EC_DATA_OSAKA} \
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(module blake2fmodexpdata)
2+
3+
(defcolumns
4+
(STAMP :i16)
5+
(ID :i32)
6+
(PHASE :byte)
7+
(INDEX :byte :display :dec)
8+
(INDEX_MAX :byte :display :dec)
9+
(LIMB :i128 :display :bytes)
10+
(IS_MODEXP_BASE :binary@prove)
11+
(IS_MODEXP_EXPONENT :binary@prove)
12+
(IS_MODEXP_MODULUS :binary@prove)
13+
(IS_MODEXP_RESULT :binary@prove)
14+
(IS_BLAKE_DATA :binary@prove)
15+
(IS_BLAKE_PARAMS :binary@prove)
16+
(IS_BLAKE_RESULT :binary@prove)
17+
)
18+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(module blake2fmodexpdata)
2+
3+
(defconst
4+
INDEX_MAX_MODEXP 63
5+
INDEX_MAX_MODEXP_BASE INDEX_MAX_MODEXP
6+
INDEX_MAX_MODEXP_EXPONENT INDEX_MAX_MODEXP
7+
INDEX_MAX_MODEXP_MODULUS INDEX_MAX_MODEXP
8+
INDEX_MAX_MODEXP_RESULT INDEX_MAX_MODEXP
9+
INDEX_MAX_BLAKE_DATA 12
10+
INDEX_MAX_BLAKE_PARAMS 1
11+
INDEX_MAX_BLAKE_RESULT 3)
12+
13+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
(module blake2fmodexpdata)
2+
3+
(defun (flag-sum)
4+
(+ IS_MODEXP_BASE
5+
IS_MODEXP_EXPONENT
6+
IS_MODEXP_MODULUS
7+
IS_MODEXP_RESULT
8+
IS_BLAKE_DATA
9+
IS_BLAKE_PARAMS
10+
IS_BLAKE_RESULT))
11+
12+
(defun (phase-sum)
13+
(+ (* PHASE_MODEXP_BASE IS_MODEXP_BASE )
14+
(* PHASE_MODEXP_EXPONENT IS_MODEXP_EXPONENT )
15+
(* PHASE_MODEXP_MODULUS IS_MODEXP_MODULUS )
16+
(* PHASE_MODEXP_RESULT IS_MODEXP_RESULT )
17+
(* PHASE_BLAKE_DATA IS_BLAKE_DATA )
18+
(* PHASE_BLAKE_PARAMS IS_BLAKE_PARAMS )
19+
(* PHASE_BLAKE_RESULT IS_BLAKE_RESULT )))
20+
21+
(defun (index-max-sum)
22+
(+ (* INDEX_MAX_MODEXP_BASE IS_MODEXP_BASE )
23+
(* INDEX_MAX_MODEXP_EXPONENT IS_MODEXP_EXPONENT )
24+
(* INDEX_MAX_MODEXP_MODULUS IS_MODEXP_MODULUS )
25+
(* INDEX_MAX_MODEXP_RESULT IS_MODEXP_RESULT )
26+
(* INDEX_MAX_BLAKE_DATA IS_BLAKE_DATA )
27+
(* INDEX_MAX_BLAKE_PARAMS IS_BLAKE_PARAMS )
28+
(* INDEX_MAX_BLAKE_RESULT IS_BLAKE_RESULT )))
29+
30+
(defconstraint no-stamp-no-flag ()
31+
(if-zero STAMP
32+
(vanishes! (flag-sum))
33+
(eq! (flag-sum) 1)))
34+
35+
(defconstraint set-phase ()
36+
(eq! PHASE (phase-sum)))
37+
38+
(defconstraint set-index-max ()
39+
(eq! INDEX_MAX (index-max-sum)))
40+
41+
(defconstraint stamp-constancies ()
42+
(stamp-constancy STAMP ID))
43+
44+
(defconstraint index-constancies (:guard INDEX)
45+
(remained-constant! (phase-sum)))
46+
47+
(defconstraint first-row (:domain {0})
48+
(vanishes! STAMP))
49+
50+
(defconstraint no-stamp-nothing ()
51+
(if-zero STAMP
52+
(begin (vanishes! ID)
53+
(vanishes! (next INDEX)))))
54+
55+
(defun (stamp-increment)
56+
(force-bin (+ (* (- 1 IS_MODEXP_BASE) (next IS_MODEXP_BASE))
57+
(* (- 1 IS_BLAKE_DATA) (next IS_BLAKE_DATA)))))
58+
59+
(defconstraint stamp-increases ()
60+
(will-inc! STAMP (stamp-increment)))
61+
62+
(defun (transition-bit)
63+
(force-bin (+ (* IS_MODEXP_BASE (next IS_MODEXP_EXPONENT))
64+
(* IS_MODEXP_EXPONENT (next IS_MODEXP_MODULUS))
65+
(* IS_MODEXP_MODULUS (next IS_MODEXP_RESULT))
66+
(* IS_MODEXP_RESULT
67+
(+ (next IS_MODEXP_BASE) (next IS_BLAKE_DATA)))
68+
(* IS_BLAKE_DATA (next IS_BLAKE_PARAMS))
69+
(* IS_BLAKE_PARAMS (next IS_BLAKE_RESULT))
70+
(* IS_BLAKE_RESULT
71+
(+ (next IS_MODEXP_BASE) (next IS_BLAKE_DATA))))))
72+
73+
(defconstraint heartbeat (:guard STAMP)
74+
(if-zero (- INDEX_MAX INDEX)
75+
(eq! (transition-bit) 1)
76+
(will-inc! INDEX 1)))
77+
78+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(defun (blake2fmodexpdata-into-wcp-oob-into-wcp-activation-flag)
2+
(force-bin (* (~ blake2fmodexpdata.STAMP)
3+
(- blake2fmodexpdata.STAMP (prev blake2fmodexpdata.STAMP)))))
4+
5+
(defclookup
6+
blake2fmodexpdata-into-wcp
7+
;; target colums (in WCP)
8+
(
9+
wcp.ARG_1
10+
wcp.ARG_2
11+
wcp.RES
12+
wcp.INST
13+
)
14+
;; source selector
15+
(blake2fmodexpdata-into-wcp-oob-into-wcp-activation-flag)
16+
;; source columns
17+
(
18+
(prev blake2fmodexpdata.ID)
19+
blake2fmodexpdata.ID
20+
1
21+
EVM_INST_LT
22+
))
23+
24+

constants/constants.lisp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@
228228
GAS_CONST_IDENTITY 15
229229
GAS_CONST_IDENTITY_WORD 3
230230
GAS_CONST_MODEXP 200
231+
GAS_CONST_MODEXP_EIP_7823 500
231232
GAS_CONST_ECADD 150
232233
GAS_CONST_ECMUL 6000
233234
GAS_CONST_ECPAIRING 45000
@@ -270,6 +271,7 @@
270271
HISTORY_STORAGE_ADDRESS_HI 0x0000f908
271272
HISTORY_STORAGE_ADDRESS_LO 0x27f1c53a10cb7a02335b175320002935
272273
EIP_7825_TRANSACTION_GAS_LIMIT_CAP 0x1000000 ;; 2^24 == 16777216 appears in OSAKA
274+
EIP_7823_MODEXP_UPPER_BYTE_SIZE_BOUND 1024
273275
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
274276
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;
275277
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; LINEA MISC ;;

0 commit comments

Comments
 (0)