Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
577 changes: 363 additions & 214 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ repository = "https://github.com/scroll-tech/scroll"
version = "4.5.47"

[workspace.dependencies]
scroll-zkvm-prover = { git = "https://github.com/scroll-tech/zkvm-prover", rev = "060be4c" }
scroll-zkvm-verifier = { git = "https://github.com/scroll-tech/zkvm-prover", rev = "060be4c" }
scroll-zkvm-types = { git = "https://github.com/scroll-tech/zkvm-prover", rev = "060be4c" }
# include compatiblity fixing from "fix/coordinator"
scroll-zkvm-prover = { git = "https://github.com/scroll-tech/zkvm-prover", rev = "2c7fd3c" }
scroll-zkvm-verifier = { git = "https://github.com/scroll-tech/zkvm-prover", rev = "2c7fd3c" }
scroll-zkvm-types = { git = "https://github.com/scroll-tech/zkvm-prover", rev = "2c7fd3c" }

sbv-primitives = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "master", features = ["scroll", "rkyv"] }
sbv-utils = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "master" }
Expand Down
2 changes: 1 addition & 1 deletion common/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"runtime/debug"
)

var tag = "v4.5.47"
var tag = "v4.6.1"

var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
Expand Down
3 changes: 2 additions & 1 deletion coordinator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ coordinator_tool:
go build -ldflags "-X scroll-tech/common/version.ZkVersion=${ZK_VERSION}" -o $(PWD)/build/bin/coordinator_tool ./cmd/tool

localsetup: coordinator_api ## Local setup: build coordinator_api, copy config, and setup releases
mkdir -p build/bin/conf
@echo "Copying configuration files..."
cp -r $(PWD)/conf $(PWD)/build/bin/
cp -r $(PWD)/conf/config.json $(PWD)/build/bin/conf/config.template.json
@echo "Setting up releases..."
cd $(PWD)/build && bash setup_releases.sh

Expand Down
3 changes: 2 additions & 1 deletion coordinator/build/setup_releases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [ -z "${SCROLL_ZKVM_VERSION}" ]; then
fi

# set ASSET_DIR by reading from config.json
CONFIG_FILE="bin/conf/config.json"
CONFIG_FILE="bin/conf/config.template.json"
if [ ! -f "$CONFIG_FILE" ]; then
echo "Config file $CONFIG_FILE not found"
exit 1
Expand Down Expand Up @@ -53,6 +53,7 @@ for ((i=0; i<$VERIFIER_COUNT; i++)); do
# assets for verifier-only mode
echo "Downloading assets for $FORK_NAME to $ASSET_DIR..."
wget https://circuit-release.s3.us-west-2.amazonaws.com/scroll-zkvm/releases/$SCROLL_ZKVM_VERSION/verifier/verifier.bin -O ${ASSET_DIR}/verifier.bin
wget https://circuit-release.s3.us-west-2.amazonaws.com/scroll-zkvm/releases/$SCROLL_ZKVM_VERSION/verifier/root_verifier_vk -O ${ASSET_DIR}/root_verifier_vk
wget https://circuit-release.s3.us-west-2.amazonaws.com/scroll-zkvm/releases/$SCROLL_ZKVM_VERSION/verifier/openVmVk.json -O ${ASSET_DIR}/openVmVk.json

echo "Completed downloading assets for $FORK_NAME"
Expand Down
2 changes: 1 addition & 1 deletion coordinator/conf/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"db": {
"driver_name": "postgres",
"dsn": "postgres://localhost/scroll?sslmode=disable",
"dsn": "postgres://dev:dev@localhost/scroll?sslmode=disable",
"maxOpenNum": 200,
"maxIdleNum": 20
},
Expand Down
17 changes: 17 additions & 0 deletions coordinator/internal/logic/libzkp/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,20 @@ func SetDynamicFeature(feats string) {
defer freeCString(cFeats)
C.set_dynamic_feature(cFeats)
}

// UnivTaskCompatibilityFix calls the universal task compatibility fix function
func UnivTaskCompatibilityFix(taskJSON string) (string, error) {
cTaskJSON := goToCString(taskJSON)
defer freeCString(cTaskJSON)

resultPtr := C.univ_task_compatibility_fix(cTaskJSON)
if resultPtr == nil {
return "", fmt.Errorf("univ_task_compatibility_fix failed")
}

// Convert result to Go string and free C memory
result := C.GoString(resultPtr)
C.release_string(resultPtr)

return result, nil
}
Comment on lines +151 to +166
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

🧩 Analysis chain

FFI wrapper looks good; confirm header const-correctness.

Memory handling is correct (free input, release returned). Confirm libzkp.h declares const char* for the parameter.


🏁 Script executed:

#!/bin/bash
# Show the header declaration for univ_task_compatibility_fix
fd -a libzkp.h
rg -n -C2 'univ_task_compatibility_fix' $(fd -a libzkp.h)

Length of output: 197


Change header to use const char for input*

