Skip to content

Commit

Permalink
Set ZK constants in compile time (#1613)
Browse files Browse the repository at this point in the history
Co-authored-by: jfldde <[email protected]>
  • Loading branch information
yaziciahmet and jfldde authored Dec 21, 2024
1 parent 04dff78 commit 8feb715
Show file tree
Hide file tree
Showing 100 changed files with 2,332 additions and 1,277 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
- name: Build citrea
run: make build-release
env:
REPR_GUEST_BUILD: 1
CITREA_NETWORK: nightly

- name: Upload artifact
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -267,9 +267,9 @@ jobs:
run: npm install
- name: Run uniswap tests
run: |
RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/sequencer_rollup_config.toml --sequencer resources/configs/mock/sequencer_config.toml --genesis-paths resources/genesis/mock/ &
RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/sequencer_rollup_config.toml --sequencer resources/configs/mock/sequencer_config.toml --genesis-paths resources/genesis/mock/ --dev &
sleep 2
RUST_LOG=off ./target/release/citrea --rollup-config-path resources/configs/mock/rollup_config.toml --genesis-paths resources/genesis/mock/ &
RUST_LOG=off ./target/release/citrea --rollup-config-path resources/configs/mock/rollup_config.toml --genesis-paths resources/genesis/mock/ --dev &
sleep 2
cd ./bin/citrea/tests/evm/uniswap
npx hardhat run --network citrea scripts/01_deploy.js
Expand Down Expand Up @@ -310,9 +310,9 @@ jobs:
run: pip install -r requirements.txt
- name: Run web3.py tests
run: |
RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/sequencer_rollup_config.toml --sequencer resources/configs/mock/sequencer_config.toml --genesis-paths resources/genesis/mock/ &
RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/sequencer_rollup_config.toml --sequencer resources/configs/mock/sequencer_config.toml --genesis-paths resources/genesis/mock/ --dev &
sleep 2
RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/rollup_config.toml --genesis-paths resources/genesis/mock/ &
RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/rollup_config.toml --genesis-paths resources/genesis/mock/ --dev &
sleep 2
cd ./bin/citrea/tests/evm/web3_py
python test.py
Expand All @@ -338,9 +338,9 @@ jobs:
run: npm install
- name: Run ethers_js tests
run: |
RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/sequencer_rollup_config.toml --sequencer resources/configs/mock/sequencer_config.toml --genesis-paths resources/genesis/mock/ &
RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/sequencer_rollup_config.toml --sequencer resources/configs/mock/sequencer_config.toml --genesis-paths resources/genesis/mock/ --dev &
sleep 2
RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/rollup_config.toml --genesis-paths resources/genesis/mock/ &
RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/rollup_config.toml --genesis-paths resources/genesis/mock/ --dev &
sleep 2
cd ./bin/citrea/tests/evm/ethers_js
npm install
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

- name: Build Project
env:
REPR_GUEST_BUILD: 1
SKIP_GUEST_BUILD: 1
run: |
cargo build --release
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Build Project
env:
REPR_GUEST_BUILD: 1
SKIP_GUEST_BUILD: 1
run: |
source $HOME/.cargo/env
cargo build --release
Expand Down
31 changes: 17 additions & 14 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ alloy-eips = { version = "0.4.2", default-features = false }
alloy-consensus = { version = "0.4.2", default-features = false, features = ["serde", "serde-bincode-compat"] }
alloy-network = { version = "0.4.2", default-features = false }

citrea-e2e = { git = "https://github.com/chainwayxyz/citrea-e2e", rev = "51a4d19" }
citrea-e2e = { git = "https://github.com/chainwayxyz/citrea-e2e", rev = "6a87ce3" }

[patch.crates-io]
bitcoincore-rpc = { version = "0.18.0", git = "https://github.com/chainwayxyz/rust-bitcoincore-rpc.git", rev = "ca3cfa2" }
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ LIGHT_OUT_PATH := resources/guests/risc0/
help: ## Display this help message
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

.PHONY: build-risc0
build-risc0:
$(MAKE) -j 2 -C guests/risc0 all

.PHONY: build-risc0-docker
build-risc0-docker:
$(MAKE) -C guests/risc0 batch-proof-bitcoin-docker OUT_PATH=$(BATCH_OUT_PATH)
Expand All @@ -32,7 +28,7 @@ build: ## Build the project
build-test: ## Build the project
@cargo build $(TEST_FEATURES)

build-release: build-risc0 build-sp1 ## Build the project in release mode
build-release: build-risc0-docker build-sp1 ## Build the project in release mode
@cargo build --release

clean: ## Cleans compiled
Expand Down
10 changes: 8 additions & 2 deletions bin/citrea/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ citrea-common = { path = "../../crates/common" }
citrea-fullnode = { path = "../../crates/fullnode" }
citrea-light-client-prover = { path = "../../crates/light-client-prover", features = ["native"] }
citrea-primitives = { path = "../../crates/primitives" }
citrea-risc0 = { package = "risc0", path = "../../guests/risc0" }
citrea-risc0-adapter = { path = "../../crates/risc0", features = ["native"] }
citrea-risc0-batch-proof = { path = "../../guests/risc0/batch-proof" }
citrea-risc0-light-client = { path = "../../guests/risc0/light-client-proof" }
citrea-sequencer = { path = "../../crates/sequencer" }
# citrea-sp1 = { path = "../../crates/sp1", features = ["native"] }
citrea-stf = { path = "../../crates/citrea-stf", features = ["native"] }
Expand Down Expand Up @@ -102,7 +103,12 @@ sp1-helper = { version = "3.0.0", default-features = false }

[features]
default = [] # Deviate from convention by making the "native" feature active by default. This aligns with how this package is meant to be used (as a binary first, library second).
testing = ["citrea-primitives/testing", "citrea-risc0/testing", "sov-rollup-interface/testing"]
testing = [
"citrea-primitives/testing",
"citrea-risc0-batch-proof/testing",
"citrea-risc0-light-client/testing",
"sov-rollup-interface/testing",
]

[[bin]]
name = "citrea"
Expand Down
32 changes: 28 additions & 4 deletions bin/citrea/src/guests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,50 @@ lazy_static! {
pub(crate) static ref BATCH_PROOF_LATEST_MOCK_GUESTS: HashMap<SpecId, (Digest, Vec<u8>)> = {
let mut m = HashMap::new();

m.insert(SpecId::Genesis, (Digest::new(citrea_risc0::BATCH_PROOF_MOCK_ID), citrea_risc0::BATCH_PROOF_MOCK_ELF.to_vec()));
m.insert(
SpecId::Fork1,
(
Digest::new(citrea_risc0_batch_proof::BATCH_PROOF_MOCK_ID),
citrea_risc0_batch_proof::BATCH_PROOF_MOCK_ELF.to_vec(),
),
);
m
};
pub(crate) static ref LIGHT_CLIENT_LATEST_MOCK_GUESTS: HashMap<SpecId, (Digest, Vec<u8>)> = {
let mut m = HashMap::new();

m.insert(SpecId::Genesis, (Digest::new(citrea_risc0::LIGHT_CLIENT_PROOF_MOCK_ID), citrea_risc0::LIGHT_CLIENT_PROOF_MOCK_ELF.to_vec()));
m.insert(
SpecId::Fork1,
(
Digest::new(citrea_risc0_light_client::LIGHT_CLIENT_PROOF_MOCK_ID),
citrea_risc0_light_client::LIGHT_CLIENT_PROOF_MOCK_ELF.to_vec(),
)
);
m
};
/// The following 2 are used as latest guest builds for tests that use Bitcoin DA.
pub(crate) static ref BATCH_PROOF_LATEST_BITCOIN_GUESTS: HashMap<SpecId, (Digest, Vec<u8>)> = {
let mut m = HashMap::new();

m.insert(SpecId::Genesis, (Digest::new(citrea_risc0::BATCH_PROOF_BITCOIN_ID), citrea_risc0::BATCH_PROOF_BITCOIN_ELF.to_vec()));
m.insert(
SpecId::Fork1,
(
Digest::new(citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ID),
citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ELF.to_vec(),
)
);
m
};
pub(crate) static ref LIGHT_CLIENT_LATEST_BITCOIN_GUESTS: HashMap<SpecId, (Digest, Vec<u8>)> = {
let mut m = HashMap::new();

m.insert(SpecId::Genesis, (Digest::new(citrea_risc0::LIGHT_CLIENT_PROOF_BITCOIN_ID), citrea_risc0::LIGHT_CLIENT_PROOF_BITCOIN_ELF.to_vec()));
m.insert(
SpecId::Fork1,
(
Digest::new(citrea_risc0_light_client::LIGHT_CLIENT_PROOF_BITCOIN_ID),
citrea_risc0_light_client::LIGHT_CLIENT_PROOF_BITCOIN_ELF.to_vec(),
)
);
m
};
/// Production guests
Expand Down
2 changes: 1 addition & 1 deletion bin/citrea/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::env;
use std::str::FromStr;

use serde::Serialize;
use sov_modules_rollup_blueprint::Network;
use sov_rollup_interface::Network;
use tracing::Level;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
Expand Down
3 changes: 2 additions & 1 deletion bin/citrea/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ use metrics_exporter_prometheus::PrometheusBuilder;
use metrics_util::MetricKindMask;
use sov_mock_da::MockDaConfig;
use sov_modules_api::Spec;
use sov_modules_rollup_blueprint::{Network, RollupBlueprint};
use sov_modules_rollup_blueprint::RollupBlueprint;
use sov_rollup_interface::Network;
use sov_state::storage::NativeStorage;
use tracing::{debug, error, info, instrument};

Expand Down
32 changes: 7 additions & 25 deletions bin/citrea/src/rollup/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,24 @@ use bitcoin_da::verifier::BitcoinVerifier;
use citrea_common::rpc::register_healthcheck_rpc;
use citrea_common::tasks::manager::TaskManager;
use citrea_common::FullNodeConfig;
use citrea_primitives::forks::use_network_forks;
use citrea_primitives::{TO_BATCH_PROOF_PREFIX, TO_LIGHT_CLIENT_PREFIX};
use citrea_risc0_adapter::host::Risc0BonsaiHost;
// use citrea_sp1::host::SP1Host;
use citrea_stf::genesis_config::StorageConfig;
use citrea_stf::runtime::Runtime;
use citrea_stf::verifier::StateTransitionVerifier;
use prover_services::{ParallelProverService, ProofGenMode};
use sov_db::ledger_db::LedgerDB;
use sov_modules_api::default_context::{DefaultContext, ZkDefaultContext};
use sov_modules_api::{Address, SpecId, Zkvm};
use sov_modules_rollup_blueprint::RollupBlueprint;
use sov_modules_stf_blueprint::StfBlueprint;
use sov_prover_storage_manager::{ProverStorageManager, SnapshotManager};
use sov_rollup_interface::da::DaVerifier;
use sov_rollup_interface::services::da::SenderWithNotifier;
use sov_state::{ProverStorage, ZkStorage};
use sov_state::ProverStorage;
use sov_stf_runner::ProverGuestRunConfig;
use tokio::sync::broadcast;
use tokio::sync::mpsc::unbounded_channel;
use tokio::sync::{broadcast, Mutex};
use tracing::instrument;

use crate::guests::{
Expand Down Expand Up @@ -57,13 +56,10 @@ impl RollupBlueprint for BitcoinRollup {
type ZkRuntime = Runtime<Self::ZkContext, Self::DaSpec>;
type NativeRuntime = Runtime<Self::NativeContext, Self::DaSpec>;

type ProverService = ParallelProverService<
Self::DaService,
Self::Vm,
StfBlueprint<Self::ZkContext, Self::DaSpec, Self::ZkRuntime>,
>;
type ProverService = ParallelProverService<Self::DaService, Self::Vm>;

fn new(network: Network) -> Self {
use_network_forks(network);
Self { network }
}

Expand Down Expand Up @@ -259,7 +255,6 @@ impl RollupBlueprint for BitcoinRollup {
&self,
proving_mode: ProverGuestRunConfig,
da_service: &Arc<Self::DaService>,
da_verifier: Self::DaVerifier,
ledger_db: LedgerDB,
proof_sampling_number: usize,
) -> Self::ProverService {
Expand All @@ -269,29 +264,16 @@ impl RollupBlueprint for BitcoinRollup {
// ledger_db.clone(),
// );

let zk_stf = StfBlueprint::new();
let zk_storage = ZkStorage::new();

let proof_mode = match proving_mode {
ProverGuestRunConfig::Skip => ProofGenMode::Skip,
ProverGuestRunConfig::Simulate => {
let stf_verifier = StateTransitionVerifier::new(zk_stf, da_verifier);
ProofGenMode::Simulate(Arc::new(Mutex::new(stf_verifier)))
}
ProverGuestRunConfig::Execute => ProofGenMode::Execute,
ProverGuestRunConfig::Prove => ProofGenMode::ProveWithSampling,
ProverGuestRunConfig::ProveWithFakeProofs => {
ProofGenMode::ProveWithSamplingWithFakeProofs(proof_sampling_number)
}
};

ParallelProverService::new_from_env(
da_service.clone(),
vm,
proof_mode,
zk_storage,
ledger_db,
)
.expect("Should be able to instantiate prover service")
ParallelProverService::new_from_env(da_service.clone(), vm, proof_mode, ledger_db)
.expect("Should be able to instantiate prover service")
}
}
Loading

0 comments on commit 8feb715

Please sign in to comment.