Skip to content

Commit ed0e0e4

Browse files
lispckunxian-xia0xmountaintopHAOYUatHZ
authored
feat(libzkp): upgrade to v0.10.0k to support blob DA (scroll-tech#1212)
Co-authored-by: kunxian-xia <[email protected]> Co-authored-by: HAOYUatHZ <[email protected]> Co-authored-by: HAOYUatHZ <[email protected]> Co-authored-by: HAOYUatHZ <[email protected]>
1 parent d203033 commit ed0e0e4

File tree

8 files changed

+755
-402
lines changed

8 files changed

+755
-402
lines changed

common/libzkp/impl/Cargo.lock

Lines changed: 671 additions & 357 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: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,29 @@ edition = "2021"
88
crate-type = ["cdylib"]
99

1010
[patch.crates-io]
11+
gobuild = { git = "https://github.com/scroll-tech/gobuild.git" }
12+
halo2curves = { git = "https://github.com/scroll-tech/halo2curves", branch = "v0.1.0" }
1113
ethers-core = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
14+
ethers-providers = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
15+
ethers-signers = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
16+
#ethers-etherscan = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
17+
#ethers = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
1218
[patch."https://github.com/privacy-scaling-explorations/halo2.git"]
13-
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "develop" }
19+
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "v1.1" }
1420
[patch."https://github.com/privacy-scaling-explorations/poseidon.git"]
15-
poseidon = { git = "https://github.com/scroll-tech/poseidon.git", branch = "scroll-dev-0220" }
16-
[patch."https://github.com/privacy-scaling-explorations/halo2wrong.git"]
17-
halo2wrong = { git = "https://github.com/scroll-tech/halo2wrong.git", branch = "halo2-ecc-snark-verifier-0323" }
18-
maingate = { git = "https://github.com/scroll-tech/halo2wrong", branch = "halo2-ecc-snark-verifier-0323" }
19-
[patch."https://github.com/privacy-scaling-explorations/halo2curves.git"]
20-
halo2curves = { git = "https://github.com/scroll-tech/halo2curves.git", branch = "0.3.1-derive-serde" }
21+
poseidon = { git = "https://github.com/scroll-tech/poseidon.git", branch = "main" }
22+
[patch."https://github.com/privacy-scaling-explorations/bls12_381"]
23+
bls12_381 = { git = "https://github.com/scroll-tech/bls12_381", branch = "feat/impl_scalar_field" }
2124

2225
[dependencies]
23-
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "develop" }
24-
prover = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.9.9", default-features = false, features = ["parallel_syn", "scroll", "shanghai", "strict-ccc"] }
26+
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "v1.1" }
27+
prover = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.10.0k", default-features = false, features = ["parallel_syn", "scroll", "shanghai"] }
2528

2629
base64 = "0.13.0"
2730
env_logger = "0.9.0"
2831
libc = "0.2"
2932
log = "0.4"
30-
once_cell = "1.8.0"
33+
once_cell = "1.19"
3134
serde = "1.0"
3235
serde_derive = "1.0"
3336
serde_json = "1.0.66"

common/libzkp/impl/rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2022-12-10
1+
nightly-2023-12-03

common/libzkp/impl/src/batch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub unsafe extern "C" fn gen_batch_proof(
119119

120120
let chunk_hashes_proofs = chunk_hashes
121121
.into_iter()
122-
.zip(chunk_proofs.into_iter())
122+
.zip(chunk_proofs)
123123
.collect();
124124

125125
let proof = PROVER

common/libzkp/impl/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(once_cell)]
2-
31
mod batch;
42
mod chunk;
53
mod types;

common/types/message/message.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ type ChunkInfo struct {
259259
WithdrawRoot common.Hash `json:"withdraw_root"`
260260
DataHash common.Hash `json:"data_hash"`
261261
IsPadding bool `json:"is_padding"`
262+
TxBytes []byte `json:"tx_bytes"`
262263
}
263264

264265
// ChunkProof includes the proof info that are required for chunk verification and rollup.

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.3.79"
8+
var tag = "v4.3.80"
99

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

prover/core/prover_test.go

