Quellcode durchsuchen

create jubjub specific tests

narodnik vor 5 Jahren
Ursprung
Commit
38b93fe60b
4 geänderte Dateien mit 36 neuen und 3 gelöschten Zeilen
  1. 7 3
      Cargo.toml
  2. 0 0
      proofs/jubjub.psm
  3. 28 0
      src/bls_extensions.rs
  4. 1 0
      src/lib.rs

+ 7 - 3
Cargo.toml

@@ -59,7 +59,7 @@ name = "simple"
 path = "src/simple.rs"
 
 [[bin]]
-name = "mint"
+name = "mint-old"
 path = "src/mint.rs"
 
 [[bin]]
@@ -79,7 +79,7 @@ name = "vmtest"
 path = "src/vmtest.rs"
 
 [[bin]]
-name = "jubjub"
+name = "jubjub-old"
 path = "src/jubjub.rs"
 
 [[bin]]
@@ -99,6 +99,10 @@ name = "zkvm"
 path = "src/zkvm.rs"
 
 [[bin]]
-name = "mint3"
+name = "mint"
 path = "src/bin/mint.rs"
 
+[[bin]]
+name = "jubjub"
+path = "src/bin/jubjub.rs"
+

+ 0 - 0
proofs/jubjub.pism → proofs/jubjub.psm


+ 28 - 0
src/bls_extensions.rs

@@ -5,6 +5,34 @@ use std::io;
 use crate::error::{Error, Result};
 use crate::serial::{Decodable, Encodable, ReadExt, WriteExt};
 
+macro_rules! from_slice {
+    ($data:expr, $len:literal) => {{
+        let mut array = [0; $len];
+        // panics if not enough data
+        let bytes = &$data[..array.len()];
+        array.copy_from_slice(bytes);
+        array
+    }};
+}
+
+pub trait BlsStringConversion {
+    fn to_string(&self) -> String;
+    fn from_string(object: &str) -> Self;
+}
+
+impl BlsStringConversion for bls::Scalar {
+    fn to_string(&self) -> String {
+        let mut bytes = self.to_bytes();
+        bytes.reverse();
+        hex::encode(bytes)
+    }
+    fn from_string(object: &str) -> Self {
+        let mut bytes = from_slice!(&hex::decode(object).unwrap(), 32);
+        bytes.reverse();
+        bls::Scalar::from_bytes(&bytes).unwrap()
+    }
+}
+
 macro_rules! serialization_bls {
     ($type:ty, $to_x:ident, $from_x:ident, $size:literal) => {
         impl Encodable for $type {

+ 1 - 0
src/lib.rs

@@ -8,6 +8,7 @@ pub mod serial;
 pub mod vm;
 pub mod vm_serial;
 
+pub use crate::bls_extensions::BlsStringConversion;
 pub use crate::serial::{Decodable, Encodable};
 pub use crate::vm::{
     AllocType, ConstraintInstruction, CryptoOperation, VariableIndex, VariableRef, ZKVMCircuit,