@@ -4,12 +4,18 @@ import (
4
4
"encoding/json"
5
5
"errors"
6
6
"fmt"
7
+ "math/big"
7
8
8
9
"github.com/scroll-tech/go-ethereum/common"
10
+ "github.com/scroll-tech/go-ethereum/common/hexutil"
9
11
)
10
12
11
13
const (
12
- euclidFork = "euclid"
14
+ EuclidFork = "euclid"
15
+ EuclidV2Fork = "euclidV2"
16
+
17
+ EuclidForkNameForProver = "euclidv1"
18
+ EuclidV2ForkNameForProver = "euclidv2"
13
19
)
14
20
15
21
// ProofType represents the type of task.
@@ -39,38 +45,102 @@ const (
39
45
ProofTypeBundle
40
46
)
41
47
42
- // ChunkTaskDetail is a type containing ChunkTask detail.
48
+ // ChunkTaskDetail is a type containing ChunkTask detail for chunk task .
43
49
type ChunkTaskDetail struct {
44
- BlockHashes []common.Hash `json:"block_hashes"`
50
+ // use one of the string of EuclidFork / EuclidV2Fork
51
+ ForkName string `json:"fork_name"`
52
+ BlockHashes []common.Hash `json:"block_hashes"`
53
+ PrevMsgQueueHash common.Hash `json:"prev_msg_queue_hash"`
54
+ }
55
+
56
+ // it is a hex encoded big with fixed length on 48 bytes
57
+ type Byte48 struct {
58
+ hexutil.Big
59
+ }
60
+
61
+ func (e Byte48 ) MarshalText () ([]byte , error ) {
62
+ i := e .ToInt ()
63
+ // overrite encode big
64
+ if sign := i .Sign (); sign < 0 {
65
+ // sanity check
66
+ return nil , errors .New ("Byte48 must be positive integer" )
67
+ } else {
68
+ s := i .Text (16 )
69
+ if len (s ) > 96 {
70
+ return nil , errors .New ("integer Exceed 384bit" )
71
+ }
72
+ return []byte (fmt .Sprintf ("0x%0*s" , 96 , s )), nil
73
+ }
74
+ }
75
+
76
+ func isString (input []byte ) bool {
77
+ return len (input ) >= 2 && input [0 ] == '"' && input [len (input )- 1 ] == '"'
78
+ }
79
+
80
+ // hexutil.Big has limition of 256bit so we have to override it ...
81
+ func (e * Byte48 ) UnmarshalJSON (input []byte ) error {
82
+ if ! isString (input ) {
83
+ return errors .New ("not hex string" )
84
+ }
85
+
86
+ b , err := hexutil .Decode (string (input [1 : len (input )- 1 ]))
87
+ if err != nil {
88
+ return err
89
+ }
90
+ if len (b ) != 48 {
91
+ return fmt .Errorf ("not a 48 bytes hex string: %d" , len (b ))
92
+ }
93
+ var dec big.Int
94
+ dec .SetBytes (b )
95
+ * e = Byte48 {(hexutil .Big )(dec )}
96
+ return nil
45
97
}
46
98
47
99
// BatchTaskDetail is a type containing BatchTask detail.
48
100
type BatchTaskDetail struct {
49
- ChunkInfos []* ChunkInfo `json:"chunk_infos"`
50
- ChunkProofs []ChunkProof `json:"chunk_proofs"`
51
- BatchHeader interface {} `json:"batch_header"`
52
- BlobBytes []byte `json:"blob_bytes"`
53
- KzgProof []byte `json:"kzg_proof"`
54
- KzgCommitment []byte `json:"kzg_commitment"`
55
- Challenge common.Hash `json:"challenge"`
101
+ // use one of the string of EuclidFork / EuclidV2Fork
102
+ ForkName string `json:"fork_name"`
103
+ ChunkInfos []* ChunkInfo `json:"chunk_infos"`
104
+ ChunkProofs []ChunkProof `json:"chunk_proofs"`
105
+ BatchHeader interface {} `json:"batch_header"`
106
+ BlobBytes []byte `json:"blob_bytes"`
107
+ KzgProof Byte48 `json:"kzg_proof,omitempty"`
108
+ KzgCommitment Byte48 `json:"kzg_commitment,omitempty"`
109
+ ChallengeDigest common.Hash `json:"challenge_digest,omitempty"`
56
110
}
57
111
58
112
// BundleTaskDetail consists of all the information required to describe the task to generate a proof for a bundle of batches.
59
113
type BundleTaskDetail struct {
60
- BatchProofs []BatchProof `json:"batch_proofs"`
114
+ // use one of the string of EuclidFork / EuclidV2Fork
115
+ ForkName string `json:"fork_name"`
116
+ BatchProofs []BatchProof `json:"batch_proofs"`
117
+ BundleInfo * OpenVMBundleInfo `json:"bundle_info,omitempty"`
61
118
}
62
119
63
120
// ChunkInfo is for calculating pi_hash for chunk
64
121
type ChunkInfo struct {
65
- ChainID uint64 `json:"chain_id"`
66
- PrevStateRoot common.Hash `json:"prev_state_root"`
67
- PostStateRoot common.Hash `json:"post_state_root"`
68
- WithdrawRoot common.Hash `json:"withdraw_root"`
69
- DataHash common.Hash `json:"data_hash"`
70
- IsPadding bool `json:"is_padding"`
71
- TxBytes []byte `json:"tx_bytes"`
72
- TxBytesHash common.Hash `json:"tx_data_digest"`
73
- PrevMsgQueueHash common.Hash `json:"prev_msg_queue_hash"`
122
+ ChainID uint64 `json:"chain_id"`
123
+ PrevStateRoot common.Hash `json:"prev_state_root"`
124
+ PostStateRoot common.Hash `json:"post_state_root"`
125
+ WithdrawRoot common.Hash `json:"withdraw_root"`
126
+ DataHash common.Hash `json:"data_hash"`
127
+ IsPadding bool `json:"is_padding"`
128
+ TxBytes []byte `json:"tx_bytes"`
129
+ TxBytesHash common.Hash `json:"tx_data_digest"`
130
+ PrevMsgQueueHash common.Hash `json:"prev_msg_queue_hash"`
131
+ PostMsgQueueHash common.Hash `json:"post_msg_queue_hash"`
132
+ TxDataLength uint64 `json:"tx_data_length"`
133
+ InitialBlockNumber uint64 `json:"initial_block_number"`
134
+ BlockCtxs []BlockContextV2 `json:"block_ctxs"`
135
+ }
136
+
137
+ // BlockContextV2 is the block context for euclid v2
138
+ type BlockContextV2 struct {
139
+ Timestamp uint64 `json:"timestamp"`
140
+ BaseFee hexutil.Big `json:"base_fee"`
141
+ GasLimit uint64 `json:"gas_limit"`
142
+ NumTxs uint16 `json:"num_txs"`
143
+ NumL1Msgs uint16 `json:"num_l1_msgs"`
74
144
}
75
145
76
146
// SubCircuitRowUsage tracing info added in v0.11.0rc8
@@ -87,7 +157,7 @@ type ChunkProof interface {
87
157
// NewChunkProof creates a new ChunkProof instance.
88
158
func NewChunkProof (hardForkName string ) ChunkProof {
89
159
switch hardForkName {
90
- case euclidFork :
160
+ case EuclidFork , EuclidV2Fork :
91
161
return & OpenVMChunkProof {}
92
162
default :
93
163
return & Halo2ChunkProof {}
@@ -121,7 +191,7 @@ type BatchProof interface {
121
191
// NewBatchProof creates a new BatchProof instance.
122
192
func NewBatchProof (hardForkName string ) BatchProof {
123
193
switch hardForkName {
124
- case euclidFork :
194
+ case EuclidFork , EuclidV2Fork :
125
195
return & OpenVMBatchProof {}
126
196
default :
127
197
return & Halo2BatchProof {}
@@ -178,7 +248,7 @@ type BundleProof interface {
178
248
// NewBundleProof creates a new BundleProof instance.
179
249
func NewBundleProof (hardForkName string ) BundleProof {
180
250
switch hardForkName {
181
- case euclidFork :
251
+ case EuclidFork , EuclidV2Fork :
182
252
return & OpenVMBundleProof {}
183
253
default :
184
254
return & Halo2BundleProof {}
@@ -258,12 +328,14 @@ func (p *OpenVMChunkProof) Proof() []byte {
258
328
259
329
// OpenVMBatchInfo is for calculating pi_hash for batch header
260
330
type OpenVMBatchInfo struct {
261
- ParentBatchHash common.Hash `json:"parent_batch_hash"`
262
- ParentStateRoot common.Hash `json:"parent_state_root"`
263
- StateRoot common.Hash `json:"state_root"`
264
- WithdrawRoot common.Hash `json:"withdraw_root"`
265
- BatchHash common.Hash `json:"batch_hash"`
266
- ChainID uint64 `json:"chain_id"`
331
+ ParentBatchHash common.Hash `json:"parent_batch_hash"`
332
+ ParentStateRoot common.Hash `json:"parent_state_root"`
333
+ StateRoot common.Hash `json:"state_root"`
334
+ WithdrawRoot common.Hash `json:"withdraw_root"`
335
+ BatchHash common.Hash `json:"batch_hash"`
336
+ ChainID uint64 `json:"chain_id"`
337
+ PrevMsgQueueHash common.Hash `json:"prev_msg_queue_hash"`
338
+ PostMsgQueueHash common.Hash `json:"post_msg_queue_hash"`
267
339
}
268
340
269
341
// BatchProof includes the proof info that are required for batch verification and rollup.
@@ -323,6 +395,7 @@ type OpenVMBundleInfo struct {
323
395
NumBatches uint32 `json:"num_batches"`
324
396
PrevBatchHash common.Hash `json:"prev_batch_hash"`
325
397
BatchHash common.Hash `json:"batch_hash"`
398
+ MsgQueueHash common.Hash `json:"msg_queue_hash"`
326
399
}
327
400
328
401
// OpenVMBundleProof includes the proof info that are required for verification of a bundle of batch proofs.
0 commit comments