@@ -4,12 +4,14 @@ import (
44 "encoding/json"
55 "errors"
66 "fmt"
7+ "math/big"
78
9+ "github.com/ethereum/go-ethereum/common/hexutil"
810 "github.com/scroll-tech/go-ethereum/common"
911)
1012
1113const (
12- euclidFork = "euclid"
14+ EuclidFork = "euclid"
1315)
1416
1517// ProofType represents the type of task.
@@ -41,18 +43,62 @@ const (
4143
4244// ChunkTaskDetail is a type containing ChunkTask detail.
4345type ChunkTaskDetail struct {
44- BlockHashes []common.Hash `json:"block_hashes"`
46+ BlockHashes []common.Hash `json:"block_hashes"`
47+ PrevMsgQueueHash common.Hash `json:"prev_msg_queue_hash"`
48+ }
49+
50+ // it is a hex encoded big with fixed length on 48 bytes
51+ type Byte48 struct {
52+ hexutil.Big
53+ }
54+
55+ func (e Byte48 ) MarshalText () ([]byte , error ) {
56+ i := e .ToInt ()
57+ // overrite encode big
58+ if sign := i .Sign (); sign < 0 {
59+ // sanity check
60+ return nil , fmt .Errorf ("Byte48 must be positive integer" )
61+ } else {
62+ s := i .Text (16 )
63+ if len (s ) > 96 {
64+ return nil , fmt .Errorf ("integer Exceed 384bit" )
65+ }
66+ return []byte (fmt .Sprintf ("0x%0*s" , 96 , s )), nil
67+ }
68+ }
69+
70+ func isString (input []byte ) bool {
71+ return len (input ) >= 2 && input [0 ] == '"' && input [len (input )- 1 ] == '"'
72+ }
73+
74+ // hexutil.Big has limition of 256bit so we have to override it ...
75+ func (e * Byte48 ) UnmarshalJSON (input []byte ) error {
76+ if ! isString (input ) {
77+ return fmt .Errorf ("not hex string" )
78+ }
79+
80+ b , err := hexutil .Decode (string (input [1 : len (input )- 1 ]))
81+ if err != nil {
82+ return err
83+ }
84+ if len (b ) != 48 {
85+ return fmt .Errorf ("not a 48 bytes hex string: %d" , len (b ))
86+ }
87+ var dec big.Int
88+ dec .SetBytes (b )
89+ * e = Byte48 {(hexutil .Big )(dec )}
90+ return nil
4591}
4692
4793// BatchTaskDetail is a type containing BatchTask detail.
4894type 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 "`
95+ ChunkInfos []* ChunkInfo `json:"chunk_infos"`
96+ ChunkProofs []ChunkProof `json:"chunk_proofs"`
97+ BatchHeader interface {} `json:"batch_header"`
98+ BlobBytes []byte `json:"blob_bytes"`
99+ KzgProof Byte48 `json:"kzg_proof"`
100+ KzgCommitment Byte48 `json:"kzg_commitment"`
101+ ChallengeDigest common.Hash `json:"challenge_digest "`
56102}
57103
58104// BundleTaskDetail consists of all the information required to describe the task to generate a proof for a bundle of batches.
@@ -62,15 +108,28 @@ type BundleTaskDetail struct {
62108
63109// ChunkInfo is for calculating pi_hash for chunk
64110type 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"`
111+ ChainID uint64 `json:"chain_id"`
112+ PrevStateRoot common.Hash `json:"prev_state_root"`
113+ PostStateRoot common.Hash `json:"post_state_root"`
114+ WithdrawRoot common.Hash `json:"withdraw_root"`
115+ DataHash common.Hash `json:"data_hash"`
116+ IsPadding bool `json:"is_padding"`
117+ TxBytes []byte `json:"tx_bytes"`
118+ TxBytesHash common.Hash `json:"tx_data_digest"`
119+ PrevMsgQueueHash common.Hash `json:"prev_msg_queue_hash"`
120+ PostMsgQueueHash common.Hash `json:"post_msg_queue_hash"`
121+ TxDataLength uint64 `json:"tx_data_length"`
122+ InitialBlockNumber uint64 `json:"initial_block_number"`
123+ BlockCtxs []BlockContextV2 `json:"block_ctxs"`
124+ }
125+
126+ // BlockContextV2 is the block context for euclid v2
127+ type BlockContextV2 struct {
128+ Timestamp uint64 `json:"timestamp"`
129+ BaseFee hexutil.Big `json:"base_fee"`
130+ GasLimit uint64 `json:"gas_limit"`
131+ NumTxs uint16 `json:"num_txs"`
132+ NumL1Msgs uint16 `json:"num_l1_msgs"`
74133}
75134
76135// SubCircuitRowUsage tracing info added in v0.11.0rc8
@@ -87,7 +146,7 @@ type ChunkProof interface {
87146// NewChunkProof creates a new ChunkProof instance.
88147func NewChunkProof (hardForkName string ) ChunkProof {
89148 switch hardForkName {
90- case euclidFork :
149+ case EuclidFork :
91150 return & OpenVMChunkProof {}
92151 default :
93152 return & Halo2ChunkProof {}
@@ -121,7 +180,7 @@ type BatchProof interface {
121180// NewBatchProof creates a new BatchProof instance.
122181func NewBatchProof (hardForkName string ) BatchProof {
123182 switch hardForkName {
124- case euclidFork :
183+ case EuclidFork :
125184 return & OpenVMBatchProof {}
126185 default :
127186 return & Halo2BatchProof {}
@@ -178,7 +237,7 @@ type BundleProof interface {
178237// NewBundleProof creates a new BundleProof instance.
179238func NewBundleProof (hardForkName string ) BundleProof {
180239 switch hardForkName {
181- case euclidFork :
240+ case EuclidFork :
182241 return & OpenVMBundleProof {}
183242 default :
184243 return & Halo2BundleProof {}
@@ -258,12 +317,14 @@ func (p *OpenVMChunkProof) Proof() []byte {
258317
259318// OpenVMBatchInfo is for calculating pi_hash for batch header
260319type 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"`
320+ ParentBatchHash common.Hash `json:"parent_batch_hash"`
321+ ParentStateRoot common.Hash `json:"parent_state_root"`
322+ StateRoot common.Hash `json:"state_root"`
323+ WithdrawRoot common.Hash `json:"withdraw_root"`
324+ BatchHash common.Hash `json:"batch_hash"`
325+ ChainID uint64 `json:"chain_id"`
326+ PrevMsgQueueHash common.Hash `json:"prev_msg_queue_hash"`
327+ PostMsgQueueHash common.Hash `json:"post_msg_queue_hash"`
267328}
268329
269330// BatchProof includes the proof info that are required for batch verification and rollup.
@@ -323,6 +384,7 @@ type OpenVMBundleInfo struct {
323384 NumBatches uint32 `json:"num_batches"`
324385 PrevBatchHash common.Hash `json:"prev_batch_hash"`
325386 BatchHash common.Hash `json:"batch_hash"`
387+ MsgQueueHash common.Hash `json:"msg_queue_hash"`
326388}
327389
328390// OpenVMBundleProof includes the proof info that are required for verification of a bundle of batch proofs.
0 commit comments