Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
feat: no_std compatibility (#8)
Browse files Browse the repository at this point in the history
* wip: no_std compatibility

* feat: the only issue is the use of HashMap and rand

* no std compatibility

* order

* dep cleanup
  • Loading branch information
ratankaliani authored Oct 11, 2024
1 parent 96bce20 commit 782a6fe
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 27 deletions.
25 changes: 11 additions & 14 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion examples/script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ clap = { version = "4.0", features = ["derive", "env"] }
hex = "0.4.3"
num-bigint = "0.4.6"
num-traits = "0.2.19"
sp1-prover = "2.0.0"
sp1-sdk = "2.0.0"
strum = "0.25"
strum_macros = "0.25"
Expand Down
5 changes: 1 addition & 4 deletions verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ version = "1.0.2"

[dependencies]
bn = { git = "https://github.com/sp1-patches/bn", branch = "patch-v0.7.0", package = "substrate-bn" }
lazy_static = "1.5.0"
num-bigint = "0.4.6"
num-traits = "0.2.19"
rand = "0.8.5"
sha2 = "0.10.8"
thiserror = "1.0.63"
thiserror-no-std = "2.0.2"
2 changes: 1 addition & 1 deletion verifier/src/converter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::cmp::Ordering;
use core::cmp::Ordering;

use bn::{AffineG1, AffineG2, Fq, Fq2};

Expand Down
2 changes: 1 addition & 1 deletion verifier/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bn::{CurveError, FieldError, GroupError};
use thiserror::Error;
use thiserror_no_std::Error;

#[derive(Error, Debug)]
pub enum Error {
Expand Down
1 change: 1 addition & 0 deletions verifier/src/groth16/converter.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloc::{vec, vec::Vec};
use bn::AffineG1;

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion verifier/src/groth16/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use thiserror::Error;
use thiserror_no_std::Error;

#[derive(Debug, Error)]
pub enum Groth16Error {
Expand Down
1 change: 1 addition & 0 deletions verifier/src/groth16/verify.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloc::vec::Vec;
use bn::{pairing, pairing_batch, AffineG1, AffineG2, Fr, Gt, G1, G2};

use super::error::Groth16Error;
Expand Down
2 changes: 2 additions & 0 deletions verifier/src/hash_to_field.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use alloc::vec;
use alloc::vec::Vec;
use core::hash::Hasher;
use sha2::Digest;

Expand Down
2 changes: 2 additions & 0 deletions verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#![deny(missing_docs)]

//! This crate provides verifiers for Groth16 and Plonk zero-knowledge proofs.
#![no_std]
extern crate alloc;

use bn::Fr;
use groth16::{
Expand Down
1 change: 1 addition & 0 deletions verifier/src/plonk/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
},
error::Error,
};
use alloc::vec::Vec;
use bn::{AffineG1, Fr, G2};

use super::{
Expand Down
2 changes: 1 addition & 1 deletion verifier/src/plonk/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use thiserror::Error;
use thiserror_no_std::Error;

#[derive(Error, Debug)]
pub enum PlonkError {
Expand Down
1 change: 1 addition & 0 deletions verifier/src/plonk/kzg.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloc::{string::ToString, vec, vec::Vec};
use bn::{pairing_batch, AffineG1, Fr, G1, G2};
use rand::rngs::OsRng;

Expand Down
2 changes: 2 additions & 0 deletions verifier/src/plonk/proof.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use alloc::vec::Vec;

use super::kzg::{BatchOpeningProof, Digest, OpeningProof};

#[derive(Debug)]
Expand Down
1 change: 1 addition & 0 deletions verifier/src/plonk/verify.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloc::{string::ToString, vec, vec::Vec};
use bn::{arith::U256, AffineG1, Fr};
use core::hash::Hasher;

Expand Down
8 changes: 4 additions & 4 deletions verifier/src/transcript.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloc::{collections::btree_map::BTreeMap, string::String, vec::Vec};
use sha2::{Digest, Sha256};
use std::collections::HashMap;

use crate::error::Error;

Expand All @@ -15,7 +15,7 @@ pub(crate) struct Challenge {
pub(crate) struct Transcript {
pub(crate) h: Sha256,

pub(crate) challenges: HashMap<String, Challenge>,
pub(crate) challenges: BTreeMap<String, Challenge>,
previous_challenge: Option<Challenge>,
}

Expand All @@ -24,7 +24,7 @@ impl Transcript {
let h = Sha256::new();

if let Some(challenges_id) = challenges_id {
let mut challenges = HashMap::new();
let mut challenges = BTreeMap::new();
for (position, id) in challenges_id.iter().enumerate() {
challenges.insert(
id.clone(),
Expand All @@ -45,7 +45,7 @@ impl Transcript {
} else {
Ok(Transcript {
h,
challenges: HashMap::new(),
challenges: BTreeMap::new(),
previous_challenge: None,
})
}
Expand Down

0 comments on commit 782a6fe

Please sign in to comment.