Skip to content

Commit

Permalink
Implement guest side verification (#1402)
Browse files Browse the repository at this point in the history
  • Loading branch information
ercecan authored Oct 31, 2024
1 parent cf49304 commit ca7a8d0
Show file tree
Hide file tree
Showing 45 changed files with 395 additions and 271 deletions.
6 changes: 3 additions & 3 deletions .github/actions/validate-bitcoin-da/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ runs:
if: inputs.action == 'check_binary'
shell: bash
run: |
RESULT=$(grep -R "BATCH_PROVER_BITCOIN_ID" target/ || echo "Grep failed")
RESULT=$(grep -R "BATCH_PROOF_BITCOIN_ID" target/ || echo "Grep failed")
EXPECTED_BITCOIN_DA_ID=$(echo "${{ env.EXPECTED_BITCOIN_DA_ID }}" | tr -d '\n\r')
if echo "$RESULT" | grep -q "$EXPECTED_BITCOIN_DA_ID"; then
echo "Check passed successfully."
echo "Expected: BATCH_PROVER_BITCOIN_ID ${{ env.EXPECTED_BITCOIN_DA_ID }} "
echo "Expected: BATCH_PROOF_BITCOIN_ID ${{ env.EXPECTED_BITCOIN_DA_ID }} "
echo "Actual: $RESULT"
else
echo "Check failed. Expected: BATCH_PROVER_BITCOIN_ID ${{ env.EXPECTED_BITCOIN_DA_ID }} "
echo "Check failed. Expected: BATCH_PROOF_BITCOIN_ID ${{ env.EXPECTED_BITCOIN_DA_ID }} "
echo "Actual: $RESULT"
exit 1
fi
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ jobs:
env:
RUST_BACKTRACE: 1
TEST_BITCOIN_DOCKER: 1
RISC0_DEV_MODE: 1 # This is needed to generate mock proofs and verify them
SHORT_PREFIX: 1
CITREA_E2E_TEST_BINARY: ${{ github.workspace }}/target/debug/citrea
- name: Upload coverage
Expand Down Expand Up @@ -374,6 +375,7 @@ jobs:
RUST_BACKTRACE: 1
BONSAI_API_URL: ${{ secrets.BONSAI_API_URL }} # TODO: remove this once we don't use the client on tests
BONSAI_API_KEY: ${{ secrets.BONSAI_API_KEY }} # TODO: remove this once we don't use the client on tests
RISC0_DEV_MODE: 1 # This is needed to generate mock proofs and verify them
TEST_BITCOIN_DOCKER: 1
SHORT_PREFIX: 1
CITREA_E2E_TEST_BINARY: ${{ github.workspace }}/target/debug/citrea
Expand Down Expand Up @@ -453,7 +455,7 @@ jobs:
name: citrea-build
path: target/release

- name: Check BATCH_PROVER_BITCOIN_ID
- name: Check BATCH_PROOF_BITCOIN_ID
id: check-id
uses: ./.github/actions/validate-bitcoin-da
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
run: |
cargo build --release
- name: Check BATCH_PROVER_BITCOIN_ID
- name: Check BATCH_PROOF_BITCOIN_ID
id: check-id
uses: ./.github/actions/validate-bitcoin-da
with:
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
source $HOME/.cargo/env
cargo build --release
- name: Check BATCH_PROVER_BITCOIN_ID
- name: Check BATCH_PROOF_BITCOIN_ID
id: check-id
uses: ./.github/actions/validate-bitcoin-da
with:
Expand Down
13 changes: 7 additions & 6 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 bin/citrea/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ rustc_version_runtime = { workspace = true }
# bitcoin-e2e dependencies
bitcoin.workspace = true
bitcoincore-rpc.workspace = true
citrea-e2e = { git = "https://github.com/chainwayxyz/citrea-e2e", rev = "bdbd991" }
citrea-e2e = { git = "https://github.com/chainwayxyz/citrea-e2e", rev = "bd8ece7" }

[build-dependencies]
sp1-helper = { version = "3.0.0", default-features = false }
Expand Down
7 changes: 6 additions & 1 deletion bin/citrea/provers/risc0/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ resolver = "2"
risc0-build = { workspace = true }

[package.metadata.risc0]
methods = ["batch-prover-bitcoin", "batch-prover-mock", "light-client-prover-bitcoin", "light-client-prover-mock"]
methods = [
"batch-proof-bitcoin",
"batch-proof-mock",
"light-client-proof-bitcoin",
"light-client-proof-mock",
]

[features]
bench = []

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

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "batch-prover-bitcoin"
name = "batch-proof-bitcoin"
version = "0.5.0-rc.1"
edition = "2021"
resolver = "2"
Expand Down

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

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "batch-prover-mock"
name = "batch-proof-mock"
version = "0.5.0-rc.1"
edition = "2021"
resolver = "2"
Expand Down
24 changes: 12 additions & 12 deletions bin/citrea/provers/risc0/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ fn main() {
let methods_path = out_dir.join("methods.rs");

let elf = r#"
pub const BATCH_PROVER_BITCOIN_ELF: &[u8] = &[];
pub const BATCH_PROVER_BITCOIN_ID: [u32; 8] = [0u32; 8];
pub const BATCH_PROVER_MOCK_ELF: &[u8] = &[];
pub const BATCH_PROVER_MOCK_ID: [u32; 8] = [0u32; 8];
pub const LIGHT_CLIENT_PROVER_BITCOIN_ELF: &[u8] = &[];
pub const LIGHT_CLIENT_PROVER_BITCOIN_ID: [u32; 8] = [0u32; 8];
pub const LIGHT_CLIENT_PROVER_MOCK_ELF: &[u8] = &[];
pub const LIGHT_CLIENT_PROVER_MOCK_ID: [u32; 8] = [0u32; 8];
pub const BATCH_PROOF_BITCOIN_ELF: &[u8] = &[];
pub const BATCH_PROOF_BITCOIN_ID: [u32; 8] = [0u32; 8];
pub const BATCH_PROOF_MOCK_ELF: &[u8] = &[];
pub const BATCH_PROOF_MOCK_ID: [u32; 8] = [0u32; 8];
pub const LIGHT_CLIENT_PROOF_BITCOIN_ELF: &[u8] = &[];
pub const LIGHT_CLIENT_PROOF_BITCOIN_ID: [u32; 8] = [0u32; 8];
pub const LIGHT_CLIENT_PROOF_MOCK_ELF: &[u8] = &[];
pub const LIGHT_CLIENT_PROOF_MOCK_ID: [u32; 8] = [0u32; 8];
"#;

return std::fs::write(methods_path, elf).expect("Failed to write mock rollup elf");
Expand Down Expand Up @@ -62,28 +62,28 @@ fn get_guest_options() -> HashMap<&'static str, risc0_build::GuestOptions> {
};

guest_pkg_to_options.insert(
"batch-prover-bitcoin",
"batch-proof-bitcoin",
GuestOptions {
features: features.clone(),
use_docker: use_docker.clone(),
},
);
guest_pkg_to_options.insert(
"batch-prover-mock",
"batch-proof-mock",
GuestOptions {
features: features.clone(),
use_docker: use_docker.clone(),
},
);
guest_pkg_to_options.insert(
"light-client-prover-bitcoin",
"light-client-proof-bitcoin",
GuestOptions {
features: features.clone(),
use_docker: use_docker.clone(),
},
);
guest_pkg_to_options.insert(
"light-client-prover-mock",
"light-client-proof-mock",
GuestOptions {
features: features.clone(),
use_docker: use_docker.clone(),
Expand Down

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

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "light-client-prover-bitcoin"
name = "light-client-proof-bitcoin"
version = "0.5.0-rc.1"
edition = "2021"
resolver = "2"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#![no_main]
use bitcoin_da::spec::{BitcoinSpec, RollupParams};
use bitcoin_da::spec::RollupParams;
use bitcoin_da::verifier::BitcoinVerifier;
use citrea_light_client_prover::circuit::run_circuit;
use citrea_light_client_prover::input::LightClientCircuitInput;
use citrea_primitives::{REVEAL_BATCH_PROOF_PREFIX, REVEAL_LIGHT_CLIENT_PREFIX};
use sov_risc0_adapter::guest::Risc0Guest;
use sov_rollup_interface::da::DaVerifier;
Expand All @@ -13,14 +12,12 @@ risc0_zkvm::guest::entry!(main);
pub fn main() {
let guest = Risc0Guest::new();

let input: LightClientCircuitInput<BitcoinSpec> = guest.read_from_host();

let da_verifier = BitcoinVerifier::new(RollupParams {
reveal_batch_prover_prefix: REVEAL_BATCH_PROOF_PREFIX.to_vec(),
reveal_light_client_prefix: REVEAL_LIGHT_CLIENT_PREFIX.to_vec(),
});

let output = run_circuit::<BitcoinVerifier>(input, da_verifier).unwrap();
let output = run_circuit::<BitcoinVerifier, Risc0Guest>(da_verifier, &guest).unwrap();

guest.commit(&output);
}

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

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "light-client-prover-mock"
name = "light-client-proof-mock"
version = "0.5.0-rc.1"
edition = "2021"
resolver = "2"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![no_main]
use citrea_light_client_prover::circuit::run_circuit;
use citrea_light_client_prover::input::LightClientCircuitInput;
use sov_mock_da::{MockDaSpec, MockDaVerifier};
use sov_mock_da::MockDaVerifier;
use sov_risc0_adapter::guest::Risc0Guest;
use sov_rollup_interface::zk::ZkvmGuest;

Expand All @@ -10,11 +9,9 @@ risc0_zkvm::guest::entry!(main);
pub fn main() {
let guest = Risc0Guest::new();

let input: LightClientCircuitInput<MockDaSpec> = guest.read_from_host();

let da_verifier = MockDaVerifier {};

let output = run_circuit::<MockDaVerifier>(input, da_verifier).unwrap();
let output = run_circuit::<MockDaVerifier, Risc0Guest>(da_verifier, &guest).unwrap();

guest.commit(&output);
}
8 changes: 4 additions & 4 deletions bin/citrea/src/rollup/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl RollupBlueprint for BitcoinRollup {
let mut map = HashMap::new();
map.insert(
SpecId::Genesis,
Digest::new(citrea_risc0::BATCH_PROVER_BITCOIN_ID),
Digest::new(citrea_risc0::BATCH_PROOF_BITCOIN_ID),
);
// let (_, vk) = citrea_sp1::host::CLIENT.setup(include_bytes!("../../provers/sp1/batch-prover-bitcoin/elf/zkvm-elf"));
// map.insert(SpecId::Genesis, vk);
Expand All @@ -110,7 +110,7 @@ impl RollupBlueprint for BitcoinRollup {

#[instrument(level = "trace", skip(self), ret)]
fn get_light_client_prover_code_commitment(&self) -> <Self::Vm as Zkvm>::CodeCommitment {
Digest::new(citrea_risc0::LIGHT_CLIENT_PROVER_BITCOIN_ID)
Digest::new(citrea_risc0::LIGHT_CLIENT_PROOF_BITCOIN_ID)
}

#[instrument(level = "trace", skip_all, err)]
Expand Down Expand Up @@ -173,7 +173,7 @@ impl RollupBlueprint for BitcoinRollup {
ledger_db: LedgerDB,
) -> Self::ProverService {
let vm = Risc0BonsaiHost::new(
citrea_risc0::BATCH_PROVER_BITCOIN_ELF,
citrea_risc0::BATCH_PROOF_BITCOIN_ELF,
std::env::var("BONSAI_API_URL").unwrap_or("".to_string()),
std::env::var("BONSAI_API_KEY").unwrap_or("".to_string()),
ledger_db.clone(),
Expand Down Expand Up @@ -211,7 +211,7 @@ impl RollupBlueprint for BitcoinRollup {
ledger_db: LedgerDB,
) -> Self::ProverService {
let vm = Risc0BonsaiHost::new(
citrea_risc0::LIGHT_CLIENT_PROVER_BITCOIN_ELF,
citrea_risc0::LIGHT_CLIENT_PROOF_BITCOIN_ELF,
std::env::var("BONSAI_API_URL").unwrap_or("".to_string()),
std::env::var("BONSAI_API_KEY").unwrap_or("".to_string()),
ledger_db.clone(),
Expand Down
8 changes: 4 additions & 4 deletions bin/citrea/src/rollup/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ impl RollupBlueprint for MockDemoRollup {
let mut map = HashMap::new();
map.insert(
SpecId::Genesis,
Digest::new(citrea_risc0::BATCH_PROVER_MOCK_ID),
Digest::new(citrea_risc0::BATCH_PROOF_MOCK_ID),
);
map
}

fn get_light_client_prover_code_commitment(&self) -> <Self::Vm as Zkvm>::CodeCommitment {
Digest::new(citrea_risc0::LIGHT_CLIENT_PROVER_MOCK_ID)
Digest::new(citrea_risc0::LIGHT_CLIENT_PROOF_MOCK_ID)
}

async fn create_da_service(
Expand All @@ -119,7 +119,7 @@ impl RollupBlueprint for MockDemoRollup {
ledger_db: LedgerDB,
) -> Self::ProverService {
let vm = Risc0BonsaiHost::new(
citrea_risc0::BATCH_PROVER_MOCK_ELF,
citrea_risc0::BATCH_PROOF_MOCK_ELF,
std::env::var("BONSAI_API_URL").unwrap_or("".to_string()),
std::env::var("BONSAI_API_KEY").unwrap_or("".to_string()),
ledger_db.clone(),
Expand Down Expand Up @@ -147,7 +147,7 @@ impl RollupBlueprint for MockDemoRollup {
ledger_db: LedgerDB,
) -> Self::ProverService {
let vm = Risc0BonsaiHost::new(
citrea_risc0::LIGHT_CLIENT_PROVER_MOCK_ELF,
citrea_risc0::LIGHT_CLIENT_PROOF_MOCK_ELF,
std::env::var("BONSAI_API_URL").unwrap_or("".to_string()),
std::env::var("BONSAI_API_KEY").unwrap_or("".to_string()),
ledger_db.clone(),
Expand Down
Loading

0 comments on commit ca7a8d0

Please sign in to comment.