Skip to content

Commit

Permalink
Make the code more coherent and included also the 1.2 version in the …
Browse files Browse the repository at this point in the history
…local source.

- Some refactor
- removed unused files
  • Loading branch information
la10736 committed Dec 19, 2024
1 parent e5ddc99 commit 51f0734
Show file tree
Hide file tree
Showing 13 changed files with 45,244 additions and 269 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ description = "A Rust library to verify risc0 STARK proofs"
keywords = ["crypto", "no-std", "blockchain", "cryptography", "risc0"]

[dependencies]
serde = { version = "1.0.215", default-features = false, features = ["derive"] }
serde = { version = "1.0.216", default-features = false, features = ["derive"] }
ciborium = { version = "0.2.2", default-features = false }
risc0-core = { version = "=1.2.0", default-features = false }
risc0-zkp = { version = "=1.2.0", default-features = false }
risc0-binfmt = { version = "=1.2.0", default-features = false }
risc0-circuit-rv32im = { version = "=1.2.0", default-features = false }
risc0-circuit-recursion = { version = "=1.2.0", default-features = false }
anyhow = { version = "1.0.93", default-features = false }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
bytemuck = { version = "1.20.0", default-features = false }
Expand Down
219 changes: 3 additions & 216 deletions src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,222 +24,9 @@ impl<T: risc0_zkp::adapter::CircuitCoreDef<risc0_zkp::field::baby_bear::BabyBear
CircuitCoreDef for T
{
}
pub mod v1_0 {
use risc0_core::field::baby_bear::BabyBear;

use risc0_zkp::{
adapter::{CircuitCoreDef, CircuitInfo, ProtocolInfo},
taps::TapSet,
};
pub mod v1_0;

pub mod control_id;
mod poly_ext;
mod taps;
pub mod v1_1;

pub const CIRCUIT: CircuitImpl = CircuitImpl::new();
pub struct CircuitImpl;

impl CircuitImpl {
const fn new() -> Self {
CircuitImpl
}
}

impl risc0_zkp::adapter::TapsProvider for CircuitImpl {
fn get_taps(&self) -> &'static TapSet<'static> {
taps::TAPSET
}
}

impl CircuitInfo for CircuitImpl {
#[rustfmt::skip]
const CIRCUIT_INFO: ProtocolInfo = ProtocolInfo(*b"RV32IM:rev1v1___");

#[rustfmt::skip]
const OUTPUT_SIZE: usize = 138;

#[rustfmt::skip]
const MIX_SIZE: usize = 40;
}

impl CircuitCoreDef<BabyBear> for CircuitImpl {}

pub mod recursive {
use risc0_zkp::{
adapter::{CircuitCoreDef, CircuitInfo, ProtocolInfo, TapsProvider},
field::baby_bear::BabyBear,
taps::TapSet,
};

#[allow(dead_code)]
pub mod control_id;
mod poly_ext;
mod taps;

/// This struct implements traits that are defined by code generated by the
/// circuit definition.
pub struct CircuitImpl;

impl CircuitImpl {
const fn new() -> Self {
CircuitImpl
}
}

impl TapsProvider for CircuitImpl {
fn get_taps(&self) -> &'static TapSet<'static> {
self::taps::TAPSET
}
}

pub const CIRCUIT: CircuitImpl = CircuitImpl::new();

impl CircuitInfo for CircuitImpl {
#[rustfmt::skip]
const CIRCUIT_INFO: ProtocolInfo = ProtocolInfo(*b"RECURSION:rev1v1");

#[rustfmt::skip]
const OUTPUT_SIZE: usize = 32;

#[rustfmt::skip]
const MIX_SIZE: usize = 20;
}

impl CircuitCoreDef<BabyBear> for CircuitImpl {}
}
}

