var snarkjs=function(t){"use strict";const e=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4];function a(t,e){return e&&10!=e?16==e?"0x"==t.slice(0,2)?BigInt(t):BigInt("0x"+t):void 0:BigInt(t)}const i=a;function o(t,e){return BigInt(t)<>BigInt(e)}const r=o,c=n;var l=Object.freeze({__proto__:null,fromString:a,e:i,fromArray:function(t,e){let a=BigInt(0);e=BigInt(e);for(let i=0;i>=BigInt(1)}return a},bits:function(t){let e=BigInt(t);const a=[];for(;e;)e&BigInt(1)?a.push(1):a.push(0),e>>=BigInt(1);return a},toNumber:function(t){if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("Number too big");return Number(t)},toArray:function(t,e){const a=[];let i=BigInt(t);for(e=BigInt(e);i;)a.unshift(Number(i%e)),i/=e;return a},add:function(t,e){return BigInt(t)+BigInt(e)},sub:function(t,e){return BigInt(t)-BigInt(e)},neg:function(t){return-BigInt(t)},mul:function(t,e){return BigInt(t)*BigInt(e)},square:function(t){return BigInt(t)*BigInt(t)},pow:function(t,e){return BigInt(t)**BigInt(e)},exp:function(t,e){return BigInt(t)**BigInt(e)},abs:function(t){return BigInt(t)>=0?BigInt(t):-BigInt(t)},div:function(t,e){return BigInt(t)/BigInt(e)},mod:function(t,e){return BigInt(t)%BigInt(e)},eq:function(t,e){return BigInt(t)==BigInt(e)},neq:function(t,e){return BigInt(t)!=BigInt(e)},lt:function(t,e){return BigInt(t)BigInt(e)},leq:function(t,e){return BigInt(t)<=BigInt(e)},geq:function(t,e){return BigInt(t)>=BigInt(e)},band:function(t,e){return BigInt(t)&BigInt(e)},bor:function(t,e){return BigInt(t)|BigInt(e)},bxor:function(t,e){return BigInt(t)^BigInt(e)},land:function(t,e){return BigInt(t)&&BigInt(e)},lor:function(t,e){return BigInt(t)||BigInt(e)},lnot:function(t){return!BigInt(t)}}),s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function d(t){var e={exports:{}};return t(e,e.exports),e.exports}var u=d((function(t){var e=function(t){var a=1e7,i=9007199254740992,o=g(i),n="0123456789abcdefghijklmnopqrstuvwxyz",r="function"==typeof BigInt;function c(t,e,a,i){return void 0===t?c[0]:void 0!==e&&(10!=+e||a)?K(t,e,a,i):Z(t)}function l(t,e){this.value=t,this.sign=e,this.isSmall=!1}function s(t){this.value=t,this.sign=t<0,this.isSmall=!0}function d(t){this.value=t}function u(t){return-i0?Math.floor(t):Math.ceil(t)}function m(t,e){var i,o,n=t.length,r=e.length,c=new Array(n),l=0,s=a;for(o=0;o=s?1:0,c[o]=i-l*s;for(;o0&&c.push(l),c}function L(t,e){return t.length>=e.length?m(t,e):m(e,t)}function w(t,e){var i,o,n=t.length,r=new Array(n),c=a;for(o=0;o0;)r[o++]=e%c,e=Math.floor(e/c);return r}function A(t,e){var i,o,n=t.length,r=e.length,c=new Array(n),l=0,s=a;for(i=0;i0;)r[o++]=l%c,l=Math.floor(l/c);return r}function C(t,e){for(var a=[];e-- >0;)a.push(0);return a.concat(t)}function F(t,e){var a=Math.max(t.length,e.length);if(a<=30)return y(t,e);a=Math.ceil(a/2);var i=t.slice(a),o=t.slice(0,a),n=e.slice(a),r=e.slice(0,a),c=F(o,r),l=F(i,n),s=F(L(o,i),L(r,n)),d=L(L(c,C(A(A(s,c),l),a)),C(l,2*a));return _(d),d}function x(t,e,i){return new l(t=0;--a)o=(n=1e7*o+t[a])-(i=h(n/e))*e,c[a]=0|i;return[c,0|o]}function B(t,e){var i,o=Z(e);if(r)return[new d(t.value/o.value),new d(t.value%o.value)];var n,u=t.value,m=o.value;if(0===m)throw new Error("Cannot divide by zero");if(t.isSmall)return o.isSmall?[new s(h(u/m)),new s(u%m)]:[c[0],t];if(o.isSmall){if(1===m)return[t,c[0]];if(-1==m)return[t.negate(),c[0]];var L=Math.abs(m);if(L=0;o--){for(i=g-1,L[o+u]!==h&&(i=Math.floor((L[o+u]*g+L[o+u-1])/h)),n=0,r=0,l=w.length,c=0;cs&&(n=(n+1)*g),i=Math.ceil(n/r);do{if(S(c=I(e,i),u)<=0)break;i--}while(i);d.push(i),u=A(u,c)}return d.reverse(),[f(d),f(u)]}(u,m),n=i[0];var y=t.sign!==o.sign,C=i[1],F=t.sign;return"number"==typeof n?(y&&(n=-n),n=new s(n)):n=new l(n,y),"number"==typeof C?(F&&(C=-C),C=new s(C)):C=new l(C,F),[n,C]}function S(t,e){if(t.length!==e.length)return t.length>e.length?1:-1;for(var a=t.length-1;a>=0;a--)if(t[a]!==e[a])return t[a]>e[a]?1:-1;return 0}function G(t){var e=t.abs();return!e.isUnit()&&(!!(e.equals(2)||e.equals(3)||e.equals(5))||!(e.isEven()||e.isDivisibleBy(3)||e.isDivisibleBy(5))&&(!!e.lesser(49)||void 0))}function P(t,a){for(var i,o,n,r=t.prev(),c=r,l=0;c.isEven();)c=c.divide(2),l++;t:for(o=0;o=0?i=A(t,e):(i=A(e,t),a=!a),"number"==typeof(i=f(i))?(a&&(i=-i),new s(i)):new l(i,a)}(a,i,this.sign)},l.prototype.minus=l.prototype.subtract,s.prototype.subtract=function(t){var e=Z(t),a=this.value;if(a<0!==e.sign)return this.add(e.negate());var i=e.value;return e.isSmall?new s(a-i):b(i,Math.abs(a),a>=0)},s.prototype.minus=s.prototype.subtract,d.prototype.subtract=function(t){return new d(this.value-Z(t).value)},d.prototype.minus=d.prototype.subtract,l.prototype.negate=function(){return new l(this.value,!this.sign)},s.prototype.negate=function(){var t=this.sign,e=new s(-this.value);return e.sign=!t,e},d.prototype.negate=function(){return new d(-this.value)},l.prototype.abs=function(){return new l(this.value,!1)},s.prototype.abs=function(){return new s(Math.abs(this.value))},d.prototype.abs=function(){return new d(this.value>=0?this.value:-this.value)},l.prototype.multiply=function(t){var e,i,o,n=Z(t),r=this.value,s=n.value,d=this.sign!==n.sign;if(n.isSmall){if(0===s)return c[0];if(1===s)return this;if(-1===s)return this.negate();if((e=Math.abs(s))0?F(r,s):y(r,s),d)},l.prototype.times=l.prototype.multiply,s.prototype._multiplyBySmall=function(t){return u(t.value*this.value)?new s(t.value*this.value):x(Math.abs(t.value),g(Math.abs(this.value)),this.sign!==t.sign)},l.prototype._multiplyBySmall=function(t){return 0===t.value?c[0]:1===t.value?this:-1===t.value?this.negate():x(Math.abs(t.value),this.value,this.sign!==t.sign)},s.prototype.multiply=function(t){return Z(t)._multiplyBySmall(this)},s.prototype.times=s.prototype.multiply,d.prototype.multiply=function(t){return new d(this.value*Z(t).value)},d.prototype.times=d.prototype.multiply,l.prototype.square=function(){return new l(v(this.value),!1)},s.prototype.square=function(){var t=this.value*this.value;return u(t)?new s(t):new l(v(g(Math.abs(this.value))),!1)},d.prototype.square=function(t){return new d(this.value*this.value)},l.prototype.divmod=function(t){var e=B(this,t);return{quotient:e[0],remainder:e[1]}},d.prototype.divmod=s.prototype.divmod=l.prototype.divmod,l.prototype.divide=function(t){return B(this,t)[0]},d.prototype.over=d.prototype.divide=function(t){return new d(this.value/Z(t).value)},s.prototype.over=s.prototype.divide=l.prototype.over=l.prototype.divide,l.prototype.mod=function(t){return B(this,t)[1]},d.prototype.mod=d.prototype.remainder=function(t){return new d(this.value%Z(t).value)},s.prototype.remainder=s.prototype.mod=l.prototype.remainder=l.prototype.mod,l.prototype.pow=function(t){var e,a,i,o=Z(t),n=this.value,r=o.value;if(0===r)return c[1];if(0===n)return c[0];if(1===n)return c[1];if(-1===n)return o.isEven()?c[1]:c[-1];if(o.sign)return c[0];if(!o.isSmall)throw new Error("The exponent "+o.toString()+" is too large.");if(this.isSmall&&u(e=Math.pow(n,r)))return new s(h(e));for(a=this,i=c[1];!0&r&&(i=i.times(a),--r),0!==r;)r/=2,a=a.square();return i},s.prototype.pow=l.prototype.pow,d.prototype.pow=function(t){var e=Z(t),a=this.value,i=e.value,o=BigInt(0),n=BigInt(1),r=BigInt(2);if(i===o)return c[1];if(a===o)return c[0];if(a===n)return c[1];if(a===BigInt(-1))return e.isEven()?c[1]:c[-1];if(e.isNegative())return new d(o);for(var l=this,s=c[1];(i&n)===n&&(s=s.times(l),--i),i!==o;)i/=r,l=l.square();return s},l.prototype.modPow=function(t,e){if(t=Z(t),(e=Z(e)).isZero())throw new Error("Cannot take modPow with modulus 0");var a=c[1],i=this.mod(e);for(t.isNegative()&&(t=t.multiply(c[-1]),i=i.modInv(e));t.isPositive();){if(i.isZero())return c[0];t.isOdd()&&(a=a.multiply(i).mod(e)),t=t.divide(2),i=i.square().mod(e)}return a},d.prototype.modPow=s.prototype.modPow=l.prototype.modPow,l.prototype.compareAbs=function(t){var e=Z(t),a=this.value,i=e.value;return e.isSmall?1:S(a,i)},s.prototype.compareAbs=function(t){var e=Z(t),a=Math.abs(this.value),i=e.value;return e.isSmall?a===(i=Math.abs(i))?0:a>i?1:-1:-1},d.prototype.compareAbs=function(t){var e=this.value,a=Z(t).value;return(e=e>=0?e:-e)===(a=a>=0?a:-a)?0:e>a?1:-1},l.prototype.compare=function(t){if(t===1/0)return-1;if(t===-1/0)return 1;var e=Z(t),a=this.value,i=e.value;return this.sign!==e.sign?e.sign?1:-1:e.isSmall?this.sign?-1:1:S(a,i)*(this.sign?-1:1)},l.prototype.compareTo=l.prototype.compare,s.prototype.compare=function(t){if(t===1/0)return-1;if(t===-1/0)return 1;var e=Z(t),a=this.value,i=e.value;return e.isSmall?a==i?0:a>i?1:-1:a<0!==e.sign?a<0?-1:1:a<0?1:-1},s.prototype.compareTo=s.prototype.compare,d.prototype.compare=function(t){if(t===1/0)return-1;if(t===-1/0)return 1;var e=this.value,a=Z(t).value;return e===a?0:e>a?1:-1},d.prototype.compareTo=d.prototype.compare,l.prototype.equals=function(t){return 0===this.compare(t)},d.prototype.eq=d.prototype.equals=s.prototype.eq=s.prototype.equals=l.prototype.eq=l.prototype.equals,l.prototype.notEquals=function(t){return 0!==this.compare(t)},d.prototype.neq=d.prototype.notEquals=s.prototype.neq=s.prototype.notEquals=l.prototype.neq=l.prototype.notEquals,l.prototype.greater=function(t){return this.compare(t)>0},d.prototype.gt=d.prototype.greater=s.prototype.gt=s.prototype.greater=l.prototype.gt=l.prototype.greater,l.prototype.lesser=function(t){return this.compare(t)<0},d.prototype.lt=d.prototype.lesser=s.prototype.lt=s.prototype.lesser=l.prototype.lt=l.prototype.lesser,l.prototype.greaterOrEquals=function(t){return this.compare(t)>=0},d.prototype.geq=d.prototype.greaterOrEquals=s.prototype.geq=s.prototype.greaterOrEquals=l.prototype.geq=l.prototype.greaterOrEquals,l.prototype.lesserOrEquals=function(t){return this.compare(t)<=0},d.prototype.leq=d.prototype.lesserOrEquals=s.prototype.leq=s.prototype.lesserOrEquals=l.prototype.leq=l.prototype.lesserOrEquals,l.prototype.isEven=function(){return 0==(1&this.value[0])},s.prototype.isEven=function(){return 0==(1&this.value)},d.prototype.isEven=function(){return(this.value&BigInt(1))===BigInt(0)},l.prototype.isOdd=function(){return 1==(1&this.value[0])},s.prototype.isOdd=function(){return 1==(1&this.value)},d.prototype.isOdd=function(){return(this.value&BigInt(1))===BigInt(1)},l.prototype.isPositive=function(){return!this.sign},s.prototype.isPositive=function(){return this.value>0},d.prototype.isPositive=s.prototype.isPositive,l.prototype.isNegative=function(){return this.sign},s.prototype.isNegative=function(){return this.value<0},d.prototype.isNegative=s.prototype.isNegative,l.prototype.isUnit=function(){return!1},s.prototype.isUnit=function(){return 1===Math.abs(this.value)},d.prototype.isUnit=function(){return this.abs().value===BigInt(1)},l.prototype.isZero=function(){return!1},s.prototype.isZero=function(){return 0===this.value},d.prototype.isZero=function(){return this.value===BigInt(0)},l.prototype.isDivisibleBy=function(t){var e=Z(t);return!e.isZero()&&(!!e.isUnit()||(0===e.compareAbs(2)?this.isEven():this.mod(e).isZero()))},d.prototype.isDivisibleBy=s.prototype.isDivisibleBy=l.prototype.isDivisibleBy,l.prototype.isPrime=function(a){var i=G(this);if(i!==t)return i;var o=this.abs(),n=o.bitLength();if(n<=64)return P(o,[2,3,5,7,11,13,17,19,23,29,31,37]);for(var r=Math.log(2)*n.toJSNumber(),c=Math.ceil(!0===a?2*Math.pow(r,2):r),l=[],s=0;s-i?new s(t-1):new l(o,!0)},d.prototype.prev=function(){return new d(this.value-BigInt(1))};for(var O=[1];2*O[O.length-1]<=a;)O.push(2*O[O.length-1]);var U=O.length,z=O[U-1];function q(t){return Math.abs(t)<=a}function Q(t,a,i){a=Z(a);for(var o=t.isNegative(),n=a.isNegative(),r=o?t.not():t,c=n?a.not():a,l=0,s=0,d=null,u=null,g=[];!r.isZero()||!c.isZero();)l=(d=B(r,z))[1].toJSNumber(),o&&(l=z-1-l),s=(u=B(c,z))[1].toJSNumber(),n&&(s=z-1-s),r=d[0],c=u[0],g.push(i(l,s));for(var f=0!==i(o?1:0,n?1:0)?e(-1):e(0),_=g.length-1;_>=0;_-=1)f=f.multiply(z).add(e(g[_]));return f}l.prototype.shiftLeft=function(t){var e=Z(t).toJSNumber();if(!q(e))throw new Error(String(e)+" is too large for shifting.");if(e<0)return this.shiftRight(-e);var a=this;if(a.isZero())return a;for(;e>=U;)a=a.multiply(z),e-=U-1;return a.multiply(O[e])},d.prototype.shiftLeft=s.prototype.shiftLeft=l.prototype.shiftLeft,l.prototype.shiftRight=function(t){var e,a=Z(t).toJSNumber();if(!q(a))throw new Error(String(a)+" is too large for shifting.");if(a<0)return this.shiftLeft(-a);for(var i=this;a>=U;){if(i.isZero()||i.isNegative()&&i.isUnit())return i;i=(e=B(i,z))[1].isNegative()?e[0].prev():e[0],a-=U-1}return(e=B(i,O[a]))[1].isNegative()?e[0].prev():e[0]},d.prototype.shiftRight=s.prototype.shiftRight=l.prototype.shiftRight,l.prototype.not=function(){return this.negate().prev()},d.prototype.not=s.prototype.not=l.prototype.not,l.prototype.and=function(t){return Q(this,t,(function(t,e){return t&e}))},d.prototype.and=s.prototype.and=l.prototype.and,l.prototype.or=function(t){return Q(this,t,(function(t,e){return t|e}))},d.prototype.or=s.prototype.or=l.prototype.or,l.prototype.xor=function(t){return Q(this,t,(function(t,e){return t^e}))},d.prototype.xor=s.prototype.xor=l.prototype.xor;var M=1<<30;function k(t){var e=t.value,i="number"==typeof e?e|M:"bigint"==typeof e?e|BigInt(M):e[0]+e[1]*a|1073758208;return i&-i}function R(t,a){if(a.compareTo(t)<=0){var i=R(t,a.square(a)),o=i.p,n=i.e,r=o.multiply(a);return r.compareTo(t)<=0?{p:r,e:2*n+1}:{p:o,e:2*n}}return{p:e(1),e:0}}function N(t,e){return t=Z(t),e=Z(e),t.greater(e)?t:e}function T(t,e){return t=Z(t),e=Z(e),t.lesser(e)?t:e}function D(t,e){if(t=Z(t).abs(),e=Z(e).abs(),t.equals(e))return t;if(t.isZero())return e;if(e.isZero())return t;for(var a,i,o=c[1];t.isEven()&&e.isEven();)a=T(k(t),k(e)),t=t.divide(a),e=e.divide(a),o=o.multiply(a);for(;t.isEven();)t=t.divide(k(t));do{for(;e.isEven();)e=e.divide(k(e));t.greater(e)&&(i=e,e=t,t=i),e=e.subtract(t)}while(!e.isZero());return o.isUnit()?t:t.multiply(o)}l.prototype.bitLength=function(){var t=this;return t.compareTo(e(0))<0&&(t=t.negate().subtract(e(1))),0===t.compareTo(e(0))?e(0):e(R(t,e(2)).e).add(e(1))},d.prototype.bitLength=s.prototype.bitLength=l.prototype.bitLength;var K=function(t,e,a,i){a=a||n,t=String(t),i||(t=t.toLowerCase(),a=a.toLowerCase());var o,r=t.length,c=Math.abs(e),l={};for(o=0;o=c)){if("1"===u&&1===c)continue;throw new Error(u+" is not a valid digit in base "+e+".")}}e=Z(e);var s=[],d="-"===t[0];for(o=d?1:0;o"!==t[o]&&o=0;i--)o=o.add(t[i].times(n)),n=n.times(e);return a?o.negate():o}function j(t,a){if((a=e(a)).isZero()){if(t.isZero())return{value:[0],isNegative:!1};throw new Error("Cannot convert nonzero numbers to base 0.")}if(a.equals(-1)){if(t.isZero())return{value:[0],isNegative:!1};if(t.isNegative())return{value:[].concat.apply([],Array.apply(null,Array(-t.toJSNumber())).map(Array.prototype.valueOf,[1,0])),isNegative:!1};var i=Array.apply(null,Array(t.toJSNumber()-1)).map(Array.prototype.valueOf,[0,1]);return i.unshift([1]),{value:[].concat.apply([],i),isNegative:!1}}var o=!1;if(t.isNegative()&&a.isPositive()&&(o=!0,t=t.abs()),a.isUnit())return t.isZero()?{value:[0],isNegative:!1}:{value:Array.apply(null,Array(t.toJSNumber())).map(Number.prototype.valueOf,1),isNegative:o};for(var n,r=[],c=t;c.isNegative()||c.compareAbs(a)>=0;){n=c.divmod(a),c=n.quotient;var l=n.remainder;l.isNegative()&&(l=a.minus(l).abs(),c=c.next()),r.push(l.toJSNumber())}return r.push(c.toJSNumber()),{value:r.reverse(),isNegative:o}}function H(t,e,a){var i=j(t,e);return(i.isNegative?"-":"")+i.value.map((function(t){return function(t,e){return t<(e=e||n).length?e[t]:"<"+t+">"}(t,a)})).join("")}function $(t){if(u(+t)){var e=+t;if(e===h(e))return r?new d(BigInt(e)):new s(e);throw new Error("Invalid integer: "+t)}var a="-"===t[0];a&&(t=t.slice(1));var i=t.split(/e/i);if(i.length>2)throw new Error("Invalid integer: "+i.join("e"));if(2===i.length){var o=i[1];if("+"===o[0]&&(o=o.slice(1)),(o=+o)!==h(o)||!u(o))throw new Error("Invalid integer: "+o+" is not a valid exponent.");var n=i[0],c=n.indexOf(".");if(c>=0&&(o-=n.length-c-1,n=n.slice(0,c)+n.slice(c+1)),o<0)throw new Error("Cannot include negative exponent part for integers");t=n+=new Array(o+1).join("0")}if(!/^([0-9][0-9]*)$/.test(t))throw new Error("Invalid integer: "+t);if(r)return new d(BigInt(a?"-"+t:t));for(var g=[],f=t.length,p=f-7;f>0;)g.push(+t.slice(p,f)),(p-=7)<0&&(p=0),f-=7;return _(g),new l(g,a)}function Z(t){return"number"==typeof t?function(t){if(r)return new d(BigInt(t));if(u(t)){if(t!==h(t))throw new Error(t+" is not an integer.");return new s(t)}return $(t.toString())}(t):"string"==typeof t?$(t):"bigint"==typeof t?new d(t):t}l.prototype.toArray=function(t){return j(this,t)},s.prototype.toArray=function(t){return j(this,t)},d.prototype.toArray=function(t){return j(this,t)},l.prototype.toString=function(e,a){if(e===t&&(e=10),10!==e)return H(this,e,a);for(var i,o=this.value,n=o.length,r=String(o[--n]);--n>=0;)i=String(o[n]),r+="0000000".slice(i.length)+i;return(this.sign?"-":"")+r},s.prototype.toString=function(e,a){return e===t&&(e=10),10!=e?H(this,e,a):String(this.value)},d.prototype.toString=s.prototype.toString,d.prototype.toJSON=l.prototype.toJSON=s.prototype.toJSON=function(){return this.toString()},l.prototype.valueOf=function(){return parseInt(this.toString(),10)},l.prototype.toJSNumber=l.prototype.valueOf,s.prototype.valueOf=function(){return this.value},s.prototype.toJSNumber=s.prototype.valueOf,d.prototype.valueOf=d.prototype.toJSNumber=function(){return parseInt(this.toString(),10)};for(var Y=0;Y<1e3;Y++)c[Y]=Z(Y),Y>0&&(c[-Y]=Z(-Y));return c.one=c[1],c.zero=c[0],c.minusOne=c[-1],c.max=N,c.min=T,c.gcd=D,c.lcm=function(t,e){return t=Z(t).abs(),e=Z(e).abs(),t.divide(D(t,e)).multiply(e)},c.isInstance=function(t){return t instanceof l||t instanceof s||t instanceof d},c.randBetween=function(t,e,i){t=Z(t),e=Z(e);var o=i||Math.random,n=T(t,e),r=N(t,e).subtract(n).add(1);if(r.isSmall)return n.add(Math.floor(o()*r));for(var l=j(r,a).value,s=[],d=!0,u=0;u>5);for(let t=0;t>5);for(let t=0;to[o.length-e-1]=t.toString(16).padStart(8,"0"))),A.fromString(o.join(""),16)},A.fromRprBE=function(t,e,a){a=a||t.byteLength,e=e||0;const i=new DataView(t.buffer,t.byteOffset+e,a),o=new Array(a/4);for(let t=0;t>=1;return a}function pt(t,e,a){if(U(a))return t.one;const i=N(a);if(0==i.legth)return t.one;let o=e;for(let a=i.length-2;a>=0;a--)o=t.square(o),i[a]&&(o=t.mul(o,e));return o}function ht(t){if(t.m%2==1)if(tt(X(t.p,4),1))if(tt(X(t.p,8),1))if(tt(X(t.p,16),1))!function(t){t.sqrt_q=Z(t.p,t.m),t.sqrt_s=0,t.sqrt_t=V(t.sqrt_q,1);for(;!k(t.sqrt_t);)t.sqrt_s=t.sqrt_s+1,t.sqrt_t=W(t.sqrt_t,2);let e=t.one;for(;t.eq(e,t.one);){const a=t.random();t.sqrt_z=t.pow(a,t.sqrt_t),e=t.pow(t.sqrt_z,2**(t.sqrt_s-1))}t.sqrt_tm1d2=W(V(t.sqrt_t,1),2),t.sqrt=function(t){const e=this;if(e.isZero(t))return e.zero;let a=e.pow(t,e.sqrt_tm1d2);const i=e.pow(e.mul(e.square(a),t),2**(e.sqrt_s-1));if(e.eq(i,e.negone))return null;let o=e.sqrt_s,n=e.mul(t,a),r=e.mul(n,a),c=e.sqrt_z;for(;!e.eq(r,e.one);){let t=e.square(r),i=1;for(;!e.eq(t,e.one);)t=e.square(t),i++;a=c;for(let t=0;t>>0,t[o]=(t[o]^t[e])>>>0,t[o]=(t[o]<<16|t[o]>>>16&65535)>>>0,t[i]=t[i]+t[o]>>>0,t[a]=(t[a]^t[i])>>>0,t[a]=(t[a]<<12|t[a]>>>20&4095)>>>0,t[e]=t[e]+t[a]>>>0,t[o]=(t[o]^t[e])>>>0,t[o]=(t[o]<<8|t[o]>>>24&255)>>>0,t[i]=t[i]+t[o]>>>0,t[a]=(t[a]^t[i])>>>0,t[a]=(t[a]<<7|t[a]>>>25&127)>>>0}class Lt{constructor(t){t=t||[0,0,0,0,0,0,0,0],this.state=[1634760805,857760878,2036477234,1797285236,t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],0,0,0,0],this.idx=16,this.buff=new Array(16)}nextU32(){return 16==this.idx&&this.update(),this.buff[this.idx++]}nextU64(){return K(H(this.nextU32(),4294967296),this.nextU32())}nextBool(){return 1==(1&this.nextU32())}update(){for(let t=0;t<16;t++)this.buff[t]=this.state[t];for(let e=0;e<10;e++)mt(t=this.buff,0,4,8,12),mt(t,1,5,9,13),mt(t,2,6,10,14),mt(t,3,7,11,15),mt(t,0,5,10,15),mt(t,1,6,11,12),mt(t,2,7,8,13),mt(t,3,4,9,14);var t;for(let t=0;t<16;t++)this.buff[t]=this.buff[t]+this.state[t]>>>0;this.idx=0,this.state[12]=this.state[12]+1>>>0,0==this.state[12]&&(this.state[13]=this.state[13]+1>>>0,0==this.state[13]&&(this.state[14]=this.state[14]+1>>>0,0==this.state[14]&&(this.state[15]=this.state[15]+1>>>0)))}}var wt={};function At(t){let e=new Uint8Array(t);if(void 0!==globalThis.crypto)globalThis.crypto.getRandomValues(e);else for(let a=0;a>>0;return e}let bt=null;function yt(){return bt||(bt=new Lt(function(){const t=At(32),e=new Uint32Array(t.buffer),a=[];for(let t=0;t<8;t++)a.push(e[t]);return a}()),bt)}class It{constructor(t){this.type="F1",this.one=BigInt(1),this.zero=BigInt(0),this.p=BigInt(t),this.m=1,this.negone=this.p-this.one,this.two=BigInt(2),this.half=this.p>>this.one,this.bitLength=P(this.p),this.mask=(this.one<>this.one;this.nqr=this.two;let a=this.pow(this.nqr,e);for(;!this.eq(a,this.negone);)this.nqr=this.nqr+this.one,a=this.pow(this.nqr,e);for(this.s=0,this.t=this.negone;(this.t&this.one)==this.zero;)this.s=this.s+1,this.t=this.t>>this.one;this.nqr_to_t=this.pow(this.nqr,this.t),ht(this)}e(t,e){let a;if(e?16==e&&(a=BigInt("0x"+t)):a=BigInt(t),a<0){let t=-a;return t>=this.p&&(t%=this.p),this.p-t}return a>=this.p?a%this.p:a}add(t,e){const a=t+e;return a>=this.p?a-this.p:a}sub(t,e){return t>=e?t-e:this.p-e+t}neg(t){return t?this.p-t:t}mul(t,e){return t*e%this.p}mulScalar(t,e){return t*this.e(e)%this.p}square(t){return t*t%this.p}eq(t,e){return t==e}neq(t,e){return t!=e}lt(t,e){return(t>this.half?t-this.p:t)<(e>this.half?e-this.p:e)}gt(t,e){return(t>this.half?t-this.p:t)>(e>this.half?e-this.p:e)}leq(t,e){return(t>this.half?t-this.p:t)<=(e>this.half?e-this.p:e)}geq(t,e){return(t>this.half?t-this.p:t)>=(e>this.half?e-this.p:e)}div(t,e){return this.mul(t,this.inv(e))}idiv(t,e){if(!e)throw new Error("Division by zero");return t/e}inv(t){if(!t)throw new Error("Division by zero");let e=this.zero,a=this.p,i=this.one,o=t%this.p;for(;o;){let t=a/o;[e,i]=[i,e-t*i],[a,o]=[o,a-t*o]}return e=this.p?a-this.p:a}bor(t,e){const a=(t|e)&this.mask;return a>=this.p?a-this.p:a}bxor(t,e){const a=(t^e)&this.mask;return a>=this.p?a-this.p:a}bnot(t){const e=t^this.mask;return e>=this.p?e-this.p:e}shl(t,e){if(Number(e)=this.p?a-this.p:a}{const a=this.p-e;return Number(a)>a:this.zero}}shr(t,e){if(Number(e)>e;{const a=this.p-e;if(Number(a)=this.p?e-this.p:e}return 0}}land(t,e){return t&&e?this.one:this.zero}lor(t,e){return t||e?this.one:this.zero}lnot(t){return t?this.zero:this.one}sqrt_old(t){if(t==this.zero)return this.zero;if(this.pow(t,this.negone>>this.one)!=this.one)return null;let e=this.s,a=this.nqr_to_t,i=this.pow(t,this.t),o=this.pow(t,this.add(this.t,this.one)>>this.one);for(;i!=this.one;){let t=this.square(i),n=1;for(;t!=this.one;)n++,t=this.square(t);let r=a;for(let t=0;tthis.p>>this.one&&(o=this.neg(o)),o}normalize(t,e){if((t=BigInt(t,e))<0){let e=-t;return e>=this.p&&(e%=this.p),this.p-e}return t>=this.p?t%this.p:t}random(){const t=2*this.bitLength/8;let e=this.zero;for(let a=0;athis.half){a="-"+(this.p-t).toString(e)}else a=t.toString(e);return a}isZero(t){return t==this.zero}fromRng(t){let e;do{e=this.zero;for(let a=0;a=this.p);return e=e*this.Ri%this.p,e}}class Ct{constructor(t){this.type="F1",this.one=u.one,this.zero=u.zero,this.p=u(t),this.m=1,this.negone=this.p.minus(u.one),this.two=u(2),this.half=this.p.shiftRight(1),this.bitLength=this.p.bitLength(),this.mask=u.one.shiftLeft(this.bitLength).minus(u.one),this.n64=Math.floor((this.bitLength-1)/64)+1,this.n32=2*this.n64,this.n8=8*this.n64,this.R=u.one.shiftLeft(64*this.n64),this.Ri=this.inv(this.R);const e=this.negone.shiftRight(this.one);this.nqr=this.two;let a=this.pow(this.nqr,e);for(;!a.equals(this.negone);)this.nqr=this.nqr.add(this.one),a=this.pow(this.nqr,e);for(this.s=this.zero,this.t=this.negone;!this.t.isOdd();)this.s=this.s.add(this.one),this.t=this.t.shiftRight(this.one);this.nqr_to_t=this.pow(this.nqr,this.t),ht(this)}e(t,e){const a=u(t,e);return this.normalize(a)}add(t,e){let a=t.add(e);return a.geq(this.p)&&(a=a.minus(this.p)),a}sub(t,e){return t.geq(e)?t.minus(e):this.p.minus(e.minus(t))}neg(t){return t.isZero()?t:this.p.minus(t)}mul(t,e){return t.times(e).mod(this.p)}mulScalar(t,e){return t.times(u(e)).mod(this.p)}square(t){return t.square().mod(this.p)}eq(t,e){return t.eq(e)}neq(t,e){return t.neq(e)}lt(t,e){const a=t.gt(this.half)?t.minus(this.p):t,i=e.gt(this.half)?e.minus(this.p):e;return a.lt(i)}gt(t,e){const a=t.gt(this.half)?t.minus(this.p):t,i=e.gt(this.half)?e.minus(this.p):e;return a.gt(i)}leq(t,e){const a=t.gt(this.half)?t.minus(this.p):t,i=e.gt(this.half)?e.minus(this.p):e;return a.leq(i)}geq(t,e){const a=t.gt(this.half)?t.minus(this.p):t,i=e.gt(this.half)?e.minus(this.p):e;return a.geq(i)}div(t,e){if(e.isZero())throw new Error("Division by zero");return t.times(e.modInv(this.p)).mod(this.p)}idiv(t,e){if(e.isZero())throw new Error("Division by zero");return t.divide(e)}inv(t){if(t.isZero())throw new Error("Division by zero");return t.modInv(this.p)}mod(t,e){return t.mod(e)}pow(t,e){return t.modPow(e,this.p)}exp(t,e){return t.modPow(e,this.p)}band(t,e){return t.and(e).and(this.mask).mod(this.p)}bor(t,e){return t.or(e).and(this.mask).mod(this.p)}bxor(t,e){return t.xor(e).and(this.mask).mod(this.p)}bnot(t){return t.xor(this.mask).mod(this.p)}shl(t,e){if(e.lt(this.bitLength))return t.shiftLeft(e).and(this.mask).mod(this.p);{const a=this.p.minus(e);return a.lt(this.bitLength)?this.shr(t,a):u.zero}}shr(t,e){if(e.lt(this.bitLength))return t.shiftRight(e);{const a=this.p.minus(e);return a.lt(this.bitLength)?this.shl(t,a):u.zero}}land(t,e){return t.isZero()||e.isZero()?u.zero:u.one}lor(t,e){return t.isZero()&&e.isZero()?u.zero:u.one}lnot(t){return t.isZero()?u.one:u.zero}sqrt_old(t){if(t.equals(this.zero))return this.zero;if(!this.pow(t,this.negone.shiftRight(this.one)).equals(this.one))return null;let e=parseInt(this.s),a=this.nqr_to_t,i=this.pow(t,this.t),o=this.pow(t,this.add(this.t,this.one).shiftRight(this.one));for(;!i.equals(this.one);){let t=this.square(i),n=1;for(;!t.equals(this.one);)n++,t=this.square(t);let r=a;for(let t=0;t>1&&i>1,t>>1)))),e.addCode(a.setLocal(l,a.i64_add(a.getLocal(l),a.i64_shr_u(a.getLocal(c),a.i64_const(32)))))),t>0&&(e.addCode(a.setLocal(c,a.i64_add(a.i64_and(a.getLocal(c),a.i64_const(4294967295)),a.i64_and(a.getLocal(s),a.i64_const(4294967295))))),e.addCode(a.setLocal(l,a.i64_add(a.i64_add(a.getLocal(l),a.i64_shr_u(a.getLocal(c),a.i64_const(32))),a.getLocal(d))))),e.addCode(a.i64_store32(a.getLocal("r"),4*t,a.getLocal(c))),e.addCode(a.setLocal(s,a.getLocal(l)),a.setLocal(d,a.i64_shr_u(a.getLocal(s),a.i64_const(32))))}e.addCode(a.i64_store32(a.getLocal("r"),4*o*2-4,a.getLocal(s)))}(),function(){const e=t.addFunction(i+"_squareOld");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(i+"_mul",a.getLocal("x"),a.getLocal("x"),a.getLocal("r")))}(),function(){!function(){const e=t.addFunction(i+"__mul1");e.addParam("px","i32"),e.addParam("y","i64"),e.addParam("pr","i32"),e.addLocal("c","i64");const a=e.getCodeBuilder();e.addCode(a.setLocal("c",a.i64_mul(a.i64_load32_u(a.getLocal("px"),0,0),a.getLocal("y")))),e.addCode(a.i64_store32(a.getLocal("pr"),0,0,a.getLocal("c")));for(let t=1;t>e)),[...l.setLocal("b",l.i32_sub(l.getLocal("b"),l.i32_const(128>>e))),...l.call(i,l.getLocal("r"),s,l.getLocal("r"))]));return t}(),l.br_if(1,l.i32_eqz(l.getLocal("i"))),l.br(0))))},Gt=function(t,e){const a=8*t.modules[e].n64,i=t.addFunction(e+"_batchInverse");i.addParam("pIn","i32"),i.addParam("inStep","i32"),i.addParam("n","i32"),i.addParam("pOut","i32"),i.addParam("outStep","i32"),i.addLocal("itAux","i32"),i.addLocal("itIn","i32"),i.addLocal("itOut","i32"),i.addLocal("i","i32");const o=i.getCodeBuilder(),n=o.i32_const(t.alloc(a));i.addCode(o.setLocal("itAux",o.i32_load(o.i32_const(0))),o.i32_store(o.i32_const(0),o.i32_add(o.getLocal("itAux"),o.i32_mul(o.i32_add(o.getLocal("n"),o.i32_const(1)),o.i32_const(a))))),i.addCode(o.call(e+"_one",o.getLocal("itAux")),o.setLocal("itIn",o.getLocal("pIn")),o.setLocal("itAux",o.i32_add(o.getLocal("itAux"),o.i32_const(a))),o.setLocal("i",o.i32_const(0)),o.block(o.loop(o.br_if(1,o.i32_eq(o.getLocal("i"),o.getLocal("n"))),o.if(o.call(e+"_isZero",o.getLocal("itIn")),o.call(e+"_copy",o.i32_sub(o.getLocal("itAux"),o.i32_const(a)),o.getLocal("itAux")),o.call(e+"_mul",o.getLocal("itIn"),o.i32_sub(o.getLocal("itAux"),o.i32_const(a)),o.getLocal("itAux"))),o.setLocal("itIn",o.i32_add(o.getLocal("itIn"),o.getLocal("inStep"))),o.setLocal("itAux",o.i32_add(o.getLocal("itAux"),o.i32_const(a))),o.setLocal("i",o.i32_add(o.getLocal("i"),o.i32_const(1))),o.br(0))),o.setLocal("itIn",o.i32_sub(o.getLocal("itIn"),o.getLocal("inStep"))),o.setLocal("itAux",o.i32_sub(o.getLocal("itAux"),o.i32_const(a))),o.setLocal("itOut",o.i32_add(o.getLocal("pOut"),o.i32_mul(o.i32_sub(o.getLocal("n"),o.i32_const(1)),o.getLocal("outStep")))),o.call(e+"_inverse",o.getLocal("itAux"),o.getLocal("itAux")),o.block(o.loop(o.br_if(1,o.i32_eqz(o.getLocal("i"))),o.if(o.call(e+"_isZero",o.getLocal("itIn")),[...o.call(e+"_copy",o.getLocal("itAux"),o.i32_sub(o.getLocal("itAux"),o.i32_const(a))),...o.call(e+"_zero",o.getLocal("itOut"))],[...o.call(e+"_copy",o.i32_sub(o.getLocal("itAux"),o.i32_const(a)),n),...o.call(e+"_mul",o.getLocal("itAux"),o.getLocal("itIn"),o.i32_sub(o.getLocal("itAux"),o.i32_const(a))),...o.call(e+"_mul",o.getLocal("itAux"),n,o.getLocal("itOut"))]),o.setLocal("itIn",o.i32_sub(o.getLocal("itIn"),o.getLocal("inStep"))),o.setLocal("itOut",o.i32_sub(o.getLocal("itOut"),o.getLocal("outStep"))),o.setLocal("itAux",o.i32_sub(o.getLocal("itAux"),o.i32_const(a))),o.setLocal("i",o.i32_sub(o.getLocal("i"),o.i32_const(1))),o.br(0)))),i.addCode(o.i32_store(o.i32_const(0),o.getLocal("itAux")))};var Pt=function(t,e,a,i,o,n){void 0===n&&(n=i=r&&e.addCode(a.i64_store32(a.getLocal("r"),4*(t-r),a.getLocal(p))),[p,h]=[h,p],e.addCode(a.setLocal(h,a.i64_shr_u(a.getLocal(p),a.i64_const(32))))}e.addCode(a.i64_store32(a.getLocal("r"),4*r-4,a.getLocal(p))),e.addCode(a.if(a.i32_wrap_i64(a.getLocal(h)),a.drop(a.call(s+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))),a.if(a.call(s+"_gte",a.getLocal("r"),a.i32_const(d)),a.drop(a.call(s+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))))))}(),function(){const e=t.addFunction(l+"_square");e.addParam("x","i32"),e.addParam("r","i32"),e.addLocal("c0","i64"),e.addLocal("c1","i64"),e.addLocal("c0_old","i64"),e.addLocal("c1_old","i64"),e.addLocal("np32","i64");for(let t=0;t>1&&i>1,t>>1)))),e.addCode(a.setLocal(p,a.i64_add(a.getLocal(p),a.i64_shr_u(a.getLocal(_),a.i64_const(32)))))),t>0&&(e.addCode(a.setLocal(_,a.i64_add(a.i64_and(a.getLocal(_),a.i64_const(4294967295)),a.i64_and(a.getLocal(h),a.i64_const(4294967295))))),e.addCode(a.setLocal(p,a.i64_add(a.i64_add(a.getLocal(p),a.i64_shr_u(a.getLocal(_),a.i64_const(32))),a.getLocal(m)))));for(let i=Math.max(1,t-r+1);i<=t&&i=r&&e.addCode(a.i64_store32(a.getLocal("r"),4*(t-r),a.getLocal(_))),e.addCode(a.setLocal(h,a.getLocal(p)),a.setLocal(m,a.i64_shr_u(a.getLocal(h),a.i64_const(32))))}e.addCode(a.i64_store32(a.getLocal("r"),4*r-4,a.getLocal(h))),e.addCode(a.if(a.i32_wrap_i64(a.getLocal(m)),a.drop(a.call(s+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))),a.if(a.call(s+"_gte",a.getLocal("r"),a.i32_const(d)),a.drop(a.call(s+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))))))}(),function(){const e=t.addFunction(l+"_squareOld");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(l+"_mul",a.getLocal("x"),a.getLocal("x"),a.getLocal("r")))}(),function(){const e=t.addFunction(l+"_toMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(l+"_mul",a.getLocal("x"),a.i32_const(g),a.getLocal("r")))}(),function(){const e=t.alloc(2*c),a=t.addFunction(l+"_fromMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const i=a.getCodeBuilder();a.addCode(i.call(s+"_copy",i.getLocal("x"),i.i32_const(e))),a.addCode(i.call(s+"_zero",i.i32_const(e+c))),a.addCode(i.call(l+"_mReduct",i.i32_const(e),i.getLocal("r")))}(),function(){const e=t.addFunction(l+"_isNegative");e.addParam("x","i32"),e.setReturnType("i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(c));e.addCode(a.call(l+"_fromMontgomery",a.getLocal("x"),i),a.call(s+"_gte",i,a.i32_const(w)))}(),function(){const e=t.addFunction(l+"_sign");e.addParam("x","i32"),e.setReturnType("i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(c));e.addCode(a.if(a.call(s+"_isZero",a.getLocal("x")),a.ret(a.i32_const(0))),a.call(l+"_fromMontgomery",a.getLocal("x"),i),a.if(a.call(s+"_gte",i,a.i32_const(w)),a.ret(a.i32_const(-1))),a.ret(a.i32_const(1)))}(),function(){const e=t.addFunction(l+"_inverse");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(l+"_fromMontgomery",a.getLocal("x"),a.getLocal("r"))),e.addCode(a.call(s+"_inverseMod",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))),e.addCode(a.call(l+"_toMontgomery",a.getLocal("r"),a.getLocal("r")))}(),function(){const e=t.addFunction(l+"_one");e.addParam("pr","i32");const a=e.getCodeBuilder();e.addCode(a.call(s+"_copy",a.i32_const(f),a.getLocal("pr")))}(),function(){const e=t.addFunction(l+"_load");e.addParam("scalar","i32"),e.addParam("scalarLen","i32"),e.addParam("r","i32"),e.addLocal("p","i32"),e.addLocal("l","i32"),e.addLocal("i","i32"),e.addLocal("j","i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(c)),o=t.alloc(c),n=a.i32_const(o);e.addCode(a.call(s+"_zero",a.getLocal("r")),a.setLocal("i",a.i32_const(c)),a.setLocal("p",a.getLocal("scalar")),a.block(a.loop(a.br_if(1,a.i32_gt_u(a.getLocal("i"),a.getLocal("scalarLen"))),a.if(a.i32_eq(a.getLocal("i"),a.i32_const(c)),a.call(l+"_one",i),a.call(l+"_mul",i,a.i32_const(g),i)),a.call(l+"_mul",a.getLocal("p"),i,n),a.call(l+"_add",a.getLocal("r"),n,a.getLocal("r")),a.setLocal("p",a.i32_add(a.getLocal("p"),a.i32_const(c))),a.setLocal("i",a.i32_add(a.getLocal("i"),a.i32_const(c))),a.br(0))),a.setLocal("l",a.i32_rem_u(a.getLocal("scalarLen"),a.i32_const(c))),a.if(a.i32_eqz(a.getLocal("l")),a.ret([])),a.call(s+"_zero",n),a.setLocal("j",a.i32_const(0)),a.block(a.loop(a.br_if(1,a.i32_eq(a.getLocal("j"),a.getLocal("l"))),a.i32_store8(a.getLocal("j"),o,a.i32_load8_u(a.getLocal("p"))),a.setLocal("p",a.i32_add(a.getLocal("p"),a.i32_const(1))),a.setLocal("j",a.i32_add(a.getLocal("j"),a.i32_const(1))),a.br(0))),a.if(a.i32_eq(a.getLocal("i"),a.i32_const(c)),a.call(l+"_one",i),a.call(l+"_mul",i,a.i32_const(g),i)),a.call(l+"_mul",n,i,n),a.call(l+"_add",a.getLocal("r"),n,a.getLocal("r")))}(),function(){const e=t.addFunction(l+"_timesScalar");e.addParam("x","i32"),e.addParam("scalar","i32"),e.addParam("scalarLen","i32"),e.addParam("r","i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(c));e.addCode(a.call(l+"_load",a.getLocal("scalar"),a.getLocal("scalarLen"),i),a.call(l+"_toMontgomery",i,i),a.call(l+"_mul",a.getLocal("x"),i,a.getLocal("r")))}(),Gt(t,l),Pt(t,l+"_batchToMontgomery",l+"_toMontgomery",c,c),Pt(t,l+"_batchFromMontgomery",l+"_fromMontgomery",c,c),Pt(t,l+"_batchNeg",l+"_neg",c,c),Ot(t,l+"_batchAdd",l+"_add",c,c),Ot(t,l+"_batchSub",l+"_sub",c,c),Ot(t,l+"_batchMul",l+"_mul",c,c),t.exportFunction(l+"_add"),t.exportFunction(l+"_sub"),t.exportFunction(l+"_neg"),t.exportFunction(l+"_isNegative"),t.exportFunction(l+"_isOne"),t.exportFunction(l+"_sign"),t.exportFunction(l+"_mReduct"),t.exportFunction(l+"_mul"),t.exportFunction(l+"_square"),t.exportFunction(l+"_squareOld"),t.exportFunction(l+"_fromMontgomery"),t.exportFunction(l+"_toMontgomery"),t.exportFunction(l+"_inverse"),t.exportFunction(l+"_one"),t.exportFunction(l+"_load"),t.exportFunction(l+"_timesScalar"),St(t,l+"_exp",c,l+"_mul",l+"_square",s+"_copy",l+"_one"),t.exportFunction(l+"_exp"),t.exportFunction(l+"_batchInverse"),o.isPrime()&&(!function(){const e=t.addFunction(l+"_sqrt");e.addParam("n","i32"),e.addParam("r","i32"),e.addLocal("m","i32"),e.addLocal("i","i32"),e.addLocal("j","i32");const a=e.getCodeBuilder(),i=a.i32_const(f),o=a.i32_const(t.alloc(c)),n=a.i32_const(t.alloc(c)),r=a.i32_const(t.alloc(c)),s=a.i32_const(t.alloc(c)),d=a.i32_const(t.alloc(c));e.addCode(a.if(a.call(l+"_isZero",a.getLocal("n")),a.ret(a.call(l+"_zero",a.getLocal("r")))),a.setLocal("m",a.i32_const(b)),a.call(l+"_copy",a.i32_const(F),o),a.call(l+"_exp",a.getLocal("n"),a.i32_const(I),a.i32_const(c),n),a.call(l+"_exp",a.getLocal("n"),a.i32_const(v),a.i32_const(c),r),a.block(a.loop(a.br_if(1,a.call(l+"_eq",n,i)),a.call(l+"_square",n,s),a.setLocal("i",a.i32_const(1)),a.block(a.loop(a.br_if(1,a.call(l+"_eq",s,i)),a.call(l+"_square",s,s),a.setLocal("i",a.i32_add(a.getLocal("i"),a.i32_const(1))),a.br(0))),a.call(l+"_copy",o,d),a.setLocal("j",a.i32_sub(a.i32_sub(a.getLocal("m"),a.getLocal("i")),a.i32_const(1))),a.block(a.loop(a.br_if(1,a.i32_eqz(a.getLocal("j"))),a.call(l+"_square",d,d),a.setLocal("j",a.i32_sub(a.getLocal("j"),a.i32_const(1))),a.br(0))),a.setLocal("m",a.getLocal("i")),a.call(l+"_square",d,o),a.call(l+"_mul",n,o,n),a.call(l+"_mul",r,d,r),a.br(0))),a.if(a.call(l+"_isNegative",r),a.call(l+"_neg",r,a.getLocal("r")),a.call(l+"_copy",r,a.getLocal("r"))))}(),function(){const e=t.addFunction(l+"_isSquare");e.addParam("n","i32"),e.setReturnType("i32");const a=e.getCodeBuilder(),i=a.i32_const(f),o=a.i32_const(t.alloc(c));e.addCode(a.if(a.call(l+"_isZero",a.getLocal("n")),a.ret(a.i32_const(1))),a.call(l+"_exp",a.getLocal("n"),a.i32_const(m),a.i32_const(c),o),a.call(l+"_eq",o,i))}(),t.exportFunction(l+"_sqrt"),t.exportFunction(l+"_isSquare")),t.exportFunction(l+"_batchToMontgomery"),t.exportFunction(l+"_batchFromMontgomery"),l},zt=function(t,e,a,i,o){const n=u(e),r=Math.floor((n.minus(1).bitLength()-1)/64)+1,c=8*r,l=a||"f1";if(t.modules[l])return l;t.modules[l]={n64:r};const s=o||"int",d=Ut(t,n,i,s),g=t.modules[d].pR2,f=t.modules[d].pq,_=t.modules[d].pePlusOne;return function(){const e=t.alloc(c),a=t.addFunction(l+"_mul");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const i=a.getCodeBuilder();a.addCode(i.call(d+"_mul",i.getLocal("x"),i.getLocal("y"),i.i32_const(e))),a.addCode(i.call(d+"_mul",i.i32_const(e),i.i32_const(g),i.getLocal("r")))}(),function(){const e=t.addFunction(l+"_square");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(l+"_mul",a.getLocal("x"),a.getLocal("x"),a.getLocal("r")))}(),function(){const e=t.addFunction(l+"_inverse");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(s+"_inverseMod",a.getLocal("x"),a.i32_const(f),a.getLocal("r")))}(),function(){const e=t.addFunction(l+"_isNegative");e.addParam("x","i32"),e.setReturnType("i32");const a=e.getCodeBuilder();e.addCode(a.call(s+"_gte",a.getLocal("x"),a.i32_const(_)))}(),t.exportFunction(d+"_add",l+"_add"),t.exportFunction(d+"_sub",l+"_sub"),t.exportFunction(d+"_neg",l+"_neg"),t.exportFunction(l+"_mul"),t.exportFunction(l+"_square"),t.exportFunction(l+"_inverse"),t.exportFunction(l+"_isNegative"),t.exportFunction(d+"_copy",l+"_copy"),t.exportFunction(d+"_zero",l+"_zero"),t.exportFunction(d+"_one",l+"_one"),t.exportFunction(d+"_isZero",l+"_isZero"),t.exportFunction(d+"_eq",l+"_eq"),l},qt=function(t,e,a,i){if(t.modules[a])return a;const o=8*t.modules[i].n64,n=t.modules[i].q;return t.modules[a]={n64:2*t.modules[i].n64},function(){const e=t.addFunction(a+"_isZero");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.i32_and(n.call(i+"_isZero",r),n.call(i+"_isZero",c)))}(),function(){const e=t.addFunction(a+"_isOne");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.ret(n.i32_and(n.call(i+"_isOne",r),n.call(i+"_isZero",c))))}(),function(){const e=t.addFunction(a+"_zero");e.addParam("x","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.call(i+"_zero",r),n.call(i+"_zero",c))}(),function(){const e=t.addFunction(a+"_one");e.addParam("x","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.call(i+"_one",r),n.call(i+"_zero",c))}(),function(){const e=t.addFunction(a+"_copy");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("r"),s=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_copy",r,l),n.call(i+"_copy",c,s))}(),function(){const n=t.addFunction(a+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const r=n.getCodeBuilder(),c=r.getLocal("x"),l=r.i32_add(r.getLocal("x"),r.i32_const(o)),s=r.getLocal("y"),d=r.i32_add(r.getLocal("y"),r.i32_const(o)),u=r.getLocal("r"),g=r.i32_add(r.getLocal("r"),r.i32_const(o)),f=r.i32_const(t.alloc(o)),_=r.i32_const(t.alloc(o)),p=r.i32_const(t.alloc(o)),h=r.i32_const(t.alloc(o));n.addCode(r.call(i+"_mul",c,s,f),r.call(i+"_mul",l,d,_),r.call(i+"_add",c,l,p),r.call(i+"_add",s,d,h),r.call(i+"_mul",p,h,p),r.call(e,_,u),r.call(i+"_add",f,u,u),r.call(i+"_add",f,_,g),r.call(i+"_sub",p,g,g))}(),function(){const e=t.addFunction(a+"_mul1");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("y"),s=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_mul",r,l,s),n.call(i+"_mul",c,l,d))}(),function(){const n=t.addFunction(a+"_square");n.addParam("x","i32"),n.addParam("r","i32");const r=n.getCodeBuilder(),c=r.getLocal("x"),l=r.i32_add(r.getLocal("x"),r.i32_const(o)),s=r.getLocal("r"),d=r.i32_add(r.getLocal("r"),r.i32_const(o)),u=r.i32_const(t.alloc(o)),g=r.i32_const(t.alloc(o)),f=r.i32_const(t.alloc(o)),_=r.i32_const(t.alloc(o));n.addCode(r.call(i+"_mul",c,l,u),r.call(i+"_add",c,l,g),r.call(e,l,f),r.call(i+"_add",c,f,f),r.call(e,u,_),r.call(i+"_add",_,u,_),r.call(i+"_mul",g,f,s),r.call(i+"_sub",s,_,s),r.call(i+"_add",u,u,d))}(),function(){const e=t.addFunction(a+"_add");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("y"),s=n.i32_add(n.getLocal("y"),n.i32_const(o)),d=n.getLocal("r"),u=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_add",r,l,d),n.call(i+"_add",c,s,u))}(),function(){const e=t.addFunction(a+"_sub");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("y"),s=n.i32_add(n.getLocal("y"),n.i32_const(o)),d=n.getLocal("r"),u=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_sub",r,l,d),n.call(i+"_sub",c,s,u))}(),function(){const e=t.addFunction(a+"_neg");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("r"),s=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_neg",r,l),n.call(i+"_neg",c,s))}(),function(){const e=t.addFunction(a+"_conjugate");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("r"),s=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_copy",r,l),n.call(i+"_neg",c,s))}(),function(){const e=t.addFunction(a+"_toMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("r"),s=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_toMontgomery",r,l),n.call(i+"_toMontgomery",c,s))}(),function(){const e=t.addFunction(a+"_fromMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("r"),s=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_fromMontgomery",r,l),n.call(i+"_fromMontgomery",c,s))}(),function(){const e=t.addFunction(a+"_eq");e.addParam("x","i32"),e.addParam("y","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("y"),s=n.i32_add(n.getLocal("y"),n.i32_const(o));e.addCode(n.i32_and(n.call(i+"_eq",r,l),n.call(i+"_eq",c,s)))}(),function(){const n=t.addFunction(a+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const r=n.getCodeBuilder(),c=r.getLocal("x"),l=r.i32_add(r.getLocal("x"),r.i32_const(o)),s=r.getLocal("r"),d=r.i32_add(r.getLocal("r"),r.i32_const(o)),u=r.i32_const(t.alloc(o)),g=r.i32_const(t.alloc(o)),f=r.i32_const(t.alloc(o)),_=r.i32_const(t.alloc(o));n.addCode(r.call(i+"_square",c,u),r.call(i+"_square",l,g),r.call(e,g,f),r.call(i+"_sub",u,f,f),r.call(i+"_inverse",f,_),r.call(i+"_mul",c,_,s),r.call(i+"_mul",l,_,d),r.call(i+"_neg",d,d))}(),function(){const e=t.addFunction(a+"_timesScalar");e.addParam("x","i32"),e.addParam("scalar","i32"),e.addParam("scalarLen","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("r"),s=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_timesScalar",r,n.getLocal("scalar"),n.getLocal("scalarLen"),l),n.call(i+"_timesScalar",c,n.getLocal("scalar"),n.getLocal("scalarLen"),s))}(),function(){const e=t.addFunction(a+"_sign");e.addParam("x","i32"),e.addLocal("s","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.setLocal("s",n.call(i+"_sign",c)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(i+"_sign",r)))}(),function(){const e=t.addFunction(a+"_isNegative");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.if(n.call(i+"_isZero",c),n.ret(n.call(i+"_isNegative",r))),n.ret(n.call(i+"_isNegative",c)))}(),t.exportFunction(a+"_isZero"),t.exportFunction(a+"_isOne"),t.exportFunction(a+"_zero"),t.exportFunction(a+"_one"),t.exportFunction(a+"_copy"),t.exportFunction(a+"_mul"),t.exportFunction(a+"_mul1"),t.exportFunction(a+"_square"),t.exportFunction(a+"_add"),t.exportFunction(a+"_sub"),t.exportFunction(a+"_neg"),t.exportFunction(a+"_sign"),t.exportFunction(a+"_conjugate"),t.exportFunction(a+"_fromMontgomery"),t.exportFunction(a+"_toMontgomery"),t.exportFunction(a+"_eq"),t.exportFunction(a+"_inverse"),Gt(t,a),St(t,a+"_exp",2*o,a+"_mul",a+"_square",a+"_copy",a+"_one"),function(){const e=t.addFunction(a+"_sqrt");e.addParam("a","i32"),e.addParam("pr","i32");const r=e.getCodeBuilder(),c=r.i32_const(t.alloc(Et(u(n).minus(u(3)).divide(4),o))),l=r.i32_const(t.alloc(Et(u(n).minus(u(1)).divide(2),o))),s=r.getLocal("a"),d=r.i32_const(t.alloc(2*o)),g=r.i32_const(t.alloc(2*o)),f=r.i32_const(t.alloc(2*o)),_=t.alloc(2*o),p=r.i32_const(_),h=r.i32_const(_),m=r.i32_const(_+o),L=r.i32_const(t.alloc(2*o)),w=r.i32_const(t.alloc(2*o));e.addCode(r.call(a+"_one",p),r.call(a+"_neg",p,p),r.call(a+"_exp",s,c,r.i32_const(o),d),r.call(a+"_square",d,g),r.call(a+"_mul",s,g,g),r.call(a+"_conjugate",g,f),r.call(a+"_mul",f,g,f),r.if(r.call(a+"_eq",f,p),r.unreachable()),r.call(a+"_mul",d,s,L),r.if(r.call(a+"_eq",g,p),[...r.call(i+"_zero",h),...r.call(i+"_one",m),...r.call(a+"_mul",p,L,r.getLocal("pr"))],[...r.call(a+"_one",w),...r.call(a+"_add",w,g,w),...r.call(a+"_exp",w,l,r.i32_const(o),w),...r.call(a+"_mul",w,L,r.getLocal("pr"))]))}(),function(){const e=t.addFunction(a+"_isSquare");e.addParam("a","i32"),e.setReturnType("i32");const i=e.getCodeBuilder(),r=i.i32_const(t.alloc(Et(u(n).minus(u(3)).divide(4),o))),c=i.getLocal("a"),l=i.i32_const(t.alloc(2*o)),s=i.i32_const(t.alloc(2*o)),d=i.i32_const(t.alloc(2*o)),g=t.alloc(2*o),f=i.i32_const(g);e.addCode(i.call(a+"_one",f),i.call(a+"_neg",f,f),i.call(a+"_exp",c,r,i.i32_const(o),l),i.call(a+"_square",l,s),i.call(a+"_mul",c,s,s),i.call(a+"_conjugate",s,d),i.call(a+"_mul",d,s,d),i.if(i.call(a+"_eq",d,f),i.ret(i.i32_const(0))),i.ret(i.i32_const(1)))}(),t.exportFunction(a+"_exp"),t.exportFunction(a+"_timesScalar"),t.exportFunction(a+"_batchInverse"),t.exportFunction(a+"_sqrt"),t.exportFunction(a+"_isSquare"),t.exportFunction(a+"_isNegative"),a},Qt=function(t,e,a,i){if(t.modules[a])return a;const o=8*t.modules[i].n64;return t.modules[a]={n64:3*t.modules[i].n64},function(){const e=t.addFunction(a+"_isZero");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.i32_and(n.i32_and(n.call(i+"_isZero",r),n.call(i+"_isZero",c)),n.call(i+"_isZero",l)))}(),function(){const e=t.addFunction(a+"_isOne");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.ret(n.i32_and(n.i32_and(n.call(i+"_isOne",r),n.call(i+"_isZero",c)),n.call(i+"_isZero",l))))}(),function(){const e=t.addFunction(a+"_zero");e.addParam("x","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.call(i+"_zero",r),n.call(i+"_zero",c),n.call(i+"_zero",l))}(),function(){const e=t.addFunction(a+"_one");e.addParam("x","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.call(i+"_one",r),n.call(i+"_zero",c),n.call(i+"_zero",l))}(),function(){const e=t.addFunction(a+"_copy");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(o)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_copy",r,s),n.call(i+"_copy",c,d),n.call(i+"_copy",l,u))}(),function(){const n=t.addFunction(a+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const r=n.getCodeBuilder(),c=r.getLocal("x"),l=r.i32_add(r.getLocal("x"),r.i32_const(o)),s=r.i32_add(r.getLocal("x"),r.i32_const(2*o)),d=r.getLocal("y"),u=r.i32_add(r.getLocal("y"),r.i32_const(o)),g=r.i32_add(r.getLocal("y"),r.i32_const(2*o)),f=r.getLocal("r"),_=r.i32_add(r.getLocal("r"),r.i32_const(o)),p=r.i32_add(r.getLocal("r"),r.i32_const(2*o)),h=r.i32_const(t.alloc(o)),m=r.i32_const(t.alloc(o)),L=r.i32_const(t.alloc(o)),w=r.i32_const(t.alloc(o)),A=r.i32_const(t.alloc(o)),b=r.i32_const(t.alloc(o)),y=r.i32_const(t.alloc(o)),I=r.i32_const(t.alloc(o)),C=r.i32_const(t.alloc(o)),F=r.i32_const(t.alloc(o)),x=r.i32_const(t.alloc(o)),v=r.i32_const(t.alloc(o)),E=r.i32_const(t.alloc(o));n.addCode(r.call(i+"_mul",c,d,h),r.call(i+"_mul",l,u,m),r.call(i+"_mul",s,g,L),r.call(i+"_add",c,l,w),r.call(i+"_add",d,u,A),r.call(i+"_add",c,s,b),r.call(i+"_add",d,g,y),r.call(i+"_add",l,s,I),r.call(i+"_add",u,g,C),r.call(i+"_add",h,m,F),r.call(i+"_add",h,L,x),r.call(i+"_add",m,L,v),r.call(i+"_mul",I,C,f),r.call(i+"_sub",f,v,f),r.call(e,f,f),r.call(i+"_add",h,f,f),r.call(i+"_mul",w,A,_),r.call(i+"_sub",_,F,_),r.call(e,L,E),r.call(i+"_add",_,E,_),r.call(i+"_mul",b,y,p),r.call(i+"_sub",p,x,p),r.call(i+"_add",p,m,p))}(),function(){const n=t.addFunction(a+"_square");n.addParam("x","i32"),n.addParam("r","i32");const r=n.getCodeBuilder(),c=r.getLocal("x"),l=r.i32_add(r.getLocal("x"),r.i32_const(o)),s=r.i32_add(r.getLocal("x"),r.i32_const(2*o)),d=r.getLocal("r"),u=r.i32_add(r.getLocal("r"),r.i32_const(o)),g=r.i32_add(r.getLocal("r"),r.i32_const(2*o)),f=r.i32_const(t.alloc(o)),_=r.i32_const(t.alloc(o)),p=r.i32_const(t.alloc(o)),h=r.i32_const(t.alloc(o)),m=r.i32_const(t.alloc(o)),L=r.i32_const(t.alloc(o)),w=r.i32_const(t.alloc(o));n.addCode(r.call(i+"_square",c,f),r.call(i+"_mul",c,l,_),r.call(i+"_add",_,_,p),r.call(i+"_sub",c,l,h),r.call(i+"_add",h,s,h),r.call(i+"_square",h,h),r.call(i+"_mul",l,s,m),r.call(i+"_add",m,m,L),r.call(i+"_square",s,w),r.call(e,L,d),r.call(i+"_add",f,d,d),r.call(e,w,u),r.call(i+"_add",p,u,u),r.call(i+"_add",f,w,g),r.call(i+"_sub",L,g,g),r.call(i+"_add",h,g,g),r.call(i+"_add",p,g,g))}(),function(){const e=t.addFunction(a+"_add");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(o)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*o)),g=n.getLocal("r"),f=n.i32_add(n.getLocal("r"),n.i32_const(o)),_=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_add",r,s,g),n.call(i+"_add",c,d,f),n.call(i+"_add",l,u,_))}(),function(){const e=t.addFunction(a+"_sub");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(o)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*o)),g=n.getLocal("r"),f=n.i32_add(n.getLocal("r"),n.i32_const(o)),_=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_sub",r,s,g),n.call(i+"_sub",c,d,f),n.call(i+"_sub",l,u,_))}(),function(){const e=t.addFunction(a+"_neg");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(o)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_neg",r,s),n.call(i+"_neg",c,d),n.call(i+"_neg",l,u))}(),function(){const e=t.addFunction(a+"_sign");e.addParam("x","i32"),e.addLocal("s","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.setLocal("s",n.call(i+"_sign",l)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.setLocal("s",n.call(i+"_sign",c)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(i+"_sign",r)))}(),function(){const e=t.addFunction(a+"_toMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(o)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_toMontgomery",r,s),n.call(i+"_toMontgomery",c,d),n.call(i+"_toMontgomery",l,u))}(),function(){const e=t.addFunction(a+"_fromMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(o)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_fromMontgomery",r,s),n.call(i+"_fromMontgomery",c,d),n.call(i+"_fromMontgomery",l,u))}(),function(){const e=t.addFunction(a+"_eq");e.addParam("x","i32"),e.addParam("y","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(o)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*o));e.addCode(n.i32_and(n.i32_and(n.call(i+"_eq",r,s),n.call(i+"_eq",c,d)),n.call(i+"_eq",l,u)))}(),function(){const n=t.addFunction(a+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const r=n.getCodeBuilder(),c=r.getLocal("x"),l=r.i32_add(r.getLocal("x"),r.i32_const(o)),s=r.i32_add(r.getLocal("x"),r.i32_const(2*o)),d=r.getLocal("r"),u=r.i32_add(r.getLocal("r"),r.i32_const(o)),g=r.i32_add(r.getLocal("r"),r.i32_const(2*o)),f=r.i32_const(t.alloc(o)),_=r.i32_const(t.alloc(o)),p=r.i32_const(t.alloc(o)),h=r.i32_const(t.alloc(o)),m=r.i32_const(t.alloc(o)),L=r.i32_const(t.alloc(o)),w=r.i32_const(t.alloc(o)),A=r.i32_const(t.alloc(o)),b=r.i32_const(t.alloc(o)),y=r.i32_const(t.alloc(o)),I=r.i32_const(t.alloc(o));n.addCode(r.call(i+"_square",c,f),r.call(i+"_square",l,_),r.call(i+"_square",s,p),r.call(i+"_mul",c,l,h),r.call(i+"_mul",c,s,m),r.call(i+"_mul",l,s,L),r.call(e,L,w),r.call(i+"_sub",f,w,w),r.call(e,p,A),r.call(i+"_sub",A,h,A),r.call(i+"_sub",_,m,b),r.call(i+"_mul",s,A,y),r.call(i+"_mul",l,b,I),r.call(i+"_add",y,I,y),r.call(e,y,y),r.call(i+"_mul",c,w,I),r.call(i+"_add",I,y,y),r.call(i+"_inverse",y,y),r.call(i+"_mul",y,w,d),r.call(i+"_mul",y,A,u),r.call(i+"_mul",y,b,g))}(),function(){const e=t.addFunction(a+"_timesScalar");e.addParam("x","i32"),e.addParam("scalar","i32"),e.addParam("scalarLen","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(o)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_timesScalar",r,n.getLocal("scalar"),n.getLocal("scalarLen"),s),n.call(i+"_timesScalar",c,n.getLocal("scalar"),n.getLocal("scalarLen"),d),n.call(i+"_timesScalar",l,n.getLocal("scalar"),n.getLocal("scalarLen"),u))}(),function(){const e=t.addFunction(a+"_isNegative");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.if(n.call(i+"_isZero",l),n.if(n.call(i+"_isZero",c),n.ret(n.call(i+"_isNegative",r)),n.ret(n.call(i+"_isNegative",c)))),n.ret(n.call(i+"_isNegative",l)))}(),t.exportFunction(a+"_isZero"),t.exportFunction(a+"_isOne"),t.exportFunction(a+"_zero"),t.exportFunction(a+"_one"),t.exportFunction(a+"_copy"),t.exportFunction(a+"_mul"),t.exportFunction(a+"_square"),t.exportFunction(a+"_add"),t.exportFunction(a+"_sub"),t.exportFunction(a+"_neg"),t.exportFunction(a+"_sign"),t.exportFunction(a+"_fromMontgomery"),t.exportFunction(a+"_toMontgomery"),t.exportFunction(a+"_eq"),t.exportFunction(a+"_inverse"),Gt(t,a),St(t,a+"_exp",3*o,a+"_mul",a+"_square",a+"_copy",a+"_one"),t.exportFunction(a+"_exp"),t.exportFunction(a+"_timesScalar"),t.exportFunction(a+"_batchInverse"),t.exportFunction(a+"_isNegative"),a},Mt=function(t,e,a,i,o,n,r,c){const l=t.addFunction(e);l.addParam("base","i32"),l.addParam("scalar","i32"),l.addParam("scalarLength","i32"),l.addParam("r","i32"),l.addLocal("old0","i32"),l.addLocal("nbits","i32"),l.addLocal("i","i32"),l.addLocal("last","i32"),l.addLocal("cur","i32"),l.addLocal("carry","i32"),l.addLocal("p","i32");const s=l.getCodeBuilder(),d=s.i32_const(t.alloc(a));function u(t){return s.i32_and(s.i32_shr_u(s.i32_load(s.i32_add(s.getLocal("scalar"),s.i32_and(s.i32_shr_u(t,s.i32_const(3)),s.i32_const(4294967292)))),s.i32_and(t,s.i32_const(31))),s.i32_const(1))}function g(t){return[...s.i32_store8(s.getLocal("p"),s.i32_const(t)),...s.setLocal("p",s.i32_add(s.getLocal("p"),s.i32_const(1)))]}l.addCode(s.if(s.i32_eqz(s.getLocal("scalarLength")),[...s.call(c,s.getLocal("r")),...s.ret([])]),s.setLocal("nbits",s.i32_shl(s.getLocal("scalarLength"),s.i32_const(3))),s.setLocal("old0",s.i32_load(s.i32_const(0))),s.setLocal("p",s.getLocal("old0")),s.i32_store(s.i32_const(0),s.i32_and(s.i32_add(s.i32_add(s.getLocal("old0"),s.i32_const(32)),s.getLocal("nbits")),s.i32_const(4294967288))),s.setLocal("i",s.i32_const(1)),s.setLocal("last",u(s.i32_const(0))),s.setLocal("carry",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("nbits"))),s.setLocal("cur",u(s.getLocal("i"))),s.if(s.getLocal("last"),s.if(s.getLocal("cur"),s.if(s.getLocal("carry"),[...s.setLocal("last",s.i32_const(0)),...s.setLocal("carry",s.i32_const(1)),...g(1)],[...s.setLocal("last",s.i32_const(0)),...s.setLocal("carry",s.i32_const(1)),...g(255)]),s.if(s.getLocal("carry"),[...s.setLocal("last",s.i32_const(0)),...s.setLocal("carry",s.i32_const(1)),...g(255)],[...s.setLocal("last",s.i32_const(0)),...s.setLocal("carry",s.i32_const(0)),...g(1)])),s.if(s.getLocal("cur"),s.if(s.getLocal("carry"),[...s.setLocal("last",s.i32_const(0)),...s.setLocal("carry",s.i32_const(1)),...g(0)],[...s.setLocal("last",s.i32_const(1)),...s.setLocal("carry",s.i32_const(0)),...g(0)]),s.if(s.getLocal("carry"),[...s.setLocal("last",s.i32_const(1)),...s.setLocal("carry",s.i32_const(0)),...g(0)],[...s.setLocal("last",s.i32_const(0)),...s.setLocal("carry",s.i32_const(0)),...g(0)]))),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))),s.if(s.getLocal("last"),s.if(s.getLocal("carry"),[...g(255),...g(0),...g(1)],[...g(1)]),s.if(s.getLocal("carry"),[...g(0),...g(1)])),s.setLocal("p",s.i32_sub(s.getLocal("p"),s.i32_const(1))),s.call(r,s.getLocal("base"),d),s.call(c,s.getLocal("r")),s.block(s.loop(s.call(o,s.getLocal("r"),s.getLocal("r")),s.setLocal("cur",s.i32_load8_u(s.getLocal("p"))),s.if(s.getLocal("cur"),s.if(s.i32_eq(s.getLocal("cur"),s.i32_const(1)),s.call(i,s.getLocal("r"),d,s.getLocal("r")),s.call(n,s.getLocal("r"),d,s.getLocal("r")))),s.br_if(1,s.i32_eq(s.getLocal("old0"),s.getLocal("p"))),s.setLocal("p",s.i32_sub(s.getLocal("p"),s.i32_const(1))),s.br(0))),s.i32_store(s.i32_const(0),s.getLocal("old0")))},kt=function(t,e,a,i,o){const n=8*t.modules[e].n64;function r(){const i=t.addFunction(a);i.addParam("pBases","i32"),i.addParam("pScalars","i32"),i.addParam("scalarSize","i32"),i.addParam("n","i32"),i.addParam("pr","i32"),i.addLocal("chunkSize","i32"),i.addLocal("nChunks","i32"),i.addLocal("itScalar","i32"),i.addLocal("endScalar","i32"),i.addLocal("itBase","i32"),i.addLocal("itBit","i32"),i.addLocal("i","i32"),i.addLocal("j","i32"),i.addLocal("nTable","i32"),i.addLocal("pTable","i32"),i.addLocal("idx","i32"),i.addLocal("pIdxTable","i32");const o=i.getCodeBuilder(),r=o.i32_const(t.alloc(n)),c=t.alloc([17,17,17,17,17,17,17,17,17,17,16,16,15,14,13,13,12,11,10,9,8,7,7,6,5,4,3,2,1,1,1,1]);i.addCode(o.call(e+"_zero",o.getLocal("pr")),o.if(o.i32_eqz(o.getLocal("n")),o.ret([])),o.setLocal("chunkSize",o.i32_load8_u(o.i32_clz(o.getLocal("n")),c)),o.setLocal("nChunks",o.i32_add(o.i32_div_u(o.i32_sub(o.i32_shl(o.getLocal("scalarSize"),o.i32_const(3)),o.i32_const(1)),o.getLocal("chunkSize")),o.i32_const(1))),o.setLocal("itBit",o.i32_mul(o.i32_sub(o.getLocal("nChunks"),o.i32_const(1)),o.getLocal("chunkSize"))),o.block(o.loop(o.br_if(1,o.i32_lt_s(o.getLocal("itBit"),o.i32_const(0))),o.if(o.i32_eqz(o.call(e+"_isZero",o.getLocal("pr"))),[...o.setLocal("j",o.i32_const(0)),...o.block(o.loop(o.br_if(1,o.i32_eq(o.getLocal("j"),o.getLocal("chunkSize"))),o.call(e+"_double",o.getLocal("pr"),o.getLocal("pr")),o.setLocal("j",o.i32_add(o.getLocal("j"),o.i32_const(1))),o.br(0)))]),o.call(a+"_chunk",o.getLocal("pBases"),o.getLocal("pScalars"),o.getLocal("scalarSize"),o.getLocal("n"),o.getLocal("itBit"),o.getLocal("chunkSize"),r),o.call(e+"_add",o.getLocal("pr"),r,o.getLocal("pr")),o.setLocal("itBit",o.i32_sub(o.getLocal("itBit"),o.getLocal("chunkSize"))),o.br(0))))}!function(){const e=t.addFunction(a+"_getChunk");e.addParam("pScalar","i32"),e.addParam("scalarSize","i32"),e.addParam("startBit","i32"),e.addParam("chunkSize","i32"),e.addLocal("bitsToEnd","i32"),e.addLocal("mask","i32"),e.setReturnType("i32");const i=e.getCodeBuilder();e.addCode(i.setLocal("bitsToEnd",i.i32_sub(i.i32_mul(i.getLocal("scalarSize"),i.i32_const(8)),i.getLocal("startBit"))),i.if(i.i32_gt_s(i.getLocal("chunkSize"),i.getLocal("bitsToEnd")),i.setLocal("mask",i.i32_sub(i.i32_shl(i.i32_const(1),i.getLocal("bitsToEnd")),i.i32_const(1))),i.setLocal("mask",i.i32_sub(i.i32_shl(i.i32_const(1),i.getLocal("chunkSize")),i.i32_const(1)))),i.i32_and(i.i32_shr_u(i.i32_load(i.i32_add(i.getLocal("pScalar"),i.i32_shr_u(i.getLocal("startBit"),i.i32_const(3))),0,0),i.i32_and(i.getLocal("startBit"),i.i32_const(7))),i.getLocal("mask")))}(),function(){const i=t.addFunction(a+"_reduceTable");i.addParam("pTable","i32"),i.addParam("p","i32"),i.addLocal("half","i32"),i.addLocal("it1","i32"),i.addLocal("it2","i32"),i.addLocal("pAcc","i32");const o=i.getCodeBuilder();i.addCode(o.if(o.i32_eq(o.getLocal("p"),o.i32_const(1)),o.ret([])),o.setLocal("half",o.i32_shl(o.i32_const(1),o.i32_sub(o.getLocal("p"),o.i32_const(1)))),o.setLocal("it1",o.getLocal("pTable")),o.setLocal("it2",o.i32_add(o.getLocal("pTable"),o.i32_mul(o.getLocal("half"),o.i32_const(n)))),o.setLocal("pAcc",o.i32_sub(o.getLocal("it2"),o.i32_const(n))),o.block(o.loop(o.br_if(1,o.i32_eq(o.getLocal("it1"),o.getLocal("pAcc"))),o.call(e+"_add",o.getLocal("it1"),o.getLocal("it2"),o.getLocal("it1")),o.call(e+"_add",o.getLocal("pAcc"),o.getLocal("it2"),o.getLocal("pAcc")),o.setLocal("it1",o.i32_add(o.getLocal("it1"),o.i32_const(n))),o.setLocal("it2",o.i32_add(o.getLocal("it2"),o.i32_const(n))),o.br(0))),o.call(a+"_reduceTable",o.getLocal("pTable"),o.i32_sub(o.getLocal("p"),o.i32_const(1))),o.setLocal("p",o.i32_sub(o.getLocal("p"),o.i32_const(1))),o.block(o.loop(o.br_if(1,o.i32_eqz(o.getLocal("p"))),o.call(e+"_double",o.getLocal("pAcc"),o.getLocal("pAcc")),o.setLocal("p",o.i32_sub(o.getLocal("p"),o.i32_const(1))),o.br(0))),o.call(e+"_add",o.getLocal("pTable"),o.getLocal("pAcc"),o.getLocal("pTable")))}(),function(){const r=t.addFunction(a+"_chunk");r.addParam("pBases","i32"),r.addParam("pScalars","i32"),r.addParam("scalarSize","i32"),r.addParam("n","i32"),r.addParam("startBit","i32"),r.addParam("chunkSize","i32"),r.addParam("pr","i32"),r.addLocal("nChunks","i32"),r.addLocal("itScalar","i32"),r.addLocal("endScalar","i32"),r.addLocal("itBase","i32"),r.addLocal("i","i32"),r.addLocal("j","i32"),r.addLocal("nTable","i32"),r.addLocal("pTable","i32"),r.addLocal("idx","i32"),r.addLocal("pIdxTable","i32");const c=r.getCodeBuilder();r.addCode(c.if(c.i32_eqz(c.getLocal("n")),[...c.call(e+"_zero",c.getLocal("pr")),...c.ret([])]),c.setLocal("nTable",c.i32_shl(c.i32_const(1),c.getLocal("chunkSize"))),c.setLocal("pTable",c.i32_load(c.i32_const(0))),c.i32_store(c.i32_const(0),c.i32_add(c.getLocal("pTable"),c.i32_mul(c.getLocal("nTable"),c.i32_const(n)))),c.setLocal("j",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("j"),c.getLocal("nTable"))),c.call(e+"_zero",c.i32_add(c.getLocal("pTable"),c.i32_mul(c.getLocal("j"),c.i32_const(n)))),c.setLocal("j",c.i32_add(c.getLocal("j"),c.i32_const(1))),c.br(0))),c.setLocal("itBase",c.getLocal("pBases")),c.setLocal("itScalar",c.getLocal("pScalars")),c.setLocal("endScalar",c.i32_add(c.getLocal("pScalars"),c.i32_mul(c.getLocal("n"),c.getLocal("scalarSize")))),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("itScalar"),c.getLocal("endScalar"))),c.setLocal("idx",c.call(a+"_getChunk",c.getLocal("itScalar"),c.getLocal("scalarSize"),c.getLocal("startBit"),c.getLocal("chunkSize"))),c.if(c.getLocal("idx"),[...c.setLocal("pIdxTable",c.i32_add(c.getLocal("pTable"),c.i32_mul(c.i32_sub(c.getLocal("idx"),c.i32_const(1)),c.i32_const(n)))),...c.call(i,c.getLocal("pIdxTable"),c.getLocal("itBase"),c.getLocal("pIdxTable"))]),c.setLocal("itScalar",c.i32_add(c.getLocal("itScalar"),c.getLocal("scalarSize"))),c.setLocal("itBase",c.i32_add(c.getLocal("itBase"),c.i32_const(o))),c.br(0))),c.call(a+"_reduceTable",c.getLocal("pTable"),c.getLocal("chunkSize")),c.call(e+"_copy",c.getLocal("pTable"),c.getLocal("pr")),c.i32_store(c.i32_const(0),c.getLocal("pTable")))}(),r(),t.exportFunction(a),t.exportFunction(a+"_chunk")},Rt=function(t,e,a,i){const o=t.modules[a].n64,n=8*o;if(t.modules[e])return e;return t.modules[e]={n64:3*o},function(){const i=t.addFunction(e+"_isZeroAffine");i.addParam("p1","i32"),i.setReturnType("i32");const o=i.getCodeBuilder();i.addCode(o.i32_and(o.call(a+"_isZero",o.getLocal("p1")),o.call(a+"_isZero",o.i32_add(o.getLocal("p1"),o.i32_const(n)))))}(),function(){const i=t.addFunction(e+"_isZero");i.addParam("p1","i32"),i.setReturnType("i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_isZero",o.i32_add(o.getLocal("p1"),o.i32_const(2*n))))}(),function(){const i=t.addFunction(e+"_zeroAffine");i.addParam("pr","i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_zero",o.getLocal("pr"))),i.addCode(o.call(a+"_zero",o.i32_add(o.getLocal("pr"),o.i32_const(n))))}(),function(){const i=t.addFunction(e+"_zero");i.addParam("pr","i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_zero",o.getLocal("pr"))),i.addCode(o.call(a+"_one",o.i32_add(o.getLocal("pr"),o.i32_const(n)))),i.addCode(o.call(a+"_zero",o.i32_add(o.getLocal("pr"),o.i32_const(2*n))))}(),function(){const a=t.addFunction(e+"_copyAffine");a.addParam("ps","i32"),a.addParam("pd","i32");const i=a.getCodeBuilder();for(let t=0;t<2*o;t++)a.addCode(i.i64_store(i.getLocal("pd"),8*t,i.i64_load(i.getLocal("ps"),8*t)))}(),function(){const a=t.addFunction(e+"_copy");a.addParam("ps","i32"),a.addParam("pd","i32");const i=a.getCodeBuilder();for(let t=0;t<3*o;t++)a.addCode(i.i64_store(i.getLocal("pd"),8*t,i.i64_load(i.getLocal("ps"),8*t)))}(),function(){const i=t.addFunction(e+"_toJacobian");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.getLocal("pr"),s=o.i32_add(o.getLocal("pr"),o.i32_const(n)),d=o.i32_add(o.getLocal("pr"),o.i32_const(2*n));i.addCode(o.if(o.call(e+"_isZeroAffine",o.getLocal("p1")),o.call(e+"_zero",o.getLocal("pr")),[...o.call(a+"_one",d),...o.call(a+"_copy",c,s),...o.call(a+"_copy",r,l)]))}(),function(){const i=t.addFunction(e+"_eqAffine");i.addParam("p1","i32"),i.addParam("p2","i32"),i.setReturnType("i32"),i.addLocal("z1","i32");const o=i.getCodeBuilder();i.addCode(o.ret(o.i32_and(o.call(a+"_eq",o.getLocal("p1"),o.getLocal("p2")),o.call(a+"_eq",o.i32_add(o.getLocal("p1"),o.i32_const(n)),o.i32_add(o.getLocal("p2"),o.i32_const(n))))))}(),function(){const i=t.addFunction(e+"_eqMixed");i.addParam("p1","i32"),i.addParam("p2","i32"),i.setReturnType("i32"),i.addLocal("z1","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n));i.addCode(o.setLocal("z1",o.i32_add(o.getLocal("p1"),o.i32_const(2*n))));const l=o.getLocal("z1"),s=o.getLocal("p2"),d=o.i32_add(o.getLocal("p2"),o.i32_const(n)),u=o.i32_const(t.alloc(n)),g=o.i32_const(t.alloc(n)),f=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),o.ret(o.call(e+"_isZeroAffine",o.getLocal("p2")))),o.if(o.call(e+"_isZeroAffine",o.getLocal("p2")),o.ret(o.i32_const(0))),o.if(o.call(a+"_isOne",l),o.ret(o.call(e+"_eqAffine",o.getLocal("p1"),o.getLocal("p2")))),o.call(a+"_square",l,u),o.call(a+"_mul",s,u,g),o.call(a+"_mul",l,u,f),o.call(a+"_mul",d,f,_),o.if(o.call(a+"_eq",r,g),o.if(o.call(a+"_eq",c,_),o.ret(o.i32_const(1)))),o.ret(o.i32_const(0)))}(),function(){const i=t.addFunction(e+"_eq");i.addParam("p1","i32"),i.addParam("p2","i32"),i.setReturnType("i32"),i.addLocal("z1","i32"),i.addLocal("z2","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n));i.addCode(o.setLocal("z1",o.i32_add(o.getLocal("p1"),o.i32_const(2*n))));const l=o.getLocal("z1"),s=o.getLocal("p2"),d=o.i32_add(o.getLocal("p2"),o.i32_const(n));i.addCode(o.setLocal("z2",o.i32_add(o.getLocal("p2"),o.i32_const(2*n))));const u=o.getLocal("z2"),g=o.i32_const(t.alloc(n)),f=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),h=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),L=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),o.ret(o.call(e+"_isZero",o.getLocal("p2")))),o.if(o.call(e+"_isZero",o.getLocal("p2")),o.ret(o.i32_const(0))),o.if(o.call(a+"_isOne",l),o.ret(o.call(e+"_eqMixed",o.getLocal("p2"),o.getLocal("p1")))),o.if(o.call(a+"_isOne",u),o.ret(o.call(e+"_eqMixed",o.getLocal("p1"),o.getLocal("p2")))),o.call(a+"_square",l,g),o.call(a+"_square",u,f),o.call(a+"_mul",r,f,_),o.call(a+"_mul",s,g,p),o.call(a+"_mul",l,g,h),o.call(a+"_mul",u,f,m),o.call(a+"_mul",c,m,L),o.call(a+"_mul",d,h,w),o.if(o.call(a+"_eq",_,p),o.if(o.call(a+"_eq",L,w),o.ret(o.i32_const(1)))),o.ret(o.i32_const(0)))}(),function(){const i=t.addFunction(e+"_doubleAffine");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.getLocal("pr"),s=o.i32_add(o.getLocal("pr"),o.i32_const(n)),d=o.i32_add(o.getLocal("pr"),o.i32_const(2*n)),u=o.i32_const(t.alloc(n)),g=o.i32_const(t.alloc(n)),f=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),h=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZeroAffine",o.getLocal("p1")),[...o.call(e+"_toJacobian",o.getLocal("p1"),o.getLocal("pr")),...o.ret([])]),o.call(a+"_square",r,u),o.call(a+"_square",c,g),o.call(a+"_square",g,f),o.call(a+"_add",r,g,_),o.call(a+"_square",_,_),o.call(a+"_sub",_,u,_),o.call(a+"_sub",_,f,_),o.call(a+"_add",_,_,_),o.call(a+"_add",u,u,p),o.call(a+"_add",p,u,p),o.call(a+"_add",c,c,d),o.call(a+"_square",p,l),o.call(a+"_sub",l,_,l),o.call(a+"_sub",l,_,l),o.call(a+"_add",f,f,h),o.call(a+"_add",h,h,h),o.call(a+"_add",h,h,h),o.call(a+"_sub",_,l,s),o.call(a+"_mul",s,p,s),o.call(a+"_sub",s,h,s))}(),function(){const i=t.addFunction(e+"_double");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.i32_add(o.getLocal("p1"),o.i32_const(2*n)),s=o.getLocal("pr"),d=o.i32_add(o.getLocal("pr"),o.i32_const(n)),u=o.i32_add(o.getLocal("pr"),o.i32_const(2*n)),g=o.i32_const(t.alloc(n)),f=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),h=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),L=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),[...o.call(e+"_copy",o.getLocal("p1"),o.getLocal("pr")),...o.ret([])]),o.if(o.call(a+"_isOne",l),[...o.ret(o.call(e+"_doubleAffine",o.getLocal("p1"),o.getLocal("pr"))),...o.ret([])]),o.call(a+"_square",r,g),o.call(a+"_square",c,f),o.call(a+"_square",f,_),o.call(a+"_add",r,f,p),o.call(a+"_square",p,p),o.call(a+"_sub",p,g,p),o.call(a+"_sub",p,_,p),o.call(a+"_add",p,p,p),o.call(a+"_add",g,g,h),o.call(a+"_add",h,g,h),o.call(a+"_square",h,m),o.call(a+"_mul",c,l,L),o.call(a+"_add",p,p,s),o.call(a+"_sub",m,s,s),o.call(a+"_add",_,_,w),o.call(a+"_add",w,w,w),o.call(a+"_add",w,w,w),o.call(a+"_sub",p,s,d),o.call(a+"_mul",d,h,d),o.call(a+"_sub",d,w,d),o.call(a+"_add",L,L,u))}(),function(){const i=t.addFunction(e+"_addAffine");i.addParam("p1","i32"),i.addParam("p2","i32"),i.addParam("pr","i32"),i.addLocal("z1","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n));i.addCode(o.setLocal("z1",o.i32_add(o.getLocal("p1"),o.i32_const(2*n))));const l=o.getLocal("p2"),s=o.i32_add(o.getLocal("p2"),o.i32_const(n)),d=o.getLocal("pr"),u=o.i32_add(o.getLocal("pr"),o.i32_const(n)),g=o.i32_add(o.getLocal("pr"),o.i32_const(2*n)),f=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),h=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),L=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n)),A=o.i32_const(t.alloc(n)),b=o.i32_const(t.alloc(n)),y=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZeroAffine",o.getLocal("p1")),[...o.call(e+"_copyAffine",o.getLocal("p2"),o.getLocal("pr")),...o.call(a+"_one",o.i32_add(o.getLocal("pr"),o.i32_const(2*n))),...o.ret([])]),o.if(o.call(e+"_isZeroAffine",o.getLocal("p2")),[...o.call(e+"_copyAffine",o.getLocal("p1"),o.getLocal("pr")),...o.call(a+"_one",o.i32_add(o.getLocal("pr"),o.i32_const(2*n))),...o.ret([])]),o.if(o.call(a+"_eq",r,l),o.if(o.call(a+"_eq",c,s),[...o.call(e+"_doubleAffine",o.getLocal("p2"),o.getLocal("pr")),...o.ret([])])),o.call(a+"_sub",l,r,f),o.call(a+"_sub",s,c,p),o.call(a+"_square",f,_),o.call(a+"_add",_,_,h),o.call(a+"_add",h,h,h),o.call(a+"_mul",f,h,m),o.call(a+"_add",p,p,L),o.call(a+"_mul",r,h,A),o.call(a+"_square",L,w),o.call(a+"_add",A,A,b),o.call(a+"_sub",w,m,d),o.call(a+"_sub",d,b,d),o.call(a+"_mul",c,m,y),o.call(a+"_add",y,y,y),o.call(a+"_sub",A,d,u),o.call(a+"_mul",u,L,u),o.call(a+"_sub",u,y,u),o.call(a+"_add",f,f,g))}(),function(){const i=t.addFunction(e+"_addMixed");i.addParam("p1","i32"),i.addParam("p2","i32"),i.addParam("pr","i32"),i.addLocal("z1","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n));i.addCode(o.setLocal("z1",o.i32_add(o.getLocal("p1"),o.i32_const(2*n))));const l=o.getLocal("z1"),s=o.getLocal("p2"),d=o.i32_add(o.getLocal("p2"),o.i32_const(n)),u=o.getLocal("pr"),g=o.i32_add(o.getLocal("pr"),o.i32_const(n)),f=o.i32_add(o.getLocal("pr"),o.i32_const(2*n)),_=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),h=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),L=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n)),A=o.i32_const(t.alloc(n)),b=o.i32_const(t.alloc(n)),y=o.i32_const(t.alloc(n)),I=o.i32_const(t.alloc(n)),C=o.i32_const(t.alloc(n)),F=o.i32_const(t.alloc(n)),x=o.i32_const(t.alloc(n)),v=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),[...o.call(e+"_copyAffine",o.getLocal("p2"),o.getLocal("pr")),...o.call(a+"_one",o.i32_add(o.getLocal("pr"),o.i32_const(2*n))),...o.ret([])]),o.if(o.call(e+"_isZeroAffine",o.getLocal("p2")),[...o.call(e+"_copy",o.getLocal("p1"),o.getLocal("pr")),...o.ret([])]),o.if(o.call(a+"_isOne",l),[...o.call(e+"_addAffine",r,s,u),...o.ret([])]),o.call(a+"_square",l,_),o.call(a+"_mul",s,_,p),o.call(a+"_mul",l,_,h),o.call(a+"_mul",d,h,m),o.if(o.call(a+"_eq",r,p),o.if(o.call(a+"_eq",c,m),[...o.call(e+"_doubleAffine",o.getLocal("p2"),o.getLocal("pr")),...o.ret([])])),o.call(a+"_sub",p,r,L),o.call(a+"_sub",m,c,A),o.call(a+"_square",L,w),o.call(a+"_add",w,w,b),o.call(a+"_add",b,b,b),o.call(a+"_mul",L,b,y),o.call(a+"_add",A,A,I),o.call(a+"_mul",r,b,F),o.call(a+"_square",I,C),o.call(a+"_add",F,F,x),o.call(a+"_sub",C,y,u),o.call(a+"_sub",u,x,u),o.call(a+"_mul",c,y,v),o.call(a+"_add",v,v,v),o.call(a+"_sub",F,u,g),o.call(a+"_mul",g,I,g),o.call(a+"_sub",g,v,g),o.call(a+"_add",l,L,f),o.call(a+"_square",f,f),o.call(a+"_sub",f,_,f),o.call(a+"_sub",f,w,f))}(),function(){const i=t.addFunction(e+"_add");i.addParam("p1","i32"),i.addParam("p2","i32"),i.addParam("pr","i32"),i.addLocal("z1","i32"),i.addLocal("z2","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n));i.addCode(o.setLocal("z1",o.i32_add(o.getLocal("p1"),o.i32_const(2*n))));const l=o.getLocal("z1"),s=o.getLocal("p2"),d=o.i32_add(o.getLocal("p2"),o.i32_const(n));i.addCode(o.setLocal("z2",o.i32_add(o.getLocal("p2"),o.i32_const(2*n))));const u=o.getLocal("z2"),g=o.getLocal("pr"),f=o.i32_add(o.getLocal("pr"),o.i32_const(n)),_=o.i32_add(o.getLocal("pr"),o.i32_const(2*n)),p=o.i32_const(t.alloc(n)),h=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),L=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n)),A=o.i32_const(t.alloc(n)),b=o.i32_const(t.alloc(n)),y=o.i32_const(t.alloc(n)),I=o.i32_const(t.alloc(n)),C=o.i32_const(t.alloc(n)),F=o.i32_const(t.alloc(n)),x=o.i32_const(t.alloc(n)),v=o.i32_const(t.alloc(n)),E=o.i32_const(t.alloc(n)),B=o.i32_const(t.alloc(n)),S=o.i32_const(t.alloc(n)),G=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),[...o.call(e+"_copy",o.getLocal("p2"),o.getLocal("pr")),...o.ret([])]),o.if(o.call(e+"_isZero",o.getLocal("p2")),[...o.call(e+"_copy",o.getLocal("p1"),o.getLocal("pr")),...o.ret([])]),o.if(o.call(a+"_isOne",l),[...o.call(e+"_addMixed",s,r,g),...o.ret([])]),o.if(o.call(a+"_isOne",u),[...o.call(e+"_addMixed",r,s,g),...o.ret([])]),o.call(a+"_square",l,p),o.call(a+"_square",u,h),o.call(a+"_mul",r,h,m),o.call(a+"_mul",s,p,L),o.call(a+"_mul",l,p,w),o.call(a+"_mul",u,h,A),o.call(a+"_mul",c,A,b),o.call(a+"_mul",d,w,y),o.if(o.call(a+"_eq",m,L),o.if(o.call(a+"_eq",b,y),[...o.call(e+"_double",o.getLocal("p1"),o.getLocal("pr")),...o.ret([])])),o.call(a+"_sub",L,m,I),o.call(a+"_sub",y,b,C),o.call(a+"_add",I,I,F),o.call(a+"_square",F,F),o.call(a+"_mul",I,F,x),o.call(a+"_add",C,C,v),o.call(a+"_mul",m,F,B),o.call(a+"_square",v,E),o.call(a+"_add",B,B,S),o.call(a+"_sub",E,x,g),o.call(a+"_sub",g,S,g),o.call(a+"_mul",b,x,G),o.call(a+"_add",G,G,G),o.call(a+"_sub",B,g,f),o.call(a+"_mul",f,v,f),o.call(a+"_sub",f,G,f),o.call(a+"_add",l,u,_),o.call(a+"_square",_,_),o.call(a+"_sub",_,p,_),o.call(a+"_sub",_,h,_),o.call(a+"_mul",_,I,_))}(),function(){const i=t.addFunction(e+"_negAffine");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.getLocal("pr"),s=o.i32_add(o.getLocal("pr"),o.i32_const(n));i.addCode(o.call(a+"_copy",r,l),o.call(a+"_neg",c,s))}(),function(){const i=t.addFunction(e+"_neg");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.i32_add(o.getLocal("p1"),o.i32_const(2*n)),s=o.getLocal("pr"),d=o.i32_add(o.getLocal("pr"),o.i32_const(n)),u=o.i32_add(o.getLocal("pr"),o.i32_const(2*n));i.addCode(o.call(a+"_copy",r,s),o.call(a+"_neg",c,d),o.call(a+"_copy",l,u))}(),function(){const a=t.addFunction(e+"_subAffine");a.addParam("p1","i32"),a.addParam("p2","i32"),a.addParam("pr","i32");const i=a.getCodeBuilder(),o=i.i32_const(t.alloc(3*n));a.addCode(i.call(e+"_negAffine",i.getLocal("p2"),o),i.call(e+"_addAffine",i.getLocal("p1"),o,i.getLocal("pr")))}(),function(){const a=t.addFunction(e+"_subMixed");a.addParam("p1","i32"),a.addParam("p2","i32"),a.addParam("pr","i32");const i=a.getCodeBuilder(),o=i.i32_const(t.alloc(3*n));a.addCode(i.call(e+"_negAffine",i.getLocal("p2"),o),i.call(e+"_addMixed",i.getLocal("p1"),o,i.getLocal("pr")))}(),function(){const a=t.addFunction(e+"_sub");a.addParam("p1","i32"),a.addParam("p2","i32"),a.addParam("pr","i32");const i=a.getCodeBuilder(),o=i.i32_const(t.alloc(3*n));a.addCode(i.call(e+"_neg",i.getLocal("p2"),o),i.call(e+"_add",i.getLocal("p1"),o,i.getLocal("pr")))}(),function(){const i=t.addFunction(e+"_fromMontgomeryAffine");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_fromMontgomery",o.getLocal("p1"),o.getLocal("pr")));for(let t=1;t<2;t++)i.addCode(o.call(a+"_fromMontgomery",o.i32_add(o.getLocal("p1"),o.i32_const(t*n)),o.i32_add(o.getLocal("pr"),o.i32_const(t*n))))}(),function(){const i=t.addFunction(e+"_fromMontgomery");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_fromMontgomery",o.getLocal("p1"),o.getLocal("pr")));for(let t=1;t<3;t++)i.addCode(o.call(a+"_fromMontgomery",o.i32_add(o.getLocal("p1"),o.i32_const(t*n)),o.i32_add(o.getLocal("pr"),o.i32_const(t*n))))}(),function(){const i=t.addFunction(e+"_toMontgomeryAffine");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_toMontgomery",o.getLocal("p1"),o.getLocal("pr")));for(let t=1;t<2;t++)i.addCode(o.call(a+"_toMontgomery",o.i32_add(o.getLocal("p1"),o.i32_const(t*n)),o.i32_add(o.getLocal("pr"),o.i32_const(t*n))))}(),function(){const i=t.addFunction(e+"_toMontgomery");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_toMontgomery",o.getLocal("p1"),o.getLocal("pr")));for(let t=1;t<3;t++)i.addCode(o.call(a+"_toMontgomery",o.i32_add(o.getLocal("p1"),o.i32_const(t*n)),o.i32_add(o.getLocal("pr"),o.i32_const(t*n))))}(),function(){const i=t.addFunction(e+"_toAffine");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.i32_add(o.getLocal("p1"),o.i32_const(2*n)),s=o.getLocal("pr"),d=o.i32_add(o.getLocal("pr"),o.i32_const(n)),u=o.i32_const(t.alloc(n)),g=o.i32_const(t.alloc(n)),f=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),[...o.call(a+"_zero",s),...o.call(a+"_zero",d)],[...o.call(a+"_inverse",l,u),...o.call(a+"_square",u,g),...o.call(a+"_mul",u,g,f),...o.call(a+"_mul",r,g,s),...o.call(a+"_mul",c,f,d)]))}(),function(){const o=t.addFunction(e+"_inCurveAffine");o.addParam("pIn","i32"),o.setReturnType("i32");const r=o.getCodeBuilder(),c=r.getLocal("pIn"),l=r.i32_add(r.getLocal("pIn"),r.i32_const(n)),s=r.i32_const(t.alloc(n)),d=r.i32_const(t.alloc(n));o.addCode(r.call(a+"_square",l,s),r.call(a+"_square",c,d),r.call(a+"_mul",c,d,d),r.call(a+"_add",d,r.i32_const(i),d),r.ret(r.call(a+"_eq",s,d)))}(),function(){const a=t.addFunction(e+"_inCurve");a.addParam("pIn","i32"),a.setReturnType("i32");const i=a.getCodeBuilder(),o=i.i32_const(t.alloc(2*n));a.addCode(i.call(e+"_toAffine",i.getLocal("pIn"),o),i.ret(i.call(e+"_inCurveAffine",o)))}(),function(){const i=t.addFunction(e+"_batchToAffine");i.addParam("pIn","i32"),i.addParam("n","i32"),i.addParam("pOut","i32"),i.addLocal("pAux","i32"),i.addLocal("itIn","i32"),i.addLocal("itAux","i32"),i.addLocal("itOut","i32"),i.addLocal("i","i32");const o=i.getCodeBuilder(),r=o.i32_const(t.alloc(n));i.addCode(o.setLocal("pAux",o.i32_load(o.i32_const(0))),o.i32_store(o.i32_const(0),o.i32_add(o.getLocal("pAux"),o.i32_mul(o.getLocal("n"),o.i32_const(n)))),o.call(a+"_batchInverse",o.i32_add(o.getLocal("pIn"),o.i32_const(2*n)),o.i32_const(3*n),o.getLocal("n"),o.getLocal("pAux"),o.i32_const(n)),o.setLocal("itIn",o.getLocal("pIn")),o.setLocal("itAux",o.getLocal("pAux")),o.setLocal("itOut",o.getLocal("pOut")),o.setLocal("i",o.i32_const(0)),o.block(o.loop(o.br_if(1,o.i32_eq(o.getLocal("i"),o.getLocal("n"))),o.if(o.call(a+"_isZero",o.getLocal("itAux")),[...o.call(a+"_zero",o.getLocal("itOut")),...o.call(a+"_zero",o.i32_add(o.getLocal("itOut"),o.i32_const(n)))],[...o.call(a+"_mul",o.getLocal("itAux"),o.i32_add(o.getLocal("itIn"),o.i32_const(n)),r),...o.call(a+"_square",o.getLocal("itAux"),o.getLocal("itAux")),...o.call(a+"_mul",o.getLocal("itAux"),o.getLocal("itIn"),o.getLocal("itOut")),...o.call(a+"_mul",o.getLocal("itAux"),r,o.i32_add(o.getLocal("itOut"),o.i32_const(n)))]),o.setLocal("itIn",o.i32_add(o.getLocal("itIn"),o.i32_const(3*n))),o.setLocal("itOut",o.i32_add(o.getLocal("itOut"),o.i32_const(2*n))),o.setLocal("itAux",o.i32_add(o.getLocal("itAux"),o.i32_const(n))),o.setLocal("i",o.i32_add(o.getLocal("i"),o.i32_const(1))),o.br(0))),o.i32_store(o.i32_const(0),o.getLocal("pAux")))}(),function(){const i=t.addFunction(e+"_normalize");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.i32_add(o.getLocal("p1"),o.i32_const(2*n)),s=o.getLocal("pr"),d=o.i32_add(o.getLocal("pr"),o.i32_const(n)),u=o.i32_add(o.getLocal("pr"),o.i32_const(2*n)),g=o.i32_const(t.alloc(n)),f=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),o.call(e+"_zero",o.getLocal("pr")),[...o.call(a+"_inverse",l,g),...o.call(a+"_square",g,f),...o.call(a+"_mul",g,f,_),...o.call(a+"_mul",r,f,s),...o.call(a+"_mul",c,_,d),...o.call(a+"_one",u)]))}(),function(){const a=t.addFunction(e+"__reverseBytes");a.addParam("pIn","i32"),a.addParam("n","i32"),a.addParam("pOut","i32"),a.addLocal("itOut","i32"),a.addLocal("itIn","i32");const i=a.getCodeBuilder();a.addCode(i.setLocal("itOut",i.i32_sub(i.i32_add(i.getLocal("pOut"),i.getLocal("n")),i.i32_const(1))),i.setLocal("itIn",i.getLocal("pIn")),i.block(i.loop(i.br_if(1,i.i32_lt_s(i.getLocal("itOut"),i.getLocal("pOut"))),i.i32_store8(i.getLocal("itOut"),i.i32_load8_u(i.getLocal("itIn"))),i.setLocal("itOut",i.i32_sub(i.getLocal("itOut"),i.i32_const(1))),i.setLocal("itIn",i.i32_add(i.getLocal("itIn"),i.i32_const(1))),i.br(0))))}(),function(){const a=t.addFunction(e+"_LEMtoU");a.addParam("pIn","i32"),a.addParam("pOut","i32");const i=a.getCodeBuilder(),o=t.alloc(2*n),r=i.i32_const(o),c=i.i32_const(o),l=i.i32_const(o+n);a.addCode(i.if(i.call(e+"_isZeroAffine",i.getLocal("pIn")),[...i.call(e+"_zeroAffine",i.getLocal("pOut")),...i.i32_store8(i.getLocal("pOut"),i.i32_const(64)),...i.ret([])]),i.call(e+"_fromMontgomeryAffine",i.getLocal("pIn"),r),i.call(e+"__reverseBytes",c,i.i32_const(n),i.getLocal("pOut")),i.call(e+"__reverseBytes",l,i.i32_const(n),i.i32_add(i.getLocal("pOut"),i.i32_const(n))))}(),function(){const i=t.addFunction(e+"_LEMtoC");i.addParam("pIn","i32"),i.addParam("pOut","i32");const o=i.getCodeBuilder(),r=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("pIn")),[...o.call(a+"_zero",o.getLocal("pOut")),...o.i32_store8(o.getLocal("pOut"),o.i32_const(64)),...o.ret([])]),o.call(a+"_fromMontgomery",o.getLocal("pIn"),r),o.call(e+"__reverseBytes",r,o.i32_const(n),o.getLocal("pOut")),o.if(o.i32_eq(o.call(a+"_sign",o.i32_add(o.getLocal("pIn"),o.i32_const(n))),o.i32_const(-1)),o.i32_store8(o.getLocal("pOut"),o.i32_or(o.i32_load8_u(o.getLocal("pOut")),o.i32_const(128)))))}(),function(){const a=t.addFunction(e+"_UtoLEM");a.addParam("pIn","i32"),a.addParam("pOut","i32");const i=a.getCodeBuilder(),o=t.alloc(2*n),r=i.i32_const(o),c=i.i32_const(o),l=i.i32_const(o+n);a.addCode(i.if(i.i32_and(i.i32_load8_u(i.getLocal("pIn")),i.i32_const(64)),[...i.call(e+"_zeroAffine",i.getLocal("pOut")),...i.ret([])]),i.call(e+"__reverseBytes",i.getLocal("pIn"),i.i32_const(n),c),i.call(e+"__reverseBytes",i.i32_add(i.getLocal("pIn"),i.i32_const(n)),i.i32_const(n),l),i.call(e+"_toMontgomeryAffine",r,i.getLocal("pOut")))}(),function(){const o=t.addFunction(e+"_CtoLEM");o.addParam("pIn","i32"),o.addParam("pOut","i32"),o.addLocal("firstByte","i32"),o.addLocal("greatest","i32");const r=o.getCodeBuilder(),c=t.alloc(2*n),l=r.i32_const(c),s=r.i32_const(c+n);o.addCode(r.setLocal("firstByte",r.i32_load8_u(r.getLocal("pIn"))),r.if(r.i32_and(r.getLocal("firstByte"),r.i32_const(64)),[...r.call(e+"_zeroAffine",r.getLocal("pOut")),...r.ret([])]),r.setLocal("greatest",r.i32_and(r.getLocal("firstByte"),r.i32_const(128))),r.call(a+"_copy",r.getLocal("pIn"),s),r.i32_store8(s,r.i32_and(r.getLocal("firstByte"),r.i32_const(63))),r.call(e+"__reverseBytes",s,r.i32_const(n),l),r.call(a+"_toMontgomery",l,r.getLocal("pOut")),r.call(a+"_square",r.getLocal("pOut"),s),r.call(a+"_mul",r.getLocal("pOut"),s,s),r.call(a+"_add",s,r.i32_const(i),s),r.call(a+"_sqrt",s,s),r.call(a+"_neg",s,l),r.if(r.i32_eq(r.call(a+"_sign",s),r.i32_const(-1)),r.if(r.getLocal("greatest"),r.call(a+"_copy",s,r.i32_add(r.getLocal("pOut"),r.i32_const(n))),r.call(a+"_neg",s,r.i32_add(r.getLocal("pOut"),r.i32_const(n)))),r.if(r.getLocal("greatest"),r.call(a+"_neg",s,r.i32_add(r.getLocal("pOut"),r.i32_const(n))),r.call(a+"_copy",s,r.i32_add(r.getLocal("pOut"),r.i32_const(n))))))}(),Pt(t,e+"_batchLEMtoU",e+"_LEMtoU",2*n,2*n),Pt(t,e+"_batchLEMtoC",e+"_LEMtoC",2*n,n),Pt(t,e+"_batchUtoLEM",e+"_UtoLEM",2*n,2*n),Pt(t,e+"_batchCtoLEM",e+"_CtoLEM",n,2*n,!0),Pt(t,e+"_batchToJacobian",e+"_toJacobian",2*n,3*n,!0),kt(t,e,e+"_multiexp",e+"_add",3*n),kt(t,e,e+"_multiexpAffine",e+"_addMixed",2*n),Mt(t,e+"_timesScalar",3*n,e+"_add",e+"_double",e+"_sub",e+"_copy",e+"_zero"),Mt(t,e+"_timesScalarAffine",2*n,e+"_addMixed",e+"_double",e+"_subMixed",e+"_copyAffine",e+"_zero"),t.exportFunction(e+"_isZero"),t.exportFunction(e+"_isZeroAffine"),t.exportFunction(e+"_eq"),t.exportFunction(e+"_eqMixed"),t.exportFunction(e+"_eqAffine"),t.exportFunction(e+"_copy"),t.exportFunction(e+"_copyAffine"),t.exportFunction(e+"_zero"),t.exportFunction(e+"_zeroAffine"),t.exportFunction(e+"_double"),t.exportFunction(e+"_doubleAffine"),t.exportFunction(e+"_add"),t.exportFunction(e+"_addMixed"),t.exportFunction(e+"_addAffine"),t.exportFunction(e+"_neg"),t.exportFunction(e+"_negAffine"),t.exportFunction(e+"_sub"),t.exportFunction(e+"_subMixed"),t.exportFunction(e+"_subAffine"),t.exportFunction(e+"_fromMontgomery"),t.exportFunction(e+"_fromMontgomeryAffine"),t.exportFunction(e+"_toMontgomery"),t.exportFunction(e+"_toMontgomeryAffine"),t.exportFunction(e+"_timesScalar"),t.exportFunction(e+"_timesScalarAffine"),t.exportFunction(e+"_normalize"),t.exportFunction(e+"_LEMtoU"),t.exportFunction(e+"_LEMtoC"),t.exportFunction(e+"_UtoLEM"),t.exportFunction(e+"_CtoLEM"),t.exportFunction(e+"_batchLEMtoU"),t.exportFunction(e+"_batchLEMtoC"),t.exportFunction(e+"_batchUtoLEM"),t.exportFunction(e+"_batchCtoLEM"),t.exportFunction(e+"_toAffine"),t.exportFunction(e+"_toJacobian"),t.exportFunction(e+"_batchToAffine"),t.exportFunction(e+"_batchToJacobian"),t.exportFunction(e+"_inCurve"),t.exportFunction(e+"_inCurveAffine"),e},Nt=function(t,e,a,i,o){const n=8*t.modules[i].n64,r=8*t.modules[a].n64,c=t.modules[i].q;let l=c.minus(u(1)),s=0;for(;!l.isOdd();)s++,l=l.shiftRight(1);let d=u(2);for(;d.modPow(c.shiftRight(1),c).equals(1);)d=d.add(1);const g=new Array(s+1);g[s]=d.modPow(l,c);let f=s-1;for(;f>=0;)g[f]=g[f+1].modPow(2,c),f--;const _=[],p=u(1).shiftLeft(8*n).mod(c);for(let t=0;t>a);return e}const x=Array(256);for(let t=0;t<256;t++)x[t]=F(t);const v=t.alloc(x);function E(){const a=t.addFunction(e+"_fft");a.addParam("px","i32"),a.addParam("n","i32"),a.addLocal("bits","i32");const o=a.getCodeBuilder(),r=o.i32_const(t.alloc(n));a.addCode(o.setLocal("bits",o.call(e+"__log2",o.getLocal("n"))),o.call(i+"_one",r),o.call(e+"_rawfft",o.getLocal("px"),o.getLocal("bits"),o.i32_const(0),r))}!function(){const a=t.addFunction(e+"__rev");a.addParam("x","i32"),a.addParam("bits","i32"),a.setReturnType("i32");const i=a.getCodeBuilder();a.addCode(i.i32_rotl(i.i32_add(i.i32_add(i.i32_shl(i.i32_load8_u(i.i32_and(i.getLocal("x"),i.i32_const(255)),v,0),i.i32_const(24)),i.i32_shl(i.i32_load8_u(i.i32_and(i.i32_shr_u(i.getLocal("x"),i.i32_const(8)),i.i32_const(255)),v,0),i.i32_const(16))),i.i32_add(i.i32_shl(i.i32_load8_u(i.i32_and(i.i32_shr_u(i.getLocal("x"),i.i32_const(16)),i.i32_const(255)),v,0),i.i32_const(8)),i.i32_load8_u(i.i32_and(i.i32_shr_u(i.getLocal("x"),i.i32_const(24)),i.i32_const(255)),v,0))),i.getLocal("bits")))}(),function(){const i=t.addFunction(e+"__reversePermutation");i.addParam("px","i32"),i.addParam("bits","i32"),i.addLocal("n","i32"),i.addLocal("i","i32"),i.addLocal("ri","i32"),i.addLocal("idx1","i32"),i.addLocal("idx2","i32");const o=i.getCodeBuilder(),n=o.i32_const(t.alloc(r));i.addCode(o.setLocal("n",o.i32_shl(o.i32_const(1),o.getLocal("bits"))),o.setLocal("i",o.i32_const(0)),o.block(o.loop(o.br_if(1,o.i32_eq(o.getLocal("i"),o.getLocal("n"))),o.setLocal("idx1",o.i32_add(o.getLocal("px"),o.i32_mul(o.getLocal("i"),o.i32_const(r)))),o.setLocal("ri",o.call(e+"__rev",o.getLocal("i"),o.getLocal("bits"))),o.setLocal("idx2",o.i32_add(o.getLocal("px"),o.i32_mul(o.getLocal("ri"),o.i32_const(r)))),o.if(o.i32_lt_u(o.getLocal("i"),o.getLocal("ri")),[...o.call(a+"_copy",o.getLocal("idx1"),n),...o.call(a+"_copy",o.getLocal("idx2"),o.getLocal("idx1")),...o.call(a+"_copy",n,o.getLocal("idx2"))]),o.setLocal("i",o.i32_add(o.getLocal("i"),o.i32_const(1))),o.br(0))))}(),function(){const n=t.addFunction(e+"__fftFinal");n.addParam("px","i32"),n.addParam("bits","i32"),n.addParam("reverse","i32"),n.addParam("mulFactor","i32"),n.addLocal("n","i32"),n.addLocal("ndiv2","i32"),n.addLocal("pInv2","i32"),n.addLocal("i","i32"),n.addLocal("mask","i32"),n.addLocal("idx1","i32"),n.addLocal("idx2","i32");const c=n.getCodeBuilder(),l=c.i32_const(t.alloc(r));n.addCode(c.if(c.i32_and(c.i32_eqz(c.getLocal("reverse")),c.call(i+"_isOne",c.getLocal("mulFactor"))),c.ret([])),c.setLocal("n",c.i32_shl(c.i32_const(1),c.getLocal("bits"))),c.setLocal("mask",c.i32_sub(c.getLocal("n"),c.i32_const(1))),c.setLocal("i",c.i32_const(1)),c.setLocal("ndiv2",c.i32_shr_u(c.getLocal("n"),c.i32_const(1))),c.block(c.loop(c.br_if(1,c.i32_ge_u(c.getLocal("i"),c.getLocal("ndiv2"))),c.setLocal("idx1",c.i32_add(c.getLocal("px"),c.i32_mul(c.getLocal("i"),c.i32_const(r)))),c.setLocal("idx2",c.i32_add(c.getLocal("px"),c.i32_mul(c.i32_sub(c.getLocal("n"),c.getLocal("i")),c.i32_const(r)))),c.if(c.getLocal("reverse"),c.if(c.call(i+"_isOne",c.getLocal("mulFactor")),[...c.call(a+"_copy",c.getLocal("idx1"),l),...c.call(a+"_copy",c.getLocal("idx2"),c.getLocal("idx1")),...c.call(a+"_copy",l,c.getLocal("idx2"))],[...c.call(a+"_copy",c.getLocal("idx1"),l),...c.call(o,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx1")),...c.call(o,l,c.getLocal("mulFactor"),c.getLocal("idx2"))]),c.if(c.call(i+"_isOne",c.getLocal("mulFactor")),[],[...c.call(o,c.getLocal("idx1"),c.getLocal("mulFactor"),c.getLocal("idx1")),...c.call(o,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx2"))])),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0))),c.if(c.call(i+"_isOne",c.getLocal("mulFactor")),[],[...c.call(o,c.getLocal("px"),c.getLocal("mulFactor"),c.getLocal("px")),...c.setLocal("idx2",c.i32_add(c.getLocal("px"),c.i32_mul(c.getLocal("ndiv2"),c.i32_const(r)))),...c.call(o,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx2"))]))}(),function(){const c=t.addFunction(e+"_rawfft");c.addParam("px","i32"),c.addParam("bits","i32"),c.addParam("reverse","i32"),c.addParam("mulFactor","i32"),c.addLocal("s","i32"),c.addLocal("k","i32"),c.addLocal("j","i32"),c.addLocal("m","i32"),c.addLocal("mdiv2","i32"),c.addLocal("n","i32"),c.addLocal("pwm","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32");const l=c.getCodeBuilder(),s=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(r)),u=l.i32_const(t.alloc(r));c.addCode(l.call(e+"__reversePermutation",l.getLocal("px"),l.getLocal("bits")),l.setLocal("n",l.i32_shl(l.i32_const(1),l.getLocal("bits"))),l.setLocal("s",l.i32_const(1)),l.block(l.loop(l.br_if(1,l.i32_gt_u(l.getLocal("s"),l.getLocal("bits"))),l.setLocal("m",l.i32_shl(l.i32_const(1),l.getLocal("s"))),l.setLocal("pwm",l.i32_add(l.i32_const(h),l.i32_mul(l.getLocal("s"),l.i32_const(n)))),l.setLocal("k",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_ge_u(l.getLocal("k"),l.getLocal("n"))),l.call(i+"_one",s),l.setLocal("mdiv2",l.i32_shr_u(l.getLocal("m"),l.i32_const(1))),l.setLocal("j",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_ge_u(l.getLocal("j"),l.getLocal("mdiv2"))),l.setLocal("idx1",l.i32_add(l.getLocal("px"),l.i32_mul(l.i32_add(l.getLocal("k"),l.getLocal("j")),l.i32_const(r)))),l.setLocal("idx2",l.i32_add(l.getLocal("idx1"),l.i32_mul(l.getLocal("mdiv2"),l.i32_const(r)))),l.call(o,l.getLocal("idx2"),s,d),l.call(a+"_copy",l.getLocal("idx1"),u),l.call(a+"_add",u,d,l.getLocal("idx1")),l.call(a+"_sub",u,d,l.getLocal("idx2")),l.call(i+"_mul",s,l.getLocal("pwm"),s),l.setLocal("j",l.i32_add(l.getLocal("j"),l.i32_const(1))),l.br(0))),l.setLocal("k",l.i32_add(l.getLocal("k"),l.getLocal("m"))),l.br(0))),l.setLocal("s",l.i32_add(l.getLocal("s"),l.i32_const(1))),l.br(0))),l.call(e+"__fftFinal",l.getLocal("px"),l.getLocal("bits"),l.getLocal("reverse"),l.getLocal("mulFactor")))}(),function(){const a=t.addFunction(e+"__log2");a.addParam("n","i32"),a.setReturnType("i32"),a.addLocal("bits","i32"),a.addLocal("aux","i32");const i=a.getCodeBuilder();a.addCode(i.setLocal("aux",i.i32_shr_u(i.getLocal("n"),i.i32_const(1)))),a.addCode(i.setLocal("bits",i.i32_const(0))),a.addCode(i.block(i.loop(i.br_if(1,i.i32_eqz(i.getLocal("aux"))),i.setLocal("aux",i.i32_shr_u(i.getLocal("aux"),i.i32_const(1))),i.setLocal("bits",i.i32_add(i.getLocal("bits"),i.i32_const(1))),i.br(0)))),a.addCode(i.if(i.i32_ne(i.getLocal("n"),i.i32_shl(i.i32_const(1),i.getLocal("bits"))),i.unreachable())),a.addCode(i.if(i.i32_gt_u(i.getLocal("bits"),i.i32_const(s)),i.unreachable())),a.addCode(i.getLocal("bits"))}(),E(),function(){const a=t.addFunction(e+"_ifft");a.addParam("px","i32"),a.addParam("n","i32"),a.addLocal("bits","i32"),a.addLocal("pInv2","i32");const i=a.getCodeBuilder();a.addCode(i.setLocal("bits",i.call(e+"__log2",i.getLocal("n"))),i.setLocal("pInv2",i.i32_add(i.i32_const(w),i.i32_mul(i.getLocal("bits"),i.i32_const(n)))),i.call(e+"_rawfft",i.getLocal("px"),i.getLocal("bits"),i.i32_const(1),i.getLocal("pInv2")))}(),function(){const c=t.addFunction(e+"_fftJoin");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32");const l=c.getCodeBuilder(),s=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(r)),u=l.i32_const(t.alloc(r));c.addCode(l.call(i+"_copy",l.getLocal("first"),s),l.setLocal("i",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_eq(l.getLocal("i"),l.getLocal("n"))),l.setLocal("idx1",l.i32_add(l.getLocal("pBuff1"),l.i32_mul(l.getLocal("i"),l.i32_const(r)))),l.setLocal("idx2",l.i32_add(l.getLocal("pBuff2"),l.i32_mul(l.getLocal("i"),l.i32_const(r)))),l.call(o,l.getLocal("idx2"),s,d),l.call(a+"_copy",l.getLocal("idx1"),u),l.call(a+"_add",u,d,l.getLocal("idx1")),l.call(a+"_sub",u,d,l.getLocal("idx2")),l.call(i+"_mul",s,l.getLocal("inc"),s),l.setLocal("i",l.i32_add(l.getLocal("i"),l.i32_const(1))),l.br(0))))}(),function(){const c=t.addFunction(e+"_fftJoinExt");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32");const l=c.getCodeBuilder(),s=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(r));c.addCode(l.setLocal("pShiftToM",l.i32_add(l.i32_const(I),l.i32_mul(l.getLocal("totalBits"),l.i32_const(n)))),l.call(i+"_copy",l.getLocal("first"),s),l.setLocal("i",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_eq(l.getLocal("i"),l.getLocal("n"))),l.setLocal("idx1",l.i32_add(l.getLocal("pBuff1"),l.i32_mul(l.getLocal("i"),l.i32_const(r)))),l.setLocal("idx2",l.i32_add(l.getLocal("pBuff2"),l.i32_mul(l.getLocal("i"),l.i32_const(r)))),l.call(a+"_add",l.getLocal("idx1"),l.getLocal("idx2"),d),l.call(o,l.getLocal("idx2"),l.getLocal("pShiftToM"),l.getLocal("idx2")),l.call(a+"_add",l.getLocal("idx1"),l.getLocal("idx2"),l.getLocal("idx2")),l.call(o,l.getLocal("idx2"),s,l.getLocal("idx2")),l.call(a+"_copy",d,l.getLocal("idx1")),l.call(i+"_mul",s,l.getLocal("inc"),s),l.setLocal("i",l.i32_add(l.getLocal("i"),l.i32_const(1))),l.br(0))))}(),function(){const c=t.addFunction(e+"_fftJoinExtInv");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32"),c.addLocal("pSConst","i32");const l=c.getCodeBuilder(),s=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(r));c.addCode(l.setLocal("pShiftToM",l.i32_add(l.i32_const(I),l.i32_mul(l.getLocal("totalBits"),l.i32_const(n)))),l.setLocal("pSConst",l.i32_add(l.i32_const(C),l.i32_mul(l.getLocal("totalBits"),l.i32_const(n)))),l.call(i+"_copy",l.getLocal("first"),s),l.setLocal("i",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_eq(l.getLocal("i"),l.getLocal("n"))),l.setLocal("idx1",l.i32_add(l.getLocal("pBuff1"),l.i32_mul(l.getLocal("i"),l.i32_const(r)))),l.setLocal("idx2",l.i32_add(l.getLocal("pBuff2"),l.i32_mul(l.getLocal("i"),l.i32_const(r)))),l.call(o,l.getLocal("idx2"),s,d),l.call(a+"_sub",l.getLocal("idx1"),d,l.getLocal("idx2")),l.call(o,l.getLocal("idx2"),l.getLocal("pSConst"),l.getLocal("idx2")),l.call(o,l.getLocal("idx1"),l.getLocal("pShiftToM"),l.getLocal("idx1")),l.call(a+"_sub",d,l.getLocal("idx1"),l.getLocal("idx1")),l.call(o,l.getLocal("idx1"),l.getLocal("pSConst"),l.getLocal("idx1")),l.call(i+"_mul",s,l.getLocal("inc"),s),l.setLocal("i",l.i32_add(l.getLocal("i"),l.i32_const(1))),l.br(0))))}(),function(){const c=t.addFunction(e+"_fftMix");c.addParam("pBuff","i32"),c.addParam("n","i32"),c.addParam("exp","i32"),c.addLocal("nGroups","i32"),c.addLocal("nPerGroup","i32"),c.addLocal("nPerGroupDiv2","i32"),c.addLocal("pairOffset","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("j","i32"),c.addLocal("pwm","i32");const l=c.getCodeBuilder(),s=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(r)),u=l.i32_const(t.alloc(r));c.addCode(l.setLocal("nPerGroup",l.i32_shl(l.i32_const(1),l.getLocal("exp"))),l.setLocal("nPerGroupDiv2",l.i32_shr_u(l.getLocal("nPerGroup"),l.i32_const(1))),l.setLocal("nGroups",l.i32_shr_u(l.getLocal("n"),l.getLocal("exp"))),l.setLocal("pairOffset",l.i32_mul(l.getLocal("nPerGroupDiv2"),l.i32_const(r))),l.setLocal("pwm",l.i32_add(l.i32_const(h),l.i32_mul(l.getLocal("exp"),l.i32_const(n)))),l.setLocal("i",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_eq(l.getLocal("i"),l.getLocal("nGroups"))),l.call(i+"_one",s),l.setLocal("j",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_eq(l.getLocal("j"),l.getLocal("nPerGroupDiv2"))),l.setLocal("idx1",l.i32_add(l.getLocal("pBuff"),l.i32_mul(l.i32_add(l.i32_mul(l.getLocal("i"),l.getLocal("nPerGroup")),l.getLocal("j")),l.i32_const(r)))),l.setLocal("idx2",l.i32_add(l.getLocal("idx1"),l.getLocal("pairOffset"))),l.call(o,l.getLocal("idx2"),s,d),l.call(a+"_copy",l.getLocal("idx1"),u),l.call(a+"_add",u,d,l.getLocal("idx1")),l.call(a+"_sub",u,d,l.getLocal("idx2")),l.call(i+"_mul",s,l.getLocal("pwm"),s),l.setLocal("j",l.i32_add(l.getLocal("j"),l.i32_const(1))),l.br(0))),l.setLocal("i",l.i32_add(l.getLocal("i"),l.i32_const(1))),l.br(0))))}(),function(){const i=t.addFunction(e+"_fftFinal");i.addParam("pBuff","i32"),i.addParam("n","i32"),i.addParam("factor","i32"),i.addLocal("idx1","i32"),i.addLocal("idx2","i32"),i.addLocal("i","i32"),i.addLocal("ndiv2","i32");const n=i.getCodeBuilder(),c=n.i32_const(t.alloc(r));i.addCode(n.setLocal("ndiv2",n.i32_shr_u(n.getLocal("n"),n.i32_const(1))),n.if(n.i32_and(n.getLocal("n"),n.i32_const(1)),n.call(o,n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("ndiv2"),n.i32_const(r))),n.getLocal("factor"),n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("ndiv2"),n.i32_const(r))))),n.setLocal("i",n.i32_const(0)),n.block(n.loop(n.br_if(1,n.i32_ge_u(n.getLocal("i"),n.getLocal("ndiv2"))),n.setLocal("idx1",n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("i"),n.i32_const(r)))),n.setLocal("idx2",n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.i32_sub(n.i32_sub(n.getLocal("n"),n.i32_const(1)),n.getLocal("i")),n.i32_const(r)))),n.call(o,n.getLocal("idx2"),n.getLocal("factor"),c),n.call(o,n.getLocal("idx1"),n.getLocal("factor"),n.getLocal("idx2")),n.call(a+"_copy",c,n.getLocal("idx1")),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))}(),function(){const c=t.addFunction(e+"_prepareLagrangeEvaluation");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32"),c.addLocal("pSConst","i32");const l=c.getCodeBuilder(),s=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(r));c.addCode(l.setLocal("pShiftToM",l.i32_add(l.i32_const(I),l.i32_mul(l.getLocal("totalBits"),l.i32_const(n)))),l.setLocal("pSConst",l.i32_add(l.i32_const(C),l.i32_mul(l.getLocal("totalBits"),l.i32_const(n)))),l.call(i+"_copy",l.getLocal("first"),s),l.setLocal("i",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_eq(l.getLocal("i"),l.getLocal("n"))),l.setLocal("idx1",l.i32_add(l.getLocal("pBuff1"),l.i32_mul(l.getLocal("i"),l.i32_const(r)))),l.setLocal("idx2",l.i32_add(l.getLocal("pBuff2"),l.i32_mul(l.getLocal("i"),l.i32_const(r)))),l.call(o,l.getLocal("idx1"),l.getLocal("pShiftToM"),d),l.call(a+"_sub",l.getLocal("idx2"),d,d),l.call(a+"_sub",l.getLocal("idx1"),l.getLocal("idx2"),l.getLocal("idx2")),l.call(o,d,l.getLocal("pSConst"),l.getLocal("idx1")),l.call(o,l.getLocal("idx2"),s,l.getLocal("idx2")),l.call(i+"_mul",s,l.getLocal("inc"),s),l.setLocal("i",l.i32_add(l.getLocal("i"),l.i32_const(1))),l.br(0))))}(),t.exportFunction(e+"_fft"),t.exportFunction(e+"_ifft"),t.exportFunction(e+"_rawfft"),t.exportFunction(e+"_fftJoin"),t.exportFunction(e+"_fftJoinExt"),t.exportFunction(e+"_fftJoinExtInv"),t.exportFunction(e+"_fftMix"),t.exportFunction(e+"_fftFinal"),t.exportFunction(e+"_prepareLagrangeEvaluation")},Tt=function(t,e,a){const i=8*t.modules[a].n64;return function(){const o=t.addFunction(e+"_zero");o.addParam("px","i32"),o.addParam("n","i32"),o.addLocal("lastp","i32"),o.addLocal("p","i32");const n=o.getCodeBuilder();o.addCode(n.setLocal("p",n.getLocal("px")),n.setLocal("lastp",n.i32_add(n.getLocal("px"),n.i32_mul(n.getLocal("n"),n.i32_const(i)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("p"),n.getLocal("lastp"))),n.call(a+"_zero",n.getLocal("p")),n.setLocal("p",n.i32_add(n.getLocal("p"),n.i32_const(i))),n.br(0))))}(),function(){const o=t.addFunction(e+"_constructLC");o.addParam("ppolynomials","i32"),o.addParam("psignals","i32"),o.addParam("nSignals","i32"),o.addParam("pres","i32"),o.addLocal("i","i32"),o.addLocal("j","i32"),o.addLocal("pp","i32"),o.addLocal("ps","i32"),o.addLocal("pd","i32"),o.addLocal("ncoefs","i32");const n=o.getCodeBuilder(),r=n.i32_const(t.alloc(i));o.addCode(n.setLocal("i",n.i32_const(0)),n.setLocal("pp",n.getLocal("ppolynomials")),n.setLocal("ps",n.getLocal("psignals")),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("i"),n.getLocal("nSignals"))),n.setLocal("ncoefs",n.i32_load(n.getLocal("pp"))),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(4))),n.setLocal("j",n.i32_const(0)),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("j"),n.getLocal("ncoefs"))),n.setLocal("pd",n.i32_add(n.getLocal("pres"),n.i32_mul(n.i32_load(n.getLocal("pp")),n.i32_const(i)))),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(4))),n.call(a+"_mul",n.getLocal("ps"),n.getLocal("pp"),r),n.call(a+"_add",r,n.getLocal("pd"),n.getLocal("pd")),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(i))),n.setLocal("j",n.i32_add(n.getLocal("j"),n.i32_const(1))),n.br(0))),n.setLocal("ps",n.i32_add(n.getLocal("ps"),n.i32_const(i))),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))}(),t.exportFunction(e+"_zero"),t.exportFunction(e+"_constructLC"),e},Dt=function(t,e,a){const i=8*t.modules[a].n64;return function(){const o=t.addFunction(e+"_buildABC");o.addParam("pCoefs","i32"),o.addParam("nCoefs","i32"),o.addParam("pWitness","i32"),o.addParam("pA","i32"),o.addParam("pB","i32"),o.addParam("pC","i32"),o.addParam("offsetOut","i32"),o.addParam("nOut","i32"),o.addParam("offsetWitness","i32"),o.addParam("nWitness","i32"),o.addLocal("it","i32"),o.addLocal("ita","i32"),o.addLocal("itb","i32"),o.addLocal("last","i32"),o.addLocal("m","i32"),o.addLocal("c","i32"),o.addLocal("s","i32"),o.addLocal("pOut","i32");const n=o.getCodeBuilder(),r=n.i32_const(t.alloc(i));o.addCode(n.setLocal("ita",n.getLocal("pA")),n.setLocal("itb",n.getLocal("pB")),n.setLocal("last",n.i32_add(n.getLocal("pA"),n.i32_mul(n.getLocal("nOut"),n.i32_const(i)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(a+"_zero",n.getLocal("ita")),n.call(a+"_zero",n.getLocal("itb")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(i))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(i))),n.br(0))),n.setLocal("it",n.getLocal("pCoefs")),n.setLocal("last",n.i32_add(n.getLocal("pCoefs"),n.i32_mul(n.getLocal("nCoefs"),n.i32_const(i+12)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("it"),n.getLocal("last"))),n.setLocal("s",n.i32_load(n.getLocal("it"),8)),n.if(n.i32_or(n.i32_lt_u(n.getLocal("s"),n.getLocal("offsetWitness")),n.i32_ge_u(n.getLocal("s"),n.i32_add(n.getLocal("offsetWitness"),n.getLocal("nWitness")))),[...n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(i+12))),...n.br(1)]),n.setLocal("m",n.i32_load(n.getLocal("it"))),n.if(n.i32_eq(n.getLocal("m"),n.i32_const(0)),n.setLocal("pOut",n.getLocal("pA")),n.if(n.i32_eq(n.getLocal("m"),n.i32_const(1)),n.setLocal("pOut",n.getLocal("pB")),[...n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(i+12))),...n.br(1)])),n.setLocal("c",n.i32_load(n.getLocal("it"),4)),n.if(n.i32_or(n.i32_lt_u(n.getLocal("c"),n.getLocal("offsetOut")),n.i32_ge_u(n.getLocal("c"),n.i32_add(n.getLocal("offsetOut"),n.getLocal("nOut")))),[...n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(i+12))),...n.br(1)]),n.setLocal("pOut",n.i32_add(n.getLocal("pOut"),n.i32_mul(n.i32_sub(n.getLocal("c"),n.getLocal("offsetOut")),n.i32_const(i)))),n.call(a+"_mul",n.i32_add(n.getLocal("pWitness"),n.i32_mul(n.i32_sub(n.getLocal("s"),n.getLocal("offsetWitness")),n.i32_const(i))),n.i32_add(n.getLocal("it"),n.i32_const(12)),r),n.call(a+"_add",n.getLocal("pOut"),r,n.getLocal("pOut")),n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(i+12))),n.br(0))),n.setLocal("ita",n.getLocal("pA")),n.setLocal("itb",n.getLocal("pB")),n.setLocal("it",n.getLocal("pC")),n.setLocal("last",n.i32_add(n.getLocal("pA"),n.i32_mul(n.getLocal("nOut"),n.i32_const(i)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(a+"_mul",n.getLocal("ita"),n.getLocal("itb"),n.getLocal("it")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(i))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(i))),n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(i))),n.br(0))))}(),function(){const o=t.addFunction(e+"_joinABC");o.addParam("pA","i32"),o.addParam("pB","i32"),o.addParam("pC","i32"),o.addParam("n","i32"),o.addParam("pP","i32"),o.addLocal("ita","i32"),o.addLocal("itb","i32"),o.addLocal("itc","i32"),o.addLocal("itp","i32"),o.addLocal("last","i32");const n=o.getCodeBuilder(),r=n.i32_const(t.alloc(i));o.addCode(n.setLocal("ita",n.getLocal("pA")),n.setLocal("itb",n.getLocal("pB")),n.setLocal("itc",n.getLocal("pC")),n.setLocal("itp",n.getLocal("pP")),n.setLocal("last",n.i32_add(n.getLocal("pA"),n.i32_mul(n.getLocal("n"),n.i32_const(i)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(a+"_mul",n.getLocal("ita"),n.getLocal("itb"),r),n.call(a+"_sub",r,n.getLocal("itc"),n.getLocal("itp")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(i))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(i))),n.setLocal("itc",n.i32_add(n.getLocal("itc"),n.i32_const(i))),n.setLocal("itp",n.i32_add(n.getLocal("itp"),n.i32_const(i))),n.br(0))))}(),function(){const o=t.addFunction(e+"_batchAdd");o.addParam("pa","i32"),o.addParam("pb","i32"),o.addParam("n","i32"),o.addParam("pr","i32"),o.addLocal("ita","i32"),o.addLocal("itb","i32"),o.addLocal("itr","i32"),o.addLocal("last","i32");const n=o.getCodeBuilder();o.addCode(n.setLocal("ita",n.getLocal("pa")),n.setLocal("itb",n.getLocal("pb")),n.setLocal("itr",n.getLocal("pr")),n.setLocal("last",n.i32_add(n.getLocal("pa"),n.i32_mul(n.getLocal("n"),n.i32_const(i)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(a+"_add",n.getLocal("ita"),n.getLocal("itb"),n.getLocal("itr")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(i))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(i))),n.setLocal("itr",n.i32_add(n.getLocal("itr"),n.i32_const(i))),n.br(0))))}(),t.exportFunction(e+"_buildABC"),t.exportFunction(e+"_joinABC"),t.exportFunction(e+"_batchAdd"),e},Kt=function(t,e,a,i,o,n,r,c){const l=t.addFunction(e);l.addParam("pIn","i32"),l.addParam("n","i32"),l.addParam("pFirst","i32"),l.addParam("pInc","i32"),l.addParam("pOut","i32"),l.addLocal("pOldFree","i32"),l.addLocal("i","i32"),l.addLocal("pFrom","i32"),l.addLocal("pTo","i32");const s=l.getCodeBuilder(),d=s.i32_const(t.alloc(r));l.addCode(s.setLocal("pFrom",s.getLocal("pIn")),s.setLocal("pTo",s.getLocal("pOut"))),l.addCode(s.call(i+"_copy",s.getLocal("pFirst"),d)),l.addCode(s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.call(c,s.getLocal("pFrom"),d,s.getLocal("pTo")),s.setLocal("pFrom",s.i32_add(s.getLocal("pFrom"),s.i32_const(o))),s.setLocal("pTo",s.i32_add(s.getLocal("pTo"),s.i32_const(n))),s.call(i+"_mul",d,s.getLocal("pInc"),d),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0)))),t.exportFunction(e)},Vt=function(t,e){const a=e||"bn128";if(t.modules[a])return a;const i=u("21888242871839275222246405745257275088696311157297823662689037894645226208583"),o=u("21888242871839275222246405745257275088548364400416034343698204186575808495617"),n=Math.floor((i.minus(1).bitLength()-1)/64)+1,r=8*n,c=r,l=r,s=2*l,d=12*l,g=t.alloc(Et(o,c)),f=Ut(t,i,"f1m");zt(t,o,"fr","frm");const _=t.alloc(Et(A(u(3)),l)),p=Rt(t,"g1m","f1m",_);Nt(t,"frm","frm","frm","frm_mul"),Tt(t,"pol","frm"),Dt(t,"qap","frm");const h=qt(t,"f1m_neg","f2m","f1m"),m=t.alloc([...Et(A(u("19485874751759354771024239261021720505790618469301721065564631296452457478373")),l),...Et(A(u("266929791119991161246907387137283842545076965332900288569378510910307636690")),l)]),L=Rt(t,"g2m","f2m",m);function w(e,a){const i=t.addFunction(e);i.addParam("pG","i32"),i.addParam("pFr","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),n=o.i32_const(t.alloc(r));i.addCode(o.call("frm_fromMontgomery",o.getLocal("pFr"),n),o.call(a,o.getLocal("pG"),n,o.i32_const(r),o.getLocal("pr"))),t.exportFunction(e)}function A(t){return u(t).times(u.one.shiftLeft(8*l)).mod(i)}w("g1m_timesFr","g1m_timesScalar"),Nt(t,"g1m","g1m","frm","g1m_timesFr"),w("g2m_timesFr","g2m_timesScalar"),Nt(t,"g2m","g2m","frm","g2m_timesFr"),w("g1m_timesFrAffine","g1m_timesScalarAffine"),w("g2m_timesFrAffine","g2m_timesScalarAffine"),Kt(t,"frm_batchApplyKey",0,"frm",r,r,r,"frm_mul"),Kt(t,"g1m_batchApplyKey",0,"frm",3*r,3*r,r,"g1m_timesFr"),Kt(t,"g1m_batchApplyKeyMixed",0,"frm",2*r,3*r,r,"g1m_timesFrAffine"),Kt(t,"g2m_batchApplyKey",0,"frm",2*r*3,3*r*2,r,"g2m_timesFr"),Kt(t,"g2m_batchApplyKeyMixed",0,"frm",2*r*2,3*r*2,r,"g2m_timesFrAffine");const b=[u("1"),u("2"),u.one],y=t.alloc([...Et(A(b[0]),l),...Et(A(b[1]),l),...Et(A(b[2]),l)]),I=[u.zero,u.one,u.zero],C=t.alloc([...Et(A(I[0]),l),...Et(A(I[1]),l),...Et(A(I[2]),l)]),F=[[u("10857046999023057135944570762232829481370756359578518086990519993285655852781"),u("11559732032986387107991004021392285783925812861821192530917403151452391805634")],[u("8495653923123431417604973247489272438418190587263600148770280649306958101930"),u("4082367875863433681332203403145435568316851327593401208105741076214120093531")],[u.one,u.zero]],x=t.alloc([...Et(A(F[0][0]),l),...Et(A(F[0][1]),l),...Et(A(F[1][0]),l),...Et(A(F[1][1]),l),...Et(A(F[2][0]),l),...Et(A(F[2][1]),l)]),v=[[u.zero,u.zero],[u.one,u.zero],[u.zero,u.zero]],E=t.alloc([...Et(A(v[0][0]),l),...Et(A(v[0][1]),l),...Et(A(v[1][0]),l),...Et(A(v[1][1]),l),...Et(A(v[2][0]),l),...Et(A(v[2][1]),l)]),B=t.alloc([...Et(A(1),l),...Et(A(0),l),...Et(A(0),l),...Et(A(0),l),...Et(A(0),l),...Et(A(0),l),...Et(A(0),l),...Et(A(0),l),...Et(A(0),l),...Et(A(0),l),...Et(A(0),l),...Et(A(0),l)]),S=t.alloc([...Et(A(9),l),...Et(A(1),l)]),G=t.alloc([...Et(A(u(2).modInv(i)),l),...Et(u(0),l)]),P=S,O=t.alloc([...Et(A("19485874751759354771024239261021720505790618469301721065564631296452457478373"),l),...Et(A("266929791119991161246907387137283842545076965332900288569378510910307636690"),l)]);!function(){const e=t.addFunction(a+"_mulNR6");e.addParam("x","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder();e.addCode(i.call(h+"_mul",i.i32_const(S),i.getLocal("x"),i.getLocal("pr")))}();const U=Qt(t,a+"_mulNR6","f6m","f2m");!function(){const e=t.addFunction(a+"_mulNR12");e.addParam("x","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder();e.addCode(i.call(h+"_mul",i.i32_const(S),i.i32_add(i.getLocal("x"),i.i32_const(4*r)),i.getLocal("pr")),i.call(h+"_copy",i.getLocal("x"),i.i32_add(i.getLocal("pr"),i.i32_const(2*r))),i.call(h+"_copy",i.i32_add(i.getLocal("x"),i.i32_const(2*r)),i.i32_add(i.getLocal("pr"),i.i32_const(4*r))))}();const z=qt(t,a+"_mulNR12","ftm",U),q=function(t){let e=t;const a=[];for(;e.gt(u.zero);)e.isOdd()?a.push(1):a.push(0),e=e.shiftRight(1);return a}(u("29793968203157093288")),Q=t.alloc(q),M=3*s,k=q.length-1,R=q.reduce(((t,e)=>t+(0!=e?1:0)),0),N=6*r,T=3*r*2+(R+k+1)*M;t.modules[a]={n64:n,pG1gen:y,pG1zero:C,pG1b:_,pG2gen:x,pG2zero:E,pG2b:m,pq:t.modules.f1m.pq,pr:g,pOneT:B,prePSize:N,preQSize:T,r:o.toString(),q:i.toString()};const D=u("4965661367192848881");function K(e){const o=[[[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")]],[[u("1"),u("0")],[u("8376118865763821496583973867626364092589906065868298776909617916018768340080"),u("16469823323077808223889137241176536799009286646108169935659301613961712198316")],[u("21888242871839275220042445260109153167277707414472061641714758635765020556617"),u("0")],[u("11697423496358154304825782922584725312912383441159505038794027105778954184319"),u("303847389135065887422783454877609941456349188919719272345083954437860409601")],[u("21888242871839275220042445260109153167277707414472061641714758635765020556616"),u("0")],[u("3321304630594332808241809054958361220322477375291206261884409189760185844239"),u("5722266937896532885780051958958348231143373700109372999374820235121374419868")],[u("21888242871839275222246405745257275088696311157297823662689037894645226208582"),u("0")],[u("13512124006075453725662431877630910996106405091429524885779419978626457868503"),u("5418419548761466998357268504080738289687024511189653727029736280683514010267")],[u("2203960485148121921418603742825762020974279258880205651966"),u("0")],[u("10190819375481120917420622822672549775783927716138318623895010788866272024264"),u("21584395482704209334823622290379665147239961968378104390343953940207365798982")],[u("2203960485148121921418603742825762020974279258880205651967"),u("0")],[u("18566938241244942414004596690298913868373833782006617400804628704885040364344"),u("16165975933942742336466353786298926857552937457188450663314217659523851788715")]]],n=[[[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")]],[[u("1"),u("0")],[u("21575463638280843010398324269430826099269044274347216827212613867836435027261"),u("10307601595873709700152284273816112264069230130616436755625194854815875713954")],[u("21888242871839275220042445260109153167277707414472061641714758635765020556616"),u("0")],[u("3772000881919853776433695186713858239009073593817195771773381919316419345261"),u("2236595495967245188281701248203181795121068902605861227855261137820944008926")],[u("2203960485148121921418603742825762020974279258880205651966"),u("0")],[u("18429021223477853657660792034369865839114504446431234726392080002137598044644"),u("9344045779998320333812420223237981029506012124075525679208581902008406485703")]],[[u("1"),u("0")],[u("2581911344467009335267311115468803099551665605076196740867805258568234346338"),u("19937756971775647987995932169929341994314640652964949448313374472400716661030")],[u("2203960485148121921418603742825762020974279258880205651966"),u("0")],[u("5324479202449903542726783395506214481928257762400643279780343368557297135718"),u("16208900380737693084919495127334387981393726419856888799917914180988844123039")],[u("21888242871839275220042445260109153167277707414472061641714758635765020556616"),u("0")],[u("13981852324922362344252311234282257507216387789820983642040889267519694726527"),u("7629828391165209371577384193250820201684255241773809077146787135900891633097")]]],r=t.addFunction(a+"__frobeniusMap"+e);r.addParam("x","i32"),r.addParam("r","i32");const c=r.getCodeBuilder();for(let a=0;a<6;a++){const i=0==a?c.getLocal("x"):c.i32_add(c.getLocal("x"),c.i32_const(a*s)),u=i,g=c.i32_add(c.getLocal("x"),c.i32_const(a*s+l)),_=0==a?c.getLocal("r"):c.i32_add(c.getLocal("r"),c.i32_const(a*s)),p=_,m=c.i32_add(c.getLocal("r"),c.i32_const(a*s+l)),L=d(o[Math.floor(a/3)][e%12],n[a%3][e%6]),w=t.alloc([...Et(A(L[0]),32),...Et(A(L[1]),32)]);e%2==1?r.addCode(c.call(f+"_copy",u,p),c.call(f+"_neg",g,m),c.call(h+"_mul",_,c.i32_const(w),_)):r.addCode(c.call(h+"_mul",i,c.i32_const(w),_))}function d(t,e){const a=u(t[0]),o=u(t[1]),n=u(e[0]),r=u(e[1]),c=[a.times(n).minus(o.times(r)).mod(i),a.times(r).add(o.times(n)).mod(i)];return c[0].isNegative()&&(c[0]=c[0].add(i)),c}}function V(e,i){const o=function(t){let e=t;const a=[];for(;e.gt(u.zero);){if(e.isOdd()){const t=2-e.mod(4).toJSNumber();a.push(t),e=e.minus(t)}else a.push(0);e=e.shiftRight(1)}return a}(e).map((t=>-1==t?255:t)),n=t.alloc(o);t.alloc(Et(e,32));const r=t.addFunction(a+"__cyclotomicExp_"+i);r.addParam("x","i32"),r.addParam("r","i32"),r.addLocal("bit","i32"),r.addLocal("i","i32");const c=r.getCodeBuilder(),l=c.getLocal("x"),s=c.getLocal("r"),g=c.i32_const(t.alloc(d));r.addCode(c.call(z+"_conjugate",l,g),c.call(z+"_one",s),c.if(c.teeLocal("bit",c.i32_load8_s(c.i32_const(o.length-1),n)),c.if(c.i32_eq(c.getLocal("bit"),c.i32_const(1)),c.call(z+"_mul",s,l,s),c.call(z+"_mul",s,g,s))),c.setLocal("i",c.i32_const(o.length-2)),c.block(c.loop(c.call(a+"__cyclotomicSquare",s,s),c.if(c.teeLocal("bit",c.i32_load8_s(c.getLocal("i"),n)),c.if(c.i32_eq(c.getLocal("bit"),c.i32_const(1)),c.call(z+"_mul",s,l,s),c.call(z+"_mul",s,g,s))),c.br_if(1,c.i32_eqz(c.getLocal("i"))),c.setLocal("i",c.i32_sub(c.getLocal("i"),c.i32_const(1))),c.br(0))))}function j(){!function(){const e=t.addFunction(a+"__cyclotomicSquare");e.addParam("x","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("x"),n=i.i32_add(i.getLocal("x"),i.i32_const(s)),r=i.i32_add(i.getLocal("x"),i.i32_const(2*s)),c=i.i32_add(i.getLocal("x"),i.i32_const(3*s)),l=i.i32_add(i.getLocal("x"),i.i32_const(4*s)),d=i.i32_add(i.getLocal("x"),i.i32_const(5*s)),u=i.getLocal("r"),g=i.i32_add(i.getLocal("r"),i.i32_const(s)),f=i.i32_add(i.getLocal("r"),i.i32_const(2*s)),_=i.i32_add(i.getLocal("r"),i.i32_const(3*s)),p=i.i32_add(i.getLocal("r"),i.i32_const(4*s)),m=i.i32_add(i.getLocal("r"),i.i32_const(5*s)),L=i.i32_const(t.alloc(s)),w=i.i32_const(t.alloc(s)),A=i.i32_const(t.alloc(s)),b=i.i32_const(t.alloc(s)),y=i.i32_const(t.alloc(s)),I=i.i32_const(t.alloc(s)),C=i.i32_const(t.alloc(s)),F=i.i32_const(t.alloc(s));e.addCode(i.call(h+"_mul",o,l,C),i.call(h+"_mul",l,i.i32_const(S),L),i.call(h+"_add",o,L,L),i.call(h+"_add",o,l,F),i.call(h+"_mul",F,L,L),i.call(h+"_mul",i.i32_const(S),C,F),i.call(h+"_add",C,F,F),i.call(h+"_sub",L,F,L),i.call(h+"_add",C,C,w),i.call(h+"_mul",c,r,C),i.call(h+"_mul",r,i.i32_const(S),A),i.call(h+"_add",c,A,A),i.call(h+"_add",c,r,F),i.call(h+"_mul",F,A,A),i.call(h+"_mul",i.i32_const(S),C,F),i.call(h+"_add",C,F,F),i.call(h+"_sub",A,F,A),i.call(h+"_add",C,C,b),i.call(h+"_mul",n,d,C),i.call(h+"_mul",d,i.i32_const(S),y),i.call(h+"_add",n,y,y),i.call(h+"_add",n,d,F),i.call(h+"_mul",F,y,y),i.call(h+"_mul",i.i32_const(S),C,F),i.call(h+"_add",C,F,F),i.call(h+"_sub",y,F,y),i.call(h+"_add",C,C,I),i.call(h+"_sub",L,o,u),i.call(h+"_add",u,u,u),i.call(h+"_add",L,u,u),i.call(h+"_add",w,l,p),i.call(h+"_add",p,p,p),i.call(h+"_add",w,p,p),i.call(h+"_mul",I,i.i32_const(P),F),i.call(h+"_add",F,c,_),i.call(h+"_add",_,_,_),i.call(h+"_add",F,_,_),i.call(h+"_sub",y,r,f),i.call(h+"_add",f,f,f),i.call(h+"_add",y,f,f),i.call(h+"_sub",A,n,g),i.call(h+"_add",g,g,g),i.call(h+"_add",A,g,g),i.call(h+"_add",b,d,m),i.call(h+"_add",m,m,m),i.call(h+"_add",b,m,m))}(),V(D,"w0");const e=t.addFunction(a+"__finalExponentiationLastChunk");e.addParam("x","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("x"),n=i.getLocal("r"),r=i.i32_const(t.alloc(d)),c=i.i32_const(t.alloc(d)),l=i.i32_const(t.alloc(d)),u=i.i32_const(t.alloc(d)),g=i.i32_const(t.alloc(d)),f=i.i32_const(t.alloc(d)),_=i.i32_const(t.alloc(d)),p=i.i32_const(t.alloc(d)),m=i.i32_const(t.alloc(d)),L=i.i32_const(t.alloc(d)),w=i.i32_const(t.alloc(d)),A=i.i32_const(t.alloc(d)),b=i.i32_const(t.alloc(d)),y=i.i32_const(t.alloc(d)),I=i.i32_const(t.alloc(d)),C=i.i32_const(t.alloc(d)),F=i.i32_const(t.alloc(d)),x=i.i32_const(t.alloc(d)),v=i.i32_const(t.alloc(d)),E=i.i32_const(t.alloc(d)),B=i.i32_const(t.alloc(d));e.addCode(i.call(a+"__cyclotomicExp_w0",o,r),i.call(z+"_conjugate",r,r),i.call(a+"__cyclotomicSquare",r,c),i.call(a+"__cyclotomicSquare",c,l),i.call(z+"_mul",l,c,u),i.call(a+"__cyclotomicExp_w0",u,g),i.call(z+"_conjugate",g,g),i.call(a+"__cyclotomicSquare",g,f),i.call(a+"__cyclotomicExp_w0",f,_),i.call(z+"_conjugate",_,_),i.call(z+"_conjugate",u,p),i.call(z+"_conjugate",_,m),i.call(z+"_mul",m,g,L),i.call(z+"_mul",L,p,w),i.call(z+"_mul",w,c,A),i.call(z+"_mul",w,g,b),i.call(z+"_mul",b,o,y),i.call(a+"__frobeniusMap1",A,I),i.call(z+"_mul",I,y,C),i.call(a+"__frobeniusMap2",w,F),i.call(z+"_mul",F,C,x),i.call(z+"_conjugate",o,v),i.call(z+"_mul",v,A,E),i.call(a+"__frobeniusMap3",E,B),i.call(z+"_mul",B,x,n))}const H=t.alloc(N),$=t.alloc(T);function Z(e){const i=t.addFunction(a+"_pairingEq"+e);for(let t=0;tt+(0!=e?1:0)),0),R=6*r,N=3*r*2+(k+M+1)*Q,T=u("15132376222941642752");function D(e){const a=[[[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")]],[[u("1"),u("0")],[u("3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760"),u("151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027")],[u("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351"),u("0")],[u("2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530"),u("1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257")],[u("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),u("0")],[u("3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557"),u("877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230")],[u("4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559786"),u("0")],[u("151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027"),u("3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760")],[u("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),u("0")],[u("1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257"),u("2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530")],[u("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437"),u("0")],[u("877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230"),u("3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557")]]],o=[[[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")]],[[u("1"),u("0")],[u("0"),u("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436")],[u("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),u("0")],[u("0"),u("1")],[u("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),u("0")],[u("0"),u("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350")]],[[u("1"),u("0")],[u("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437"),u("0")],[u("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),u("0")],[u("4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559786"),u("0")],[u("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),u("0")],[u("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351"),u("0")]]],n=t.addFunction(U+"_frobeniusMap"+e);n.addParam("x","i32"),n.addParam("r","i32");const s=n.getCodeBuilder();for(let i=0;i<6;i++){const u=0==i?s.getLocal("x"):s.i32_add(s.getLocal("x"),s.i32_const(i*l)),g=u,f=s.i32_add(s.getLocal("x"),s.i32_const(i*l+c)),_=0==i?s.getLocal("r"):s.i32_add(s.getLocal("r"),s.i32_const(i*l)),h=_,m=s.i32_add(s.getLocal("r"),s.i32_const(i*l+c)),w=d(a[Math.floor(i/3)][e%12],o[i%3][e%6]),A=t.alloc([...Et(y(w[0]),r),...Et(y(w[1]),r)]);e%2==1?n.addCode(s.call(p+"_copy",g,h),s.call(p+"_neg",f,m),s.call(L+"_mul",_,s.i32_const(A),_)):n.addCode(s.call(L+"_mul",u,s.i32_const(A),_))}function d(t,e){const a=u(t[0]),o=u(t[1]),n=u(e[0]),r=u(e[1]),c=[a.times(n).minus(o.times(r)).mod(i),a.times(r).add(o.times(n)).mod(i)];return c[0].isNegative()&&(c[0]=c[0].add(i)),c}}function K(e,i,o){const n=function(t){let e=t;const a=[];for(;e.gt(u.zero);){if(e.isOdd()){const t=2-e.mod(4).toJSNumber();a.push(t),e=e.minus(t)}else a.push(0);e=e.shiftRight(1)}return a}(e).map((t=>-1==t?255:t)),r=t.alloc(n),c=t.addFunction(a+"__cyclotomicExp_"+o);c.addParam("x","i32"),c.addParam("r","i32"),c.addLocal("bit","i32"),c.addLocal("i","i32");const l=c.getCodeBuilder(),d=l.getLocal("x"),g=l.getLocal("r"),f=l.i32_const(t.alloc(s));c.addCode(l.call(U+"_conjugate",d,f),l.call(U+"_one",g),l.if(l.teeLocal("bit",l.i32_load8_s(l.i32_const(n.length-1),r)),l.if(l.i32_eq(l.getLocal("bit"),l.i32_const(1)),l.call(U+"_mul",g,d,g),l.call(U+"_mul",g,f,g))),l.setLocal("i",l.i32_const(n.length-2)),l.block(l.loop(l.call(a+"__cyclotomicSquare",g,g),l.if(l.teeLocal("bit",l.i32_load8_s(l.getLocal("i"),r)),l.if(l.i32_eq(l.getLocal("bit"),l.i32_const(1)),l.call(U+"_mul",g,d,g),l.call(U+"_mul",g,f,g))),l.br_if(1,l.i32_eqz(l.getLocal("i"))),l.setLocal("i",l.i32_sub(l.getLocal("i"),l.i32_const(1))),l.br(0)))),i&&c.addCode(l.call(U+"_conjugate",g,g))}t.modules[a]={n64q:n,n64r:d,n8q:r,n8r:g,pG1gen:C,pG1zero:x,pG1b:h,pG2gen:E,pG2zero:S,pG2b:w,pq:t.modules.f1m.pq,pr:_,pOneT:G,r:o,q:i,prePSize:R,preQSize:N},function(){const e=t.addFunction(O+"_mul1");e.addParam("pA","i32"),e.addParam("pC1","i32"),e.addParam("pR","i32");const a=e.getCodeBuilder(),i=a.getLocal("pA"),o=a.i32_add(a.getLocal("pA"),a.i32_const(2*c)),n=a.i32_add(a.getLocal("pA"),a.i32_const(4*c)),r=a.getLocal("pC1"),l=a.getLocal("pR"),s=a.i32_add(a.getLocal("pR"),a.i32_const(2*c)),d=a.i32_add(a.getLocal("pR"),a.i32_const(4*c)),u=a.i32_const(t.alloc(2*c)),g=a.i32_const(t.alloc(2*c));e.addCode(a.call(L+"_add",i,o,u),a.call(L+"_add",o,n,g),a.call(L+"_mul",o,r,d),a.call(L+"_mul",g,r,l),a.call(L+"_sub",l,d,l),a.call(L+"_mulNR",l,l),a.call(L+"_mul",u,r,s),a.call(L+"_sub",s,d,s))}(),function(){const e=t.addFunction(O+"_mul01");e.addParam("pA","i32"),e.addParam("pC0","i32"),e.addParam("pC1","i32"),e.addParam("pR","i32");const a=e.getCodeBuilder(),i=a.getLocal("pA"),o=a.i32_add(a.getLocal("pA"),a.i32_const(2*c)),n=a.i32_add(a.getLocal("pA"),a.i32_const(4*c)),r=a.getLocal("pC0"),l=a.getLocal("pC1"),s=a.getLocal("pR"),d=a.i32_add(a.getLocal("pR"),a.i32_const(2*c)),u=a.i32_add(a.getLocal("pR"),a.i32_const(4*c)),g=a.i32_const(t.alloc(2*c)),f=a.i32_const(t.alloc(2*c)),_=a.i32_const(t.alloc(2*c)),p=a.i32_const(t.alloc(2*c));e.addCode(a.call(L+"_mul",i,r,g),a.call(L+"_mul",o,l,f),a.call(L+"_add",i,o,_),a.call(L+"_add",i,n,p),a.call(L+"_add",o,n,s),a.call(L+"_mul",s,l,s),a.call(L+"_sub",s,f,s),a.call(L+"_mulNR",s,s),a.call(L+"_add",s,g,s),a.call(L+"_add",r,l,d),a.call(L+"_mul",d,_,d),a.call(L+"_sub",d,g,d),a.call(L+"_sub",d,f,d),a.call(L+"_mul",p,r,u),a.call(L+"_sub",u,g,u),a.call(L+"_add",u,f,u))}(),function(){const e=t.addFunction(U+"_mul014");e.addParam("pA","i32"),e.addParam("pC0","i32"),e.addParam("pC1","i32"),e.addParam("pC4","i32"),e.addParam("pR","i32");const a=e.getCodeBuilder(),i=a.getLocal("pA"),o=a.i32_add(a.getLocal("pA"),a.i32_const(6*c)),n=a.getLocal("pC0"),r=a.getLocal("pC1"),l=a.getLocal("pC4"),s=a.i32_const(t.alloc(6*c)),d=a.i32_const(t.alloc(6*c)),u=a.i32_const(t.alloc(2*c)),g=a.getLocal("pR"),f=a.i32_add(a.getLocal("pR"),a.i32_const(6*c));e.addCode(a.call(O+"_mul01",i,n,r,s),a.call(O+"_mul1",o,l,d),a.call(L+"_add",r,l,u),a.call(O+"_add",o,i,f),a.call(O+"_mul01",f,n,u,f),a.call(O+"_sub",f,s,f),a.call(O+"_sub",f,d,f),a.call(O+"_copy",d,g),a.call(O+"_mulNR",g,g),a.call(O+"_add",g,s,g))}(),function(){const e=t.addFunction(a+"_ell");e.addParam("pP","i32"),e.addParam("pCoefs","i32"),e.addParam("pF","i32");const i=e.getCodeBuilder(),o=i.getLocal("pP"),n=i.i32_add(i.getLocal("pP"),i.i32_const(r)),l=i.getLocal("pF"),s=i.getLocal("pCoefs"),d=i.i32_add(i.getLocal("pCoefs"),i.i32_const(c)),u=i.i32_add(i.getLocal("pCoefs"),i.i32_const(2*c)),g=i.i32_add(i.getLocal("pCoefs"),i.i32_const(3*c)),f=i.i32_add(i.getLocal("pCoefs"),i.i32_const(4*c)),_=t.alloc(2*c),h=i.i32_const(_),m=i.i32_const(_),L=i.i32_const(_+c),w=t.alloc(2*c),A=i.i32_const(w),b=i.i32_const(w),y=i.i32_const(w+c);e.addCode(i.call(p+"_mul",s,n,m),i.call(p+"_mul",d,n,L),i.call(p+"_mul",u,o,b),i.call(p+"_mul",g,o,y),i.call(U+"_mul014",l,f,A,h,l))}();const V=t.alloc(R),j=t.alloc(N);function H(e){const i=t.addFunction(a+"_pairingEq"+e);for(let t=0;t{a[i]=t(e[i])})),a}return e},unstringifyBigInts:function t(e){if("string"==typeof e&&/^[0-9]+$/.test(e))return BigInt(e);if("string"==typeof e&&/^0x[0-9a-fA-F]+$/.test(e))return BigInt(e);if(Array.isArray(e))return e.map(t);if("object"==typeof e){if(null===e)return null;const a={};return Object.keys(e).forEach((i=>{a[i]=t(e[i])})),a}return e},beBuff2int:function(t){let e=BigInt(0),a=t.length,i=0;const o=new DataView(t.buffer,t.byteOffset,t.byteLength);for(;a>0;)a>=4?(a-=4,e+=BigInt(o.getUint32(a))<=2?(a-=2,e+=BigInt(o.getUint16(a))<0;)n-4>=0?(n-=4,o.setUint32(n,Number(a&BigInt(4294967295))),a>>=BigInt(32)):n-2>=0?(n-=2,o.setUint16(n,Number(a&BigInt(65535))),a>>=BigInt(16)):(n-=1,o.setUint8(n,Number(a&BigInt(255))),a>>=BigInt(8));if(a)throw new Error("Number does not fit in this length");return i},leBuff2int:function(t){let e=BigInt(0),a=0;const i=new DataView(t.buffer,t.byteOffset,t.byteLength);for(;a>=BigInt(32)):n+2<=e?(o.setUint16(Number(n,a&BigInt(65535)),!0),n+=2,a>>=BigInt(16)):(o.setUint8(Number(n,a&BigInt(255)),!0),n+=1,a>>=BigInt(8));if(a)throw new Error("Number does not fit in this length");return i},stringifyFElements:function t(e,a){if("bigint"==typeof a||void 0!==a.eq)return a.toString(10);if(a instanceof Uint8Array)return e.toString(e.e(a));if(Array.isArray(a))return a.map(t.bind(this,e));if("object"==typeof a){const i={};return Object.keys(a).forEach((o=>{i[o]=t(e,a[o])})),i}return a},unstringifyFElements:function t(e,a){if("string"==typeof a&&/^[0-9]+$/.test(a))return e.e(a);if("string"==typeof a&&/^0x[0-9a-fA-F]+$/.test(a))return e.e(a);if(Array.isArray(a))return a.map(t.bind(this,e));if("object"==typeof a){if(null===a)return null;const i={};return Object.keys(a).forEach((o=>{i[o]=t(e,a[o])})),i}return a}});var $t=Object.freeze({__proto__:null,stringifyBigInts:function t(e){if("bigint"==typeof e||void 0!==e.eq)return e.toString(10);if(Array.isArray(e))return e.map(t);if("object"==typeof e){const a={};return Object.keys(e).forEach((i=>{a[i]=t(e[i])})),a}return e},unstringifyBigInts:function t(e){if("string"==typeof e&&/^[0-9]+$/.test(e))return u(e);if("string"==typeof e&&/^0x[0-9a-fA-F]+$/.test(e))return u(e);if(Array.isArray(e))return e.map(t);if("object"==typeof e){const a={};return Object.keys(e).forEach((i=>{a[i]=t(e[i])})),a}return e},beBuff2int:function(t){let e=u.zero;for(let a=0;a=0;){let t=Number(a.and(u("255")));o[i]=t,i--,a=a.shiftRight(8)}if(!a.eq(u.zero))throw new Error("Number does not fit in this length");return o},leBuff2int:function(t){let e=u.zero;for(let a=0;a>=1;return a}Zt.bitReverse=function(t,e){return(Yt[t>>>24]|Yt[t>>>16&255]<<8|Yt[t>>>8&255]<<16|Yt[255&t]<<24)>>>32-e},Zt.log2=function(t){return(0!=(4294901760&t)?(t&=4294901760,16):0)|(0!=(4278255360&t)?(t&=4278255360,8):0)|(0!=(4042322160&t)?(t&=4042322160,4):0)|(0!=(3435973836&t)?(t&=3435973836,2):0)|0!=(2863311530&t)},Zt.buffReverseBits=function(t,e){const a=t.byteLength/e,i=Zt.log2(a);if(a!=1<a){const i=t.slice(o*e,(o+1)*e);t.set(t.slice(a*e,(a+1)*e),o*e),t.set(i,a*e)}}},Zt.array2buffer=function(t,e){const a=new Uint8Array(e*t.length);for(let i=0;i0;){const t=r+c>ge?ge-r:c,e=new Uint8Array(this.buffers[n].buffer,this.buffers[n].byteOffset+r,t);if(t==a)return e.slice();o||(o=a<=ge?new Uint8Array(a):new fe(a)),o.set(e,a-c),c-=t,n++,r=0}return o}set(t,e){void 0===e&&(e=0);const a=t.byteLength;if(0==a)return;const i=Math.floor(e/ge);if(i==Math.floor((e+a-1)/ge))return t instanceof fe&&1==t.buffers.length?this.buffers[i].set(t.buffers[0],e%ge):this.buffers[i].set(t,e%ge);let o=i,n=e%ge,r=a;for(;r>0;){const e=n+r>ge?ge-n:r,i=t.slice(a-r,a-r+e);new Uint8Array(this.buffers[o].buffer,this.buffers[o].byteOffset+n,e).set(i),r-=e,o++,n=0}}}function _e(t,e,a,i){return async function(o){const n=Math.floor(o.byteLength/a);if(n*a!==o.byteLength)throw new Error("Invalid buffer size");const r=Math.floor(n/t.concurrency),c=[];for(let l=0;l=0;t--)this.w[t]=this.square(this.w[t+1]);if(!this.eq(this.w[0],this.one))throw new Error("Error calculating roots of unity");this.batchToMontgomery=_e(t,e+"_batchToMontgomery",this.n8,this.n8),this.batchFromMontgomery=_e(t,e+"_batchFromMontgomery",this.n8,this.n8)}op2(t,e,a){return this.tm.setBuff(this.pOp1,e),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op2Bool(t,e,a){return this.tm.setBuff(this.pOp1,e),this.tm.setBuff(this.pOp2,a),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2)}op1(t,e){return this.tm.setBuff(this.pOp1,e),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op1Bool(t,e){return this.tm.setBuff(this.pOp1,e),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3)}add(t,e){return this.op2("_add",t,e)}eq(t,e){return this.op2Bool("_eq",t,e)}isZero(t){return this.op1Bool("_isZero",t)}sub(t,e){return this.op2("_sub",t,e)}neg(t){return this.op1("_neg",t)}inv(t){return this.op1("_inverse",t)}toMontgomery(t){return this.op1("_toMontgomery",t)}fromMontgomery(t){return this.op1("_fromMontgomery",t)}mul(t,e){return this.op2("_mul",t,e)}div(t,e){return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[this.prefix+"_inverse"](this.pOp2,this.pOp2),this.tm.instance.exports[this.prefix+"_mul"](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}square(t){return this.op1("_square",t)}isSquare(t){return this.op1Bool("_isSquare",t)}sqrt(t){return this.op1("_sqrt",t)}exp(t,e){return e instanceof Uint8Array||(e=x(S(e))),this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[this.prefix+"_exp"](this.pOp1,this.pOp2,e.byteLength,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}isNegative(t){return this.op1Bool("_isNegative",t)}e(t,e){if(t instanceof Uint8Array)return t;let a=S(t,e);O(a)?(a=j(a),it(a,this.p)&&(a=X(a,this.p)),a=V(this.p,a)):it(a,this.p)&&(a=X(a,this.p));const i=re(a,this.n8);return this.toMontgomery(i)}toString(t,e){const a=this.fromMontgomery(t),i=I(a,0);return F(i,e)}fromRng(t){let e;const a=new Uint8Array(this.n8);do{e=v;for(let a=0;ai.buffer.byteLength){const o=i.buffer.byteLength/65536;let n=Math.floor((a[0]+t)/65536)+1;n>e&&(n=e),i.grow(n-o)}return o}function r(t){const e=n(t.byteLength);return l(e,t),e}function c(t,e){const a=new Uint8Array(i.buffer);return new Uint8Array(a.buffer,a.byteOffset+t,e)}function l(t,e){new Uint8Array(i.buffer).set(new Uint8Array(e),t)}function s(t){if("INIT"==t[0].cmd)return o(t[0]);const e={vars:[],out:[]},s=new Uint32Array(i.buffer,0,1)[0];for(let i=0;i{this.reject=e,this.resolve=t}))}}var Ie;const Ce="data:application/javascript;base64,"+(Ie="("+we.toString()+")(self)",globalThis.btoa(Ie));class Fe{constructor(){this.actionQueue=[],this.oldPFree=0}startSyncOp(){if(0!=this.oldPFree)throw new Error("Sync operation in progress");this.oldPFree=this.u32[0]}endSyncOp(){if(0==this.oldPFree)throw new Error("No sync operation in progress");this.u32[0]=this.oldPFree,this.oldPFree=0}postAction(t,e,a,i){if(this.working[t])throw new Error("Posting a job t a working worker");return this.working[t]=!0,this.pendingDeferreds[t]=i||new ye,this.workers[t].postMessage(e,a),this.pendingDeferreds[t].promise}processWorks(){for(let t=0;t0;t++)if(0==this.working[t]){const e=this.actionQueue.shift();this.postAction(t,e.data,e.transfers,e.deferred)}}queueAction(t,e){const a=new ye;if(this.singleThread){const e=this.taskManager(t);a.resolve(e)}else this.actionQueue.push({data:t,transfers:e,deferred:a}),this.processWorks();return a.promise}resetMemory(){this.u32[0]=this.initalPFree}allocBuff(t){const e=this.alloc(t.byteLength);return this.setBuff(e,t),e}getBuff(t,e){return this.u8.slice(t,t+e)}setBuff(t,e){this.u8.set(new Uint8Array(e),t)}alloc(t){for(;3&this.u32[0];)this.u32[0]++;const e=this.u32[0];return this.u32[0]+=t,e}async terminate(){for(let t=0;tsetTimeout(e,t))))}}function xe(t,e){const a=t[e],i=t.Fr,o=t.tm;t[e].batchApplyKey=async function(t,n,r,c,l){let s,d,u,g,f;if(c=c||"affine",l=l||"affine","G1"==e)"jacobian"==c?(u=3*a.F.n8,s="g1m_batchApplyKey"):(u=2*a.F.n8,s="g1m_batchApplyKeyMixed"),g=3*a.F.n8,"jacobian"==l?f=3*a.F.n8:(d="g1m_batchToAffine",f=2*a.F.n8);else if("G2"==e)"jacobian"==c?(u=3*a.F.n8,s="g2m_batchApplyKey"):(u=2*a.F.n8,s="g2m_batchApplyKeyMixed"),g=3*a.F.n8,"jacobian"==l?f=3*a.F.n8:(d="g2m_batchToAffine",f=2*a.F.n8);else{if("Fr"!=e)throw new Error("Invalid group: "+e);s="frm_batchApplyKey",u=a.n8,g=a.n8,f=a.n8}const _=Math.floor(t.byteLength/u),p=Math.floor(_/o.concurrency),h=[];r=i.e(r);let m=i.e(n);for(let e=0;e=0;t--){if(!a.isZero(p))for(let t=0;ts&&(p=s),p<1024&&(p=1024);const h=[];for(let e=0;e(c&&c.debug(`Multiexp end: ${l}: ${e}/${u}`),t))))}const m=await Promise.all(h);let L=a.zero;for(let t=m.length-1;t>=0;t--)L=a.add(L,m[t]);return L}a.multiExp=async function(t,e,a,i){return await n(t,e,"jacobian",a,i)},a.multiExpAffine=async function(t,e,a,i){return await n(t,e,"affine",a,i)}}function Be(t,e){const a=t[e],i=t.Fr,o=a.tm;async function n(t,c,l,s,d,u){l=l||"affine",s=s||"affine";let g,f,_,p,h,m,L,w;"G1"==e?("affine"==l?(g=2*a.F.n8,p="g1m_batchToJacobian"):g=3*a.F.n8,f=3*a.F.n8,c&&(w="g1m_fftFinal"),L="g1m_fftJoin",m="g1m_fftMix","affine"==s?(_=2*a.F.n8,h="g1m_batchToAffine"):_=3*a.F.n8):"G2"==e?("affine"==l?(g=2*a.F.n8,p="g2m_batchToJacobian"):g=3*a.F.n8,f=3*a.F.n8,c&&(w="g2m_fftFinal"),L="g2m_fftJoin",m="g2m_fftMix","affine"==s?(_=2*a.F.n8,h="g2m_batchToAffine"):_=3*a.F.n8):"Fr"==e&&(g=a.n8,f=a.n8,_=a.n8,c&&(w="frm_fftFinal"),m="frm_fftMix",L="frm_fftJoin");let A=!1;Array.isArray(t)?(t=ce(t,g),A=!0):t=t.slice(0,t.byteLength);const b=t.byteLength/g,y=Xt(b);if(1<1<<28?new fe(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return g.set(u[0]),g.set(u[1],u[0].byteLength),g}(t,l,s,d,u):await async function(t,e,a,o,c){let l,s;l=t.slice(0,t.byteLength/2),s=t.slice(t.byteLength/2,t.byteLength);const d=[];[l,s]=await r(l,s,"fftJoinExt",i.one,i.shift,e,"jacobian",o,c),d.push(n(l,!1,"jacobian",a,o,c)),d.push(n(s,!1,"jacobian",a,o,c));const u=await Promise.all(d);let g;g=u[0].byteLength>1<<28?new fe(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return g.set(u[0]),g.set(u[1],u[0].byteLength),g}(t,l,s,d,u),A?le(e,_):e}let I,C,F;c&&(I=i.inv(i.e(b))),te(t,g);let x=Math.min(16384,b),v=b/x;for(;v=16;)v*=2,x/=2;const E=Xt(x),B=[];for(let e=0;e(d&&d.debug(`${u}: fft ${y} mix end: ${e}/${v}`),t))))}F=await Promise.all(B);for(let t=0;t(d&&d.debug(`${u}: fft ${y} join ${t}/${y} ${r+1}/${e} ${c}/${a/2}`),i))))}const r=await Promise.all(n);for(let t=0;t0;e--)C.set(F[e],t),t+=x*_,delete F[e];C.set(F[0].slice(0,(x-1)*_),t),delete F[0]}else for(let t=0;t65536&&(A=65536);const b=[];for(let e=0;e(u&&u.debug(`${g}: fftJoinExt End: ${e}/${w}`),t))))}const y=await Promise.all(b);let I,C;w*h>1<<28?(I=new fe(w*h),C=new fe(w*h)):(I=new Uint8Array(w*h),C=new Uint8Array(w*h));let F=0;for(let t=0;ti.s+1)throw l&&l.error("lagrangeEvaluations input too big"),new Error("lagrangeEvaluations input too big");let f=t.slice(0,t.byteLength/2),_=t.slice(t.byteLength/2,t.byteLength);const p=i.exp(i.shift,u/2),h=i.inv(i.sub(i.one,p));[f,_]=await r(f,_,"prepareLagrangeEvaluation",h,i.shiftInv,o,"jacobian",l,s+" prep");const m=[];let L;return m.push(n(f,!0,"jacobian",c,l,s+" t0")),m.push(n(_,!0,"jacobian",c,l,s+" t1")),[f,_]=await Promise.all(m),L=f.byteLength>1<<28?new fe(2*f.byteLength):new Uint8Array(2*f.byteLength),L.set(f),L.set(_,f.byteLength),L},a.fftMix=async function(t){const n=3*a.F.n8;let r,c;if("G1"==e)r="g1m_fftMix",c="g1m_fftJoin";else if("G2"==e)r="g2m_fftMix",c="g2m_fftJoin";else{if("Fr"!=e)throw new Error("Invalid group");r="frm_fftMix",c="frm_fftJoin"}const l=Math.floor(t.byteLength/n),s=Xt(l);let d=1<=0;t--)f.set(g[t][0],_),_+=g[t][0].byteLength;return f}}async function Se(t){const e=await async function(t,e){const a=new Fe;a.memory=new WebAssembly.Memory({initial:25}),a.u8=new Uint8Array(a.memory.buffer),a.u32=new Uint32Array(a.memory.buffer);const i=await WebAssembly.compile(t.code);if(a.instance=await WebAssembly.instantiate(i,{env:{memory:a.memory}}),a.singleThread=e,a.initalPFree=a.u32[0],a.pq=t.pq,a.pr=t.pr,a.pG1gen=t.pG1gen,a.pG1zero=t.pG1zero,a.pG2gen=t.pG2gen,a.pG2zero=t.pG2zero,a.pOneT=t.pOneT,e)a.code=t.code,a.taskManager=we(),await a.taskManager([{cmd:"INIT",init:25,code:a.code.slice()}]),a.concurrency=1;else{let e;a.workers=[],a.pendingDeferreds=[],a.working=[],e="object"==typeof navigator&&navigator.hardwareConcurrency?navigator.hardwareConcurrency:Ae.cpus().length,0==e&&(e=2),e>64&&(e=64),a.concurrency=e;for(let t=0;t>6,128|63&i):i<55296||i>=57344?e.push(224|i>>12,128|i>>6&63,128|63&i):(a++,i=65536+((1023&i)<<10|1023&t.charCodeAt(a)),e.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|63&i))}return e}(t);return[...Ue(e.length),...e]},qe=function t(e){if("string"==typeof e){let t=e.split("\n");for(let e=0;eke[t.type]))],...this.returnType?[1,ke[this.returnType]]:[0]]}getBody(){const t=this.locals.map((t=>[...Qe.varuint32(t.length),ke[t.type]])),e=[...Qe.varuint32(this.locals.length),...[].concat(...t),...this.code,11];return[...Qe.varuint32(e.length),...e]}addCode(...t){this.code.push(...[].concat(...t))}getCodeBuilder(){return new Me(this)}};var Ne=class{constructor(){this.functions=[],this.functionIdxByName={},this.nImportFunctions=0,this.nInternalFunctions=0,this.memory={pagesSize:1,moduleName:"env",fieldName:"memory"},this.free=8,this.datas=[],this.modules={},this.exports=[],this.functionsTable=[]}build(){return this._setSignatures(),new Uint8Array([...Qe.u32(1836278016),...Qe.u32(1),...this._buildType(),...this._buildImport(),...this._buildFunctionDeclarations(),...this._buildFunctionsTable(),...this._buildExports(),...this._buildElements(),...this._buildCode(),...this._buildData()])}addFunction(t){if(void 0!==this.functionIdxByName[t])throw new Error(`Function already defined: ${t}`);const e=this.functions.length;return this.functionIdxByName[t]=e,this.functions.push(new Re(this,t,"internal")),this.nInternalFunctions++,this.functions[e]}addIimportFunction(t,e,a){if(void 0!==this.functionIdxByName[t])throw new Error(`Function already defined: ${t}`);if(this.functions.length>0&&"internal"==this.functions[this.functions.length-1].type)throw new Error(`Import functions must be declared before internal: ${t}`);let i=a||t;const o=this.functions.length;return this.functionIdxByName[t]=o,this.functions.push(new Re(this,t,"import",e,i)),this.nImportFunctions++,this.functions[o]}setMemory(t,e,a){this.memory={pagesSize:t,moduleName:e||"env",fieldName:a||"memory"}}exportFunction(t,e){const a=e||t;if(void 0===this.functionIdxByName[t])throw new Error(`Function not defined: ${t}`);const i=this.functionIdxByName[t];a!=t&&(this.functionIdxByName[a]=i),this.exports.push({exportName:a,idx:i})}addFunctionToTable(t){const e=this.functionIdxByName[t];this.functionsTable.push(e)}addData(t,e){this.datas.push({offset:t,bytes:e})}alloc(t,e){let a,i;(Array.isArray(t)||ArrayBuffer.isView(t))&&void 0===e?(a=t.length,i=t):(a=t,i=e),a=1+(a-1>>3)<<3;const o=this.free;return this.free+=a,i&&this.addData(o,i),o}allocString(t){const e=(new globalThis.TextEncoder).encode(t);return this.alloc([...e,0])}_setSignatures(){this.signatures=[];const t={};if(this.functionsTable.length>0){const e=this.functions[this.functionsTable[0]].getSignature();t["s_"+Qe.toHexString(e)]=0,this.signatures.push(e)}for(let e=0;e{e.pendingLoads.push({page:t,resolve:a,reject:i})}));return e.__statusPage("After Load request: ",t),a}__statusPage(t,e){const a=[],i=this;if(!i.logHistory)return;a.push("=="+t+" "+e);let o="";for(let t=0;t "+e.history[t][a][i])}_triggerLoad(){const t=this;if(t.reading)return;if(0==t.pendingLoads.length)return;const e=Object.keys(t.pages),a=[];for(let i=0;i0&&(void 0!==t.pages[t.pendingLoads[0].page]||i>0||a.length>0);){const e=t.pendingLoads.shift();if(void 0!==t.pages[e.page]){t.pages[e.page].pendingOps++;const i=a.indexOf(e.page);i>=0&&a.splice(i,1),t.pages[e.page].loading?t.pages[e.page].loading.push(e):e.resolve(),t.__statusPage("After Load (cached): ",e.page)}else{if(i)i--;else{const e=a.shift();t.__statusPage("Before Unload: ",e),t.avBuffs.unshift(t.pages[e]),delete t.pages[e],t.__statusPage("After Unload: ",e)}e.page>=t.totalPages?(t.pages[e.page]=n(),e.resolve(),t.__statusPage("After Load (new): ",e.page)):(t.reading=!0,t.pages[e.page]=n(),t.pages[e.page].loading=[e],o.push(t.fd.read(t.pages[e.page].buff,0,t.pageSize,e.page*t.pageSize).then((a=>{t.pages[e.page].size=a.bytesRead;const i=t.pages[e.page].loading;delete t.pages[e.page].loading;for(let t=0;t{e.reject(t)}))),t.__statusPage("After Load (loading): ",e.page))}}function n(){if(t.avBuffs.length>0){const e=t.avBuffs.shift();return e.dirty=!1,e.pendingOps=1,e.size=0,e}return{dirty:!1,buff:new Uint8Array(t.pageSize),pendingOps:1,size:0}}Promise.all(o).then((()=>{t.reading=!1,t.pendingLoads.length>0&&setImmediate(t._triggerLoad.bind(t)),t._tryClose()}))}_triggerWrite(){const t=this;if(t.writing)return;const e=Object.keys(t.pages),a=[];for(let i=0;i{o.writing=!1}),(e=>{console.log("ERROR Writing: "+e),t.error=e,t._tryClose()}))))}t.writing&&Promise.all(a).then((()=>{t.writing=!1,setImmediate(t._triggerWrite.bind(t)),t._tryClose(),t.pendingLoads.length>0&&setImmediate(t._triggerLoad.bind(t))}))}_getDirtyPage(){for(let t in this.pages)if(this.pages[t].dirty)return t;return-1}async write(t,e){if(0==t.byteLength)return;const a=this;if(void 0===e&&(e=a.pos),a.pos=e+t.byteLength,a.totalSize0;){await n[r-i];const e=c+l>a.pageSize?a.pageSize-c:l,o=t.slice(t.byteLength-l,t.byteLength-l+e);new Uint8Array(a.pages[r].buff.buffer,c,e).set(o),a.pages[r].dirty=!0,a.pages[r].pendingOps--,a.pages[r].size=Math.max(c+e,a.pages[r].size),r>=a.totalPages&&(a.totalPages=r+1),l-=e,r++,c=0,a.writing||setImmediate(a._triggerWrite.bind(a))}}async read(t,e){let a=new Uint8Array(t);return await this.readToBuffer(a,0,t,e),a}async readToBuffer(t,e,a,i){if(0==a)return;const o=this;if(a>o.pageSize*o.maxPagesLoaded*.8){const t=Math.floor(1.1*a);this.maxPagesLoaded=Math.floor(t/o.pageSize)+1}if(void 0===i&&(i=o.pos),o.pos=i+a,o.pendingClose)throw new Error("Reading a closing file");const n=Math.floor(i/o.pageSize),r=Math.floor((i+a-1)/o.pageSize),c=[];for(let t=n;t<=r;t++)c.push(o._loadPage(t));o._triggerLoad();let l=n,s=i%o.pageSize,d=i+a>o.totalSize?a-(i+a-o.totalSize):a;for(;d>0;){await c[l-n],o.__statusPage("After Await (read): ",l);const i=s+d>o.pageSize?o.pageSize-s:d,r=new Uint8Array(o.pages[l].buff.buffer,o.pages[l].buff.byteOffset+s,i);t.set(r,e+a-d),o.pages[l].pendingOps--,o.__statusPage("After Op done: ",l),d-=i,l++,s=0,o.pendingLoads.length>0&&setImmediate(o._triggerLoad.bind(o))}this.pos=i+a}_tryClose(){const t=this;if(!t.pendingClose)return;t.error&&t.pendingCloseReject(t.error);t._getDirtyPage()>=0||t.writing||t.reading||t.pendingLoads.length>0||t.pendingClose()}close(){const t=this;if(t.pendingClose)throw new Error("Closing the file twice");return new Promise(((e,a)=>{t.pendingClose=e,t.pendingCloseReject=a,t._tryClose()})).then((()=>{t.fd.close()}),(e=>{throw t.fd.close(),e}))}async discard(){await this.close(),await Ze.promises.unlink(this.fileName)}async writeULE32(t,e){const a=new Uint8Array(4);new DataView(a.buffer).setUint32(0,t,!0),await this.write(a,e)}async writeUBE32(t,e){const a=new Uint8Array(4);new DataView(a.buffer).setUint32(0,t,!1),await this.write(a,e)}async writeULE64(t,e){const a=new Uint8Array(8),i=new DataView(a.buffer);i.setUint32(0,4294967295&t,!0),i.setUint32(4,Math.floor(t/4294967296),!0),await this.write(a,e)}async readULE32(t){const e=await this.read(4,t);return new Uint32Array(e.buffer)[0]}async readUBE32(t){const e=await this.read(4,t);return new DataView(e.buffer).getUint32(0,!1)}async readULE64(t){const e=await this.read(8,t),a=new Uint32Array(e.buffer);return 4294967296*a[1]+a[0]}}const We=new Uint8Array(4),Xe=new DataView(We.buffer),ta=new Uint8Array(8),ea=new DataView(ta.buffer);class aa{constructor(){this.pageSize=16384}_resizeIfNeeded(t){if(t>this.allocSize){const e=Math.max(this.allocSize+(1<<20),Math.floor(1.1*this.allocSize),t),a=new Uint8Array(e);a.set(this.o.data),this.o.data=a,this.allocSize=e}}async write(t,e){if(void 0===e&&(e=this.pos),this.readOnly)throw new Error("Writing a read only file");this._resizeIfNeeded(e+t.byteLength),this.o.data.set(t.slice(),e),e+t.byteLength>this.totalSize&&(this.totalSize=e+t.byteLength),this.pos=e+t.byteLength}async readToBuffer(t,e,a,i){if(void 0===i&&(i=this.pos),this.readOnly&&i+a>this.totalSize)throw new Error("Reading out of bounds");this._resizeIfNeeded(i+a);const o=new Uint8Array(this.o.data.buffer,this.o.data.byteOffset+i,a);t.set(o,e),this.pos=i+a}async read(t,e){const a=new Uint8Array(t);return await this.readToBuffer(a,0,t,e),a}close(){this.o.data.byteLength!=this.totalSize&&(this.o.data=this.o.data.slice(0,this.totalSize))}async discard(){}async writeULE32(t,e){Xe.setUint32(0,t,!0),await this.write(We,e)}async writeUBE32(t,e){Xe.setUint32(0,t,!1),await this.write(We,e)}async writeULE64(t,e){ea.setUint32(0,4294967295&t,!0),ea.setUint32(4,Math.floor(t/4294967296),!0),await this.write(ta,e)}async readULE32(t){const e=await this.read(4,t);return new Uint32Array(e.buffer)[0]}async readUBE32(t){const e=await this.read(4,t);return new DataView(e.buffer).getUint32(0,!1)}async readULE64(t){const e=await this.read(8,t),a=new Uint32Array(e.buffer);return 4294967296*a[1]+a[0]}}const ia=1<<22;const oa=new Uint8Array(4),na=new DataView(oa.buffer),ra=new Uint8Array(8),ca=new DataView(ra.buffer);class la{constructor(){this.pageSize=16384}_resizeIfNeeded(t){if(t<=this.totalSize)return;if(this.readOnly)throw new Error("Reading out of file bounds");const e=Math.floor((t-1)/ia)+1;for(let a=Math.max(this.o.data.length-1,0);a0;){const e=o+n>ia?ia-o:n,r=t.slice(t.byteLength-n,t.byteLength-n+e);new Uint8Array(a.o.data[i].buffer,o,e).set(r),n-=e,i++,o=0}this.pos=e+t.byteLength}async readToBuffer(t,e,a,i){const o=this;if(void 0===i&&(i=o.pos),this.readOnly&&i+a>this.totalSize)throw new Error("Reading out of bounds");this._resizeIfNeeded(i+a);let n=Math.floor(i/ia),r=i%ia,c=a;for(;c>0;){const i=r+c>ia?ia-r:c,l=new Uint8Array(o.o.data[n].buffer,r,i);t.set(l,e+a-c),c-=i,n++,r=0}this.pos=i+a}async read(t,e){const a=new Uint8Array(t);return await this.readToBuffer(a,0,t,e),a}close(){}async discard(){}async writeULE32(t,e){na.setUint32(0,t,!0),await this.write(oa,e)}async writeUBE32(t,e){na.setUint32(0,t,!1),await this.write(oa,e)}async writeULE64(t,e){ca.setUint32(0,4294967295&t,!0),ca.setUint32(4,Math.floor(t/4294967296),!0),await this.write(ra,e)}async readULE32(t){const e=await this.read(4,t);return new Uint32Array(e.buffer)[0]}async readUBE32(t){const e=await this.read(4,t);return new DataView(e.buffer).getUint32(0,!1)}async readULE64(t){const e=await this.read(8,t),a=new Uint32Array(e.buffer);return 4294967296*a[1]+a[0]}}async function sa(t,e,a){if("string"==typeof t&&(t={type:"file",fileName:t,cacheSize:e||65536,pageSize:a||8192}),"file"==t.type)return await Ye(t.fileName,"w+",t.cacheSize,t.pageSize);if("mem"==t.type)return function(t){const e=t.initialSize||1<<20,a=new aa;return a.o=t,a.o.data=new Uint8Array(e),a.allocSize=e,a.totalSize=0,a.readOnly=!1,a.pos=0,a}(t);if("bigMem"==t.type)return function(t){const e=t.initialSize||0,a=new la;a.o=t;const i=e?Math.floor((e-1)/ia)+1:0;a.o.data=[];for(let t=0;ta)throw new Error("Version not supported");const l=await n.readULE32();let s=[];for(let t=0;t1)throw new Error(t.fileName+": Section Duplicated "+a);t.pos=e[a][0].p,t.readingSection=e[a][0]}async function ha(t,e){if(void 0===t.readingSection)throw new Error("Not reading a section");if(!e&&t.pos-t.readingSection.p!=t.readingSection.size)throw new Error("Invalid section size reading");delete t.readingSection}async function ma(t,e,a,i){const o=new Uint8Array(a);He.toRprLE(o,0,e,a),await t.write(o,i)}async function La(t,e,a){const i=await t.read(e,a);return He.fromRprLE(i,0,e)}async function wa(t,e,a,i,o){void 0===o&&(o=e[i][0].size);const n=t.pageSize;await pa(t,e,i),await fa(a,i);for(let e=0;ee[a][0].size)throw new Error("Reading out of the range of the section");let n;return n=o<1<<30?new Uint8Array(o):new fe(o),await t.readToBuffer(n,0,o,e[a][0].p+i),n}async function ba(t,e,a,i,o){const n=16*t.pageSize;if(await pa(t,e,o),await pa(a,i,o),e[o][0].size!=i[o][0].size)return!1;const r=e[o][0].size;for(let e=0;e=0)e=await De();else{if(!(["BLS12381"].indexOf(a)>=0))throw new Error(`Curve not supported: ${t}`);e=await Ke()}return e}var xa=function t(e,a){if(!e){var i=new va(a);throw Error.captureStackTrace&&Error.captureStackTrace(i,t),i}};class va extends Error{}function Ea(t){return t.length}va.prototype.name="AssertionError";var Ba={byteLength:Ea,toString:function(t){const e=t.byteLength;let a="";for(let i=0;i1&&61===t.charCodeAt(e-1)&&e--,3*e>>>2}Ga[45]=62,Ga[95]=63;var Oa={byteLength:Pa,toString:function(t){const e=t.byteLength;let a="";for(let i=0;i>2]+Sa[(3&t[i])<<4|t[i+1]>>4]+Sa[(15&t[i+1])<<2|t[i+2]>>6]+Sa[63&t[i+2]];return e%3==2?a=a.substring(0,a.length-1)+"=":e%3==1&&(a=a.substring(0,a.length-2)+"=="),a},write:function(t,e,a=0,i=Pa(e)){const o=Math.min(i,t.byteLength-a);for(let a=0,i=0;a>4,t[i++]=(15&n)<<4|r>>2,t[i++]=(3&r)<<6|63&c}return o}};function Ua(t){return t.length>>>1}var za={byteLength:Ua,toString:function(t){const e=t.byteLength;t=new DataView(t.buffer,t.byteOffset,e);let a="",i=0;for(let o=e-e%4;i=48&&t<=57?t-48:t>=65&&t<=70?t-65+10:t>=97&&t<=102?t-97+10:void 0}function Qa(t){let e=0;for(let a=0,i=t.length;a=55296&&o<=56319&&a+1=56320&&i<=57343){e+=4,a++;continue}}e+=o<=127?1:o<=2047?2:3}return e}let Ma,ka;if("undefined"!=typeof TextDecoder){const t=new TextDecoder;Ma=function(e){return t.decode(e)}}else Ma=function(t){const e=t.byteLength;let a="",i=0;for(;i0){let e=0;for(;e>i,i-=6;i>=0;)t[r++]=128|a>>i&63,i-=6;n+=a>=65536?2:1}return o};var Ra={byteLength:Qa,toString:Ma,write:ka};function Na(t){return 2*t.length}var Ta={byteLength:Na,toString:function(t){const e=t.byteLength;let a="";for(let i=0;i>8,r=o%256;t[a+2*i]=r,t[a+2*i+1]=n}return o}};function Da(t){switch(t){case"ascii":return Ba;case"base64":return Oa;case"hex":return za;case"utf8":case"utf-8":case void 0:return Ra;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Ta;default:throw new Error(`Unknown encoding: ${t}`)}}function Ka(t){return t instanceof Uint8Array}function Va(t,e,a){return"string"==typeof t?function(t,e){const a=Da(e),i=new Uint8Array(a.byteLength(t));return a.write(i,t,0,i.byteLength),i}(t,e):Array.isArray(t)?function(t){const e=new Uint8Array(t.length);return e.set(t),e}(t):ArrayBuffer.isView(t)?function(t){const e=new Uint8Array(t.byteLength);return e.set(t),e}(t):function(t,e,a){return new Uint8Array(t,e,a)}(t,e,a)}function ja(t,e,a){const i=t[e];t[e]=t[a],t[a]=i}var Ha={isBuffer:Ka,alloc:function(t,e,a){const i=new Uint8Array(t);return void 0!==e&&e(i,e,0,i.byteLength,a),i},allocUnsafe:function(t){return new Uint8Array(t)},allocUnsafeSlow:function(t){return new Uint8Array(t)},byteLength:function(t,e){return Da(e).byteLength(t)},compare:function(t,e){if(t===e)return 0;const a=Math.min(t.byteLength,e.byteLength);t=new DataView(t.buffer,t.byteOffset,t.byteLength),e=new DataView(e.buffer,e.byteOffset,e.byteLength);let i=0;for(let o=a-a%4;io)return 1}for(;io)return 1}return t.byteLength>e.byteLength?1:t.byteLengtht+e.byteLength),0));const a=new Uint8Array(e);return t.reduce(((t,e)=>(a.set(e,t),t+e.byteLength)),0),a},copy:function(t,e,a=0,i=0,o=t.byteLength){if(o>0&&o=t.byteLength)throw new RangeError("sourceStart is out of range");if(o<0)throw new RangeError("sourceEnd is out of range");a>=e.byteLength&&(a=e.byteLength),o>t.byteLength&&(o=t.byteLength),e.byteLength-a=o||i<=a?"":(a<0&&(a=0),i>o&&(i=o),(0!==a||i{for(var t=new Uint8Array(128),e=0;e<64;e++)t[e<26?e+65:e<52?e+71:e<62?e-4:4*e-205]=e;return e=>{for(var a=e.length,i=new Uint8Array(3*(a-("="==e[a-1])-("="==e[a-2]))/4|0),o=0,n=0;o>4,i[n++]=c<<4|l>>2,i[n++]=l<<6|s}return i}})(),Za=((t,e)=>function(){return e||(0,t[Object.keys(t)[0]])((e={exports:{}}).exports,e),e.exports})({"wasm-binary:./blake2b.wat"(t,e){e.exports=$a("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")}}),Ya=Za(),Ja=WebAssembly.compile(Ya),Wa=d((function(t){var e=null,a="undefined"!=typeof WebAssembly&&(async t=>(await WebAssembly.instantiate(await Ja,t)).exports)().then((t=>{e=t})),i=64,o=[];t.exports=u;var n=t.exports.BYTES_MIN=16,r=t.exports.BYTES_MAX=64;t.exports.BYTES=32;var c=t.exports.KEYBYTES_MIN=16,l=t.exports.KEYBYTES_MAX=64;t.exports.KEYBYTES=32;var s=t.exports.SALTBYTES=16,d=t.exports.PERSONALBYTES=16;function u(t,a,g,f,_){if(!(this instanceof u))return new u(t,a,g,f,_);if(!e)throw new Error("WASM not loaded. Wait for Blake2b.ready(cb)");t||(t=32),!0!==_&&(xa(t>=n,"digestLength must be at least "+n+", was given "+t),xa(t<=r,"digestLength must be at most "+r+", was given "+t),null!=a&&(xa(a instanceof Uint8Array,"key must be Uint8Array or Buffer"),xa(a.length>=c,"key must be at least "+c+", was given "+a.length),xa(a.length<=l,"key must be at least "+l+", was given "+a.length)),null!=g&&(xa(g instanceof Uint8Array,"salt must be Uint8Array or Buffer"),xa(g.length===s,"salt must be exactly "+s+", was given "+g.length)),null!=f&&(xa(f instanceof Uint8Array,"personal must be Uint8Array or Buffer"),xa(f.length===d,"personal must be exactly "+d+", was given "+f.length))),o.length||(o.push(i),i+=216),this.digestLength=t,this.finalized=!1,this.pointer=o.pop(),this._memory=new Uint8Array(e.memory.buffer),this._memory.fill(0,0,64),this._memory[0]=this.digestLength,this._memory[1]=a?a.length:0,this._memory[2]=1,this._memory[3]=1,g&&this._memory.set(g,32),f&&this._memory.set(f,48),this.pointer+216>this._memory.length&&this._realloc(this.pointer+216),e.blake2b_init(this.pointer,this.digestLength),a&&(this.update(a),this._memory.fill(0,i,i+a.length),this._memory[this.pointer+200]=128)}function g(){}u.prototype._realloc=function(t){e.memory.grow(Math.max(0,Math.ceil(Math.abs(t-this._memory.length)/65536))),this._memory=new Uint8Array(e.memory.buffer)},u.prototype.update=function(t){return xa(!1===this.finalized,"Hash instance finalized"),xa(t instanceof Uint8Array,"input must be Uint8Array or Buffer"),i+t.length>this._memory.length&&this._realloc(i+t.length),this._memory.set(t,i),e.blake2b_update(this.pointer,i,i+t.length),this},u.prototype.digest=function(t){if(xa(!1===this.finalized,"Hash instance finalized"),this.finalized=!0,o.push(this.pointer),e.blake2b_final(this.pointer),!t||"binary"===t)return this._memory.slice(this.pointer+128,this.pointer+128+this.digestLength);if("string"==typeof t)return Ha.toString(this._memory,t,this.pointer+128,this.pointer+128+this.digestLength);xa(t instanceof Uint8Array&&t.length>=this.digestLength,"input must be Uint8Array or Buffer");for(var a=0;at()),t):t(new Error("WebAssembly not supported"))},u.prototype.ready=u.ready,u.prototype.getPartialHash=function(){return this._memory.slice(this.pointer,this.pointer+216)},u.prototype.setPartialHash=function(t){this._memory.set(t,this.pointer)}}));const Xa=[];for(let t=0;t<256;t++)Xa[t]=ti(t,8);function ti(t,e){let a=0,i=t;for(let t=0;t>=1;return a}function ei(t){return(0!=(4294901760&t)?(t&=4294901760,16):0)|(0!=(4278255360&t)?(t&=4278255360,8):0)|(0!=(4042322160&t)?(t&=4042322160,4):0)|(0!=(3435973836&t)?(t&=3435973836,2):0)|0!=(2863311530&t)}function ai(t,e){const a=new DataView(t.buffer,t.byteOffset,t.byteLength);let i="";for(let t=0;t<4;t++){t>0&&(i+="\n"),i+="\t\t";for(let e=0;e<4;e++)e>0&&(i+=" "),i+=a.getUint32(16*t+4*e).toString(16).padStart(8,"0")}return e&&(i=e+"\n"+i),i}function ii(t,e){if(t.byteLength!=e.byteLength)return!1;for(var a=new Int8Array(t),i=new Int8Array(e),o=0;o!=t.byteLength;o++)if(a[o]!=i[o])return!1;return!0}function oi(t){const e=t.getPartialHash(),a=Wa(64);return a.setPartialHash(e),a}async function ni(t,e,a,i,o){if(t.G1.isZero(e))return!1;if(t.G1.isZero(a))return!1;if(t.G2.isZero(i))return!1;if(t.G2.isZero(o))return!1;return await t.pairingEq(e,o,t.G1.neg(a),i)}async function ri(t){for(;!t;)t=await window.prompt("Enter a random text. (Entropy): ","");const e=Wa(64);e.update(wt.randomBytes(64));const a=new TextEncoder;e.update(a.encode(t));const i=Buffer.from(e.digest()),o=[];for(let t=0;t<8;t++)o[t]=i.readUInt32BE(4*t);return new Lt(o)}function ci(t,e){let a,i;e<32?(a=1<>>0,i=1):(a=4294967296,i=1<>>0);let o=t;for(let t=0;t0){const e=new Uint8Array(i);await t.writeULE32(e.byteLength),await t.write(e)}else await t.writeULE32(0)}async function wi(t,e,a){await fa(t,10),await t.write(a.csHash),await t.writeULE32(a.contributions.length);for(let i=0;i0;)a.unshift(0),n--;return a}async function Ei(t,e){e=e||{};let a,i=32767,o=!1;for(;!o;)try{a=new WebAssembly.Memory({initial:i}),o=!0}catch(t){if(1===i)throw t;console.warn("Could not allocate "+1024*i*64+" bytes. This may cause severe instability. Trying with "+1024*i*64/2+" bytes"),i=Math.floor(i/2)}const n=await WebAssembly.compile(t);let r;const c=await WebAssembly.instantiate(n,{env:{memory:a},runtime:{exceptionHandler:function(t){let e;throw e=1==t?"Signal not found. ":2==t?"Too many signals set. ":3==t?"Signal already set. ":4==t?"Assert Failed. ":5==t?"Not enough memory. ":"Unknown error.",console.log("ERROR: ",t,e),new Error(e)},showSharedRWMemory:function(){const t=c.exports.getFieldNumLen32(),e=new Uint32Array(t);for(let a=0;a0;a++)i.push(e[t+a]);return String.fromCharCode.apply(null,i)}}class Bi{constructor(t,e,a){this.memory=t,this.i32=new Uint32Array(t.buffer),this.instance=e,this.n32=(this.instance.exports.getFrLen()>>2)-2;const i=this.instance.exports.getPRawPrime(),o=new Array(this.n32);for(let t=0;t>2)+t];this.prime=He.fromArray(o,4294967296),this.Fr=new vt(this.prime),this.mask32=He.fromString("FFFFFFFF",16),this.NVars=this.instance.exports.getNVars(),this.n64=Math.floor((this.Fr.bitLength-1)/64)+1,this.R=this.Fr.e(He.shiftLeft(1,64*this.n64)),this.RInv=this.Fr.inv(this.R),this.sanityCheck=a}circom_version(){return 1}async _doCalculateWitness(t,e){this.instance.exports.init(this.sanityCheck||e?1:0);const a=this.allocInt(),i=this.allocFr();Object.keys(t).forEach((e=>{const o=xi(e),n=parseInt(o.slice(0,8),16),r=parseInt(o.slice(8,16),16);try{this.instance.exports.getSignalOffset32(a,0,n,r)}catch(t){throw new Error(`Signal ${e} is not an input of the circuit.`)}const c=this.getInt(a),l=Fi(t[e]);for(let t=0;t>2]}setInt(t,e){this.i32[t>>2]=e}getFr(t){const e=this,a=t>>2;if(2147483648&e.i32[a+1]){const t=new Array(e.n32);for(let i=0;i>2]=o,void(a.i32[1+(t>>2)]=0)}a.i32[t>>2]=0,a.i32[1+(t>>2)]=2147483648;const n=He.toArray(e,4294967296);for(let e=0;e>2)+e]=i>=0?n[i]:0}}}class Si{constructor(t,e){this.instance=t,this.version=this.instance.exports.getVersion(),this.n32=this.instance.exports.getFieldNumLen32(),this.instance.exports.getRawPrime();const a=new Array(this.n32);for(let t=0;t{const a=xi(e),o=parseInt(a.slice(0,8),16),n=parseInt(a.slice(8,16),16),r=Fi(t[e]);for(let t=0;t1)throw new Error(t.fileName+": File has more than one header");t.pos=e[1][0].p;const a=await t.readULE32(),i=await t.read(a),o=He.fromRprLE(i),n=await Ca(o);if(8*n.F1.n64!=a)throw new Error(t.fileName+": Invalid size");const r=await t.readULE32(),c=await t.readULE32();if(t.pos-e[1][0].p!=e[1][0].size)throw new Error("Invalid PTau header size");return{curve:n,power:r,ceremonyPower:c}}function Ni(t,e,a,i){const o={tau:{},alpha:{},beta:{}};return o.tau.g1_s=n(),o.tau.g1_sx=n(),o.alpha.g1_s=n(),o.alpha.g1_sx=n(),o.beta.g1_s=n(),o.beta.g1_sx=n(),o.tau.g2_spx=r(),o.alpha.g2_spx=r(),o.beta.g2_spx=r(),o;function n(){let o;return o=i?a.G1.fromRprLEM(t,e):a.G1.fromRprUncompressed(t,e),e+=2*a.G1.F.n8,o}function r(){let o;return o=i?a.G2.fromRprLEM(t,e):a.G2.fromRprUncompressed(t,e),e+=2*a.G2.F.n8,o}}function Ti(t,e,a,i,o){async function n(i){o?a.G1.toRprLEM(t,e,i):a.G1.toRprUncompressed(t,e,i),e+=2*a.F1.n8}async function r(i){o?a.G2.toRprLEM(t,e,i):a.G2.toRprUncompressed(t,e,i),e+=2*a.F2.n8}return n(i.tau.g1_s),n(i.tau.g1_sx),n(i.alpha.g1_s),n(i.alpha.g1_sx),n(i.beta.g1_s),n(i.beta.g1_sx),r(i.tau.g2_spx),r(i.alpha.g2_spx),r(i.beta.g2_spx),t}async function Di(t,e){const a={};a.tauG1=await l(),a.tauG2=await s(),a.alphaG1=await l(),a.betaG1=await l(),a.betaG2=await s(),a.key=await async function(t,e,a){return Ni(await t.read(2*e.F1.n8*6+2*e.F2.n8*3),0,e,a)}(t,e,!0),a.partialHash=await t.read(216),a.nextChallenge=await t.read(64),a.type=await t.readULE32();const i=new Uint8Array(2*e.G1.F.n8*6+2*e.G2.F.n8*3);Ti(i,0,e,a.key,!1);const o=Wa(64);o.setPartialHash(a.partialHash),o.update(i),a.responseHash=o.digest();const n=await t.readULE32(),r=t.pos;let c=0;for(;t.pos-r1)throw new Error(t.fileName+": File has more than one contributions section");t.pos=a[7][0].p;const i=await t.readULE32(),o=[];for(let a=0;a0){const e=new Uint8Array(n);await t.writeULE32(e.byteLength),await t.write(e)}else await t.writeULE32(0);async function r(a){e.G1.toRprLEM(i,0,a),await t.write(i)}async function c(a){e.G2.toRprLEM(o,0,a),await t.write(o)}}async function ji(t,e,a){await t.writeULE32(7);const i=t.pos;await t.writeULE64(0),await t.writeULE32(a.length);for(let i=0;i0?u[u.length-1].nextChallenge:Hi(s,d,n);const w=await ga(a,"ptau",1,o?7:2);await ki(w,s,d);const A=await m.read(64);if(ii(r,L)&&(L=A,u[u.length-1].nextChallenge=L),!ii(A,L))throw new Error("Wrong contribution. this contribution is not based on the previus hash");const b=new Wa(64);b.update(A);const y=[];let I;I=await x(m,w,"G1",2,2**d*2-1,[1],"tauG1"),g.tauG1=I[0],I=await x(m,w,"G2",3,2**d,[1],"tauG2"),g.tauG2=I[0],I=await x(m,w,"G1",4,2**d,[0],"alphaG1"),g.alphaG1=I[0],I=await x(m,w,"G1",5,2**d,[0],"betaG1"),g.betaG1=I[0],I=await x(m,w,"G2",6,1,[0],"betaG2"),g.betaG2=I[0],g.partialHash=b.getPartialHash();const C=await m.read(2*s.F1.n8*6+2*s.F2.n8*3);g.key=Ni(C,0,s,!1),b.update(new Uint8Array(C));const F=b.digest();if(n&&n.info(ai(F,"Contribution Response Hash imported: ")),o){const t=new Wa(64);t.update(F),await v(t,w,"G1",2,2**d*2-1,"tauG1",n),await v(t,w,"G2",3,2**d,"tauG2",n),await v(t,w,"G1",4,2**d,"alphaTauG1",n),await v(t,w,"G1",5,2**d,"betaTauG1",n),await v(t,w,"G2",6,1,"betaG2",n),g.nextChallenge=t.digest(),n&&n.info(ai(g.nextChallenge,"Next Challenge Hash: "))}else g.nextChallenge=r;return u.push(g),await ji(w,s,u),await m.close(),await w.close(),await c.close(),g.nextChallenge;async function x(t,e,a,i,r,c,l){return o?await async function(t,e,a,i,o,r,c){const l=s[a],d=l.F.n8,u=2*l.F.n8,g=[];await fa(e,i);const f=Math.floor((1<<24)/u);y[i]=e.pos;for(let a=0;a=a&&e=e&&o1?l[l.length-2]:s;const u=l[l.length-1];if(e&&e.debug("Validating contribution #"+l[l.length-1].id),!await Yi(n,u,d,e))return!1;const g=Wa(64);g.update(u.responseHash),e&&e.debug("Verifying powers in tau*G1 section");const f=await A(2,"G1","tauG1",2**r*2-1,[0,1],e);if(a=await Zi(n,f.R1,f.R2,n.G2.g,u.tauG2),!0!==a)return e&&e.error("tauG1 section. Powers do not match"),!1;if(!n.G1.eq(n.G1.g,f.singularPoints[0]))return e&&e.error("First element of tau*G1 section must be the generator"),!1;if(!n.G1.eq(u.tauG1,f.singularPoints[1]))return e&&e.error("Second element of tau*G1 section does not match the one in the contribution section"),!1;e&&e.debug("Verifying powers in tau*G2 section");const _=await A(3,"G2","tauG2",2**r,[0,1],e);if(a=await Zi(n,n.G1.g,u.tauG1,_.R1,_.R2),!0!==a)return e&&e.error("tauG2 section. Powers do not match"),!1;if(!n.G2.eq(n.G2.g,_.singularPoints[0]))return e&&e.error("First element of tau*G2 section must be the generator"),!1;if(!n.G2.eq(u.tauG2,_.singularPoints[1]))return e&&e.error("Second element of tau*G2 section does not match the one in the contribution section"),!1;e&&e.debug("Verifying powers in alpha*tau*G1 section");const p=await A(4,"G1","alphatauG1",2**r,[0],e);if(a=await Zi(n,p.R1,p.R2,n.G2.g,u.tauG2),!0!==a)return e&&e.error("alphaTauG1 section. Powers do not match"),!1;if(!n.G1.eq(u.alphaG1,p.singularPoints[0]))return e&&e.error("First element of alpha*tau*G1 section (alpha*G1) does not match the one in the contribution section"),!1;e&&e.debug("Verifying powers in beta*tau*G1 section");const h=await A(5,"G1","betatauG1",2**r,[0],e);if(a=await Zi(n,h.R1,h.R2,n.G2.g,u.tauG2),!0!==a)return e&&e.error("betaTauG1 section. Powers do not match"),!1;if(!n.G1.eq(u.betaG1,h.singularPoints[0]))return e&&e.error("First element of beta*tau*G1 section (beta*G1) does not match the one in the contribution section"),!1;const m=await async function(t){const e=n.G2,a=2*e.F.n8,r=new Uint8Array(a);if(!o[6])throw t.error("File has no BetaG2 section"),new Error("File has no BetaG2 section");if(o[6].length>1)throw t.error("File has no BetaG2 section"),new Error("File has more than one GetaG2 section");i.pos=o[6][0].p;const c=await i.read(a),l=e.fromRprLEM(c);return e.toRprUncompressed(r,0,l),g.update(r),l}(e);if(!n.G2.eq(u.betaG2,m))return e&&e.error("betaG2 element in betaG2 section does not match the one in the contribution section"),!1;const L=g.digest();if(r==c&&!ii(L,u.nextChallenge))return e&&e.error("Hash of the values does not match the next challenge of the last contributor in the contributions section"),!1;e&&e.info(ai(L,"Next challenge hash: ")),w(u,d);for(let t=l.length-2;t>=0;t--){const a=l[t],i=t>0?l[t-1]:s;if(!await Yi(n,a,i,e))return!1;w(a,i)}if(e&&e.info("-----------------------------------------------------"),o[12]&&o[13]&&o[14]&&o[15]){let t;if(t=await b("G1",2,12,"tauG1",e),!t)return!1;if(t=await b("G2",3,13,"tauG2",e),!t)return!1;if(t=await b("G1",4,14,"alphaTauG1",e),!t)return!1;if(t=await b("G1",5,15,"betaTauG1",e),!t)return!1}else e&&e.warn('this file does not contain phase2 precalculated values. Please run: \n snarkjs "powersoftau preparephase2" to prepare this file to be used in the phase2 ceremony.');return await i.close(),e&&e.info("Powers of Tau Ok!"),!0;function w(t,a){if(!e)return;e.info("-----------------------------------------------------"),e.info(`Contribution #${t.id}: ${t.name||""}`),e.info(ai(t.nextChallenge,"Next Challenge: "));const i=new Uint8Array(2*n.G1.F.n8*6+2*n.G2.F.n8*3);Ti(i,0,n,t.key,!1);const o=Wa(64);o.setPartialHash(t.partialHash),o.update(i);const r=o.digest();e.info(ai(r,"Response Hash:")),e.info(ai(a.nextChallenge,"Response Hash:")),1==t.type&&(e.info(`Beacon generator: ${si(t.beaconHash)}`),e.info(`Beacon iterations Exp: ${t.numIterationsExp}`))}async function A(t,e,a,r,c,l){const s=n[e],d=2*s.F.n8;await pa(i,o,t);const u=[];let f=s.zero,_=s.zero,p=s.zero;for(let t=0;t0){const t=s.fromRprLEM(o,0),e=wt.randomBytes(4).readUInt32BE(0,!0);f=s.add(f,s.timesScalar(p,e)),_=s.add(_,s.timesScalar(t,e))}const m=await s.multiExpAffine(o.slice(0,(e-1)*d),h),L=await s.multiExpAffine(o.slice(d),h);f=s.add(f,m),_=s.add(_,L),p=s.fromRprLEM(o,(e-1)*d);for(let a=0;a=t&&i1;)s/=2,d+=1;if(2**d!=l)throw new Error("Invalid file size");o&&o.debug("Power to tau size: "+d);const u=await ri(i),g=await sa(a),f=Wa(64);for(let t=0;t{o.debug(e+".g1_s: "+t.G1.toString(h[e].g1_s,16)),o.debug(e+".g1_sx: "+t.G1.toString(h[e].g1_sx,16)),o.debug(e+".g2_sp: "+t.G2.toString(h[e].g2_sp,16)),o.debug(e+".g2_spx: "+t.G2.toString(h[e].g2_spx,16)),o.debug("")}));const m=Wa(64);await g.write(p),m.update(p),await Wi(n,g,m,t,"G1",2**d*2-1,t.Fr.one,h.tau.prvKey,"COMPRESSED","tauG1",o),await Wi(n,g,m,t,"G2",2**d,t.Fr.one,h.tau.prvKey,"COMPRESSED","tauG2",o),await Wi(n,g,m,t,"G1",2**d,h.alpha.prvKey,h.tau.prvKey,"COMPRESSED","alphaTauG1",o),await Wi(n,g,m,t,"G1",2**d,h.beta.prvKey,h.tau.prvKey,"COMPRESSED","betaTauG1",o),await Wi(n,g,m,t,"G2",1,h.beta.prvKey,h.tau.prvKey,"COMPRESSED","betaTauG2",o);const L=new Uint8Array(2*t.F1.n8*6+2*t.F2.n8*3);Ti(L,0,t,h,!1),await g.write(L),m.update(L);const w=m.digest();o&&o.info(ai(w,"Contribution Response Hash: ")),await g.close(),await n.close()},beacon:async function(t,e,a,i,o,n){const r=li(i);if(0==r.byteLength||2*r.byteLength!=i.length)return n&&n.error("Invalid Beacon Hash. (It must be a valid hexadecimal sequence)"),!1;if(r.length>=256)return n&&n.error("Maximum lenght of beacon hash is 255 bytes"),!1;if((o=parseInt(o))<10||o>63)return n&&n.error("Invalid numIterationsExp. (Must be between 10 and 63)"),!1;await Wa.ready();const{fd:c,sections:l}=await ua(t,"ptau",1),{curve:s,power:d,ceremonyPower:u}=await Ri(c,l);if(d!=u)return n&&n.error("This file has been reduced. You cannot contribute into a reduced file."),!1;l[12]&&n&&n.warn("Contributing into a file that has phase2 calculated. You will have to prepare phase2 again.");const g=await Ki(c,s,l),f={name:a,type:1,numIterationsExp:o,beaconHash:r};let _;_=g.length>0?g[g.length-1].nextChallenge:Hi(s,d,n),f.key=$i(s,_,r,o);const p=new Wa(64);p.update(_);const h=await ga(e,"ptau",1,7);await ki(h,s,d);const m=[];let L;L=await y(2,"G1",2**d*2-1,s.Fr.e(1),f.key.tau.prvKey,"tauG1",n),f.tauG1=L[1],L=await y(3,"G2",2**d,s.Fr.e(1),f.key.tau.prvKey,"tauG2",n),f.tauG2=L[1],L=await y(4,"G1",2**d,f.key.alpha.prvKey,f.key.tau.prvKey,"alphaTauG1",n),f.alphaG1=L[0],L=await y(5,"G1",2**d,f.key.beta.prvKey,f.key.tau.prvKey,"betaTauG1",n),f.betaG1=L[0],L=await y(6,"G2",1,f.key.beta.prvKey,f.key.tau.prvKey,"betaTauG2",n),f.betaG2=L[0],f.partialHash=p.getPartialHash();const w=new Uint8Array(2*s.F1.n8*6+2*s.F2.n8*3);Ti(w,0,s,f.key,!1),p.update(new Uint8Array(w));const A=p.digest();n&&n.info(ai(A,"Contribution Response Hash imported: "));const b=new Wa(64);return b.update(A),await I(h,"G1",2,2**d*2-1,"tauG1",n),await I(h,"G2",3,2**d,"tauG2",n),await I(h,"G1",4,2**d,"alphaTauG1",n),await I(h,"G1",5,2**d,"betaTauG1",n),await I(h,"G2",6,1,"betaG2",n),f.nextChallenge=b.digest(),n&&n.info(ai(f.nextChallenge,"Next Challenge Hash: ")),g.push(f),await ji(h,s,g),await c.close(),await h.close(),A;async function y(t,e,a,i,o,n,r){const d=[];c.pos=l[t][0].p,await fa(h,t),m[t]=h.pos;const u=s[e],g=2*u.F.n8,f=Math.floor((1<<20)/g);let _=i;for(let t=0;t0?d[d.length-1].nextChallenge:Hi(c,l,o),u.key=Mi(c,g,f);const _=new Wa(64);_.update(g);const p=await ga(e,"ptau",1,7);await ki(p,c,l);const h=[];let m;m=await b(2,"G1",2**l*2-1,c.Fr.e(1),u.key.tau.prvKey,"tauG1"),u.tauG1=m[1],m=await b(3,"G2",2**l,c.Fr.e(1),u.key.tau.prvKey,"tauG2"),u.tauG2=m[1],m=await b(4,"G1",2**l,u.key.alpha.prvKey,u.key.tau.prvKey,"alphaTauG1"),u.alphaG1=m[0],m=await b(5,"G1",2**l,u.key.beta.prvKey,u.key.tau.prvKey,"betaTauG1"),u.betaG1=m[0],m=await b(6,"G2",1,u.key.beta.prvKey,u.key.tau.prvKey,"betaTauG2"),u.betaG2=m[0],u.partialHash=_.getPartialHash();const L=new Uint8Array(2*c.F1.n8*6+2*c.F2.n8*3);Ti(L,0,c,u.key,!1),_.update(new Uint8Array(L));const w=_.digest();o&&o.info(ai(w,"Contribution Response Hash imported: "));const A=new Wa(64);return A.update(w),await y(p,"G1",2,2**l*2-1,"tauG1"),await y(p,"G2",3,2**l,"tauG2"),await y(p,"G1",4,2**l,"alphaTauG1"),await y(p,"G1",5,2**l,"betaTauG1"),await y(p,"G2",6,1,"betaG2"),u.nextChallenge=A.digest(),o&&o.info(ai(u.nextChallenge,"Next Challenge Hash: ")),d.push(u),await ji(p,c,d),await n.close(),await p.close(),w;async function b(t,e,a,i,l,s){const d=[];n.pos=r[t][0].p,await fa(p,t),h[t]=p.pos;const u=c[e],g=2*u.F.n8,f=Math.floor((1<<20)/g);let m=i;for(let t=0;t=this.length&&(this.length=t+1),!0}getKeys(){const t=new io;for(let e=0;e1<<20?new io:[];for(let t=0;t1<<20?new io:[];for(let t=0;t{a[i]=lo(t,e[i])})),a}return"bigint"==typeof e||void 0!==e.eq?e.toString(10):e}var so=Object.freeze({__proto__:null,print:function(t,e,a){for(let e=0;e{let i="";return Object.keys(a).forEach((o=>{let n=e.varIdx2Name[o];"one"==n&&(n="");let r=t.curve.Fr.toString(a[o]);"1"==r&&(r=""),"-1"==r&&(r="-"),""!=i&&"-"!=r[0]&&(r="+"+r),""!=i&&(r=" "+r),i=i+r+n})),i},n=`[ ${o(i[0])} ] * [ ${o(i[1])} ] - [ ${o(i[2])} ] = 0`;a&&a.info(n)}},info:async function(t,e){const a=await no(t);return He.eq(a.prime,co)?e&&e.info("Curve: bn-128"):He.eq(a.prime,ro)?e&&e.info("Curve: bls12-381"):e&&e.info(`Unknown Curve. Prime: ${He.toString(a.prime)}`),e&&e.info(`# of Wires: ${a.nVars}`),e&&e.info(`# of Constraints: ${a.nConstraints}`),e&&e.info(`# of Private Inputs: ${a.nPrvInputs}`),e&&e.info(`# of Public Inputs: ${a.nPubInputs}`),e&&e.info(`# of Labels: ${a.nLabels}`),e&&e.info(`# of Outputs: ${a.nOutputs}`),a},exportJson:async function(t,e){const a=await no(t,!0,!0,!0,e),i=a.curve.Fr;return delete a.curve,lo(i,a)}});async function uo(t){const e={labelIdx2Name:["one"],varIdx2Name:["one"],componentIdx2Name:[]},a=await da(t),i=await a.read(a.totalSize),o=new TextDecoder("utf-8").decode(i).split("\n");for(let t=0;t=this.length&&(this.length=t+1),!0}getKeys(){const t=new ho;for(let e=0;el)return i&&i.error(`circuit too big for this power of tau ceremony. ${u.nConstraints}*2 > 2**${l}`),-1;if(!r[12])return i&&i.error("Powers of tau is not prepared."),-1;const h=u.nOutputs+u.nPubInputs,m=2**p;await fa(g,1),await g.writeULE32(1),await _a(g),await fa(g,2);const L=c.q,w=8*(Math.floor((He.bitLength(L)-1)/64)+1),A=c.r,b=8*(Math.floor((He.bitLength(A)-1)/64)+1),y=He.mod(He.shl(1,8*b),A),I=c.Fr.e(He.mod(He.mul(y,y),A));let C,F,x;await g.writeULE32(w),await ma(g,L,w),await g.writeULE32(b),await ma(g,A,b),await g.writeULE32(u.nVars),await g.writeULE32(h),await g.writeULE32(m),C=await n.read(f,r[4][0].p),await g.write(C),C=await c.G1.batchLEMtoU(C),o.update(C),F=await n.read(f,r[5][0].p),await g.write(F),F=await c.G1.batchLEMtoU(F),o.update(F),x=await n.read(_,r[6][0].p),await g.write(x),x=await c.G2.batchLEMtoU(x),o.update(x);const v=new Uint8Array(f);c.G1.toRprLEM(v,0,c.G1.g);const E=new Uint8Array(_);c.G2.toRprLEM(E,0,c.G2.g);const B=new Uint8Array(f);c.G1.toRprUncompressed(B,0,c.G1.g);const S=new Uint8Array(_);c.G2.toRprUncompressed(S,0,c.G2.g),await g.write(E),await g.write(v),await g.write(E),o.update(S),o.update(B),o.update(S),await _a(g),i&&i.info("Reading r1cs");let G=await Aa(s,d,2);const P=new ho(u.nVars),O=new ho(u.nVars),U=new ho(u.nVars),z=new ho(u.nVars-h-1),q=new Array(h+1);i&&i.info("Reading tauG1");let Q=await Aa(n,r,12,(m-1)*f,m*f);i&&i.info("Reading tauG2");let M=await Aa(n,r,13,(m-1)*_,m*_);i&&i.info("Reading alphatauG1");let k=await Aa(n,r,14,(m-1)*f,m*f);i&&i.info("Reading betatauG1");let R=await Aa(n,r,15,(m-1)*f,m*f);await async function(){const t=new Uint8Array(12+c.Fr.n8),e=new DataView(t.buffer),a=new Uint8Array(c.Fr.n8);c.Fr.toRprLE(a,0,c.Fr.e(1));let o=0;function n(){const t=G.slice(o,o+4);o+=4;return new DataView(t.buffer).getUint32(0,!0)}const r=new ho;for(let t=0;t=0?c.Fr.fromRprLE(G.slice(i[3],i[3]+c.Fr.n8),0):c.Fr.fromRprLE(a,0);const n=c.Fr.mul(o,I);c.Fr.toRprLE(t,12,n),l.set(t,d),d+=t.length}await g.write(l),await _a(g)}(),await T(3,"G1",q,"IC"),await async function(){await fa(g,9);const t=new fe(m*f);if(p(i&&i.debug(`Writing points end ${n}: ${d}/${a.length}`),t)))),s+=o,t++}const d=await Promise.all(l);for(let t=0;t32768?(f=new fe(p*n),_=new fe(p*c.Fr.n8)):(f=new Uint8Array(p*n),_=new Uint8Array(p*c.Fr.n8));let h=0,m=0;const L=[Q,M,k,R],w=new Uint8Array(c.Fr.n8);c.Fr.toRprLE(w,0,c.Fr.e(1));let A=0;for(let t=0;t=0?_.set(G.slice(e[t][o][2],e[t][o][2]+c.Fr.n8),A*c.Fr.n8):_.set(w,A*c.Fr.n8),A++;if(e.length>1){const t=[];t.push({cmd:"ALLOCSET",var:0,buff:f}),t.push({cmd:"ALLOCSET",var:1,buff:_}),t.push({cmd:"ALLOC",var:2,len:e.length*r}),h=0,m=0;let a=0;for(let i=0;i=0;t--){const e=d.contributions[t];i&&i.info("-------------------------"),i&&i.info(ai(e.contributionHash,`contribution #${t+1} ${e.name?e.name:""}:`)),1==e.type&&(i&&i.info(`Beacon generator: ${si(e.beaconHash)}`),i&&i.info(`Beacon iterations Exp: ${e.numIterationsExp}`))}return i&&i.info("-------------------------"),i&&i.info("ZKey Ok!"),!0;async function L(t,e){const a=2*l.G1.F.n8,i=t.byteLength/a,o=l.tm.concurrency,n=Math.floor(i/o),r=[];for(let a=0;ag.contributions.length)return o&&o.error("The impoerted file does not include new contributions"),!1;for(let t=0;t=256)return n&&n.error("Maximum lenght of beacon hash is 255 bytes"),!1;if((o=parseInt(o))<10||o>63)return n&&n.error("Invalid numIterationsExp. (Must be between 10 and 63)"),!1;const{fd:c,sections:l}=await ua(t,"zkey",2),s=await pi(c,l);if("groth16"!=s.protocol)throw new Error("zkey file is not groth16");const d=await Ca(s.q),u=await mi(c,d,l),g=await ga(e,"zkey",1,10),f=await ci(r,o),_=Wa(64);_.update(u.csHash);for(let t=0;t>5,this.byteCount=this.blockCount<<2,this.outputBlocks=a>>5,this.extraBytes=(31&a)>>3;for(var i=0;i<50;++i)this.s[i]=0}function P(t,e,a){G.call(this,t,e,a)}G.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var a,i=typeof t;if("string"!==i){if("object"!==i)throw new Error(e);if(null===t)throw new Error(e);if(r&&t.constructor===ArrayBuffer)t=new Uint8Array(t);else if(!(Array.isArray(t)||r&&ArrayBuffer.isView(t)))throw new Error(e);a=!0}for(var o,n,c=this.blocks,l=this.byteCount,s=t.length,u=this.blockCount,g=0,f=this.s;g>2]|=t[g]<>2]|=n<>2]|=(192|n>>6)<>2]|=(128|63&n)<=57344?(c[o>>2]|=(224|n>>12)<>2]|=(128|n>>6&63)<>2]|=(128|63&n)<>2]|=(240|n>>18)<>2]|=(128|n>>12&63)<>2]|=(128|n>>6&63)<>2]|=(128|63&n)<=l){for(this.start=o-l,this.block=c[u],o=0;o>=8);a>0;)o.unshift(a),a=255&(t>>=8),++i;return e?o.push(i):o.unshift(i),this.update(o),o.length},G.prototype.encodeString=function(t){var a,i=typeof t;if("string"!==i){if("object"!==i)throw new Error(e);if(null===t)throw new Error(e);if(r&&t.constructor===ArrayBuffer)t=new Uint8Array(t);else if(!(Array.isArray(t)||r&&ArrayBuffer.isView(t)))throw new Error(e);a=!0}var o=0,n=t.length;if(a)o=n;else for(var c=0;c=57344?o+=3:(l=65536+((1023&l)<<10|1023&t.charCodeAt(++c)),o+=4)}return o+=this.encode(8*o),this.update(t),o},G.prototype.bytepad=function(t,e){for(var a=this.encode(e),i=0;i>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[a],e=1;e>4&15]+c[15&t]+c[t>>12&15]+c[t>>8&15]+c[t>>20&15]+c[t>>16&15]+c[t>>28&15]+c[t>>24&15];r%e==0&&(O(a),n=0)}return o&&(t=a[n],l+=c[t>>4&15]+c[15&t],o>1&&(l+=c[t>>12&15]+c[t>>8&15]),o>2&&(l+=c[t>>20&15]+c[t>>16&15])),l},G.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,a=this.s,i=this.outputBlocks,o=this.extraBytes,n=0,r=0,c=this.outputBits>>3;t=o?new ArrayBuffer(i+1<<2):new ArrayBuffer(c);for(var l=new Uint32Array(t);r>8&255,l[t+2]=e>>16&255,l[t+3]=e>>24&255;c%a==0&&O(i)}return n&&(t=c<<2,e=i[r],l[t]=255&e,n>1&&(l[t+1]=e>>8&255),n>2&&(l[t+2]=e>>16&255)),l},P.prototype=new G,P.prototype.finalize=function(){return this.encode(this.outputBits,!0),G.prototype.finalize.call(this)};var O=function(t){var e,a,i,o,n,r,c,l,s,d,g,f,_,p,h,m,L,w,A,b,y,I,C,F,x,v,E,B,S,G,P,O,U,z,q,Q,M,k,R,N,T,D,K,V,j,H,$,Z,Y,J,W,X,tt,et,at,it,ot,nt,rt,ct,lt,st,dt;for(i=0;i<48;i+=2)o=t[0]^t[10]^t[20]^t[30]^t[40],n=t[1]^t[11]^t[21]^t[31]^t[41],r=t[2]^t[12]^t[22]^t[32]^t[42],c=t[3]^t[13]^t[23]^t[33]^t[43],l=t[4]^t[14]^t[24]^t[34]^t[44],s=t[5]^t[15]^t[25]^t[35]^t[45],d=t[6]^t[16]^t[26]^t[36]^t[46],g=t[7]^t[17]^t[27]^t[37]^t[47],e=(f=t[8]^t[18]^t[28]^t[38]^t[48])^(r<<1|c>>>31),a=(_=t[9]^t[19]^t[29]^t[39]^t[49])^(c<<1|r>>>31),t[0]^=e,t[1]^=a,t[10]^=e,t[11]^=a,t[20]^=e,t[21]^=a,t[30]^=e,t[31]^=a,t[40]^=e,t[41]^=a,e=o^(l<<1|s>>>31),a=n^(s<<1|l>>>31),t[2]^=e,t[3]^=a,t[12]^=e,t[13]^=a,t[22]^=e,t[23]^=a,t[32]^=e,t[33]^=a,t[42]^=e,t[43]^=a,e=r^(d<<1|g>>>31),a=c^(g<<1|d>>>31),t[4]^=e,t[5]^=a,t[14]^=e,t[15]^=a,t[24]^=e,t[25]^=a,t[34]^=e,t[35]^=a,t[44]^=e,t[45]^=a,e=l^(f<<1|_>>>31),a=s^(_<<1|f>>>31),t[6]^=e,t[7]^=a,t[16]^=e,t[17]^=a,t[26]^=e,t[27]^=a,t[36]^=e,t[37]^=a,t[46]^=e,t[47]^=a,e=d^(o<<1|n>>>31),a=g^(n<<1|o>>>31),t[8]^=e,t[9]^=a,t[18]^=e,t[19]^=a,t[28]^=e,t[29]^=a,t[38]^=e,t[39]^=a,t[48]^=e,t[49]^=a,p=t[0],h=t[1],H=t[11]<<4|t[10]>>>28,$=t[10]<<4|t[11]>>>28,B=t[20]<<3|t[21]>>>29,S=t[21]<<3|t[20]>>>29,ct=t[31]<<9|t[30]>>>23,lt=t[30]<<9|t[31]>>>23,D=t[40]<<18|t[41]>>>14,K=t[41]<<18|t[40]>>>14,z=t[2]<<1|t[3]>>>31,q=t[3]<<1|t[2]>>>31,m=t[13]<<12|t[12]>>>20,L=t[12]<<12|t[13]>>>20,Z=t[22]<<10|t[23]>>>22,Y=t[23]<<10|t[22]>>>22,G=t[33]<<13|t[32]>>>19,P=t[32]<<13|t[33]>>>19,st=t[42]<<2|t[43]>>>30,dt=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,at=t[4]<<30|t[5]>>>2,Q=t[14]<<6|t[15]>>>26,M=t[15]<<6|t[14]>>>26,w=t[25]<<11|t[24]>>>21,A=t[24]<<11|t[25]>>>21,J=t[34]<<15|t[35]>>>17,W=t[35]<<15|t[34]>>>17,O=t[45]<<29|t[44]>>>3,U=t[44]<<29|t[45]>>>3,F=t[6]<<28|t[7]>>>4,x=t[7]<<28|t[6]>>>4,it=t[17]<<23|t[16]>>>9,ot=t[16]<<23|t[17]>>>9,k=t[26]<<25|t[27]>>>7,R=t[27]<<25|t[26]>>>7,b=t[36]<<21|t[37]>>>11,y=t[37]<<21|t[36]>>>11,X=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,V=t[8]<<27|t[9]>>>5,j=t[9]<<27|t[8]>>>5,v=t[18]<<20|t[19]>>>12,E=t[19]<<20|t[18]>>>12,nt=t[29]<<7|t[28]>>>25,rt=t[28]<<7|t[29]>>>25,N=t[38]<<8|t[39]>>>24,T=t[39]<<8|t[38]>>>24,I=t[48]<<14|t[49]>>>18,C=t[49]<<14|t[48]>>>18,t[0]=p^~m&w,t[1]=h^~L&A,t[10]=F^~v&B,t[11]=x^~E&S,t[20]=z^~Q&k,t[21]=q^~M&R,t[30]=V^~H&Z,t[31]=j^~$&Y,t[40]=et^~it&nt,t[41]=at^~ot&rt,t[2]=m^~w&b,t[3]=L^~A&y,t[12]=v^~B&G,t[13]=E^~S&P,t[22]=Q^~k&N,t[23]=M^~R&T,t[32]=H^~Z&J,t[33]=$^~Y&W,t[42]=it^~nt&ct,t[43]=ot^~rt<,t[4]=w^~b&I,t[5]=A^~y&C,t[14]=B^~G&O,t[15]=S^~P&U,t[24]=k^~N&D,t[25]=R^~T&K,t[34]=Z^~J&X,t[35]=Y^~W&tt,t[44]=nt^~ct&st,t[45]=rt^~lt&dt,t[6]=b^~I&p,t[7]=y^~C&h,t[16]=G^~O&F,t[17]=P^~U&x,t[26]=N^~D&z,t[27]=T^~K&q,t[36]=J^~X&V,t[37]=W^~tt&j,t[46]=ct^~st&et,t[47]=lt^~dt&at,t[8]=I^~p&m,t[9]=C^~h&L,t[18]=O^~F&v,t[19]=U^~x&E,t[28]=D^~z&Q,t[29]=K^~q&M,t[38]=X^~V&H,t[39]=tt^~j&$,t[48]=st^~et&it,t[49]=dt^~at&ot,t[0]^=u[i],t[1]^=u[i+1]};if(n)t.exports=I;else for(F=0;F3*l.domainSize-4&&!d.isZero(e))throw new Error("T Polynomial is not divisible")}a&&a.debug("ifft Tz");const x=await d.ifft(I);for(let t=0;t<4*l.domainSize;t++){const e=x.slice(t*g,(t+1)*g);if(t>3*l.domainSize+5){if(!d.isZero(e))throw new Error("Tz Polynomial is not well calculated")}else F.set(d.add(F.slice(t*g,(t+1)*g),e),t*g)}function E(t,e,a,i,o){let n,r;const c=d.mul(t,e),l=d.mul(t,i),s=d.mul(a,e);n=c;let u=d.mul(a,i);return r=d.add(l,s),o&&(r=d.add(r,d.mul(_[o],u))),[n,r]}function G(t,e,a,i,o,n,r,c,l){let s,u;const g=d.mul(t,e),f=d.mul(t,n),p=d.mul(o,e),L=d.mul(o,n),w=d.mul(a,i),A=d.mul(a,c),b=d.mul(r,i),y=d.mul(r,c);s=d.mul(g,w);let I=d.mul(p,w);I=d.add(I,d.mul(f,w)),I=d.add(I,d.mul(g,b)),I=d.add(I,d.mul(g,A));let C=d.mul(L,w);C=d.add(C,d.mul(p,b)),C=d.add(C,d.mul(p,A)),C=d.add(C,d.mul(f,b)),C=d.add(C,d.mul(f,A)),C=d.add(C,d.mul(g,y));let F=d.mul(f,y);F=d.add(F,d.mul(p,y)),F=d.add(F,d.mul(L,A)),F=d.add(F,d.mul(L,b));let x=d.mul(L,y);return u=I,l&&(u=d.add(u,d.mul(_[l],C)),u=d.add(u,d.mul(h[l],F)),u=d.add(u,d.mul(m[l],x))),[s,u]}v=F.slice(0,(3*l.domainSize+6)*g),B.T1=await T(F.slice(0,l.domainSize*g),"multiexp T1"),B.T2=await T(F.slice(l.domainSize*g,2*l.domainSize*g),"multiexp T2"),B.T3=await T(F.slice(2*l.domainSize*g,(3*l.domainSize+6)*g),"multiexp T3")}(),await async function(){const t=new fe(l.domainSize*g);await r.readToBuffer(t,0,l.domainSize*g,c[7][0].p);const e=new fe(l.domainSize*g);await r.readToBuffer(e,0,l.domainSize*g,c[8][0].p);const i=new fe(l.domainSize*g);await r.readToBuffer(i,0,l.domainSize*g,c[9][0].p);const o=new fe(l.domainSize*g);await r.readToBuffer(o,0,l.domainSize*g,c[10][0].p);const n=new fe(l.domainSize*g);await r.readToBuffer(n,0,l.domainSize*g,c[11][0].p);const s=new fe(l.domainSize*g);await r.readToBuffer(s,0,l.domainSize*g,c[12][0].p+10*l.domainSize*g);const f=new Uint8Array(2*u.F.n8*3);u.toRprUncompressed(f,0,B.T1),u.toRprUncompressed(f,2*u.F.n8,B.T2),u.toRprUncompressed(f,4*u.F.n8,B.T3),z.xi=k(f),a&&a.debug("xi: "+d.toString(z.xi));B.eval_a=R(I,z.xi),B.eval_b=R(C,z.xi),B.eval_c=R(F,z.xi),B.eval_s1=R(P,z.xi),B.eval_s2=R(O,z.xi),B.eval_t=R(v,z.xi),B.eval_zw=R(x,d.mul(z.xi,d.w[l.power]));const _=d.mul(B.eval_a,B.eval_b);let p=B.eval_a;const h=d.mul(z.beta,z.xi);p=d.add(p,h),p=d.add(p,z.gamma);let m=B.eval_b;m=d.add(m,d.mul(h,l.k1)),m=d.add(m,z.gamma);let L=B.eval_c;L=d.add(L,d.mul(h,l.k2)),L=d.add(L,z.gamma);const w=d.mul(d.mul(d.mul(p,m),L),z.alpha);let A=B.eval_a;A=d.add(A,d.mul(z.beta,B.eval_s1)),A=d.add(A,z.gamma);let b=B.eval_b;b=d.add(b,d.mul(z.beta,B.eval_s2)),b=d.add(b,z.gamma);let y=d.mul(A,b);y=d.mul(y,z.beta),y=d.mul(y,B.eval_zw),y=d.mul(y,z.alpha),z.xim=z.xi;for(let t=0;t=0;o--)i=d.add(d.mul(i,e),t.slice(o*g,(o+1)*g));return i}function N(t,e){const a=t.byteLength/g,i=new fe(a*g);i.set(d.zero,(a-1)*g),i.set(t.slice((a-1)*g,a*g),(a-2)*g);for(let o=a-3;o>=0;o--)i.set(d.add(t.slice((o+1)*g,(o+2)*g),d.mul(e,i.slice((o+1)*g,(o+2)*g))),o*g);if(!d.eq(t.slice(0,g),d.mul(d.neg(e),i.slice(0,g))))throw new Error("Polinomial does not divide");return i}async function T(t,e){const i=t.byteLength/g,o=U.slice(0,i*s.G1.F.n8*2),n=await s.Fr.batchFromMontgomery(t);let r=await s.G1.multiExpAffine(o,n,a,e);return r=s.G1.toAffine(r),r}async function D(t,e){e=e||[];let a=await d.ifft(t);const i=new fe(g*l.domainSize*4);i.set(a,0);const o=new fe(g*(l.domainSize+e.length));o.set(a,0);for(let t=0;t>1),a=t.slice(t.length>>1),i=n(e),o=n(a),c=i[0],l=o[0],s=w++,d=r.Fr.zero,u=_.neg(i[1]),g=_.neg(o[1]),f=r.Fr.one,p=r.Fr.zero;return m.push([c,l,s,d,u,g,f,p]),L.push([c,l,i[1],o[1]]),[s,r.Fr.one]}for(let t=1;t<=A;t++){const e=t,a=0,i=0,o=r.Fr.zero,n=r.Fr.one,c=r.Fr.zero,l=r.Fr.zero,s=r.Fr.zero;m.push([e,a,i,o,n,c,l,s])}for(let t=0;tc)return i&&i.error(`circuit too big for this power of tau ceremony. ${m.length} > 2**${c}`),-1;if(!n[12])return i&&i.error("Powers of tau is not prepared."),-1;const C=new fe(I*u),F=n[12][0].p+(2**y-1)*u;await o.readToBuffer(C,0,I*u,F);const[x,v]=function(){let t=_.two;for(;a(t,[],y);)_.add(t,_.one);let e=_.add(t,_.one);for(;a(e,[t],y);)_.add(e,_.one);return[t,e];function a(t,e,a){const i=2**a;let o=_.one;for(let n=0;n