From 56c1d56646ed650375c5baf9773a68f9126114b8 Mon Sep 17 00:00:00 2001 From: agnik Date: Thu, 3 Oct 2024 15:19:37 +0530 Subject: [PATCH] init --- .github/workflows/release-fedora.yml | 78 ++++++++++++++++++++++++++++ Dockerfile.fedora | 77 +++++++++++++++++++++++++++ stone-prover.spec | 33 ++++++++++++ 3 files changed, 188 insertions(+) create mode 100644 .github/workflows/release-fedora.yml create mode 100644 Dockerfile.fedora create mode 100644 stone-prover.spec diff --git a/.github/workflows/release-fedora.yml b/.github/workflows/release-fedora.yml new file mode 100644 index 0000000..f0c65a3 --- /dev/null +++ b/.github/workflows/release-fedora.yml @@ -0,0 +1,78 @@ +name: Release Stone Prover for Fedora + +on: + push: + tags: + - 'v*.*.*' + +jobs: + build: + runs-on: ubuntu-latest + env: + TARGET_ARCH: x86_64 + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Build Docker image (Fedora) + run: | + docker buildx build --target test --file Dockerfile.fedora --load -t stone-prover-fedora-test . + + - name: Extract binaries from Docker image + run: | + docker create --name temp stone-prover-fedora-test + docker cp temp:/usr/bin/cpu_air_prover ./cpu_air_prover-${TARGET_ARCH} + docker cp temp:/usr/bin/cpu_air_verifier ./cpu_air_verifier-${TARGET_ARCH} + docker rm temp + + - name: Run tests in Fedora container + run: | + docker run --rm stone-prover-fedora-test /bin/bash -c " + bazelisk test //... && + cd /app/e2e_test/CairoZero && + cairo-compile fibonacci.cairo --output fibonacci_compiled.json --proof_mode && + cairo-run --program=fibonacci_compiled.json --layout=small --program_input=fibonacci_input.json --air_public_input=fibonacci_public_input.json --air_private_input=fibonacci_private_input.json --trace_file=fibonacci_trace.json --memory_file=fibonacci_memory.json --min_steps=512 --print_output --proof_mode && + cpu_air_prover --out_file=fibonacci_proof.json --private_input_file=fibonacci_private_input.json --public_input_file=fibonacci_public_input.json --prover_config_file=cpu_air_prover_config.json --parameter_file=cpu_air_params.json && + cpu_air_verifier --in_file=fibonacci_proof.json && echo 'Successfully verified example proof.' + " + + - name: Set version output + id: vars + run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT + + - name: Build target Docker image (Fedora) + run: | + docker buildx build --target target --file Dockerfile.fedora --load -t stone-prover-fedora . + + - name: Package RPM inside Fedora container + run: | + docker run --rm -v $(pwd):/rpmbuild/SOURCES stone-prover-fedora \ + bash -c "dnf install -y rpm-build && \ + mkdir -p /rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} && \ + cp /rpmbuild/SOURCES/stone-prover.spec /rpmbuild/SPECS/ && \ + rpmbuild -ba /rpmbuild/SPECS/stone-prover.spec \ + --define \"version ${{ steps.vars.outputs.tag }}\" \ + --define \"_topdir /rpmbuild\"" + + - name: Rename RPM package + run: | + mv ./RPMS/x86_64/*.rpm ./stone-prover-fedora-${TARGET_ARCH}.rpm + + - name: Verify file existence + run: | + ls -la ./ + ls -la ./RPMS/x86_64/ + + - name: Upload files to GitHub release + uses: softprops/action-gh-release@v2 + with: + files: | + ./cpu_air_prover-${TARGET_ARCH} + ./cpu_air_verifier-${TARGET_ARCH} + ./stone-prover-fedora-${TARGET_ARCH}.rpm + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/Dockerfile.fedora b/Dockerfile.fedora new file mode 100644 index 0000000..53c29e6 --- /dev/null +++ b/Dockerfile.fedora @@ -0,0 +1,77 @@ +# Stage 1: Build +FROM fedora:latest AS build + +WORKDIR /app + +# Install dependencies +RUN dnf update -y && dnf install -y \ + gcc gcc-c++ make python3-pip wget git \ + elfutils-libelf-devel gmp-devel python3-devel \ + elfutils-devel clang libstdc++-devel libcxx libcxx-devel \ + ncurses-compat-libs cairo-devel \ + && dnf clean all \ + && rm -rf /var/cache/dnf +RUN pip install cpplint pytest numpy sympy==1.12.1 cairo-lang==0.12.0 + +# Install Bazelisk +RUN wget https://github.com/bazelbuild/bazelisk/releases/download/v1.20.0/bazelisk-linux-amd64 \ + && chmod +x bazelisk-linux-amd64 \ + && mv bazelisk-linux-amd64 /usr/local/bin/bazelisk + +COPY . . + +# Build +RUN bazelisk build //... --disk_cache=/tmp/bazel-disk-cache --cxxopt='-std=c++17' + + +# Stage 2: Test +FROM build AS test + +# Run tests +RUN bazelisk test //... + +# Copy cpu_air_prover and cpu_air_verifier +RUN ln -s /app/build/bazelbin/src/starkware/main/cpu/cpu_air_prover /bin/cpu_air_prover +RUN ln -s /app/build/bazelbin/src/starkware/main/cpu/cpu_air_verifier /bin/cpu_air_verifier + +# End to end test +WORKDIR /app/e2e_test/CairoZero + +RUN cairo-compile fibonacci.cairo --output fibonacci_compiled.json --proof_mode + +RUN cairo-run \ + --program=fibonacci_compiled.json \ + --layout=small \ + --program_input=fibonacci_input.json \ + --air_public_input=fibonacci_public_input.json \ + --air_private_input=fibonacci_private_input.json \ + --trace_file=fibonacci_trace.json \ + --memory_file=fibonacci_memory.json \ + --min_steps=512 \ + --print_output \ + --proof_mode + +RUN cpu_air_prover \ + --out_file=fibonacci_proof.json \ + --private_input_file=fibonacci_private_input.json \ + --public_input_file=fibonacci_public_input.json \ + --prover_config_file=cpu_air_prover_config.json \ + --parameter_file=cpu_air_params.json + +RUN cpu_air_verifier --in_file=fibonacci_proof.json && echo "Successfully verified example proof." + +# Stage 3: Target Image +FROM fedora:latest AS target + +# Copy necessary binaries +COPY --from=build /app/build/bazelbin/src/starkware/main/cpu/cpu_air_prover /usr/bin/ +COPY --from=build /app/build/bazelbin/src/starkware/main/cpu/cpu_air_verifier /usr/bin/ +COPY --from=build /usr/local/bin/bazelisk /usr/local/bin/ + +# Install necessary runtime dependencies +RUN dnf update -y && dnf install -y \ + elfutils-libelf gmp libstdc++ \ + && dnf clean all \ + && rm -rf /var/cache/dnf + +ENTRYPOINT ["/bin/bash"] \ No newline at end of file diff --git a/stone-prover.spec b/stone-prover.spec new file mode 100644 index 0000000..b8285a3 --- /dev/null +++ b/stone-prover.spec @@ -0,0 +1,33 @@ +Name: stone-prover +Version: %{version} +Release: 1%{?dist} +Summary: High-performance proof verification tool + +License: MIT +URL: https://github.com/baking-bad/stone-prover +Source0: %{name}-%{version}.tar.gz + +BuildRequires: gcc gcc-c++ make bazel python3-devel gmp-devel elfutils-libelf-devel +Requires: python3 python3-numpy python3-sympy gmp elfutils-libelf + +%description +Stone-prover is a high-performance proof verification tool. + +%prep +%autosetup -n %{name}-%{version} + +%build +./build.sh + +%install +mkdir -p %{buildroot}%{_bindir} +install -m 755 bazelbin/src/starkware/main/cpu/cpu_air_prover %{buildroot}%{_bindir}/cpu_air_prover +install -m 755 bazelbin/src/starkware/main/cpu/cpu_air_verifier %{buildroot}%{_bindir}/cpu_air_verifier + +%files +%{_bindir}/cpu_air_prover +%{_bindir}/cpu_air_verifier + +%changelog +* Wed Oct 02 2024 Your Name - %{version}-1 +- Initial RPM package for stone-prover. \ No newline at end of file