Skip to content

Commit

Permalink
Merge pull request #5 from kroma-network/feat/split-operator-worker-s…
Browse files Browse the repository at this point in the history
…hard

feat: separate shard proof generation logic into operator and worker logic
  • Loading branch information
dongchangYoo authored Aug 8, 2024
2 parents dd032eb + d2a17f9 commit 1bdcd07
Show file tree
Hide file tree
Showing 723 changed files with 153,216 additions and 123 deletions.
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [
"recursion/program",
"sdk",
"zkvm/*",
"examples/fibonacci/script",
]
exclude = ["examples/target"]
resolver = "2"
Expand Down
3 changes: 2 additions & 1 deletion core/src/utils/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::env;

use crate::runtime::{SplitOpts, DEFERRED_SPLIT_THRESHOLD};

const DEFAULT_SHARD_SIZE: usize = 1 << 22;
// const DEFAULT_SHARD_SIZE: usize = 1 << 22;
const DEFAULT_SHARD_SIZE: usize = 128;
const DEFAULT_SHARD_BATCH_SIZE: usize = 16;
const DEFAULT_COMMIT_STREAM_CAPACITY: usize = 1;
const DEFAULT_PROVE_STREAM_CAPACITY: usize = 1;
Expand Down
4 changes: 2 additions & 2 deletions core/src/utils/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ where
Ok(proof)
}

