arkworks_utils/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2
3#[macro_use]
4extern crate ark_std;
5
6use ark_ff::PrimeField;
7pub use ark_std::vec::Vec;
8pub use hex::FromHexError;
9
10pub mod mimc_params;
11pub mod poseidon_params;
12
13type Bytes = Vec<u8>;
14
15#[derive(Copy, Clone)]
16pub enum Curve {
17	Bls381,
18	Bn254,
19}
20
21pub fn decode_hex(s: &str) -> Result<Bytes, FromHexError> {
22	let s = &s[2..];
23	hex::decode(s)
24}
25
26pub fn parse_vec(arr: Vec<&str>) -> Result<Vec<Bytes>, FromHexError> {
27	let mut res = Vec::new();
28	for r in arr.iter() {
29		res.push(decode_hex(r)?);
30	}
31	Ok(res)
32}
33
34pub fn parse_matrix(mds_entries: Vec<Vec<&str>>) -> Result<Vec<Vec<Bytes>>, FromHexError> {
35	let width = mds_entries.len();
36	let mut mds = vec![vec![Vec::new(); width]; width];
37	for i in 0..width {
38		for j in 0..width {
39			mds[i][j] = decode_hex(mds_entries[i][j])?;
40		}
41	}
42	Ok(mds)
43}
44
45pub fn bytes_vec_to_f<F: PrimeField>(bytes_vec: &Vec<Vec<u8>>) -> Vec<F> {
46	bytes_vec
47		.iter()
48		.map(|x| F::from_be_bytes_mod_order(x))
49		.collect()
50}
51
52pub fn bytes_matrix_to_f<F: PrimeField>(bytes_matrix: &Vec<Vec<Vec<u8>>>) -> Vec<Vec<F>> {
53	bytes_matrix.iter().map(|x| bytes_vec_to_f(x)).collect()
54}