pub mod v1_1 {
use risc0_core::field::baby_bear::BabyBear;
use risc0_zkp::core::digest::Digest;

use risc0_zkp::{
adapter::{CircuitCoreDef, CircuitInfo, ProtocolInfo},
taps::TapSet,
};
use risc0_zkp::{MAX_CYCLES_PO2, MIN_CYCLES_PO2};

pub mod control_id;
mod poly_ext;
mod taps;

pub const CIRCUIT: CircuitImpl = CircuitImpl::new();

pub struct CircuitImpl;

impl CircuitImpl {
const fn new() -> Self {
CircuitImpl
}
}

impl risc0_zkp::adapter::TapsProvider for CircuitImpl {
fn get_taps(&self) -> &'static TapSet<'static> {
taps::TAPSET
}
}

impl CircuitInfo for CircuitImpl {
#[rustfmt::skip]
const CIRCUIT_INFO: ProtocolInfo = ProtocolInfo(*b"RV32IM:rev1v1___");

#[rustfmt::skip]
const OUTPUT_SIZE: usize = 138;

#[rustfmt::skip]
const MIX_SIZE: usize = 40;
}

impl CircuitCoreDef<BabyBear> for CircuitImpl {}

/// Fetch a control ID with the given hash, by name, and cycle limit as a power of two (po2) from
/// the precomputed table. If the hash function is not precomputed, or the po2 is out of range,
/// this function will return `None`.
///
/// Supported values for hash_name are "sha-256", "poseidon2", and "blake2b".
pub fn control_id(hash_name: &str, po2: usize) -> Option<Digest> {
if !(MIN_CYCLES_PO2..=MAX_CYCLES_PO2).contains(&po2) {
return None;
}
let idx = po2 - MIN_CYCLES_PO2;
use control_id::*;
match hash_name {
"sha-256" => Some(SHA256_CONTROL_IDS[idx]),
"poseidon2" => Some(POSEIDON2_CONTROL_IDS[idx]),
"blake2b" => Some(BLAKE2B_CONTROL_IDS[idx]),
_ => None,
}
}

pub mod recursive {
use risc0_zkp::{
adapter::{CircuitCoreDef, CircuitInfo, ProtocolInfo, TapsProvider},
field::baby_bear::BabyBear,
taps::TapSet,
};

#[allow(dead_code)]
pub mod control_id;
mod poly_ext;
mod taps;

/// This struct implements traits that are defined by code generated by the
/// circuit definition.
pub struct CircuitImpl;

impl CircuitImpl {
const fn new() -> Self {
CircuitImpl
}
}

impl TapsProvider for CircuitImpl {
fn get_taps(&self) -> &'static TapSet<'static> {
self::taps::TAPSET
}
}

pub const CIRCUIT: CircuitImpl = CircuitImpl::new();

impl CircuitInfo for CircuitImpl {
#[rustfmt::skip]
const CIRCUIT_INFO: ProtocolInfo = ProtocolInfo(*b"RECURSION:rev1v1");

#[rustfmt::skip]
const OUTPUT_SIZE: usize = 32;

#[rustfmt::skip]
const MIX_SIZE: usize = 20;
}

impl CircuitCoreDef<BabyBear> for CircuitImpl {}
}
}

pub mod v1_2 {
pub use risc0_circuit_rv32im::*;
use risc0_zkp::{core::digest::Digest, MAX_CYCLES_PO2, MIN_CYCLES_PO2};

/// Fetch a control ID with the given hash, by name, and cycle limit as a power of two (po2) from
/// the precomputed table. If the hash function is not precomputed, or the po2 is out of range,
/// this function will return `None`.
///
/// Supported values for hash_name are "sha-256", "poseidon2", and "blake2b".
pub fn control_id(hash_name: &str, po2: usize) -> Option<Digest> {
if !(MIN_CYCLES_PO2..=MAX_CYCLES_PO2).contains(&po2) {
return None;
}
let idx = po2 - MIN_CYCLES_PO2;
use control_id::*;
match hash_name {
"sha-256" => Some(SHA256_CONTROL_IDS[idx]),
"poseidon2" => Some(POSEIDON2_CONTROL_IDS[idx]),
"blake2b" => Some(BLAKE2B_CONTROL_IDS[idx]),
_ => None,
}
}

pub mod recursive {
pub use risc0_circuit_recursion::*;
}
}
pub mod v1_2;
99 changes: 99 additions & 0 deletions src/circuit/v1_0.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright Copyright 2024, Horizen Labs, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

use risc0_core::field::baby_bear::BabyBear;

use risc0_zkp::{
adapter::{CircuitCoreDef, CircuitInfo, ProtocolInfo},
taps::TapSet,
};

pub mod control_id;
mod poly_ext;
mod taps;

pub const CIRCUIT: CircuitImpl = CircuitImpl::new();
pub struct CircuitImpl;

impl CircuitImpl {
const fn new() -> Self {
CircuitImpl
}
}

impl risc0_zkp::adapter::TapsProvider for CircuitImpl {
fn get_taps(&self) -> &'static TapSet<'static> {
taps::TAPSET
}
}

impl CircuitInfo for CircuitImpl {
#[rustfmt::skip]
const CIRCUIT_INFO: ProtocolInfo = ProtocolInfo(*b"RV32IM:rev1v1___");

#[rustfmt::skip]
const OUTPUT_SIZE: usize = 138;

#[rustfmt::skip]
const MIX_SIZE: usize = 40;
}

impl CircuitCoreDef<BabyBear> for CircuitImpl {}

pub mod recursive {
use risc0_zkp::{
adapter::{CircuitCoreDef, CircuitInfo, ProtocolInfo, TapsProvider},
field::baby_bear::BabyBear,
taps::TapSet,
};

#[allow(dead_code)]
pub mod control_id;
mod poly_ext;
mod taps;

/// This struct implements traits that are defined by code generated by the
/// circuit definition.
pub struct CircuitImpl;

impl CircuitImpl {
const fn new() -> Self {
CircuitImpl
}
}

impl TapsProvider for CircuitImpl {
fn get_taps(&self) -> &'static TapSet<'static> {
self::taps::TAPSET
}
}

pub const CIRCUIT: CircuitImpl = CircuitImpl::new();

impl CircuitInfo for CircuitImpl {
#[rustfmt::skip]
const CIRCUIT_INFO: ProtocolInfo = ProtocolInfo(*b"RECURSION:rev1v1");

#[rustfmt::skip]
const OUTPUT_SIZE: usize = 32;

#[rustfmt::skip]
const MIX_SIZE: usize = 20;
}

impl CircuitCoreDef<BabyBear> for CircuitImpl {}
}
Loading

0 comments on commit 51f0734

Please sign in to comment.