From 7231fdf755f1967dbe9c3e7f0e731154a14789c7 Mon Sep 17 00:00:00 2001 From: Drygin Date: Wed, 3 Jul 2019 19:02:28 +0300 Subject: [PATCH] wip: add read vk from uncompressed binary --- test_back_fluence/proof2.bin | 2 +- test_back_fluence/src/main.rs | 121 ++++++++++++++++++-------- test_back_fluence/verification222.key | Bin 0 -> 772 bytes 3 files changed, 86 insertions(+), 37 deletions(-) create mode 100644 test_back_fluence/verification222.key diff --git a/test_back_fluence/proof2.bin b/test_back_fluence/proof2.bin index ef2298e..30c1508 100644 --- a/test_back_fluence/proof2.bin +++ b/test_back_fluence/proof2.bin @@ -1,2 +1,2 @@ <4{  -"ҼV".sOUqw!Qr]bD|,̊I0"m78`Bw } \ No newline at end of file +"ҼV".sOUqw!Qr]bD|,̊I0"m78`Bw })ۨ{7!.ժ;~4ȺJC. Bx[.1B\|"YT/,)=E3HsV= 箶3MAnН1ox۾}fNP)>\dR}`3(J֯e Wؖ,Sܑ] t]th \ No newline at end of file diff --git a/test_back_fluence/src/main.rs b/test_back_fluence/src/main.rs index d9288ef..60ebb02 100644 --- a/test_back_fluence/src/main.rs +++ b/test_back_fluence/src/main.rs @@ -59,45 +59,84 @@ fn main() { EncodedPoint }; - - use crate::{ - SynthesisError - }; - use std::io::{self, Read}; use std::sync::Arc; - // import verification key + use std::io::{Cursor, Seek, SeekFrom}; + + // import verification key ---------------------------------------------------------------------------------------- //let vk_file = File::open(PathBuf::from("./verification.key")).unwrap(); //let vk : VerifyingKey = VerifyingKey::read(vk_file).unwrap(); - //let vk_file = File::open(PathBuf::from("./vk.key")).unwrap(); - //let vk : VerifyingKey = VerifyingKey::read(vk_file).unwrap(); + //vk.alpha_g1 + let mut hex_string = hex::decode("1fea09defec64586a976a33dbfb70961fc7e03fb6f4d5a1e074f97312ce789cd").unwrap(); + hex_string.append(hex::decode("006653d8d2e65ab55fa795c44971eabcc6dbb1dd383c7a8a20de68486eb28154").unwrap().as_mut()); + //vk.beta_g1 + hex_string.append(hex::decode("09dcdb7f3d5d8f36be6363578bc80c86bb0978b2da7f396e366552c19327d2fa").unwrap().as_mut()); + hex_string.append(hex::decode("06c8435a1215747694d059d9b1e4a36d6acd204af1efaf96c22fa3c978b7b57e").unwrap().as_mut()); + //vk.beta_g2 + hex_string.append(hex::decode("1fb73b30d15c6acbf8e723365798381cddccd353d3473853f8586045da20d9c7").unwrap().as_mut()); + hex_string.append(hex::decode("0ea0d501ac34e65153ff483d15864b7b99d03727e3d18a10442ed2c5b7475616").unwrap().as_mut()); + hex_string.append(hex::decode("15f0b1a8a45717104ab0625e08eadf52f69f05b9fe3b18f33ffa088718c75bb5").unwrap().as_mut()); + hex_string.append(hex::decode("20a215cbe73f412eb06c4f05fbfba106600474e659572d5cacab3e02db4d56b5").unwrap().as_mut()); + //vk.gamma_g2 + hex_string.append(hex::decode("288918039bccc005d837cc445b01e394df8a8ba5f6c9640a54013ce723195a91").unwrap().as_mut()); + hex_string.append(hex::decode("257c137fe6037e6302bcc0e0c8d12c55c32663ea30aaf8602cb505cce116934d").unwrap().as_mut()); + hex_string.append(hex::decode("0b9641484e773a5c30f604b912e7008d8c80221eb8af076206d1cb62d5459d6d").unwrap().as_mut()); + hex_string.append(hex::decode("1422be63e21d8de851ba9ef345b3ba8e9f30dcc9b2b9181700c6c7387fd0000c").unwrap().as_mut()); + //vk.delta_g1 + hex_string.append(hex::decode("2685638d1ab1c53e240faa4c600e08bf5acaeb923f530d6c6b02d752c4401c6e").unwrap().as_mut()); + hex_string.append(hex::decode("16bd94558a5419e22b4fca334f8e11c67d2aeaa0668521a6c41cd5804c03afa3").unwrap().as_mut()); + //vk.delta_g2 + hex_string.append(hex::decode("199f02185af5ab7a2646ad6523cf0e75160919770fac8be6d87a2c85f5c62fa2").unwrap().as_mut()); + hex_string.append(hex::decode("2415e319be12366f2b5f59f6475008d3fa8f2486dbbd417ff979dc727ac8b506").unwrap().as_mut()); + hex_string.append(hex::decode("211d44b4f8fc9f4aa10acce7e45205e497df0ba61ae321db03a520d213f2f884").unwrap().as_mut()); + hex_string.append(hex::decode("1a684894edd1457382d460ac84ffbae1dbb1d35403e3729e06edf10960ccbb58").unwrap().as_mut()); + //vk.ic len + hex_string.append(3u32.to_be_bytes().to_vec().as_mut()); + //vk.ic + hex_string.append(hex::decode("26d321094b0704a73f6c3b0fa361ce36ec94775d3dcd4b0fcbed086f2417b69d").unwrap().as_mut()); + hex_string.append(hex::decode("26895772f453edf3d38c1e3b11a74d134fec4e3f225bae6620470bafedbbe374").unwrap().as_mut()); + hex_string.append(hex::decode("28ca43de88e898c1b5871d2d2da4a60fb470a459c64922556253eb0d87a0950e").unwrap().as_mut()); + hex_string.append(hex::decode("2e076fbdb638cd389f3a2748ba759ddbee20b97dfb577343af18109506675ead").unwrap().as_mut()); + hex_string.append(hex::decode("02a3959d26d938fbbd2f1453b4cdc8558703133524ddab59dba20e8b920f27ab").unwrap().as_mut()); + hex_string.append(hex::decode("293e35b2ba09b27006eead4fe4a4aae136391e33a56ee5b2b9bff744f2657e74").unwrap().as_mut()); - //let prepared_vk = prepare_verifying_key(&vk); + let mut c = Cursor::new(Vec::new()); - // import proof - let proof_file = File::open(PathBuf::from("./proof.bin")).unwrap(); - let proof : Proof = Proof::read(proof_file).unwrap(); + c.write_all(hex_string.as_slice()).unwrap(); + c.seek(SeekFrom::Start(0)).unwrap(); - // export proof - let mut proof_file = File::create(PathBuf::from("./proof2.bin")).unwrap(); - proof_file.write_all(proof.a.into_uncompressed().as_ref()); - //proof_file.write_all(proof.b.into_compressed().as_ref()); - //0x125c6452b97d9b83600e903313aa93284a8b8d8318050ed6af65c10df7ebb5ec - //let [u8] = - //proof_file.write_all(proof.c.into_compressed().as_ref()); + let vk : VerifyingKey = VerifyingKey::read(c).unwrap(); - let mut proof_file = File::open(PathBuf::from("./proof2.bin")).unwrap(); - //let proof : Proof = Proof::read(proof_file).unwrap(); + let prepared_vk = prepare_verifying_key(&vk); + // import proof --------------------------------------------------------------------------------------------------- + + /*let proof_file = File::open(PathBuf::from("./proof.bin")).unwrap(); + let proof : Proof = Proof::read(proof_file).unwrap();*/ + + let mut hex_string = hex::decode("143c347b098006a40a22eaa2d2bc56222e734f55bd717721c90886518872015d").unwrap(); + hex_string.append(hex::decode("10f7e2ca628844cb7c2ccacc8abb4930cd226dcd37f9e83860f942a177020c7d").unwrap().as_mut()); + + hex_string.append(hex::decode("2902bfe7dba8187bd73795211f2eece7d5aa3ba8a1f27e34c8ba148cad4ac743").unwrap().as_mut()); + hex_string.append(hex::decode("2e0b0d4278e6b20f5b2e31fa425c7c91d1eebdaeb01fef228b5954e2a0c01f8a").unwrap().as_mut()); + hex_string.append(hex::decode("2f2c29c73d45cfedf4334873e418860f561c3d7fa4090fe7aeb686023398874d").unwrap().as_mut()); + hex_string.append(hex::decode("14f4411f6edfd09d31ad7f6f78dbbe7debfa66a0cb4e0450888790b4293eeaf1").unwrap().as_mut()); + + hex_string.append(hex::decode("125c6452b97d9b83600e903313aa93284a8b8d8318050ed6af65c10df7ebb5ec").unwrap().as_mut()); + hex_string.append(hex::decode("1a5702d896bdf72c8853dc91819a5de30d7415c61c0eb9c55d947485b268ef89").unwrap().as_mut()); + + let mut c = Cursor::new(Vec::new()); + + c.write_all(hex_string.as_slice()).unwrap(); + c.seek(SeekFrom::Start(0)).unwrap(); let mut g1_repr = ::Uncompressed::empty(); - //let mut g2_repr = ::Uncompressed::empty(); + let mut g2_repr = ::Uncompressed::empty(); - proof_file.read_exact(g1_repr.as_mut()); - //let a = g1_repr.into_affine(); + c.read_exact(g1_repr.as_mut()); let a = g1_repr .into_affine() .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) @@ -106,21 +145,31 @@ fn main() { } else { Ok(e) }).unwrap(); - println!("!!! proof a g1: {}", a); + //println!("proof a g1: {}", a); + c.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) + }).unwrap(); + //println!("proof b g2: {}", b); - // write proof.a in hex form and binary form - let a : G1Affine = proof.a; - println!("proof a g1: {}", a); - println!("proof a g1 compressed: {:?}", a.into_compressed().as_ref()); + c.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) + }).unwrap(); + //println!("proof c g1: {}", c); - let b : G2Affine = proof.b; - println!("proof b g2: {}", b); - println!("proof b g2 compressed: {:?}", b.into_compressed().as_ref()); - - let c : G1Affine = proof.c; - println!("proof c g1: {}", c); - println!("proof c g1 uncompressed: {:?}", c.into_compressed().as_ref()); + let proof : Proof = Proof {a: a, b: b, c: c}; // import public inputs //let public_inputs = vec![]; diff --git a/test_back_fluence/verification222.key b/test_back_fluence/verification222.key new file mode 100644 index 0000000000000000000000000000000000000000..55259fbb5fb70fde846ca062cfaf4981dadf8fef GIT binary patch literal 772 zcmV+f1N;0R>IvTd#zlsycB4JNw+UhVegpe&OeVG=32F1r zaq7Ir+p*m^JbH>C-e^c}vVl|y+}nRWU5_@tV`Eo~$P9+N33#&Fe>rY8Wm3VDC(`-` z$U|BZ6?Ar#&{^5BvP=Tx!es=OZ>(m^d8W%+piT zM>tdXSYSokAlb(bpw$7aH0DuL|42O*hD&>y&^IUJ(TWg6F4D!fM^+XU@Uf_*R~HaU zuwq^a>fciKp9Q)8I~emn`Ur;@$6K`^q7}>MKS3_AY)=LI`=JJ41a#(ES1nwut3CqT zO;)uii5LT$%)kZMH_Sv^0ppb4ii@T8$z%#t0X*j;8CsDgd=r1>1Ab!yyujed(JWQN zCS&R_s`y|mwFS)K7L!d2mO)5PcRE}!_5`^S=Kzh2fFd5auLoiV(aU1hMV)OFBEDnd z9gXNwx}Nhzv$~F-Fx<(qxfmA!#>Y5+&;Sf3g=38xvBf?l52{RH4hX+m%IlIpQw?lu z0@qT+Kpbusy_8joR2kwcPs%e-juFOvD(awSg(0TI9MynK1FxeQp8^`p%-TdrmxM+>j*yW?~y%0u3W=$OH^haD{~q^1wFaHLtrNg`EZ zQ|k?fpp_0T2XDQ$IL$bpIwwfFb)DPpAh~_}S93$J7!Z{PXI`xWqm`W|**N>XFBDU> z&B#@U0~0kQ-K$yKq7I9a4=1ZBJ~gts39@ho?yXPcq^jXIIUX~mZsoGMzxPD)Wqx!z C4r_J* literal 0 HcmV?d00001