arnaucube
arnaucube/babyjubjub-arkPublic Self-hosted repository
babyjubjub-ark/src/lib.rs
src/lib.rsRaw
  1#[macro_use]
  2extern crate arrayref;
  3extern crate generic_array;
  4extern crate mimc_rs;
  5extern crate num;
  6extern crate num_bigint;
  7extern crate num_traits;
  8extern crate rand;
  9
 10use blake2::{Blake2b, Digest};
 11use mimc_rs::Mimc7;
 12use poseidon_rs::Poseidon;
 13use std::cmp::min;
 14
 15use num_bigint::{BigInt, RandBigInt, Sign, ToBigInt};
 16use num_traits::{One, Zero};
 17
 18use generic_array::GenericArray;
 19
 20mod utils;
 21
 22#[macro_use]
 23extern crate lazy_static;
 24
 25lazy_static! {
 26    static ref D: BigInt = BigInt::parse_bytes(b"168696", 10).unwrap();
 27    static ref A: BigInt = BigInt::parse_bytes(b"168700", 10).unwrap();
 28    static ref Q: BigInt = BigInt::parse_bytes(
 29        b"21888242871839275222246405745257275088548364400416034343698204186575808495617",
 30        10,
 31    )
 32    .unwrap();
 33    static ref B8: Point = Point {
 34        x: BigInt::parse_bytes(
 35            b"5299619240641551281634865583518297030282874472190772894086521144482721001553",
 36            10,
 37        )
 38        .unwrap(),
 39        y: BigInt::parse_bytes(
 40            b"16950150798460657717958625567821834550301663161624707787222815936182638968203",
 41            10,
 42        )
 43        .unwrap(),
 44    };
 45    static ref ORDER: BigInt = BigInt::parse_bytes(
 46        b"21888242871839275222246405745257275088614511777268538073601725287587578984328",
 47        10,
 48    )
 49    .unwrap();
 50    static ref SUBORDER: BigInt = &BigInt::parse_bytes(
 51        b"21888242871839275222246405745257275088614511777268538073601725287587578984328",
 52        10,
 53    )
 54    .unwrap()
 55        >> 3;
 56}
 57
 58#[derive(Clone, Debug)]
 59pub struct Point {
 60    pub x: BigInt,
 61    pub y: BigInt,
 62}
 63
 64impl Point {
 65    pub fn add(&self, q: &Point) -> Result<Point, String> {
 66        // x = (x1*y2+y1*x2)/(c*(1+d*x1*x2*y1*y2))
 67        // y = (y1*y2-x1*x2)/(c*(1-d*x1*x2*y1*y2))
 68
 69        // x = (x1 * y2 + y1 * x2) / (1 + d * x1 * y1 * y2)
 70        let one: BigInt = One::one();
 71        let x_num: BigInt = &self.x * &q.y + &self.y * &q.x;
 72        let x_den: BigInt = &one + &D.clone() * &self.x * &q.x * &self.y * &q.y;
 73        let x_den_inv = utils::modinv(&x_den, &Q)?;
 74        let x: BigInt = utils::modulus(&(&x_num * &x_den_inv), &Q);
 75
 76        // y = (y1 * y2 - a * x1 * x2) / (1 - d * x1 * x2 * y1 * y2)
 77        let y_num = &self.y * &q.y - &A.clone() * &self.x * &q.x;
 78        let y_den = utils::modulus(&(&one - &D.clone() * &self.x * &q.x * &self.y * &q.y), &Q);
 79        let y_den_inv = utils::modinv(&y_den, &Q)?;
 80        let y: BigInt = utils::modulus(&(&y_num * &y_den_inv), &Q);
 81
 82        Ok(Point { x: x, y: y })
 83    }
 84
 85    pub fn mul_scalar(&self, n: &BigInt) -> Result<Point, String> {
 86        let mut r: Point = Point {
 87            x: Zero::zero(),
 88            y: One::one(),
 89        };
 90        let mut rem: BigInt = n.clone();
 91        let mut exp: Point = self.clone();
 92
 93        let zero: BigInt = Zero::zero();
 94        let one: BigInt = One::one();
 95        while rem != zero {
 96            let is_odd = &rem & &one == one;
 97            if is_odd == true {
 98                r = r.add(&exp)?;
 99            }
100            exp = exp.add(&exp)?;
101            rem = rem >> 1;
102        }
103        r.x = utils::modulus(&r.x, &Q);
104        r.y = utils::modulus(&r.y, &Q);
105        Ok(r)
106    }
107
108    pub fn compress(&self) -> [u8; 32] {
109        let mut r: [u8; 32] = [0; 32];
110        let (_, y_bytes) = self.y.to_bytes_le();
111        let len = min(y_bytes.len(), r.len());
112        r[..len].copy_from_slice(&y_bytes[..len]);
113        if &self.x > &(&Q.clone() >> 1) {
114            r[31] = r[31] | 0x80;
115        }
116        r
117    }
118
119    pub fn equals(&self, p: Point) -> bool {
120        if self.x == p.x && self.y == p.y {
121            return true;
122        }
123        false
124    }
125}
126
127pub fn decompress_point(bb: [u8; 32]) -> Result<Point, String> {
128    // https://tools.ietf.org/html/rfc8032#section-5.2.3
129    let mut sign: bool = false;
130    let mut b = bb.clone();
131    if b[31] & 0x80 != 0x00 {
132        sign = true;
133        b[31] = b[31] & 0x7F;
134    }
135    let y: BigInt = BigInt::from_bytes_le(Sign::Plus, &b[..]);
136    if y >= Q.clone() {
137        return Err("y outside the Finite Field over R".to_string());
138    }
139    let one: BigInt = One::one();
140
141    // x^2 = (1 - y^2) / (a - d * y^2) (mod p)
142    let den = utils::modinv(
143        &utils::modulus(
144            &(&A.clone() - utils::modulus(&(&D.clone() * (&y * &y)), &Q)),
145            &Q,
146        ),
147        &Q,
148    )?;
149    let mut x: BigInt = utils::modulus(&((one - utils::modulus(&(&y * &y), &Q)) * den), &Q);
150    x = utils::modsqrt(&x, &Q)?;
151
152    if sign && !(&x > &(&Q.clone() >> 1)) || (!sign && (&x > &(&Q.clone() >> 1))) {
153        x = x * -1.to_bigint().unwrap();
154    }
155    x = utils::modulus(&x, &Q);
156    Ok(Point { x: x, y: y })
157}
158
159pub struct Signature {
160    r_b8: Point,
161    s: BigInt,
162}
163
164impl Signature {
165    pub fn compress(&self) -> [u8; 64] {
166        let mut b: Vec<u8> = Vec::new();
167        b.append(&mut self.r_b8.compress().to_vec());
168        let (_, s_bytes) = self.s.to_bytes_le();
169        let mut s_32bytes: [u8; 32] = [0; 32];
170        let len = min(s_bytes.len(), s_32bytes.len());
171        s_32bytes[..len].copy_from_slice(&s_bytes[..len]);
172        b.append(&mut s_32bytes.to_vec());
173        let mut r: [u8; 64] = [0; 64];
174        r[..].copy_from_slice(&b[..]);
175        r
176    }
177}
178
179pub fn decompress_signature(b: &[u8; 64]) -> Result<Signature, String> {
180    let r_b8_bytes: [u8; 32] = *array_ref!(b[..32], 0, 32);
181    let s: BigInt = BigInt::from_bytes_le(Sign::Plus, &b[32..]);
182    let r_b8 = decompress_point(r_b8_bytes);
183    match r_b8 {
184        Result::Err(err) => return Err(err.to_string()),
185        Result::Ok(res) => Ok(Signature {
186            r_b8: res.clone(),
187            s: s,
188        }),
189    }
190}
191
192pub struct PrivateKey {
193    key: BigInt,
194}
195
196impl PrivateKey {
197    pub fn public(&self) -> Result<Point, String> {
198        // https://tools.ietf.org/html/rfc8032#section-5.1.5
199        let pk = B8.mul_scalar(&self.key)?;
200        Ok(pk.clone())
201    }
202
203    pub fn sign_mimc(&self, msg: BigInt) -> Result<Signature, String> {
204        // https://tools.ietf.org/html/rfc8032#section-5.1.6
205        let mut hasher = Blake2b::new();
206        let (_, sk_bytes) = self.key.to_bytes_be();
207        hasher.input(sk_bytes);
208        let mut h = hasher.result(); // h: hash(sk)
209                                     // s: h[32:64]
210        let s = GenericArray::<u8, generic_array::typenum::U32>::from_mut_slice(&mut h[32..64]);
211        let (_, msg_bytes) = msg.to_bytes_be();
212        let r_bytes = utils::concatenate_arrays(s, &msg_bytes);
213        let mut r = BigInt::from_bytes_be(Sign::Plus, &r_bytes[..]);
214        r = utils::modulus(&r, &SUBORDER);
215        let r8: Point = B8.mul_scalar(&r)?;
216        let a = &self.public()?;
217
218        let hm_input = vec![r8.x.clone(), r8.y.clone(), a.x.clone(), a.y.clone(), msg];
219        let mimc7 = Mimc7::new();
220        let hm = mimc7.hash(hm_input)?;
221
222        let mut s = &self.key << 3;
223        s = hm * s;
224        s = r + s;
225        s = s % &SUBORDER.clone();
226
227        Ok(Signature {
228            r_b8: r8.clone(),
229            s: s,
230        })
231    }
232    pub fn sign_poseidon(&self, msg: BigInt) -> Result<Signature, String> {
233        // https://tools.ietf.org/html/rfc8032#section-5.1.6
234        let mut hasher = Blake2b::new();
235        let (_, sk_bytes) = self.key.to_bytes_be();
236        hasher.input(sk_bytes);
237        let mut h = hasher.result(); // h: hash(sk)
238                                     // s: h[32:64]
239        let s = GenericArray::<u8, generic_array::typenum::U32>::from_mut_slice(&mut h[32..64]);
240        let (_, msg_bytes) = msg.to_bytes_be();
241        let r_bytes = utils::concatenate_arrays(s, &msg_bytes);
242        let mut r = BigInt::from_bytes_be(Sign::Plus, &r_bytes[..]);
243        r = utils::modulus(&r, &SUBORDER);
244        let r8: Point = B8.mul_scalar(&r)?;
245        let a = &self.public()?;
246
247        let hm_input = vec![r8.x.clone(), r8.y.clone(), a.x.clone(), a.y.clone(), msg];
248        let poseidon = Poseidon::new();
249        let hm = poseidon.hash(hm_input)?;
250
251        let mut s = &self.key << 3;
252        s = hm * s;
253        s = r + s;
254        s = s % &SUBORDER.clone();
255
256        Ok(Signature {
257            r_b8: r8.clone(),
258            s: s,
259        })
260    }
261
262    pub fn sign_schnorr(&self, m: Vec<u8>) -> Result<(Point, BigInt), String> {
263        // random r
264        let mut rng = rand::thread_rng();
265        let k = rng.gen_biguint(1024).to_bigint().unwrap();
266
267        // r = k·G
268        let r = B8.mul_scalar(&k)?;
269
270        // h = H(x, r, m)
271        let pk = &self.public()?;
272        let h = schnorr_hash(&pk, m, &r)?;
273
274        // s= k+x·h
275        let s = k + &self.key * &h;
276        Ok((r, s))
277    }
278}
279
280pub fn schnorr_hash(pk: &Point, m: Vec<u8>, c: &Point) -> Result<BigInt, String> {
281    let b: &mut Vec<u8> = &mut Vec::new();
282
283    // other option could be to do it without compressing the points, and concatenating x|y
284    b.append(&mut pk.compress().to_vec());
285    b.append(&mut c.compress().to_vec());
286    b.append(&mut m.clone());
287
288    let poseidon = Poseidon::new();
289    let h = poseidon.hash_bytes(b.to_vec())?;
290    println!("h {:?}", h.to_string());
291    Ok(h)
292}
293
294pub fn verify_schnorr(pk: Point, m: Vec<u8>, r: Point, s: BigInt) -> Result<bool, String> {
295    // sG = s·G
296    let sg = B8.mul_scalar(&s)?;
297
298    // r + h · x
299    let h = schnorr_hash(&pk, m, &r)?;
300    let pk_h = pk.mul_scalar(&h)?;
301    let right = r.add(&pk_h)?;
302
303    Ok(sg.equals(right))
304}
305
306pub fn new_key() -> PrivateKey {
307    // https://tools.ietf.org/html/rfc8032#section-5.1.5
308    let mut rng = rand::thread_rng();
309    let sk_raw = rng.gen_biguint(1024).to_bigint().unwrap();
310
311    let mut hasher = Blake2b::new();
312    let (_, sk_raw_bytes) = sk_raw.to_bytes_be();
313    hasher.input(sk_raw_bytes);
314    let mut h = hasher.result();
315
316    h[0] = h[0] & 0xF8;
317    h[31] = h[31] & 0x7F;
318    h[31] = h[31] | 0x40;
319
320    let sk = BigInt::from_bytes_le(Sign::Plus, &h[..]);
321
322    PrivateKey { key: sk }
323}
324
325pub fn verify_mimc(pk: Point, sig: Signature, msg: BigInt) -> bool {
326    let hm_input = vec![
327        sig.r_b8.x.clone(),
328        sig.r_b8.y.clone(),
329        pk.x.clone(),
330        pk.y.clone(),
331        msg,
332    ];
333    let mimc7 = Mimc7::new();
334    let hm = match mimc7.hash(hm_input) {
335        Result::Err(_) => return false,
336        Result::Ok(hm) => hm,
337    };
338    let l = match B8.mul_scalar(&sig.s) {
339        Result::Err(_) => return false,
340        Result::Ok(l) => l,
341    };
342    let r = match sig
343        .r_b8
344        .add(&pk.mul_scalar(&(8.to_bigint().unwrap() * hm)).unwrap())
345    {
346        Result::Err(_) => return false,
347        Result::Ok(r) => r,
348    };
349    l.equals(r)
350}
351pub fn verify_poseidon(pk: Point, sig: Signature, msg: BigInt) -> bool {
352    let hm_input = vec![
353        sig.r_b8.x.clone(),
354        sig.r_b8.y.clone(),
355        pk.x.clone(),
356        pk.y.clone(),
357        msg,
358    ];
359    let poseidon = Poseidon::new();
360    let hm = match poseidon.hash(hm_input) {
361        Result::Err(_) => return false,
362        Result::Ok(hm) => hm,
363    };
364    let l = match B8.mul_scalar(&sig.s) {
365        Result::Err(_) => return false,
366        Result::Ok(l) => l,
367    };
368    let r = match sig
369        .r_b8
370        .add(&pk.mul_scalar(&(8.to_bigint().unwrap() * hm)).unwrap())
371    {
372        Result::Err(_) => return false,
373        Result::Ok(r) => r,
374    };
375    l.equals(r)
376}
377
378#[cfg(test)]
379mod tests {
380    use super::*;
381    extern crate rustc_hex;
382    use rustc_hex::{FromHex, ToHex};
383
384    #[test]
385    fn test_add_same_point() {
386        let p: Point = Point {
387            x: BigInt::parse_bytes(
388                b"17777552123799933955779906779655732241715742912184938656739573121738514868268",
389                10,
390            )
391            .unwrap(),
392            y: BigInt::parse_bytes(
393                b"2626589144620713026669568689430873010625803728049924121243784502389097019475",
394                10,
395            )
396            .unwrap(),
397        };
398        let q: Point = Point {
399            x: BigInt::parse_bytes(
400                b"17777552123799933955779906779655732241715742912184938656739573121738514868268",
401                10,
402            )
403            .unwrap(),
404            y: BigInt::parse_bytes(
405                b"2626589144620713026669568689430873010625803728049924121243784502389097019475",
406                10,
407            )
408            .unwrap(),
409        };
410        let res = p.add(&q).unwrap();
411        assert_eq!(
412            res.x.to_string(),
413            "6890855772600357754907169075114257697580319025794532037257385534741338397365"
414        );
415        assert_eq!(
416            res.y.to_string(),
417            "4338620300185947561074059802482547481416142213883829469920100239455078257889"
418        );
419    }
420    #[test]
421    fn test_add_different_points() {
422        let p: Point = Point {
423            x: BigInt::parse_bytes(
424                b"17777552123799933955779906779655732241715742912184938656739573121738514868268",
425                10,
426            )
427            .unwrap(),
428            y: BigInt::parse_bytes(
429                b"2626589144620713026669568689430873010625803728049924121243784502389097019475",
430                10,
431            )
432            .unwrap(),
433        };
434        let q: Point = Point {
435            x: BigInt::parse_bytes(
436                b"16540640123574156134436876038791482806971768689494387082833631921987005038935",
437                10,
438            )
439            .unwrap(),
440            y: BigInt::parse_bytes(
441                b"20819045374670962167435360035096875258406992893633759881276124905556507972311",
442                10,
443            )
444            .unwrap(),
445        };
446        let res = p.add(&q).unwrap();
447        assert_eq!(
448            res.x.to_string(),
449            "7916061937171219682591368294088513039687205273691143098332585753343424131937"
450        );
451        assert_eq!(
452            res.y.to_string(),
453            "14035240266687799601661095864649209771790948434046947201833777492504781204499"
454        );
455    }
456
457    #[test]
458    fn test_mul_scalar() {
459        let p: Point = Point {
460            x: BigInt::parse_bytes(
461                b"17777552123799933955779906779655732241715742912184938656739573121738514868268",
462                10,
463            )
464            .unwrap(),
465            y: BigInt::parse_bytes(
466                b"2626589144620713026669568689430873010625803728049924121243784502389097019475",
467                10,
468            )
469            .unwrap(),
470        };
471        let res_m = p.mul_scalar(&3.to_bigint().unwrap()).unwrap();
472        let res_a = p.add(&p).unwrap();
473        let res_a = res_a.add(&p).unwrap();
474        assert_eq!(res_m.x, res_a.x);
475        assert_eq!(
476            res_m.x.to_string(),
477            "19372461775513343691590086534037741906533799473648040012278229434133483800898"
478        );
479        assert_eq!(
480            res_m.y.to_string(),
481            "9458658722007214007257525444427903161243386465067105737478306991484593958249"
482        );
483
484        let n = BigInt::parse_bytes(
485            b"14035240266687799601661095864649209771790948434046947201833777492504781204499",
486            10,
487        )
488        .unwrap();
489        let res2 = p.mul_scalar(&n).unwrap();
490        assert_eq!(
491            res2.x.to_string(),
492            "17070357974431721403481313912716834497662307308519659060910483826664480189605"
493        );
494        assert_eq!(
495            res2.y.to_string(),
496            "4014745322800118607127020275658861516666525056516280575712425373174125159339"
497        );
498    }
499
500    #[test]
501    fn test_new_key_sign_verify_mimc_0() {
502        let sk = new_key();
503        let pk = sk.public().unwrap();
504        let msg = 5.to_bigint().unwrap();
505        let sig = sk.sign_mimc(msg.clone()).unwrap();
506        let v = verify_mimc(pk, sig, msg);
507        assert_eq!(v, true);
508    }
509
510    #[test]
511    fn test_new_key_sign_verify_mimc_1() {
512        let sk = new_key();
513        let pk = sk.public().unwrap();
514        let msg = BigInt::parse_bytes(b"123456789012345678901234567890", 10).unwrap();
515        let sig = sk.sign_mimc(msg.clone()).unwrap();
516        let v = verify_mimc(pk, sig, msg);
517        assert_eq!(v, true);
518    }
519    #[test]
520    fn test_new_key_sign_verify_poseidon_0() {
521        let sk = new_key();
522        let pk = sk.public().unwrap();
523        let msg = 5.to_bigint().unwrap();
524        let sig = sk.sign_poseidon(msg.clone()).unwrap();
525        let v = verify_poseidon(pk, sig, msg);
526        assert_eq!(v, true);
527    }
528
529    #[test]
530    fn test_new_key_sign_verify_poseidon_1() {
531        let sk = new_key();
532        let pk = sk.public().unwrap();
533        let msg = BigInt::parse_bytes(b"123456789012345678901234567890", 10).unwrap();
534        let sig = sk.sign_poseidon(msg.clone()).unwrap();
535        let v = verify_poseidon(pk, sig, msg);
536        assert_eq!(v, true);
537    }
538
539    #[test]
540    fn test_point_compress_decompress() {
541        let p: Point = Point {
542            x: BigInt::parse_bytes(
543                b"17777552123799933955779906779655732241715742912184938656739573121738514868268",
544                10,
545            )
546            .unwrap(),
547            y: BigInt::parse_bytes(
548                b"2626589144620713026669568689430873010625803728049924121243784502389097019475",
549                10,
550            )
551            .unwrap(),
552        };
553        let p_comp = p.compress();
554        assert_eq!(
555            p_comp[..].to_hex(),
556            "53b81ed5bffe9545b54016234682e7b2f699bd42a5e9eae27ff4051bc698ce85"
557        );
558        let p2 = decompress_point(p_comp).unwrap();
559        assert_eq!(p.x, p2.x);
560        assert_eq!(p.y, p2.y);
561    }
562
563    #[test]
564    fn test_point_decompress0() {
565        let y_bytes_raw = "b5328f8791d48f20bec6e481d91c7ada235f1facf22547901c18656b6c3e042f"
566            .from_hex()
567            .unwrap();
568        let mut y_bytes: [u8; 32] = [0; 32];
569        y_bytes.copy_from_slice(&y_bytes_raw);
570        let p = decompress_point(y_bytes).unwrap();
571
572        let expected_px_raw = "b86cc8d9c97daef0afe1a4753c54fb2d8a530dc74c7eee4e72b3fdf2496d2113"
573            .from_hex()
574            .unwrap();
575        let mut e_px_bytes: [u8; 32] = [0; 32];
576        e_px_bytes.copy_from_slice(&expected_px_raw);
577        let expected_px: BigInt = BigInt::from_bytes_le(Sign::Plus, &e_px_bytes);
578        assert_eq!(&p.x, &expected_px);
579    }
580
581    #[test]
582    fn test_point_decompress1() {
583        let y_bytes_raw = "70552d3ff548e09266ded29b33ce75139672b062b02aa66bb0d9247ffecf1d0b"
584            .from_hex()
585            .unwrap();
586        let mut y_bytes: [u8; 32] = [0; 32];
587        y_bytes.copy_from_slice(&y_bytes_raw);
588        let p = decompress_point(y_bytes).unwrap();
589
590        let expected_px_raw = "30f1635ba7d56f9cb32c3ffbe6dca508a68c7f43936af11a23c785ce98cb3404"
591            .from_hex()
592            .unwrap();
593        let mut e_px_bytes: [u8; 32] = [0; 32];
594        e_px_bytes.copy_from_slice(&expected_px_raw);
595        let expected_px: BigInt = BigInt::from_bytes_le(Sign::Plus, &e_px_bytes);
596        assert_eq!(&p.x, &expected_px);
597    }
598
599    #[test]
600    fn test_point_decompress_loop() {
601        for _ in 0..5 {
602            let mut rng = rand::thread_rng();
603            let sk_raw = rng.gen_biguint(1024).to_bigint().unwrap();
604            let mut hasher = Blake2b::new();
605            let (_, sk_raw_bytes) = sk_raw.to_bytes_be();
606            hasher.input(sk_raw_bytes);
607            let mut h = hasher.result();
608
609            h[0] = h[0] & 0xF8;
610            h[31] = h[31] & 0x7F;
611            h[31] = h[31] | 0x40;
612
613            let sk = BigInt::from_bytes_le(Sign::Plus, &h[..]);
614            let point = B8.mul_scalar(&sk).unwrap();
615            let cmp_point = point.compress();
616            let dcmp_point = decompress_point(cmp_point).unwrap();
617
618            assert_eq!(&point.x, &dcmp_point.x);
619            assert_eq!(&point.y, &dcmp_point.y);
620        }
621    }
622
623    #[test]
624    fn test_signature_compress_decompress() {
625        let sk = new_key();
626        let pk = sk.public().unwrap();
627
628        for i in 0..5 {
629            let msg_raw = "123456".to_owned() + &i.to_string();
630            let msg = BigInt::parse_bytes(msg_raw.as_bytes(), 10).unwrap();
631            let sig = sk.sign_mimc(msg.clone()).unwrap();
632
633            let compressed_sig = sig.compress();
634            let decompressed_sig = decompress_signature(&compressed_sig).unwrap();
635            assert_eq!(&sig.r_b8.x, &decompressed_sig.r_b8.x);
636            assert_eq!(&sig.r_b8.y, &decompressed_sig.r_b8.y);
637            assert_eq!(&sig.s, &decompressed_sig.s);
638
639            let v = verify_mimc(pk.clone(), decompressed_sig, msg);
640            assert_eq!(v, true);
641        }
642    }
643
644    #[test]
645    fn test_schnorr_signature() {
646        let sk = new_key();
647        let pk = sk.public().unwrap();
648
649        let msg: Vec<u8> = ("123456".to_owned() + &1.to_string()).as_bytes().to_vec();
650        let (s, e) = sk.sign_schnorr(msg.clone()).unwrap();
651        println!("s {:?}", s.x.to_string());
652        println!("s {:?}", s.y.to_string());
653        println!("e {:?}", e.to_string());
654        let verification = verify_schnorr(pk, msg, s, e).unwrap();
655        assert_eq!(true, verification);
656    }
657}