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

Set ZK constants in compile time #1613

Merged
merged 105 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from 88 commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
f61421e
Carry guest input read outside of run_sequencer_commitments_in_da_slot
yaziciahmet Dec 13, 2024
39e90d9
Get light client input as arg in circuit
yaziciahmet Dec 13, 2024
d9ec09e
Remove useless generic
yaziciahmet Dec 13, 2024
3de7c07
Add SEQ PUB KEYS and implement Fork str parser
yaziciahmet Dec 15, 2024
4c2b182
Fmt
yaziciahmet Dec 15, 2024
af6f754
One more fail-test
yaziciahmet Dec 15, 2024
fec0dcf
Rename
yaziciahmet Dec 16, 2024
b9ba404
Init const FORKS
yaziciahmet Dec 16, 2024
be04c37
Add doc
yaziciahmet Dec 16, 2024
39a4106
Lower count to 50
yaziciahmet Dec 16, 2024
b2e67e3
Implement fork list parser
yaziciahmet Dec 16, 2024
0036433
Rename
yaziciahmet Dec 16, 2024
8778b13
Fix list parser & add tests
yaziciahmet Dec 16, 2024
3d83afd
Validate fork list on parse
yaziciahmet Dec 16, 2024
9457a0d
Add light client consts
yaziciahmet Dec 16, 2024
c9433c6
Use specific const-hex v
yaziciahmet Dec 16, 2024
f1706d3
Update do not use comment
yaziciahmet Dec 16, 2024
73d4907
Merge branch 'nightly' into yaziciahmet/set-zk-constants-from-env
yaziciahmet Dec 16, 2024
9398b56
Merge branch 'nightly' into yaziciahmet/set-zk-constants-from-env
yaziciahmet Dec 16, 2024
6b942a4
Allow same activation heights for consecutive forks
yaziciahmet Dec 16, 2024
50d1164
Enforce env variables in guest build
yaziciahmet Dec 16, 2024
57222b4
Add env variables to mocks
yaziciahmet Dec 16, 2024
b07aa3c
Separate fork list verification
yaziciahmet Dec 16, 2024
4c4a05d
Add doc
yaziciahmet Dec 16, 2024
515d3b8
Allow non-zero start of forks
yaziciahmet Dec 17, 2024
da2b66d
Create Forks wrapper struct
yaziciahmet Dec 17, 2024
53f48ce
Add derive
yaziciahmet Dec 17, 2024
be23c03
Update guests accordingly
yaziciahmet Dec 17, 2024
479e0b4
Implement serde for Fork & Forks
yaziciahmet Dec 17, 2024
7c2fda0
Implement Forks::from_slice
yaziciahmet Dec 17, 2024
57fcb97
Read forks from rollup config
yaziciahmet Dec 17, 2024
ed2756f
Add lifetime to ForkManager
yaziciahmet Dec 17, 2024
84e0433
Separate fork_pos_from_block_number method as a helper
yaziciahmet Dec 17, 2024
8d73c8e
Improve verify_forks method
yaziciahmet Dec 17, 2024
ff3c60c
Make FORKS OnceLock static global
yaziciahmet Dec 17, 2024
e841a2a
Check first byte of da public key in compile time
yaziciahmet Dec 17, 2024
23fedae
Merge nightly
yaziciahmet Dec 17, 2024
d9d9d0a
Update test_helpers according to nightly
yaziciahmet Dec 17, 2024
e6114d9
Pass forks as arg
yaziciahmet Dec 17, 2024
aec4378
Have single SpecId
yaziciahmet Dec 18, 2024
1fb4c64
Take sequencer pub keys as arg to batch proof circuit
yaziciahmet Dec 18, 2024
487c84a
Get light client circuit constants as arg
yaziciahmet Dec 18, 2024
0b69f36
Lint
yaziciahmet Dec 18, 2024
41b15dd
Fix comment
yaziciahmet Dec 18, 2024
69a3f3b
Match DA public key env key for native and zk
yaziciahmet Dec 18, 2024
ebd3a8d
Make FORKS constant per environment
yaziciahmet Dec 18, 2024
cd89430
Remove forks from config
yaziciahmet Dec 18, 2024
f49bf57
Set everything from CITREA_NETWORK env
yaziciahmet Dec 18, 2024
539bcee
Remove unused Forks
yaziciahmet Dec 18, 2024
8bfd76d
Check fork ordering in compile time
yaziciahmet Dec 18, 2024
fdae8e1
Remove serde from Fork
yaziciahmet Dec 18, 2024
d755d0a
Newline
yaziciahmet Dec 18, 2024
ded4659
Rename sp1
yaziciahmet Dec 18, 2024
ed94e64
Fix sp1
yaziciahmet Dec 18, 2024
8a24f29
Update guest Dockerfile & Makefile
yaziciahmet Dec 18, 2024
4093f54
Fix udeps
yaziciahmet Dec 18, 2024
096a30d
Fix no-std
yaziciahmet Dec 18, 2024
76fbb91
Fix comment
yaziciahmet Dec 18, 2024
ee66672
Fix no-std warning
yaziciahmet Dec 18, 2024
9ee5ce0
Remove testing forks
yaziciahmet Dec 18, 2024
101e3cb
Merge nightly
yaziciahmet Dec 18, 2024
b3245e1
Match config env key and guest env keys
yaziciahmet Dec 18, 2024
d6dc818
Set mainnet keys to 0
yaziciahmet Dec 18, 2024
183c256
Add prover da pub key for regtest
yaziciahmet Dec 18, 2024
bcaaa87
Update latest guest spec to be Fork1
yaziciahmet Dec 18, 2024
952b80c
Run tests on Nightly
yaziciahmet Dec 19, 2024
9fbf384
Match e2e test keys with guest nightly
yaziciahmet Dec 19, 2024
1905fdd
Set genesis state roots
yaziciahmet Dec 19, 2024
0d9196c
Remove todo
yaziciahmet Dec 19, 2024
e6e0bc6
Set mock configs to be same with regtest
yaziciahmet Dec 19, 2024
48630e1
Set l2 genesis root for mock proof
yaziciahmet Dec 19, 2024
93f0557
Remove Simulate proof mode
yaziciahmet Dec 19, 2024
287a27d
Fix udeps
yaziciahmet Dec 19, 2024
abd9da4
Add sender_address back to rollup
yaziciahmet Dec 19, 2024
d76e286
Add todo
yaziciahmet Dec 19, 2024
e0d7d56
Update crates/sovereign-sdk/rollup-interface/src/network.rs
yaziciahmet Dec 19, 2024
090bd53
Merge nightly
yaziciahmet Dec 19, 2024
e701018
Fix CANCUN related test
yaziciahmet Dec 19, 2024
9ee8551
Match citrea-e2e pub keys
yaziciahmet Dec 19, 2024
5080e80
Separate batch and light client guests
yaziciahmet Dec 20, 2024
82f24b5
Update docker and make file
yaziciahmet Dec 20, 2024
c8264a5
Use batch proof method id from build in light client
yaziciahmet Dec 20, 2024
5d6c9e1
Merge branch 'nightly' into yaziciahmet/set-zk-constants-from-env
yaziciahmet Dec 20, 2024
4ba9399
Update build-release
yaziciahmet Dec 20, 2024
b9a0217
Use input public key for output
yaziciahmet Dec 20, 2024
0aeeef3
Merge branch 'nightly' into yaziciahmet/set-zk-constants-from-env
yaziciahmet Dec 20, 2024
5eb7228
Attempt to make preproven commitments test faster
yaziciahmet Dec 20, 2024
82fff65
Add env variable to release.yml workflow && rerun build on env change
yaziciahmet Dec 20, 2024
6d5bd92
SKIP_GUEST_BUILD in release.yml
yaziciahmet Dec 20, 2024
54876c3
Add genesis to fork1 l1 diff size change test
yaziciahmet Dec 20, 2024
8233e77
Remove test
yaziciahmet Dec 20, 2024
7f64d64
Merge branch 'nightly' into yaziciahmet/set-zk-constants-from-env
yaziciahmet Dec 20, 2024
1803b53
Make default evm in tests Fork1
yaziciahmet Dec 20, 2024
05cb5dc
Fix most sys tx tests
yaziciahmet Dec 20, 2024
daef7bd
Fix all sys tx tests
yaziciahmet Dec 20, 2024
1036e86
Fix most hooks tests
yaziciahmet Dec 20, 2024
d6d9d0f
Fix all hooks tests
yaziciahmet Dec 20, 2024
29fc600
Fix all genesis tests
yaziciahmet Dec 20, 2024
a67259e
Fix all call tests
yaziciahmet Dec 20, 2024
78588ee
Remove unnecessary fork setting
yaziciahmet Dec 20, 2024
31303bd
Fix fork tests
yaziciahmet Dec 20, 2024
1792171
Lint
yaziciahmet Dec 20, 2024
5ecdb1c
Recover l1 fee compression discount
yaziciahmet Dec 20, 2024
8918da8
Merge nightly
yaziciahmet Dec 21, 2024
443b7ed
Lint
yaziciahmet Dec 21, 2024
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
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
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ jobs:

- name: Build Project
env:
REPR_GUEST_BUILD: 1
# TODO: make this dynamic somehow
yaziciahmet marked this conversation as resolved.
Show resolved Hide resolved
CITREA_NETWORK: testnet
run: |
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
30 changes: 6 additions & 24 deletions bin/citrea/src/rollup/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@ 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;
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,
) -> Self::ProverService {
let vm = Risc0BonsaiHost::new(ledger_db.clone());
Expand All @@ -268,26 +263,13 @@ 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(stf_verifier)
}
ProverGuestRunConfig::Execute => ProofGenMode::Execute,
ProverGuestRunConfig::Prove => ProofGenMode::Prove,
};

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
Loading