@@ -4,12 +4,18 @@ import (
44 "encoding/json"
55 "errors"
66 "fmt"
7+ "math/big"
78
89 "github.com/scroll-tech/go-ethereum/common"
10+ "github.com/scroll-tech/go-ethereum/common/hexutil"
911)
1012
1113const (
12- euclidFork = "euclid"
14+ EuclidFork = "euclid"
15+ EuclidV2Fork = "euclidV2"
16+
17+ EuclidForkNameForProver = "euclidv1"
18+ EuclidV2ForkNameForProver = "euclidv2"
1319)
1420
1521// ProofType represents the type of task.
@@ -39,38 +45,102 @@ const (
3945 ProofTypeBundle
4046)
4147
42- // ChunkTaskDetail is a type containing ChunkTask detail.
48+ // ChunkTaskDetail is a type containing ChunkTask detail for chunk task .
4349type 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
4597}
4698
4799// BatchTaskDetail is a type containing BatchTask detail.
48100type 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"`
56110}
57111
58112// BundleTaskDetail consists of all the information required to describe the task to generate a proof for a bundle of batches.
59113type 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"`
61118}
62119
63120// ChunkInfo is for calculating pi_hash for chunk
64121type 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"`
74144}
75145
76146// SubCircuitRowUsage tracing info added in v0.11.0rc8
@@ -87,7 +157,7 @@ type ChunkProof interface {
87157// NewChunkProof creates a new ChunkProof instance.
88158func NewChunkProof (hardForkName string ) ChunkProof {
89159 switch hardForkName {
90- case euclidFork :
160+ case EuclidFork , EuclidV2Fork :
91161 return & OpenVMChunkProof {}
92162 default :
93163 return & Halo2ChunkProof {}
@@ -121,7 +191,7 @@ type BatchProof interface {
121191// NewBatchProof creates a new BatchProof instance.
122192func NewBatchProof (hardForkName string ) BatchProof {
123193 switch hardForkName {
124- case euclidFork :
194+ case EuclidFork , EuclidV2Fork :
125195 return & OpenVMBatchProof {}
126196 default :
127197 return & Halo2BatchProof {}
@@ -178,7 +248,7 @@ type BundleProof interface {
178248// NewBundleProof creates a new BundleProof instance.
179249func NewBundleProof (hardForkName string ) BundleProof {
180250 switch hardForkName {
181- case euclidFork :
251+ case EuclidFork , EuclidV2Fork :
182252 return & OpenVMBundleProof {}
183253 default :
184254 return & Halo2BundleProof {}
@@ -258,12 +328,14 @@ func (p *OpenVMChunkProof) Proof() []byte {
258328
259329// OpenVMBatchInfo is for calculating pi_hash for batch header
260330type 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"`
267339}
268340
269341// BatchProof includes the proof info that are required for batch verification and rollup.
@@ -323,6 +395,7 @@ type OpenVMBundleInfo struct {
323395 NumBatches uint32 `json:"num_batches"`
324396 PrevBatchHash common.Hash `json:"prev_batch_hash"`
325397 BatchHash common.Hash `json:"batch_hash"`
398+ MsgQueueHash common.Hash `json:"msg_queue_hash"`
326399}
327400
328401// OpenVMBundleProof includes the proof info that are required for verification of a bundle of batch proofs.
0 commit comments