Skip to content

Commit 4365aaf

Browse files
committed
refactor libzkp to be completely mocked out
1 parent 6ee026f commit 4365aaf

File tree

5 files changed

+76
-28
lines changed

5 files changed

+76
-28
lines changed

coordinator/internal/logic/libzkp/lib.go

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !mock_verifier
2+
13
package libzkp
24

35
/*
@@ -13,8 +15,6 @@ import (
1315
"os"
1416
"strings"
1517
"unsafe"
16-
17-
"scroll-tech/common/types/message"
1818
)
1919

2020
func init() {
@@ -72,31 +72,6 @@ func VerifyBundleProof(proofData, forkName string) bool {
7272
return result != 0
7373
}
7474

75-
// TaskType enum values matching the Rust enum
76-
const (
77-
TaskTypeChunk = 0
78-
TaskTypeBatch = 1
79-
TaskTypeBundle = 2
80-
)
81-
82-
func fromMessageTaskType(taskType int) int {
83-
switch message.ProofType(taskType) {
84-
case message.ProofTypeChunk:
85-
return TaskTypeChunk
86-
case message.ProofTypeBatch:
87-
return TaskTypeBatch
88-
case message.ProofTypeBundle:
89-
return TaskTypeBundle
90-
default:
91-
panic(fmt.Sprintf("unsupported proof type: %d", taskType))
92-
}
93-
}
94-
95-
// Generate a universal task
96-
func GenerateUniversalTask(taskType int, taskJSON, forkName string, expectedVk []byte) (bool, string, string, []byte) {
97-
return generateUniversalTask(fromMessageTaskType(taskType), taskJSON, strings.ToLower(forkName), expectedVk)
98-
}
99-
10075
// Generate wrapped proof
10176
func GenerateWrappedProof(proofJSON, metadata string, vkData []byte) string {
10277
cProofJSON := goToCString(proofJSON)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//go:build mock_verifier
2+
3+
package libzkp
4+
5+
// // InitVerifier is a no-op in the mock.
6+
// func InitVerifier(configJSON string) {}
7+
8+
// // VerifyChunkProof returns a fixed success in the mock.
9+
// func VerifyChunkProof(proofData, forkName string) bool {
10+
// return true
11+
// }
12+
13+
// // VerifyBatchProof returns a fixed success in the mock.
14+
// func VerifyBatchProof(proofData, forkName string) bool {
15+
// return true
16+
// }
17+
18+
// // VerifyBundleProof returns a fixed success in the mock.
19+
// func VerifyBundleProof(proofData, forkName string) bool {
20+
// return true
21+
// }
22+
23+
// GenerateWrappedProof returns a fixed dummy proof string in the mock.
24+
func GenerateWrappedProof(proofJSON, metadata string, vkData []byte) string {
25+
return "mock-wrapped-proof"
26+
}
27+
28+
// DumpVk is a no-op and returns nil in the mock.
29+
func DumpVk(forkName, filePath string) error {
30+
return nil
31+
}
32+
33+
// SetDynamicFeature is a no-op in the mock.
34+
func SetDynamicFeature(feats string) {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package libzkp
2+
3+
import (
4+
"fmt"
5+
"scroll-tech/common/types/message"
6+
)
7+
8+
// TaskType enum values matching the Rust enum
9+
const (
10+
TaskTypeChunk = 0
11+
TaskTypeBatch = 1
12+
TaskTypeBundle = 2
13+
)
14+
15+
func fromMessageTaskType(taskType int) int {
16+
switch message.ProofType(taskType) {
17+
case message.ProofTypeChunk:
18+
return TaskTypeChunk
19+
case message.ProofTypeBatch:
20+
return TaskTypeBatch
21+
case message.ProofTypeBundle:
22+
return TaskTypeBundle
23+
default:
24+
panic(fmt.Sprintf("unsupported proof type: %d", taskType))
25+
}
26+
}

coordinator/internal/logic/libzkp/mock_universal_task.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package libzkp
55
import (
66
"encoding/json"
77
"fmt"
8+
"strings"
89

910
"scroll-tech/common/types/message"
1011

@@ -14,6 +15,10 @@ import (
1415
func InitL2geth(configJSON string) {
1516
}
1617

18+
func GenerateUniversalTask(taskType int, taskJSON, forkName string, expectedVk []byte) (bool, string, string, []byte) {
19+
return generateUniversalTask(fromMessageTaskType(taskType), taskJSON, strings.ToLower(forkName), expectedVk)
20+
}
21+
1722
func generateUniversalTask(taskType int, taskJSON, forkName string, expectedVk []byte) (bool, string, string, []byte) {
1823

1924
fmt.Printf("call mocked generate universal task %d, taskJson %s\n", taskType, taskJSON)

coordinator/internal/logic/libzkp/universal_task.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ package libzkp
77
#include "libzkp.h"
88
*/
99
import "C" //nolint:typecheck
10-
import "unsafe"
10+
import (
11+
"strings"
12+
"unsafe"
13+
)
1114

1215
// Initialize the handler for universal task
1316
func InitL2geth(configJSON string) {
@@ -17,6 +20,11 @@ func InitL2geth(configJSON string) {
1720
C.init_l2geth(cConfig)
1821
}
1922

23+
// Generate a universal task
24+
func GenerateUniversalTask(taskType int, taskJSON, forkName string, expectedVk []byte) (bool, string, string, []byte) {
25+
return generateUniversalTask(fromMessageTaskType(taskType), taskJSON, strings.ToLower(forkName), expectedVk)
26+
}
27+
2028
func generateUniversalTask(taskType int, taskJSON, forkName string, expectedVk []byte) (bool, string, string, []byte) {
2129
cTask := goToCString(taskJSON)
2230
cForkName := goToCString(forkName)

0 commit comments

Comments
 (0)