Skip to content

Commit

Permalink
Implement feature to use pre-built docker ELF
Browse files Browse the repository at this point in the history
  • Loading branch information
austinabell committed Sep 30, 2024
1 parent e1236b1 commit 99e3f40
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ target/
.env

contracts/cache
contracts/out
dockerfiles

# Docker build ignored, to allow overriding the dockerized service with the deterministic build.
!target/riscv-guest/riscv32im-risc0-zkvm-elf/docker/light_client_guest/light-client-guest
3 changes: 3 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ reqwest = "0.12.4"
serde = { workspace = true }
serde_json = "1.0"
serde_with = { version = "3.8", features = ["base64"] }

[features]
prebuilt-docker = ["blobstream0-core/prebuilt-docker"]
12 changes: 6 additions & 6 deletions contracts/artifacts/Blobstream0.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/src/ImageID.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ pragma solidity ^0.8.20;

library ImageID {
bytes32 public constant LIGHT_CLIENT_GUEST_ID =
bytes32(0x4383189e399cb4bb64bc8b77fbaefcfe4c3c6472867bdd61de5eb1d4334a34c6);
bytes32(0x3229c3708db83fd93c3f28275361870e40d75740c5c09498196474da8fc65f8e);
}
3 changes: 3 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ tendermint-proto = { workspace = true }
tendermint-rpc = { workspace = true, features = ["http-client"] }
tokio = { version = "1.38.0", features = ["rt", "macros", "fs"] }
tracing = "0.1.40"

[features]
prebuilt-docker = ["light-client-guest/prebuilt-docker"]
11 changes: 10 additions & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use blobstream0_primitives::{
IBlobstream::IBlobstreamInstance,
LightBlockProveData, RangeCommitment,
};
use light_client_guest::LIGHT_CLIENT_GUEST_ELF;
// use light_client_guest::LIGHT_CLIENT_GUEST_ELF;
use risc0_ethereum_contracts::groth16;
use risc0_zkvm::{default_prover, is_dev_mode, sha::Digestible, ExecutorEnv, ProverOpts, Receipt};
use std::{ops::Range, sync::Arc, time::Duration};
Expand All @@ -34,6 +34,15 @@ use tracing::{instrument, Level};
mod range_iterator;
use range_iterator::LightBlockRangeIterator;

// This is configured to use the default docker build path. The reason for the feature flag is
// because we want a consistent docker image to build the program, which should not be run within
// the dockerized service container.
#[cfg(feature = "prebuilt-docker")]
const LIGHT_CLIENT_GUEST_ELF: &[u8] =
include_bytes!("../../target/riscv-guest/riscv32im-risc0-zkvm-elf/docker/light_client_guest/light-client-guest");
#[cfg(not(feature = "prebuilt-docker"))]
use light_client_guest::LIGHT_CLIENT_GUEST_ELF;

/// Currently set to the max allowed by tendermint RPC
const HEADER_REQ_COUNT: u64 = 20;

Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/blobstream0.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ WORKDIR /app
COPY . .

# Build the project
RUN cargo build -p blobstream0 --release
RUN cargo build -p blobstream0 --release --features prebuilt-docker

# Create a new stage for a smaller final image
FROM debian:bullseye-slim as final
Expand Down
5 changes: 4 additions & 1 deletion light-client-guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ risc0-build-ethereum = { git = "https://github.com/risc0/risc0-ethereum", tag =
# Currently just used to format built artifact
serde_json = "1.0"

[features]
prebuilt-docker = []

[package.metadata.risc0]
methods = ["guest"]
methods = ["guest"]
6 changes: 6 additions & 0 deletions light-client-guest/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const SOLIDITY_IMAGE_ID_PATH: &str = "../contracts/src/ImageID.sol";
const SOLIDITY_ELF_PATH: &str = "../contracts/test/Elf.sol";

fn main() {
// If this feature is enabled, skip build and just use pre-built guest and EVM artifacts.
if cfg!(feature = "prebuilt-docker") {
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_PREBUILT_DOCKER");
return;
}

// Builds can be made deterministic, and thereby reproducible, by using Docker to build the
// guest. Check the RISC0_USE_DOCKER variable and use Docker to build the guest if set.
let use_docker = env::var("RISC0_USE_DOCKER").ok().map(|_| DockerOptions {
Expand Down
1 change: 1 addition & 0 deletions light-client-guest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#[cfg(not(feature = "prebuilt-docker"))]
include!(concat!(env!("OUT_DIR"), "/methods.rs"));

0 comments on commit 99e3f40

Please sign in to comment.