Skip to content

Commit 0578aab

Browse files
colinlyguojonastheisomerfirmaknoel2004roynalnaruto
authored
feat: openvm euclid v2 (#1613)
Signed-off-by: noelwei <[email protected]> Co-authored-by: jonastheis <[email protected]> Co-authored-by: Ömer Faruk Irmak <[email protected]> Co-authored-by: noelwei <[email protected]> Co-authored-by: Rohit Narurkar <[email protected]> Co-authored-by: Péter Garamvölgyi <[email protected]> Co-authored-by: Morty <[email protected]> Co-authored-by: omerfirmak <[email protected]> Co-authored-by: jonastheis <[email protected]> Co-authored-by: georgehao <[email protected]> Co-authored-by: kunxian xia <[email protected]> Co-authored-by: Morty <[email protected]> Co-authored-by: Velaciela <[email protected]> Co-authored-by: colinlyguo <[email protected]>
1 parent 55dfbf6 commit 0578aab

File tree

32 files changed

+2149
-1439
lines changed

32 files changed

+2149
-1439
lines changed

common/libzkp/impl/Cargo.lock

Lines changed: 365 additions & 491 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/libzkp/impl/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ ruint = { git = "https://github.com/scroll-tech/uint.git", branch = "v1.12.3" }
1414
tiny-keccak = { git = "https://github.com/scroll-tech/tiny-keccak", branch = "scroll-patch-v2.0.2-openvm-v1.0.0-rc.1" }
1515

1616
[dependencies]
17-
euclid_prover = { git = "https://github.com/scroll-tech/zkvm-prover.git", tag = "v0.1.0-rc.6", package = "scroll-zkvm-prover" }
18-
euclid_verifier = { git = "https://github.com/scroll-tech/zkvm-prover.git", tag = "v0.1.0-rc.6", package = "scroll-zkvm-verifier" }
17+
euclid_prover = { git = "https://github.com/scroll-tech/zkvm-prover.git", tag = "v0.2.0", package = "scroll-zkvm-prover" }
18+
euclid_verifier = { git = "https://github.com/scroll-tech/zkvm-prover.git", tag = "v0.2.0", package = "scroll-zkvm-verifier" }
1919

2020
base64 = "0.13.0"
2121
env_logger = "0.9.0"

common/libzkp/impl/src/verifier.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#![allow(static_mut_refs)]
22

33
mod euclid;
4+
mod euclidv2;
45

56
use anyhow::{bail, Result};
67
use euclid::EuclidVerifier;
8+
use euclidv2::EuclidV2Verifier;
79
use serde::{Deserialize, Serialize};
810
use std::{cell::OnceCell, path::Path, rc::Rc};
911

@@ -51,7 +53,17 @@ pub fn init(config: VerifierConfig) {
5153
unsafe {
5254
VERIFIER_LOW
5355
.set(VerifierPair(
54-
config.high_version_circuit.fork_name,
56+
"euclid".to_string(),
57+
Rc::new(Box::new(verifier)),
58+
))
59+
.unwrap_unchecked();
60+
}
61+
62+
let verifier = EuclidV2Verifier::new(&config.high_version_circuit.assets_path);
63+
unsafe {
64+
VERIFIER_HIGH
65+
.set(VerifierPair(
66+
"euclidV2".to_string(),
5567
Rc::new(Box::new(verifier)),
5668
))
5769
.unwrap_unchecked();

common/libzkp/impl/src/verifier/euclid.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use anyhow::Result;
44

55
use crate::utils::panic_catch;
66
use euclid_prover::{BatchProof, BundleProof, ChunkProof};
7-
use euclid_verifier::verifier::{BatchVerifier, BundleVerifier, ChunkVerifier};
7+
use euclid_verifier::verifier::{BatchVerifier, BundleVerifierEuclidV1, ChunkVerifier};
88
use std::{fs::File, path::Path};
99

1010
pub struct EuclidVerifier {
1111
chunk_verifier: ChunkVerifier,
1212
batch_verifier: BatchVerifier,
13-
bundle_verifier: BundleVerifier,
13+
bundle_verifier: BundleVerifierEuclidV1,
1414
}
1515

1616
impl EuclidVerifier {
@@ -24,7 +24,7 @@ impl EuclidVerifier {
2424
.expect("Setting up chunk verifier"),
2525
batch_verifier: BatchVerifier::setup(&config, &exe, &verifier_bin)
2626
.expect("Setting up batch verifier"),
27-
bundle_verifier: BundleVerifier::setup(&config, &exe, &verifier_bin)
27+
bundle_verifier: BundleVerifierEuclidV1::setup(&config, &exe, &verifier_bin)
2828
.expect("Setting up bundle verifier"),
2929
}
3030
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
use super::{ProofVerifier, TaskType, VKDump};
2+
3+
use anyhow::Result;
4+
5+
use crate::utils::panic_catch;
6+
use euclid_prover::{BatchProof, BundleProof, ChunkProof};
7+
use euclid_verifier::verifier::{BatchVerifier, BundleVerifierEuclidV2, ChunkVerifier};
8+
use std::{fs::File, path::Path};
9+
10+
pub struct EuclidV2Verifier {
11+
chunk_verifier: ChunkVerifier,
12+
batch_verifier: BatchVerifier,
13+
bundle_verifier: BundleVerifierEuclidV2,
14+
}
15+
16+
impl EuclidV2Verifier {
17+
pub fn new(assets_dir: &str) -> Self {
18+
let verifier_bin = Path::new(assets_dir).join("verifier.bin");
19+
let config = Path::new(assets_dir).join("root-verifier-vm-config");
20+
let exe = Path::new(assets_dir).join("root-verifier-committed-exe");
21+
22+
Self {
23+
chunk_verifier: ChunkVerifier::setup(&config, &exe, &verifier_bin)
24+
.expect("Setting up chunk verifier"),
25+
batch_verifier: BatchVerifier::setup(&config, &exe, &verifier_bin)
26+
.expect("Setting up batch verifier"),
27+
bundle_verifier: BundleVerifierEuclidV2::setup(&config, &exe, &verifier_bin)
28+
.expect("Setting up bundle verifier"),
29+
}
30+
}
31+
}
32+
33+
impl ProofVerifier for EuclidV2Verifier {
34+
fn verify(&self, task_type: super::TaskType, proof: Vec<u8>) -> Result<bool> {
35+
panic_catch(|| match task_type {
36+
TaskType::Chunk => {
37+
let proof = serde_json::from_slice::<ChunkProof>(proof.as_slice()).unwrap();
38+
self.chunk_verifier
39+
.verify_proof(proof.proof.as_root_proof().unwrap())
40+
}
41+
TaskType::Batch => {
42+
let proof = serde_json::from_slice::<BatchProof>(proof.as_slice()).unwrap();
43+
self.batch_verifier
44+
.verify_proof(proof.proof.as_root_proof().unwrap())
45+
}
46+
TaskType::Bundle => {
47+
let proof = serde_json::from_slice::<BundleProof>(proof.as_slice()).unwrap();
48+
self.bundle_verifier
49+
.verify_proof_evm(&proof.proof.as_evm_proof().unwrap())
50+
}
51+
})
52+
.map_err(|err_str: String| anyhow::anyhow!(err_str))
53+
}
54+
55+
fn dump_vk(&self, file: &Path) {
56+
let f = File::create(file).expect("Failed to open file to dump VK");
57+
58+
let dump = VKDump {
59+
chunk_vk: base64::encode(self.chunk_verifier.get_app_vk()),
60+
batch_vk: base64::encode(self.batch_verifier.get_app_vk()),
61+
bundle_vk: base64::encode(self.bundle_verifier.get_app_vk()),
62+
};
63+
serde_json::to_writer(f, &dump).expect("Failed to dump VK");
64+
}
65+
}

common/types/message/message.go

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

1113
const (
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.
4349
type 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.
48100
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"`
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.
59113
type 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
64121
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"`
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.
88158
func 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.
122192
func 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.
179249
func 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
260330
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"`
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.

common/types/message/message_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package message
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
)
7+
8+
func TestBytes48(t *testing.T) {
9+
ti := &Byte48{}
10+
ti.UnmarshalText([]byte("0x1"))
11+
if s, err := ti.MarshalText(); err == nil {
12+
if len(s) != 98 {
13+
panic(fmt.Sprintf("wrong str: %s", s))
14+
}
15+
}
16+
ti.UnmarshalText([]byte("0x0"))
17+
if s, err := ti.MarshalText(); err == nil {
18+
if len(s) != 98 {
19+
panic(fmt.Sprintf("wrong str: %s", s))
20+
}
21+
}
22+
}

common/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"runtime/debug"
66
)
77

8-
var tag = "v4.4.99"
8+
var tag = "v4.5.0"
99

1010
var commit = func() string {
1111
if info, ok := debug.ReadBuildInfo(); ok {

coordinator/go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ module scroll-tech/coordinator
22

33
go 1.22
44

5-
toolchain go1.22.2
6-
75
require (
86
github.com/appleboy/gin-jwt/v2 v2.9.1
97
github.com/gin-gonic/gin v1.9.1
108
github.com/go-resty/resty/v2 v2.7.0
119
github.com/google/uuid v1.6.0
1210
github.com/mitchellh/mapstructure v1.5.0
1311
github.com/prometheus/client_golang v1.19.0
14-
github.com/scroll-tech/da-codec v0.1.3-0.20250310095435-012aaee6b435
12+
github.com/scroll-tech/da-codec v0.1.3-0.20250401062930-9f9f53898493
1513
github.com/scroll-tech/go-ethereum v1.10.14-0.20250305151038-478940e79601
1614
github.com/shopspring/decimal v1.3.1
1715
github.com/stretchr/testify v1.10.0

coordinator/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU
177177
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
178178
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
179179
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
180-
github.com/scroll-tech/da-codec v0.1.3-0.20250310095435-012aaee6b435 h1:X9fkvjrYBY79lGgKEPpUhuiJ4vWpWwzOVw4H8CU8L54=
181-
github.com/scroll-tech/da-codec v0.1.3-0.20250310095435-012aaee6b435/go.mod h1:yhTS9OVC0xQGhg7DN5iV5KZJvnSIlFWAxDdp+6jxQtY=
180+
github.com/scroll-tech/da-codec v0.1.3-0.20250401062930-9f9f53898493 h1:Ioc01J0WEMxuwFvEPGJeBKXdf2KY4Yc3XbFky/IxLlI=
181+
github.com/scroll-tech/da-codec v0.1.3-0.20250401062930-9f9f53898493/go.mod h1:yhTS9OVC0xQGhg7DN5iV5KZJvnSIlFWAxDdp+6jxQtY=
182182
github.com/scroll-tech/go-ethereum v1.10.14-0.20250305151038-478940e79601 h1:NEsjCG6uSvLRBlsP3+x6PL1kM+Ojs3g8UGotIPgJSz8=
183183
github.com/scroll-tech/go-ethereum v1.10.14-0.20250305151038-478940e79601/go.mod h1:OblWe1+QrZwdpwO0j/LY3BSGuKT3YPUFBDQQgvvfStQ=
184184
github.com/scroll-tech/zktrie v0.8.4 h1:UagmnZ4Z3ITCk+aUq9NQZJNAwnWl4gSxsLb2Nl7IgRE=

0 commit comments

Comments
 (0)