Skip to content

Commit

Permalink
Bump version (more documentation).
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaker committed Jan 30, 2024
1 parent d726f04 commit e415ef8
Show file tree
Hide file tree
Showing 7 changed files with 517 additions and 504 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

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

19 changes: 11 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nimue"
version = "0.0.1-beta6"
version = "0.0.1-beta10"
authors = ["Michele Orrù <[email protected]>"]
description = "A library for Fiat-Shamir transcripts."
edition = "2021"
Expand All @@ -12,8 +12,9 @@ ark-std = {git = "https://github.com/arkworks-rs/utils"}
ark-ec = {git = "https://github.com/arkworks-rs/algebra"}
ark-ff = {git = "https://github.com/arkworks-rs/algebra"}
ark-serialize = {git = "https://github.com/arkworks-rs/algebra"}
ark-serialize-derive = {git = "https://github.com/arkworks-rs/algebra"}
ark-bls12-381 = {git = "https://github.com/arkworks-rs/algebra"}
ark-curve25519 = {git = "https://github.com/arkworks-rs/algebra"}


[dependencies]
zeroize = {version="1.6.0", features=["zeroize_derive"]}
Expand All @@ -27,25 +28,27 @@ log = "0.4.20"
ark-ff = {version="0.4.0", optional=true}
ark-ec = {version="0.4.0", optional=true}
ark-serialize = {version="0.4.2", optional=true, features=["std"]}
curve25519-dalek = {version="4.0.0", optional=true, features=["group"]}
# anemoi = {git = "https://github.com/anemoi-hash/anemoi-rust", optional=true}
group = {version="0.13.0", optional=true}
ark-bls12-381 = {version="0.4.0", optional=true}

[features]
default = []
ark = ["dep:ark-ff", "dep:ark-ec", "dep:ark-serialize", "dep:ark-bls12-381"]
group = ["dep:group", "dep:curve25519-dalek"]
ark = ["dep:ark-ff", "dep:ark-ec", "dep:ark-serialize"] # "dep:ark-bls12-381"
group = ["dep:group"]
# anemoi = ["dep:anemoi"]

[dev-dependencies]
ark-std = "0.4.0"
sha2 = "0.10.7"
blake2 = "0.10.6"
ark-curve25519 = "0.4.0"
hex = "0.4.3"
anyhow = { version = "1.0.75", features = ["backtrace"] }
# test curve25519 compatibility
curve25519-dalek = {version="4.0.0", features=["group"]}
ark-curve25519 = "0.4.0"
# test algebraic hashers
ark-bls12-381 = {version="0.4.0"}

anyhow = { version = "1.0.75", features = ["backtrace"] }

[package.metadata.docs.rs]
rustdoc-args = [
Expand Down
27 changes: 11 additions & 16 deletions examples/schnorr_algebraic_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,13 @@ where
Merlin<'a, H, U>: GroupReader<G> + FieldReader<G::BaseField> + ByteChallenges,
{
// Read the protocol from the transcript:
let [K] = merlin.next_points().unwrap();
let c_bytes = merlin.challenge_bytes::<16>().unwrap();
let [K] = merlin.next_points()?;
let c_bytes = merlin.challenge_bytes::<16>()?;
let c = G::ScalarField::from_le_bytes_mod_order(&c_bytes);
let [r_q] = merlin.next_scalars().unwrap();
// Map the response to the field of the hash function to be absorbed easilty.
let [r_q] = merlin.next_scalars()?;
let r = swap_field::<G::BaseField, G::ScalarField>(r_q)?;

// Check the verification equation, otherwise return a verification error.
// The type ProofError is an enum that can report:
// - InvalidProof: the proof is not valid
// - InvalidIO: the transcript does not match the IO pattern
// - SerializationError: there was an error serializing/deserializing an element
if P * r == K + X * c {
Ok(())
} else {
Expand All @@ -127,19 +123,18 @@ where

#[allow(non_snake_case)]
fn main() {
// Instantiate the group and the random oracle:
// Set the group:
// Choose the group:
type G = ark_bls12_381::G1Projective;
type Fq = ark_bls12_381::Fq;

// Set the hash function (commented out other valid choices):
// type H = nimue::hash::Keccak;
// type H = nimue::hash::legacy::DigestBridge<blake2::Blake2s256>;
type H = nimue::hash::legacy::DigestBridge<blake2::Blake2s256>;
// type H = nimue::hash::legacy::DigestBridge<sha2::Sha256>;
type H = nimue::plugins::ark::poseidon::PoseidonHash;
// type H = nimue::plugins::ark::poseidon::PoseidonHash;

//
// type U = u8;
type U = Fq;
// Unit type where the hash function works over.
type U = u8;
// type U = ark_bls12_381::Fq;

// Set up the IO for the protocol transcript with domain separator "nimue::examples::schnorr"
let io = IOPattern::<H, U>::new("nimue::examples::schnorr");
Expand Down
15 changes: 10 additions & 5 deletions src/plugins/ark/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/// Common utilities for adding public elements to the protocol transcript.
mod common;
/// IO Pattern utilities.
mod iopattern;
/// (WIP) Support for the Poseidon Hash function.
pub mod poseidon;
/// Veririfer's utilities for decoding a transcript.
mod reader;
/// Prover's utilities for encoding into a transcript.
mod writer;
// poseidon support
pub mod poseidon;

#[cfg(feature = "anemoi")]
pub mod anemoi;
Expand All @@ -12,11 +16,12 @@ pub use crate::traits::*;
pub use crate::{hash::Unit, Arthur, DuplexHash, IOPattern, Merlin, ProofError, ProofResult, Safe};

super::traits::field_traits!(ark_ff::Field);
super::traits::group_traits!(ark_ec::CurveGroup, G::BaseField : ark_ff::PrimeField);
super::traits::group_traits!(ark_ec::CurveGroup, Scalar: ark_ff::PrimeField);

/// Move a value from freld F1 to field F2 to another.
/// Move a value from prime field F1 to prime field F2.
///
/// Return an error if the value is larger than the destination field.
/// Return an error if the element considered mod |F1| is different, when seen as an integer, mod |F2|.
/// This in particular happens when element > |F2|.
pub fn swap_field<F1: ark_ff::PrimeField, F2: ark_ff::PrimeField>(a_f1: F1) -> ProofResult<F2> {
use ark_ff::BigInteger;
let a_f2 = F2::from_le_bytes_mod_order(&a_f1.into_bigint().to_bytes_le());
Expand Down
Loading

0 comments on commit e415ef8

Please sign in to comment.