{% include 'mimc_constants.psm' %} contract mimc param left_0 param right {# Jinja cannot set variables inside loops so use this hack #} {% set ns = namespace(right="right") %} {% for i in range(322) %} # Each round perform these steps: # xL, xR := xR + (xL + Ci)^3, xL local mimc_const load mimc_const mimc_constant_{{i}} private tmp_{{i}} set tmp_{{i}} left_{{i}} add tmp_{{i}} mimc_const square tmp_{{i}} lc0_add left_{{i}} lc0_add_constant mimc_constant_{{i}} lc1_add left_{{i}} lc1_add_constant mimc_constant_{{i}} lc2_add tmp_{{i}} enforce # new_xL = xR + (xL + Ci)^3 # new_xL = xR + tmp * (xL + Ci) # new_xL - xR = tmp * (xL + Ci) private left_{{i+1}} set left_{{i+1}} left_{{i}} add left_{{i+1}} mimc_const mul left_{{i+1}} tmp_{{i}} add left_{{i+1}} {{ns.right}} lc0_add tmp_{{i}} lc1_add left_{{i}} lc1_add_constant mimc_constant_{{i}} lc2_add left_{{i+1}} lc2_sub {{ns.right}} enforce # xR = xL # right_{{i+1}} = left_{{i}} {% set ns.right = "left_" + i|string %} # xL = new_xL {% endfor %} public hash_result set hash_result left_322 lc0_add left_322 lc1_add_one lc2_add hash_result enforce end