Skip to content

Commit

Permalink
Merge pull request #1295 from o1-labs/feature/op-program
Browse files Browse the repository at this point in the history
Setup CLI for cannon MIPS VM
  • Loading branch information
dannywillems authored Oct 24, 2023
2 parents 2365ebb + c7254f7 commit 69db0c8
Show file tree
Hide file tree
Showing 14 changed files with 558 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "optimism/ethereum-optimism"]
path = optimism/ethereum-optimism
url = https://github.com/ethereum-optimism/optimism.git
136 changes: 125 additions & 11 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 @@ -6,6 +6,7 @@ members = [
"groupmap",
"hasher",
"kimchi",
"optimism",
"poseidon",
"poseidon/export_test_vectors",
"poly-commitment",
Expand Down
1 change: 1 addition & 0 deletions optimism/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rpcs.sh
30 changes: 30 additions & 0 deletions optimism/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "kimchi_optimism"
version = "0.1.0"
description = "MIPS demo"
repository = "https://github.com/o1-labs/proof-systems"
homepage = "https://o1-labs.github.io/proof-systems/"
documentation = "https://o1-labs.github.io/proof-systems/rustdoc/"
readme = "README.md"
edition = "2021"
license = "Apache-2.0"

[lib]
path = "src/lib.rs"

[dependencies]
kimchi = { path = "../kimchi", version = "0.1.0" }
poly-commitment = { path = "../poly-commitment", version = "0.1.0" }
groupmap = { path = "../groupmap", version = "0.1.0" }
mina-curves = { path = "../curves", version = "0.1.0" }
mina-poseidon = { path = "../poseidon", version = "0.1.0" }
elf = "0.7.2"
rmp-serde = "1.1.1"
serde_json = "1.0.91"
serde = "1.0.130"
serde_with = "1.10.0"
ark-poly = { version = "0.3.0", features = [ "parallel" ] }
ark-ff = { version = "0.3.0", features = [ "parallel" ] }
clap = "4.4.6"
hex = "0.4.3"
regex = "1.10.2"
18 changes: 18 additions & 0 deletions optimism/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
To run the demo:
* create an executable file `rpcs.sh` that looks like
```bash
#!/usr/bin/env bash
export L1RPC=http://xxxxxxxxx
export L2RPC=http://xxxxxxxxx
```
* run the `run-code.sh` script.

This will
* generate the initial state,
* execute the OP program,
* execute the OP program through the cannon MIPS VM,
* execute the OP program through the kimchi MIPS VM prover.

The initial state will be output to a file with format `YYYY-MM-DD-HH-MM-SS-op-program-data-log.sh`.

If you want to re-run against an existing state, pass the environment variable `FILENAME=YYYY-MM-DD-HH-MM-SS-op-program-data-log.sh` to the `run-code.sh` script.
1 change: 1 addition & 0 deletions optimism/ethereum-optimism
Submodule ethereum-optimism added at c83cd9
50 changes: 50 additions & 0 deletions optimism/generate-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash
set -euo pipefail

source rpcs.sh

# L2 output oracle on Goerli
# L2_OUTPUT_ORACLE=0xE6Dfba0953616Bacab0c9A8ecb3a9BBa77FC15c0
# L2 output oracle on Sepolia
L2_OUTPUT_ORACLE=0x90E9c4f8a994a250F6aEfd61CAFb4F2e895D458F

L2_FINALIZED_NUMBER=$(cast block finalized --rpc-url "${L2RPC}" -f number)
echo "Finalize number: ${L2_FINALIZED_NUMBER}" 1>&2
L2_FINALIZED_HASH=$(cast block "${L2_FINALIZED_NUMBER}" --rpc-url "${L2RPC}" -f hash)

L1_FINALIZED_NUMBER=$(cast block finalized --rpc-url "${L1RPC}" -f number)
L1_FINALIZED_HASH=$(cast block "${L1_FINALIZED_NUMBER}" --rpc-url "${L1RPC}" -f hash)

OUTPUT_INDEX=$(cast call --rpc-url "${L1RPC}" "${L2_OUTPUT_ORACLE}" 'getL2OutputIndexAfter(uint256) returns(uint256)' "${L2_FINALIZED_NUMBER}")
OUTPUT_INDEX=$((OUTPUT_INDEX-1))

OUTPUT=$(cast call --rpc-url "${L1RPC}" "${L2_OUTPUT_ORACLE}" 'getL2Output(uint256) returns(bytes32,uint128,uint128)' "${OUTPUT_INDEX}")
OUTPUT_ROOT=$(echo ${OUTPUT} | cut -d' ' -f 1)
OUTPUT_TIMESTAMP=$(echo ${OUTPUT} | cut -d' ' -f 2)
OUTPUT_L2BLOCK_NUMBER=$(echo ${OUTPUT} | cut -d' ' -f 3)

L1_HEAD=$L1_FINALIZED_HASH
L2_CLAIM=$OUTPUT_ROOT
L2_BLOCK_NUMBER=$OUTPUT_L2BLOCK_NUMBER

STARTING_L2BLOCK_NUMBER=$((L2_BLOCK_NUMBER-100))
STARTING_OUTPUT_INDEX=$(cast call --rpc-url "${L1RPC}" "${L2_OUTPUT_ORACLE}" 'getL2OutputIndexAfter(uint256) returns(uint256)' "${STARTING_L2BLOCK_NUMBER}")
STARTING_OUTPUT=$(cast call --rpc-url "${L1RPC}" "${L2_OUTPUT_ORACLE}" 'getL2Output(uint256) returns(bytes32,uint128,uint128)' "${STARTING_OUTPUT_INDEX}")
STARTING_OUTPUT_ROOT=$(echo ${OUTPUT} | cut -d' ' -f 1)
L2_HEAD_NUMBER=$(echo ${OUTPUT} | cut -d' ' -f 3)
L2_HEAD=$(cast block "${L2_HEAD_NUMBER}" --rpc-url "${L2RPC}" -f hash)

TODAY=$(date +"%Y-%m-%d-%H-%M-%S")
FILENAME=${TODAY}-op-program-data-log.sh
OP_PROGRAM_DATA_DIR=$(pwd)/op-program-db-sepolia-${TODAY}

echo "export L1_HEAD=${L1_HEAD}" >> ${FILENAME}
echo "export L2_HEAD=${L2_HEAD}" >> ${FILENAME}
echo "export L2_BLOCK_NUMBER=${L2_BLOCK_NUMBER}" >> ${FILENAME}
echo "export STARTING_OUTPUT_ROOT=${STARTING_OUTPUT_ROOT}" >> ${FILENAME}
echo "export L2_CLAIM=${L2_CLAIM}" >> ${FILENAME}
echo "export OP_PROGRAM_DATA_DIR=${OP_PROGRAM_DATA_DIR}" >> ${FILENAME}
echo "export L1RPC=${L1RPC}" >> ${FILENAME}
echo "export L2RPC=${L2RPC}" >> ${FILENAME}

echo "${FILENAME}"
16 changes: 16 additions & 0 deletions optimism/run-code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -euo pipefail

source rpcs.sh

set +u
if [ -z "${FILENAME}" ]; then
FILENAME="$(./generate-config.sh)"
fi
set -u

source $FILENAME

./run-op-program.sh

./run-vm.sh
39 changes: 39 additions & 0 deletions optimism/run-op-program.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
set -euo pipefail

make -C ./ethereum-optimism/op-program op-program
make -C ./ethereum-optimism/cannon cannon

set -x
./ethereum-optimism/op-program/bin/op-program \
--log.level DEBUG \
--l1 $L1RPC \
--l2 $L2RPC \
--network sepolia \
--datadir ${OP_PROGRAM_DATA_DIR} \
--l1.head $L1_HEAD \
--l2.head $L2_HEAD \
--l2.outputroot $STARTING_OUTPUT_ROOT \
--l2.claim $L2_CLAIM \
--l2.blocknumber $L2_BLOCK_NUMBER

./ethereum-optimism/cannon/bin/cannon load-elf --path=./ethereum-optimism/op-program/bin/op-program-client.elf

./ethereum-optimism/cannon/bin/cannon run \
--pprof.cpu \
--info-at '%10000000' \
--proof-at never \
--input ./state.json \
-- \
./ethereum-optimism/op-program/bin/op-program \
--log.level DEBUG \
--l1 ${L1RPC} \
--l2 ${L2RPC} \
--network sepolia \
--datadir ${OP_PROGRAM_DATA_DIR} \
--l1.head ${L1_HEAD} \
--l2.head ${L2_HEAD} \
--l2.outputroot ${STARTING_OUTPUT_ROOT} \
--l2.claim ${L2_CLAIM} \
--l2.blocknumber ${L2_BLOCK_NUMBER} \
--server
Loading

0 comments on commit 69db0c8

Please sign in to comment.