Lines changed: 67 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import (
77
"encoding/base64"
88
"encoding/json"
99
"flag"
10+
"fmt"
1011
"io"
1112
"os"
13+
"path/filepath"
14+
"sort"
1215
"testing"
1316

1417
"github.com/scroll-tech/go-ethereum/core/types"
@@ -24,8 +27,7 @@ var (
2427
paramsPath = flag.String("params", "/assets/test_params", "params dir")
2528
assetsPath = flag.String("assets", "/assets/test_assets", "assets dir")
2629
proofDumpPath = flag.String("dump", "/assets/proof_data", "the path proofs dump to")
27-
tracePath1 = flag.String("trace1", "/assets/traces/1_transfer.json", "chunk trace 1")
28-
tracePath2 = flag.String("trace2", "/assets/traces/10_transfer.json", "chunk trace 2")
30+
batchDirPath = flag.String("batch-dir", "/assets/traces/batch_24", "batch directory")
2931
batchVkPath = flag.String("batch-vk", "/assets/test_assets/agg_vk.vkey", "batch vk")
3032
chunkVkPath = flag.String("chunk-vk", "/assets/test_assets/chunk_vk.vkey", "chunk vk")
3133
)
@@ -46,23 +48,34 @@ func TestFFI(t *testing.T) {
4648
as.Equal(chunkProverCore.VK, readVk(*chunkVkPath, as))
4749
t.Log("Chunk VK must be available when init")
4850

49-
chunkTrace1 := readChunkTrace(*tracePath1, as)
50-
chunkTrace2 := readChunkTrace(*tracePath2, as)
51-
t.Log("Loaded chunk traces")
52-
53-
chunkInfo1, err := chunkProverCore.TracesToChunkInfo(chunkTrace1)
54-
as.NoError(err)
55-
chunkInfo2, err := chunkProverCore.TracesToChunkInfo(chunkTrace2)
56-
as.NoError(err)
57-
t.Log("Converted to chunk infos")
58-
59-
chunkProof1, err := chunkProverCore.ProveChunk("chunk_proof1", chunkTrace1)
60-
as.NoError(err)
61-
t.Log("Generated and dumped chunk proof 1")
62-
63-
chunkProof2, err := chunkProverCore.ProveChunk("chunk_proof2", chunkTrace2)
51+
// Get the list of subdirectories (chunks)
52+
chunkDirs, err := os.ReadDir(*batchDirPath)
6453
as.NoError(err)
65-
t.Log("Generated and dumped chunk proof 2")
54+
sort.Slice(chunkDirs, func(i, j int) bool {
55+
return chunkDirs[i].Name() < chunkDirs[j].Name()
56+
})
57+
58+
chunkInfos := make([]*message.ChunkInfo, 0, len(chunkDirs))
59+
chunkProofs := make([]*message.ChunkProof, 0, len(chunkDirs))
60+
61+
for i, dir := range chunkDirs {
62+
if dir.IsDir() {
63+
chunkPath := filepath.Join(*batchDirPath, dir.Name())
64+
65+
chunkTrace := readChunkTrace(chunkPath, as)
66+
t.Logf("Loaded chunk trace %d", i+1)
67+
68+
chunkInfo, err := chunkProverCore.TracesToChunkInfo(chunkTrace)
69+
as.NoError(err)
70+
chunkInfos = append(chunkInfos, chunkInfo)
71+
t.Logf("Converted to chunk info %d", i+1)
72+
73+
chunkProof, err := chunkProverCore.ProveChunk(fmt.Sprintf("chunk_proof%d", i+1), chunkTrace)
74+
as.NoError(err)
75+
chunkProofs = append(chunkProofs, chunkProof)
76+
t.Logf("Generated and dumped chunk proof %d", i+1)
77+
}
78+
}
6679

6780
as.Equal(chunkProverCore.VK, readVk(*chunkVkPath, as))
6881
t.Log("Chunk VKs must be equal after proving")
@@ -79,29 +92,53 @@ func TestFFI(t *testing.T) {
7992
as.Equal(batchProverCore.VK, readVk(*batchVkPath, as))
8093
t.Log("Batch VK must be available when init")
8194

82-
chunkInfos := []*message.ChunkInfo{chunkInfo1, chunkInfo2}
83-
chunkProofs := []*message.ChunkProof{chunkProof1, chunkProof2}
8495
_, err = batchProverCore.ProveBatch("batch_proof", chunkInfos, chunkProofs)
8596
as.NoError(err)
8697
t.Log("Generated and dumped batch proof")
8798

8899
as.Equal(batchProverCore.VK, readVk(*batchVkPath, as))
89100
t.Log("Batch VKs must be equal after proving")
90101
}
91-
92102
func readChunkTrace(filePat string, as *assert.Assertions) []*types.BlockTrace {
93-
f, err := os.Open(filePat)
94-
as.NoError(err)
95-
defer func() {
96-
as.NoError(f.Close())
97-
}()
98-
byt, err := io.ReadAll(f)
103+
fileInfo, err := os.Stat(filePat)
99104
as.NoError(err)
100105

101-
trace := &types.BlockTrace{}
102-
as.NoError(json.Unmarshal(byt, trace))
106+
var traces []*types.BlockTrace
107+
108+
readFile := func(path string) {
109+
f, err := os.Open(path)
110+
as.NoError(err)
111+
defer func() {
112+
as.NoError(f.Close())
113+
}()
114+
byt, err := io.ReadAll(f)
115+
as.NoError(err)
116+
117+
trace := &types.BlockTrace{}
118+
as.NoError(json.Unmarshal(byt, trace))
119+
120+
traces = append(traces, trace)
121+
}
122+
123+
if fileInfo.IsDir() {
124+
files, err := os.ReadDir(filePat)
125+
as.NoError(err)
126+
127+
// Sort files alphabetically
128+
sort.Slice(files, func(i, j int) bool {
129+
return files[i].Name() < files[j].Name()
130+
})
131+
132+
for _, file := range files {
133+
if !file.IsDir() {
134+
readFile(filepath.Join(filePat, file.Name()))
135+
}
136+
}
137+
} else {
138+
readFile(filePat)
139+
}
103140

104-
return []*types.BlockTrace{trace}
141+
return traces
105142
}
106143

107144
func readVk(filePat string, as *assert.Assertions) string {

0 commit comments

Comments
 (0)