fn trace_checkpoint(
pub fn trace_checkpoint(
program: Program,
file: &File,
opts: SP1CoreOpts,
Expand All @@ -513,7 +513,7 @@ fn trace_checkpoint(
(events, runtime.report)
}

fn reset_seek(file: &mut File) {
pub fn reset_seek(file: &mut File) {
file.seek(std::io::SeekFrom::Start(0))
.expect("failed to seek to start of tempfile");
}
Expand Down
16 changes: 16 additions & 0 deletions examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions examples/fibonacci/contracts/.github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: test

on: workflow_dispatch

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test
15 changes: 15 additions & 0 deletions examples/fibonacci/contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Compiler files
cache/
out/

# Ignores development broadcast logs
/broadcast
/broadcast/*/11155111/
/broadcast/*/31337/
/broadcast/**/dry-run/

# Docs
docs/

# Dotenv file
.env
61 changes: 61 additions & 0 deletions examples/fibonacci/contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# SP1 Project Template Contracts

This is a template for writing a contract that uses verification of [SP1](https://github.com/succinctlabs/sp1) PlonK proofs onchain using the [SP1VerifierGateway](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/src/SP1VerifierGateway.sol).

## Requirements

- [Foundry](https://book.getfoundry.sh/getting-started/installation)

## Test

```sh
forge test -v
```

## Deployment

#### Step 1: Set the `VERIFIER` environment variable

Find the address of the `verifer` to use from the [deployments](https://github.com/succinctlabs/sp1-contracts/tree/main/contracts/deployments) list for the chain you are deploying to. Set it to the `VERIFIER` environment variable, for example:

```sh
VERIFIER=0x3B6041173B80E77f038f3F2C0f9744f04837185e
```

Note: you can use either the [SP1VerifierGateway](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/src/SP1VerifierGateway.sol) or a specific version, but it is highly recommended to use the gateway as this will allow you to use different versions of SP1.

#### Step 2: Set the `PROGRAM_VKEY` environment variable

Find your program verification key by going into the `../script` directory and running `RUST_LOG=info cargo run --package fibonacci-script --bin vkey --release`, which will print an output like:

> Program Verification Key: 0x00620892344c310c32a74bf0807a5c043964264e4f37c96a10ad12b5c9214e0e
Then set the `PROGRAM_VKEY` environment variable to the output of that command, for example:

```sh
PROGRAM_VKEY=0x00620892344c310c32a74bf0807a5c043964264e4f37c96a10ad12b5c9214e0e
```

#### Step 3: Deploy the contract

Fill out the rest of the details needed for deployment:

```sh
RPC_URL=...
```

```sh
PRIVATE_KEY=...
```

Then deploy the contract to the chain:

```sh
forge create src/Fibonacci.sol:Fibonacci --rpc-url $RPC_URL --private-key $PRIVATE_KEY --constructor-args $VERIFIER $PROGRAM_VKEY
```

It can also be a good idea to verify the contract when you deploy, in which case you would also need to set `ETHERSCAN_API_KEY`:

```sh
forge create src/Fibonacci.sol:Fibonacci --rpc-url $RPC_URL --private-key $PRIVATE_KEY --constructor-args $VERIFIER $PROGRAM_VKEY --verify --verifier etherscan --etherscan-api-key $ETHERSCAN_API_KEY
```
7 changes: 7 additions & 0 deletions examples/fibonacci/contracts/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
fs_permissions = [{ access = "read-write", path = "./" }]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
1 change: 1 addition & 0 deletions examples/fibonacci/contracts/lib/forge-std/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/Vm.sol linguist-generated
128 changes: 128 additions & 0 deletions examples/fibonacci/contracts/lib/forge-std/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: CI

on:
workflow_dispatch:
pull_request:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Print forge version
run: forge --version

# Backwards compatibility checks:
# - the oldest and newest version of each supported minor version
# - versions with specific issues
- name: Check compatibility with latest
if: always()
run: |
output=$(forge build --skip test)
if echo "$output" | grep -q "Warning"; then
echo "$output"
exit 1
fi
- name: Check compatibility with 0.8.0
if: always()
run: |
output=$(forge build --skip test --use solc:0.8.0)
if echo "$output" | grep -q "Warning"; then
echo "$output"
exit 1
fi
- name: Check compatibility with 0.7.6
if: always()
run: |
output=$(forge build --skip test --use solc:0.7.6)
if echo "$output" | grep -q "Warning"; then
echo "$output"
exit 1
fi
- name: Check compatibility with 0.7.0
if: always()
run: |
output=$(forge build --skip test --use solc:0.7.0)
if echo "$output" | grep -q "Warning"; then
echo "$output"
exit 1
fi
- name: Check compatibility with 0.6.12
if: always()
run: |
output=$(forge build --skip test --use solc:0.6.12)
if echo "$output" | grep -q "Warning"; then
echo "$output"
exit 1
fi
- name: Check compatibility with 0.6.2
if: always()
run: |
output=$(forge build --skip test --use solc:0.6.2)
if echo "$output" | grep -q "Warning"; then
echo "$output"
exit 1
fi
# via-ir compilation time checks.
- name: Measure compilation time of Test with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationTest.sol --use solc:0.8.17 --via-ir

- name: Measure compilation time of TestBase with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationTestBase.sol --use solc:0.8.17 --via-ir

- name: Measure compilation time of Script with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationScript.sol --use solc:0.8.17 --via-ir

- name: Measure compilation time of ScriptBase with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationScriptBase.sol --use solc:0.8.17 --via-ir

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Print forge version
run: forge --version

- name: Run tests
run: forge test -vvv

fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Print forge version
run: forge --version

- name: Check formatting
run: forge fmt --check
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Sync Release Branch

on:
release:
types:
- created

jobs:
sync-release-branch:
runs-on: ubuntu-latest
if: startsWith(github.event.release.tag_name, 'v1')
steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: v1

# The email is derived from the bots user id,
# found here: https://api.github.com/users/github-actions%5Bbot%5D
- name: Configure Git
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- name: Sync Release Branch
run: |
git fetch --tags
git checkout v1
git reset --hard ${GITHUB_REF}
git push --force
4 changes: 4 additions & 0 deletions examples/fibonacci/contracts/lib/forge-std/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cache/
out/
.vscode
.idea
Loading

0 comments on commit 1bdcd07

Please sign in to comment.