Skip to content

Commit cdf0d2f

Browse files
omerfirmaknoel2004
andcommitted
feat(coordinator): add euclid proof types
Co-authored-by: noelwei <[email protected]>
1 parent 1c17ca5 commit cdf0d2f

File tree

4 files changed

+214
-0
lines changed

4 files changed

+214
-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":{"bundle_info":{"chain_id":534352,"num_batches":2,"prev_state_root":"0xabacadaeaf000000000000000000000000000000000000000000000000000000","prev_batch_hash":"0xabacadaeaf000000000000000000000000000000000000000000000000000000","post_state_root":"0x9e8b9928c55ccbc933911283175842fa515e49dd3f2fe0192c4346095695d741","batch_hash":"0x30d2f51e20e9a4ecd460466af9c81d13daad4fb8d1ca1e42dab30603374f7e5f","withdraw_root":"0x7ed4c7d56e2ed40f65d25eecbb0110f3b3f4db68e87700287c7e0cedcb68272c"},"bundle_pi_hash":"0x7d1ab51aacfabcda1d110e0e34d04b4446f1ec7b9e83d080d0ef5e480e2566f4"},"proof":{"instances":[["97e96308bd98ffa3f39dc0000000000000000000000000000000000000000000","01f2a29f309390ad118fcd000000000000000000000000000000000000000000","92bc68866f74b390b60800000000000000000000000000000000000000000000","57fb7f3a0dad5147efe147000000000000000000000000000000000000000000","857c69b8d846f355e063a5000000000000000000000000000000000000000000","c223d2a4af009c159a1d00000000000000000000000000000000000000000000","67c7eaa18b594adcc30aef000000000000000000000000000000000000000000","3dbd5480333e992459b18c000000000000000000000000000000000000000000","f8ba1b51078ee337910900000000000000000000000000000000000000000000","58ed5e390c5bf96796402a000000000000000000000000000000000000000000","9d7082eee45c81f6f0c5c7000000000000000000000000000000000000000000","249d4588fd1ae3ce8c1700000000000000000000000000000000000000000000","7aa3fdd20f009a07adf150d2f74895240b1d311e37f918ae97dfa3e093017600","e89f797fae1a2a08707189a1772082fd6f30500d5c60796e4432d7e7b9380400","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":[6,13,251,83,157,229,78,147,240,211,105,211,233,165,231,246,12,118,219,182,204,150,39,214,40,239,218,244,108,49,14,248,4,50,195,55,248,15,73,230,30,192,200,178,184,159,146,207,28,4,236,42,145,115,160,169,78,212,138,69,110,0,90,93,18,187,91,198,40,107,123,170,50,254,243,170,167,213,52,111,239,127,158,2,145,90,234,125,182,59,7,7,144,45,12,49,9,204,120,71,94,150,202,83,104,20,140,119,122,105,216,190,7,17,236,14,237,140,119,247,12,130,71,27,238,137,0,57,44,137,143,13,224,20,159,155,145,123,160,36,182,220,239,150,223,161,211,160,214,105,57,242,144,235,93,103,106,226,124,93,20,175,142,101,200,241,44,171,133,13,194,150,254,97,134,14,177,255,208,255,37,186,227,128,174,204,203,81,27,62,151,182,35,122,197,178,129,249,93,142,204,56,227,173,210,121,208,13,22,57,166,128,179,95,134,111,21,69,224,30,211,54,112,48,15,181,2,115,21,37,234,68,111,71,55,235,242,160,113,15,212,211,1,237,190,62,210,90,153,42,106,90,154,85,203,96,39,65,58,143,44,152,99,222,185,28,144,150,20,134,251,200,200,48,193,238,145,132,11,19,210,84,97,9,186,19,13,60,40,44,247,229,82,148,74,179,157,238,110,134,255,116,45,32,1,200,118,59,111,127,244,73,142,147,153,119,77,235,244,193,28,221,181,243,200,74,24,119,108,234,77,213,159,68,174,191,10,138,13,23,47,116,14,196,146,61,178,121,224,25,239,13,13,141,202,250,23,42,102,201,159,215,234,116,144,251,180,43,203,195,188,0,244,126,78,248,29,98,243,101,165,37,251,9,26,170,181,112,56,131,75,27,101,214,76,235,34,230,121,62,199,214,55,79,125,97,73,35,217,212,142,83,143,177,189,82,20,208,132,125,135,25,133,93,71,134,188,128,29,37,206,112,225,182,15,247,134,134,218,61,102,223,173,131,77,31,244,178,32,19,162,173,72,128,105,233,170,190,232,7,37,152,35,47,86,128,15,171,240,78,158,87,31,68,36,115,158,172,46,17,12,228,208,116,68,177,189,163,47,80,72,21,245,188,52,2,173,254,73,255,228,92,95,56,75,96,120,74,9,74,230,154,16,73,148,131,75,149,180,19,162,35,113,223,180,153,164,214,138,105,185,145,8,191,120,148,94,144,28,82,237,111,28,33,15,22,148,49,85,46,176,21,39,60,199,85,46,13,60,204,0,243,23,125,50,105,102,199,137,164,1,148,178,156,223,84,21,230,90,140,218,69,245,58,204,95,126,177,73,73,122,142,56,235,68,89,226,191,212,254,7,242,44,252,133,245,44,197,16,178,244,169,55,240,20,166,220,19,65,220,157,188,158,100,166,177,248,95,145,38,54,23,222,56,73,190,63,82,69,38,5,136,125,98,121,38,122,179,55,156,212,94,168,123,118,221,110,134,33,177,209,66,59,210,189,148,161,251,142,240,77,43,12,73,219,185,204,129,218,83,8,144,96,191,92,173,199,234,51,237,199,26,151,230,226,229,235,204,51,251,90,150,36,52,44,57,45,17,47,182,60,69,216,20,157,123,240,37,106,107,25,156,196,204,71,212,178,124,167,14,136,178,94,129,36,135,10,52,214,252,254,2,238,44,210,158,173,107,45,255,150,60,95,84,193,129,228,198,103,253,228,7,20,68,32,255,52,95,4,202,39,206,45,231,10,142,78,205,223,169,127,200,224,110,88,14,112,72,21,200,223,101,248,164,136,94,184,178,99,219,23,141,26,230,121,151,80,142,36,101,71,173,235,89,216,242,144,130,93,151,247,157,81,94,166,219,250,50,23,124,37,237,3,28,1,80,59,253,15,62,164,11,234,45,42,148,76,250,10,60,5,64,134,75,97,53,30,22,101,231,5,190,159,62,7,25,188,223,162,102,175,100,251,83,219,106,118,251,144,130,53,81,14,146,142,191,55,204,245,189,242,213,45,34,81,3,16,105,122,205,69,38,147,176,110,249,61,62,238,153,145,56,36,249,229,1,59,68,143,106,241,173,233,59,81,207,187,142,34,152,42,165,178,189,143,237,63,84,135,15,213,34,41,253,242,132,226,80,233,160,176,159,48,65,92,252,155,222,233,105,7,46,252,171,177,180,55,249,124,23,185,246,248,136,61,144,41,26,227,194,175,146,236,95,125,123,148,44,180,117,47,242,4,199,226,247,28,221,16,194,21,101,118,95,37,161,158,221,54,118,46,102,180,183,34,40,144,131,181,51,175,124,63,106,28,55,28,120,16,241,105,31,192,222,117,121,193,152,53,142,33,157,146,108,189,22,239,182,229,227,72,254,163,144,30,231,36,184,239,92,82,72,209,10,33,212,9,231,84,105,164,129,90,179,160,196,251,5,224,82,62,94,46,89,111,130,183,125,6,74,23,131,215,233,84,97,205,72,244,68,197,246,97,159,172,122,74,114,178,134,12,175,129,110,86,125,142,206,254,183,29,29,110,165,207,1,203,23,38,178,142,30,64,129,2,186,19,54,48,116,11,249,29,145,227,18,229,111,189,61,117,39,40,84,193,255,37,121,26,210,148,220,223,222,162,182,185,84,41,139,109,106,65,204,205,72,238,173,59,120,247,143,14,150,35,194,59,14,96,84,120,204,121,117,126,61,161,41,143,200,46,196,43,197,199,137,142,185,172,152,198,119,170,168,228,119,39,119,21,199,27,233,154,40,37,91,147,152,220,47,75,173,41,198,248,25,15,220,40,114,207,169,39,143,194,225,44,219,44,126,211,225,79,136,49,226,110,6,235,41,138,201,20,46,106,105,71,92,28,239,224,59,158,116,96,127,63,42,37,148,39,189,200,211,199,225,197,38,16,147,191,110,238,45,201,177,142,169,82,63,117,176,165,158,46,156,6,225,131,166,11,167,24,76,103,7,106,17,169,211,232,137,140,126,15,175,252,5,2,204,103,171,94,230,78,40,205,49,101,148,148,182,75,32,39,109,180,112,205,175,134,114,48,6,52,28,59,10,195,16,75,84,177,162,186,223,26,90,158,79,87,199,120,244,115,164]},"vk":"AhYAAAAABAAAAD2PumVP6pqldS0PKWW8Q4IvnE/rvtm5/2fXvG196sYhI47ROxge2z4kg7ybLacHwn9EMlyXIRVV4j4RbMs2AiQNu8s47Xabxy0EViND1dzsu5HicdAWl0xG5C+VpO2faJdK4nGwtD4WHtbdqWY72nSY5aKSDxAYO85vLy+9cJZl4YV1JRvVS93TXSFqhKGUEGQz8whNVHZcWy3igkXP0lv1viqH+tQ3npbYoF7PNhRVSRp/YxwFufgw3O4cGkpuZMw8T9j5UXpHz3K/2yuVSXK6OvMG4/058TXG09qKgXYP","git_version":"daf3b1d"}

