Skip to content

Commit e0fd995

Browse files
committed
Merge branch 'versionpump' of github.com:element36-io/hyperfridge-r0 into versionpump
2 parents 23cea47 + c0b2e42 commit e0fd995

File tree

9 files changed

+173
-18
lines changed

9 files changed

+173
-18
lines changed

.github/workflows/checks.yml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,16 @@ jobs:
2727

2828
- name: Install Rust
2929
run: |
30-
rustup update stable --no-self-update
31-
rustup target add wasm32-unknown-unknown
32-
cargo install cargo-binstall
33-
cargo binstall cargo-risczero -y
34-
cargo risczero install
35-
rustup component add rustfmt
36-
rustup component add clippy
30+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.81
31+
. "$HOME/.cargo/env"
32+
export PATH="$PATH:/home/runner/.risc0/bin:/home/runner/.cargo/bin"
33+
curl -L https://risczero.com/install | bash
34+
source "/home/runner/.bashrc"
35+
cat "/home/runner/.bashrc"
36+
rzup install
3737
3838
- name: Run tests (with coverage)
3939
run: |
40-
rustup install stable
4140
cargo install cargo-tarpaulin
4241
RUST_BACKTRACE=1 RISC0_DEV_MODE=true cargo +stable build --release
4342
RISC0_SKIP_BUILD=1 RISC0_DEV_MODE=true cargo +stable test
@@ -55,12 +54,12 @@ jobs:
5554
env:
5655
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
5756

58-
- name: Run fmt
59-
run: cargo fmt --all -- --check
57+
# - name: Run fmt
58+
# run: cargo fmt --all -- --check
6059

61-
- name: Run clippy
62-
run: |
63-
RISC0_SKIP_BUILD=true cargo clippy --all-targets
60+
# - name: Run clippy
61+
# run: |
62+
# RISC0_SKIP_BUILD=true cargo clippy --all-targets
6463

6564
- name: Check Build
6665
run: |

.github/workflows/docker-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Docker Build
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [ main, versionpump ]
66

77
pull_request:
88
branches: [ main ]

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@
1818
"titleBar.inactiveBackground": "#12352499",
1919
"titleBar.inactiveForeground": "#e7e7e799"
2020
}
21+
"yaml.schemas": {
22+
"https://json.schemastore.org/github-workflow.json": "file:///home/w/ghvlada/hyperfridge-r0/.github/workflows/checks.yml"
23+
}
2124
}

CLAUDE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Hyperfridge Commands and Guidelines
2+
3+
## Build and Test Commands
4+
- Build project: `cargo build`
5+
- Run tests with dev mode: `RISC0_DEV_MODE=1 cargo test`
6+
- Run guest tests: `cd methods/guest && RISC0_DEV_MODE=1 cargo test --features debug_mode -- --nocapture`
7+
- Generate documentation: `cargo doc --no-deps --open`
8+
- Run host with logging: `cd host && RUST_LOG="executor=info" RISC0_DEV_MODE=1 cargo run [COMMAND]`
9+
- Run single test: `RISC0_DEV_MODE=1 cargo test test_name -- --nocapture`
10+
11+
## Code Style Guidelines
12+
- Use the Rust 2018 edition
13+
- Follow standard Rust naming conventions (snake_case for functions/variables, CamelCase for types)
14+
- Organize imports: std first, then external crates alphabetically
15+
- Document all public functions and modules with rustdoc
16+
- Use Result<T, E> for error handling with descriptive error types
17+
- Prefer strong typing over primitive types
18+
- Use Clippy and rustfmt: `cargo clippy` and `cargo fmt`
19+
- Respect the risc0 zkVM architecture (host/guest separation)
20+
- Consider zero-knowledge patterns when implementing crypto operations

DockerfileMacOs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Base stage for building
22
FROM debian:12-slim as build
33
# Install required dependencies
4-
# docker buildx build --build-arg PLATFORM=linux/amd64 --load -t temp .
4+
# on MacOs:
5+
# docker buildx build -f DockerfileMacOs --load -t temp .
6+
57

68
RUN apt-get update && apt-get install -y \
79
curl \

