Skip to content

Commit 00d932e

Browse files
author
colinlyguo
committed
migrate interfaces fixes
1 parent 2d64f55 commit 00d932e

File tree

3 files changed

+108
-36
lines changed

3 files changed

+108
-36
lines changed

common/types/message/message.go

Lines changed: 89 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1113
const (
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.
4345
type 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.
4894
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"`
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
64110
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"`
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.
88147
func 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.
122181
func 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.
179238
func 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
260319
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"`
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.

coordinator/internal/logic/provertask/batch_prover_task.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"math/big"
78
"time"
89

10+
"github.com/ethereum/go-ethereum/common/hexutil"
911
"github.com/gin-gonic/gin"
1012
"github.com/prometheus/client_golang/prometheus"
1113
"github.com/prometheus/client_golang/prometheus/promauto"
@@ -211,13 +213,19 @@ func (bp *BatchProverTask) formatProverTask(ctx context.Context, task *orm.Prove
211213
WithdrawRoot: common.HexToHash(chunk.WithdrawRoot),
212214
DataHash: common.HexToHash(chunk.Hash),
213215
PrevMsgQueueHash: common.HexToHash(chunk.PrevL1MessageQueueHash),
216+
PostMsgQueueHash: common.HexToHash(chunk.PostL1MessageQueueHash),
214217
IsPadding: false,
215218
}
216-
if haloProot, ok := proof.(*message.Halo2ChunkProof); ok {
217-
if haloProot.ChunkInfo != nil {
218-
chunkInfo.TxBytes = haloProot.ChunkInfo.TxBytes
219+
if halo2Proof, ok := proof.(*message.Halo2ChunkProof); ok {
220+
if halo2Proof.ChunkInfo != nil {
221+
chunkInfo.TxBytes = halo2Proof.ChunkInfo.TxBytes
219222
}
220223
}
224+
if openvmProof, ok := proof.(*message.OpenVMChunkProof); ok {
225+
chunkInfo.InitialBlockNumber = openvmProof.MetaData.ChunkInfo.InitialBlockNumber
226+
chunkInfo.BlockCtxs = openvmProof.MetaData.ChunkInfo.BlockCtxs
227+
chunkInfo.TxDataLength = openvmProof.MetaData.ChunkInfo.TxDataLength
228+
}
221229
chunkInfos = append(chunkInfos, &chunkInfo)
222230
}
223231

@@ -280,8 +288,8 @@ func (bp *BatchProverTask) getBatchTaskDetail(dbBatch *orm.Batch, chunkInfos []*
280288
// | z | y | kzg_commitment | kzg_proof |
281289
// |---------|---------|----------------|-----------|
282290
// | bytes32 | bytes32 | bytes48 | bytes48 |
283-
taskDetail.KzgProof = dbBatch.BlobDataProof[112:160]
284-
taskDetail.KzgCommitment = dbBatch.BlobDataProof[64:112]
285-
taskDetail.Challenge = common.Hash(dbBatch.BlobDataProof[0:32])
291+
taskDetail.KzgProof = message.Byte48{Big: hexutil.Big(*new(big.Int).SetBytes(dbBatch.BlobDataProof[112:160]))}
292+
taskDetail.KzgCommitment = message.Byte48{Big: hexutil.Big(*new(big.Int).SetBytes(dbBatch.BlobDataProof[64:112]))}
293+
taskDetail.ChallengeDigest = common.BytesToHash(dbBatch.BlobDataProof[0:32]) // FIXME: Challenge = ChallengeDigest % BLS_MODULUS, get the original ChallengeDigest.
286294
return taskDetail, nil
287295
}

coordinator/internal/logic/provertask/chunk_prover_task.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/gin-gonic/gin"
1010
"github.com/prometheus/client_golang/prometheus"
1111
"github.com/prometheus/client_golang/prometheus/promauto"
12+
"github.com/scroll-tech/go-ethereum/common"
1213
"github.com/scroll-tech/go-ethereum/log"
1314
"github.com/scroll-tech/go-ethereum/params"
1415
"gorm.io/gorm"
@@ -162,7 +163,7 @@ func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato
162163
return nil, ErrCoordinatorInternalFailure
163164
}
164165

165-
taskMsg, err := cp.formatProverTask(ctx.Copy(), &proverTask, hardForkName)
166+
taskMsg, err := cp.formatProverTask(ctx.Copy(), &proverTask, chunkTask, hardForkName)
166167
if err != nil {
167168
cp.recoverActiveAttempts(ctx, chunkTask)
168169
log.Error("format prover task failure", "task_id", chunkTask.Hash, "err", err)
@@ -179,15 +180,16 @@ func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato
179180
return taskMsg, nil
180181
}
181182

182-
func (cp *ChunkProverTask) formatProverTask(ctx context.Context, task *orm.ProverTask, hardForkName string) (*coordinatorType.GetTaskSchema, error) {
183+
func (cp *ChunkProverTask) formatProverTask(ctx context.Context, task *orm.ProverTask, chunk *orm.Chunk, hardForkName string) (*coordinatorType.GetTaskSchema, error) {
183184
// Get block hashes.
184185
blockHashes, dbErr := cp.blockOrm.GetL2BlockHashesByChunkHash(ctx, task.TaskID)
185186
if dbErr != nil || len(blockHashes) == 0 {
186187
return nil, fmt.Errorf("failed to fetch block hashes of a chunk, chunk hash:%s err:%w", task.TaskID, dbErr)
187188
}
188189

189190
taskDetail := message.ChunkTaskDetail{
190-
BlockHashes: blockHashes,
191+
BlockHashes: blockHashes,
192+
PrevMsgQueueHash: common.HexToHash(chunk.PrevL1MessageQueueHash),
191193
}
192194
blockHashesBytes, err := json.Marshal(taskDetail)
193195
if err != nil {

0 commit comments

Comments
 (0)