Implement last hash and conversion

This commit is contained in:
Remco Bloemen 2022-03-11 15:01:20 -08:00
parent a7108109fc
commit 3de4debd55

View File

@ -13,6 +13,7 @@ use ark_relations::r1cs::SynthesisError;
use ark_std::{rand::thread_rng, UniformRand}; use ark_std::{rand::thread_rng, UniformRand};
use color_eyre::Result; use color_eyre::Result;
use ethers_core::utils::keccak256; use ethers_core::utils::keccak256;
use num_bigint::{BigInt, BigUint, ToBigInt};
use std::{collections::HashMap, fs::File, ops::Shr, time::Instant}; use std::{collections::HashMap, fs::File, ops::Shr, time::Instant};
use thiserror::Error; use thiserror::Error;
@ -35,8 +36,11 @@ fn merkle_proof_to_vec(proof: &merkle_tree::Proof<PoseidonHash>) -> Vec<Field> {
/// Internal helper to hash the signal to make sure it's in the field /// Internal helper to hash the signal to make sure it's in the field
fn hash_signal(signal: &[u8]) -> Field { fn hash_signal(signal: &[u8]) -> Field {
todo!() let hash = keccak256(signal);
// BigInt::from_bytes_be(Sign::Plus, &keccak256(signal)).shr(8) // Shift right one byte to make it fit in the field
let mut bytes = [0_u8; 32];
bytes[1..].copy_from_slice(&hash[..31]);
Field::from_be_bytes_mod_order(&bytes)
} }
/// Internal helper to hash the external nullifier /// Internal helper to hash the external nullifier
@ -68,8 +72,9 @@ pub enum ProofError {
SynthesisError(#[from] SynthesisError), SynthesisError(#[from] SynthesisError),
} }
fn ark_to_bigint(n: Field) -> num_bigint::BigInt { fn ark_to_bigint(n: Field) -> BigInt {
todo!() let n: BigUint = n.into();
n.to_bigint().expect("conversion always succeeds for uint")
} }
/// Generates a semaphore proof /// Generates a semaphore proof