bump arkworks deps to version 0.4.0 (#30536)

* bump ark-works 0.4.0

* removed obsolete commented code

* bumped deps again after rebase

* paring: merged two vectors into one

* added zero serialization test

* reverted formatting change

* updated Cargo.lock after rebase

* fixed Cargo.lock
This commit is contained in:
ananas-block 2023-04-05 03:16:47 +01:00 committed by GitHub
parent fac76715e9
commit c4648f5a26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 402 additions and 100 deletions

161
Cargo.lock generated
View File

@ -143,9 +143,20 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea691771ebbb28aea556c044e2e5c5227398d840cee0c34d4d20fa8eb2689e8c"
dependencies = [
"ark-ec",
"ark-ff",
"ark-std",
"ark-ec 0.3.0",
"ark-ff 0.3.0",
"ark-std 0.3.0",
]
[[package]]
name = "ark-bn254"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a22f4561524cd949590d78d7d4c5df8f592430d221f7f3c9497bbafd8972120f"
dependencies = [
"ark-ec 0.4.2",
"ark-ff 0.4.2",
"ark-std 0.4.0",
]
[[package]]
@ -154,24 +165,41 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dea978406c4b1ca13c2db2373b05cc55429c3575b8b21f1b9ee859aa5b03dd42"
dependencies = [
"ark-ff",
"ark-serialize",
"ark-std",
"ark-ff 0.3.0",
"ark-serialize 0.3.0",
"ark-std 0.3.0",
"derivative",
"num-traits",
"zeroize",
]
[[package]]
name = "ark-ec"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba"
dependencies = [
"ark-ff 0.4.2",
"ark-poly",
"ark-serialize 0.4.2",
"ark-std 0.4.0",
"derivative",
"hashbrown 0.13.2",
"itertools",
"num-traits",
"zeroize",
]
[[package]]
name = "ark-ff"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b3235cc41ee7a12aaaf2c575a2ad7b46713a8a50bda2fc3b003a04845c05dd6"
dependencies = [
"ark-ff-asm",
"ark-ff-macros",
"ark-serialize",
"ark-std",
"ark-ff-asm 0.3.0",
"ark-ff-macros 0.3.0",
"ark-serialize 0.3.0",
"ark-std 0.3.0",
"derivative",
"num-bigint 0.4.3",
"num-traits",
@ -180,6 +208,26 @@ dependencies = [
"zeroize",
]
[[package]]
name = "ark-ff"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba"
dependencies = [
"ark-ff-asm 0.4.2",
"ark-ff-macros 0.4.2",
"ark-serialize 0.4.2",
"ark-std 0.4.0",
"derivative",
"digest 0.10.6",
"itertools",
"num-bigint 0.4.3",
"num-traits",
"paste",
"rustc_version 0.4.0",
"zeroize",
]
[[package]]
name = "ark-ff-asm"
version = "0.3.0"
@ -190,6 +238,16 @@ dependencies = [
"syn 1.0.107",
]
[[package]]
name = "ark-ff-asm"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348"
dependencies = [
"quote 1.0.26",
"syn 1.0.107",
]
[[package]]
name = "ark-ff-macros"
version = "0.3.0"
@ -202,16 +260,65 @@ dependencies = [
"syn 1.0.107",
]
[[package]]
name = "ark-ff-macros"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565"
dependencies = [
"num-bigint 0.4.3",
"num-traits",
"proc-macro2 1.0.53",
"quote 1.0.26",
"syn 1.0.107",
]
[[package]]
name = "ark-poly"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf"
dependencies = [
"ark-ff 0.4.2",
"ark-serialize 0.4.2",
"ark-std 0.4.0",
"derivative",
"hashbrown 0.13.2",
]
[[package]]
name = "ark-serialize"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d6c2b318ee6e10f8c2853e73a83adc0ccb88995aa978d8a3408d492ab2ee671"
dependencies = [
"ark-std",
"ark-std 0.3.0",
"digest 0.9.0",
]
[[package]]
name = "ark-serialize"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5"
dependencies = [
"ark-serialize-derive",
"ark-std 0.4.0",
"digest 0.10.6",
"num-bigint 0.4.3",
]
[[package]]
name = "ark-serialize-derive"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae3281bc6d0fd7e549af32b52511e1302185bd688fd3359fa36423346ff682ea"
dependencies = [
"proc-macro2 1.0.53",
"quote 1.0.26",
"syn 1.0.107",
]
[[package]]
name = "ark-std"
version = "0.3.0"
@ -222,6 +329,16 @@ dependencies = [
"rand 0.8.5",
]
[[package]]
name = "ark-std"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185"
dependencies = [
"num-traits",
"rand 0.8.5",
]
[[package]]
name = "array-bytes"
version = "1.4.1"
@ -2043,6 +2160,15 @@ dependencies = [
"ahash 0.7.6",
]
[[package]]
name = "hashbrown"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e"
dependencies = [
"ahash 0.8.3",
]
[[package]]
name = "headers"
version = "0.3.7"
@ -6100,9 +6226,9 @@ version = "1.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46ff25d98df385a10351036828588155cbdf74c2a60d630bc08951770b267931"
dependencies = [
"ark-bn254",
"ark-ec",
"ark-ff",
"ark-bn254 0.3.0",
"ark-ec 0.3.0",
"ark-ff 0.3.0",
"array-bytes",
"base64 0.13.1",
"bincode",
@ -6153,9 +6279,10 @@ name = "solana-program"
version = "1.16.0"
dependencies = [
"anyhow",
"ark-bn254",
"ark-ec",
"ark-ff",
"ark-bn254 0.4.0",
"ark-ec 0.4.2",
"ark-ff 0.4.2",
"ark-serialize 0.4.2",
"array-bytes",
"assert_matches",
"base64 0.13.1",

View File

@ -124,9 +124,10 @@ edition = "2021"
aes-gcm-siv = "0.10.3"
ahash = "0.8.3"
anyhow = "1.0.58"
ark-bn254 = "0.3.0"
ark-ec = "0.3.0"
ark-ff = "0.3.0"
ark-bn254 = "0.4.0"
ark-ec = "0.4.0"
ark-ff = "0.4.0"
ark-serialize = "0.4.0"
array-bytes = "=1.4.1"
arrayref = "0.3.7"
assert_cmd = "2.0"

161
programs/sbf/Cargo.lock generated
View File

@ -143,9 +143,20 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea691771ebbb28aea556c044e2e5c5227398d840cee0c34d4d20fa8eb2689e8c"
dependencies = [
"ark-ec",
"ark-ff",
"ark-std",
"ark-ec 0.3.0",
"ark-ff 0.3.0",
"ark-std 0.3.0",
]
[[package]]
name = "ark-bn254"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a22f4561524cd949590d78d7d4c5df8f592430d221f7f3c9497bbafd8972120f"
dependencies = [
"ark-ec 0.4.2",
"ark-ff 0.4.2",
"ark-std 0.4.0",
]
[[package]]
@ -154,24 +165,41 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dea978406c4b1ca13c2db2373b05cc55429c3575b8b21f1b9ee859aa5b03dd42"
dependencies = [
"ark-ff",
"ark-serialize",
"ark-std",
"ark-ff 0.3.0",
"ark-serialize 0.3.0",
"ark-std 0.3.0",
"derivative",
"num-traits",
"zeroize",
]
[[package]]
name = "ark-ec"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba"
dependencies = [
"ark-ff 0.4.2",
"ark-poly",
"ark-serialize 0.4.2",
"ark-std 0.4.0",
"derivative",
"hashbrown 0.13.2",
"itertools",
"num-traits",
"zeroize",
]
[[package]]
name = "ark-ff"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b3235cc41ee7a12aaaf2c575a2ad7b46713a8a50bda2fc3b003a04845c05dd6"
dependencies = [
"ark-ff-asm",
"ark-ff-macros",
"ark-serialize",
"ark-std",
"ark-ff-asm 0.3.0",
"ark-ff-macros 0.3.0",
"ark-serialize 0.3.0",
"ark-std 0.3.0",
"derivative",
"num-bigint 0.4.3",
"num-traits",
@ -180,6 +208,26 @@ dependencies = [
"zeroize",
]
[[package]]
name = "ark-ff"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba"
dependencies = [
"ark-ff-asm 0.4.2",
"ark-ff-macros 0.4.2",
"ark-serialize 0.4.2",
"ark-std 0.4.0",
"derivative",
"digest 0.10.6",
"itertools",
"num-bigint 0.4.3",
"num-traits",
"paste",
"rustc_version 0.4.0",
"zeroize",
]
[[package]]
name = "ark-ff-asm"
version = "0.3.0"
@ -190,6 +238,16 @@ dependencies = [
"syn 1.0.107",
]
[[package]]
name = "ark-ff-asm"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348"
dependencies = [
"quote 1.0.26",
"syn 1.0.107",
]
[[package]]
name = "ark-ff-macros"
version = "0.3.0"
@ -202,16 +260,65 @@ dependencies = [
"syn 1.0.107",
]
[[package]]
name = "ark-ff-macros"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565"
dependencies = [
"num-bigint 0.4.3",
"num-traits",
"proc-macro2 1.0.53",
"quote 1.0.26",
"syn 1.0.107",
]
[[package]]
name = "ark-poly"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf"
dependencies = [
"ark-ff 0.4.2",
"ark-serialize 0.4.2",
"ark-std 0.4.0",
"derivative",
"hashbrown 0.13.2",
]
[[package]]
name = "ark-serialize"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d6c2b318ee6e10f8c2853e73a83adc0ccb88995aa978d8a3408d492ab2ee671"
dependencies = [
"ark-std",
"ark-std 0.3.0",
"digest 0.9.0",
]
[[package]]
name = "ark-serialize"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5"
dependencies = [
"ark-serialize-derive",
"ark-std 0.4.0",
"digest 0.10.6",
"num-bigint 0.4.3",
]
[[package]]
name = "ark-serialize-derive"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae3281bc6d0fd7e549af32b52511e1302185bd688fd3359fa36423346ff682ea"
dependencies = [
"proc-macro2 1.0.53",
"quote 1.0.26",
"syn 1.0.107",
]
[[package]]
name = "ark-std"
version = "0.3.0"
@ -222,6 +329,16 @@ dependencies = [
"rand 0.8.5",
]
[[package]]
name = "ark-std"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185"
dependencies = [
"num-traits",
"rand 0.8.5",
]
[[package]]
name = "array-bytes"
version = "1.4.1"
@ -1798,6 +1915,15 @@ dependencies = [
"ahash 0.7.6",
]
[[package]]
name = "hashbrown"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e"
dependencies = [
"ahash 0.8.3",
]
[[package]]
name = "headers"
version = "0.3.7"
@ -5072,9 +5198,9 @@ version = "1.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ae9f0fa7db3a4e90fa0df2723ac8cbc042e579cf109cd0380bc5a8c88bed924"
dependencies = [
"ark-bn254",
"ark-ec",
"ark-ff",
"ark-bn254 0.3.0",
"ark-ec 0.3.0",
"ark-ff 0.3.0",
"array-bytes",
"base64 0.13.1",
"bincode",
@ -5124,9 +5250,10 @@ dependencies = [
name = "solana-program"
version = "1.16.0"
dependencies = [
"ark-bn254",
"ark-ec",
"ark-ff",
"ark-bn254 0.4.0",
"ark-ec 0.4.2",
"ark-ff 0.4.2",
"ark-serialize 0.4.2",
"array-bytes",
"base64 0.13.1",
"bincode",

View File

@ -40,6 +40,7 @@ thiserror = { workspace = true }
ark-bn254 = { workspace = true }
ark-ec = { workspace = true }
ark-ff = { workspace = true }
ark-serialize = { workspace = true }
array-bytes = { workspace = true }
bitflags = { workspace = true }
base64 = { workspace = true, features = ["alloc", "std"] }

View File

@ -52,6 +52,8 @@ pub enum AltBn128Error {
UnexpectedError,
#[error("Failed to convert a byte slice into a vector {0:?}")]
TryIntoVecError(Vec<u8>),
#[error("Failed to convert projective to affine g1")]
ProjectiveToG1Failed,
}
impl From<u64> for AltBn128Error {
@ -61,6 +63,7 @@ impl From<u64> for AltBn128Error {
2 => AltBn128Error::GroupError,
3 => AltBn128Error::SliceOutOfBounds,
4 => AltBn128Error::TryIntoVecError(Vec::new()),
5 => AltBn128Error::ProjectiveToG1Failed,
_ => AltBn128Error::UnexpectedError,
}
}
@ -73,6 +76,7 @@ impl From<AltBn128Error> for u64 {
AltBn128Error::GroupError => 2,
AltBn128Error::SliceOutOfBounds => 3,
AltBn128Error::TryIntoVecError(_) => 4,
AltBn128Error::ProjectiveToG1Failed => 5,
AltBn128Error::UnexpectedError => 0,
}
}
@ -90,20 +94,14 @@ pub struct PodG2(pub [u8; 128]);
mod target_arch {
use {
super::*,
ark_bn254::{self, Parameters},
ark_ec::{
self,
models::bn::{g1::G1Prepared, g2::G2Prepared, Bn},
AffineCurve, PairingEngine, ProjectiveCurve,
},
ark_ff::{
bytes::{FromBytes, ToBytes},
BigInteger, BigInteger256, One, Zero,
},
ark_bn254::{self, Config},
ark_ec::{self, models::bn::Bn, pairing::Pairing, AffineRepr},
ark_ff::{BigInteger, BigInteger256, One},
ark_serialize::{CanonicalDeserialize, CanonicalSerialize, Compress, Validate},
};
type G1 = ark_ec::short_weierstrass_jacobian::GroupAffine<ark_bn254::g1::Parameters>;
type G2 = ark_ec::short_weierstrass_jacobian::GroupAffine<ark_bn254::g2::Parameters>;
type G1 = ark_bn254::g1::G1Affine;
type G2 = ark_bn254::g2::G2Affine;
impl TryFrom<PodG1> for G1 {
type Error = AltBn128Error;
@ -112,7 +110,11 @@ mod target_arch {
if bytes.0 == [0u8; 64] {
return Ok(G1::zero());
}
let g1 = <Self as FromBytes>::read(&*[&bytes.0[..], &[0u8][..]].concat());
let g1 = Self::deserialize_with_mode(
&*[&bytes.0[..], &[0u8][..]].concat(),
Compress::No,
Validate::Yes,
);
match g1 {
Ok(g1) => {
@ -134,7 +136,11 @@ mod target_arch {
if bytes.0 == [0u8; 128] {
return Ok(G2::zero());
}
let g2 = <Self as FromBytes>::read(&*[&bytes.0[..], &[0u8][..]].concat());
let g2 = Self::deserialize_with_mode(
&*[&bytes.0[..], &[0u8][..]].concat(),
Compress::No,
Validate::Yes,
);
match g2 {
Ok(g2) => {
@ -170,15 +176,22 @@ mod target_arch {
)
.try_into()?;
let mut result_point_data = [0; ALT_BN128_ADDITION_OUTPUT_LEN + 1];
let result_point = p + q;
<G1 as ToBytes>::write(&result_point, &mut result_point_data[..])
let mut result_point_data = [0u8; ALT_BN128_ADDITION_OUTPUT_LEN];
let result_point_affine: G1 = result_point
.try_into()
.map_err(|_| AltBn128Error::ProjectiveToG1Failed)?;
result_point_affine
.x
.serialize_with_mode(&mut result_point_data[..32], Compress::No)
.map_err(|_| AltBn128Error::InvalidInputData)?;
result_point_affine
.y
.serialize_with_mode(&mut result_point_data[32..], Compress::No)
.map_err(|_| AltBn128Error::InvalidInputData)?;
if result_point == G1::zero() {
return Ok([0u8; ALT_BN128_ADDITION_OUTPUT_LEN].to_vec());
}
Ok(convert_edianness_64(&result_point_data[..ALT_BN128_ADDITION_OUTPUT_LEN]).to_vec())
Ok(convert_edianness_64(&result_point_data[..]).to_vec())
}
pub fn alt_bn128_multiplication(input: &[u8]) -> Result<Vec<u8>, AltBn128Error> {
@ -195,16 +208,24 @@ mod target_arch {
.map_err(AltBn128Error::TryIntoVecError)?,
)
.try_into()?;
let fr = <BigInteger256 as FromBytes>::read(convert_edianness_64(&input[64..96]).as_ref())
let fr = BigInteger256::deserialize_uncompressed_unchecked(
&convert_edianness_64(&input[64..96])[..],
)
.map_err(|_| AltBn128Error::InvalidInputData)?;
let result_point: G1 = p.mul_bigint(fr).into();
let mut result_point_data = [0u8; ALT_BN128_MULTIPLICATION_OUTPUT_LEN];
result_point
.x
.serialize_with_mode(&mut result_point_data[..32], Compress::No)
.map_err(|_| AltBn128Error::InvalidInputData)?;
result_point
.y
.serialize_with_mode(&mut result_point_data[32..], Compress::No)
.map_err(|_| AltBn128Error::InvalidInputData)?;
let mut result_point_data = [0; ALT_BN128_MULTIPLICATION_OUTPUT_LEN + 1];
let result_point: G1 = p.into_projective().mul(fr).into();
<G1 as ToBytes>::write(&result_point, &mut result_point_data[..])
.map_err(|_| AltBn128Error::InvalidInputData)?;
if result_point == G1::zero() {
return Ok([0u8; ALT_BN128_MULTIPLICATION_OUTPUT_LEN].to_vec());
}
Ok(
convert_edianness_64(&result_point_data[..ALT_BN128_MULTIPLICATION_OUTPUT_LEN])
.to_vec(),
@ -221,38 +242,42 @@ mod target_arch {
}
let ele_len = input.len().saturating_div(ALT_BN128_PAIRING_ELEMENT_LEN);
let mut vec_pairs: Vec<(G1Prepared<Parameters>, G2Prepared<Parameters>)> = Vec::new();
let mut vec_pairs: Vec<(G1, G2)> = Vec::new();
for i in 0..ele_len {
let g1: G1 = PodG1(
convert_edianness_64(
&input[i.saturating_mul(ALT_BN128_PAIRING_ELEMENT_LEN)
..i.saturating_mul(ALT_BN128_PAIRING_ELEMENT_LEN)
.saturating_add(ALT_BN128_POINT_SIZE)],
vec_pairs.push((
PodG1(
convert_edianness_64(
&input[i.saturating_mul(ALT_BN128_PAIRING_ELEMENT_LEN)
..i.saturating_mul(ALT_BN128_PAIRING_ELEMENT_LEN)
.saturating_add(ALT_BN128_POINT_SIZE)],
)
.try_into()
.map_err(AltBn128Error::TryIntoVecError)?,
)
.try_into()
.map_err(AltBn128Error::TryIntoVecError)?,
)
.try_into()?;
let g2: G2 = PodG2(
convert_edianness_128(
&input[i
.saturating_mul(ALT_BN128_PAIRING_ELEMENT_LEN)
.saturating_add(ALT_BN128_POINT_SIZE)
..i.saturating_mul(ALT_BN128_PAIRING_ELEMENT_LEN)
.saturating_add(ALT_BN128_PAIRING_ELEMENT_LEN)],
.try_into()?,
PodG2(
convert_edianness_128(
&input[i
.saturating_mul(ALT_BN128_PAIRING_ELEMENT_LEN)
.saturating_add(ALT_BN128_POINT_SIZE)
..i.saturating_mul(ALT_BN128_PAIRING_ELEMENT_LEN)
.saturating_add(ALT_BN128_PAIRING_ELEMENT_LEN)],
)
.try_into()
.map_err(AltBn128Error::TryIntoVecError)?,
)
.try_into()
.map_err(AltBn128Error::TryIntoVecError)?,
)
.try_into()?;
vec_pairs.push((g1.into(), g2.into()));
.try_into()?,
));
}
let mut result = BigInteger256::from(0u64);
let res =
<Bn<Parameters> as PairingEngine>::product_of_pairings((vec_pairs[..ele_len]).iter());
type GT = <ark_ec::models::bn::Bn<ark_bn254::Parameters> as ark_ec::PairingEngine>::Fqk;
if res == GT::one() {
let res = <Bn<Config> as Pairing>::multi_pairing(
vec_pairs.iter().map(|pair| pair.0),
vec_pairs.iter().map(|pair| pair.1),
);
if res.0 == ark_bn254::Fq12::one() {
result = BigInteger256::from(1u64);
}
@ -345,7 +370,32 @@ mod target_arch {
#[cfg(test)]
mod tests {
use crate::alt_bn128::prelude::*;
use {
crate::alt_bn128::{prelude::*, PodG1},
ark_bn254::g1::G1Affine,
ark_ec::AffineRepr,
ark_serialize::{CanonicalSerialize, Compress},
};
#[test]
fn zero_serialization_test() {
let zero = G1Affine::zero();
let mut result_point_data = [0u8; 64];
zero.x
.serialize_with_mode(&mut result_point_data[..32], Compress::No)
.map_err(|_| AltBn128Error::InvalidInputData)
.unwrap();
zero.y
.serialize_with_mode(&mut result_point_data[32..], Compress::No)
.map_err(|_| AltBn128Error::InvalidInputData)
.unwrap();
assert_eq!(result_point_data, [0u8; 64]);
let p: G1Affine = PodG1(result_point_data[..64].try_into().unwrap())
.try_into()
.unwrap();
assert_eq!(p, zero);
}
#[test]
fn alt_bn128_addition_test() {
@ -434,10 +484,10 @@ mod tests {
let input = array_bytes::hex2bytes_unchecked(&test.input);
let result = alt_bn128_addition(&input);
assert!(result.is_ok());
let result = result.unwrap();
let expected = array_bytes::hex2bytes_unchecked(&test.expected);
assert_eq!(result, expected);
assert_eq!(result.unwrap(), expected);
});
}
@ -570,10 +620,8 @@ mod tests {
let input = array_bytes::hex2bytes_unchecked(&test.input);
let result = alt_bn128_multiplication(&input);
assert!(result.is_ok());
let result = result.unwrap();
let expected = array_bytes::hex2bytes_unchecked(&test.expected);
assert_eq!(result, expected);
assert_eq!(result.unwrap(), expected);
});
}
@ -682,10 +730,8 @@ mod tests {
let input = array_bytes::hex2bytes_unchecked(&test.input);
let result = alt_bn128_pairing(&input);
assert!(result.is_ok());
let result = result.unwrap();
let expected = array_bytes::hex2bytes_unchecked(&test.expected);
assert_eq!(result, expected);
assert_eq!(result.unwrap(), expected);
});
}
}