common/types/message/message.go

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package message
22

33
import (
4+
"encoding/json"
45
"errors"
56
"fmt"
67

78
"github.com/scroll-tech/go-ethereum/common"
89
)
910

11+
const (
12+
euclidFork = "euclid"
13+
)
14+
1015
// ProofType represents the type of task.
1116
type ProofType uint8
1217

@@ -61,6 +66,7 @@ type ChunkInfo struct {
6166
DataHash common.Hash `json:"data_hash"`
6267
IsPadding bool `json:"is_padding"`
6368
TxBytes []byte `json:"tx_bytes"`
69+
TxBytesHash common.Hash `json:"tx_data_digest"`
6470
}
6571

6672
// SubCircuitRowUsage tracing info added in v0.11.0rc8
@@ -77,6 +83,8 @@ type ChunkProof interface {
7783
// NewChunkProof creates a new ChunkProof instance.
7884
func NewChunkProof(hardForkName string) ChunkProof {
7985
switch hardForkName {
86+
case euclidFork:
87+
return &OpenVMChunkProof{}
8088
default:
8189
return &Halo2ChunkProof{}
8290
}
@@ -109,6 +117,8 @@ type BatchProof interface {
109117
// NewBatchProof creates a new BatchProof instance.
110118
func NewBatchProof(hardForkName string) BatchProof {
111119
switch hardForkName {
120+
case euclidFork:
121+
return &OpenVMBatchProof{}
112122
default:
113123
return &Halo2BatchProof{}
114124
}
@@ -164,6 +174,8 @@ type BundleProof interface {
164174
// NewBundleProof creates a new BundleProof instance.
165175
func NewBundleProof(hardForkName string) BundleProof {
166176
switch hardForkName {
177+
case euclidFork:
178+
return &OpenVMBundleProof{}
167179
default:
168180
return &Halo2BundleProof{}
169181
}
@@ -207,3 +219,149 @@ func (ap *Halo2BundleProof) SanityCheck() error {
207219

208220
return nil
209221
}
222+
223+
// Proof for flatten VM proof
224+
type OpenVMProof struct {
225+
Proof interface{} `json:"proofs"`
226+
PublicValues []uint32 `json:"public_values"`
227+
}
228+
229+
// Proof for flatten EVM proof
230+
type OpenVMEvmProof struct {
231+
Proof []byte `json:"proof"`
232+
Instances [][]string `json:"instances"`
233+
}
234+
235+
// OpenVMChunkProof includes the proof info that are required for chunk verification and rollup.
236+
type OpenVMChunkProof struct {
237+
MetaData struct {
238+
ChunkInfo *ChunkInfo `json:"chunk_info"`
239+
} `json:"metadata"`
240+
241+
VmProof *OpenVMProof `json:"proof"`
242+
Vk []byte `json:"vk,omitempty"`
243+
GitVersion string `json:"git_version,omitempty"`
244+
}
245+
246+
func (p *OpenVMChunkProof) Proof() []byte {
247+
proofJson, err := json.Marshal(p.VmProof)
248+
if err != nil {
249+
panic(fmt.Sprint("marshaling error", err))
250+
}
251+
252+
return proofJson
253+
}
254+
255+
// OpenVMBatchInfo is for calculating pi_hash for batch header
256+
type OpenVMBatchInfo struct {
257+
ParentBatchHash common.Hash `json:"parent_batch_hash"`
258+
ParentStateRoot common.Hash `json:"parent_state_root"`
259+
StateRoot common.Hash `json:"state_root"`
260+
WithdrawRoot common.Hash `json:"withdraw_root"`
261+
BatchHash common.Hash `json:"batch_hash"`
262+
ChainID uint64 `json:"chain_id"`
263+
}
264+
265+
// BatchProof includes the proof info that are required for batch verification and rollup.
266+
type OpenVMBatchProof struct {
267+
MetaData struct {
268+
BatchInfo *OpenVMBatchInfo `json:"batch_info"`
269+
BatchHash common.Hash `json:"batch_hash"`
270+
} `json:"metadata"`
271+
272+
VmProof *OpenVMProof `json:"proof"`
273+
Vk []byte `json:"vk,omitempty"`
274+
GitVersion string `json:"git_version,omitempty"`
275+
}
276+
277+
func (p *OpenVMBatchProof) Proof() []byte {
278+
proofJson, err := json.Marshal(p.VmProof)
279+
if err != nil {
280+
panic(fmt.Sprint("marshaling error", err))
281+
}
282+
283+
return proofJson
284+
}
285+
286+
// SanityCheck checks whether a BatchProof is in a legal format
287+
func (ap *OpenVMBatchProof) SanityCheck() error {
288+
if ap == nil {
289+
return errors.New("agg_proof is nil")
290+
}
291+
if ap.MetaData.BatchInfo == nil {
292+
return errors.New("batch info not ready")
293+
}
294+
295+
if ap.VmProof == nil {
296+
return errors.New("proof not ready")
297+
} else {
298+
if len(ap.Vk) == 0 {
299+
return errors.New("vk not ready")
300+
}
301+
pf := ap.VmProof
302+
if pf.Proof == nil {
303+
return errors.New("proof data not ready")
304+
}
305+
if len(pf.PublicValues) == 0 {
306+
return errors.New("proof public value not ready")
307+
}
308+
}
309+
310+
return nil
311+
}
312+
313+
// OpenVMBundleInfo is for calculating pi_hash for bundle header
314+
type OpenVMBundleInfo struct {
315+
ChainID uint64 `json:"chain_id"`
316+
PrevStateRoot common.Hash `json:"prev_state_root"`
317+
PostStateRoot common.Hash `json:"post_state_root"`
318+
WithdrawRoot common.Hash `json:"withdraw_root"`
319+
NumBatches uint32 `json:"num_batches"`
320+
PrevBatchHash common.Hash `json:"prev_batch_hash"`
321+
BatchHash common.Hash `json:"batch_hash"`
322+
}
323+
324+
// OpenVMBundleProof includes the proof info that are required for verification of a bundle of batch proofs.
325+
type OpenVMBundleProof struct {
326+
MetaData struct {
327+
BundleInfo *OpenVMBundleInfo `json:"bundle_info"`
328+
BunndlePIHash common.Hash `json:"bundle_pi_hash"`
329+
} `json:"metadata"`
330+
331+
EvmProof *OpenVMEvmProof `json:"proof"`
332+
Vk []byte `json:"vk,omitempty"`
333+
GitVersion string `json:"git_version,omitempty"`
334+
}
335+
336+
func (p *OpenVMBundleProof) Proof() []byte {
337+
return p.EvmProof.Proof
338+
}
339+
340+
// SanityCheck checks whether a BundleProof is in a legal format
341+
func (ap *OpenVMBundleProof) SanityCheck() error {
342+
if ap == nil {
343+
return errors.New("agg_proof is nil")
344+
}
345+
346+
if ap.MetaData.BundleInfo == nil {
347+
return errors.New("bundle info not ready")
348+
}
349+
350+
if ap.EvmProof == nil {
351+
return errors.New("proof not ready")
352+
} else {
353+
if len(ap.Vk) == 0 {
354+
return errors.New("vk not ready")
355+
}
356+
pf := ap.EvmProof
357+
if len(pf.Proof)%32 != 0 {
358+
return fmt.Errorf("proof buffer length must be a multiple of 32, got: %d", len(pf.Proof))
359+
}
360+
361+
if len(pf.Instances) == 0 {
362+
return errors.New("instance not ready")
363+
}
364+
}
365+
366+
return nil
367+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package message
2+
3+
import (
4+
"encoding/json"
5+
"os"
6+
"testing"
7+
8+
"github.com/scroll-tech/go-ethereum/common"
9+
)
10+
11+
func TestDeserializeOpenVMProof(t *testing.T) {
12+
// Read the batch.json file located in the same directory.
13+
data, err := os.ReadFile("batch-proof-sample.json")
14+
if err != nil {
15+
t.Fatalf("failed to read batch proof sample.json: %v", err)
16+
}
17+
18+
// Decode the JSON data into an BatchTask instance.
19+
batchProof := NewBatchProof("euclid")
20+
if err = json.Unmarshal(data, &batchProof); err != nil {
21+
t.Fatalf("failed to unmarshal JSON into Batch Proof: %v", err)
22+
}
23+
if err = batchProof.SanityCheck(); err != nil {
24+
t.Fatalf("failed to sanity check for Batch Proof: %v", err)
25+
}
26+
27+
ovmbatchProof := batchProof.(*OpenVMBatchProof)
28+
29+
if ovmbatchProof.MetaData.BatchInfo.ParentStateRoot !=
30+
common.HexToHash("0xe3440bcf882852bb1a9d6ba941e53a645220fee2c531ed79fa60481be8078c12") {
31+
t.Fatalf("get unexpected bundle info, parent state root is %v", ovmbatchProof.MetaData.BatchInfo.ParentStateRoot)
32+
}
33+
34+
// Read the batch.json file located in the same directory.
35+
data, err = os.ReadFile("bundle-proof-sample.json")
36+
if err != nil {
37+
t.Fatalf("failed to read bundle proof sample.json: %v", err)
38+
}
39+
40+
// Decode the JSON data into an BatchTask instance.
41+
bundleProof := NewBundleProof("euclid")
42+
if err = json.Unmarshal(data, &bundleProof); err != nil {
43+
t.Fatalf("failed to unmarshal JSON into Bundle Proof: %v", err)
44+
}
45+
if err = bundleProof.SanityCheck(); err != nil {
46+
t.Fatalf("failed to sanity check for Bundle Proof: %v", err)
47+
}
48+
ovmbundleProof := bundleProof.(*OpenVMBundleProof)
49+
50+
if ovmbundleProof.MetaData.BundleInfo.PostStateRoot !=
51+
common.HexToHash("0x9e8b9928c55ccbc933911283175842fa515e49dd3f2fe0192c4346095695d741") {
52+
t.Fatalf("get unexpected bundle info, post state root is %v", ovmbundleProof.MetaData.BundleInfo.PostStateRoot)
53+
}
54+
}

0 commit comments

Comments
 (0)