/* * Copyright 2024 by Ideal Labs, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #![allow(dead_code)] use crate::verifier::ArkScale; use ark_ec::AffineRepr; use ark_scale::hazmat::ArkScaleProjective; use ark_serialize::{CanonicalSerialize, Compress}; use ark_std::{UniformRand, test_rng, vec, vec::Vec}; pub type ScalarFieldFor = ::ScalarField; // `words_count` is the scalar length in words, with 1 word assumed to be 64 bits. // Most significant bit is set. fn make_scalar(words_count: u32) -> Vec { let mut scalar: Vec<_> = (0..words_count as usize) .map(|_| u64::rand(&mut test_rng())) .collect(); // Arkworks assumes scalar to be in **big endian** scalar[0] |= 1 << 63; scalar } fn make_base() -> Group { Group::rand(&mut test_rng()) } // `words_count` is the scalar length in words, with 1 word assumed to be 64 bits. // Most significant bit is set. pub fn make_scalar_args( words_count: u32, ) -> (ArkScale, ArkScale>) { (make_base::().into(), make_scalar(words_count).into()) } // `words_count` is the scalar length in words, with 1 word assumed to be 64 bits. // Most significant bit is set. pub fn make_scalar_args_projective( words_count: u32, ) -> (ArkScaleProjective, ArkScale>) { (make_base::().into(), make_scalar(words_count).into()) } pub fn make_pairing_args() -> (ArkScale, ArkScale) { (make_base::().into(), make_base::().into()) } pub fn make_msm_args( size: u32, ) -> (ArkScale>, ArkScale>) { let rng = &mut test_rng(); let scalars = (0..size) .map(|_| Group::ScalarField::rand(rng)) .collect::>(); let bases = (0..size).map(|_| Group::rand(rng)).collect::>(); let bases: ArkScale> = bases.into(); let scalars: ArkScale> = scalars.into(); (bases, scalars) } pub fn serialize_argument(argument: impl CanonicalSerialize) -> Vec { let mut buf = vec![0; argument.serialized_size(Compress::No)]; argument .serialize_uncompressed(buf.as_mut_slice()) .unwrap_or_default(); buf }