Skip to content

Commit c29b603

Browse files
authored
feat: recognition of new precompile address for secp256r1 curve in TR… (#818)
In Osaka, a new precompile is added at address 0x100. TRM module now recognizes this address as a precompile. As the address of this new precompile is not contiguous like the other ones, we've renamed the constant `MAX_PRC_ADDRESS` to `MAX_PRC_CONTIGUOUS_ADDRESS`
1 parent 70e21b2 commit c29b603

File tree

7 files changed

+69
-8
lines changed

7 files changed

+69
-8
lines changed

Makefile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ CONSTANTS := constants/constants.lisp
2828
CONSTANTS_LONDON := constants/london/constants.zkasm
2929
CONSTANTS_CANCUN := constants/cancun/constants.zkasm
3030
CONSTANTS_PRAGUE := constants/prague/constants.zkasm
31+
CONSTANTS_OSAKA := constants/osaka/constants.zkasm
3132

3233
EC_DATA_LONDON := ecdata/london
3334

@@ -97,7 +98,8 @@ TABLES_LONDON := reftables/london/*.lisp
9798
TABLES_CANCUN := reftables/cancun/*.lisp
9899
TABLES_PRAGUE := reftables/prague/*.lisp
99100

100-
TRM := trm/trm.zkasm
101+
TRM_LONDON := trm/trm_london.zkasm
102+
TRM_OSAKA := trm/trm_osaka.zkasm
101103

102104
TXN_DATA_LONDON := txndata/london
103105
TXN_DATA_SHANGHAI := txndata/shanghai
@@ -129,7 +131,6 @@ ZKEVM_MODULES_COMMON := ${CONSTANTS} \
129131
${SHAKIRA_DATA} \
130132
${SHIFT} \
131133
${STP} \
132-
${TRM} \
133134
${WCP}
134135

135136
ZKEVM_MODULES_LONDON := ${ZKEVM_MODULES_COMMON} \
@@ -145,6 +146,7 @@ ZKEVM_MODULES_LONDON := ${ZKEVM_MODULES_COMMON} \
145146
${OOB_LONDON} \
146147
${RLP_TXN_LONDON} \
147148
${RLP_TXN_RCPT_LONDON} \
149+
${TRM_LONDON} \
148150
${TXN_DATA_LONDON}
149151

150152

@@ -163,6 +165,7 @@ ZKEVM_MODULES_SHANGHAI := ${ZKEVM_MODULES_COMMON} \
163165
${OOB_SHANGHAI} \
164166
${RLP_TXN_LONDON} \
165167
${RLP_TXN_RCPT_LONDON} \
168+
${TRM_LONDON} \
166169
${TXN_DATA_SHANGHAI}
167170

168171
ZKEVM_MODULES_CANCUN := ${ZKEVM_MODULES_COMMON} \
@@ -180,6 +183,7 @@ ZKEVM_MODULES_CANCUN := ${ZKEVM_MODULES_COMMON} \
180183
${RLP_TXN_CANCUN} \
181184
${RLP_TXN_RCPT_LONDON} \
182185
${RLP_UTILS_CANCUN} \
186+
${TRM_LONDON} \
183187
${TXN_DATA_CANCUN}
184188

185189
ZKEVM_MODULES_PRAGUE := ${ZKEVM_MODULES_COMMON} \
@@ -197,10 +201,11 @@ ZKEVM_MODULES_PRAGUE := ${ZKEVM_MODULES_COMMON} \
197201
${RLP_TXN_PRAGUE} \
198202
${RLP_TXN_RCPT_LONDON} \
199203
${RLP_UTILS_CANCUN} \
204+
${TRM_LONDON} \
200205
${TXN_DATA_PRAGUE}
201206

202207
ZKEVM_MODULES_OSAKA := ${ZKEVM_MODULES_COMMON} \
203-
${CONSTANTS_PRAGUE} \
208+
${CONSTANTS_OSAKA} \
204209
${TABLES_PRAGUE} \
205210
${BLOCKDATA_CANCUN} \
206211
${BLS_PRAGUE} \
@@ -214,6 +219,7 @@ ZKEVM_MODULES_OSAKA := ${ZKEVM_MODULES_COMMON} \
214219
${RLP_TXN_PRAGUE} \
215220
${RLP_TXN_RCPT_OSAKA} \
216221
${RLP_UTILS_CANCUN} \
222+
${TRM_OSAKA} \
217223
${TXN_DATA_OSAKA}
218224

219225
all: zkevm_london.bin zkevm_paris.bin zkevm_shanghai.bin zkevm_cancun.bin zkevm_prague.bin zkevm_osaka.bin

constants/cancun/constants.zkasm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
const MAX_PRC_ADDRESS = 0x0a
1+
const MAX_PRC_CONTIGUOUS_ADDRESS = 0x0a

constants/london/constants.zkasm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
const MAX_PRC_ADDRESS = 0x09
1+
const MAX_PRC_CONTIGUOUS_ADDRESS = 0x09

constants/osaka/constants.zkasm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const MAX_PRC_CONTIGUOUS_ADDRESS = 0x11
2+
;; this constant will be used once issue in go-corset is fixed https://github.com/Consensys/go-corset/issues/1284
3+
const P256_VERIFY_ADDRESS = 0x100

constants/prague/constants.zkasm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
const MAX_PRC_ADDRESS = 0x11
1+
const MAX_PRC_CONTIGUOUS_ADDRESS = 0x11

trm/trm.zkasm renamed to trm/trm_london.zkasm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
;;
1818
;; NOTE: the function currently only returns the high word of the
1919
;; trimmed address, since the low word is unchanged.
20+
;; NOTE2: once issue is fixed in go-corset, we will be able to
21+
;; recombine trm_london and trm_osaka
22+
;; https://github.com/Consensys/go-corset/issues/1284
2023
pub fn trm(RAW_ADDRESS u256) -> (ADDRESS_HI u32, IS_PRECOMPILE u1) {
2124
var low, tmp u128
2225
var high u96
@@ -27,8 +30,8 @@ pub fn trm(RAW_ADDRESS u256) -> (ADDRESS_HI u32, IS_PRECOMPILE u1) {
2730
if ADDRESS_HI != 0 goto exit_0
2831
;; discount address 0
2932
if low == 0 goto exit_0
30-
;; determine low <= MAX_PRC_ADDRESS
31-
b,tmp = low - MAX_PRC_ADDRESS - 1
33+
;; determine low <= MAX_PRC_CONTIGUOUS_ADDRESS
34+
b,tmp = low - MAX_PRC_CONTIGUOUS_ADDRESS - 1
3235
;; done
3336
IS_PRECOMPILE=b
3437
return

trm/trm_osaka.zkasm

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
;; The address trimming module does two things: (i) reduce 256bit
2+
;; addresses into u160 addresses (i.e. modulo 2^160); (b) identify
3+
;; addresses of precompiles : {0x1, 0x2 ... 0x11} U {0x100}
4+
;;
5+
;; The need for this function arises as some EVM opcodes take an u256
6+
;; stack argument requires trimming to be interpreted as an address.
7+
;; Likewise, when computing a deployment address associated with an
8+
;; invocation of a CREATE-type, the raw KECCAK hash must be trimmed.
9+
;;
10+
;; The following opcodes may trigger it:
11+
;;
12+
;; * BALANCE
13+
;; * EXTCODESIZE / EXTCODECOPY / EXTCODEHASH
14+
;; * CALL / CALLCODE / STATICCALL
15+
;; * SELFDESTRUCT
16+
;; * DELEGATECALL
17+
;;
18+
;; NOTE: the function currently only returns the high word of the
19+
;; trimmed address, since the low word is unchanged.
20+
;; NOTE2: once issue is fixed in go-corset, we will be able to
21+
;; recombine trm_london and trm_osaka by adding a
22+
;; P256_VERIFY_ADDRESS constant on all forks prior to Osaka
23+
;; whose value will be an already verified prc address
24+
;; https://github.com/Consensys/go-corset/issues/1284
25+
pub fn trm(RAW_ADDRESS u256) -> (ADDRESS_HI u32, IS_PRECOMPILE u1) {
26+
var low, tmp u128
27+
var high u96
28+
var b1 u1
29+
;; trim off most significant 96 bytes
30+
high,ADDRESS_HI,low = RAW_ADDRESS
31+
;; if hi word not zero, cannot be precompile.
32+
if ADDRESS_HI != 0 goto exit_0
33+
;; discount address 0
34+
if low == 0 goto exit_0
35+
;; determine low <= MAX_PRC_CONTIGUOUS_ADDRESS
36+
b1,tmp = low - MAX_PRC_CONTIGUOUS_ADDRESS - 1
37+
;; if not, check low is P256_VERIFY_ADDRESS
38+
if b1 == 0 goto check_p256_verify
39+
;; done
40+
IS_PRECOMPILE=1
41+
return
42+
check_p256_verify:
43+
IS_PRECOMPILE = low == 0x100 ? 1 : 0
44+
return
45+
exit_0:
46+
;; no, not precompile
47+
IS_PRECOMPILE=0
48+
return
49+
}

0 commit comments

Comments
 (0)