Skip to content

Commit b3b0fea

Browse files
committed
feat(coordinator): add euclid proof types
1 parent f03d56e commit b3b0fea

File tree

4 files changed

+188
-0
lines changed

4 files changed

+188
-0
lines changed

common/types/message/batch-proof-sample.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"metadata":null,"proof":{"instances":[["31ff3e68c303b187643d62000000000000000000000000000000000000000000","511046535fbfe6acbaf95e000000000000000000000000000000000000000000","bdaf9874f99e5b6e9f2300000000000000000000000000000000000000000000","9fbd6d21e025994cef993a000000000000000000000000000000000000000000","6f951f0bd5843685da5145000000000000000000000000000000000000000000","05c058fddf264153a90e00000000000000000000000000000000000000000000","1390fef2e0288741926de4000000000000000000000000000000000000000000","f99a9f47b49fb6140d1e8e000000000000000000000000000000000000000000","b8d59cd7db9c22e0a00d00000000000000000000000000000000000000000000","c9edbf55224d3f8d6997dc000000000000000000000000000000000000000000","ce6fcc33ba079746f64fa2000000000000000000000000000000000000000000","81a8ceda3bdcaf48ed0600000000000000000000000000000000000000000000","850b8ad3be6fdc1b89b408c70a7fd0c5826237c495375f31e00be4067ee81600","0b99d439ed30ad5d4f8f46b70b14d0599016405dd4cb3492a3795fa086e63d00","7d00000000000000000000000000000000000000000000000000000000000000","1a00000000000000000000000000000000000000000000000000000000000000","b500000000000000000000000000000000000000000000000000000000000000","1a00000000000000000000000000000000000000000000000000000000000000","ac00000000000000000000000000000000000000000000000000000000000000","fa00000000000000000000000000000000000000000000000000000000000000","bc00000000000000000000000000000000000000000000000000000000000000","da00000000000000000000000000000000000000000000000000000000000000","1d00000000000000000000000000000000000000000000000000000000000000","1100000000000000000000000000000000000000000000000000000000000000","0e00000000000000000000000000000000000000000000000000000000000000","0e00000000000000000000000000000000000000000000000000000000000000","3400000000000000000000000000000000000000000000000000000000000000","d000000000000000000000000000000000000000000000000000000000000000","4b00000000000000000000000000000000000000000000000000000000000000","4400000000000000000000000000000000000000000000000000000000000000","4600000000000000000000000000000000000000000000000000000000000000","f100000000000000000000000000000000000000000000000000000000000000","ec00000000000000000000000000000000000000000000000000000000000000","7b00000000000000000000000000000000000000000000000000000000000000","9e00000000000000000000000000000000000000000000000000000000000000","8300000000000000000000000000000000000000000000000000000000000000","d000000000000000000000000000000000000000000000000000000000000000","8000000000000000000000000000000000000000000000000000000000000000","d000000000000000000000000000000000000000000000000000000000000000","ef00000000000000000000000000000000000000000000000000000000000000","5e00000000000000000000000000000000000000000000000000000000000000","4800000000000000000000000000000000000000000000000000000000000000","0e00000000000000000000000000000000000000000000000000000000000000","2500000000000000000000000000000000000000000000000000000000000000","6600000000000000000000000000000000000000000000000000000000000000","f400000000000000000000000000000000000000000000000000000000000000"]],"proof":[43,162,92,146,126,74,14,56,40,52,177,85,254,141,143,124,185,195,222,180,201,38,165,234,217,104,76,76,221,165,112,190,2,246,172,84,194,17,17,136,185,54,180,156,203,89,112,189,229,116,108,248,212,143,122,110,104,193,140,70,224,42,255,88,16,44,109,144,22,110,57,64,148,168,120,137,16,48,92,127,22,152,112,172,62,137,184,91,127,210,166,220,228,201,197,248,33,254,183,11,63,56,118,22,116,81,161,197,37,103,222,47,66,228,202,94,246,120,65,79,153,42,189,142,91,83,44,226,45,70,225,208,140,37,183,142,103,236,126,103,20,5,17,22,198,15,132,88,239,161,189,105,55,234,126,199,188,235,191,201,5,177,104,8,13,135,214,158,215,140,68,107,115,39,20,148,162,235,209,21,158,131,112,169,253,194,78,72,149,89,25,70,19,48,252,228,121,53,118,43,111,65,177,125,15,145,152,55,86,128,155,159,111,21,19,64,158,31,117,240,58,26,249,255,8,145,233,176,3,79,254,56,51,15,104,18,53,139,41,61,171,203,174,94,167,81,88,174,192,55,53,171,241,136,129,189,31,29,207,109,193,125,49,188,162,165,142,247,173,100,232,198,93,76,98,119,233,109,237,241,162,90,37,28,205,110,111,70,45,121,231,76,16,202,148,91,222,62,183,179,4,32,66,13,25,44,129,159,131,2,156,52,73,151,123,255,240,135,3,241,38,141,129,123,113,56,66,66,51,75,221,214,249,123,239,244,254,132,19,136,161,178,120,48,232,10,141,141,21,119,109,16,43,224,165,195,161,232,181,168,232,196,146,13,245,58,147,139,27,28,49,18,16,189,114,184,207,100,59,30,69,184,254,185,39,9,176,49,49,211,50,173,128,87,187,129,138,122,206,1,209,179,220,223,170,215,92,211,86,46,245,105,105,153,137,236,18,82,239,156,220,79,149,18,100,78,103,77,128,101,142,88,143,106,204,140,74,227,155,214,230,0,33,54,23,236,125,197,16,147,203,205,17,200,9,148,29,207,243,115,165,201,222,5,189,187,176,193,134,168,154,235,17,81,41,221,196,234,114,56,34,141,172,190,98,168,253,255,0,201,88,180,254,48,29,0,36,142,242,181,86,42,105,227,198,27,83,77,133,101,98,241,26,119,252,91,249,48,39,245,202,241,183,120,10,190,109,239,182,179,37,194,28,249,3,46,224,146,15,171,246,31,165,227,18,127,90,51,11,169,108,255,239,59,56,223,219,146,130,195,128,59,228,32,47,38,82,138,146,123,127,27,49,95,56,37,39,110,248,136,126,130,148,189,129,153,248,125,73,54,138,231,114,217,118,102,50,21,169,169,243,71,138,137,13,59,168,0,21,139,228,111,222,203,69,108,181,36,132,151,1,36,219,115,142,140,239,34,156,248,7,248,82,121,190,34,15,200,186,226,23,13,73,78,80,117,135,74,84,25,242,242,119,240,15,240,247,59,103,164,59,17,179,236,112,10,32,12,73,67,176,16,37,5,223,55,201,35,104,202,28,151,166,49,176,78,235,227,160,148,48,115,22,248,76,21,148,25,174,182,47,29,245,31,16,56,114,246,161,201,209,217,242,23,82,212,185,21,196,162,64,192,166,250,198,211,87,105,219,100,78,41,218,74,202,128,24,192,88,11,211,68,142,3,34,63,248,113,180,146,211,58,164,96,139,125,13,227,110,3,96,175,132,15,237,28,15,6,31,193,116,36,191,42,209,129,73,18,177,243,27,248,33,141,163,136,59,66,244,254,81,51,95,191,212,91,227,222,111,18,42,14,20,14,47,0,159,126,212,88,27,216,39,78,21,56,162,227,5,143,171,132,29,178,43,84,188,138,243,181,24,125,11,139,140,241,88,145,79,76,142,158,16,187,194,152,191,174,88,219,13,70,58,225,123,119,239,141,139,70,100,103,65,113,3,79,150,9,72,255,133,97,116,33,253,134,161,86,213,197,180,26,236,191,20,201,105,44,9,23,51,112,144,197,151,50,36,183,35,17,208,114,103,111,89,141,61,74,115,184,169,231,18,17,71,229,253,253,72,126,253,63,87,160,195,221,90,179,21,149,232,4,151,96,192,141,124,0,231,3,199,204,70,52,130,95,56,112,34,250,212,125,138,162,19,136,135,93,249,160,6,97,124,214,233,250,49,255,247,169,229,195,230,29,197,213,209,89,59,14,177,14,249,168,16,63,46,99,222,144,110,255,32,235,37,168,180,167,28,122,12,211,62,198,237,69,52,201,222,20,108,120,115,102,198,93,79,186,244,240,82,33,76,89,23,103,51,27,139,123,167,47,157,60,196,25,9,63,95,29,248,232,103,99,239,234,44,156,121,252,198,205,55,36,22,197,43,165,253,154,225,131,81,10,30,251,35,200,106,75,14,192,149,101,29,94,4,79,174,41,139,168,37,96,37,243,54,92,11,111,32,154,218,3,216,81,119,89,25,106,78,64,237,240,215,19,40,210,85,134,107,162,164,87,89,105,114,1,109,158,39,36,40,51,196,150,166,157,181,103,134,47,224,45,34,103,65,249,131,235,18,156,84,10,246,122,118,77,54,57,238,139,46,4,219,207,245,145,144,174,255,34,125,16,32,88,229,137,63,50,24,126,174,11,113,168,142,6,122,231,241,160,227,0,36,84,49,231,10,196,3,90,37,12,141,146,255,130,149,37,148,155,89,255,250,92,62,3,231,91,252,205,228,50,102,140,37,75,40,40,8,182,169,106,222,172,169,214,53,50,132,203,68,158,198,43,224,253,99,10,41,90,102,151,127,39,148,53,15,5,244,233,240,53,89,195,99,59,220,237,218,32,7,239,187,197,183,184,130,113,108,47,123,223,124,76,151,86,201,218,29,189,11,59,69,203,197,69,0,40,95,118,186,119,144,105,48,235,127,149,46,189,48,12,244,140,137,215,37,178,154,19,42,82,0,183,1,48,152,251,23,39,132,214,30,109,75,193,165,28,213,243,189,7,76,76,108,191,57,185,149,96,32,94,30,77,111,21,81,193,171,60,76,23,158,166,50,111,194,232,226,73,37,233,132,218,67,32,169,223,17,166,76,119,88,85]},"git_version":"1407454"}

