From ac05245c691fc02784052222c14a07590fb4d26b Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Thu, 28 Sep 2023 15:01:28 +0400 Subject: [PATCH 01/38] - Added code from bn254 at wavesplatform/groth16verify; - One JNI library instead of two; - Common JNI initialization. --- .gitignore | 2 + zwaves_jni/Cargo.toml | 15 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- zwaves_jni/javalib/gradlew | 0 .../zwaves/{bls12 => }/JNILibrary.java | 2 +- .../zwaves/ZWavesJNILibrary.java | 9 + .../wavesplatform/zwaves/bls12/Groth16.java | 4 +- .../wavesplatform/zwaves/bn256/Groth16.java | 9 + zwaves_jni/src/bls12/mod.rs | 89 +++++++ zwaves_jni/src/{ => bls12}/tests/mod.rs | 64 ++--- zwaves_jni/src/bn256/bin/show_test_vectors.rs | 88 ++++++ zwaves_jni/src/bn256/mod.rs | 65 +++++ zwaves_jni/src/bn256/serialization.rs | 46 ++++ zwaves_jni/src/bn256/verifier.rs | 251 ++++++++++++++++++ zwaves_jni/src/lib.rs | 166 +++--------- 15 files changed, 631 insertions(+), 181 deletions(-) mode change 100644 => 100755 zwaves_jni/javalib/gradlew rename zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/{bls12 => }/JNILibrary.java (99%) create mode 100644 zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/ZWavesJNILibrary.java create mode 100644 zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/bn256/Groth16.java create mode 100644 zwaves_jni/src/bls12/mod.rs rename zwaves_jni/src/{ => bls12}/tests/mod.rs (78%) create mode 100644 zwaves_jni/src/bn256/bin/show_test_vectors.rs create mode 100644 zwaves_jni/src/bn256/mod.rs create mode 100644 zwaves_jni/src/bn256/serialization.rs create mode 100644 zwaves_jni/src/bn256/verifier.rs diff --git a/.gitignore b/.gitignore index 18f8e7e..1aedb3d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ bin/ pkg/ wasm-pack.log .vscode +.idea +!zwaves_jni/src/bn256/bin !zwaves_setup/src/bin diff --git a/zwaves_jni/Cargo.toml b/zwaves_jni/Cargo.toml index 862b957..8db422a 100644 --- a/zwaves_jni/Cargo.toml +++ b/zwaves_jni/Cargo.toml @@ -1,21 +1,32 @@ [package] name = "zwaves_jni" -version = "0.1.0" +version = "0.2.0" authors = ["Igor Gulamov "] edition = "2018" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "rlib"] name = "zwaves_jni" +[[bin]] +path = "src/bn256/bin/show_test_vectors.rs" +name="show_test_vectors" + [dependencies] bellman = { version = "0.1.0" } zwaves_primitives = { path = "../zwaves_primitives"} sapling-crypto = { path = "../sapling-crypto" } pairing = "0.14" +pairing_ce = "0.18" # for bn256 num = "0.2" serde = { version = "1.0", features = ["derive"] } base64 = "0.11.0" jni = "0.14.0" byteorder = "1" rand = "0.4" + +# for bn256 +[dependencies.ff] +version = "=0.7" +features = ["derive"] +package = "ff_ce" diff --git a/zwaves_jni/javalib/gradle/wrapper/gradle-wrapper.properties b/zwaves_jni/javalib/gradle/wrapper/gradle-wrapper.properties index f4d7b2b..b7c8c5d 100644 --- a/zwaves_jni/javalib/gradle/wrapper/gradle-wrapper.properties +++ b/zwaves_jni/javalib/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/zwaves_jni/javalib/gradlew b/zwaves_jni/javalib/gradlew old mode 100644 new mode 100755 diff --git a/zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/bls12/JNILibrary.java b/zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/JNILibrary.java similarity index 99% rename from zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/bls12/JNILibrary.java rename to zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/JNILibrary.java index 11e617f..f0cd654 100644 --- a/zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/bls12/JNILibrary.java +++ b/zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/JNILibrary.java @@ -7,7 +7,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html *******************************************************************************/ -package com.wavesplatform.zwaves.bls12; +package com.wavesplatform.zwaves; import java.io.*; import java.lang.reflect.Method; diff --git a/zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/ZWavesJNILibrary.java b/zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/ZWavesJNILibrary.java new file mode 100644 index 0000000..ae649ff --- /dev/null +++ b/zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/ZWavesJNILibrary.java @@ -0,0 +1,9 @@ +package com.wavesplatform.zwaves; + +public class ZWavesJNILibrary { + static { + new JNILibrary("zwaves_jni", ZWavesJNILibrary.class).load(); + } + + public static void init() {} +} diff --git a/zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/bls12/Groth16.java b/zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/bls12/Groth16.java index 96f16ba..e18ccff 100644 --- a/zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/bls12/Groth16.java +++ b/zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/bls12/Groth16.java @@ -4,6 +4,6 @@ public class Groth16 { public static native boolean verify(byte[] vk, byte[] proof, byte[] inputs); static { - new JNILibrary("zwaves_jni", Groth16.class).load(); + com.wavesplatform.zwaves.ZWavesJNILibrary.init(); } -} \ No newline at end of file +} diff --git a/zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/bn256/Groth16.java b/zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/bn256/Groth16.java new file mode 100644 index 0000000..64d75a8 --- /dev/null +++ b/zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/bn256/Groth16.java @@ -0,0 +1,9 @@ +package com.wavesplatform.zwaves.bn256; + +public class Groth16 { + public static native boolean verify(byte[] vk, byte[] proof, byte[] inputs); + + static { + com.wavesplatform.zwaves.ZWavesJNILibrary.init(); + } +} diff --git a/zwaves_jni/src/bls12/mod.rs b/zwaves_jni/src/bls12/mod.rs new file mode 100644 index 0000000..b11c91f --- /dev/null +++ b/zwaves_jni/src/bls12/mod.rs @@ -0,0 +1,89 @@ +use std::io; + +use bellman::groth16::Proof; +use pairing::bls12_381::{Bls12, Fr}; + +use zwaves_primitives::serialization::read_fr_vec; +use zwaves_primitives::verifier::{TruncatedVerifyingKey, verify_proof}; + +#[cfg(test)] +pub mod tests; + +pub fn groth16_verify(vk: &[u8], proof: &[u8], inputs: &[u8]) -> io::Result { + let buff_vk_len = vk.len(); + let buff_proof_len = proof.len(); + let buff_inputs_len = inputs.len(); + + if (buff_vk_len % 48 != 0) || (buff_inputs_len % 32 != 0) { + return Err(io::Error::new(io::ErrorKind::InvalidData, "wrong buffer length")); + } + + let inputs_len = buff_inputs_len / 32; + + if ((buff_vk_len / 48) != (inputs_len + 8)) || (buff_proof_len != 192) { + return Err(io::Error::new(io::ErrorKind::InvalidData, "wrong buffer length")); + } + + let vk = TruncatedVerifyingKey::::read(vk)?; + let proof = Proof::::read(proof)?; + let inputs = read_fr_vec::(inputs)?; + + if (inputs.len() != inputs_len) || (vk.ic.len() != (inputs_len + 1)) { + return Err(io::Error::new(io::ErrorKind::InvalidData, "wrong buffer parsing")); + } + + Ok(verify_proof( + &vk, + &proof, + inputs.as_slice(), + ).map(|r| r as u8).unwrap_or(0)) +} + +#[cfg(test)] +mod local_tests { + use base64::decode; + + use super::*; + + #[test] + fn test_groth16_verify_binaries_ok() { + let vk = "hwk883gUlTKCyXYA6XWZa8H9/xKIYZaJ0xEs0M5hQOMxiGpxocuX/8maSDmeCk3bo5ViaDBdO7ZBxAhLSe5k/5TFQyF5Lv7KN2tLKnwgoWMqB16OL8WdbePIwTCuPtJNAFKoTZylLDbSf02kckMcZQDPF9iGh+JC99Pio74vDpwTEjUx5tQ99gNQwxULtztsqDRsPnEvKvLmsxHt8LQVBkEBm2PBJFY+OXf1MNW021viDBpR10mX4WQ6zrsGL5L0GY4cwf4tlbh+Obit+LnN/SQTnREf8fPpdKZ1sa/ui3pGi8lMT6io4D7Ujlwx2RdCkBF+isfMf77HCEGsZANw0hSrO2FGg14Sl26xLAIohdaW8O7gEaag8JdVAZ3OVLd5Df1NkZBEr753Xb8WwaXsJjE7qxwINL1KdqA4+EiYW4edb7+a9bbBeOPtb67ZxmFqgyTNS/4obxahezNkjk00ytswsENg//Ee6dWBJZyLH+QGsaU2jO/W4WvRyZhmKKPdipOhiz4Rlrd2XYgsfHsfWf5v4GOTL+13ZB24dW1/m39n2woJ+v686fXbNW85XP/r"; + let proof = "lvQLU/KqgFhsLkt/5C/scqs7nWR+eYtyPdWiLVBux9GblT4AhHYMdCgwQfSJcudvsgV6fXoK+DUSRgJ++Nqt+Wvb7GlYlHpxCysQhz26TTu8Nyo7zpmVPH92+UYmbvbQCSvX2BhWtvkfHmqDVjmSIQ4RUMfeveA1KZbSf999NE4qKK8Do+8oXcmTM4LZVmh1rlyqznIdFXPN7x3pD4E0gb6/y69xtWMChv9654FMg05bAdueKt9uA4BEcAbpkdHF"; + let inputs = "LcMT3OOlkHLzJBKCKjjzzVMg+r+FVgd52LlhZPB4RFg="; + + let vk = decode(vk).unwrap(); + let proof = decode(proof).unwrap(); + let inputs = decode(inputs).unwrap(); + + let res = groth16_verify(&vk, &proof, &inputs).unwrap_or(0) != 0; + assert!(res, "groth16_verify should be true"); + } + + #[test] + fn test_groth16_verify_binaries_notok() { + let vk = "hwk883gUlTKCyXYA6XWZa8H9/xKIYZaJ0xEs0M5hQOMxiGpxocuX/8maSDmeCk3bo5ViaDBdO7ZBxAhLSe5k/5TFQyF5Lv7KN2tLKnwgoWMqB16OL8WdbePIwTCuPtJNAFKoTZylLDbSf02kckMcZQDPF9iGh+JC99Pio74vDpwTEjUx5tQ99gNQwxULtztsqDRsPnEvKvLmsxHt8LQVBkEBm2PBJFY+OXf1MNW021viDBpR10mX4WQ6zrsGL5L0GY4cwf4tlbh+Obit+LnN/SQTnREf8fPpdKZ1sa/ui3pGi8lMT6io4D7Ujlwx2RdCkBF+isfMf77HCEGsZANw0hSrO2FGg14Sl26xLAIohdaW8O7gEaag8JdVAZ3OVLd5Df1NkZBEr753Xb8WwaXsJjE7qxwINL1KdqA4+EiYW4edb7+a9bbBeOPtb67ZxmFqgyTNS/4obxahezNkjk00ytswsENg//Ee6dWBJZyLH+QGsaU2jO/W4WvRyZhmKKPdipOhiz4Rlrd2XYgsfHsfWf5v4GOTL+13ZB24dW1/m39n2woJ+v686fXbNW85XP/r"; + let proof = "lvQLU/KqgFhsLkt/5C/scqs7nWR+eYtyPdWiLVBux9GblT4AhHYMdCgwQfSJcudvsgV6fXoK+DUSRgJ++Nqt+Wvb7GlYlHpxCysQhz26TTu8Nyo7zpmVPH92+UYmbvbQCSvX2BhWtvkfHmqDVjmSIQ4RUMfeveA1KZbSf999NE4qKK8Do+8oXcmTM4LZVmh1rlyqznIdFXPN7x3pD4E0gb6/y69xtWMChv9654FMg05bAdueKt9uA4BEcAbpkdHF"; + let inputs = "cmzVCcRVnckw3QUPhmG4Bkppeg4K50oDQwQ9EH+Fq1s="; + + let vk = decode(vk).unwrap(); + let proof = decode(proof).unwrap(); + let inputs = decode(inputs).unwrap(); + + let res = groth16_verify(&vk, &proof, &inputs).unwrap_or(0) != 0; + assert!(!res, "groth16_verify should be false"); + } + + #[test] + fn test_groth16_verify_binaries_bad_data() { + let vk = "hwk883gUlTKCyXYA6XWZa8H9/xKIYZaJ0xEs0M5hQOMxiGpxocuX/8maSDmeCk3bo5ViaDBdO7ZBxAhLSe5k/5TFQyF5Lv7KN2tLKnwgoWMqB16OL8WdbePIwTCuPtJNAFKoTZylLDbSf02kckMcZQDPF9iGh+JC99Pio74vDpwTEjUx5tQ99gNQwxULtztsqDRsPnEvKvLmsxHt8LQVBkEBm2PBJFY+OXf1MNW021viDBpR10mX4WQ6zrsGL5L0GY4cwf4tlbh+Obit+LnN/SQTnREf8fPpdKZ1sa/ui3pGi8lMT6io4D7Ujlwx2RdCkBF+isfMf77HCEGsZANw0hSrO2FGg14Sl26xLAIohdaW8O7gEaag8JdVAZ3OVLd5Df1NkZBEr753Xb8WwaXsJjE7qxwINL1KdqA4+EiYW4edb7+a9bbBeOPtb67ZxmFqgyTNS/4obxahezNkjk00ytswsENg//Ee6dWBJZyLH+QGsaU2jO/W4WvRyZhmKKPdipOhiz4Rlrd2XYgsfHsfWf5v4GOTL+13ZB24dW1/m39n2woJ+v686fXbNW85XP/r"; + let proof = "lvQLU/KqgFhsLkt/5C/scqs7nWR+eYtyPdWiLVBux9GblT4AhHYMdCgwQfSJcudvsgV6fXoK+DUSRgJ++Nqt+Wvb7GlYlHpxCysQhz26TTu8Nyo7zpmVPH92+UYmbvbQCSvX2BhWtvkfHmqDVjmSIQ4RUMfeveA1KZbSf999NE4qKK8Do+8oXcmTM4LZVmh1rlyqznIdFXPN7x3pD4E0gb6/y69xtWMChv9654FMg05bAdueKt9uA4BEcAbpkdHF"; + let inputs = "cmzVCcRVnckw3QUPhmG4Bkppeg4K50oDQwQ9EH+Fq1s="; + + let vk = decode(vk).unwrap(); + let proof = decode(proof).unwrap(); + let inputs = decode(inputs).unwrap(); + + let res = groth16_verify(&vk, &proof, &inputs[0..1]).unwrap_or(0) != 0; + assert!(!res, "groth16_verify should be false"); + } +} diff --git a/zwaves_jni/src/tests/mod.rs b/zwaves_jni/src/bls12/tests/mod.rs similarity index 78% rename from zwaves_jni/src/tests/mod.rs rename to zwaves_jni/src/bls12/tests/mod.rs index 6dcc9bc..6080de6 100644 --- a/zwaves_jni/src/tests/mod.rs +++ b/zwaves_jni/src/bls12/tests/mod.rs @@ -1,38 +1,34 @@ extern crate pairing; +use std::io::{Cursor, Read, Seek, SeekFrom}; + use bellman::{Circuit, ConstraintSystem, SynthesisError}; -use sapling_crypto::jubjub::{JubjubEngine, JubjubParams, JubjubBls12}; -use sapling_crypto::circuit::{pedersen_hash}; -use sapling_crypto::circuit::num::{AllocatedNum, Num}; -use bellman::groth16::{Proof, generate_random_parameters, create_random_proof}; +use bellman::groth16::{create_random_proof, generate_random_parameters}; use bellman::LinearCombination; - -use pairing::bls12_381::{Bls12, Fr, FrRepr}; -use pairing::{Engine, PrimeField, Field, PrimeFieldRepr}; +use pairing::{Engine, Field, PrimeField, PrimeFieldRepr}; +use pairing::bls12_381::{Bls12, Fr}; use rand::os::OsRng; use rand::Rng; -use std::io::{Cursor, Read, Seek, SeekFrom, Write}; -use zwaves_primitives::verifier::{truncate_verifying_key, TruncatedVerifyingKey, verify_proof}; -use zwaves_primitives::serialization::write_fr_iter; +use sapling_crypto::circuit::num::AllocatedNum; +use sapling_crypto::circuit::pedersen_hash; +use sapling_crypto::jubjub::{JubjubBls12, JubjubEngine, JubjubParams}; use zwaves_primitives::pedersen_hasher; - -use base64::encode; -use std::iter; - +use zwaves_primitives::serialization::write_fr_iter; +use zwaves_primitives::verifier::{truncate_verifying_key, verify_proof}; #[derive(Clone)] pub struct PedersenDemo { pub params: Box, pub image: Option, pub data: Vec>, - pub preimage: Option + pub preimage: Option, } -impl Circuit for PedersenDemo { +impl Circuit for PedersenDemo { fn synthesize>( self, - cs: &mut CS + cs: &mut CS, ) -> Result<(), SynthesisError> { let image = AllocatedNum::alloc(cs.namespace(|| "signal public input image"), || self.image.ok_or(SynthesisError::AssignmentMissing))?; @@ -43,16 +39,14 @@ impl Circuit for PedersenDemo { cs.namespace(|| "image_calculated <== pedersen_hash(preimage_bits)"), pedersen_hash::Personalization::NoteCommitment, &preimage_bits, - &self.params + &self.params, )?.get_x().clone(); let mut data_sum = LinearCombination::::zero(); - - self.data.into_iter().enumerate().for_each(|(i, e)| { let n = AllocatedNum::alloc(cs.namespace(|| format!("data_item[{}]", i)), || e.ok_or(SynthesisError::AssignmentMissing)).unwrap(); - n.inputize(cs.namespace(|| format!("data_item[{}] inputize", i))).unwrap(); + n.inputize(cs.namespace(|| format!("data_item[{}] inputize", i))).unwrap(); data_sum = data_sum.clone() + (E::Fr::one(), n.get_variable()); }); @@ -62,19 +56,16 @@ impl Circuit for PedersenDemo { } } - #[cfg(test)] mod tests { use super::*; - #[test] pub fn test_groth16_verify_get_vectors() -> std::io::Result<()> { - let rng = &mut OsRng::new().unwrap(); let mut sum = Fr::zero(); - let mut data :Vec = (0..15).into_iter().map(|_| { + let mut data: Vec = (0..15).into_iter().map(|_| { let n = rng.gen(); sum.add_assign(&n); n @@ -82,9 +73,6 @@ mod tests { data[14].sub_assign(&sum); - - - let preimage = rng.gen(); let params = JubjubBls12::new(); @@ -98,25 +86,23 @@ mod tests { let c = PedersenDemo:: { params: Box::new(JubjubBls12::new()), image: None, - data: vec![None;15], - preimage: None + data: vec![None; 15], + preimage: None, }; generate_random_parameters(c, rng).unwrap() }; let tvk = truncate_verifying_key(¶ms.vk); - - println!("Creating proofs..."); let c = PedersenDemo:: { params: Box::new(JubjubBls12::new()), image: Some(image), data: data.iter().map(|e| Some(e.clone())).collect(), - preimage: Some(preimage) + preimage: Some(preimage), }; - + let proof = create_random_proof(c, ¶ms, rng).unwrap(); - + let mut tvk_c = Cursor::new(Vec::new()); tvk.write(&mut tvk_c)?; tvk_c.seek(SeekFrom::Start(0)).unwrap(); @@ -134,8 +120,7 @@ mod tests { let mut inputs = vec![image]; inputs.extend(data.iter().cloned()); - - let mut inputs_b = vec![0u8;32*inputs.len()]; + let mut inputs_b = vec![0u8; 32 * inputs.len()]; write_fr_iter((&inputs).into_iter(), &mut inputs_b)?; println!("Inputs: {}", base64::encode(&inputs_b)); @@ -143,12 +128,9 @@ mod tests { let result = verify_proof( &tvk, &proof, - &inputs + &inputs, ).unwrap(); assert!(result, "Proof is correct"); Ok(()) } - - - } diff --git a/zwaves_jni/src/bn256/bin/show_test_vectors.rs b/zwaves_jni/src/bn256/bin/show_test_vectors.rs new file mode 100644 index 0000000..1298555 --- /dev/null +++ b/zwaves_jni/src/bn256/bin/show_test_vectors.rs @@ -0,0 +1,88 @@ +extern crate zwaves_jni; + +use std::io::Cursor; + +use ff::Field; +use pairing_ce::{CurveAffine, CurveProjective}; +use pairing_ce::bn256::*; +use rand::{Rand, SeedableRng, XorShiftRng}; +use zwaves_jni::bn256::serialization::write_fr_iter; +use zwaves_jni::bn256::verifier::Proof; +use zwaves_jni::bn256::verifier::TruncatedVerifyingKey; + +fn main() { + const NINPUTS: usize = 1; + let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); + + const SAMPLES: usize = 1000; + + let v = (0..SAMPLES) + .map(|_| { + let inputs = (0..NINPUTS).map(|_| Fr::rand(&mut rng)).collect::>(); + let mut inputs_buff = vec![0u8; 32 * NINPUTS]; + write_fr_iter(inputs.iter(), &mut inputs_buff).unwrap(); + + let ic = (0..NINPUTS + 1) + .map(|_| G1::rand(&mut rng).into_affine()) + .collect::>(); + + let mut x_sum = ic[0].into_projective(); + for i in 1..NINPUTS + 1 { + let mut t = ic[i].into_projective(); + t.mul_assign(inputs[i - 1]); + x_sum.add_assign(&t); + } + let g1_gen = x_sum.into_affine(); + let g2_gen = G2::rand(&mut rng).into_affine(); + + let a_1 = Fr::one(); + let a_2 = Fr::rand(&mut rng); + let a_3 = Fr::rand(&mut rng); + let b_1 = Fr::one(); + let b_2 = Fr::rand(&mut rng); + let b_3 = Fr::rand(&mut rng); + let b_4 = Fr::rand(&mut rng); + + let mut a_4 = Fr::zero(); + let mut t = a_1; + t.mul_assign(&b_1); + a_4.add_assign(&t); + t = a_2; + t.mul_assign(&b_2); + a_4.add_assign(&t); + t = a_3; + t.mul_assign(&b_3); + a_4.add_assign(&t); + a_4.mul_assign(&b_4.inverse().unwrap()); + + let vk = TruncatedVerifyingKey:: { + alpha_g1: g1_gen.mul(a_3).into_affine(), + beta_g2: g2_gen.mul(b_3).into_affine(), + gamma_g2: g2_gen.clone(), + delta_g2: g2_gen.mul(b_2).into_affine(), + ic, + }; + let mut vk_buff = Cursor::new(Vec::::new()); + vk.write(&mut vk_buff).unwrap(); + + let proof = Proof:: { + a: g1_gen.mul(a_4).into_affine(), + b: g2_gen.mul(b_4).into_affine(), + c: g1_gen.mul(a_2).into_affine(), + }; + let mut proof_buff = Cursor::new(Vec::::new()); + proof.write(&mut proof_buff).unwrap(); + + //let res = crate::verifier::verify_proof(&vk, &proof, &inputs).unwrap_or(false); + //assert!(res, "groth16_verify should be true"); + + ( + base64::encode(vk_buff.get_ref()), + base64::encode(proof_buff.get_ref()), + base64::encode(&inputs_buff), + ) + }) + .collect::>(); + + println!("{:?}", v); +} diff --git a/zwaves_jni/src/bn256/mod.rs b/zwaves_jni/src/bn256/mod.rs new file mode 100644 index 0000000..86275ec --- /dev/null +++ b/zwaves_jni/src/bn256/mod.rs @@ -0,0 +1,65 @@ +use std::io; + +use pairing_ce::bn256::{Bn256, Fr}; +use serialization::read_fr_vec; +use verifier::{TruncatedVerifyingKey, verify_proof}; +use verifier::Proof; + +pub mod serialization; +pub mod verifier; + +pub fn groth16_verify(vk: &[u8], proof: &[u8], inputs: &[u8]) -> io::Result { + let buff_vk_len = vk.len(); + let buff_proof_len = proof.len(); + let buff_inputs_len = inputs.len(); + + if (buff_vk_len % 32 != 0) || (buff_inputs_len % 32 != 0) { + return Err(io::Error::new( + io::ErrorKind::InvalidData, + "wrong buffer length", + )); + } + + let inputs_len = buff_inputs_len / 32; + + if ((buff_vk_len / 32) != (inputs_len + 8)) || (buff_proof_len != 128) { + return Err(io::Error::new( + io::ErrorKind::InvalidData, + "wrong buffer length", + )); + } + + let vk = TruncatedVerifyingKey::::read(vk)?; + let proof = Proof::::read(proof)?; + let inputs = read_fr_vec::(inputs)?; + + if (inputs.len() != inputs_len) || (vk.ic.len() != (inputs_len + 1)) { + return Err(io::Error::new( + io::ErrorKind::InvalidData, + "wrong buffer parsing", + )); + } + + Ok(verify_proof(&vk, &proof, inputs.as_slice()) + .map(|r| r as u8) + .unwrap_or(0)) +} + +#[cfg(test)] +mod local_tests { + use base64::decode; + + use super::*; + + #[test] + fn test_groth16_verify_binaries_ok() { + let (vk, proof, inputs) = ("LDCJzjgi5HtcHEXHfU8TZz+ZUHD2ZwsQ7JIEvzdMPYKYs9SoGkKUmg1yya4TE0Ms7x+KOJ4Ze/CPfKp2s5jbniFNM71N/YlHVbNkytLtQi1DzReSh9SNBsvskdY5mavQJe+67PuPVEYnx+lJ97qIG8243njZbGWPqUJ2Vqj49NAunhqX+eIkK3zAB3IPWls3gruzX2t9wrmyE9cVVvf1kgWx63PsQV37qdH0KcFRpCH89k4TPS6fLmqdFxX3YGHCGFTpr6tLogvjbUFJPT98kJ/xck0C0B/s8PTVKdao4VQHT4DBIO8+GB3CQVh6VV4EcMLtDWWNxF4yloAlKcFT0Q4AzJSimpFqd/SwSz9Pb7uk5srte3nwphVamC+fHlJt", "GQPBoHuCPcIosF+WZKE5jZV13Ib4EdjLnABncpSHcMKBZl0LhllnPxcuzExIQwhxcfXvFFAjlnDGpKauQ9OQsjBKUBsdBZnGiV2Sg4TSdyHuLo2AbRRqJN0IV3iH3On8I4ngnL30ZAxVyGQH2EK58aUZGxMbbXGR9pQdh99QaiE=", "IfZhAypdtgvecKDWzVyRuvXatmFf2ZYcMWVkCJ0/MQo="); + + let vk = decode(vk).unwrap(); + let proof = decode(proof).unwrap(); + let inputs = decode(inputs).unwrap(); + + let res = groth16_verify(&vk, &proof, &inputs).unwrap_or(0) != 0; + assert!(res, "groth16_verify should be true"); + } +} diff --git a/zwaves_jni/src/bn256/serialization.rs b/zwaves_jni/src/bn256/serialization.rs new file mode 100644 index 0000000..9ef9c80 --- /dev/null +++ b/zwaves_jni/src/bn256/serialization.rs @@ -0,0 +1,46 @@ +use std::{io, mem}; + +use ff::{PrimeField, PrimeFieldRepr}; + +pub fn read_fr_repr_be(data: &[u8]) -> io::Result { + let mut fr_repr = Fr::zero().into_repr(); + + match fr_repr.read_be(data) { + Err(e) => return Err(e), + _ => {} + } + Ok(fr_repr) +} + +pub fn read_fr_vec(data: &[u8]) -> io::Result> { + let mut inputs = vec![]; + + let mut offset = 0; + let fr_repr_sz = mem::size_of::(); + + loop { + let fr_repr = match read_fr_repr_be::(&data[offset..]) { + Ok(x) => x, + _ => break, + }; + + offset += fr_repr_sz; + let fr = Fr::from_repr(fr_repr) + .map_err(|_e| io::Error::new(io::ErrorKind::InvalidData, "not in field"))?; + inputs.push(fr); + } + + Ok(inputs) +} + +pub fn write_fr_iter<'a, I, Fr>(source: I, data: &mut [u8]) -> io::Result<()> + where + Fr: PrimeField, + I: IntoIterator, +{ + let fr_repr_sz = mem::size_of::(); + for (i, e) in source.into_iter().enumerate() { + e.into_repr().write_be(&mut data[fr_repr_sz * i..])?; + } + Ok(()) +} diff --git a/zwaves_jni/src/bn256/verifier.rs b/zwaves_jni/src/bn256/verifier.rs new file mode 100644 index 0000000..980f2ea --- /dev/null +++ b/zwaves_jni/src/bn256/verifier.rs @@ -0,0 +1,251 @@ +use std::io; +use std::io::{Read, Write}; + +use ff::{Field, PrimeField}; +use pairing_ce::{CurveAffine, CurveProjective, EncodedPoint, Engine}; + +#[derive(Debug)] +pub enum SynthesisError { + /// During synthesis, we lacked knowledge of a variable assignment. + AssignmentMissing, + /// During synthesis, we divided by zero. + DivisionByZero, + /// During synthesis, we constructed an unsatisfiable constraint system. + Unsatisfiable, + /// During synthesis, our polynomials ended up being too high of degree + PolynomialDegreeTooLarge, + /// During proof generation, we encountered an identity in the CRS + UnexpectedIdentity, + /// During proof generation, we encountered an I/O error with the CRS + IoError(io::Error), + /// During verification, our verifying key was malformed. + MalformedVerifyingKey, + /// During CRS generation, we observed an unconstrained auxillary variable + UnconstrainedVariable, +} + +#[derive(Clone)] +pub struct Proof { + pub a: E::G1Affine, + pub b: E::G2Affine, + pub c: E::G1Affine, +} + +impl PartialEq for Proof { + fn eq(&self, other: &Self) -> bool { + self.a == other.a && self.b == other.b && self.c == other.c + } +} + +impl Proof { + pub fn write(&self, mut writer: W) -> io::Result<()> { + writer.write_all(self.a.into_compressed().as_ref())?; + writer.write_all(self.b.into_compressed().as_ref())?; + writer.write_all(self.c.into_compressed().as_ref())?; + + Ok(()) + } + + pub fn read(mut reader: R) -> io::Result { + let mut g1_repr = ::Compressed::empty(); + let mut g2_repr = ::Compressed::empty(); + + reader.read_exact(g1_repr.as_mut())?; + let a = g1_repr + .into_affine() + .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) + .and_then(|e| { + if e.is_zero() { + Err(io::Error::new( + io::ErrorKind::InvalidData, + "point at infinity", + )) + } else { + Ok(e) + } + })?; + + reader.read_exact(g2_repr.as_mut())?; + let b = g2_repr + .into_affine() + .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) + .and_then(|e| { + if e.is_zero() { + Err(io::Error::new( + io::ErrorKind::InvalidData, + "point at infinity", + )) + } else { + Ok(e) + } + })?; + + reader.read_exact(g1_repr.as_mut())?; + let c = g1_repr + .into_affine() + .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) + .and_then(|e| { + if e.is_zero() { + Err(io::Error::new( + io::ErrorKind::InvalidData, + "point at infinity", + )) + } else { + Ok(e) + } + })?; + + Ok(Proof { a: a, b: b, c: c }) + } +} + +#[derive(Clone)] +pub struct TruncatedVerifyingKey { + pub alpha_g1: E::G1Affine, + pub beta_g2: E::G2Affine, + pub gamma_g2: E::G2Affine, + pub delta_g2: E::G2Affine, + pub ic: Vec, +} + +impl TruncatedVerifyingKey { + pub fn write(&self, mut writer: W) -> io::Result<()> { + writer.write_all(self.alpha_g1.into_compressed().as_ref())?; + writer.write_all(self.beta_g2.into_compressed().as_ref())?; + writer.write_all(self.gamma_g2.into_compressed().as_ref())?; + writer.write_all(self.delta_g2.into_compressed().as_ref())?; + for ic in &self.ic { + writer.write_all(ic.into_compressed().as_ref())?; + } + Ok(()) + } + + pub fn read(mut reader: R) -> io::Result { + let mut g1_repr = ::Compressed::empty(); + let mut g2_repr = ::Compressed::empty(); + + reader.read_exact(g1_repr.as_mut())?; + let alpha_g1 = g1_repr + .into_affine_unchecked() + .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) + .and_then(|e| { + if e.is_zero() { + Err(io::Error::new( + io::ErrorKind::InvalidData, + "point at infinity", + )) + } else { + Ok(e) + } + })?; + + reader.read_exact(g2_repr.as_mut())?; + let beta_g2 = g2_repr + .into_affine_unchecked() + .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) + .and_then(|e| { + if e.is_zero() { + Err(io::Error::new( + io::ErrorKind::InvalidData, + "point at infinity", + )) + } else { + Ok(e) + } + })?; + + reader.read_exact(g2_repr.as_mut())?; + let gamma_g2 = g2_repr + .into_affine_unchecked() + .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) + .and_then(|e| { + if e.is_zero() { + Err(io::Error::new( + io::ErrorKind::InvalidData, + "point at infinity", + )) + } else { + Ok(e) + } + })?; + + reader.read_exact(g2_repr.as_mut())?; + let delta_g2 = g2_repr + .into_affine_unchecked() + .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) + .and_then(|e| { + if e.is_zero() { + Err(io::Error::new( + io::ErrorKind::InvalidData, + "point at infinity", + )) + } else { + Ok(e) + } + })?; + + let mut ic = vec![]; + + while reader.read_exact(g1_repr.as_mut()).is_ok() { + let g1 = g1_repr + .into_affine_unchecked() + .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) + .and_then(|e| { + if e.is_zero() { + Err(io::Error::new( + io::ErrorKind::InvalidData, + "point at infinity", + )) + } else { + Ok(e) + } + })?; + ic.push(g1); + } + + Ok(TruncatedVerifyingKey { + alpha_g1: alpha_g1, + beta_g2: beta_g2, + gamma_g2: gamma_g2, + delta_g2: delta_g2, + ic: ic.clone(), + }) + } +} + +pub fn verify_proof<'a, E: Engine>( + tvk: &'a TruncatedVerifyingKey, + proof: &Proof, + public_inputs: &[E::Fr], +) -> Result { + if (public_inputs.len() + 1) != tvk.ic.len() { + return Err(SynthesisError::MalformedVerifyingKey); + } + + if !proof.b.mul(E::Fr::char()).is_zero() { + return Ok(false); + } + + let mut acc = tvk.ic[0].into_projective(); + + for (i, b) in public_inputs.iter().zip(tvk.ic.iter().skip(1)) { + acc.add_assign(&b.mul(i.into_repr())); + } + + // The original verification equation is: + // A * B = alpha * beta + inputs * gamma + C * delta + // ... however, we rearrange it so that it is: + // (-A) * B + alpha * beta + inputs * gamma + C * delta == 1 + + let mut neg_a = proof.a.clone(); + neg_a.negate(); + + Ok(E::final_exponentiation(&E::miller_loop(&[ + (&neg_a.prepare(), &proof.b.prepare()), + (&tvk.alpha_g1.prepare(), &tvk.beta_g2.prepare()), + (&acc.into_affine().prepare(), &tvk.gamma_g2.prepare()), + (&proof.c.prepare(), &tvk.delta_g2.prepare()), + ])) + .unwrap() + == E::Fqk::one()) +} diff --git a/zwaves_jni/src/lib.rs b/zwaves_jni/src/lib.rs index 6ffcbce..478380d 100644 --- a/zwaves_jni/src/lib.rs +++ b/zwaves_jni/src/lib.rs @@ -1,28 +1,47 @@ -#[cfg(test)] -pub mod tests; +use std::mem; use jni::JNIEnv; -use jni::sys::{jboolean, jbyteArray, jlong}; -use jni::objects::{JObject, JValue, JClass}; +use jni::objects::JClass; +use jni::sys::{jboolean, jbyteArray}; -use pairing::bls12_381::{Fr, FrRepr, Bls12}; -use pairing::{Engine, PrimeField, Field, PrimeFieldRepr}; +pub mod bls12; +pub mod bn256; -use bellman::groth16::{Proof}; +#[no_mangle] +pub extern "system" fn Java_com_wavesplatform_zwaves_bls12_Groth16_verify( + env: JNIEnv, + _class: JClass, + jvk: jbyteArray, + jproof: jbyteArray, + jinputs: jbyteArray) + -> jboolean { + let vk = parse_jni_bytes(&env, jvk); + let proof = parse_jni_bytes(&env, jproof); + let inputs = parse_jni_bytes(&env, jinputs); -use std::{mem, io, iter}; -use std::io::{Read, Write}; -use byteorder::{BigEndian, ReadBytesExt}; + bls12::groth16_verify(&vk, &proof, &inputs).unwrap_or(0u8) +} -use zwaves_primitives::serialization::{read_fr_repr_be, read_fr_vec}; -use zwaves_primitives::verifier::{TruncatedVerifyingKey, verify_proof}; +#[no_mangle] +pub extern "system" fn Java_com_wavesplatform_zwaves_bn256_Groth16_verify( + env: JNIEnv, + _class: JClass, + jvk: jbyteArray, + jproof: jbyteArray, + jinputs: jbyteArray, +) -> jboolean { + let vk = parse_jni_bytes(&env, jvk); + let proof = parse_jni_bytes(&env, jproof); + let inputs = parse_jni_bytes(&env, jinputs); + bn256::groth16_verify(&vk, &proof, &inputs).unwrap_or(0u8) +} fn parse_jni_bytes(env: &JNIEnv, jv: jbyteArray) -> Vec { let v_len = env.get_array_length(jv).unwrap() as usize; let mut v = vec![0i8; v_len]; env.get_byte_array_region(jv, 0, &mut v[..]).unwrap(); - + unsafe { let ptr = v.as_mut_ptr(); let len = v.len(); @@ -31,124 +50,3 @@ fn parse_jni_bytes(env: &JNIEnv, jv: jbyteArray) -> Vec { Vec::from_raw_parts(ptr as *mut u8, len, cap) } } - - - - - -fn groth16_verify(vk:&[u8], proof:&[u8], inputs:&[u8]) -> io::Result { - - let buff_vk_len = vk.len(); - let buff_proof_len = proof.len(); - let buff_inputs_len = inputs.len(); - - if (buff_vk_len % 48 != 0) || (buff_inputs_len % 32 != 0) { - return Err(io::Error::new(io::ErrorKind::InvalidData, "wrong buffer length")); - } - - - let inputs_len = buff_inputs_len / 32; - - if ((buff_vk_len / 48) != (inputs_len + 8)) || (buff_proof_len != 192) { - return Err(io::Error::new(io::ErrorKind::InvalidData, "wrong buffer length")); - } - - - let vk = TruncatedVerifyingKey::::read(vk)?; - let proof = Proof::::read(proof)?; - let inputs = read_fr_vec::(inputs)?; - - if (inputs.len() != inputs_len) || (vk.ic.len() != (inputs_len + 1)) { - return Err(io::Error::new(io::ErrorKind::InvalidData, "wrong buffer parsing")); - } - - Ok(verify_proof( - &vk, - &proof, - inputs.as_slice() - ).map(|r| r as u8).unwrap_or(0)) -} - - - - - - -#[no_mangle] -pub extern "system" fn Java_com_wavesplatform_zwaves_bls12_Groth16_verify(env: JNIEnv, - class: JClass, - jvk: jbyteArray, - jproof: jbyteArray, - jinputs: jbyteArray) - -> jboolean { - - let vk = parse_jni_bytes(&env, jvk); - let proof = parse_jni_bytes(&env, jproof); - let inputs = parse_jni_bytes(&env, jinputs); - - groth16_verify(&vk, &proof, &inputs).unwrap_or(0u8) - -} - - - -#[cfg(test)] -mod local_tests { - use base64::decode; - use super::*; - - - - #[test] - fn test_groth16_verify_binaries_ok() { - - let vk = "hwk883gUlTKCyXYA6XWZa8H9/xKIYZaJ0xEs0M5hQOMxiGpxocuX/8maSDmeCk3bo5ViaDBdO7ZBxAhLSe5k/5TFQyF5Lv7KN2tLKnwgoWMqB16OL8WdbePIwTCuPtJNAFKoTZylLDbSf02kckMcZQDPF9iGh+JC99Pio74vDpwTEjUx5tQ99gNQwxULtztsqDRsPnEvKvLmsxHt8LQVBkEBm2PBJFY+OXf1MNW021viDBpR10mX4WQ6zrsGL5L0GY4cwf4tlbh+Obit+LnN/SQTnREf8fPpdKZ1sa/ui3pGi8lMT6io4D7Ujlwx2RdCkBF+isfMf77HCEGsZANw0hSrO2FGg14Sl26xLAIohdaW8O7gEaag8JdVAZ3OVLd5Df1NkZBEr753Xb8WwaXsJjE7qxwINL1KdqA4+EiYW4edb7+a9bbBeOPtb67ZxmFqgyTNS/4obxahezNkjk00ytswsENg//Ee6dWBJZyLH+QGsaU2jO/W4WvRyZhmKKPdipOhiz4Rlrd2XYgsfHsfWf5v4GOTL+13ZB24dW1/m39n2woJ+v686fXbNW85XP/r"; - let proof = "lvQLU/KqgFhsLkt/5C/scqs7nWR+eYtyPdWiLVBux9GblT4AhHYMdCgwQfSJcudvsgV6fXoK+DUSRgJ++Nqt+Wvb7GlYlHpxCysQhz26TTu8Nyo7zpmVPH92+UYmbvbQCSvX2BhWtvkfHmqDVjmSIQ4RUMfeveA1KZbSf999NE4qKK8Do+8oXcmTM4LZVmh1rlyqznIdFXPN7x3pD4E0gb6/y69xtWMChv9654FMg05bAdueKt9uA4BEcAbpkdHF"; - let inputs = "LcMT3OOlkHLzJBKCKjjzzVMg+r+FVgd52LlhZPB4RFg="; - - let vk = decode(vk).unwrap(); - let proof = decode(proof).unwrap(); - let inputs = decode(inputs).unwrap(); - - - let res = groth16_verify(&vk, &proof, &inputs).unwrap_or(0) != 0; - assert!(res, "groth16_verify should be true"); - } - - - #[test] - fn test_groth16_verify_binaries_notok() { - - let vk = "hwk883gUlTKCyXYA6XWZa8H9/xKIYZaJ0xEs0M5hQOMxiGpxocuX/8maSDmeCk3bo5ViaDBdO7ZBxAhLSe5k/5TFQyF5Lv7KN2tLKnwgoWMqB16OL8WdbePIwTCuPtJNAFKoTZylLDbSf02kckMcZQDPF9iGh+JC99Pio74vDpwTEjUx5tQ99gNQwxULtztsqDRsPnEvKvLmsxHt8LQVBkEBm2PBJFY+OXf1MNW021viDBpR10mX4WQ6zrsGL5L0GY4cwf4tlbh+Obit+LnN/SQTnREf8fPpdKZ1sa/ui3pGi8lMT6io4D7Ujlwx2RdCkBF+isfMf77HCEGsZANw0hSrO2FGg14Sl26xLAIohdaW8O7gEaag8JdVAZ3OVLd5Df1NkZBEr753Xb8WwaXsJjE7qxwINL1KdqA4+EiYW4edb7+a9bbBeOPtb67ZxmFqgyTNS/4obxahezNkjk00ytswsENg//Ee6dWBJZyLH+QGsaU2jO/W4WvRyZhmKKPdipOhiz4Rlrd2XYgsfHsfWf5v4GOTL+13ZB24dW1/m39n2woJ+v686fXbNW85XP/r"; - let proof = "lvQLU/KqgFhsLkt/5C/scqs7nWR+eYtyPdWiLVBux9GblT4AhHYMdCgwQfSJcudvsgV6fXoK+DUSRgJ++Nqt+Wvb7GlYlHpxCysQhz26TTu8Nyo7zpmVPH92+UYmbvbQCSvX2BhWtvkfHmqDVjmSIQ4RUMfeveA1KZbSf999NE4qKK8Do+8oXcmTM4LZVmh1rlyqznIdFXPN7x3pD4E0gb6/y69xtWMChv9654FMg05bAdueKt9uA4BEcAbpkdHF"; - let inputs = "cmzVCcRVnckw3QUPhmG4Bkppeg4K50oDQwQ9EH+Fq1s="; - - let vk = decode(vk).unwrap(); - let proof = decode(proof).unwrap(); - let inputs = decode(inputs).unwrap(); - - - let res = groth16_verify(&vk, &proof, &inputs).unwrap_or(0) != 0; - assert!(!res, "groth16_verify should be false"); - - } - - #[test] - fn test_groth16_verify_binaries_bad_data() { - - let vk = "hwk883gUlTKCyXYA6XWZa8H9/xKIYZaJ0xEs0M5hQOMxiGpxocuX/8maSDmeCk3bo5ViaDBdO7ZBxAhLSe5k/5TFQyF5Lv7KN2tLKnwgoWMqB16OL8WdbePIwTCuPtJNAFKoTZylLDbSf02kckMcZQDPF9iGh+JC99Pio74vDpwTEjUx5tQ99gNQwxULtztsqDRsPnEvKvLmsxHt8LQVBkEBm2PBJFY+OXf1MNW021viDBpR10mX4WQ6zrsGL5L0GY4cwf4tlbh+Obit+LnN/SQTnREf8fPpdKZ1sa/ui3pGi8lMT6io4D7Ujlwx2RdCkBF+isfMf77HCEGsZANw0hSrO2FGg14Sl26xLAIohdaW8O7gEaag8JdVAZ3OVLd5Df1NkZBEr753Xb8WwaXsJjE7qxwINL1KdqA4+EiYW4edb7+a9bbBeOPtb67ZxmFqgyTNS/4obxahezNkjk00ytswsENg//Ee6dWBJZyLH+QGsaU2jO/W4WvRyZhmKKPdipOhiz4Rlrd2XYgsfHsfWf5v4GOTL+13ZB24dW1/m39n2woJ+v686fXbNW85XP/r"; - let proof = "lvQLU/KqgFhsLkt/5C/scqs7nWR+eYtyPdWiLVBux9GblT4AhHYMdCgwQfSJcudvsgV6fXoK+DUSRgJ++Nqt+Wvb7GlYlHpxCysQhz26TTu8Nyo7zpmVPH92+UYmbvbQCSvX2BhWtvkfHmqDVjmSIQ4RUMfeveA1KZbSf999NE4qKK8Do+8oXcmTM4LZVmh1rlyqznIdFXPN7x3pD4E0gb6/y69xtWMChv9654FMg05bAdueKt9uA4BEcAbpkdHF"; - let inputs = "cmzVCcRVnckw3QUPhmG4Bkppeg4K50oDQwQ9EH+Fq1s="; - - let vk = decode(vk).unwrap(); - let proof = decode(proof).unwrap(); - let inputs = decode(inputs).unwrap(); - - - let res = groth16_verify(&vk, &proof, &inputs[0..1]).unwrap_or(0) != 0; - assert!(!res, "groth16_verify should be false"); - - } - - -} \ No newline at end of file From f5c8908a6883f127c53a49b0a53946cb1c868980 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Thu, 28 Sep 2023 17:42:16 +0400 Subject: [PATCH 02/38] CI --- .github/workflows/release.yml | 96 +++++++++++++++++++ zwaves_jni/.cargo/config | 13 --- zwaves_jni/javalib/build.gradle | 21 ++++ .../META-INF/native/osx64/aarch64/.gitkeep | 1 + 4 files changed, 118 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/release.yml delete mode 100644 zwaves_jni/.cargo/config create mode 100644 zwaves_jni/javalib/src/main/resources/META-INF/native/osx64/aarch64/.gitkeep diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..bad0fb3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,96 @@ +name: Publish artfiacts to Sonatype Repo + +on: [push] + +env: + NATIVE_DIR: zwaves_jni/javalib/src/main/resources/META-INF/native + +jobs: + build-native: + runs-on: ${{ matrix.os }} + env: + target-path: ${{ matrix.platform }}-${{ matrix.arch }} + strategy: + matrix: + platform: [darwin] + arch: [x86-64, aarch64] +# exclude: +# - platform: linux +# arch: x86-64 +# - platform: win32 +# arch: aarch64 + include: + - platform: darwin + os: macos-12 + artifact: libzwaves_jni.dylib + + - platform: darwin + arch: aarch64 + target: aarch64-apple-darwin + dest: osx64/aarch64 + + - platform: darwin + arch: x86-64 + target: x86_64-apple-darwin + dest: osx + steps: + - name: Checkout sources + uses: actions/checkout@v4 + +# - name: Remove the rust-toolchain.toml file +# run: rm rust-toolchain.toml + + - name: Install stable toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + target: ${{ matrix.target }} + + # - uses: Swatinem/rust-cache@v2 + + - name: Build native image + env: + # TARGET_FLAGS: + TARGET_DIR: ./target + # Emit backtraces on panics. + RUST_BACKTRACE: 1 + run: | + set -euxo pipefail + + cd zwaves_jni + cargo build --release --target ${{ matrix.target }} + cd .. + + cp target/${{ matrix.target }}/release/${{ matrix.artifact }} ${{ env.NATIVE_DIR }}/${{ matrix.dest }} + + - name: Upload result + uses: actions/upload-artifact@v3 + with: + name: native-libraries + path: ${{ env.NATIVE_DIR }}/**/* + + build-jni: + runs-on: ubuntu-latest + needs: build-native + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: 8 + distribution: temurin + cache: gradle + - uses: actions/download-artifact@v3 + with: + name: native-libraries + path: ${{ env.NATIVE_DIR }} + + - name: Publish Snapshot + run: | + cd zwaves_jni/javalib + ./gradlew publishToMavenLocal + + - name: Upload result + uses: actions/upload-artifact@v3 + with: + name: javalib + path: ~/.m2/repository/com/wavesplatform diff --git a/zwaves_jni/.cargo/config b/zwaves_jni/.cargo/config deleted file mode 100644 index f550e2a..0000000 --- a/zwaves_jni/.cargo/config +++ /dev/null @@ -1,13 +0,0 @@ -[target.x86_64-apple-darwin] -linker = "x86_64-apple-darwin14-clang" -ar = "x86_64-apple-darwin14-ar" - -[target.x86_64-pc-windows-gnu] -linker = "x86_64-w64-mingw32-gcc" -ar = "x86_64-w64-mingw32-gcc-ar" - -[target.i686-pc-windows-gnu] -linker = "i686-w64-mingw32-gcc" -ar = "i686-w64-mingw32-gcc-ar" - - diff --git a/zwaves_jni/javalib/build.gradle b/zwaves_jni/javalib/build.gradle index ea8180a..0166cfd 100644 --- a/zwaves_jni/javalib/build.gradle +++ b/zwaves_jni/javalib/build.gradle @@ -9,6 +9,9 @@ plugins { // Apply the java-library plugin to add support for Java Library id 'java-library' + id 'maven' + id 'maven-publish' + id 'signing' } repositories { @@ -17,6 +20,10 @@ repositories { jcenter() } +group = "com.wavesplatform" +archivesBaseName = "zwaves" +version = "0.2.0-SNAPSHOT" + dependencies { // This dependency is exported to consumers, that is to say found on their compile classpath. api 'org.apache.commons:commons-math3:3.6.1' @@ -28,6 +35,20 @@ dependencies { testImplementation 'junit:junit:4.12' } +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + + groupId = project.group + artifactId = 'zwaves' + version = project.version + } + } + repositories { + mavenLocal() + } +} test { useJUnit() diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/osx64/aarch64/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/osx64/aarch64/.gitkeep new file mode 100644 index 0000000..eec68a2 --- /dev/null +++ b/zwaves_jni/javalib/src/main/resources/META-INF/native/osx64/aarch64/.gitkeep @@ -0,0 +1 @@ +place here libzwaves_jni.dylib for Apple ARM file \ No newline at end of file From 504f5cd2ae192f1bf2833fbbac8d9e0c4e7788c0 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Fri, 29 Sep 2023 16:37:37 +0400 Subject: [PATCH 03/38] - New tests for groth16; - Formatting with rustfmt. --- rustfmt.toml | 7 + zwaves_jni/Cargo.toml | 3 + zwaves_jni/src/bls12/mod.rs | 133 +++++++++++------- zwaves_jni/src/bls12/tests/mod.rs | 85 ++++++----- zwaves_jni/src/bn256/bin/show_test_vectors.rs | 10 +- zwaves_jni/src/bn256/mod.rs | 92 +++++++++--- zwaves_jni/src/bn256/serialization.rs | 9 +- zwaves_jni/src/bn256/verifier.rs | 48 ++----- zwaves_jni/src/lib.rs | 12 +- 9 files changed, 243 insertions(+), 156 deletions(-) create mode 100644 rustfmt.toml diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..bb26182 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,7 @@ +edition = "2018" + +max_width = 120 +hard_tabs = false +newline_style = "Unix" + +imports_granularity = "Crate" diff --git a/zwaves_jni/Cargo.toml b/zwaves_jni/Cargo.toml index 8db422a..b98b326 100644 --- a/zwaves_jni/Cargo.toml +++ b/zwaves_jni/Cargo.toml @@ -30,3 +30,6 @@ rand = "0.4" version = "=0.7" features = ["derive"] package = "ff_ce" + +[dev-dependencies] +test-case = "3.2.1" diff --git a/zwaves_jni/src/bls12/mod.rs b/zwaves_jni/src/bls12/mod.rs index b11c91f..f3f3140 100644 --- a/zwaves_jni/src/bls12/mod.rs +++ b/zwaves_jni/src/bls12/mod.rs @@ -3,8 +3,10 @@ use std::io; use bellman::groth16::Proof; use pairing::bls12_381::{Bls12, Fr}; -use zwaves_primitives::serialization::read_fr_vec; -use zwaves_primitives::verifier::{TruncatedVerifyingKey, verify_proof}; +use zwaves_primitives::{ + serialization::read_fr_vec, + verifier::{verify_proof, TruncatedVerifyingKey}, +}; #[cfg(test)] pub mod tests; @@ -32,58 +34,89 @@ pub fn groth16_verify(vk: &[u8], proof: &[u8], inputs: &[u8]) -> io::Result return Err(io::Error::new(io::ErrorKind::InvalidData, "wrong buffer parsing")); } - Ok(verify_proof( - &vk, - &proof, - inputs.as_slice(), - ).map(|r| r as u8).unwrap_or(0)) + Ok(verify_proof(&vk, &proof, inputs.as_slice()) + .map(|r| r as u8) + .unwrap_or(0)) } #[cfg(test)] mod local_tests { - use base64::decode; - use super::*; - - #[test] - fn test_groth16_verify_binaries_ok() { - let vk = "hwk883gUlTKCyXYA6XWZa8H9/xKIYZaJ0xEs0M5hQOMxiGpxocuX/8maSDmeCk3bo5ViaDBdO7ZBxAhLSe5k/5TFQyF5Lv7KN2tLKnwgoWMqB16OL8WdbePIwTCuPtJNAFKoTZylLDbSf02kckMcZQDPF9iGh+JC99Pio74vDpwTEjUx5tQ99gNQwxULtztsqDRsPnEvKvLmsxHt8LQVBkEBm2PBJFY+OXf1MNW021viDBpR10mX4WQ6zrsGL5L0GY4cwf4tlbh+Obit+LnN/SQTnREf8fPpdKZ1sa/ui3pGi8lMT6io4D7Ujlwx2RdCkBF+isfMf77HCEGsZANw0hSrO2FGg14Sl26xLAIohdaW8O7gEaag8JdVAZ3OVLd5Df1NkZBEr753Xb8WwaXsJjE7qxwINL1KdqA4+EiYW4edb7+a9bbBeOPtb67ZxmFqgyTNS/4obxahezNkjk00ytswsENg//Ee6dWBJZyLH+QGsaU2jO/W4WvRyZhmKKPdipOhiz4Rlrd2XYgsfHsfWf5v4GOTL+13ZB24dW1/m39n2woJ+v686fXbNW85XP/r"; - let proof = "lvQLU/KqgFhsLkt/5C/scqs7nWR+eYtyPdWiLVBux9GblT4AhHYMdCgwQfSJcudvsgV6fXoK+DUSRgJ++Nqt+Wvb7GlYlHpxCysQhz26TTu8Nyo7zpmVPH92+UYmbvbQCSvX2BhWtvkfHmqDVjmSIQ4RUMfeveA1KZbSf999NE4qKK8Do+8oXcmTM4LZVmh1rlyqznIdFXPN7x3pD4E0gb6/y69xtWMChv9654FMg05bAdueKt9uA4BEcAbpkdHF"; - let inputs = "LcMT3OOlkHLzJBKCKjjzzVMg+r+FVgd52LlhZPB4RFg="; - - let vk = decode(vk).unwrap(); - let proof = decode(proof).unwrap(); - let inputs = decode(inputs).unwrap(); - - let res = groth16_verify(&vk, &proof, &inputs).unwrap_or(0) != 0; - assert!(res, "groth16_verify should be true"); - } - - #[test] - fn test_groth16_verify_binaries_notok() { - let vk = "hwk883gUlTKCyXYA6XWZa8H9/xKIYZaJ0xEs0M5hQOMxiGpxocuX/8maSDmeCk3bo5ViaDBdO7ZBxAhLSe5k/5TFQyF5Lv7KN2tLKnwgoWMqB16OL8WdbePIwTCuPtJNAFKoTZylLDbSf02kckMcZQDPF9iGh+JC99Pio74vDpwTEjUx5tQ99gNQwxULtztsqDRsPnEvKvLmsxHt8LQVBkEBm2PBJFY+OXf1MNW021viDBpR10mX4WQ6zrsGL5L0GY4cwf4tlbh+Obit+LnN/SQTnREf8fPpdKZ1sa/ui3pGi8lMT6io4D7Ujlwx2RdCkBF+isfMf77HCEGsZANw0hSrO2FGg14Sl26xLAIohdaW8O7gEaag8JdVAZ3OVLd5Df1NkZBEr753Xb8WwaXsJjE7qxwINL1KdqA4+EiYW4edb7+a9bbBeOPtb67ZxmFqgyTNS/4obxahezNkjk00ytswsENg//Ee6dWBJZyLH+QGsaU2jO/W4WvRyZhmKKPdipOhiz4Rlrd2XYgsfHsfWf5v4GOTL+13ZB24dW1/m39n2woJ+v686fXbNW85XP/r"; - let proof = "lvQLU/KqgFhsLkt/5C/scqs7nWR+eYtyPdWiLVBux9GblT4AhHYMdCgwQfSJcudvsgV6fXoK+DUSRgJ++Nqt+Wvb7GlYlHpxCysQhz26TTu8Nyo7zpmVPH92+UYmbvbQCSvX2BhWtvkfHmqDVjmSIQ4RUMfeveA1KZbSf999NE4qKK8Do+8oXcmTM4LZVmh1rlyqznIdFXPN7x3pD4E0gb6/y69xtWMChv9654FMg05bAdueKt9uA4BEcAbpkdHF"; - let inputs = "cmzVCcRVnckw3QUPhmG4Bkppeg4K50oDQwQ9EH+Fq1s="; - - let vk = decode(vk).unwrap(); - let proof = decode(proof).unwrap(); - let inputs = decode(inputs).unwrap(); - - let res = groth16_verify(&vk, &proof, &inputs).unwrap_or(0) != 0; - assert!(!res, "groth16_verify should be false"); - } - - #[test] - fn test_groth16_verify_binaries_bad_data() { - let vk = "hwk883gUlTKCyXYA6XWZa8H9/xKIYZaJ0xEs0M5hQOMxiGpxocuX/8maSDmeCk3bo5ViaDBdO7ZBxAhLSe5k/5TFQyF5Lv7KN2tLKnwgoWMqB16OL8WdbePIwTCuPtJNAFKoTZylLDbSf02kckMcZQDPF9iGh+JC99Pio74vDpwTEjUx5tQ99gNQwxULtztsqDRsPnEvKvLmsxHt8LQVBkEBm2PBJFY+OXf1MNW021viDBpR10mX4WQ6zrsGL5L0GY4cwf4tlbh+Obit+LnN/SQTnREf8fPpdKZ1sa/ui3pGi8lMT6io4D7Ujlwx2RdCkBF+isfMf77HCEGsZANw0hSrO2FGg14Sl26xLAIohdaW8O7gEaag8JdVAZ3OVLd5Df1NkZBEr753Xb8WwaXsJjE7qxwINL1KdqA4+EiYW4edb7+a9bbBeOPtb67ZxmFqgyTNS/4obxahezNkjk00ytswsENg//Ee6dWBJZyLH+QGsaU2jO/W4WvRyZhmKKPdipOhiz4Rlrd2XYgsfHsfWf5v4GOTL+13ZB24dW1/m39n2woJ+v686fXbNW85XP/r"; - let proof = "lvQLU/KqgFhsLkt/5C/scqs7nWR+eYtyPdWiLVBux9GblT4AhHYMdCgwQfSJcudvsgV6fXoK+DUSRgJ++Nqt+Wvb7GlYlHpxCysQhz26TTu8Nyo7zpmVPH92+UYmbvbQCSvX2BhWtvkfHmqDVjmSIQ4RUMfeveA1KZbSf999NE4qKK8Do+8oXcmTM4LZVmh1rlyqznIdFXPN7x3pD4E0gb6/y69xtWMChv9654FMg05bAdueKt9uA4BEcAbpkdHF"; - let inputs = "cmzVCcRVnckw3QUPhmG4Bkppeg4K50oDQwQ9EH+Fq1s="; - - let vk = decode(vk).unwrap(); - let proof = decode(proof).unwrap(); - let inputs = decode(inputs).unwrap(); - - let res = groth16_verify(&vk, &proof, &inputs[0..1]).unwrap_or(0) != 0; - assert!(!res, "groth16_verify should be false"); + use base64::decode; + use test_case::test_case; + + #[test_case( + "hwk883gUlTKCyXYA6XWZa8H9/xKIYZaJ0xEs0M5hQOMxiGpxocuX/8maSDmeCk3bo5ViaDBdO7ZBxAhLSe5k/5TFQyF5Lv7KN2tLKnwgoWMqB16OL8WdbePIwTCuPtJNAFKoTZylLDbSf02kckMcZQDPF9iGh+JC99Pio74vDpwTEjUx5tQ99gNQwxULtztsqDRsPnEvKvLmsxHt8LQVBkEBm2PBJFY+OXf1MNW021viDBpR10mX4WQ6zrsGL5L0GY4cwf4tlbh+Obit+LnN/SQTnREf8fPpdKZ1sa/ui3pGi8lMT6io4D7Ujlwx2RdCkBF+isfMf77HCEGsZANw0hSrO2FGg14Sl26xLAIohdaW8O7gEaag8JdVAZ3OVLd5Df1NkZBEr753Xb8WwaXsJjE7qxwINL1KdqA4+EiYW4edb7+a9bbBeOPtb67ZxmFqgyTNS/4obxahezNkjk00ytswsENg//Ee6dWBJZyLH+QGsa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xCysQhz26TTu8Nyo7zpmVPH92+UYmbvbQCSvX2BhWtvkfHmqDVjmSIQ4RUMfeveA1KZbSf999NE4qKK8Do+8oXcmTM4LZVmh1rlyqznIdFXPN7x3pD4E0gb6/y69xtWMChv9654FMg05bAdueKt9uA4BEcAbpkdHF", + "cmzVCcRVnckw3QUPhmG4Bkppeg4K50oDQwQ9EH+Fq1s=" + => false + )] + #[test_case( + "kYYCAS8vM2T99GeCr4toQ+iQzvl5fI89mPrncYqx3C1d75BQbFk8LMtcnLWwntd6knkzSwcsialcheg69eZYPK8EzKRVI5FrRHKi8rgB+R5jyPV70ejmYEx1neTmfYKODRmARr/ld6pZTzBWYDfrCkiS1QB+3q3M08OQgYcLzs/vjW4epetDCmk0K1CEGcWdh7yLzdqr7HHQNOpZI8mdj/7lR0IBqB9zvRfyTr+guUG22kZo4y2KINDp272xGglKEeTglTxyDUriZJNF/+T6F8w70MR/rV+flvuo6EJ0+HA+A2ZnBbTjOIl9wjisBV+0jgld4oAppAOzvQ7eoIx2tbuuKVSdbJm65KDxl/T+boaYnjRm3omdETYnYRk3HAhrAeWpefX+dM/k7PrcheInnxHUyjzSzqlN03xYjg28kdda9FZJaVsQKqdEJ/St9ivXlp7+dPDIOfm77haSFnvr33VwYH/KbIalfOJPRvBLzqlHD8BxunNebMr6Gr6S+u+n", + "sStVLdyxqInmv76iaNnRFB464lGq48iVeqYWSi2linE9DST0fTNhxSnvSXAoPpt8tFsanj5vPafC+ij/Fh98dOUlMbO42bf280pOZ4lm+zr63AWUpOOIugST+S6pq9zeB0OHp2NY8XFmriOEKhxeabhuV89ljqCDjlhXBeNZwM5zti4zg89Hd8TbKcw46jAsjIJe2Siw3Th7ELQQKR5ucX50f0GISmnOSceePPdvjbGJ8fSFOnSmSp8dK7uyehrU", + "" + => true + )] + #[test_case( + "mY//hEITCBCZUJUN/wsOlw1iUSSOESL6PFSbN1abGK80t5jPNICNlPuSorio4mmWpf+4uOyv3gPZe54SYGM4pfhteqJpwFQxdl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bVqRgKXWtihuIvPFaM6dt7HZEbkeMnXWwSINeYC/j3lqYnce8Jq+XkuF42stVNiooI+TuXECnFdFi9Ib25b9wtyz3H/oKg48He1ftntj5uIRCOBvzkFHGUF6Ty214v3JYvXJjdS4uS2jekplZYoV0aXEnYEOIvfF7d4xay3qkx2NspooM4HeZpiHknIWkUVhGVJBzBDLjLB", + "jiGBK+TGHfH8Oadexhdet7ExyIWibSmamWQvffZkyl3WnMoVbTQ3lOks4Mca3sU5qgcaLyQQ1FjFW4g6vtoMapZ43hTGKaWO7bQHsOCvdwHCdwJDulVH16cMTyS9F0BfBJxa88F+JKZc4qMTJjQhspmq755SrKhN9Jf+7uPUhgB4hJTSrmlOkTatgW+/HAf5kZKhv2oRK5p5kS4sU48oqlG1azhMtcHEXDQdcwf9ANel4Z9cb+MQyp2RzI/3hlIx", + "" + => false + )] + #[test_case( + "lp7+dPDIOfm77haSFnvr33VwYH/KbIalfOJPRvBLzqlHD8BxunNebMr6Gr6S+u+nh7yLzdqr7HHQNOpZI8mdj/7lR0IBqB9zvRfyTr+guUG22kZo4y2KINDp272xGglKEeTglTxyDUriZJNF/+T6F8w70MR/rV+flvuo6EJ0+HA+A2ZnBbTjOIl9wjisBV+0iISo2JdNY1vPXlpwhlL2fVpW/WlREkF0bKlBadDIbNJBgM4niJGuEZDru3wqrGueETKHPv7hQ8em+p6vQolp7c0iknjXrGnvlpf4QtUtpg3z/D+snWjRPbVqRgKXWtihuIvPFaM6dt7HZEbkeMnXWwSINeYC/j3lqYnce8Jq+XkuF42stVNiooI+TuXECnFdFi9Ib25b9wtyz3H/oKg48He1ftntj5uIRCOBvzkFHGUF6Ty214v3JYvXJjdS4uS2jekplZYoV0aXEnYEOIvfF7d4xay3qkx2NspooM4HeZpiHknIWkUVhGVJBzBDLjLBjiGBK+TGHfH8Oadexhdet7ExyIWibSmamWQvffZkyl3WnMoVbTQ3lOks4Mca3sU5", + "hp1iMepdu0rKoBh0NXcw9F9hkiggDIkRNINq2rlvUypPiSmp8U8tDSMeG0YVSovFteecr3THhBJj0qNeEe9jA2Ci64fKG9WT1heMYzEAQKebOErYXYCm9d72n97mYn1XBq+g1Y730XEDv4BIDI1hBDntJcgcj/cSvcILB1+60axJvtyMyuizxUr1JUBUq9njtmJ9m8zK6QZLNqMiKh0f2jokQb5mVhu6v5guW3KIjwQc/oFK/l5ehKAOPKUUggNh", + "c9BSUPtO0xjPxWVNkEMfXe7O4UZKpaH/nLIyQJj7iA4=" + => false + )] + #[test_case( + "lp7+dPDIOfm77haSFnvr33VwYH/KbIalfOJPRvBLzqlHD8BxunNebMr6Gr6S+u+nh7yLzdqr7HHQNOpZI8mdj/7lR0IBqB9zvRfyTr+guUG22kZo4y2KINDp272xGglKEeTglTxyDUriZJNF/+T6F8w70MR/rV+flvuo6EJ0+HA+A2ZnBbTjOIl9wjisBV+0iISo2JdNY1vPXlpwhlL2fVpW/WlREkF0bKlBadDIbNJBgM4niJGuEZDru3wqrGueETKHPv7hQ8em+p6vQolp7c0iknjXrGnvlpf4QtUtpg3z/D+snWjRPbVqRgKXWtihuIvPFaM6dt7HZEbkeMnXWwSINeYC/j3lqYnce8Jq+XkuF42stVNiooI+TuXECnFdFi9Ib25b9wtyz3H/oKg48He1ftntj5uIRCOBvzkFHGUF6Ty214v3JYvXJjdS4uS2jekplZYoV0aXEnYEOIvfF7d4xay3qkx2NspooM4HeZpiHknIWkUVhGVJBzBDLjLBjiGBK+TGHfH8Oadexhdet7ExyIWibSmamWQvffZkyl3WnMoVbTQ3lOks4Mca3sU5hp1iMepdu0rKoBh0NXcw9F9hkiggDIkRNINq2rlvUypPiSmp8U8tDSMeG0YVSovFlA4DsjBwntJH45NgNbY/Rbu/hfe7QskTkBiTo2A+kmYSH75Uvf2UAXwBAT1PoE0sqtYndF2Kbthl6GylV3j9NIKtIzHd/GwleExuM7KlI1H22P78br5zmh8D7V1aFcxPpftQhjch4abXuxEP4ahgfNmthdhoSvQykLhjbmG9BrvwmyaDRd/sHCTeSXmLq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mmReN9NrSoovLepDsNmzDVraO71B4rkx7uPXvkqvt3Zkr2EPBjj2m83dbA/GGVgoYYjgBmFX6/srvLADxerZTKG2moOQrmAx9GJ99nwhRbW", + "I8C5RcBDPi2n4omt9oOV2rZk9T9xlSV8PQvLeVHjGb00fCVz7AHOIjLJ03ZCTLQwEKkAk9tQWJ6gFTBnG2+0DDHlXcVkwpMafcpS2diKFe0T4fRb0t9mxNzOFiRVcJoeMU1zb/rE4dIMm9rbEPSDnVSOd8tHNnJDkT+/NcNsQ2w0UEVJJRAEnC7G0Y3522RlDLxpTZ6w0U/9V0pLNkFgDCkFBKvpaEfPDJjoEVyCUWDC1ts9LIR43xh3ZZBdcO/HATHoLzxM3Ef11qF+riV7WDPEJfK11u8WGazzCAFhsx0aKkkbnKl7LnypBzwRvrG2JxdLI/oXL0eoIw9woVjqrg6elHudnHDXezDVXjRWMPaU+L3tOW9aqN+OdP4AhtpgT2CoRCjrOIU3MCFqsrCK9bh33PW1gtNeHC78mIetQM5LWZHtw4KNwafTrQ+GCKPelJhiC2x7ygBtat5rtBsJAVF5wjssLPZx/7fqNqifXB7WyMV7J1M8LBQVXj5kLoS9bpmNHlERRSadC0DEUbY9xhIG2xo7R88R0sq04a299MFv8XJNd+IdueYiMiGF5broHD4UUhPxRBlBO3lOfDTPnRSUGS3Sr6GxwCjKO3MObz/6RNxCk9SnQ4NccD17hS/mEFt8d4ERZOfmuvD3A0RCPCnx3Fr6rHdm6j+cfn/NM6o=" + => false + )] + fn groth16_verify_test(vk_b64: &str, proof_b64: &str, inputs_b64: &str) -> bool { + let vk = decode(&vk_b64).unwrap(); + let proof = decode(&proof_b64).unwrap(); + let inputs = decode(&inputs_b64).unwrap(); + + return groth16_verify(&vk, &proof, &inputs).unwrap_or(0) != 0; } } diff --git a/zwaves_jni/src/bls12/tests/mod.rs b/zwaves_jni/src/bls12/tests/mod.rs index 6080de6..54c055e 100644 --- a/zwaves_jni/src/bls12/tests/mod.rs +++ b/zwaves_jni/src/bls12/tests/mod.rs @@ -2,20 +2,25 @@ extern crate pairing; use std::io::{Cursor, Read, Seek, SeekFrom}; -use bellman::{Circuit, ConstraintSystem, SynthesisError}; -use bellman::groth16::{create_random_proof, generate_random_parameters}; -use bellman::LinearCombination; -use pairing::{Engine, Field, PrimeField, PrimeFieldRepr}; -use pairing::bls12_381::{Bls12, Fr}; -use rand::os::OsRng; -use rand::Rng; - -use sapling_crypto::circuit::num::AllocatedNum; -use sapling_crypto::circuit::pedersen_hash; -use sapling_crypto::jubjub::{JubjubBls12, JubjubEngine, JubjubParams}; -use zwaves_primitives::pedersen_hasher; -use zwaves_primitives::serialization::write_fr_iter; -use zwaves_primitives::verifier::{truncate_verifying_key, verify_proof}; +use bellman::{ + groth16::{create_random_proof, generate_random_parameters}, + Circuit, ConstraintSystem, LinearCombination, SynthesisError, +}; +use pairing::{ + bls12_381::{Bls12, Fr}, + Field, +}; +use rand::{os::OsRng, Rng}; + +use sapling_crypto::{ + circuit::{num::AllocatedNum, pedersen_hash}, + jubjub::{JubjubBls12, JubjubEngine}, +}; +use zwaves_primitives::{ + pedersen_hasher, + serialization::write_fr_iter, + verifier::{truncate_verifying_key, verify_proof}, +}; #[derive(Clone)] pub struct PedersenDemo { @@ -26,31 +31,42 @@ pub struct PedersenDemo { } impl Circuit for PedersenDemo { - fn synthesize>( - self, - cs: &mut CS, - ) -> Result<(), SynthesisError> - { - let image = AllocatedNum::alloc(cs.namespace(|| "signal public input image"), || self.image.ok_or(SynthesisError::AssignmentMissing))?; + fn synthesize>(self, cs: &mut CS) -> Result<(), SynthesisError> { + let image = AllocatedNum::alloc(cs.namespace(|| "signal public input image"), || { + self.image.ok_or(SynthesisError::AssignmentMissing) + })?; image.inputize(cs.namespace(|| "image inputize"))?; - let preimage = AllocatedNum::alloc(cs.namespace(|| "signal input preimage"), || self.preimage.ok_or(SynthesisError::AssignmentMissing))?; + let preimage = AllocatedNum::alloc(cs.namespace(|| "signal input preimage"), || { + self.preimage.ok_or(SynthesisError::AssignmentMissing) + })?; let preimage_bits = preimage.into_bits_le_strict(cs.namespace(|| "preimage_bits <== bitify(preimage)"))?; let image_calculated = pedersen_hash::pedersen_hash( cs.namespace(|| "image_calculated <== pedersen_hash(preimage_bits)"), pedersen_hash::Personalization::NoteCommitment, &preimage_bits, &self.params, - )?.get_x().clone(); + )? + .get_x() + .clone(); let mut data_sum = LinearCombination::::zero(); self.data.into_iter().enumerate().for_each(|(i, e)| { - let n = AllocatedNum::alloc(cs.namespace(|| format!("data_item[{}]", i)), || e.ok_or(SynthesisError::AssignmentMissing)).unwrap(); - n.inputize(cs.namespace(|| format!("data_item[{}] inputize", i))).unwrap(); + let n = AllocatedNum::alloc(cs.namespace(|| format!("data_item[{}]", i)), || { + e.ok_or(SynthesisError::AssignmentMissing) + }) + .unwrap(); + n.inputize(cs.namespace(|| format!("data_item[{}] inputize", i))) + .unwrap(); data_sum = data_sum.clone() + (E::Fr::one(), n.get_variable()); }); - cs.enforce(|| "image_calculated === image", |lc| lc + image.get_variable(), |lc| lc + CS::one(), |lc| lc + image_calculated.get_variable()); + cs.enforce( + || "image_calculated === image", + |lc| lc + image.get_variable(), + |lc| lc + CS::one(), + |lc| lc + image_calculated.get_variable(), + ); cs.enforce(|| "data sum equals zero", |lc| lc, |lc| lc, |lc| lc + &data_sum); Ok(()) } @@ -65,11 +81,14 @@ mod tests { let rng = &mut OsRng::new().unwrap(); let mut sum = Fr::zero(); - let mut data: Vec = (0..15).into_iter().map(|_| { - let n = rng.gen(); - sum.add_assign(&n); - n - }).collect(); + let mut data: Vec = (0..15) + .into_iter() + .map(|_| { + let n = rng.gen(); + sum.add_assign(&n); + n + }) + .collect(); data[14].sub_assign(&sum); @@ -125,11 +144,7 @@ mod tests { println!("Inputs: {}", base64::encode(&inputs_b)); - let result = verify_proof( - &tvk, - &proof, - &inputs, - ).unwrap(); + let result = verify_proof(&tvk, &proof, &inputs).unwrap(); assert!(result, "Proof is correct"); Ok(()) } diff --git a/zwaves_jni/src/bn256/bin/show_test_vectors.rs b/zwaves_jni/src/bn256/bin/show_test_vectors.rs index 1298555..a596956 100644 --- a/zwaves_jni/src/bn256/bin/show_test_vectors.rs +++ b/zwaves_jni/src/bn256/bin/show_test_vectors.rs @@ -3,12 +3,12 @@ extern crate zwaves_jni; use std::io::Cursor; use ff::Field; -use pairing_ce::{CurveAffine, CurveProjective}; -use pairing_ce::bn256::*; +use pairing_ce::{bn256::*, CurveAffine, CurveProjective}; use rand::{Rand, SeedableRng, XorShiftRng}; -use zwaves_jni::bn256::serialization::write_fr_iter; -use zwaves_jni::bn256::verifier::Proof; -use zwaves_jni::bn256::verifier::TruncatedVerifyingKey; +use zwaves_jni::bn256::{ + serialization::write_fr_iter, + verifier::{Proof, TruncatedVerifyingKey}, +}; fn main() { const NINPUTS: usize = 1; diff --git a/zwaves_jni/src/bn256/mod.rs b/zwaves_jni/src/bn256/mod.rs index 86275ec..69ed2b9 100644 --- a/zwaves_jni/src/bn256/mod.rs +++ b/zwaves_jni/src/bn256/mod.rs @@ -2,8 +2,7 @@ use std::io; use pairing_ce::bn256::{Bn256, Fr}; use serialization::read_fr_vec; -use verifier::{TruncatedVerifyingKey, verify_proof}; -use verifier::Proof; +use verifier::{verify_proof, Proof, TruncatedVerifyingKey}; pub mod serialization; pub mod verifier; @@ -14,19 +13,13 @@ pub fn groth16_verify(vk: &[u8], proof: &[u8], inputs: &[u8]) -> io::Result let buff_inputs_len = inputs.len(); if (buff_vk_len % 32 != 0) || (buff_inputs_len % 32 != 0) { - return Err(io::Error::new( - io::ErrorKind::InvalidData, - "wrong buffer length", - )); + return Err(io::Error::new(io::ErrorKind::InvalidData, "wrong buffer length")); } let inputs_len = buff_inputs_len / 32; if ((buff_vk_len / 32) != (inputs_len + 8)) || (buff_proof_len != 128) { - return Err(io::Error::new( - io::ErrorKind::InvalidData, - "wrong buffer length", - )); + return Err(io::Error::new(io::ErrorKind::InvalidData, "wrong buffer length")); } let vk = TruncatedVerifyingKey::::read(vk)?; @@ -34,10 +27,7 @@ pub fn groth16_verify(vk: &[u8], proof: &[u8], inputs: &[u8]) -> io::Result let inputs = read_fr_vec::(inputs)?; if (inputs.len() != inputs_len) || (vk.ic.len() != (inputs_len + 1)) { - return Err(io::Error::new( - io::ErrorKind::InvalidData, - "wrong buffer parsing", - )); + return Err(io::Error::new(io::ErrorKind::InvalidData, "wrong buffer parsing")); } Ok(verify_proof(&vk, &proof, inputs.as_slice()) @@ -50,16 +40,76 @@ mod local_tests { use base64::decode; use super::*; + use test_case::test_case; - #[test] - fn test_groth16_verify_binaries_ok() { - let (vk, proof, inputs) = ("LDCJzjgi5HtcHEXHfU8TZz+ZUHD2ZwsQ7JIEvzdMPYKYs9SoGkKUmg1yya4TE0Ms7x+KOJ4Ze/CPfKp2s5jbniFNM71N/YlHVbNkytLtQi1DzReSh9SNBsvskdY5mavQJe+67PuPVEYnx+lJ97qIG8243njZbGWPqUJ2Vqj49NAunhqX+eIkK3zAB3IPWls3gruzX2t9wrmyE9cVVvf1kgWx63PsQV37qdH0KcFRpCH89k4TPS6fLmqdFxX3YGHCGFTpr6tLogvjbUFJPT98kJ/xck0C0B/s8PTVKdao4VQHT4DBIO8+GB3CQVh6VV4EcMLtDWWNxF4yloAlKcFT0Q4AzJSimpFqd/SwSz9Pb7uk5srte3nwphVamC+fHlJt", "GQPBoHuCPcIosF+WZKE5jZV13Ib4EdjLnABncpSHcMKBZl0LhllnPxcuzExIQwhxcfXvFFAjlnDGpKauQ9OQsjBKUBsdBZnGiV2Sg4TSdyHuLo2AbRRqJN0IV3iH3On8I4ngnL30ZAxVyGQH2EK58aUZGxMbbXGR9pQdh99QaiE=", "IfZhAypdtgvecKDWzVyRuvXatmFf2ZYcMWVkCJ0/MQo="); + #[test_case( + "LDCJzjgi5HtcHEXHfU8TZz+ZUHD2ZwsQ7JIEvzdMPYKYs9SoGkKUmg1yya4TE0Ms7x+KOJ4Ze/CPfKp2s5jbniFNM71N/YlHVbNkytLtQi1DzReSh9SNBsvskdY5mav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EAY2zQCZ/z3sFs7FwAZ5TXhDfhYR5sQ8tZaF3FWh+Yzf5hgMmXWrApp/arwPszNhKCoxScnhPSgfcxYSdauqvp5+vcacJFY1OkWG6tQ6iuh5CZSdX645oA7oNr9d5kXYSewhTflcV9pufeaH21BtEipHpO3sNRkUngnHC+uj1D8ReSgcCofnv8s0mVme9Ml64r6CbeaHK+x5Mc9bolN96XJZ137xkPDpev+RVrVK6ZIFrH2hFl8/vGoBwWDlmjmVzUt4YQdsCavsf7c0vBa7d33EcvyvQMDY="; + )] + fn groth16_verify_ok_test(vk_b64: &str, proof_b64: &str, inputs_b64: &str) { + let vk = decode(&vk_b64).unwrap(); + let proof = decode(&proof_b64).unwrap(); + let inputs = decode(&inputs_b64).unwrap(); - let vk = decode(vk).unwrap(); - let proof = decode(proof).unwrap(); - let inputs = decode(inputs).unwrap(); + let res = groth16_verify(&vk, &proof, &inputs).unwrap_or(0) != 0; + assert!(res, "groth16_verify should return true"); + } + + #[test_case( + vec![1; 256], + "CfEpVT6b8+4NAeDs3QwiSN7zqfxzAkQdIu8eBXzoAQIS+AgJcYppUx7COvtbWa7TDtaER1ydtoYWBcBtRMvrHQJ64u4XmLooTwikzECPz+VRcYknrGEoyGeZanNFWEwgplf9bX3JvW1RshlAfN7iJESdqBCmUNsrObHNxhHFJRo=", + ""; + "256 byte vk, empty inputs" + )] + #[test_case( + [1; 256 + 32].to_vec(), + "CfEpVT6b8+4NAeDs3QwiSN7zqfxzAkQdIu8eBXzoAQIS+AgJcYppUx7COvtbWa7TDtaER1ydtoYWBcBtRMvrHQJ64u4XmLooTwikzECPz+VRcYknrGEoyGeZanNFWEwgplf9bX3JvW1RshlAfN7iJESdqBCmUNsrObHNxhHFJRo=", + "c9BSUPtO0xjPxWVNkEMfXe7O4UZKpaH/nLIyQJj7iA4="; + "288 byte vk" + )] + #[test_case( + [1; 256 + 32 * 15].to_vec(), + "CfEpVT6b8+4NAeDs3QwiSN7zqfxzAkQdIu8eBXzoAQIS+AgJ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cVkwpMafcpS2diKFe0T4fRb0t9mxNzOFiRVcJoeMU1zb/rE4dIMm9rbEPSDnVSOd8tHNnJDkT+/NcNsQ2w0UEVJJRAEnC7G0Y3522RlDLxpTZ6w0U/9V0pLNkFgDCkFBKvpaEfPDJjoEVyCUWDC1ts9LIR43xh3ZZBdcO/HATHoLzxM3Ef11qF+riV7WDPEJfK11u8WGazzCAFhsx0aKkkbnKl7LnypBzwRvrG2JxdLI/oXL0eoIw9woVjqrg6elHudnHDXezDVXjRWMPaU+L3tOW9aqN+OdP4AhtpgT2CoRCjrOIU3MCFqsrCK9bh33PW1gtNeHC78mIetQM5LWZHtw4KNwafTrQ+GCKPelJhiC2x7ygBtat5rtBsJAVF5wjssLPZx/7fqNqifXB7WyMV7J1M8LBQVXj5kLoS9bpmNHlERRSadC0DEUbY9xhIG2xo7R88R0sq04a299MFv8XJNd+IdueYiMiGF5broHD4UUhPxRBlBO3lOfDTPnRSUGS3Sr6GxwCjKO3MObz/6RNxCk9SnQ4NccD17hS/mEFt8d4ERZOfmuvD3A0RCPCnx3Fr6rHdm6j+cfn/NM6o="; + "768 byte vk" + )] + fn groth16_verify_fail_test(vk: Vec, proof_b64: &str, inputs_b64: &str) { + let proof = base64::decode(proof_b64).expect("Invalid base64 in proof"); + let inputs = base64::decode(inputs_b64).expect("Invalid base64 in inputs"); let res = groth16_verify(&vk, &proof, &inputs).unwrap_or(0) != 0; - assert!(res, "groth16_verify should be true"); + assert!(!res, "groth16_verify should return false"); } } diff --git a/zwaves_jni/src/bn256/serialization.rs b/zwaves_jni/src/bn256/serialization.rs index 9ef9c80..b3469a7 100644 --- a/zwaves_jni/src/bn256/serialization.rs +++ b/zwaves_jni/src/bn256/serialization.rs @@ -25,8 +25,7 @@ pub fn read_fr_vec(data: &[u8]) -> io::Result> { }; offset += fr_repr_sz; - let fr = Fr::from_repr(fr_repr) - .map_err(|_e| io::Error::new(io::ErrorKind::InvalidData, "not in field"))?; + let fr = Fr::from_repr(fr_repr).map_err(|_e| io::Error::new(io::ErrorKind::InvalidData, "not in field"))?; inputs.push(fr); } @@ -34,9 +33,9 @@ pub fn read_fr_vec(data: &[u8]) -> io::Result> { } pub fn write_fr_iter<'a, I, Fr>(source: I, data: &mut [u8]) -> io::Result<()> - where - Fr: PrimeField, - I: IntoIterator, +where + Fr: PrimeField, + I: IntoIterator, { let fr_repr_sz = mem::size_of::(); for (i, e) in source.into_iter().enumerate() { diff --git a/zwaves_jni/src/bn256/verifier.rs b/zwaves_jni/src/bn256/verifier.rs index 980f2ea..6a19142 100644 --- a/zwaves_jni/src/bn256/verifier.rs +++ b/zwaves_jni/src/bn256/verifier.rs @@ -1,5 +1,7 @@ -use std::io; -use std::io::{Read, Write}; +use std::{ + io, + io::{Read, Write}, +}; use ff::{Field, PrimeField}; use pairing_ce::{CurveAffine, CurveProjective, EncodedPoint, Engine}; @@ -56,10 +58,7 @@ impl Proof { .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) .and_then(|e| { if e.is_zero() { - Err(io::Error::new( - io::ErrorKind::InvalidData, - "point at infinity", - )) + Err(io::Error::new(io::ErrorKind::InvalidData, "point at infinity")) } else { Ok(e) } @@ -71,10 +70,7 @@ impl Proof { .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) .and_then(|e| { if e.is_zero() { - Err(io::Error::new( - io::ErrorKind::InvalidData, - "point at infinity", - )) + Err(io::Error::new(io::ErrorKind::InvalidData, "point at infinity")) } else { Ok(e) } @@ -86,10 +82,7 @@ impl Proof { .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) .and_then(|e| { if e.is_zero() { - Err(io::Error::new( - io::ErrorKind::InvalidData, - "point at infinity", - )) + Err(io::Error::new(io::ErrorKind::InvalidData, "point at infinity")) } else { Ok(e) } @@ -130,10 +123,7 @@ impl TruncatedVerifyingKey { .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) .and_then(|e| { if e.is_zero() { - Err(io::Error::new( - io::ErrorKind::InvalidData, - "point at infinity", - )) + Err(io::Error::new(io::ErrorKind::InvalidData, "point at infinity")) } else { Ok(e) } @@ -145,10 +135,7 @@ impl TruncatedVerifyingKey { .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) .and_then(|e| { if e.is_zero() { - Err(io::Error::new( - io::ErrorKind::InvalidData, - "point at infinity", - )) + Err(io::Error::new(io::ErrorKind::InvalidData, "point at infinity")) } else { Ok(e) } @@ -160,10 +147,7 @@ impl TruncatedVerifyingKey { .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) .and_then(|e| { if e.is_zero() { - Err(io::Error::new( - io::ErrorKind::InvalidData, - "point at infinity", - )) + Err(io::Error::new(io::ErrorKind::InvalidData, "point at infinity")) } else { Ok(e) } @@ -175,10 +159,7 @@ impl TruncatedVerifyingKey { .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) .and_then(|e| { if e.is_zero() { - Err(io::Error::new( - io::ErrorKind::InvalidData, - "point at infinity", - )) + Err(io::Error::new(io::ErrorKind::InvalidData, "point at infinity")) } else { Ok(e) } @@ -192,10 +173,7 @@ impl TruncatedVerifyingKey { .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) .and_then(|e| { if e.is_zero() { - Err(io::Error::new( - io::ErrorKind::InvalidData, - "point at infinity", - )) + Err(io::Error::new(io::ErrorKind::InvalidData, "point at infinity")) } else { Ok(e) } @@ -246,6 +224,6 @@ pub fn verify_proof<'a, E: Engine>( (&acc.into_affine().prepare(), &tvk.gamma_g2.prepare()), (&proof.c.prepare(), &tvk.delta_g2.prepare()), ])) - .unwrap() + .unwrap() == E::Fqk::one()) } diff --git a/zwaves_jni/src/lib.rs b/zwaves_jni/src/lib.rs index 478380d..8d5f50f 100644 --- a/zwaves_jni/src/lib.rs +++ b/zwaves_jni/src/lib.rs @@ -1,8 +1,10 @@ use std::mem; -use jni::JNIEnv; -use jni::objects::JClass; -use jni::sys::{jboolean, jbyteArray}; +use jni::{ + objects::JClass, + sys::{jboolean, jbyteArray}, + JNIEnv, +}; pub mod bls12; pub mod bn256; @@ -13,8 +15,8 @@ pub extern "system" fn Java_com_wavesplatform_zwaves_bls12_Groth16_verify( _class: JClass, jvk: jbyteArray, jproof: jbyteArray, - jinputs: jbyteArray) - -> jboolean { + jinputs: jbyteArray, +) -> jboolean { let vk = parse_jni_bytes(&env, jvk); let proof = parse_jni_bytes(&env, jproof); let inputs = parse_jni_bytes(&env, jinputs); From d83c8c871b730bdf11107dedc76fd20e0b7e8f6a Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 08:25:23 +0400 Subject: [PATCH 04/38] - Running Rust tests in build; - Removed unnecessary dependencies in Java project. --- .github/workflows/release.yml | 1 + zwaves_jni/javalib/build.gradle | 11 ----------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bad0fb3..f893533 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -59,6 +59,7 @@ jobs: cd zwaves_jni cargo build --release --target ${{ matrix.target }} + cargo test --target ${{ matrix.target }} cd .. cp target/${{ matrix.target }}/release/${{ matrix.artifact }} ${{ env.NATIVE_DIR }}/${{ matrix.dest }} diff --git a/zwaves_jni/javalib/build.gradle b/zwaves_jni/javalib/build.gradle index 0166cfd..a76c53e 100644 --- a/zwaves_jni/javalib/build.gradle +++ b/zwaves_jni/javalib/build.gradle @@ -24,17 +24,6 @@ group = "com.wavesplatform" archivesBaseName = "zwaves" version = "0.2.0-SNAPSHOT" -dependencies { - // This dependency is exported to consumers, that is to say found on their compile classpath. - api 'org.apache.commons:commons-math3:3.6.1' - - // This dependency is used internally, and not exposed to consumers on their own compile classpath. - implementation 'com.google.guava:guava:27.0.1-jre' - - // Use JUnit test framework - testImplementation 'junit:junit:4.12' -} - publishing { publications { mavenJava(MavenPublication) { From a20f27e65489f4f4b464e1eaaafbf4968355ee53 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 08:37:31 +0400 Subject: [PATCH 05/38] Fix running Rust tests --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f893533..26be2e0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Publish artfiacts to Sonatype Repo +name: Publish artifacts to Sonatype Repo on: [push] @@ -58,8 +58,8 @@ jobs: set -euxo pipefail cd zwaves_jni + cargo test --lib --target ${{ matrix.target }} cargo build --release --target ${{ matrix.target }} - cargo test --target ${{ matrix.target }} cd .. cp target/${{ matrix.target }}/release/${{ matrix.artifact }} ${{ env.NATIVE_DIR }}/${{ matrix.dest }} From 97c7a55a204bf1c9a810bde17e2346c53f8b6351 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 09:19:15 +0400 Subject: [PATCH 06/38] Fix running Rust tests (2) --- .github/workflows/release.yml | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 26be2e0..c969735 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,9 +7,14 @@ env: jobs: build-native: + name: Build and test native libraries runs-on: ${{ matrix.os }} env: target-path: ${{ matrix.platform }}-${{ matrix.arch }} + # rust flags + TARGET_DIR: ./target + # Emit backtraces on panics. + RUST_BACKTRACE: 1 strategy: matrix: platform: [darwin] @@ -37,28 +42,24 @@ jobs: - name: Checkout sources uses: actions/checkout@v4 -# - name: Remove the rust-toolchain.toml file -# run: rm rust-toolchain.toml - - name: Install stable toolchain uses: dtolnay/rust-toolchain@stable with: toolchain: stable target: ${{ matrix.target }} - # - uses: Swatinem/rust-cache@v2 + - name: Enable rust dependencies caching + uses: Swatinem/rust-cache@v2 - - name: Build native image - env: - # TARGET_FLAGS: - TARGET_DIR: ./target - # Emit backtraces on panics. - RUST_BACKTRACE: 1 + - name: Run rust tests + if: matrix.arch != 'aarch64' # Architecture is x86-64 always: https://stackoverflow.com/a/71220337 + run: | + cd zwaves_jni + cargo test --lib --target ${{ matrix.target }} + + - name: Build native libraries run: | - set -euxo pipefail - cd zwaves_jni - cargo test --lib --target ${{ matrix.target }} cargo build --release --target ${{ matrix.target }} cd .. @@ -71,6 +72,7 @@ jobs: path: ${{ env.NATIVE_DIR }}/**/* build-jni: + name: Build JNI library runs-on: ubuntu-latest needs: build-native steps: From fd690b71e53ab518161a10dc7100963522d0c034 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 09:59:22 +0400 Subject: [PATCH 07/38] Run Java tests --- .github/workflows/release.yml | 27 ++++++++++++------- zwaves_jni/javalib/build.gradle | 6 ++++- .../zwaves/bls12/Groth16Test.java | 10 +++---- .../zwaves/bn256/Groth16Test.java | 23 ++++++++++++++++ 4 files changed, 48 insertions(+), 18 deletions(-) create mode 100644 zwaves_jni/javalib/src/test/java/com/wavesplatform/zwaves/bn256/Groth16Test.java diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c969735..79a1a25 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,13 +1,13 @@ name: Publish artifacts to Sonatype Repo -on: [push] +on: [ push ] env: NATIVE_DIR: zwaves_jni/javalib/src/main/resources/META-INF/native jobs: build-native: - name: Build and test native libraries + name: ${{ matrix.target }} library runs-on: ${{ matrix.os }} env: target-path: ${{ matrix.platform }}-${{ matrix.arch }} @@ -17,16 +17,16 @@ jobs: RUST_BACKTRACE: 1 strategy: matrix: - platform: [darwin] - arch: [x86-64, aarch64] -# exclude: -# - platform: linux -# arch: x86-64 -# - platform: win32 -# arch: aarch64 + platform: [ darwin ] + arch: [ x86-64, aarch64 ] + # exclude: + # - platform: linux + # arch: x86-64 + # - platform: win32 + # arch: aarch64 include: - platform: darwin - os: macos-12 + os: macos-latest artifact: libzwaves_jni.dylib - platform: darwin @@ -77,16 +77,23 @@ jobs: needs: build-native steps: - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 with: java-version: 8 distribution: temurin cache: gradle + - uses: actions/download-artifact@v3 with: name: native-libraries path: ${{ env.NATIVE_DIR }} + - name: Run tests + run: | + cd zwaves_jni/javalib + ./gradlew publishToMavenLocal + - name: Publish Snapshot run: | cd zwaves_jni/javalib diff --git a/zwaves_jni/javalib/build.gradle b/zwaves_jni/javalib/build.gradle index a76c53e..341d62a 100644 --- a/zwaves_jni/javalib/build.gradle +++ b/zwaves_jni/javalib/build.gradle @@ -24,6 +24,11 @@ group = "com.wavesplatform" archivesBaseName = "zwaves" version = "0.2.0-SNAPSHOT" +dependencies { + // Use JUnit test framework + testImplementation 'junit:junit:4.12' +} + publishing { publications { mavenJava(MavenPublication) { @@ -44,4 +49,3 @@ test { maxHeapSize = '1G' } - diff --git a/zwaves_jni/javalib/src/test/java/com/wavesplatform/zwaves/bls12/Groth16Test.java b/zwaves_jni/javalib/src/test/java/com/wavesplatform/zwaves/bls12/Groth16Test.java index 03d2621..16e9153 100644 --- a/zwaves_jni/javalib/src/test/java/com/wavesplatform/zwaves/bls12/Groth16Test.java +++ b/zwaves_jni/javalib/src/test/java/com/wavesplatform/zwaves/bls12/Groth16Test.java @@ -1,16 +1,14 @@ package com.wavesplatform.zwaves.bls12; import org.junit.Test; -import static org.junit.Assert.*; import java.util.Base64; -public class Groth16Test { - +import static org.junit.Assert.*; +public class Groth16Test { @Test public void test() { - byte[] vk = Base64.getDecoder().decode("hwk883gUlTKCyXYA6XWZa8H9/xKIYZaJ0xEs0M5hQOMxiGpxocuX/8maSDmeCk3bo5ViaDBdO7ZBxAhLSe5k/5TFQyF5Lv7KN2tLKnwgoWMqB16OL8WdbePIwTCuPtJNAFKoTZylLDbSf02kckMcZQDPF9iGh+JC99Pio74vDpwTEjUx5tQ99gNQwxULtztsqDRsPnEvKvLmsxHt8LQVBkEBm2PBJFY+OXf1MNW021viDBpR10mX4WQ6zrsGL5L0GY4cwf4tlbh+Obit+LnN/SQTnREf8fPpdKZ1sa/ui3pGi8lMT6io4D7Ujlwx2RdCkBF+isfMf77HCEGsZANw0hSrO2FGg14Sl26xLAIohdaW8O7gEaag8JdVAZ3OVLd5Df1NkZBEr753Xb8WwaXsJjE7qxwINL1KdqA4+EiYW4edb7+a9bbBeOPtb67ZxmFqgyTNS/4obxahezNkjk00ytswsENg//Ee6dWBJZyLH+QGsaU2jO/W4WvRyZhmKKPdipOhiz4Rlrd2XYgsfHsfWf5v4GOTL+13ZB24dW1/m39n2woJ+v686fXbNW85XP/r"); byte[] proof = Base64.getDecoder().decode("lvQLU/KqgFhsLkt/5C/scqs7nWR+eYtyPdWiLVBux9GblT4AhHYMdCgwQfSJcudvsgV6fXoK+DUSRgJ++Nqt+Wvb7GlYlHpxCysQhz26TTu8Nyo7zpmVPH92+UYmbvbQCSvX2BhWtvkfHmqDVjmSIQ4RUMfeveA1KZbSf999NE4qKK8Do+8oXcmTM4LZVmh1rlyqznIdFXPN7x3pD4E0gb6/y69xtWMChv9654FMg05bAdueKt9uA4BEcAbpkdHF"); byte[] inputs = Base64.getDecoder().decode("LcMT3OOlkHLzJBKCKjjzzVMg+r+FVgd52LlhZPB4RFg="); @@ -20,8 +18,6 @@ public void test() { assertTrue("Result should be true", Groth16.verify(vk, proof, inputs)); assertFalse("Result should be false", Groth16.verify(vk, proof, inputs2)); - assertFalse("Result should be false", Groth16.verify(vk, proof, inputs3)); - + assertFalse("Result should be false", Groth16.verify(vk, proof, inputs3)); } - } \ No newline at end of file diff --git a/zwaves_jni/javalib/src/test/java/com/wavesplatform/zwaves/bn256/Groth16Test.java b/zwaves_jni/javalib/src/test/java/com/wavesplatform/zwaves/bn256/Groth16Test.java new file mode 100644 index 0000000..3b84709 --- /dev/null +++ b/zwaves_jni/javalib/src/test/java/com/wavesplatform/zwaves/bn256/Groth16Test.java @@ -0,0 +1,23 @@ +package com.wavesplatform.zwaves.bn256; + +import org.junit.Test; + +import java.util.Base64; + +import static org.junit.Assert.*; + +public class Groth16Test { + @Test + public void test() { + byte[] vk = Base64.getDecoder().decode("LDCJzjgi5HtcHEXHfU8TZz+ZUHD2ZwsQ7JIEvzdMPYKYs9SoGkKUmg1yya4TE0Ms7x+KOJ4Ze/CPfKp2s5jbniFNM71N/YlHVbNkytLtQi1DzReSh9SNBsvskdY5mavQJe+67PuPVEYnx+lJ97qIG8243njZbGWPqUJ2Vqj49NAunhqX+eIkK3zAB3IPWls3gruzX2t9wrmyE9cVVvf1kgWx63PsQV37qdH0KcFRpCH89k4TPS6fLmqdFxX3YGHCGFTpr6tLogvjbUFJPT98kJ/xck0C0B/s8PTVKdao4VQHT4DBIO8+GB3CQVh6VV4EcMLtDWWNxF4yloAlKcFT0Q4AzJSimpFqd/SwSz9Pb7uk5srte3nwphVamC+fHlJt"); + byte[] proof = Base64.getDecoder().decode("GQPBoHuCPcIosF+WZKE5jZV13Ib4EdjLnABncpSHcMKBZl0LhllnPxcuzExIQwhxcfXvFFAjlnDGpKauQ9OQsjBKUBsdBZnGiV2Sg4TSdyHuLo2AbRRqJN0IV3iH3On8I4ngnL30ZAxVyGQH2EK58aUZGxMbbXGR9pQdh99QaiE="); + byte[] inputs = Base64.getDecoder().decode("IfZhAypdtgvecKDWzVyRuvXatmFf2ZYcMWVkCJ0/MQo="); + + byte[] inputs2 = Base64.getDecoder().decode("cmzVCcRVnckw3QUPhmG4Bkppeg4K50oDQwQ9EH+Fq1s="); + byte[] inputs3 = {}; + + assertTrue("Result should be true", Groth16.verify(vk, proof, inputs)); + assertFalse("Result should be false", Groth16.verify(vk, proof, inputs2)); + assertFalse("Result should be false", Groth16.verify(vk, proof, inputs3)); + } +} \ No newline at end of file From 1662eaf5f16d63e24f5741f5408dc4a01cd53936 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 11:36:28 +0400 Subject: [PATCH 08/38] - Build for more platforms; - Better directory structure. --- .github/workflows/release.yml | 63 ++++++++++++------- .../{linux32 => linux/aarch64}/.gitkeep | 0 .../native/{linux64 => linux/amd64}/.gitkeep | 0 .../META-INF/native/linux/x86/.gitkeep | 1 + .../native/{osx64 => osx}/aarch64/.gitkeep | 0 .../META-INF/native/osx/{ => amd64}/.gitkeep | 0 .../META-INF/native/windows/amd64/.gitkeep | 1 + .../META-INF/native/windows/x86/.gitkeep | 1 + .../META-INF/native/windows32/.gitkeep | 1 - .../META-INF/native/windows64/.gitkeep | 1 - 10 files changed, 43 insertions(+), 25 deletions(-) rename zwaves_jni/javalib/src/main/resources/META-INF/native/{linux32 => linux/aarch64}/.gitkeep (100%) rename zwaves_jni/javalib/src/main/resources/META-INF/native/{linux64 => linux/amd64}/.gitkeep (100%) create mode 100644 zwaves_jni/javalib/src/main/resources/META-INF/native/linux/x86/.gitkeep rename zwaves_jni/javalib/src/main/resources/META-INF/native/{osx64 => osx}/aarch64/.gitkeep (100%) rename zwaves_jni/javalib/src/main/resources/META-INF/native/osx/{ => amd64}/.gitkeep (100%) create mode 100644 zwaves_jni/javalib/src/main/resources/META-INF/native/windows/amd64/.gitkeep create mode 100644 zwaves_jni/javalib/src/main/resources/META-INF/native/windows/x86/.gitkeep delete mode 100644 zwaves_jni/javalib/src/main/resources/META-INF/native/windows32/.gitkeep delete mode 100644 zwaves_jni/javalib/src/main/resources/META-INF/native/windows64/.gitkeep diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 79a1a25..ceb2caa 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,35 +10,52 @@ jobs: name: ${{ matrix.target }} library runs-on: ${{ matrix.os }} env: - target-path: ${{ matrix.platform }}-${{ matrix.arch }} + build-arch: ${{ matrix.arch }} + build-platform: ${{ matrix.platform }} + build-target: ${{ matrix.build-arch }}-${{ matrix.build-platform }} + + target-path: ${{ matrix.platform }}/${{ matrix.arch }} # rust flags TARGET_DIR: ./target # Emit backtraces on panics. RUST_BACKTRACE: 1 strategy: matrix: - platform: [ darwin ] - arch: [ x86-64, aarch64 ] - # exclude: - # - platform: linux - # arch: x86-64 - # - platform: win32 - # arch: aarch64 + platform: [ linux, osx, windows ] + arch: [ aarch64, amd64, x86 ] + exclude: + - platform: osx + arch: x86 + - platform: windows + arch: aarch64 + include: - - platform: darwin + - platform: linux + os: ubuntu-latest + build-platform: unknown-linux-gnu + artifact: libzwaves_jni.so + + - platform: osx os: macos-latest + build-platform: apple-darwin artifact: libzwaves_jni.dylib - - platform: darwin - arch: aarch64 - target: aarch64-apple-darwin - dest: osx64/aarch64 + - platform: windows + os: windows-latest + build-platform: pc-windows-gnu + artifact: libzwaves_jni.dll + + - arch: amd64 + build-arch: x86_64 - - platform: darwin - arch: x86-64 - target: x86_64-apple-darwin - dest: osx + - arch: x86 + build-arch: i686 steps: + - name: Debug + run: | + echo "Build target: ${{ matrix.build-target }}" + echo "Target path: ${{ matrix.target-path }}" + - name: Checkout sources uses: actions/checkout@v4 @@ -46,24 +63,24 @@ jobs: uses: dtolnay/rust-toolchain@stable with: toolchain: stable - target: ${{ matrix.target }} + target: ${{ matrix.build-target }} - - name: Enable rust dependencies caching + - name: Enable Rust dependencies caching uses: Swatinem/rust-cache@v2 - - name: Run rust tests + - name: Run Rust tests if: matrix.arch != 'aarch64' # Architecture is x86-64 always: https://stackoverflow.com/a/71220337 run: | cd zwaves_jni - cargo test --lib --target ${{ matrix.target }} + cargo test --lib --target ${{ matrix.build-target }} - name: Build native libraries run: | cd zwaves_jni - cargo build --release --target ${{ matrix.target }} + cargo build --release --target ${{ matrix.build-target }} cd .. - cp target/${{ matrix.target }}/release/${{ matrix.artifact }} ${{ env.NATIVE_DIR }}/${{ matrix.dest }} + cp target/${{ matrix.build-target }}/release/${{ matrix.artifact }} ${{ env.NATIVE_DIR }}/${{ matrix.target-path }} - name: Upload result uses: actions/upload-artifact@v3 diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/linux32/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/linux/aarch64/.gitkeep similarity index 100% rename from zwaves_jni/javalib/src/main/resources/META-INF/native/linux32/.gitkeep rename to zwaves_jni/javalib/src/main/resources/META-INF/native/linux/aarch64/.gitkeep diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/linux64/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/linux/amd64/.gitkeep similarity index 100% rename from zwaves_jni/javalib/src/main/resources/META-INF/native/linux64/.gitkeep rename to zwaves_jni/javalib/src/main/resources/META-INF/native/linux/amd64/.gitkeep diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/linux/x86/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/linux/x86/.gitkeep new file mode 100644 index 0000000..859d1c9 --- /dev/null +++ b/zwaves_jni/javalib/src/main/resources/META-INF/native/linux/x86/.gitkeep @@ -0,0 +1 @@ +place here libzwaves_jni.so file \ No newline at end of file diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/osx64/aarch64/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/osx/aarch64/.gitkeep similarity index 100% rename from zwaves_jni/javalib/src/main/resources/META-INF/native/osx64/aarch64/.gitkeep rename to zwaves_jni/javalib/src/main/resources/META-INF/native/osx/aarch64/.gitkeep diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/osx/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/osx/amd64/.gitkeep similarity index 100% rename from zwaves_jni/javalib/src/main/resources/META-INF/native/osx/.gitkeep rename to zwaves_jni/javalib/src/main/resources/META-INF/native/osx/amd64/.gitkeep diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/windows/amd64/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/windows/amd64/.gitkeep new file mode 100644 index 0000000..9577c3a --- /dev/null +++ b/zwaves_jni/javalib/src/main/resources/META-INF/native/windows/amd64/.gitkeep @@ -0,0 +1 @@ +place here libzwaves_jni.dll file diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/windows/x86/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/windows/x86/.gitkeep new file mode 100644 index 0000000..9577c3a --- /dev/null +++ b/zwaves_jni/javalib/src/main/resources/META-INF/native/windows/x86/.gitkeep @@ -0,0 +1 @@ +place here libzwaves_jni.dll file diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/windows32/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/windows32/.gitkeep deleted file mode 100644 index 795def8..0000000 --- a/zwaves_jni/javalib/src/main/resources/META-INF/native/windows32/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -place here libzwaves_jni.dll file \ No newline at end of file diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/windows64/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/windows64/.gitkeep deleted file mode 100644 index 795def8..0000000 --- a/zwaves_jni/javalib/src/main/resources/META-INF/native/windows64/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -place here libzwaves_jni.dll file \ No newline at end of file From 9bdcb8f149bd66894a370e426f3cdaadb25959f6 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 11:39:38 +0400 Subject: [PATCH 09/38] Build fix --- .github/workflows/release.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ceb2caa..247d76d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,7 +7,7 @@ env: jobs: build-native: - name: ${{ matrix.target }} library + name: ${{ matrix.build-target }} library runs-on: ${{ matrix.os }} env: build-arch: ${{ matrix.arch }} @@ -72,15 +72,15 @@ jobs: if: matrix.arch != 'aarch64' # Architecture is x86-64 always: https://stackoverflow.com/a/71220337 run: | cd zwaves_jni - cargo test --lib --target ${{ matrix.build-target }} + cargo test --lib --target ${{ env.build-target }} - name: Build native libraries run: | cd zwaves_jni - cargo build --release --target ${{ matrix.build-target }} + cargo build --release --target ${{ env.build-target }} cd .. - cp target/${{ matrix.build-target }}/release/${{ matrix.artifact }} ${{ env.NATIVE_DIR }}/${{ matrix.target-path }} + cp target/${{ env.build-target }}/release/${{ matrix.artifact }} ${{ env.NATIVE_DIR }}/${{ env.target-path }} - name: Upload result uses: actions/upload-artifact@v3 From 8b635ee73d2738506a02059ed631ea81c1971c1c Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 11:41:07 +0400 Subject: [PATCH 10/38] Build fix (2) --- .github/workflows/release.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 247d76d..c6ff685 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -53,8 +53,8 @@ jobs: steps: - name: Debug run: | - echo "Build target: ${{ matrix.build-target }}" - echo "Target path: ${{ matrix.target-path }}" + echo "Build target: ${{ env.build-target }}" + echo "Target path: ${{ env.target-path }}" - name: Checkout sources uses: actions/checkout@v4 @@ -63,7 +63,7 @@ jobs: uses: dtolnay/rust-toolchain@stable with: toolchain: stable - target: ${{ matrix.build-target }} + target: ${{ env.build-target }} - name: Enable Rust dependencies caching uses: Swatinem/rust-cache@v2 From 3ab7d137ea1a6a9a7d0ab4c301866fb22c425886 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 11:43:19 +0400 Subject: [PATCH 11/38] Build fix (3) --- .github/workflows/release.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c6ff685..a470f89 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,16 +7,20 @@ env: jobs: build-native: - name: ${{ matrix.build-target }} library + name: ${{ env.build-target }} library runs-on: ${{ matrix.os }} env: + # Where a library should be + target-path: ${{ matrix.platform }}/${{ matrix.arch }} + + # Rust build target build-arch: ${{ matrix.arch }} build-platform: ${{ matrix.platform }} - build-target: ${{ matrix.build-arch }}-${{ matrix.build-platform }} + build-target: ${{ env.build-arch }}-${{ env.build-platform }} - target-path: ${{ matrix.platform }}/${{ matrix.arch }} - # rust flags + # Rust target directory TARGET_DIR: ./target + # Emit backtraces on panics. RUST_BACKTRACE: 1 strategy: From a33ba907b93ffb5cb1e46977a57dc2227f1214a5 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 11:43:43 +0400 Subject: [PATCH 12/38] Build fix (4) --- .github/workflows/release.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a470f89..95f673b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,7 +7,6 @@ env: jobs: build-native: - name: ${{ env.build-target }} library runs-on: ${{ matrix.os }} env: # Where a library should be From 6492664d27a3f5613766d15921c14436ec174652 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 11:49:53 +0400 Subject: [PATCH 13/38] Build fix (5) --- .github/workflows/release.yml | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 95f673b..9d0ce67 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,16 +7,9 @@ env: jobs: build-native: + name: ${{ matrix.build-target }} library runs-on: ${{ matrix.os }} env: - # Where a library should be - target-path: ${{ matrix.platform }}/${{ matrix.arch }} - - # Rust build target - build-arch: ${{ matrix.arch }} - build-platform: ${{ matrix.platform }} - build-target: ${{ env.build-arch }}-${{ env.build-platform }} - # Rust target directory TARGET_DIR: ./target @@ -33,6 +26,12 @@ jobs: arch: aarch64 include: + - target-path: ${{ matrix.platform }}/${{ matrix.arch }} # Where a library should be + # Rust build target + build-arch: ${{ matrix.arch }} + build-platform: ${{ matrix.platform }} + build-target: ${{ matrix.build-arch }}-${{ matrix.build-platform }} + - platform: linux os: ubuntu-latest build-platform: unknown-linux-gnu @@ -56,8 +55,8 @@ jobs: steps: - name: Debug run: | - echo "Build target: ${{ env.build-target }}" - echo "Target path: ${{ env.target-path }}" + echo "Build target: ${{ matrix.build-target }}" + echo "Target path: ${{ matrix.target-path }}" - name: Checkout sources uses: actions/checkout@v4 @@ -66,7 +65,7 @@ jobs: uses: dtolnay/rust-toolchain@stable with: toolchain: stable - target: ${{ env.build-target }} + target: ${{ matrix.build-target }} - name: Enable Rust dependencies caching uses: Swatinem/rust-cache@v2 @@ -75,15 +74,15 @@ jobs: if: matrix.arch != 'aarch64' # Architecture is x86-64 always: https://stackoverflow.com/a/71220337 run: | cd zwaves_jni - cargo test --lib --target ${{ env.build-target }} + cargo test --lib --target ${{ matrix.build-target }} - name: Build native libraries run: | cd zwaves_jni - cargo build --release --target ${{ env.build-target }} + cargo build --release --target ${{ matrix.build-target }} cd .. - cp target/${{ env.build-target }}/release/${{ matrix.artifact }} ${{ env.NATIVE_DIR }}/${{ env.target-path }} + cp target/${{ matrix.build-target }}/release/${{ matrix.artifact }} ${{ env.NATIVE_DIR }}/${{ matrix.target-path }} - name: Upload result uses: actions/upload-artifact@v3 From c749dda8f3edf9234f732aa4fd5c48b65f2384f1 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 12:02:39 +0400 Subject: [PATCH 14/38] Build fix (6) --- .github/workflows/release.yml | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9d0ce67..32cf18d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,9 +7,15 @@ env: jobs: build-native: - name: ${{ matrix.build-target }} library + name: ${{ matrix.arch }}/${{ matrix.platform }} library runs-on: ${{ matrix.os }} env: + # Where a library should be + target-path: ${{ matrix.platform }}/${{ matrix.arch }} + + # Rust build target + build-target: ${{ matrix.build-arch }}-${{ matrix.build-platform }} + # Rust target directory TARGET_DIR: ./target @@ -26,12 +32,6 @@ jobs: arch: aarch64 include: - - target-path: ${{ matrix.platform }}/${{ matrix.arch }} # Where a library should be - # Rust build target - build-arch: ${{ matrix.arch }} - build-platform: ${{ matrix.platform }} - build-target: ${{ matrix.build-arch }}-${{ matrix.build-platform }} - - platform: linux os: ubuntu-latest build-platform: unknown-linux-gnu @@ -47,6 +47,9 @@ jobs: build-platform: pc-windows-gnu artifact: libzwaves_jni.dll + - arch: aarch64 + build-arch: aarch64 + - arch: amd64 build-arch: x86_64 @@ -55,8 +58,8 @@ jobs: steps: - name: Debug run: | - echo "Build target: ${{ matrix.build-target }}" - echo "Target path: ${{ matrix.target-path }}" + echo "Build target: ${{ env.build-target }}" + echo "Target path: ${{ env.target-path }}" - name: Checkout sources uses: actions/checkout@v4 @@ -65,7 +68,7 @@ jobs: uses: dtolnay/rust-toolchain@stable with: toolchain: stable - target: ${{ matrix.build-target }} + target: ${{ env.build-target }} - name: Enable Rust dependencies caching uses: Swatinem/rust-cache@v2 @@ -74,15 +77,15 @@ jobs: if: matrix.arch != 'aarch64' # Architecture is x86-64 always: https://stackoverflow.com/a/71220337 run: | cd zwaves_jni - cargo test --lib --target ${{ matrix.build-target }} + cargo test --lib --target ${{ env.build-target }} - name: Build native libraries run: | cd zwaves_jni - cargo build --release --target ${{ matrix.build-target }} + cargo build --release --target ${{ env.build-target }} cd .. - cp target/${{ matrix.build-target }}/release/${{ matrix.artifact }} ${{ env.NATIVE_DIR }}/${{ matrix.target-path }} + cp target/${{ env.build-target }}/release/${{ matrix.artifact }} ${{ env.NATIVE_DIR }}/${{ env.target-path }} - name: Upload result uses: actions/upload-artifact@v3 From a8a422db5fe4a84632598cf102d53a93d3e34abe Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 12:05:11 +0400 Subject: [PATCH 15/38] Build fix (7) --- .github/workflows/release.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 32cf18d..cbae10c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -74,7 +74,8 @@ jobs: uses: Swatinem/rust-cache@v2 - name: Run Rust tests - if: matrix.arch != 'aarch64' # Architecture is x86-64 always: https://stackoverflow.com/a/71220337 + # Architecture is x86-64 always: https://stackoverflow.com/a/71220337 + if: !(matrix.arch == 'aarch64' || matrix.arch == 'x86') run: | cd zwaves_jni cargo test --lib --target ${{ env.build-target }} From 28f88f0664e6800a14c5ea9d9479e9d8a7bb94b7 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 12:06:24 +0400 Subject: [PATCH 16/38] Build fix (8) --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cbae10c..68f5140 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -75,7 +75,7 @@ jobs: - name: Run Rust tests # Architecture is x86-64 always: https://stackoverflow.com/a/71220337 - if: !(matrix.arch == 'aarch64' || matrix.arch == 'x86') + if: matrix.arch != 'aarch64' && matrix.arch != 'x86' run: | cd zwaves_jni cargo test --lib --target ${{ env.build-target }} From 372d89785efb95f8ec2af1f10c5759ad84005ce0 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 12:20:03 +0400 Subject: [PATCH 17/38] Build fix (9) --- .cargo/config.toml | 10 ++++++++++ .github/workflows/release.yml | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..5d4bb7e --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,10 @@ +[target.aarch64-unknown-linux-gnu] +linker = "aarch64-linux-gnu-gcc" + +[target.x86_64-pc-windows-gnu] +linker = "x86_64-w64-mingw32-gcc" +ar = "x86_64-w64-mingw32-gcc-ar" + +[target.i686-pc-windows-gnu] +linker = "i686-w64-mingw32-gcc" +ar = "i686-w64-mingw32-gcc-ar" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 68f5140..c46093f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,7 +7,7 @@ env: jobs: build-native: - name: ${{ matrix.arch }}/${{ matrix.platform }} library + name: ${{ matrix.platform }}/${{ matrix.arch }} library runs-on: ${{ matrix.os }} env: # Where a library should be From 191bae4e096d67c5bcf1e60e3e332f346f23a22b Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 12:22:14 +0400 Subject: [PATCH 18/38] Build fix (10) --- .github/workflows/release.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c46093f..d211bac 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,6 +30,9 @@ jobs: arch: x86 - platform: windows arch: aarch64 + # osxcross is required + - platform: linux + arch: aarch64 include: - platform: linux From 5441e174aee5b50a306bcb9669cd31026e2d3159 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 12:28:49 +0400 Subject: [PATCH 19/38] Build fix (11): extra packages --- .github/workflows/release.yml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d211bac..37cf7e1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -31,15 +31,23 @@ jobs: - platform: windows arch: aarch64 # osxcross is required - - platform: linux - arch: aarch64 + # - platform: linux + # arch: aarch64 include: - platform: linux - os: ubuntu-latest + os: ubuntu-20.04 build-platform: unknown-linux-gnu artifact: libzwaves_jni.so + - platform: linux + arch: aarch64 + extra-packages: gcc-9-aarch64-linux-gnu gcc-aarch64-linux-gnu + + - platform: linux + arch: x86 + extra-packages: gcc-9-multilib-i686-linux-gnu gcc-multilib-i686-linux-gnu + - platform: osx os: macos-latest build-platform: apple-darwin @@ -67,6 +75,12 @@ jobs: - name: Checkout sources uses: actions/checkout@v4 + - name: Install build tools + if: ${{ matrix.extra-packages }} + run: | + sudo apt-get update + sudo apt-get install -y ${{ matrix.extra-packages }} + - name: Install stable toolchain uses: dtolnay/rust-toolchain@stable with: From 549b87c006755df8080abd51b832918ae2f83595 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 12:58:20 +0400 Subject: [PATCH 20/38] Build fix (12): extra packages --- .github/workflows/release.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 37cf7e1..0a53c1f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -46,7 +46,8 @@ jobs: - platform: linux arch: x86 - extra-packages: gcc-9-multilib-i686-linux-gnu gcc-multilib-i686-linux-gnu + # extra-packages: gcc-9-multilib-i686-linux-gnu gcc-multilib-i686-linux-gnu + extra-packages: gcc-multilib - platform: osx os: macos-latest From fc70ccd56738d062f0cbbc522b86c9ce98638ef2 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 13:06:11 +0400 Subject: [PATCH 21/38] Build fix (13): windows build --- .cargo/config.toml | 14 ++++----- .github/workflows/release.yml | 54 +++++++++++++++++------------------ 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 5d4bb7e..43afdf0 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,10 +1,10 @@ [target.aarch64-unknown-linux-gnu] linker = "aarch64-linux-gnu-gcc" -[target.x86_64-pc-windows-gnu] -linker = "x86_64-w64-mingw32-gcc" -ar = "x86_64-w64-mingw32-gcc-ar" - -[target.i686-pc-windows-gnu] -linker = "i686-w64-mingw32-gcc" -ar = "i686-w64-mingw32-gcc-ar" +#[target.x86_64-pc-windows-gnu] +#linker = "x86_64-w64-mingw32-gcc" +#ar = "x86_64-w64-mingw32-gcc-ar" +# +#[target.i686-pc-windows-gnu] +#linker = "i686-w64-mingw32-gcc" +#ar = "i686-w64-mingw32-gcc-ar" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0a53c1f..b27eeb9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,44 +23,42 @@ jobs: RUST_BACKTRACE: 1 strategy: matrix: - platform: [ linux, osx, windows ] + platform: [ windows ] + # platform: [ linux, osx, windows ] arch: [ aarch64, amd64, x86 ] exclude: - - platform: osx - arch: x86 +# - platform: osx +# arch: x86 - platform: windows arch: aarch64 - # osxcross is required - # - platform: linux - # arch: aarch64 include: - - platform: linux - os: ubuntu-20.04 - build-platform: unknown-linux-gnu - artifact: libzwaves_jni.so - - - platform: linux - arch: aarch64 - extra-packages: gcc-9-aarch64-linux-gnu gcc-aarch64-linux-gnu - - - platform: linux - arch: x86 - # extra-packages: gcc-9-multilib-i686-linux-gnu gcc-multilib-i686-linux-gnu - extra-packages: gcc-multilib - - - platform: osx - os: macos-latest - build-platform: apple-darwin - artifact: libzwaves_jni.dylib +# - platform: linux +# os: ubuntu-20.04 +# build-platform: unknown-linux-gnu +# artifact: libzwaves_jni.so +# +# - platform: linux +# arch: aarch64 +# extra-packages: gcc-9-aarch64-linux-gnu gcc-aarch64-linux-gnu # TODO do we need gcc-9? +# +# - platform: linux +# arch: x86 +# extra-packages: gcc-multilib +# +# - platform: osx +# os: macos-latest +# build-platform: apple-darwin +# artifact: libzwaves_jni.dylib - platform: windows - os: windows-latest + os: ubuntu-20.04 + extra-packages: mingw-w64 build-platform: pc-windows-gnu artifact: libzwaves_jni.dll - - arch: aarch64 - build-arch: aarch64 +# - arch: aarch64 +# build-arch: aarch64 - arch: amd64 build-arch: x86_64 @@ -93,7 +91,7 @@ jobs: - name: Run Rust tests # Architecture is x86-64 always: https://stackoverflow.com/a/71220337 - if: matrix.arch != 'aarch64' && matrix.arch != 'x86' + if: matrix.arch == 'amd64' run: | cd zwaves_jni cargo test --lib --target ${{ env.build-target }} From ad2d769740a715ebfd05bccf2e8745f207f123b0 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 13:42:00 +0400 Subject: [PATCH 22/38] Build fix (14): windows build --- .cargo/config.toml | 12 +++++------- .github/workflows/release.yml | 3 ++- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 43afdf0..d129bd4 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,10 +1,8 @@ [target.aarch64-unknown-linux-gnu] linker = "aarch64-linux-gnu-gcc" -#[target.x86_64-pc-windows-gnu] -#linker = "x86_64-w64-mingw32-gcc" -#ar = "x86_64-w64-mingw32-gcc-ar" -# -#[target.i686-pc-windows-gnu] -#linker = "i686-w64-mingw32-gcc" -#ar = "i686-w64-mingw32-gcc-ar" +[target.i686-pc-windows-gnu] +rustflags = ["-C", "link-arg=-fuse-ld=lld"] + +[target.x86_64-pc-windows-gnu] +rustflags = ["-C", "link-arg=-fuse-ld=lld"] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b27eeb9..f86deaf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -91,7 +91,7 @@ jobs: - name: Run Rust tests # Architecture is x86-64 always: https://stackoverflow.com/a/71220337 - if: matrix.arch == 'amd64' + if: matrix.arch == 'amd64' && matrix.platform != 'windows' run: | cd zwaves_jni cargo test --lib --target ${{ env.build-target }} @@ -101,6 +101,7 @@ jobs: cd zwaves_jni cargo build --release --target ${{ env.build-target }} cd .. + find target -type f cp target/${{ env.build-target }}/release/${{ matrix.artifact }} ${{ env.NATIVE_DIR }}/${{ env.target-path }} From faa3d2ba7218e124029045431eeebf78fb10ba98 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 2 Oct 2023 16:21:09 +0400 Subject: [PATCH 23/38] Build fix (15): windows build --- .cargo/config.toml | 8 ++++++-- .github/workflows/release.yml | 14 +++++++------- .../META-INF/native/windows/amd64/.gitkeep | 2 +- .../resources/META-INF/native/windows/x86/.gitkeep | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index d129bd4..f824f8c 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,8 +1,12 @@ [target.aarch64-unknown-linux-gnu] linker = "aarch64-linux-gnu-gcc" -[target.i686-pc-windows-gnu] +[target.x86_64-pc-windows-gnu] +linker = "x86_64-w64-mingw32-gcc" +ar = "x86_64-w64-mingw32-gcc-ar" rustflags = ["-C", "link-arg=-fuse-ld=lld"] -[target.x86_64-pc-windows-gnu] +[target.i686-pc-windows-gnu] +linker = "i686-w64-mingw32-gcc" +ar = "i686-w64-mingw32-gcc-ar" rustflags = ["-C", "link-arg=-fuse-ld=lld"] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f86deaf..50d1fd8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,12 +20,13 @@ jobs: TARGET_DIR: ./target # Emit backtraces on panics. - RUST_BACKTRACE: 1 + # RUST_BACKTRACE: 1 strategy: matrix: platform: [ windows ] + arch: [ x86 ] # platform: [ linux, osx, windows ] - arch: [ aarch64, amd64, x86 ] +# arch: [ aarch64, amd64, x86 ] exclude: # - platform: osx # arch: x86 @@ -55,13 +56,13 @@ jobs: os: ubuntu-20.04 extra-packages: mingw-w64 build-platform: pc-windows-gnu - artifact: libzwaves_jni.dll + artifact: zwaves_jni.dll # - arch: aarch64 # build-arch: aarch64 - - - arch: amd64 - build-arch: x86_64 +# +# - arch: amd64 +# build-arch: x86_64 - arch: x86 build-arch: i686 @@ -101,7 +102,6 @@ jobs: cd zwaves_jni cargo build --release --target ${{ env.build-target }} cd .. - find target -type f cp target/${{ env.build-target }}/release/${{ matrix.artifact }} ${{ env.NATIVE_DIR }}/${{ env.target-path }} diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/windows/amd64/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/windows/amd64/.gitkeep index 9577c3a..12550e1 100644 --- a/zwaves_jni/javalib/src/main/resources/META-INF/native/windows/amd64/.gitkeep +++ b/zwaves_jni/javalib/src/main/resources/META-INF/native/windows/amd64/.gitkeep @@ -1 +1 @@ -place here libzwaves_jni.dll file +place here zwaves_jni.dll file diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/windows/x86/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/windows/x86/.gitkeep index 9577c3a..12550e1 100644 --- a/zwaves_jni/javalib/src/main/resources/META-INF/native/windows/x86/.gitkeep +++ b/zwaves_jni/javalib/src/main/resources/META-INF/native/windows/x86/.gitkeep @@ -1 +1 @@ -place here libzwaves_jni.dll file +place here zwaves_jni.dll file From 12ec4e8de84bdf3a95c35adbe7ef54eeeb740313 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Tue, 3 Oct 2023 11:40:05 +0400 Subject: [PATCH 24/38] Build fix (16): windows build (x86) --- .cargo/config.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index f824f8c..29124b2 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -9,4 +9,6 @@ rustflags = ["-C", "link-arg=-fuse-ld=lld"] [target.i686-pc-windows-gnu] linker = "i686-w64-mingw32-gcc" ar = "i686-w64-mingw32-gcc-ar" -rustflags = ["-C", "link-arg=-fuse-ld=lld"] +# "link-arg=-fuse-ld=lld" to use LLVM linker +# "panic=abort" to disable unwinding during exception handling, because of linker issues on this platform +rustflags = ["-C", "link-arg=-fuse-ld=lld", "-C", "panic=abort"] From 0f901038e771a56df75fccb7707040641330cea2 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Tue, 3 Oct 2023 11:51:04 +0400 Subject: [PATCH 25/38] Build fix (17): windows build (x86), msvc --- .github/workflows/release.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 50d1fd8..5aae24a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -53,9 +53,9 @@ jobs: # artifact: libzwaves_jni.dylib - platform: windows - os: ubuntu-20.04 - extra-packages: mingw-w64 - build-platform: pc-windows-gnu + # os: ubuntu-20.04 + # extra-packages: mingw-w64 + # build-platform: pc-windows-gnu artifact: zwaves_jni.dll # - arch: aarch64 @@ -65,6 +65,8 @@ jobs: # build-arch: x86_64 - arch: x86 + os: windows-2019 + build-platform: pc-windows-msvc build-arch: i686 steps: - name: Debug From 14e414844a643c326eb9922f1b46b95c9c167298 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Tue, 3 Oct 2023 11:58:14 +0400 Subject: [PATCH 26/38] Build fix (18): windows build, msvc --- .cargo/config.toml | 12 ------------ .github/workflows/release.yml | 15 ++++++--------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 29124b2..3c32d25 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,14 +1,2 @@ [target.aarch64-unknown-linux-gnu] linker = "aarch64-linux-gnu-gcc" - -[target.x86_64-pc-windows-gnu] -linker = "x86_64-w64-mingw32-gcc" -ar = "x86_64-w64-mingw32-gcc-ar" -rustflags = ["-C", "link-arg=-fuse-ld=lld"] - -[target.i686-pc-windows-gnu] -linker = "i686-w64-mingw32-gcc" -ar = "i686-w64-mingw32-gcc-ar" -# "link-arg=-fuse-ld=lld" to use LLVM linker -# "panic=abort" to disable unwinding during exception handling, because of linker issues on this platform -rustflags = ["-C", "link-arg=-fuse-ld=lld", "-C", "panic=abort"] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5aae24a..703e83f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: platform: [ windows ] - arch: [ x86 ] + arch: [ amd64, x86 ] # platform: [ linux, osx, windows ] # arch: [ aarch64, amd64, x86 ] exclude: @@ -53,20 +53,17 @@ jobs: # artifact: libzwaves_jni.dylib - platform: windows - # os: ubuntu-20.04 - # extra-packages: mingw-w64 - # build-platform: pc-windows-gnu + os: windows-2019 + build-platform: pc-windows-msvc artifact: zwaves_jni.dll # - arch: aarch64 # build-arch: aarch64 -# -# - arch: amd64 -# build-arch: x86_64 + + - arch: amd64 + build-arch: x86_64 - arch: x86 - os: windows-2019 - build-platform: pc-windows-msvc build-arch: i686 steps: - name: Debug From f954ab35f864c76ee386314674b443eb3a5ec6d4 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Tue, 3 Oct 2023 12:06:51 +0400 Subject: [PATCH 27/38] Build fix (19): all platforms test --- .github/workflows/release.yml | 54 +++++++++++++++++------------------ 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 703e83f..284f46b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,45 +20,43 @@ jobs: TARGET_DIR: ./target # Emit backtraces on panics. - # RUST_BACKTRACE: 1 + RUST_BACKTRACE: 1 strategy: matrix: - platform: [ windows ] - arch: [ amd64, x86 ] - # platform: [ linux, osx, windows ] -# arch: [ aarch64, amd64, x86 ] + platform: [ linux, osx, windows ] + arch: [ aarch64, amd64, x86 ] exclude: -# - platform: osx -# arch: x86 + - platform: osx + arch: x86 - platform: windows arch: aarch64 include: -# - platform: linux -# os: ubuntu-20.04 -# build-platform: unknown-linux-gnu -# artifact: libzwaves_jni.so -# -# - platform: linux -# arch: aarch64 -# extra-packages: gcc-9-aarch64-linux-gnu gcc-aarch64-linux-gnu # TODO do we need gcc-9? -# -# - platform: linux -# arch: x86 -# extra-packages: gcc-multilib -# -# - platform: osx -# os: macos-latest -# build-platform: apple-darwin -# artifact: libzwaves_jni.dylib + - platform: linux + os: ubuntu-20.04 + build-platform: unknown-linux-gnu + artifact: libzwaves_jni.so + + - platform: linux + arch: aarch64 + extra-packages: gcc-aarch64-linux-gnu + + - platform: linux + arch: x86 + extra-packages: gcc-multilib + + - platform: osx + os: macos-latest + build-platform: apple-darwin + artifact: libzwaves_jni.dylib - platform: windows os: windows-2019 - build-platform: pc-windows-msvc + build-platform: pc-windows-msvc # x86 and gcc lead to "undefined reference to _Unwind_Resume" artifact: zwaves_jni.dll -# - arch: aarch64 -# build-arch: aarch64 + - arch: aarch64 + build-arch: aarch64 - arch: amd64 build-arch: x86_64 @@ -91,7 +89,7 @@ jobs: - name: Run Rust tests # Architecture is x86-64 always: https://stackoverflow.com/a/71220337 - if: matrix.arch == 'amd64' && matrix.platform != 'windows' + if: matrix.arch == 'amd64' run: | cd zwaves_jni cargo test --lib --target ${{ env.build-target }} From ea3c71fd4441245a4f11025c28dbadfacf78a71d Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Tue, 3 Oct 2023 12:45:12 +0400 Subject: [PATCH 28/38] Build fix (20): fixed the native libraries directory structure --- .github/workflows/release.yml | 10 +++++++++- .../native/{linux/aarch64 => linux32/x86}/.gitkeep | 0 .../native/{linux/amd64 => linux64/aarch64}/.gitkeep | 0 .../native/{linux/x86 => linux64/amd64}/.gitkeep | 0 .../META-INF/native/{osx => osx64}/aarch64/.gitkeep | 0 .../META-INF/native/{osx => osx64}/amd64/.gitkeep | 0 .../native/{windows/amd64 => windows32/x86}/.gitkeep | 0 .../native/{windows/x86 => windows64/amd64}/.gitkeep | 0 8 files changed, 9 insertions(+), 1 deletion(-) rename zwaves_jni/javalib/src/main/resources/META-INF/native/{linux/aarch64 => linux32/x86}/.gitkeep (100%) rename zwaves_jni/javalib/src/main/resources/META-INF/native/{linux/amd64 => linux64/aarch64}/.gitkeep (100%) rename zwaves_jni/javalib/src/main/resources/META-INF/native/{linux/x86 => linux64/amd64}/.gitkeep (100%) rename zwaves_jni/javalib/src/main/resources/META-INF/native/{osx => osx64}/aarch64/.gitkeep (100%) rename zwaves_jni/javalib/src/main/resources/META-INF/native/{osx => osx64}/amd64/.gitkeep (100%) rename zwaves_jni/javalib/src/main/resources/META-INF/native/{windows/amd64 => windows32/x86}/.gitkeep (100%) rename zwaves_jni/javalib/src/main/resources/META-INF/native/{windows/x86 => windows64/amd64}/.gitkeep (100%) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 284f46b..1b4dc9e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,7 +11,7 @@ jobs: runs-on: ${{ matrix.os }} env: # Where a library should be - target-path: ${{ matrix.platform }}/${{ matrix.arch }} + target-path: ${{ matrix.jni-platform }}/${{ matrix.arch }} # Rust build target build-target: ${{ matrix.build-arch }}-${{ matrix.build-platform }} @@ -36,6 +36,7 @@ jobs: os: ubuntu-20.04 build-platform: unknown-linux-gnu artifact: libzwaves_jni.so + jni-platform: linux64 - platform: linux arch: aarch64 @@ -44,16 +45,23 @@ jobs: - platform: linux arch: x86 extra-packages: gcc-multilib + jni-platform: linux32 - platform: osx os: macos-latest build-platform: apple-darwin artifact: libzwaves_jni.dylib + jni-platform: osx64 - platform: windows os: windows-2019 build-platform: pc-windows-msvc # x86 and gcc lead to "undefined reference to _Unwind_Resume" artifact: zwaves_jni.dll + jni-platform: windows64 + + - platform: windows + arch: x86 + jni-platform: windows32 - arch: aarch64 build-arch: aarch64 diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/linux/aarch64/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/linux32/x86/.gitkeep similarity index 100% rename from zwaves_jni/javalib/src/main/resources/META-INF/native/linux/aarch64/.gitkeep rename to zwaves_jni/javalib/src/main/resources/META-INF/native/linux32/x86/.gitkeep diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/linux/amd64/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/linux64/aarch64/.gitkeep similarity index 100% rename from zwaves_jni/javalib/src/main/resources/META-INF/native/linux/amd64/.gitkeep rename to zwaves_jni/javalib/src/main/resources/META-INF/native/linux64/aarch64/.gitkeep diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/linux/x86/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/linux64/amd64/.gitkeep similarity index 100% rename from zwaves_jni/javalib/src/main/resources/META-INF/native/linux/x86/.gitkeep rename to zwaves_jni/javalib/src/main/resources/META-INF/native/linux64/amd64/.gitkeep diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/osx/aarch64/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/osx64/aarch64/.gitkeep similarity index 100% rename from zwaves_jni/javalib/src/main/resources/META-INF/native/osx/aarch64/.gitkeep rename to zwaves_jni/javalib/src/main/resources/META-INF/native/osx64/aarch64/.gitkeep diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/osx/amd64/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/osx64/amd64/.gitkeep similarity index 100% rename from zwaves_jni/javalib/src/main/resources/META-INF/native/osx/amd64/.gitkeep rename to zwaves_jni/javalib/src/main/resources/META-INF/native/osx64/amd64/.gitkeep diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/windows/amd64/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/windows32/x86/.gitkeep similarity index 100% rename from zwaves_jni/javalib/src/main/resources/META-INF/native/windows/amd64/.gitkeep rename to zwaves_jni/javalib/src/main/resources/META-INF/native/windows32/x86/.gitkeep diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/windows/x86/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/windows64/amd64/.gitkeep similarity index 100% rename from zwaves_jni/javalib/src/main/resources/META-INF/native/windows/x86/.gitkeep rename to zwaves_jni/javalib/src/main/resources/META-INF/native/windows64/amd64/.gitkeep From 20007245cdae399399454756fce46457eb2d818a Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Wed, 11 Oct 2023 12:17:44 +0400 Subject: [PATCH 29/38] Publishing (WIP) --- .github/workflows/release.yml | 302 ++++++++++-------- zwaves_jni/build_all.sh | 9 - zwaves_jni/javalib/build.gradle | 92 ++++-- zwaves_jni/javalib/settings.gradle | 9 - .../com/wavesplatform/zwaves/JNILibrary.java | 2 +- .../zwaves/bls12/Groth16Test.java | 2 +- .../zwaves/bn256/Groth16Test.java | 2 +- 7 files changed, 241 insertions(+), 177 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1b4dc9e..3b2570e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,125 +1,134 @@ name: Publish artifacts to Sonatype Repo -on: [ push ] +on: + push: + branches: + - master + - version-[0-9].[0-9]+.x + tags: + - v[0-9].[0-9]+.[0-9]+ + pull_request: env: NATIVE_DIR: zwaves_jni/javalib/src/main/resources/META-INF/native + GRADLE_EXTRA_ARGS: --console=plain -Ppr=${{ github.event.number }} -PrefName=${{ github.head_ref }} + # GITHUB_CONTEXT: ${{ toJson(github) }} # For debugging purposes jobs: - build-native: - name: ${{ matrix.platform }}/${{ matrix.arch }} library - runs-on: ${{ matrix.os }} - env: - # Where a library should be - target-path: ${{ matrix.jni-platform }}/${{ matrix.arch }} - - # Rust build target - build-target: ${{ matrix.build-arch }}-${{ matrix.build-platform }} - - # Rust target directory - TARGET_DIR: ./target - - # Emit backtraces on panics. - RUST_BACKTRACE: 1 - strategy: - matrix: - platform: [ linux, osx, windows ] - arch: [ aarch64, amd64, x86 ] - exclude: - - platform: osx - arch: x86 - - platform: windows - arch: aarch64 - - include: - - platform: linux - os: ubuntu-20.04 - build-platform: unknown-linux-gnu - artifact: libzwaves_jni.so - jni-platform: linux64 - - - platform: linux - arch: aarch64 - extra-packages: gcc-aarch64-linux-gnu - - - platform: linux - arch: x86 - extra-packages: gcc-multilib - jni-platform: linux32 - - - platform: osx - os: macos-latest - build-platform: apple-darwin - artifact: libzwaves_jni.dylib - jni-platform: osx64 - - - platform: windows - os: windows-2019 - build-platform: pc-windows-msvc # x86 and gcc lead to "undefined reference to _Unwind_Resume" - artifact: zwaves_jni.dll - jni-platform: windows64 - - - platform: windows - arch: x86 - jni-platform: windows32 - - - arch: aarch64 - build-arch: aarch64 - - - arch: amd64 - build-arch: x86_64 - - - arch: x86 - build-arch: i686 - steps: - - name: Debug - run: | - echo "Build target: ${{ env.build-target }}" - echo "Target path: ${{ env.target-path }}" - - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Install build tools - if: ${{ matrix.extra-packages }} - run: | - sudo apt-get update - sudo apt-get install -y ${{ matrix.extra-packages }} - - - name: Install stable toolchain - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - target: ${{ env.build-target }} - - - name: Enable Rust dependencies caching - uses: Swatinem/rust-cache@v2 - - - name: Run Rust tests - # Architecture is x86-64 always: https://stackoverflow.com/a/71220337 - if: matrix.arch == 'amd64' - run: | - cd zwaves_jni - cargo test --lib --target ${{ env.build-target }} - - - name: Build native libraries - run: | - cd zwaves_jni - cargo build --release --target ${{ env.build-target }} - cd .. - - cp target/${{ env.build-target }}/release/${{ matrix.artifact }} ${{ env.NATIVE_DIR }}/${{ env.target-path }} - - - name: Upload result - uses: actions/upload-artifact@v3 - with: - name: native-libraries - path: ${{ env.NATIVE_DIR }}/**/* - +# build-native: +# name: ${{ matrix.platform }}/${{ matrix.arch }} library +# runs-on: ${{ matrix.os }} +# env: +# # Where a library should be +# target-path: ${{ matrix.jni-platform }}/${{ matrix.arch }} +# +# # Rust build target +# build-target: ${{ matrix.build-arch }}-${{ matrix.build-platform }} +# +# # Rust target directory +# TARGET_DIR: ./target +# +# # Emit backtraces on panics. +# RUST_BACKTRACE: 1 +# strategy: +# matrix: +# platform: [ linux, osx, windows ] +# arch: [ aarch64, amd64, x86 ] +# exclude: +# - platform: osx +# arch: x86 +# - platform: windows +# arch: aarch64 +# +# include: +# - platform: linux +# os: ubuntu-20.04 +# build-platform: unknown-linux-gnu +# artifact: libzwaves_jni.so +# jni-platform: linux64 +# +# - platform: linux +# arch: aarch64 +# extra-packages: gcc-aarch64-linux-gnu +# +# - platform: linux +# arch: x86 +# extra-packages: gcc-multilib +# jni-platform: linux32 +# +# - platform: osx +# os: macos-latest +# build-platform: apple-darwin +# artifact: libzwaves_jni.dylib +# jni-platform: osx64 +# +# - platform: windows +# os: windows-2019 +# build-platform: pc-windows-msvc # x86 and gcc lead to "undefined reference to _Unwind_Resume" +# artifact: zwaves_jni.dll +# jni-platform: windows64 +# +# - platform: windows +# arch: x86 +# jni-platform: windows32 +# +# - arch: aarch64 +# build-arch: aarch64 +# +# - arch: amd64 +# build-arch: x86_64 +# +# - arch: x86 +# build-arch: i686 +# steps: +# - name: Checkout sources +# uses: actions/checkout@v4 +# +# - name: Print debug information +# run: | +# echo "Build target: ${{ env.build-target }}" +# echo "Target path: ${{ env.target-path }}" +# +# - name: Install build tools +# if: ${{ matrix.extra-packages }} +# run: | +# sudo apt-get update +# sudo apt-get install -y ${{ matrix.extra-packages }} +# +# - name: Install stable toolchain +# uses: dtolnay/rust-toolchain@stable +# with: +# toolchain: stable +# target: ${{ env.build-target }} +# +# - name: Enable Rust dependencies caching +# uses: Swatinem/rust-cache@v2 +# +# - name: Run Rust tests +# # Architecture is x86-64 always: https://stackoverflow.com/a/71220337 +# if: matrix.arch == 'amd64' +# run: | +# cd zwaves_jni +# cargo test --lib --target ${{ env.build-target }} +# +# - name: Build native libraries +# run: | +# cd zwaves_jni +# cargo build --release --target ${{ env.build-target }} +# cd .. +# +# cp target/${{ env.build-target }}/release/${{ matrix.artifact }} ${{ env.NATIVE_DIR }}/${{ env.target-path }} +# +# - name: Upload result +# uses: actions/upload-artifact@v3 +# with: +# name: native-libraries +# path: ${{ env.NATIVE_DIR }}/**/* +# build-jni: name: Build JNI library - runs-on: ubuntu-latest - needs: build-native + runs-on: ubuntu-20.04 + # needs: build-native steps: - uses: actions/checkout@v3 @@ -129,23 +138,58 @@ jobs: distribution: temurin cache: gradle - - uses: actions/download-artifact@v3 - with: - name: native-libraries - path: ${{ env.NATIVE_DIR }} - - - name: Run tests + - name: Print debug information run: | - cd zwaves_jni/javalib - ./gradlew publishToMavenLocal + cd ./zwaves_jni/javalib + + # About -q: https://github.com/gradle/gradle/issues/5098#issuecomment-1084652709 + VERSION=$(./gradlew -q printVersion $GRADLE_EXTRA_ARGS) + ELIGIBLE_FOR_PUBLISHING=$(./gradlew -q eligibleForPublishing $GRADLE_EXTRA_ARGS) + + # echo "$GITHUB_CONTEXT" # For debugging purposes + + echo "Args: ${GRADLE_EXTRA_ARGS}" + echo "Building ${VERSION}, eligible for publishing: ${ELIGIBLE_FOR_PUBLISHING}" + + # Move to next step + echo "VERSION=${VERSION}" >> $GITHUB_ENV + echo "ELIGIBLE_FOR_PUBLISHING=${ELIGIBLE_FOR_PUBLISHING}" >> $GITHUB_ENV - - name: Publish Snapshot + - name: Checking 1 + if: ${{ env.ELIGIBLE_FOR_PUBLISHING == 'true' }} run: | - cd zwaves_jni/javalib - ./gradlew publishToMavenLocal + echo "Run if true" - - name: Upload result - uses: actions/upload-artifact@v3 - with: - name: javalib - path: ~/.m2/repository/com/wavesplatform + - name: Checking 1 + if: ${{ env.ELIGIBLE_FOR_PUBLISHING == 'false' }} + run: | + echo "Run if false" + +# - uses: actions/download-artifact@v3 +# with: +# name: native-libraries +# path: ${{ env.NATIVE_DIR }} +# +# - name: Run tests +# run: | +# cd zwaves_jni/javalib +# ./gradlew test +# +# - name: Publish Snapshot +# if: ${{ !contains(github.ref, '/tags/') }} +# run: | +# ./gradlew publishToSonatype \ +# -PsonatypeRepo=https://oss.sonatype.org/content/repositories/snapshots \ +# -PsonatypeUsername='${{ secrets.OSSRH_USERNAME }}' \ +# -PsonatypePassword='${{ secrets.OSSRH_PASSWORD }}' \ +# -PgpgKey='${{ secrets.OSSRH_GPG_KEY_ASCII }}' \ +# -PgpgPassphrase='${{ secrets.OSSRH_GPG_PASSPHRASE }}' +# - name: Publish Release +# if: contains(github.ref, '/tags/') +# run: | +# ./gradlew publishToSonatype \ +# -PsonatypeRepo=https://oss.sonatype.org/service/local/staging/deploy/maven2 \ +# -PsonatypeUsername='${{ secrets.OSSRH_USERNAME }}' \ +# -PsonatypePassword='${{ secrets.OSSRH_PASSWORD }}' \ +# -PgpgKey='${{ secrets.OSSRH_GPG_KEY_ASCII }}' \ +# -PgpgPassphrase='${{ secrets.OSSRH_GPG_PASSPHRASE }}' diff --git a/zwaves_jni/build_all.sh b/zwaves_jni/build_all.sh index 93b1393..4bbf7cc 100644 --- a/zwaves_jni/build_all.sh +++ b/zwaves_jni/build_all.sh @@ -1,12 +1,3 @@ -if [ ! -d "osxcross" ]; then - git clone https://github.com/tpoechtrager/osxcross - pushd osxcross - wget -nc https://s3.dockerproject.org/darwin/v2/MacOSX10.10.sdk.tar.xz - mv MacOSX10.10.sdk.tar.xz tarballs/ - UNATTENDED=yes OSX_VERSION_MIN=10.7 ./build.sh - popd -fi - cargo build --target=i686-unknown-linux-gnu --release cp ../target/i686-unknown-linux-gnu/release/libzwaves_jni.so javalib/src/main/resources/META-INF/native/linux32 diff --git a/zwaves_jni/javalib/build.gradle b/zwaves_jni/javalib/build.gradle index 341d62a..1634e2f 100644 --- a/zwaves_jni/javalib/build.gradle +++ b/zwaves_jni/javalib/build.gradle @@ -1,51 +1,89 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * This generated file contains a sample Java Library project to get you started. - * For more details take a look at the Java Libraries chapter in the Gradle - * User Manual available at https://docs.gradle.org/5.4.1/userguide/java_library_plugin.html - */ - plugins { - // Apply the java-library plugin to add support for Java Library - id 'java-library' - id 'maven' - id 'maven-publish' - id 'signing' + id "java-library" + id "maven-publish" + id "signing" + id "io.github.gradle-nexus.publish-plugin" version "1.3.0" } repositories { - // Use jcenter for resolving your dependencies. - // You can declare any Maven/Ivy/file repository here. - jcenter() + mavenCentral() +} + +def pr() { project.findProperty('pr').toString() ?: "" } + +def refName() { project.findProperty('refName').toString() ?: "" } + +ext { + baseVersion = "0.1.7" + + eligibleForPublishing = pr()?.isNumber() || refName() == "v${baseVersion}" + + artifactVersion = { + if (pr()?.isNumber()) "${baseVersion}-${pr()}-SNAPSHOT" + else baseVersion + } } group = "com.wavesplatform" archivesBaseName = "zwaves" -version = "0.2.0-SNAPSHOT" +version = artifactVersion() dependencies { - // Use JUnit test framework testImplementation 'junit:junit:4.12' } +test { + useJUnit() + maxHeapSize = '1G' +} + +tasks.register('printVersion') { + doLast { + println version + } +} + +tasks.register('eligibleForPublishing') { + doLast { + println(eligibleForPublishing) + } +} + publishing { publications { mavenJava(MavenPublication) { from components.java - groupId = project.group - artifactId = 'zwaves' - version = project.version + pom { + name.set("zwaves") + licenses { + license { + name.set("MIT License") + url.set("LICENSE") + } + } + scm { + connection.set("scm:git:git://github.com/wavesplatform/zwaves.git") + developerConnection.set("scm:git:git@github.com:wavesplatform/zwaves.git") + url.set("https://github.com/wavesplatform/zwaves") + } + } } } - repositories { - mavenLocal() - } } -test { - useJUnit() +signing { + useInMemoryPgpKeys(project.findProperty('gpgKey') as String, project.findProperty('gpgPassphrase') as String) + sign(publishing.publications["mavenJava"]) +} - maxHeapSize = '1G' +nexusPublishing { + repositories { + sonatype { + snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots")) + nexusUrl.set(uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")) + username = project.findProperty('sonatypeUsername') + password = project.findProperty('sonatypePassword') + } + } } diff --git a/zwaves_jni/javalib/settings.gradle b/zwaves_jni/javalib/settings.gradle index 059992b..00387bc 100644 --- a/zwaves_jni/javalib/settings.gradle +++ b/zwaves_jni/javalib/settings.gradle @@ -1,10 +1 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * The settings file is used to specify which projects to include in your build. - * - * Detailed information about configuring a multi-project build in Gradle can be found - * in the user manual at https://docs.gradle.org/5.4.1/userguide/multi_project_builds.html - */ - rootProject.name = 'zwaves' diff --git a/zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/JNILibrary.java b/zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/JNILibrary.java index f0cd654..91cf819 100644 --- a/zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/JNILibrary.java +++ b/zwaves_jni/javalib/src/main/java/com/wavesplatform/zwaves/JNILibrary.java @@ -538,4 +538,4 @@ private boolean loadLibrary(ArrayList errors, String lib) { return false; } -} \ No newline at end of file +} diff --git a/zwaves_jni/javalib/src/test/java/com/wavesplatform/zwaves/bls12/Groth16Test.java b/zwaves_jni/javalib/src/test/java/com/wavesplatform/zwaves/bls12/Groth16Test.java index 16e9153..3df4968 100644 --- a/zwaves_jni/javalib/src/test/java/com/wavesplatform/zwaves/bls12/Groth16Test.java +++ b/zwaves_jni/javalib/src/test/java/com/wavesplatform/zwaves/bls12/Groth16Test.java @@ -20,4 +20,4 @@ public void test() { assertFalse("Result should be false", Groth16.verify(vk, proof, inputs2)); assertFalse("Result should be false", Groth16.verify(vk, proof, inputs3)); } -} \ No newline at end of file +} diff --git a/zwaves_jni/javalib/src/test/java/com/wavesplatform/zwaves/bn256/Groth16Test.java b/zwaves_jni/javalib/src/test/java/com/wavesplatform/zwaves/bn256/Groth16Test.java index 3b84709..054e6e3 100644 --- a/zwaves_jni/javalib/src/test/java/com/wavesplatform/zwaves/bn256/Groth16Test.java +++ b/zwaves_jni/javalib/src/test/java/com/wavesplatform/zwaves/bn256/Groth16Test.java @@ -20,4 +20,4 @@ public void test() { assertFalse("Result should be false", Groth16.verify(vk, proof, inputs2)); assertFalse("Result should be false", Groth16.verify(vk, proof, inputs3)); } -} \ No newline at end of file +} From 48079a64265fd1be1e524ccb6f896b19dfe48f05 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Wed, 11 Oct 2023 14:52:36 +0400 Subject: [PATCH 30/38] Publishing (2) --- .github/workflows/release.yml | 218 +++++++++++++++----------------- zwaves_jni/javalib/build.gradle | 2 +- 2 files changed, 101 insertions(+), 119 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3b2570e..fa895bd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,38 +15,40 @@ env: # GITHUB_CONTEXT: ${{ toJson(github) }} # For debugging purposes jobs: -# build-native: -# name: ${{ matrix.platform }}/${{ matrix.arch }} library -# runs-on: ${{ matrix.os }} -# env: -# # Where a library should be -# target-path: ${{ matrix.jni-platform }}/${{ matrix.arch }} -# -# # Rust build target -# build-target: ${{ matrix.build-arch }}-${{ matrix.build-platform }} -# -# # Rust target directory -# TARGET_DIR: ./target -# -# # Emit backtraces on panics. -# RUST_BACKTRACE: 1 -# strategy: -# matrix: + build-native: + name: ${{ matrix.platform }}/${{ matrix.arch }} library + runs-on: ${{ matrix.os }} + env: + # Where a library should be + target-path: ${{ matrix.jni-platform }}/${{ matrix.arch }} + + # Rust build target + build-target: ${{ matrix.build-arch }}-${{ matrix.build-platform }} + + # Rust target directory + TARGET_DIR: ./target + + # Emit backtraces on panics. + RUST_BACKTRACE: 1 + strategy: + matrix: # platform: [ linux, osx, windows ] # arch: [ aarch64, amd64, x86 ] -# exclude: -# - platform: osx -# arch: x86 -# - platform: windows -# arch: aarch64 -# -# include: -# - platform: linux -# os: ubuntu-20.04 -# build-platform: unknown-linux-gnu -# artifact: libzwaves_jni.so -# jni-platform: linux64 -# + platform: [ linux ] + arch: [ amd64 ] + exclude: + - platform: osx + arch: x86 + - platform: windows + arch: aarch64 + + include: + - platform: linux + os: ubuntu-20.04 + build-platform: unknown-linux-gnu + artifact: libzwaves_jni.so + jni-platform: linux64 + # - platform: linux # arch: aarch64 # extra-packages: gcc-aarch64-linux-gnu @@ -74,61 +76,61 @@ jobs: # # - arch: aarch64 # build-arch: aarch64 -# -# - arch: amd64 -# build-arch: x86_64 -# + + - arch: amd64 + build-arch: x86_64 + # - arch: x86 # build-arch: i686 -# steps: -# - name: Checkout sources -# uses: actions/checkout@v4 -# -# - name: Print debug information -# run: | -# echo "Build target: ${{ env.build-target }}" -# echo "Target path: ${{ env.target-path }}" -# -# - name: Install build tools -# if: ${{ matrix.extra-packages }} -# run: | -# sudo apt-get update -# sudo apt-get install -y ${{ matrix.extra-packages }} -# -# - name: Install stable toolchain -# uses: dtolnay/rust-toolchain@stable -# with: -# toolchain: stable -# target: ${{ env.build-target }} -# -# - name: Enable Rust dependencies caching -# uses: Swatinem/rust-cache@v2 -# -# - name: Run Rust tests -# # Architecture is x86-64 always: https://stackoverflow.com/a/71220337 -# if: matrix.arch == 'amd64' -# run: | -# cd zwaves_jni -# cargo test --lib --target ${{ env.build-target }} -# -# - name: Build native libraries -# run: | -# cd zwaves_jni -# cargo build --release --target ${{ env.build-target }} -# cd .. -# -# cp target/${{ env.build-target }}/release/${{ matrix.artifact }} ${{ env.NATIVE_DIR }}/${{ env.target-path }} -# -# - name: Upload result -# uses: actions/upload-artifact@v3 -# with: -# name: native-libraries -# path: ${{ env.NATIVE_DIR }}/**/* -# + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Print debug information + run: | + echo "Build target: ${{ env.build-target }}" + echo "Target path: ${{ env.target-path }}" + + - name: Install build tools + if: ${{ matrix.extra-packages }} + run: | + sudo apt-get update + sudo apt-get install -y ${{ matrix.extra-packages }} + + - name: Install stable toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + target: ${{ env.build-target }} + + - name: Enable Rust dependencies caching + uses: Swatinem/rust-cache@v2 + + - name: Run Rust tests + # Architecture is x86-64 always: https://stackoverflow.com/a/71220337 + if: matrix.arch == 'amd64' + run: | + cd zwaves_jni + cargo test --lib --target ${{ env.build-target }} + + - name: Build native libraries + run: | + cd zwaves_jni + cargo build --release --target ${{ env.build-target }} + cd .. + + cp target/${{ env.build-target }}/release/${{ matrix.artifact }} ${{ env.NATIVE_DIR }}/${{ env.target-path }} + + - name: Upload result + uses: actions/upload-artifact@v3 + with: + name: native-libraries + path: ${{ env.NATIVE_DIR }}/**/* + build-jni: name: Build JNI library runs-on: ubuntu-20.04 - # needs: build-native + needs: build-native steps: - uses: actions/checkout@v3 @@ -138,6 +140,11 @@ jobs: distribution: temurin cache: gradle + - uses: actions/download-artifact@v3 + with: + name: native-libraries + path: ${{ env.NATIVE_DIR }} + - name: Print debug information run: | cd ./zwaves_jni/javalib @@ -148,48 +155,23 @@ jobs: # echo "$GITHUB_CONTEXT" # For debugging purposes - echo "Args: ${GRADLE_EXTRA_ARGS}" + echo "Gradle extra arguments: ${GRADLE_EXTRA_ARGS}" echo "Building ${VERSION}, eligible for publishing: ${ELIGIBLE_FOR_PUBLISHING}" - # Move to next step - echo "VERSION=${VERSION}" >> $GITHUB_ENV + # Make environment variables available in the next step echo "ELIGIBLE_FOR_PUBLISHING=${ELIGIBLE_FOR_PUBLISHING}" >> $GITHUB_ENV - - name: Checking 1 - if: ${{ env.ELIGIBLE_FOR_PUBLISHING == 'true' }} + - name: Run tests run: | - echo "Run if true" + cd zwaves_jni/javalib + ./gradlew ${GRADLE_EXTRA_ARGS} test - - name: Checking 1 - if: ${{ env.ELIGIBLE_FOR_PUBLISHING == 'false' }} + - name: Publish + if: ${{ env.ELIGIBLE_FOR_PUBLISHING == 'true' }} run: | - echo "Run if false" - -# - uses: actions/download-artifact@v3 -# with: -# name: native-libraries -# path: ${{ env.NATIVE_DIR }} -# -# - name: Run tests -# run: | -# cd zwaves_jni/javalib -# ./gradlew test -# -# - name: Publish Snapshot -# if: ${{ !contains(github.ref, '/tags/') }} -# run: | -# ./gradlew publishToSonatype \ -# -PsonatypeRepo=https://oss.sonatype.org/content/repositories/snapshots \ -# -PsonatypeUsername='${{ secrets.OSSRH_USERNAME }}' \ -# -PsonatypePassword='${{ secrets.OSSRH_PASSWORD }}' \ -# -PgpgKey='${{ secrets.OSSRH_GPG_KEY_ASCII }}' \ -# -PgpgPassphrase='${{ secrets.OSSRH_GPG_PASSPHRASE }}' -# - name: Publish Release -# if: contains(github.ref, '/tags/') -# run: | -# ./gradlew publishToSonatype \ -# -PsonatypeRepo=https://oss.sonatype.org/service/local/staging/deploy/maven2 \ -# -PsonatypeUsername='${{ secrets.OSSRH_USERNAME }}' \ -# -PsonatypePassword='${{ secrets.OSSRH_PASSWORD }}' \ -# -PgpgKey='${{ secrets.OSSRH_GPG_KEY_ASCII }}' \ -# -PgpgPassphrase='${{ secrets.OSSRH_GPG_PASSPHRASE }}' + cd zwaves_jni/javalib + ./gradlew publishToSonatype ${GRADLE_EXTRA_ARGS} \ + -PsonatypeUsername='${{ secrets.OSSRH_USERNAME }}' \ + -PsonatypePassword='${{ secrets.OSSRH_PASSWORD }}' \ + -PgpgKey='${{ secrets.OSSRH_GPG_KEY_ASCII }}' \ + -PgpgPassphrase='${{ secrets.OSSRH_GPG_PASSPHRASE }}' diff --git a/zwaves_jni/javalib/build.gradle b/zwaves_jni/javalib/build.gradle index 1634e2f..8b0449b 100644 --- a/zwaves_jni/javalib/build.gradle +++ b/zwaves_jni/javalib/build.gradle @@ -74,7 +74,7 @@ publishing { signing { useInMemoryPgpKeys(project.findProperty('gpgKey') as String, project.findProperty('gpgPassphrase') as String) - sign(publishing.publications["mavenJava"]) + sign(publishing.publications.mavenJava) } nexusPublishing { From 166cd0db5eba7f14af5f0e07a913f4cc48800d57 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Wed, 11 Oct 2023 15:26:52 +0400 Subject: [PATCH 31/38] Publishing (3), snapshot publications work --- .github/workflows/release.yml | 66 ++++++++++++++++----------------- zwaves_jni/javalib/build.gradle | 4 +- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fa895bd..3b25562 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,10 +32,8 @@ jobs: RUST_BACKTRACE: 1 strategy: matrix: -# platform: [ linux, osx, windows ] -# arch: [ aarch64, amd64, x86 ] - platform: [ linux ] - arch: [ amd64 ] + platform: [ linux, osx, windows ] + arch: [ aarch64, amd64, x86 ] exclude: - platform: osx arch: x86 @@ -49,39 +47,39 @@ jobs: artifact: libzwaves_jni.so jni-platform: linux64 -# - platform: linux -# arch: aarch64 -# extra-packages: gcc-aarch64-linux-gnu -# -# - platform: linux -# arch: x86 -# extra-packages: gcc-multilib -# jni-platform: linux32 -# -# - platform: osx -# os: macos-latest -# build-platform: apple-darwin -# artifact: libzwaves_jni.dylib -# jni-platform: osx64 -# -# - platform: windows -# os: windows-2019 -# build-platform: pc-windows-msvc # x86 and gcc lead to "undefined reference to _Unwind_Resume" -# artifact: zwaves_jni.dll -# jni-platform: windows64 -# -# - platform: windows -# arch: x86 -# jni-platform: windows32 -# -# - arch: aarch64 -# build-arch: aarch64 + - platform: linux + arch: aarch64 + extra-packages: gcc-aarch64-linux-gnu + + - platform: linux + arch: x86 + extra-packages: gcc-multilib + jni-platform: linux32 + + - platform: osx + os: macos-latest + build-platform: apple-darwin + artifact: libzwaves_jni.dylib + jni-platform: osx64 + + - platform: windows + os: windows-2019 + build-platform: pc-windows-msvc # x86 and gcc lead to "undefined reference to _Unwind_Resume" + artifact: zwaves_jni.dll + jni-platform: windows64 + + - platform: windows + arch: x86 + jni-platform: windows32 + + - arch: aarch64 + build-arch: aarch64 - arch: amd64 build-arch: x86_64 -# - arch: x86 -# build-arch: i686 + - arch: x86 + build-arch: i686 steps: - name: Checkout sources uses: actions/checkout@v4 @@ -107,7 +105,7 @@ jobs: uses: Swatinem/rust-cache@v2 - name: Run Rust tests - # Architecture is x86-64 always: https://stackoverflow.com/a/71220337 + # Architecture is always x86-64: https://stackoverflow.com/a/71220337 if: matrix.arch == 'amd64' run: | cd zwaves_jni diff --git a/zwaves_jni/javalib/build.gradle b/zwaves_jni/javalib/build.gradle index 8b0449b..1185397 100644 --- a/zwaves_jni/javalib/build.gradle +++ b/zwaves_jni/javalib/build.gradle @@ -14,7 +14,7 @@ def pr() { project.findProperty('pr').toString() ?: "" } def refName() { project.findProperty('refName').toString() ?: "" } ext { - baseVersion = "0.1.7" + baseVersion = "0.2.0" eligibleForPublishing = pr()?.isNumber() || refName() == "v${baseVersion}" @@ -45,7 +45,7 @@ tasks.register('printVersion') { tasks.register('eligibleForPublishing') { doLast { - println(eligibleForPublishing) + println eligibleForPublishing } } From a4099ef254021789d336b2d228f0bfd6b4edc877 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Thu, 12 Oct 2023 10:32:48 +0400 Subject: [PATCH 32/38] Publishing staging version test --- .github/workflows/release.yml | 67 +++++++++++++++++---------------- zwaves_jni/javalib/build.gradle | 2 +- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3b25562..9abb55e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,8 +32,10 @@ jobs: RUST_BACKTRACE: 1 strategy: matrix: - platform: [ linux, osx, windows ] - arch: [ aarch64, amd64, x86 ] +# platform: [ linux, osx, windows ] +# arch: [ aarch64, amd64, x86 ] + platform: [ linux ] + arch: [ amd64 ] exclude: - platform: osx arch: x86 @@ -47,39 +49,39 @@ jobs: artifact: libzwaves_jni.so jni-platform: linux64 - - platform: linux - arch: aarch64 - extra-packages: gcc-aarch64-linux-gnu - - - platform: linux - arch: x86 - extra-packages: gcc-multilib - jni-platform: linux32 - - - platform: osx - os: macos-latest - build-platform: apple-darwin - artifact: libzwaves_jni.dylib - jni-platform: osx64 - - - platform: windows - os: windows-2019 - build-platform: pc-windows-msvc # x86 and gcc lead to "undefined reference to _Unwind_Resume" - artifact: zwaves_jni.dll - jni-platform: windows64 - - - platform: windows - arch: x86 - jni-platform: windows32 - - - arch: aarch64 - build-arch: aarch64 +# - platform: linux +# arch: aarch64 +# extra-packages: gcc-aarch64-linux-gnu +# +# - platform: linux +# arch: x86 +# extra-packages: gcc-multilib +# jni-platform: linux32 +# +# - platform: osx +# os: macos-latest +# build-platform: apple-darwin +# artifact: libzwaves_jni.dylib +# jni-platform: osx64 +# +# - platform: windows +# os: windows-2019 +# build-platform: pc-windows-msvc # x86 and gcc lead to "undefined reference to _Unwind_Resume" +# artifact: zwaves_jni.dll +# jni-platform: windows64 +# +# - platform: windows +# arch: x86 +# jni-platform: windows32 +# +# - arch: aarch64 +# build-arch: aarch64 - arch: amd64 build-arch: x86_64 - - arch: x86 - build-arch: i686 +# - arch: x86 +# build-arch: i686 steps: - name: Checkout sources uses: actions/checkout@v4 @@ -168,7 +170,8 @@ jobs: if: ${{ env.ELIGIBLE_FOR_PUBLISHING == 'true' }} run: | cd zwaves_jni/javalib - ./gradlew publishToSonatype ${GRADLE_EXTRA_ARGS} \ + ./gradlew printVersion -q -PrefName=v0.1.7 + ./gradlew publishToSonatype --info -PrefName=v0.1.7 \ -PsonatypeUsername='${{ secrets.OSSRH_USERNAME }}' \ -PsonatypePassword='${{ secrets.OSSRH_PASSWORD }}' \ -PgpgKey='${{ secrets.OSSRH_GPG_KEY_ASCII }}' \ diff --git a/zwaves_jni/javalib/build.gradle b/zwaves_jni/javalib/build.gradle index 1185397..f798be2 100644 --- a/zwaves_jni/javalib/build.gradle +++ b/zwaves_jni/javalib/build.gradle @@ -14,7 +14,7 @@ def pr() { project.findProperty('pr').toString() ?: "" } def refName() { project.findProperty('refName').toString() ?: "" } ext { - baseVersion = "0.2.0" + baseVersion = "0.1.7" eligibleForPublishing = pr()?.isNumber() || refName() == "v${baseVersion}" From cafe871afa044fb9cad8fa04326ac7f8eb73abf0 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Thu, 12 Oct 2023 11:23:14 +0400 Subject: [PATCH 33/38] Publishing staging version test (2) --- .github/workflows/release.yml | 34 ++++++++++++++++++++++++++------- zwaves_jni/javalib/build.gradle | 8 +++++--- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9abb55e..d53b1ba 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -151,28 +151,48 @@ jobs: # About -q: https://github.com/gradle/gradle/issues/5098#issuecomment-1084652709 VERSION=$(./gradlew -q printVersion $GRADLE_EXTRA_ARGS) - ELIGIBLE_FOR_PUBLISHING=$(./gradlew -q eligibleForPublishing $GRADLE_EXTRA_ARGS) + # PUBLISHING_TYPE=$(./gradlew -q publishingType $GRADLE_EXTRA_ARGS) + PUBLISHING_TYPE=staging # echo "$GITHUB_CONTEXT" # For debugging purposes echo "Gradle extra arguments: ${GRADLE_EXTRA_ARGS}" - echo "Building ${VERSION}, eligible for publishing: ${ELIGIBLE_FOR_PUBLISHING}" + echo "Building ${VERSION}, publishing type: ${PUBLISHING_TYPE}" # Make environment variables available in the next step - echo "ELIGIBLE_FOR_PUBLISHING=${ELIGIBLE_FOR_PUBLISHING}" >> $GITHUB_ENV + echo "PUBLISHING_TYPE=${PUBLISHING_TYPE}" >> $GITHUB_ENV - name: Run tests run: | cd zwaves_jni/javalib ./gradlew ${GRADLE_EXTRA_ARGS} test - - name: Publish - if: ${{ env.ELIGIBLE_FOR_PUBLISHING == 'true' }} + - name: Publish snapshot version + if: ${{ env.PUBLISHING_TYPE == 'snapshot' }} run: | cd zwaves_jni/javalib - ./gradlew printVersion -q -PrefName=v0.1.7 - ./gradlew publishToSonatype --info -PrefName=v0.1.7 \ + ./gradlew publishToSonatype ${GRADLE_EXTRA_ARGS} \ -PsonatypeUsername='${{ secrets.OSSRH_USERNAME }}' \ -PsonatypePassword='${{ secrets.OSSRH_PASSWORD }}' \ -PgpgKey='${{ secrets.OSSRH_GPG_KEY_ASCII }}' \ -PgpgPassphrase='${{ secrets.OSSRH_GPG_PASSPHRASE }}' + + - name: Publish staging version + if: ${{ env.PUBLISHING_TYPE == 'staging' }} + run: | + cd zwaves_jni/javalib + + # TODO: ${GRADLE_EXTRA_ARGS} + + # Debug step + ./gradlew --info retrieveSonatypeStagingProfile -PrefName=v0.1.7 \ + -PsonatypeUsername='${{ secrets.OSSRH_USERNAME }}' \ + -PsonatypePassword='${{ secrets.OSSRH_PASSWORD }}' \ + -PgpgKey='${{ secrets.OSSRH_GPG_KEY_ASCII }}' \ + -PgpgPassphrase='${{ secrets.OSSRH_GPG_PASSPHRASE }}' + +# ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -PrefName=v0.1.7 \ +# -PsonatypeUsername='${{ secrets.OSSRH_USERNAME }}' \ +# -PsonatypePassword='${{ secrets.OSSRH_PASSWORD }}' \ +# -PgpgKey='${{ secrets.OSSRH_GPG_KEY_ASCII }}' \ +# -PgpgPassphrase='${{ secrets.OSSRH_GPG_PASSPHRASE }}' diff --git a/zwaves_jni/javalib/build.gradle b/zwaves_jni/javalib/build.gradle index f798be2..a145c74 100644 --- a/zwaves_jni/javalib/build.gradle +++ b/zwaves_jni/javalib/build.gradle @@ -16,7 +16,9 @@ def refName() { project.findProperty('refName').toString() ?: "" } ext { baseVersion = "0.1.7" - eligibleForPublishing = pr()?.isNumber() || refName() == "v${baseVersion}" + publishingType = { + if (pr()?.isNumber()) "snapshot" else if (refName() == "v${baseVersion}") "staging" else "prohibited" + } artifactVersion = { if (pr()?.isNumber()) "${baseVersion}-${pr()}-SNAPSHOT" @@ -43,9 +45,9 @@ tasks.register('printVersion') { } } -tasks.register('eligibleForPublishing') { +tasks.register('publishingType') { doLast { - println eligibleForPublishing + println publishingType() } } From 4b7d874f775924a52d14bfa90211a731f8c5e2c5 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Thu, 12 Oct 2023 11:38:49 +0400 Subject: [PATCH 34/38] Publishing staging version test (3) --- .github/workflows/release.yml | 8 +------- zwaves_jni/javalib/build.gradle | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d53b1ba..5095e76 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -185,14 +185,8 @@ jobs: # TODO: ${GRADLE_EXTRA_ARGS} # Debug step - ./gradlew --info retrieveSonatypeStagingProfile -PrefName=v0.1.7 \ + ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -PrefName=v0.1.7 \ -PsonatypeUsername='${{ secrets.OSSRH_USERNAME }}' \ -PsonatypePassword='${{ secrets.OSSRH_PASSWORD }}' \ -PgpgKey='${{ secrets.OSSRH_GPG_KEY_ASCII }}' \ -PgpgPassphrase='${{ secrets.OSSRH_GPG_PASSPHRASE }}' - -# ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -PrefName=v0.1.7 \ -# -PsonatypeUsername='${{ secrets.OSSRH_USERNAME }}' \ -# -PsonatypePassword='${{ secrets.OSSRH_PASSWORD }}' \ -# -PgpgKey='${{ secrets.OSSRH_GPG_KEY_ASCII }}' \ -# -PgpgPassphrase='${{ secrets.OSSRH_GPG_PASSPHRASE }}' diff --git a/zwaves_jni/javalib/build.gradle b/zwaves_jni/javalib/build.gradle index a145c74..92c1840 100644 --- a/zwaves_jni/javalib/build.gradle +++ b/zwaves_jni/javalib/build.gradle @@ -83,7 +83,7 @@ nexusPublishing { repositories { sonatype { snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots")) - nexusUrl.set(uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")) + nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) username = project.findProperty('sonatypeUsername') password = project.findProperty('sonatypePassword') } From dfea3dfcd3e020e0779a910c8d162a01ad04bc84 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Thu, 12 Oct 2023 12:29:46 +0400 Subject: [PATCH 35/38] Publishing staging version with io.github.gradle-nexus.publish-plugin (not working) --- .github/workflows/release.yml | 73 +++++++++++++++------------------ zwaves_jni/javalib/build.gradle | 4 +- 2 files changed, 35 insertions(+), 42 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5095e76..bef31db 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,10 +32,8 @@ jobs: RUST_BACKTRACE: 1 strategy: matrix: -# platform: [ linux, osx, windows ] -# arch: [ aarch64, amd64, x86 ] - platform: [ linux ] - arch: [ amd64 ] + platform: [ linux, osx, windows ] + arch: [ aarch64, amd64, x86 ] exclude: - platform: osx arch: x86 @@ -49,39 +47,39 @@ jobs: artifact: libzwaves_jni.so jni-platform: linux64 -# - platform: linux -# arch: aarch64 -# extra-packages: gcc-aarch64-linux-gnu -# -# - platform: linux -# arch: x86 -# extra-packages: gcc-multilib -# jni-platform: linux32 -# -# - platform: osx -# os: macos-latest -# build-platform: apple-darwin -# artifact: libzwaves_jni.dylib -# jni-platform: osx64 -# -# - platform: windows -# os: windows-2019 -# build-platform: pc-windows-msvc # x86 and gcc lead to "undefined reference to _Unwind_Resume" -# artifact: zwaves_jni.dll -# jni-platform: windows64 -# -# - platform: windows -# arch: x86 -# jni-platform: windows32 -# -# - arch: aarch64 -# build-arch: aarch64 + - platform: linux + arch: aarch64 + extra-packages: gcc-aarch64-linux-gnu + + - platform: linux + arch: x86 + extra-packages: gcc-multilib + jni-platform: linux32 + + - platform: osx + os: macos-latest + build-platform: apple-darwin + artifact: libzwaves_jni.dylib + jni-platform: osx64 + + - platform: windows + os: windows-2019 + build-platform: pc-windows-msvc # x86 and gcc lead to "undefined reference to _Unwind_Resume" + artifact: zwaves_jni.dll + jni-platform: windows64 + + - platform: windows + arch: x86 + jni-platform: windows32 + + - arch: aarch64 + build-arch: aarch64 - arch: amd64 build-arch: x86_64 -# - arch: x86 -# build-arch: i686 + - arch: x86 + build-arch: i686 steps: - name: Checkout sources uses: actions/checkout@v4 @@ -151,8 +149,7 @@ jobs: # About -q: https://github.com/gradle/gradle/issues/5098#issuecomment-1084652709 VERSION=$(./gradlew -q printVersion $GRADLE_EXTRA_ARGS) - # PUBLISHING_TYPE=$(./gradlew -q publishingType $GRADLE_EXTRA_ARGS) - PUBLISHING_TYPE=staging + PUBLISHING_TYPE=$(./gradlew -q publishingType $GRADLE_EXTRA_ARGS) # echo "$GITHUB_CONTEXT" # For debugging purposes @@ -181,11 +178,7 @@ jobs: if: ${{ env.PUBLISHING_TYPE == 'staging' }} run: | cd zwaves_jni/javalib - - # TODO: ${GRADLE_EXTRA_ARGS} - - # Debug step - ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -PrefName=v0.1.7 \ + ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository ${GRADLE_EXTRA_ARGS} \ -PsonatypeUsername='${{ secrets.OSSRH_USERNAME }}' \ -PsonatypePassword='${{ secrets.OSSRH_PASSWORD }}' \ -PgpgKey='${{ secrets.OSSRH_GPG_KEY_ASCII }}' \ diff --git a/zwaves_jni/javalib/build.gradle b/zwaves_jni/javalib/build.gradle index 92c1840..9506a3b 100644 --- a/zwaves_jni/javalib/build.gradle +++ b/zwaves_jni/javalib/build.gradle @@ -14,7 +14,7 @@ def pr() { project.findProperty('pr').toString() ?: "" } def refName() { project.findProperty('refName').toString() ?: "" } ext { - baseVersion = "0.1.7" + baseVersion = "0.2.0" publishingType = { if (pr()?.isNumber()) "snapshot" else if (refName() == "v${baseVersion}") "staging" else "prohibited" @@ -83,7 +83,7 @@ nexusPublishing { repositories { sonatype { snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots")) - nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) + nexusUrl.set(uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")) username = project.findProperty('sonatypeUsername') password = project.findProperty('sonatypePassword') } From 2969e872695f6ed61b4875bf6d3de2a1b84b00af Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Thu, 12 Oct 2023 12:44:37 +0400 Subject: [PATCH 36/38] Publishing staging version with io.github.gradle-nexus.publish-plugin (WIP) --- .github/workflows/release.yml | 10 ++++++---- zwaves_jni/javalib/build.gradle | 17 +++++++---------- zwaves_jni/javalib/gradle.properties | 5 +++++ 3 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 zwaves_jni/javalib/gradle.properties diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bef31db..ca40148 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -148,8 +148,9 @@ jobs: cd ./zwaves_jni/javalib # About -q: https://github.com/gradle/gradle/issues/5098#issuecomment-1084652709 - VERSION=$(./gradlew -q printVersion $GRADLE_EXTRA_ARGS) - PUBLISHING_TYPE=$(./gradlew -q publishingType $GRADLE_EXTRA_ARGS) + VERSION=$(./gradlew -q $GRADLE_EXTRA_ARGS printVersion) + # PUBLISHING_TYPE=$(./gradlew -q $GRADLE_EXTRA_ARGS publishingType) + PUBLISHING_TYPE=staging # echo "$GITHUB_CONTEXT" # For debugging purposes @@ -168,7 +169,7 @@ jobs: if: ${{ env.PUBLISHING_TYPE == 'snapshot' }} run: | cd zwaves_jni/javalib - ./gradlew publishToSonatype ${GRADLE_EXTRA_ARGS} \ + ./gradlew ${GRADLE_EXTRA_ARGS} publishToSonatype \ -PsonatypeUsername='${{ secrets.OSSRH_USERNAME }}' \ -PsonatypePassword='${{ secrets.OSSRH_PASSWORD }}' \ -PgpgKey='${{ secrets.OSSRH_GPG_KEY_ASCII }}' \ @@ -178,7 +179,8 @@ jobs: if: ${{ env.PUBLISHING_TYPE == 'staging' }} run: | cd zwaves_jni/javalib - ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository ${GRADLE_EXTRA_ARGS} \ + # ./gradlew ${GRADLE_EXTRA_ARGS} publishToSonatype closeAndReleaseSonatypeStagingRepository \ + ./gradlew -PrefName=v0.1.7 publishToSonatype \ -PsonatypeUsername='${{ secrets.OSSRH_USERNAME }}' \ -PsonatypePassword='${{ secrets.OSSRH_PASSWORD }}' \ -PgpgKey='${{ secrets.OSSRH_GPG_KEY_ASCII }}' \ diff --git a/zwaves_jni/javalib/build.gradle b/zwaves_jni/javalib/build.gradle index 9506a3b..d6d387b 100644 --- a/zwaves_jni/javalib/build.gradle +++ b/zwaves_jni/javalib/build.gradle @@ -14,7 +14,7 @@ def pr() { project.findProperty('pr').toString() ?: "" } def refName() { project.findProperty('refName').toString() ?: "" } ext { - baseVersion = "0.2.0" + baseVersion = "0.1.7" publishingType = { if (pr()?.isNumber()) "snapshot" else if (refName() == "v${baseVersion}") "staging" else "prohibited" @@ -57,7 +57,9 @@ publishing { from components.java pom { - name.set("zwaves") + packaging = 'jar' + url = 'https://github.com/wavesplatform/zwaves' + licenses { license { name.set("MIT License") @@ -75,17 +77,12 @@ publishing { } signing { - useInMemoryPgpKeys(project.findProperty('gpgKey') as String, project.findProperty('gpgPassphrase') as String) - sign(publishing.publications.mavenJava) + useInMemoryPgpKeys(gpgKey, gpgPassphrase) + sign configurations.archives } nexusPublishing { repositories { - sonatype { - snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots")) - nexusUrl.set(uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")) - username = project.findProperty('sonatypeUsername') - password = project.findProperty('sonatypePassword') - } + sonatype() } } diff --git a/zwaves_jni/javalib/gradle.properties b/zwaves_jni/javalib/gradle.properties new file mode 100644 index 0000000..7b72eff --- /dev/null +++ b/zwaves_jni/javalib/gradle.properties @@ -0,0 +1,5 @@ +sonatypeRepo= +sonatypeUsername= +sonatypePassword= +gpgKey= +gpgPassphrase= \ No newline at end of file From e7cd793a905a1d16681dbca92a0b37b16bd083b9 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Thu, 12 Oct 2023 17:42:48 +0400 Subject: [PATCH 37/38] Publishing staging version with io.github.gradle-nexus.publish-plugin --- .github/workflows/release.yml | 6 ++---- zwaves_jni/javalib/build.gradle | 4 +--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ca40148..506fbbc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -149,8 +149,7 @@ jobs: # About -q: https://github.com/gradle/gradle/issues/5098#issuecomment-1084652709 VERSION=$(./gradlew -q $GRADLE_EXTRA_ARGS printVersion) - # PUBLISHING_TYPE=$(./gradlew -q $GRADLE_EXTRA_ARGS publishingType) - PUBLISHING_TYPE=staging + PUBLISHING_TYPE=$(./gradlew -q $GRADLE_EXTRA_ARGS publishingType) # echo "$GITHUB_CONTEXT" # For debugging purposes @@ -179,8 +178,7 @@ jobs: if: ${{ env.PUBLISHING_TYPE == 'staging' }} run: | cd zwaves_jni/javalib - # ./gradlew ${GRADLE_EXTRA_ARGS} publishToSonatype closeAndReleaseSonatypeStagingRepository \ - ./gradlew -PrefName=v0.1.7 publishToSonatype \ + ./gradlew ${GRADLE_EXTRA_ARGS} publishToSonatype closeAndReleaseSonatypeStagingRepository \ -PsonatypeUsername='${{ secrets.OSSRH_USERNAME }}' \ -PsonatypePassword='${{ secrets.OSSRH_PASSWORD }}' \ -PgpgKey='${{ secrets.OSSRH_GPG_KEY_ASCII }}' \ diff --git a/zwaves_jni/javalib/build.gradle b/zwaves_jni/javalib/build.gradle index d6d387b..1a78c88 100644 --- a/zwaves_jni/javalib/build.gradle +++ b/zwaves_jni/javalib/build.gradle @@ -21,8 +21,7 @@ ext { } artifactVersion = { - if (pr()?.isNumber()) "${baseVersion}-${pr()}-SNAPSHOT" - else baseVersion + if (pr()?.isNumber()) "${baseVersion}-${pr()}-SNAPSHOT" else baseVersion } } @@ -59,7 +58,6 @@ publishing { pom { packaging = 'jar' url = 'https://github.com/wavesplatform/zwaves' - licenses { license { name.set("MIT License") From ecc8b0cc49ab45f3f68315f6fa91d8c389446dc2 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Fri, 13 Oct 2023 13:40:52 +0400 Subject: [PATCH 38/38] Added newlines --- zwaves_jni/javalib/gradle.properties | 2 +- .../src/main/resources/META-INF/native/linux32/x86/.gitkeep | 2 +- .../src/main/resources/META-INF/native/linux64/aarch64/.gitkeep | 2 +- .../src/main/resources/META-INF/native/linux64/amd64/.gitkeep | 2 +- .../src/main/resources/META-INF/native/osx64/aarch64/.gitkeep | 2 +- .../src/main/resources/META-INF/native/osx64/amd64/.gitkeep | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/zwaves_jni/javalib/gradle.properties b/zwaves_jni/javalib/gradle.properties index 7b72eff..7ccbfc6 100644 --- a/zwaves_jni/javalib/gradle.properties +++ b/zwaves_jni/javalib/gradle.properties @@ -2,4 +2,4 @@ sonatypeRepo= sonatypeUsername= sonatypePassword= gpgKey= -gpgPassphrase= \ No newline at end of file +gpgPassphrase= diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/linux32/x86/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/linux32/x86/.gitkeep index 859d1c9..f5dabae 100644 --- a/zwaves_jni/javalib/src/main/resources/META-INF/native/linux32/x86/.gitkeep +++ b/zwaves_jni/javalib/src/main/resources/META-INF/native/linux32/x86/.gitkeep @@ -1 +1 @@ -place here libzwaves_jni.so file \ No newline at end of file +place here libzwaves_jni.so file diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/linux64/aarch64/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/linux64/aarch64/.gitkeep index 859d1c9..f5dabae 100644 --- a/zwaves_jni/javalib/src/main/resources/META-INF/native/linux64/aarch64/.gitkeep +++ b/zwaves_jni/javalib/src/main/resources/META-INF/native/linux64/aarch64/.gitkeep @@ -1 +1 @@ -place here libzwaves_jni.so file \ No newline at end of file +place here libzwaves_jni.so file diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/linux64/amd64/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/linux64/amd64/.gitkeep index 859d1c9..f5dabae 100644 --- a/zwaves_jni/javalib/src/main/resources/META-INF/native/linux64/amd64/.gitkeep +++ b/zwaves_jni/javalib/src/main/resources/META-INF/native/linux64/amd64/.gitkeep @@ -1 +1 @@ -place here libzwaves_jni.so file \ No newline at end of file +place here libzwaves_jni.so file diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/osx64/aarch64/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/osx64/aarch64/.gitkeep index eec68a2..a6d5407 100644 --- a/zwaves_jni/javalib/src/main/resources/META-INF/native/osx64/aarch64/.gitkeep +++ b/zwaves_jni/javalib/src/main/resources/META-INF/native/osx64/aarch64/.gitkeep @@ -1 +1 @@ -place here libzwaves_jni.dylib for Apple ARM file \ No newline at end of file +place here libzwaves_jni.dylib for Apple ARM file diff --git a/zwaves_jni/javalib/src/main/resources/META-INF/native/osx64/amd64/.gitkeep b/zwaves_jni/javalib/src/main/resources/META-INF/native/osx64/amd64/.gitkeep index 01edf4d..5e4aea5 100644 --- a/zwaves_jni/javalib/src/main/resources/META-INF/native/osx64/amd64/.gitkeep +++ b/zwaves_jni/javalib/src/main/resources/META-INF/native/osx64/amd64/.gitkeep @@ -1 +1 @@ -place here libzwaves_jni.dylib file \ No newline at end of file +place here libzwaves_jni.dylib file