Skip to content

Commit 19ca180

Browse files
feat(operator): bump risc0 and sp1 versions (#1324)
Co-authored-by: Marcos Nicolau <[email protected]>
1 parent c69a172 commit 19ca180

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+13033
-2909
lines changed

.github/workflows/build-and-test-go.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ jobs:
2727
cache: false
2828
- name: Build SP1 bindings
2929
run: make build_sp1_linux
30+
- name: Build Old SP1 bindings
31+
run: make build_sp1_linux_old
3032
- name: Build Risc Zero go bindings
3133
run: make build_risc_zero_linux
34+
- name: Build Old Risc Zero go bindings
35+
run: make build_risc_zero_linux_old
3236
- name: Build Merkle Tree bindings
3337
run: make build_merkle_tree_linux
3438
- name: Build operator
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: test-risc-zero-old
2+
3+
on:
4+
merge_group:
5+
push:
6+
branches: [main]
7+
pull_request:
8+
branches: ["*"]
9+
paths:
10+
- "operator/risc_zero_old/**"
11+
- ".github/workflows/test-risc-zero-old.yml"
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Clear device space
18+
run: |
19+
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
20+
sudo rm -rf /usr/local/lib/android
21+
sudo rm -rf /opt/ghc
22+
sudo rm -rf /usr/local/.ghcup
23+
sudo rm -rf /usr/share/dotnet
24+
sudo rm -rf /opt/ghc
25+
sudo rm -rf "/usr/local/share/boost"
26+
- uses: actions/checkout@v4
27+
- uses: actions/setup-go@v5
28+
with:
29+
go-version: "1.22"
30+
cache: false
31+
- uses: actions-rs/toolchain@v1
32+
with:
33+
toolchain: stable
34+
- name: Test Old Risc Zero Rust
35+
run: make test_risc_zero_rust_ffi_old
36+
- name: Test Old Risc Zero go bindings
37+
run: make test_risc_zero_go_bindings_linux_old

.github/workflows/test-sp1-old.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: test-sp1-old
2+
3+
on:
4+
merge_group:
5+
push:
6+
branches: [main]
7+
pull_request:
8+
branches: ["*"]
9+
paths:
10+
- 'operator/sp1_old/**'
11+
- '.github/workflows/test-sp1-old.yml'
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-go@v5
19+
with:
20+
go-version: '1.22'
21+
cache: false
22+
- uses: actions-rs/toolchain@v1
23+
with:
24+
toolchain: stable
25+
- name: Test Old SP1 Rust
26+
run: make test_sp1_rust_ffi_old
27+
- name: Test Old SP1 go bindings
28+
run: make test_sp1_go_bindings_linux_old

Makefile

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ifeq ($(OS),Darwin)
1717
endif
1818

1919
ifeq ($(OS),Linux)
20-
LD_LIBRARY_PATH += $(CURDIR)/operator/risc_zero/lib
20+
LD_LIBRARY_PATH+=$(CURDIR)/operator/risc_zero_old/lib:$(CURDIR)/operator/risc_zero/lib
2121
endif
2222

2323
ifeq ($(OS),Linux)
@@ -513,11 +513,11 @@ build_binaries:
513513
__SP1_FFI__: ##
514514
build_sp1_macos:
515515
@cd operator/sp1/lib && cargo build $(RELEASE_FLAG)
516-
@cp operator/sp1/lib/target/$(TARGET_REL_PATH)/libsp1_verifier_ffi.dylib operator/sp1/lib/libsp1_verifier.dylib
516+
@cp operator/sp1/lib/target/$(TARGET_REL_PATH)/libsp1_verifier_ffi.dylib operator/sp1/lib/libsp1_verifier_ffi.dylib
517517

518518
build_sp1_linux:
519519
@cd operator/sp1/lib && cargo build $(RELEASE_FLAG)
520-
@cp operator/sp1/lib/target/$(TARGET_REL_PATH)/libsp1_verifier_ffi.so operator/sp1/lib/libsp1_verifier.so
520+
@cp operator/sp1/lib/target/$(TARGET_REL_PATH)/libsp1_verifier_ffi.so operator/sp1/lib/libsp1_verifier_ffi.so
521521

522522
test_sp1_rust_ffi:
523523
@echo "Testing SP1 Rust FFI source code..."
@@ -542,6 +542,25 @@ generate_risc_zero_empty_journal_proof:
542542
@cd scripts/test_files/risc_zero/no_public_inputs && RUST_LOG=info cargo run --release
543543
@echo "Fibonacci proof and ELF with empty journal generated in scripts/test_files/risc_zero/no_public_inputs folder"
544544

545+
build_sp1_macos_old:
546+
@cd operator/sp1_old/lib && cargo build $(RELEASE_FLAG)
547+
@cp operator/sp1_old/lib/target/$(TARGET_REL_PATH)/libsp1_verifier_old_ffi.dylib operator/sp1_old/lib/libsp1_verifier_old_ffi.dylib
548+
549+
build_sp1_linux_old:
550+
@cd operator/sp1_old/lib && cargo build $(RELEASE_FLAG)
551+
@cp operator/sp1_old/lib/target/$(TARGET_REL_PATH)/libsp1_verifier_old_ffi.so operator/sp1_old/lib/libsp1_verifier_old_ffi.so
552+
553+
test_sp1_rust_ffi_old:
554+
@echo "Testing SP1 Rust FFI source code..."
555+
@cd operator/sp1_old/lib && RUST_MIN_STACK=83886080 cargo t --release
556+
557+
test_sp1_go_bindings_macos_old: build_sp1_macos_old
558+
@echo "Testing SP1 Go bindings..."
559+
go test ./operator/sp1_old/... -v
560+
561+
test_sp1_go_bindings_linux_old: build_sp1_linux_old
562+
@echo "Testing SP1 Go bindings..."
563+
go test ./operator/sp1_old/... -v
545564

546565
__RISC_ZERO_FFI__: ##
547566
build_risc_zero_macos:
@@ -569,6 +588,27 @@ generate_risc_zero_fibonacci_proof:
569588
RUST_LOG=info cargo run --release && \
570589
echo "Fibonacci proof, pub input and image ID generated in scripts/test_files/risc_zero folder"
571590

591+
build_risc_zero_macos_old:
592+
@cd operator/risc_zero_old/lib && cargo build $(RELEASE_FLAG)
593+
@cp operator/risc_zero_old/lib/target/$(TARGET_REL_PATH)/librisc_zero_verifier_old_ffi.dylib operator/risc_zero_old/lib/librisc_zero_verifier_old_ffi.dylib
594+
595+
build_risc_zero_linux_old:
596+
@cd operator/risc_zero_old/lib && cargo build $(RELEASE_FLAG)
597+
@cp operator/risc_zero_old/lib/target/$(TARGET_REL_PATH)/librisc_zero_verifier_old_ffi.so operator/risc_zero_old/lib/librisc_zero_verifier_old_ffi.so
598+
599+
test_risc_zero_rust_ffi_old:
600+
@echo "Testing RISC Zero Rust FFI source code..."
601+
@cd operator/risc_zero_old/lib && cargo test --release
602+
603+
test_risc_zero_go_bindings_macos_old: build_risc_zero_macos_old
604+
@echo "Testing RISC Zero Go bindings..."
605+
go test ./operator/risc_zero_old/... -v
606+
607+
test_risc_zero_go_bindings_linux_old: build_risc_zero_linux_old
608+
@echo "Testing RISC Zero Go bindings..."
609+
go test ./operator/risc_zero_old/... -v
610+
611+
572612
__MERKLE_TREE_FFI__: ##
573613
build_merkle_tree_macos:
574614
@cd operator/merkle_tree/lib && cargo build $(RELEASE_FLAG)
@@ -607,13 +647,17 @@ build_all_ffi_macos: ## Build all FFIs for macOS
607647
@echo "Building all FFIs for macOS..."
608648
@$(MAKE) build_sp1_macos
609649
@$(MAKE) build_risc_zero_macos
650+
@$(MAKE) build_sp1_macos_old
651+
@$(MAKE) build_risc_zero_macos_old
610652
@$(MAKE) build_merkle_tree_macos
611653
@echo "All macOS FFIs built successfully."
612654

613655
build_all_ffi_linux: ## Build all FFIs for Linux
614656
@echo "Building all FFIs for Linux..."
615657
@$(MAKE) build_sp1_linux
616658
@$(MAKE) build_risc_zero_linux
659+
@$(MAKE) build_sp1_linux_old
660+
@$(MAKE) build_risc_zero_linux_old
617661
@$(MAKE) build_merkle_tree_linux
618662
@echo "All Linux FFIs built successfully."
619663

operator/pkg/operator.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ import (
1818
"github.com/ethereum/go-ethereum/crypto"
1919
"github.com/urfave/cli/v2"
2020
"github.com/yetanotherco/aligned_layer/operator/risc_zero"
21+
"github.com/yetanotherco/aligned_layer/operator/risc_zero_old"
2122
"golang.org/x/crypto/sha3"
2223

2324
"github.com/prometheus/client_golang/prometheus"
2425
"github.com/yetanotherco/aligned_layer/metrics"
2526

2627
"github.com/yetanotherco/aligned_layer/operator/sp1"
28+
"github.com/yetanotherco/aligned_layer/operator/sp1_old"
2729

2830
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
2931
"github.com/Layr-Labs/eigensdk-go/logging"
@@ -518,15 +520,28 @@ func (o *Operator) verify(verificationData VerificationData, disabledVerifiersBi
518520

519521
case common.SP1:
520522
verificationResult, err := sp1.VerifySp1Proof(verificationData.Proof, verificationData.VmProgramCode)
523+
if !verificationResult {
524+
o.Logger.Infof("SP1 proof verification failed. Trying old SP1 version...")
525+
verificationResult, err = sp1_old.VerifySp1ProofOld(verificationData.Proof, verificationData.VmProgramCode)
526+
if !verificationResult {
527+
o.Logger.Errorf("Old SP1 proof verification failed")
528+
}
529+
}
530+
o.Logger.Infof("SP1 proof verification result: %t", verificationResult)
521531
o.handleVerificationResult(results, verificationResult, err, "SP1 proof verification")
522532

523533
case common.Risc0:
524534
verificationResult, err := risc_zero.VerifyRiscZeroReceipt(verificationData.Proof,
525535
verificationData.VmProgramCode, verificationData.PubInput)
526-
o.handleVerificationResult(results, verificationResult, err, "RiscZero proof verification")
527-
536+
if !verificationResult {
537+
o.Logger.Infof("Risc0 proof verification failed. Trying old Risc0 version...")
538+
verificationResult, err = risc_zero_old.VerifyRiscZeroReceiptOld(verificationData.Proof, verificationData.VmProgramCode, verificationData.PubInput)
539+
if !verificationResult {
540+
o.Logger.Errorf("Old Risc0 proof verification failed")
541+
}
542+
}
528543
o.Logger.Infof("Risc0 proof verification result: %t", verificationResult)
529-
results <- verificationResult
544+
o.handleVerificationResult(results, verificationResult, err, "Risc0 proof verification")
530545
default:
531546
o.Logger.Error("Unrecognized proving system ID")
532547
results <- false

operator/risc_zero/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
lib/librisc_zero_verifier_ffi.a
1+
lib/librisc_zero_verifier_ffi.so
22
lib/librisc_zero_verifier_ffi.dylib

0 commit comments

Comments
 (0)