risc0_zkp/
lib.rs

1// Copyright 2024 RISC Zero, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#![doc = include_str!("../README.md")]
16#![cfg_attr(not(feature = "std"), no_std)]
17#![deny(rustdoc::broken_intra_doc_links)]
18#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
19
20extern crate alloc;
21
22pub mod adapter;
23pub mod core;
24#[cfg(feature = "prove")]
25pub mod hal;
26pub mod layout;
27mod merkle;
28#[cfg(feature = "prove")]
29pub mod prove;
30pub mod taps;
31pub mod verify;
32
33#[cfg(not(feature = "prove"))]
34pub mod hal {
35    pub mod cpu {
36        use core::marker::PhantomData;
37        // TODO: Don't depend on SyncSlice in non-proving code.
38        pub struct SyncSlice<T>(PhantomData<T>);
39    }
40}
41
42pub use risc0_core::field;
43
44pub const MIN_CYCLES_PO2: usize = 13;
45pub const MIN_CYCLES: usize = 1 << MIN_CYCLES_PO2; // 8K
46pub const MAX_CYCLES_PO2: usize = 24;
47pub const MAX_CYCLES: usize = 1 << MAX_CYCLES_PO2; // 16M
48
49/// 50 FRI queries is sufficient to achieve our security target of 97 bits (conjectured security)
50pub const QUERIES: usize = 50;
51pub const ZK_CYCLES: usize = 1994; // TODO: Ideally we'd compute ZK_CYCLES programmatically
52pub const MIN_PO2: usize = core::log2_ceil(1 + ZK_CYCLES);
53
54/// Inverse of Reed-Solomon Expansion Rate
55pub const INV_RATE: usize = 4;
56
57const FRI_FOLD_PO2: usize = 4;
58
59/// FRI folding factor is 2 ^ FRI_FOLD_PO2
60pub const FRI_FOLD: usize = 1 << FRI_FOLD_PO2;
61
62/// FRI continues until the degree of the FRI polynomial reaches FRI_MIN_DEGREE
63const FRI_MIN_DEGREE: usize = 256;