SHARE
TWEET

Untitled

a guest Sep 20th, 2019 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn create_proof<E>(...)
  2. where
  3.     E: Engine
  4. {
  5.     let blahblah = multiexp::<E>(...);
  6. }
  7.  
  8. // Engine trait is something like this, it doesn't provide any information more
  9. // than types of the G1 and G2 curves and their underlying primefields.
  10. // Putting the `multiexp()` and `fft()` functions inside the Engine trait would
  11. // require big changes.
  12. pub trait Engine {
  13.     type G1: CurveProjective;
  14.     type G2: CurveProjective;
  15.     type Fr: PrimeField;
  16.  
  17.     fn miller_loop(...);
  18.     fn final_exponentiation(...);
  19.     fn pairing(...);
  20. }
  21.  
  22. // Original multiexp is a generic implementation that works for any pairs of types
  23. // that implement CurveProjective and PrimeField traits.
  24. fn multiexp<E>(bases: [E::G1], exps: [E::Fr])
  25. where
  26.     E: Engine
  27. {
  28.     let mut acc = E::G1::zero();
  29.     for b,e bases.zip(exps) {
  30.         acc.add_assign(b.mul(e));
  31.         /* add_assign() and mul() are very different for different Engines and Curves
  32.            So we should probably detect the type of E::G1 and E::Fr somehow and
  33.            generate the OpenCL source codes accordingly.
  34.            
  35.            There are several ways we can generate the OpenCL codes, which one is better?
  36.            
  37.            1- Put OpenCL source codes of E::G1 and E::F1 operations inside them,
  38.               get them through a function like: E::Fr::opencl_add_assign_code()
  39.               and concat them later for generating final multiexp kernel, like:
  40.               E::Fr::opencl_add_assign_code() + "\n" + E::G1::opencl_mul_code() + "\n" + "void multiexp(...) {};"
  41.              
  42.            2- Put entire OpenCL kernel code inside of E, like E::opencl_multiexp_code()
  43.            
  44.            3- Define a function like get_opencl_code<E>(e: E) where E::Engine { }
  45.               which detects the Engine and generates the code, without changing
  46.               E::G1 and E::Fr types.*/
  47.        
  48.     }
  49.     return acc;
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top