libzkp.h currently declares char* univ_task_compatibility_fix(char* task_json); — update the parameter to const char* task_json (return char* can remain). File: coordinator/internal/logic/libzkp/libzkp.h:60

🤖 Prompt for AI Agents
coordinator/internal/logic/libzkp/lib.go lines 151-166: update the C header
declaration to accept a const char* for the input parameter so it matches the
intended immutable input; open coordinator/internal/logic/libzkp/libzkp.h
(around line 60) and change the function prototype from char*
univ_task_compatibility_fix(char* task_json); to char*
univ_task_compatibility_fix(const char* task_json); then save the header so the
cgo build uses the new signature (no change needed in Go callsite since Go
passes a C string pointer for read-only input).

2 changes: 2 additions & 0 deletions coordinator/internal/logic/libzkp/libzkp.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,7 @@ void release_string(char* string_ptr);

void set_dynamic_feature(const char* feats);

// Universal task compatibility fix function
char* univ_task_compatibility_fix(char* task_json);

#endif /* LIBZKP_H */
8 changes: 8 additions & 0 deletions coordinator/internal/logic/provertask/batch_prover_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ func (bp *BatchProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato
return nil, ErrCoordinatorInternalFailure
}
proverTask.Metadata = metadata

if isCompatibilityFixingVersion(taskCtx.ProverVersion) {
log.Info("Apply compatibility fixing for prover", "version", taskCtx.ProverVersion)
if err := fixCompatibility(taskMsg); err != nil {
log.Error("apply compatibility failure", "err", err)
return nil, ErrCoordinatorInternalFailure
}
}
}

// Store session info.
Expand Down
8 changes: 8 additions & 0 deletions coordinator/internal/logic/provertask/bundle_prover_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ func (bp *BundleProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinat
// bundle proof require snark
taskMsg.UseSnark = true
proverTask.Metadata = metadata

if isCompatibilityFixingVersion(taskCtx.ProverVersion) {
log.Info("Apply compatibility fixing for prover", "version", taskCtx.ProverVersion)
if err := fixCompatibility(taskMsg); err != nil {
log.Error("apply compatibility failure", "err", err)
return nil, ErrCoordinatorInternalFailure
}
}
}

// Store session info.
Expand Down
18 changes: 18 additions & 0 deletions coordinator/internal/logic/provertask/prover_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"gorm.io/gorm"

"scroll-tech/common/types/message"
"scroll-tech/common/version"

"scroll-tech/coordinator/internal/config"
"scroll-tech/coordinator/internal/logic/libzkp"
Expand Down Expand Up @@ -201,6 +202,23 @@ func (b *BaseProverTask) applyUniversal(schema *coordinatorType.GetTaskSchema) (
return schema, []byte(metadata), nil
}

const CompatibilityVersion = "4.5.43"

func isCompatibilityFixingVersion(ver string) bool {
return !version.CheckScrollRepoVersion(ver, CompatibilityVersion)
}

func fixCompatibility(schema *coordinatorType.GetTaskSchema) error {

fixedTask, err := libzkp.UnivTaskCompatibilityFix(schema.TaskData)
if err != nil {
return err
}
schema.TaskData = fixedTask

return nil
}

