Skip to content
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

Add build configs for testing #21

Merged
merged 18 commits into from
Oct 2, 2024
Merged
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
/target
.vscode
/examples/cairo-lang/*
/examples/bootloader/starkware/*
/examples/bootloader/gen/*
/examples/bootloader/hidden/*
/examples/bootloader/stone-prover/*
!.gitkeep
50 changes: 47 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,58 @@
FROM rust:1.74.1
FROM ciimage/python:3.9-ci

# install pyenv
RUN curl https://pyenv.run | bash
ENV HOME="/root"
WORKDIR ${HOME}
ENV PYENV_ROOT="${HOME}/.pyenv"
ENV PATH="${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:${PATH}"

# install python 3.9.15
RUN yes | pyenv install 3.9.15 && pyenv global 3.9.15

# install Rust 1.74.1
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN rustup install 1.74.1
RUN rustup default 1.74.1-x86_64-unknown-linux-gnu

# install foundry anvil
RUN curl -L https://foundry.paradigm.xyz | bash
RUN /root/.foundry/bin/foundryup
ENV PATH="/root/.foundry/bin:${PATH}"

WORKDIR /usr/app
# copy the project
RUN mkdir /opt/app
WORKDIR /opt/app
COPY examples ./examples/
COPY Cargo.toml Cargo.lock README.md ./
COPY src ./src/
COPY tests ./tests/

# install required python dependencies
RUN pip install -r examples/bootloader/requirements.txt

# install cairo-lang
WORKDIR /opt/app/examples/bootloader
RUN git clone https://github.com/starkware-libs/cairo-lang.git cairo-lang
RUN cd cairo-lang && git checkout efa9648f57568aad8f8a13fbf027d2de7c63c2c0 && cd ..
RUN cp -r cairo-lang/src/starkware starkware/
RUN rm -rf cairo-lang/
RUN cp hidden/simple-bootloader-utils.py starkware/cairo/bootloaders/simple_bootloader/utils.py
RUN cp hidden/simple-bootloader-objects.py starkware/cairo/bootloaders/simple_bootloader/objects.py
RUN cp hidden/bootloader-utils.py starkware/cairo/bootloaders/bootloader/utils.py
RUN cp hidden/bootloader-objects.py starkware/cairo/bootloaders/bootloader/objects.py

# build the Rust project
WORKDIR /opt/app
RUN cargo install --path .

COPY . .
# generate the annotated proof
WORKDIR /opt/app/examples/bootloader
RUN python3 test_bootloader_fib.py > output.log

# build the verify_stone_proof example
WORKDIR /opt/app
RUN cargo build --example verify_stone_proof

CMD ["sh", "-c", "cargo run --example verify_stone_proof"]
53 changes: 46 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,22 @@ println!("{}", serde_json::to_string_pretty(&split_proofs).unwrap());

Note that the annotated proof file, `annotated_proof.json`, can be generated using this CLI tool.

## CLI
## CLI

### Installation

```bash
cargo install stark_evm_adapter
```

### Usage

```bash
stark_evm_adapter --help
```

To generate an annotated proof based on the outputs of the stone-prover:

```bash
stark_evm_adapter gen-annotated-proof \
--stone-proof-file tests/fixtures/stone_proof.json \
Expand All @@ -53,25 +57,60 @@ stark_evm_adapter gen-annotated-proof \
--output annotated_proof.json
```

Generating an annotated proof requires the proof file from `cpu_air_prover` described [here](https://github.com/starkware-libs/stone-prover/tree/00b274b55c82077184be4c0758f7bed18950eaba#creating-and-verifying-a-proof-of-a-cairozero-program) as well as two annotation files from running `cpu_air_verifier` with `--annotation-file` and `--extra-output-file`:
The annotated proof originates from 3 file outputs of the [stone-prover](https://github.com/starkware-libs/stone-prover/tree/00b274b55c82077184be4c0758f7bed18950eaba#creating-and-verifying-a-proof-of-a-cairozero-program).

* `stark_evm_adapter --stone-proof-file` comes from `cpu_air_prover --out_file` (JSON format)
* `stark_evm_adapter --stone-annotation-file` comes from `cpu_air_verifier --annotation-file` (.txt format)
* `stark_evm_adapter --stone-extra-annotation-file` comes from `cpu_air_verifier --extra-output-file` (.txt format)

Once you have this annotated proof, you can use it to generate the split proofs and submit them to the L1 EVM verifier. Please refer to the [example demo](https://github.com/zksecurity/stark-evm-adapter/blob/8af44a0aa61c89e36a08261320f234709e99ed71/examples/verify_stone_proof.rs#L18)

## DEMO
You can use docker to run the demo. The demo will generate split proofs from an annotated proof and submit them to the L1 EVM verifier.
## Demo

You can run the demo to split the proof and submit it to the Ethereum mainnet verifier. The [existing proof](./examples/bootloader/fib_annotated_proof.json) contains an internal proof that the 10th Fibonacci number is 144.

### Using existing proof

First, install Anvil using [Foundry](https://book.getfoundry.sh/getting-started/installation)

Then, run the following command:

```bash
FORK_URL=<ETHEREUM-MAINNET-RPC> \
ANNOTATED_PROOF=./annotated_proof.json \
FACT_TOPOLOGIES=./fact_topologies.json \
cargo run --example verify_stone_proof
```

### Generate new proof

You can create a new proof using Docker

#### Prerequisites

- Copy `objects.py` and `utils.py` for bootloader as `hidden/bootloader-objects.py` and `hidden/bootloader-utils.py`
- Copy `objects.py` and `utils.py` for simple bootloader as `hidden/simple-bootloader-objects.py` and `hidden/simple-bootloader-utils.py`
- Copy `cpu_air_prover` and `cpu_air_verifier` binaries generated from [stone-prover](https://github.com/starkware-libs/stone-prover) into the `./examples/bootloader/stone-prover` directory (Can also use the binaries from this [release](https://github.com/zksecurity/stark-evm-adapter/releases/tag/v0.1.0-alpha))

#### Customize program that is being proven

- Replace `TASK_PROGRAM_INPUT_PATH` and `TASK_PROGRAM_COMPILED_PATH` variables in `test_bootloader_fib.py` with your own program.

#### Run

First, build the docker image. This will create an annotated proof and a fact topologies file that is needed to split the proof for verifying on Ethereum:

First, build the docker image:
```bash
docker build -t stark-evm-adapter .
```

Then, run the demo script:

```bash
docker run -it -e "MAINNET_RPC=******" stark-evm-adapter
docker run -it -e FORK_URL=<ETHEREUM-MAINNET-RPC> -e ANNOTATED_PROOF=./examples/bootloader/gen/annotated_proof.json -e FACT_TOPOLOGIES=./examples/bootloader/gen/fact_topologies.json stark-evm-adapter
```

Note that you will need to set the environment variable `MAINNET_RPC` to the RPC endpoint of the Ethereum mainnet. For example, you can use [Infura](https://infura.io/) to get the RPC endpoint. This demo code will automatically make a fork of the mainnet and submit the split proofs to the L1 EVM verifier on the forked chain.
### Note

- Alternatively, you can use `URL` instead of `FORK_URL` env to submit transactions on-chain instead of running them on a fork.
- This example verifies proofs on [`0xd51a3d50d4d2f99a345a66971e650eea064dd8df`](https://etherscan.io/address/0xd51a3d50d4d2f99a345a66971e650eea064dd8df), which is the previous version of the verifier on Ethereum. The most recent version is [`0x9fb7F48dCB26b7bFA4e580b2dEFf637B13751942`](https://etherscan.io/address/0x9fb7F48dCB26b7bFA4e580b2dEFf637B13751942), and we are working to update this example to use the most recent version.
Loading