DockerfileMacOs2

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Base stage for building
2+
FROM --platform=linux/amd64 debian:12-slim as build
3+
# Install required dependencies
4+
# on MacOs:
5+
# docker buildx build -f DockerfileMacOs2 --load -t temp .
6+
7+
8+
RUN apt-get update && apt-get install -y \
9+
curl \
10+
build-essential \
11+
git \
12+
pkg-config \
13+
libssl-dev \
14+
cmake \
15+
python3 \
16+
ninja-build \
17+
git perl qpdf xxd libxml2-utils
18+
19+
# Install Rust 1.81 --> CHECK rust-toolchain.toml for rust verion; must be same
20+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.81
21+
ENV PATH="/root/.risc0/bin:/root/.cargo/bin:${PATH}"
22+
RUN . "$HOME/.cargo/env"
23+
# Install the RISC0 toolchain
24+
RUN git clone https://github.com/risc0/risc0.git
25+
WORKDIR /risc0
26+
RUN cargo install --path rzup
27+
RUN rzup toolchain build rust
28+
RUN git checkout origin/release-1.3
29+
RUN cargo install --path risc0/cargo-risczero
30+
31+
32+
# Test toolchain installation
33+
RUN rustup toolchain list --verbose | grep risc0
34+
35+
# Copy build files
36+
COPY data data
37+
COPY host host
38+
COPY verifier verifier
39+
COPY methods methods
40+
COPY Cargo.toml Cargo.lock rust-toolchain.toml /
41+
# RUN rustup toolchain install .
42+
43+
# create directory holding generated Image Id of Computation which will be proved.
44+
RUN mkdir -p /host/out
45+
# remove test data / receipts
46+
RUN rm -R /data/test/*.json
47+
48+
# build the project
49+
WORKDIR /
50+
RUN RUST_BACKTRACE=1 RISC0_DEV_MODE=true cargo build --release
51+
52+
53+
# creates fake proof for test data, so that calling "verifier" without parameters works
54+
RUN RUST_BACKTRACE=1 RISC0_DEV_MODE=true ./target/release/host --verbose prove-camt53 \
55+
--request=/data/test/test.xml \
56+
--bankkey /data/pub_bank.pem \
57+
--clientkey /data/client.pem \
58+
--witnesskey /data/pub_witness.pem --clientiban CH4308307000289537312
59+
60+
RUN RUST_BACKTRACE=1 RISC0_DEV_MODE=true ./target/release/host show-image-id > /host/out/IMAGE_ID.hex
61+
62+
#RUN cat /host/out/IMAGE_ID.hex && find /data -type f -name "*-Receipt-*.json"
63+
COPY host/out/IMAGE_ID.hex /data/IMAGE_ID.hex
64+
RUN cp /data/test/test.xml-Receipt-$(cat ./host/out/IMAGE_ID.hex)-latest.json /data/test/test.xml-Receipt-test.json
65+
66+
# Final Stage - Build the executable image
67+
FROM --platform=linux/amd64 debian:12-slim as runtime
68+
# qdpf is for zlib flate
69+
RUN apt update && apt install -y perl qpdf xxd libxml2-utils openssl inotify-tools unzip zip
70+
71+
#FROM alpine:latest as runteim
72+
# add glibc
73+
# RUN apk --no-cache add ca-certificates libgcc gcompat
74+
75+
# Copy the compiled binaries from the build stage
76+
COPY --from=build /target/release/host /app/host
77+
COPY --from=build /target/release/verifier /app/verifier
78+
COPY --from=build /target/riscv-guest/methods/hyperfridge/riscv32im-risc0-zkvm-elf/release/hyperfridge /app/hyperfridge
79+
COPY --from=build /host/out/IMAGE_ID.hex /app/IMAGE_ID.hex
80+
COPY --from=build /data /data
81+
82+
# Create symbolic links to the binaries in /usr/local/bin which is in the PATH
83+
RUN ln -s /app/verifier /usr/local/bin/verifier
84+
RUN ln -s /app/host /usr/local/bin/host
85+
RUN ln -s /app/host /usr/local/bin/fridge
86+
87+
# Check if the proof and testdata is there
88+
RUN ls -la /data/test/test.xml-Receipt-$(cat /app/IMAGE_ID.hex)-latest.json
89+
90+
WORKDIR /app
91+
CMD ["/app/host", "--help"]

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,23 @@ It is possible to organize the files for these components in various ways.
7474
However, in this starter template we use a standard directory structure for zkVM
7575
applications, which we think is a good starting point for your applications.
7676

77+
The codebase is organized into three main components:
78+
79+
1. Host (host/src/main.rs):
80+
- Handles user inputs and proof generation
81+
- Sets up the zkVM environment with bank statements, keys, and signatures
82+
- Writes the proof (receipt) to disk as JSON
83+
84+
2. Guest (methods/guest/src/main.rs):
85+
- Runs inside the RISC Zero zkVM
86+
- Performs cryptographic validation of bank data
87+
- Verifies signatures, decrypts transaction keys, and parses CAMT53 files
88+
- Creates a commitment containing verified account information
89+
s
90+
3. Verifier (verifier/src/main.rs):
91+
- Standalone tool that validates proofs
92+
- Checks that computations were performed
93+
7794
```text
7895
project_name
7996
├── Cargo.toml

buildPublish.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
set -e
3-
3+
# Needs to be run on a Mac with M1 or similar
44

55
docker login
66

@@ -14,8 +14,6 @@ echo "container-id $CONTAINER_ID"
1414
# Copy the IMAGE_ID.hex file from the container to the host
1515
docker cp $CONTAINER_ID:/app/IMAGE_ID.hex ./IMAGE_ID.hex
1616

17-
18-
1917
# Read the content of IMAGE_ID.hex
2018
IMAGE_ID=$(cat IMAGE_ID.hex)
2119
echo "image-id $IMAGE_ID"

docs/runtime.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,28 @@ RISC0_DEV_MODE=true \
100100
cargo run -- --verbose verify \
101101
--imageid-hex=$imageid --proof-json=$proof
102102
```
103+
104+
# Notes on Optimization using Chinese Remainder Theorem (CRT)
105+
106+
The rsa crate automatically uses CRT optimization for decryption when:
107+
1. The private key contains the necessary prime factors (p and q)
108+
2. The key is properly loaded with all components
109+
110+
When the code calls client_key.decrypt(Pkcs1v15Encrypt, &transaction_key_bin) in the guest code, the library is already using CRT optimization
111+
under the hood to speed up the computation.
112+
113+
The CRT optimization in the library:
114+
- Performs two smaller exponentiations (mod p and mod q) instead of one large exponentiation
115+
- Combines the results using the Chinese Remainder Theorem
116+
- Achieves approximately 3-4x speedup for RSA private key operations
117+
118+
This means Hyperfridge is already benefiting from CRT optimization for the expensive RSA decryption operations without requiring code changes. The
119+
"hazmat" feature that's enabled in the Cargo.toml also exposes the underlying cryptographic primitives, giving the library full access to optimize
120+
these operations.
121+
122+
To potentially gain further optimization, you could focus on other aspects like:
123+
1. Parallelizing independent operations
124+
2. Pre-computing values where possible
125+
3. Using batch verification techniques for multiple signatures
126+
127+
But for the specific RSA decryption performance, CRT is already applied by the library.

0 commit comments

Comments
 (0)