-
Notifications
You must be signed in to change notification settings - Fork 628
[Refactor] For universal prover task (the update on coordinator) #1682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f88f0b9
update coordinator for universal task prover
noel2004 9d47f2e
complete the getmetadata method
noel2004 e1ce631
fix lints
noel2004 dc6d3af
fix test failure
noel2004 7b01c4a
fixing according to reviews
noel2004 1ff82ab
rewrite metadata caching by persist into db
noel2004 e7db393
try fix CI
noel2004 b046f99
temporary swich libzkp to depend master branch of zkvm-prover for CI …
noel2004 3bb4ccf
chore: auto version bump [bot]
georgehao 745a7d3
fix more CI and update according to reviews
noel2004 1f3fb8c
Merge remote-tracking branch 'origin/develop' into refactor/zkvm_2_co…
noel2004 d844890
resume log format
noel2004 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| module scroll-tech/common/libzkp | ||
|
|
||
| go 1.22 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| use std::{ | ||
| ffi::CStr, | ||
| os::raw::c_char, | ||
| ffi::{c_char, CStr}, | ||
| panic::{catch_unwind, AssertUnwindSafe}, | ||
| }; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,48 @@ | ||
| // BatchVerifier is used to: | ||
| // Verifier is used to: | ||
| // - Verify a batch proof | ||
| // - Verify a bundle proof | ||
| void init(char* config); | ||
| // - Verify a chunk proof | ||
|
|
||
| char verify_batch_proof(char* proof, char* fork_name); | ||
| #ifndef LIBZKP_H | ||
| #define LIBZKP_H | ||
|
|
||
| char verify_bundle_proof(char* proof, char* fork_name); | ||
| #include <stddef.h> // For size_t | ||
|
|
||
| // Initialize the verifier with configuration | ||
| void init_verifier(char* config); | ||
|
|
||
| // Initialize the l2geth with configuration | ||
| void init_l2geth(char* config); | ||
|
|
||
| // Verify proofs - returns non-zero for success, zero for failure | ||
| char verify_batch_proof(char* proof, char* fork_name); | ||
georgehao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| char verify_bundle_proof(char* proof, char* fork_name); | ||
| char verify_chunk_proof(char* proof, char* fork_name); | ||
|
|
||
| // Dump verification key to file | ||
| void dump_vk(char* fork_name, char* file); | ||
|
|
||
| // The result struct to hold data from handling a proving task | ||
| typedef struct { | ||
| char ok; | ||
| char* universal_task; | ||
| char* metadata; | ||
| char expected_pi_hash[32]; | ||
| } HandlingResult; | ||
|
|
||
georgehao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Generate a universal task based on task type and input JSON | ||
| // Returns a struct containing task data, metadata, and expected proof hash | ||
| HandlingResult gen_universal_task(int task_type, char* task, char* fork_name); | ||
|
|
||
| // Release memory allocated for a HandlingResult returned by gen_universal_task | ||
| void release_task_result(HandlingResult result); | ||
georgehao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Generate a wrapped proof from the universal prover output and metadata | ||
| // Returns a JSON string containing the wrapped proof, or NULL on error | ||
| // The caller must call release_string on the returned pointer when done | ||
| char* gen_wrapped_proof(char* proof_json, char* metadata, char* vk, size_t vk_len); | ||
|
|
||
| // Release memory allocated for a string returned by gen_wrapped_proof | ||
| void release_string(char* string_ptr); | ||
|
|
||
| #endif /* LIBZKP_H */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| package libzkp | ||
|
|
||
| /* | ||
| #cgo LDFLAGS: -lzkp -lm -ldl -L${SRCDIR}/lib -Wl,-rpath=${SRCDIR}/lib | ||
| #cgo gpu LDFLAGS: -lzkp -lm -ldl -lgmp -lstdc++ -lprocps -L/usr/local/cuda/lib64/ -lcudart -L${SRCDIR}/lib/ -Wl,-rpath=${SRCDIR}/lib | ||
| #include <stdlib.h> | ||
| #include "interface/libzkp.h" | ||
| */ | ||
| import "C" //nolint:typecheck | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "unsafe" | ||
| ) | ||
|
|
||
| // Helper function to convert Go string to C string and handle cleanup | ||
| func goToCString(s string) *C.char { | ||
| return C.CString(s) | ||
| } | ||
|
|
||
| // Helper function to free C string | ||
| func freeCString(s *C.char) { | ||
| C.free(unsafe.Pointer(s)) | ||
| } | ||
|
|
||
| // Initialize the verifier | ||
| func InitVerifier(configJSON string) { | ||
| cConfig := goToCString(configJSON) | ||
| defer freeCString(cConfig) | ||
|
|
||
| C.init_verifier(cConfig) | ||
| } | ||
|
|
||
| // Initialize the verifier | ||
| func InitL2geth(configJSON string) { | ||
| cConfig := goToCString(configJSON) | ||
| defer freeCString(cConfig) | ||
|
|
||
| C.init_l2geth(cConfig) | ||
| } | ||
|
|
||
| // Verify a chunk proof | ||
| func VerifyChunkProof(proofData, forkName string) bool { | ||
| cProof := goToCString(proofData) | ||
| cForkName := goToCString(forkName) | ||
| defer freeCString(cProof) | ||
| defer freeCString(cForkName) | ||
|
|
||
| result := C.verify_chunk_proof(cProof, cForkName) | ||
| return result != 0 | ||
| } | ||
|
|
||
| // Verify a batch proof | ||
| func VerifyBatchProof(proofData, forkName string) bool { | ||
| cProof := goToCString(proofData) | ||
| cForkName := goToCString(forkName) | ||
| defer freeCString(cProof) | ||
| defer freeCString(cForkName) | ||
|
|
||
| result := C.verify_batch_proof(cProof, cForkName) | ||
| return result != 0 | ||
| } | ||
|
|
||
| // Verify a bundle proof | ||
| func VerifyBundleProof(proofData, forkName string) bool { | ||
| cProof := goToCString(proofData) | ||
| cForkName := goToCString(forkName) | ||
| defer freeCString(cProof) | ||
| defer freeCString(cForkName) | ||
|
|
||
| result := C.verify_bundle_proof(cProof, cForkName) | ||
| return result != 0 | ||
| } | ||
|
|
||
| // Generate a universal task | ||
| func GenerateUniversalTask(taskType int, taskJSON, forkName string) (bool, string, string, []byte) { | ||
| cTask := goToCString(taskJSON) | ||
| cForkName := goToCString(forkName) | ||
| defer freeCString(cTask) | ||
| defer freeCString(cForkName) | ||
|
|
||
| result := C.gen_universal_task(C.int(taskType), cTask, cForkName) | ||
| defer C.release_task_result(result) | ||
|
|
||
| // Check if the operation was successful | ||
| if result.ok == 0 { | ||
| return false, "", "", nil | ||
| } | ||
|
|
||
| // Convert C strings to Go strings | ||
| universalTask := C.GoString(result.universal_task) | ||
| metadata := C.GoString(result.metadata) | ||
|
|
||
| // Convert C array to Go slice | ||
| piHash := make([]byte, 32) | ||
| for i := 0; i < 32; i++ { | ||
| piHash[i] = byte(result.expected_pi_hash[i]) | ||
| } | ||
|
|
||
| return true, universalTask, metadata, piHash | ||
| } | ||
|
|
||
| // Generate wrapped proof | ||
| func GenerateWrappedProof(proofJSON, metadata string, vkData []byte) string { | ||
| cProofJSON := goToCString(proofJSON) | ||
| cMetadata := goToCString(metadata) | ||
| defer freeCString(cProofJSON) | ||
| defer freeCString(cMetadata) | ||
|
|
||
| // Create a C array from Go slice | ||
| cVkData := (*C.char)(unsafe.Pointer(&vkData[0])) | ||
|
|
||
| resultPtr := C.gen_wrapped_proof(cProofJSON, cMetadata, cVkData, C.size_t(len(vkData))) | ||
| if resultPtr == nil { | ||
| return "" | ||
| } | ||
|
|
||
georgehao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Convert result to Go string and free C memory | ||
| result := C.GoString(resultPtr) | ||
| C.release_string(resultPtr) | ||
|
|
||
| return result | ||
| } | ||
|
|
||
| // Dumps a verification key to a file | ||
| func DumpVk(forkName, filePath string) error { | ||
| cForkName := goToCString(forkName) | ||
| cFilePath := goToCString(filePath) | ||
| defer freeCString(cForkName) | ||
| defer freeCString(cFilePath) | ||
|
|
||
| // Call the C function to dump the verification key | ||
| C.dump_vk(cForkName, cFilePath) | ||
|
|
||
| // Check if the file was created successfully | ||
| // Note: The C function doesn't return an error code, so we check if the file exists | ||
| if _, err := os.Stat(filePath); os.IsNotExist(err) { | ||
| return fmt.Errorf("failed to dump verification key: file %s was not created", filePath) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
lispc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| /build/bin | ||
| .idea | ||
| internal/logic/verifier/lib | ||
| internal/libzkp/lib/libzkp.so |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.