func newGetTaskCounterVec(factory promauto.Factory, taskType string) *prometheus.CounterVec {
getTaskCounterInitOnce.Do(func() {
getTaskCounterVec = factory.NewCounterVec(prometheus.CounterOpts{
Expand Down
2 changes: 1 addition & 1 deletion coordinator/test/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func setupCoordinator(t *testing.T, proversPerSession uint8, coordinatorURL stri
func setEnv(t *testing.T) {
var err error

version.Version = "v4.4.89"
version.Version = "v4.5.45"

glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.LogfmtFormat()))
glogger.Verbosity(log.LvlInfo)
Expand Down
41 changes: 41 additions & 0 deletions crates/libzkp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,47 @@ pub fn checkout_chunk_task(
Ok(ret)
}

/// Convert the universal task json into compatible form for old prover
pub fn univ_task_compatibility_fix(task_json: &str) -> eyre::Result<String> {
use scroll_zkvm_types::proof::VmInternalStarkProof;

let u_task: tasks::ProvingTask = serde_json::from_str(task_json)?;
let aggregated_proofs: Vec<VmInternalStarkProof> = u_task
.aggregated_proofs
.into_iter()
.map(|proof| VmInternalStarkProof {
proofs: proof.proofs,
public_values: proof.public_values,
})
.collect();

#[derive(Serialize)]
struct CompatibleProvingTask {
/// seralized witness which should be written into stdin first
pub serialized_witness: Vec<Vec<u8>>,
/// aggregated proof carried by babybear fields, should be written into stdin
/// followed `serialized_witness`
pub aggregated_proofs: Vec<VmInternalStarkProof>,
/// Fork name specify
pub fork_name: String,
/// The vk of app which is expcted to prove this task
pub vk: Vec<u8>,
/// An identifier assigned by coordinator, it should be kept identify for the
/// same task (for example, using chunk, batch and bundle hashes)
pub identifier: String,
}

let compatible_u_task = CompatibleProvingTask {
serialized_witness: u_task.serialized_witness,
aggregated_proofs,
fork_name: u_task.fork_name,
vk: u_task.vk,
identifier: u_task.identifier,
};

Ok(serde_json::to_string(&compatible_u_task)?)
}

/// Generate required staff for proving tasks
/// return (pi_hash, metadata, task)
pub fn gen_universal_task(
Expand Down
13 changes: 13 additions & 0 deletions crates/libzkp_c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,19 @@ pub unsafe extern "C" fn gen_wrapped_proof(
}
}

/// # Safety
#[no_mangle]
pub unsafe extern "C" fn univ_task_compatibility_fix(task_json: *const c_char) -> *mut c_char {
let task_json_str = c_char_to_str(task_json);
match libzkp::univ_task_compatibility_fix(task_json_str) {
Ok(result) => CString::new(result).unwrap().into_raw(),
Err(e) => {
tracing::error!("univ_task_compability_fix failed, error: {:#}", e);
std::ptr::null_mut()
}
}
}
Comment on lines +241 to +252
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

🧩 Analysis chain

Const-correctness with C header declaration.

Ensure the C header uses const char* for the parameter to match this implementation.


🏁 Script executed:

#!/bin/bash
# Verify the C declaration is const-correct
rg -n -C2 -P '\buniv_task_compatibility_fix\s*\(' coordinator | sed -n '1,200p'
rg -n -P '\buniv_task_compatibility_fix\s*\(\s*const\s+char\s*\*' || echo "Header may be missing const for parameter"

Length of output: 791


Use const in C header parameter for univ_task_compatibility_fix

coordinator/internal/logic/libzkp/libzkp.h:60 currently has
char* univ_task_compatibility_fix(char* task_json);
Change to
char* univ_task_compatibility_fix(const char* task_json);
to match the Rust signature (task_json: *const c_char).

🤖 Prompt for AI Agents
In crates/libzkp_c/src/lib.rs around lines 241 to 252, the Rust FFI function
accepts a const c_char pointer but the C header declares a non-const char*;
update the C header declaration (coordinator/internal/logic/libzkp/libzkp.h line
~60) to use const char* for the task_json parameter so the signatures match
(char* univ_task_compatibility_fix(char* task_json); -> char*
univ_task_compatibility_fix(const char* task_json);) and then rebuild/regenerate
any C bindings or headers used by the project to ensure consistency.


/// # Safety
#[no_mangle]
pub unsafe extern "C" fn release_string(ptr: *mut c_char) {
Expand Down
3 changes: 2 additions & 1 deletion tests/prover-e2e/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.PHONY: clean setup_db test_tool all check_vars

GOOSE_CMD?=goose

BEGIN_BLOCK?=10973711
END_BLOCK?=10973721

all: setup_db test_tool import_data

Expand Down
16 changes: 15 additions & 1 deletion tests/prover-e2e/prepare/dump_block_records.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
-- Create a file with INSERT statements for the specific records
\o block_export.sql
\o 00100_import_blocks.sql
\t on
\a
-- Write header comment
SELECT '-- +goose Up';
SELECT '-- +goose StatementBegin';
SELECT '';

SELECT 'INSERT INTO l2_block (number, hash, parent_hash, header, withdraw_root,
state_root, tx_num, gas_used, block_timestamp, row_consumption,
chunk_hash, transactions
Expand All @@ -22,6 +27,15 @@ SELECT 'INSERT INTO l2_block (number, hash, parent_hash, header, withdraw_root,
FROM l2_block
WHERE number >= 10973700 and number <= 10973730
ORDER BY number ASC;

-- Write footer
SELECT '';
SELECT '-- +goose StatementEnd';
SELECT '-- +goose Down';
SELECT '-- +goose StatementBegin';
SELECT 'DELETE FROM l2_block;';
SELECT '-- +goose StatementEnd';
Comment on lines +31 to +37
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Limit the Down migration to rows inserted by this script

DELETE FROM l2_block; will wipe the entire table, which is risky even in e2e.

Apply this diff to target the same block range used above:

-SELECT 'DELETE FROM l2_block;';
+SELECT 'DELETE FROM l2_block WHERE number BETWEEN 10973700 AND 10973730;';

If BEGIN_BLOCK/END_BLOCK are parameterized elsewhere, mirror them here to keep Up/Down symmetrical.

🤖 Prompt for AI Agents
In tests/prover-e2e/prepare/dump_block_records.sql around lines 31 to 37, the
Down migration currently does "DELETE FROM l2_block;" which will remove the
entire table; change it to delete only the rows inserted by this script by
adding a WHERE clause that mirrors the same block range used in the Up (e.g.
"WHERE block_number BETWEEN <BEGIN_BLOCK> AND <END_BLOCK>" or whatever parameter
names are used), and if BEGIN_BLOCK/END_BLOCK are parameterized elsewhere,
reference the same parameter names here so the Up and Down are symmetrical and
only target the inserted rows.


\t off
\a
\o
Loading