Skip to content

Commit

Permalink
Generate padding using TAI
Browse files Browse the repository at this point in the history
  • Loading branch information
davxy committed Sep 18, 2024
1 parent 78b30bb commit 105b1e7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
1 change: 0 additions & 1 deletion ring/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ rayon = { workspace = true, optional = true }
common = { path = "../common", default-features = false }
blake2 = { version = "0.10", default-features = false }
arrayvec = { version = "0.7", default-features = false }
rand_chacha = { version = "0.3", default-features = false }
ark-transcript = { git = "https://github.com/w3f/ring-vrf", default-features = false }

[dev-dependencies]
Expand Down
20 changes: 19 additions & 1 deletion ring/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg_attr(not(feature = "std"), no_std)]

use ark_ec::short_weierstrass::{Affine, SWCurveConfig};
use ark_ec::{short_weierstrass::{Affine, SWCurveConfig}, AffineRepr};
use ark_ff::{One, PrimeField, Zero};
use ark_serialize::CanonicalSerialize;
use ark_std::rand::RngCore;
Expand Down Expand Up @@ -35,6 +35,24 @@ pub fn find_complement_point<Curve: SWCurveConfig>() -> Affine<Curve> {
}
}

// Hash to curve using TAI
pub fn hash_to_curve<F: PrimeField, Curve: SWCurveConfig<BaseField = F>>(message: &[u8]) -> Affine<Curve> {
use blake2::Digest;
let mut seed = message.to_vec();
seed.push(0);
let cnt_offset = seed.len() - 1;
loop {
let hash: [u8; 64] = blake2::Blake2b::digest(&seed[..]).into();
let x = F::from_le_bytes_mod_order(&hash);
if let Some(point) = Affine::<Curve>::get_point_from_x_unchecked(x, false) {
let point = point.clear_cofactor();
assert!(point.is_in_correct_subgroup_assuming_on_curve());
return point
}
seed[cnt_offset] += 1;
}
}

#[derive(Clone)]
pub struct ArkTranscript(ark_transcript::Transcript);

Expand Down
8 changes: 1 addition & 7 deletions ring/src/piop/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ pub struct PiopParams<F: PrimeField, Curve: SWCurveConfig<BaseField=F>> {

impl<F: PrimeField, Curve: SWCurveConfig<BaseField=F>> PiopParams<F, Curve> {
pub fn setup(domain: Domain<F>, h: Affine<Curve>, seed: Affine<Curve>) -> Self {
let padding_point = {
use ark_std::{rand::SeedableRng, UniformRand};
use blake2::Digest;
let seed = blake2::Blake2b::digest(b"w3f/ring-proof/common/padding");
Affine::<Curve>::rand(&mut rand_chacha::ChaCha20Rng::from_seed(seed.into()))
};

let padding_point = crate::hash_to_curve(b"w3f/ring-proof/common/padding");
let scalar_bitlen = Curve::ScalarField::MODULUS_BIT_SIZE as usize;
// 1 accounts for the last cells of the points and bits columns that remain unconstrained
let keyset_part_size = domain.capacity - scalar_bitlen - 1;
Expand Down

0 comments on commit 105b1e7

Please sign in to comment.