common/types/message/message.go

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import (
77
"github.com/scroll-tech/go-ethereum/common"
88
)
99

10+
const (
11+
euclidFork = "euclid"
12+
)
13+
1014
// ProofType represents the type of task.
1115
type ProofType uint8
1216

@@ -61,6 +65,7 @@ type ChunkInfo struct {
6165
DataHash common.Hash `json:"data_hash"`
6266
IsPadding bool `json:"is_padding"`
6367
TxBytes []byte `json:"tx_bytes"`
68+
TxBytesHash common.Hash `json:"tx_data_digest"`
6469
}
6570

6671
// SubCircuitRowUsage tracing info added in v0.11.0rc8
@@ -77,6 +82,8 @@ type ChunkProof interface {
7782
// NewChunkProof creates a new ChunkProof instance.
7883
func NewChunkProof(hardForkName string) ChunkProof {
7984
switch hardForkName {
85+
case euclidFork:
86+
return &OpenVMChunkProof{}
8087
default:
8188
return &Halo2ChunkProof{}
8289
}
@@ -109,6 +116,8 @@ type BatchProof interface {
109116
// NewBatchProof creates a new BatchProof instance.
110117
func NewBatchProof(hardForkName string) BatchProof {
111118
switch hardForkName {
119+
case euclidFork:
120+
return &OpenVMBatchProof{}
112121
default:
113122
return &Halo2BatchProof{}
114123
}
@@ -164,6 +173,8 @@ type BundleProof interface {
164173
// NewBundleProof creates a new BundleProof instance.
165174
func NewBundleProof(hardForkName string) BundleProof {
166175
switch hardForkName {
176+
case euclidFork:
177+
return &OpenVMBundleProof{}
167178
default:
168179
return &Halo2BundleProof{}
169180
}
@@ -207,3 +218,139 @@ func (ap *Halo2BundleProof) SanityCheck() error {
207218

208219
return nil
209220
}
221+
222+
// Proof for flatten VM proof
223+
type OpenVMProof struct {
224+
Proof interface{} `json:"proofs"`
225+
PublicValues []uint32 `json:"public_values"`
226+
Vk []byte `json:"vk,omitempty"`
227+
}
228+
229+
// Proof for flatten EVM proof
230+
type OpenVMEvmProof struct {
231+
Proof []byte `json:"proof"`
232+
Instances [][]string `json:"instances"`
233+
Vk []byte `json:"vk,omitempty"`
234+
}
235+
236+
// OpenVMChunkProof includes the proof info that are required for chunk verification and rollup.
237+
type OpenVMChunkProof struct {
238+
MetaData struct {
239+
ChunkInfo *ChunkInfo `json:"chunk_info"`
240+
} `json:"metadata"`
241+
242+
VmProof *OpenVMProof `json:"proof"`
243+
GitVersion string `json:"git_version,omitempty"`
244+
}
245+
246+
func (p *OpenVMChunkProof) Proof() []byte {
247+
return nil // todo: ???
248+
}
249+
250+
// OpenVMBatchInfo is for calculating pi_hash for batch header
251+
type OpenVMBatchInfo struct {
252+
ParentBatchHash common.Hash `json:"parent_batch_hash"`
253+
ParentStateRoot common.Hash `json:"parent_state_root"`
254+
StateRoot common.Hash `json:"state_root"`
255+
WithdrawRoot common.Hash `json:"withdraw_root"`
256+
BatchHash common.Hash `json:"batch_hash"`
257+
ChainID uint64 `json:"chain_id"`
258+
}
259+
260+
// BatchProof includes the proof info that are required for batch verification and rollup.
261+
type OpenVMBatchProof struct {
262+
MetaData struct {
263+
BatchInfo *OpenVMBatchInfo `json:"batch_info"`
264+
BatchHash common.Hash `json:"batch_hash"`
265+
} `json:"metadata"`
266+
267+
VmProof *OpenVMProof `json:"proof"`
268+
GitVersion string `json:"git_version,omitempty"`
269+
}
270+
271+
func (p *OpenVMBatchProof) Proof() []byte {
272+
return nil // todo: ???
273+
}
274+
275+
// SanityCheck checks whether a BatchProof is in a legal format
276+
func (ap *OpenVMBatchProof) SanityCheck() error {
277+
if ap == nil {
278+
return errors.New("agg_proof is nil")
279+
}
280+
if ap.MetaData.BatchInfo == nil {
281+
return errors.New("batch info not ready")
282+
}
283+
284+
if ap.VmProof == nil {
285+
return errors.New("proof not ready")
286+
} else {
287+
pf := ap.VmProof
288+
if pf.Proof == nil {
289+
return errors.New("proof data not ready")
290+
}
291+
292+
// TODO: resume this after rc2
293+
// if len(pf.Vk) == 0 {
294+
// return errors.New("vk not ready")
295+
// }
296+
}
297+
298+
return nil
299+
}
300+
301+
// OpenVMBundleInfo is for calculating pi_hash for bundle header
302+
type OpenVMBundleInfo struct {
303+
ChainID uint64 `json:"chain_id"`
304+
PrevStateRoot common.Hash `json:"prev_state_root"`
305+
PostStateRoot common.Hash `json:"post_state_root"`
306+
WithdrawRoot common.Hash `json:"withdraw_root"`
307+
NumBatches uint32 `json:"num_batches"`
308+
PrevBatchHash common.Hash `json:"prev_batch_hash"`
309+
BatchHash common.Hash `json:"batch_hash"`
310+
}
311+
312+
// OpenVMBundleProof includes the proof info that are required for verification of a bundle of batch proofs.
313+
type OpenVMBundleProof struct {
314+
MetaData struct {
315+
BundleInfo *OpenVMBundleInfo `json:"bundle_info"`
316+
BunndlePIHash common.Hash `json:"bundle_pi_hash"`
317+
} `json:"metadata"`
318+
319+
EvmProof *OpenVMEvmProof `json:"proof"`
320+
GitVersion string `json:"git_version,omitempty"`
321+
}
322+
323+
func (p *OpenVMBundleProof) Proof() []byte {
324+
return p.EvmProof.Proof
325+
}
326+
327+
// SanityCheck checks whether a BundleProof is in a legal format
328+
func (ap *OpenVMBundleProof) SanityCheck() error {
329+
if ap == nil {
330+
return errors.New("agg_proof is nil")
331+
}
332+
// TODO: resume this after metadata of bundle info is ready
333+
// if ap.MetaData.BundleInfo == nil {
334+
// return errors.New("bundle info not ready")
335+
// }
336+
337+
if ap.EvmProof == nil {
338+
return errors.New("proof not ready")
339+
} else {
340+
pf := ap.EvmProof
341+
if len(pf.Proof)%32 != 0 {
342+
return fmt.Errorf("proof buffer length must be a multiple of 32, got: %d", len(pf.Proof))
343+
}
344+
345+
if len(pf.Instances) == 0 {
346+
return errors.New("instance not ready")
347+
}
348+
349+
// TODO: resume this after rc2
350+
// if len(pf.Vk) == 0 {
351+
// return errors.New("vk not ready")
352+
// }
353+
}
354+
355+
return nil
356+
}

common/types/message/message_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package message
2+
3+
import (
4+
"encoding/json"
5+
"os"
6+
"testing"
7+
)
8+
9+
func TestDeserializeOpenVMProof(t *testing.T) {
10+
// Read the batch.json file located in the same directory.
11+
data, err := os.ReadFile("batch-proof-sample.json")
12+
if err != nil {
13+
t.Fatalf("failed to read batch proof sample.json: %v", err)
14+
}
15+
16+
// Decode the JSON data into an BatchTask instance.
17+
batchProof := NewBatchProof("euclid")
18+
if err = json.Unmarshal(data, &batchProof); err != nil {
19+
t.Fatalf("failed to unmarshal JSON into Batch Proof: %v", err)
20+
}
21+
if err = batchProof.SanityCheck(); err != nil {
22+
t.Fatalf("failed to sanity check for Batch Proof: %v", err)
23+
}
24+
25+
// Read the batch.json file located in the same directory.
26+
data, err = os.ReadFile("bundle-proof-sample.json")
27+
if err != nil {
28+
t.Fatalf("failed to read bundle proof sample.json: %v", err)
29+
}
30+
31+
// Decode the JSON data into an BatchTask instance.
32+
bundleProof := NewBundleProof("euclid")
33+
if err = json.Unmarshal(data, &bundleProof); err != nil {
34+
t.Fatalf("failed to unmarshal JSON into Bundle Proof: %v", err)
35+
}
36+
if err = bundleProof.SanityCheck(); err != nil {
37+
t.Fatalf("failed to sanity check for Bundle Proof: %v", err)
38+
}
39+
}

0 commit comments

Comments
 (0)