Skip to content

Commit

Permalink
name (#835)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-lj authored Sep 13, 2024
1 parent bc45da8 commit ff4c32a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
7 changes: 5 additions & 2 deletions fastcrypto-cli/src/vdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,11 @@ fn execute(cmd: Command) -> Result<String, Error> {
Command::Hash(arguments) => {
let input = hex::decode(arguments.message)
.map_err(|_| Error::new(ErrorKind::InvalidInput, "Invalid message."))?;
let output = QuadraticForm::hash_to_group(&input, &DISCRIMINANT_3072)
.map_err(|_| Error::new(ErrorKind::InvalidInput, "The discriminant is invalid."))?;
let output =
QuadraticForm::hash_to_group_with_default_parameters(&input, &DISCRIMINANT_3072)
.map_err(|_| {
Error::new(ErrorKind::InvalidInput, "The discriminant is invalid.")
})?;

let output_bytes = hex::encode(bcs::to_bytes(&output).unwrap());

Expand Down
8 changes: 5 additions & 3 deletions fastcrypto-vdf/benches/class_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ fn class_group_ops_single<M: Measurement>(
let discriminant =
Discriminant::try_from(BigInt::from_str_radix(discriminant_string, 10).unwrap()).unwrap();
let discriminant_size = discriminant.bits();
let x = QuadraticForm::hash_to_group(&[0, 1, 2], &discriminant).unwrap();
let y = QuadraticForm::hash_to_group(&[3, 4, 5], &discriminant).unwrap();
let x =
QuadraticForm::hash_to_group_with_default_parameters(&[0, 1, 2], &discriminant).unwrap();
let y =
QuadraticForm::hash_to_group_with_default_parameters(&[3, 4, 5], &discriminant).unwrap();
let z = y.clone();

group.bench_function(format!("Compose/{}", discriminant_size), move |b| {
Expand Down Expand Up @@ -51,7 +53,7 @@ fn hash_to_class_group_single<M: Measurement>(
group.bench_function(format!("{} bits, default", bits), move |b| {
let mut seed = [0u8; 32];
thread_rng().fill_bytes(&mut seed);
b.iter(|| QuadraticForm::hash_to_group(&seed, &discriminant))
b.iter(|| QuadraticForm::hash_to_group_with_default_parameters(&seed, &discriminant))
});
}

Expand Down
8 changes: 6 additions & 2 deletions fastcrypto-vdf/src/class_group/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ impl QuadraticForm {
///
/// This method returns an [InvalidInput] error if the discriminant is so small that there are
/// no secure parameters, and it may also happen if the discriminant is not a prime.
pub fn hash_to_group(seed: &[u8], discriminant: &Discriminant) -> FastCryptoResult<Self> {
pub fn hash_to_group_with_default_parameters(
seed: &[u8],
discriminant: &Discriminant,
) -> FastCryptoResult<Self> {
if discriminant.bits() <= MINIMAL_DISCRIMINANT_SIZE {
return Err(InvalidInput);
}
Expand Down Expand Up @@ -285,7 +288,8 @@ mod tests {
fn qf_default_hash_test() {
let discriminant = Discriminant::from_trusted_bigint(-BigInt::from_str_radix("c3811f4ad2f4a7bdf2ed89385866ad526c6dd3aa942e04c141d0562a8e7b014f08804f47b3c2ecbba0a5a0ad8f4d8e869a10cff13dbc522aea141f6d1c42913f2d3bff8d3e7656c72523a2e9d47f838234bd65f05ef3ca86c2f640bca6630ed8d1da21e30a67f83e25b89c32c2d0dc0bacb81bd971b0932a82d131b4a74bff36b60b66543105da2c3ecb1a4e8c2cb6d47c1e85942cce8f3fc50c27856e6dfbd15c0bd5017fea15ae0eb43dfb32b2d947c3131d1951f00bcc40352eeb65e364551e40d13768f443406760ee6b37a5b5819d3f630c034c7f42212ad49c803772aaafd4cd1f87697c68d5a6b0855f475b370b20058558993e76759caa38edbc82407b4e3559bade5f7479a860ebef62fed82d657765ebb8f7f375c2b78f73669760e4bd4932177087a49a0b68d7", 16).unwrap());

let qf = QuadraticForm::hash_to_group(b"seed", &discriminant).unwrap();
let qf =
QuadraticForm::hash_to_group_with_default_parameters(b"seed", &discriminant).unwrap();
assert_eq!(bcs::to_bytes(&qf).unwrap(), hex::decode("2300a0f9131173334d92c14bbc1d83d411168de882cb1e387b48a5194006c58632e9a9c33269cc033517c7d6b299377c647ba53aded9e27341dd4b941716b9e5191144864791c162fd9e52c5572ff85beae15ebdd9a2ab8a024dbaa59598e97587ae8ecb848611552c21b4a7a32ee1a69dc968dbc37b67774712a9ca92d630113853952ec9d55c737738c59bfcd452ab7f45d1c8df8ce405f55de4392d85d96428a8f1b547b44a11a2b418f5b4ccbd5385723fd34e60a7e3a4b8ac812addf27ace931c3450f989eae8c382e1f9181914e96a35902e6ef5fe972b7d0a1562d7274a68256de34a228c5260df099baa42a13cc011713dd246f149cb085b5002701e95c1a9c7b61467aefab791d9793bfed8c3ebfb251fe0d8f578b165d79b2cb8109cd6b62f84405f659668b9580fffd6f7631f66079ec18846a9e9feb75c128e318914ff93fcb24152ba7c655131af3a75832b37a5024c8095a13faadd23723b90c586ec").unwrap());
}
}
4 changes: 3 additions & 1 deletion fastcrypto-vdf/src/class_group/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ fn test_qf_to_from_bytes() {
fn test_large_qf_to_from_bytes() {
assert_eq!(DISCRIMINANT_3072.bits(), 3072);

let expected = QuadraticForm::hash_to_group(&[1, 2, 3], &DISCRIMINANT_3072).unwrap();
let expected =
QuadraticForm::hash_to_group_with_default_parameters(&[1, 2, 3], &DISCRIMINANT_3072)
.unwrap();
let bytes = bcs::to_bytes(&expected).unwrap();
let actual = bcs::from_bytes(&bytes).unwrap();
assert_eq!(expected, actual);
Expand Down
6 changes: 5 additions & 1 deletion fastcrypto-vdf/src/vdf/wesolowski.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ mod tests {
);

// Compute the VDF input from the combined randomness
let input = QuadraticForm::hash_to_group(&combined_randomness, &DISCRIMINANT_3072).unwrap();
let input = QuadraticForm::hash_to_group_with_default_parameters(
&combined_randomness,
&DISCRIMINANT_3072,
)
.unwrap();
assert_eq!(bcs::to_bytes(&input).unwrap(), hex::decode("2300b094d4facc4b552df23714f5d09a6ddfde4f0d06163b7fda1fc022ebafa5be196f4d33fc3bce80649d3e64cb6d1497bf65f6b40ffcf5ca3211889b994019cf4dfa8697b0f69a70c5ee14ef438cf0e50b2f93786f506fde02412ad75a441ab785dbe34ce00cb829962e4216f964fb8c53852cc86e0977428322ef7d505e10c37260a9ebeb0cc66ddb59901556bc4a6fa9bc0f9d8159c3319f3a2e1781912000917a12054126a728b46dc6849cda81648e0f34200824a050fd1e01382bf4cfa17019ae2f6f48cfbe6e4ef84e1b00361ed6a4892e4b5db94e8847e0c7050637d668c5cbef08fc60fde9b5d68a02af4c5ed7f7ba99f3b68eb59fa2ea8a282b705124ec5577f166130a0c043823ea1a3fd495643dfbe8d294a9f034d91f8c8e76689a676ebe1ded776bdf7fd1e4050a84b8cead2e6adcd0ae7d12a6e221cb6579eb54911d3ce9739048924f3451c07b203ab811a9506d4d134b335eab6e84c49983f405f3d5b2040c522922e501086c19db5a82a4c7134a7cad5738bc884b382e4b3cfca0521a0e7eacd0d053855dcbb6fa897f122cc2b49df60d4d3424d37a01764b77b65b5f5472365ae3b82a3cb7f9f7a13d4a6ca100c4").unwrap());

// Compute the output of the VDF
Expand Down

0 comments on commit ff4c32a

Please sign in to comment.