Skip to content

Commit

Permalink
Changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
JackPiri committed Jun 3, 2024
1 parent fb87edc commit c223fb0
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 16 deletions.
2 changes: 1 addition & 1 deletion HEADER-APACHE2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024, The Horizen Foundation
// Copyright 2024, Horizen Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# risc0-verifier

A verifier for [RISC-Zero](https://github.com/risc0/risc0) STARK proofs. This crate
A verifier for [RISC-Zero](https://github.com/risc0/risc0) STARK proofs.

This crate provides a way for deserializing the proof and the verification key (aka image id) and a function to check if the proof is correct:

Expand Down
19 changes: 19 additions & 0 deletions resources/guest_1/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![no_main]
// If you want to try std support, also update the guest Cargo.toml file
#![no_std] // std support is experimental

use risc0_zkvm::guest::env;

risc0_zkvm::guest::entry!(main);

fn main() {
// TODO: Implement your guest code here

// read the input
let input: u32 = env::read();

let output = input + 1;

// write public output to the journal
env::commit(&output);
}
19 changes: 19 additions & 0 deletions resources/guest_2/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![no_main]
// If you want to try std support, also update the guest Cargo.toml file
#![no_std] // std support is experimental

use risc0_zkvm::guest::env;

risc0_zkvm::guest::entry!(main);

fn main() {
// TODO: Implement your guest code here

// read the input
let input: u32 = env::read();

let output = input;

// write public output to the journal
env::commit(&output);
}
2 changes: 1 addition & 1 deletion src/deserializer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024, The Horizen Foundation
// Copyright 2024, Horizen Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
23 changes: 23 additions & 0 deletions src/key.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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.

/// The verification key (aka image id, the hash of the guest program)
pub struct Vk(pub risc0_zkp::core::digest::Digest);

impl From<[u32; 8]> for Vk {
fn from(value: [u32; 8]) -> Self {
Self(value.into())
}
}
22 changes: 11 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024, The Horizen Foundation
// Copyright 2024, Horizen Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,20 +16,24 @@
#![cfg_attr(not(feature = "std"), no_std)]

mod deserializer;
mod key;
mod proof;

use deserializer::{deserialize, DeserializeError};
pub use key::Vk;
pub use proof::ProofRawData;
use snafu::Snafu;

/// Deserialization error.
#[derive(Debug, Snafu)]
pub enum VerifyError {
/// Invalid data (not deserializable)
#[snafu(display("Invalid data for verification: [{:?}]", cause))]
InvalidData {
#[snafu(source)]
cause: DeserializeError,
},
/// Verification failure
#[snafu(display("Failed to verify: [{:?}]", cause))]
Failure {
cause: risc0_zkp::verify::VerificationError,
Expand All @@ -48,15 +52,11 @@ impl From<risc0_zkp::verify::VerificationError> for VerifyError {
}
}

pub struct Vk(risc0_zkp::core::digest::Digest);

impl From<[u32; 8]> for Vk {
fn from(value: [u32; 8]) -> Self {
Self(value.into())
}
}

pub fn verify(proof: ProofRawData, image_id: Vk) -> Result<(), VerifyError> {
let receipt = deserialize(proof)?;
/// Verify the given proof raw data `proof` using verification key `image_id`.
/// Can fail if:
/// - the raw proof data is not serializable as a `risc0_zkvm::Receipt`
/// - the receipt is not valid for the given verification key
pub fn verify(raw_proof_data: ProofRawData, image_id: Vk) -> Result<(), VerifyError> {
let receipt = deserialize(raw_proof_data)?;
receipt.verify(image_id.0).map_err(Into::into)
}
3 changes: 2 additions & 1 deletion src/proof.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024, The Horizen Foundation
// Copyright 2024, Horizen Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,4 +13,5 @@
// See the License for the specific language governing permissions and
// limitations under the License.

/// The proof raw data (a serialized `risc0_zkvm::Receipt`).
pub type ProofRawData<'a> = &'a [u8];
2 changes: 1 addition & 1 deletion tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024, The Horizen Foundation
// Copyright 2024, Horizen Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down

0 comments on commit c223fb0

Please sign in to comment.