codegen.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Functions here are called from pism.py using getattr()
  2. # and the function name as a string.
  3. def witness(line, out, point):
  4. return \
  5. r"""let %s = ecc::EdwardsPoint::witness(
  6. cs.namespace(|| "%s"),
  7. %s.map(jubjub::ExtendedPoint::from))?;""" % (out, line, point)
  8. def assert_not_small_order(line, point):
  9. return '%s.assert_not_small_order(cs.namespace(|| "%s"))?;' % (point, line)
  10. def fr_as_binary_le(line, out, fr):
  11. return \
  12. r"""let %s = boolean::field_into_boolean_vec_le(
  13. cs.namespace(|| "%s"), %s)?;""" % (out, line, fr)
  14. def ec_mul_const(line, out, fr, base):
  15. return \
  16. r"""let %s = ecc::fixed_base_multiplication(
  17. cs.namespace(|| "%s"),
  18. &%s,
  19. &%s,
  20. )?;""" % (out, line, base, fr)
  21. def ec_add(line, out, a, b):
  22. return 'let %s = %s.add(cs.namespace(|| "%s"), &%s)?;' % (out, a, line, b)
  23. def ec_repr(line, out, point):
  24. return 'let %s = %s.repr(cs.namespace(|| "%s"))?;' % (out, point, line)
  25. def emit_ec(line, point):
  26. return '%s.inputize(cs.namespace(|| "%s"))?;' % (point, line)
  27. def alloc_binary(line, out):
  28. return "let mut %s = vec![];" % out
  29. def binary_clone(line, out, binary):
  30. return "let %s = %s.iter().cloned()" % (out, binary)
  31. def binary_extend(line, binary, value):
  32. return "%s.extend(%s);" % (binary, value)