Skip to content

Instantly share code, notes, and snippets.

@vivianjeng
Created May 15, 2024 05:30
Show Gist options
  • Save vivianjeng/374c0fd6e45910e916fc5c2bba704131 to your computer and use it in GitHub Desktop.
Save vivianjeng/374c0fd6e45910e916fc5c2bba704131 to your computer and use it in GitHub Desktop.
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){const a=t.toString(16);return 4*(a.length-1)+e[parseInt(a[0],16)]}function n(t){return BigInt(t)<BigInt(0)}function l(t){return!t}function r(t,e){return BigInt(t)<<BigInt(e)}function s(t,e){return BigInt(t)>>BigInt(e)}const c=r,d=s;function u(t){return(BigInt(t)&BigInt(1))==BigInt(1)}function g(t){let e=BigInt(t);const a=[];for(;e;)e&BigInt(1)?a.push(1):a.push(0),e>>=BigInt(1);return a}function f(t){if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("Number too big");return Number(t)}function h(t,e){return BigInt(t)+BigInt(e)}function _(t,e){return BigInt(t)-BigInt(e)}function p(t){return-BigInt(t)}function m(t,e){return BigInt(t)*BigInt(e)}function w(t,e){return BigInt(t)**BigInt(e)}function L(t,e){return BigInt(t)/BigInt(e)}function b(t,e){return BigInt(t)%BigInt(e)}function y(t,e){return BigInt(t)==BigInt(e)}function A(t,e){return BigInt(t)>BigInt(e)}function C(t,e){return BigInt(t)>=BigInt(e)}function I(t,e){return BigInt(t)&BigInt(e)}function F(t,e,a,i){const o="0000000"+a.toString(16),n=new Uint32Array(t.buffer,t.byteOffset+e,i/4),l=1+(4*(o.length-7)-1>>5);for(let t=0;t<l;t++)n[t]=parseInt(o.substring(o.length-8*t-8,o.length-8*t),16);for(let t=l;t<n.length;t++)n[t]=0;for(let e=4*n.length;e<i;e++)t[e]=f(I(s(a,8*e),255))}function x(t,e,a,i){const o="0000000"+a.toString(16),n=new DataView(t.buffer,t.byteOffset+e,i),l=1+(4*(o.length-7)-1>>5);for(let t=0;t<l;t++)n.setUint32(i-4*t-4,parseInt(o.substring(o.length-8*t-8,o.length-8*t),16),!1);for(let t=0;t<i/4-l;t++)n[t]=0}function E(t,e,i){i=i||t.byteLength,e=e||0;const o=new Uint32Array(t.buffer,t.byteOffset+e,i/4),n=new Array(i/4);return o.forEach(((t,e)=>n[n.length-e-1]=t.toString(16).padStart(8,"0"))),a(n.join(""),16)}function v(t,e,i){i=i||t.byteLength,e=e||0;const o=new DataView(t.buffer,t.byteOffset+e,i),n=new Array(i/4);for(let t=0;t<i/4;t++)n[t]=o.getUint32(4*t,!1).toString(16).padStart(8,"0");return a(n.join(""),16)}function B(t,e){return t.toString(e)}function S(t){const e=new Uint8Array(Math.floor((o(t)-1)/8)+1);return F(e,0,t,e.byteLength),e}const P=i(0),G=i(1);var O=Object.freeze({__proto__:null,abs:function(t){return BigInt(t)>=0?BigInt(t):-BigInt(t)},add:h,band:I,bitLength:o,bits:g,bor:function(t,e){return BigInt(t)|BigInt(e)},bxor:function(t,e){return BigInt(t)^BigInt(e)},div:L,e:i,eq:y,exp:function(t,e){return BigInt(t)**BigInt(e)},fromArray:function(t,e){let a=BigInt(0);e=BigInt(e);for(let i=0;i<t.length;i++)a=a*e+BigInt(t[i]);return a},fromRprBE:v,fromRprLE:E,fromString:a,geq:C,gt:A,isNegative:n,isOdd:u,isZero:l,land:function(t,e){return BigInt(t)&&BigInt(e)},leq:function(t,e){return BigInt(t)<=BigInt(e)},lnot:function(t){return!BigInt(t)},lor:function(t,e){return BigInt(t)||BigInt(e)},lt:function(t,e){return BigInt(t)<BigInt(e)},mod:b,mul:m,naf:function(t){let e=BigInt(t);const a=[];for(;e;){if(e&BigInt(1)){const t=2-Number(e%BigInt(4));a.push(t),e-=BigInt(t)}else a.push(0);e>>=BigInt(1)}return a},neg:p,neq:function(t,e){return BigInt(t)!=BigInt(e)},one:G,pow:w,shiftLeft:r,shiftRight:s,shl:c,shr:d,square:function(t){return BigInt(t)*BigInt(t)},sub:_,toArray:function(t,e){const a=[];let i=BigInt(t);for(e=BigInt(e);i;)a.unshift(Number(i%e)),i/=e;return a},toLEBuff:S,toNumber:f,toRprBE:x,toRprLE:F,toString:B,zero:P});function T(t,e,a){if(l(a))return t.one;const i=g(a);if(0==i.length)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 U(t){if(t.m%2==1)if(y(b(t.p,4),1))if(y(b(t.p,8),1))if(y(b(t.p,16),1))!function(t){t.sqrt_q=w(t.p,t.m),t.sqrt_s=0,t.sqrt_t=_(t.sqrt_q,1);for(;!u(t.sqrt_t);)t.sqrt_s=t.sqrt_s+1,t.sqrt_t=L(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=L(_(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),l=e.mul(n,a),r=e.sqrt_z;for(;!e.eq(l,e.one);){let t=e.square(l),i=1;for(;!e.eq(t,e.one);)t=e.square(t),i++;a=r;for(let t=0;t<o-i-1;t++)a=e.square(a);r=e.square(a),l=e.mul(l,r),n=e.mul(n,a),o=i}return e.geq(n,e.zero)?n:e.neg(n)}}(t);else{if(!y(b(t.p,16),9))throw new Error("Field withot sqrt");!function(t){t.sqrt=function(){throw new Error("Sqrt alg 4 not implemented")}}(t)}else{if(!y(b(t.p,8),5))throw new Error("Field withot sqrt");!function(t){t.sqrt=function(){throw new Error("Sqrt alg 3 not implemented")}}(t)}else y(b(t.p,4),3)&&function(t){t.sqrt_q=w(t.p,t.m),t.sqrt_e1=L(_(t.sqrt_q,3),4),t.sqrt=function(e){if(this.isZero(e))return this.zero;const a=this.pow(e,this.sqrt_e1),i=this.mul(this.square(a),e);if(this.eq(i,this.negone))return null;const o=this.mul(a,e);return t.geq(o,t.zero)?o:t.neg(o)}}(t);else{const e=b(w(t.p,t.m/2),4);1==e?function(t){t.sqrt=function(){throw new Error("Sqrt alg 10 not implemented")}}(t):3==e?function(t){t.sqrt_q=w(t.p,t.m/2),t.sqrt_e34=L(_(t.sqrt_q,3),4),t.sqrt_e12=L(_(t.sqrt_q,1),2),t.frobenius=function(e,a){return e%2==1?t.conjugate(a):a},t.sqrt=function(t){const e=this,a=e.pow(t,e.sqrt_e34),i=e.mul(e.square(a),t),o=e.mul(e.frobenius(1,i),i);if(e.eq(o,e.negone))return null;const n=e.mul(a,t);let l;if(e.eq(i,e.negone))l=e.mul(n,[e.F.zero,e.F.one]);else{const t=e.pow(e.add(e.one,i),e.sqrt_e12);l=e.mul(t,n)}return e.geq(l,e.zero)?l:e.neg(l)}}(t):function(t){t.sqrt=function(){throw new Error("Sqrt alg 8 not implemented")}}(t)}}function z(t,e,a,i,o){t[e]=t[e]+t[a]>>>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 Q{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 h(m(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++)z(t=this.buff,0,4,8,12),z(t,1,5,9,13),z(t,2,6,10,14),z(t,3,7,11,15),z(t,0,5,10,15),z(t,1,6,11,12),z(t,2,7,8,13),z(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)))}}function q(t){let e=new Uint8Array(t);if(void 0!==globalThis.crypto)globalThis.crypto.getRandomValues(e);else for(let a=0;a<t;a++)e[a]=4294967296*Math.random()>>>0;return e}let M=null;function k(){return M||(M=new Q(function(){const t=q(32),e=new Uint32Array(t.buffer),a=[];for(let t=0;t<8;t++)a.push(e[t]);return a}()),M)}class R{constructor(t,e,a){this.F=e,this.G=t,this.opMulGF=a;let i=e.sqrt_t||e.t,o=e.sqrt_s||e.s,n=e.one;for(;e.eq(e.pow(n,e.half),e.one);)n=e.add(n,e.one);this.w=new Array(o+1),this.wi=new Array(o+1),this.w[o]=this.F.pow(n,i),this.wi[o]=this.F.inv(this.w[o]);let l=o-1;for(;l>=0;)this.w[l]=this.F.square(this.w[l+1]),this.wi[l]=this.F.square(this.wi[l+1]),l--;this.roots=[],this._setRoots(Math.min(o,15))}_setRoots(t){for(let e=t;e>=0&&!this.roots[e];e--){let t=this.F.one;const a=1<<e,i=new Array(a);for(let o=0;o<a;o++)i[o]=t,t=this.F.mul(t,this.w[e]);this.roots[e]=i}}fft(t){if(t.length<=1)return t;const e=D(t.length-1)+1;this._setRoots(e);const a=1<<e;if(t.length!=a)throw new Error("Size must be multiple of 2");return N(this,t,e,0,1)}ifft(t){if(t.length<=1)return t;const e=D(t.length-1)+1;this._setRoots(e);const a=1<<e;if(t.length!=a)throw new Error("Size must be multiple of 2");const i=N(this,t,e,0,1),o=this.F.inv(this.F.mulScalar(this.F.one,a)),n=new Array(a);for(let t=0;t<a;t++)n[t]=this.opMulGF(i[(a-t)%a],o);return n}}function D(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 N(t,e,a,i,o){const n=1<<a;if(1==n)return[e[i]];if(2==n)return[t.G.add(e[i],e[i+o]),t.G.sub(e[i],e[i+o])];const l=n>>1,r=N(t,e,a-1,i,2*o),s=N(t,e,a-1,i+o,2*o),c=new Array(n);for(let e=0;e<l;e++)c[e]=t.G.add(r[e],t.opMulGF(s[e],t.roots[a][e])),c[e+l]=t.G.sub(r[e],t.opMulGF(s[e],t.roots[a][e]));return c}class ${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=o(this.p),this.mask=(this.one<<BigInt(this.bitLength))-this.one,this.n64=Math.floor((this.bitLength-1)/64)+1,this.n32=2*this.n64,this.n8=8*this.n64,this.R=this.e(this.one<<BigInt(64*this.n64)),this.Ri=this.inv(this.R);const e=this.negone>>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),U(this),this.FFT=new R(this,this,this.mul.bind(this)),this.fft=this.FFT.fft.bind(this.FFT),this.ifft=this.FFT.ifft.bind(this.FFT),this.w=this.FFT.w,this.wi=this.FFT.wi,this.shift=this.square(this.nqr),this.k=this.exp(this.nqr,2**this.s)}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.zero&&(e+=this.p),e}mod(t,e){return t%e}pow(t,e){return T(this,t,e)}exp(t,e){return T(this,t,e)}band(t,e){const a=t&e&this.mask;return a>=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.bitLength){const a=t<<e&this.mask;return a>=this.p?a-this.p:a}{const a=this.p-e;return Number(a)<this.bitLength?t>>a:this.zero}}shr(t,e){if(Number(e)<this.bitLength)return t>>e;{const a=this.p-e;if(Number(a)<this.bitLength){const e=t<<a&this.mask;return e>=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 l=a;for(let t=0;t<e-n-1;t++)l=this.square(l);e=n,a=this.square(l),i=this.mul(i,a),o=this.mul(o,l)}return o>this.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;a<t;a++)e=(e<<BigInt(8))+BigInt(q(1)[0]);return e%this.p}toString(t,e){let a;if(e=e||10,t>this.half&&10==e){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.n64;a++)e+=t.nextU64()<<BigInt(64*a);e&=this.mask}while(e>=this.p);return e=e*this.Ri%this.p,e}fft(t){return this.FFT.fft(t)}ifft(t){return this.FFT.ifft(t)}toRprLE(t,e,a){F(t,e,a,8*this.n64)}toRprBE(t,e,a){x(t,e,a,8*this.n64)}toRprBEM(t,e,a){return this.toRprBE(t,e,this.mul(this.R,a))}toRprLEM(t,e,a){return this.toRprLE(t,e,this.mul(this.R,a))}fromRprLE(t,e){return E(t,e,this.n8)}fromRprBE(t,e){return v(t,e,this.n8)}fromRprLEM(t,e){return this.mul(this.fromRprLE(t,e),this.Ri)}fromRprBEM(t,e){return this.mul(this.fromRprBE(t,e),this.Ri)}toObject(t){return t}}var V={bigInt2BytesLE:function(t,e){const a=Array(e);let i=BigInt(t);for(let t=0;t<e;t++)a[t]=Number(0xFFn&i),i>>=8n;return a},bigInt2U32LE:function(t,e){const a=Array(e);let i=BigInt(t);for(let t=0;t<e;t++)a[t]=Number(0xFFFFFFFFn&i),i>>=32n;return a},isOcamNum:function(t){return!!Array.isArray(t)&&(3==t.length&&("number"==typeof t[0]&&("number"==typeof t[1]&&!!Array.isArray(t[2]))))}},K=function(t,e,a,i,o,n,l){const r=t.addFunction(e);r.addParam("base","i32"),r.addParam("scalar","i32"),r.addParam("scalarLength","i32"),r.addParam("r","i32"),r.addLocal("i","i32"),r.addLocal("b","i32");const s=r.getCodeBuilder(),c=s.i32_const(t.alloc(a));r.addCode(s.if(s.i32_eqz(s.getLocal("scalarLength")),[...s.call(l,s.getLocal("r")),...s.ret([])])),r.addCode(s.call(n,s.getLocal("base"),c)),r.addCode(s.call(l,s.getLocal("r"))),r.addCode(s.setLocal("i",s.getLocal("scalarLength"))),r.addCode(s.block(s.loop(s.setLocal("i",s.i32_sub(s.getLocal("i"),s.i32_const(1))),s.setLocal("b",s.i32_load8_u(s.i32_add(s.getLocal("scalar"),s.getLocal("i")))),...function(){const t=[];for(let e=0;e<8;e++)t.push(...s.call(o,s.getLocal("r"),s.getLocal("r")),...s.if(s.i32_ge_u(s.getLocal("b"),s.i32_const(128>>e)),[...s.setLocal("b",s.i32_sub(s.getLocal("b"),s.i32_const(128>>e))),...s.call(i,s.getLocal("r"),c,s.getLocal("r"))]));return t}(),s.br_if(1,s.i32_eqz(s.getLocal("i"))),s.br(0))))},j=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 H=function(t,e,a,i,o,n){void 0===n&&(n=i<o);const l=t.addFunction(e);l.addParam("pIn","i32"),l.addParam("n","i32"),l.addParam("pOut","i32"),l.addLocal("i","i32"),l.addLocal("itIn","i32"),l.addLocal("itOut","i32");const r=l.getCodeBuilder();n?l.addCode(r.setLocal("itIn",r.i32_add(r.getLocal("pIn"),r.i32_mul(r.i32_sub(r.getLocal("n"),r.i32_const(1)),r.i32_const(i)))),r.setLocal("itOut",r.i32_add(r.getLocal("pOut"),r.i32_mul(r.i32_sub(r.getLocal("n"),r.i32_const(1)),r.i32_const(o)))),r.setLocal("i",r.i32_const(0)),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("i"),r.getLocal("n"))),r.call(a,r.getLocal("itIn"),r.getLocal("itOut")),r.setLocal("itIn",r.i32_sub(r.getLocal("itIn"),r.i32_const(i))),r.setLocal("itOut",r.i32_sub(r.getLocal("itOut"),r.i32_const(o))),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0)))):l.addCode(r.setLocal("itIn",r.getLocal("pIn")),r.setLocal("itOut",r.getLocal("pOut")),r.setLocal("i",r.i32_const(0)),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("i"),r.getLocal("n"))),r.call(a,r.getLocal("itIn"),r.getLocal("itOut")),r.setLocal("itIn",r.i32_add(r.getLocal("itIn"),r.i32_const(i))),r.setLocal("itOut",r.i32_add(r.getLocal("itOut"),r.i32_const(o))),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0))))};var Z=function(t,e,a,i,o,n){void 0===n&&(n=i<o);const l=t.addFunction(e);l.addParam("pIn1","i32"),l.addParam("pIn2","i32"),l.addParam("n","i32"),l.addParam("pOut","i32"),l.addLocal("i","i32"),l.addLocal("itIn1","i32"),l.addLocal("itIn2","i32"),l.addLocal("itOut","i32");const r=l.getCodeBuilder();n?l.addCode(r.setLocal("itIn1",r.i32_add(r.getLocal("pIn1"),r.i32_mul(r.i32_sub(r.getLocal("n"),r.i32_const(1)),r.i32_const(i)))),r.setLocal("itIn2",r.i32_add(r.getLocal("pIn2"),r.i32_mul(r.i32_sub(r.getLocal("n"),r.i32_const(1)),r.i32_const(i)))),r.setLocal("itOut",r.i32_add(r.getLocal("pOut"),r.i32_mul(r.i32_sub(r.getLocal("n"),r.i32_const(1)),r.i32_const(o)))),r.setLocal("i",r.i32_const(0)),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("i"),r.getLocal("n"))),r.call(a,r.getLocal("itIn1"),r.getLocal("itIn2"),r.getLocal("itOut")),r.setLocal("itIn1",r.i32_sub(r.getLocal("itIn1"),r.i32_const(i))),r.setLocal("itIn2",r.i32_sub(r.getLocal("itIn2"),r.i32_const(i))),r.setLocal("itOut",r.i32_sub(r.getLocal("itOut"),r.i32_const(o))),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0)))):l.addCode(r.setLocal("itIn1",r.getLocal("pIn1")),r.setLocal("itIn2",r.getLocal("pIn2")),r.setLocal("itOut",r.getLocal("pOut")),r.setLocal("i",r.i32_const(0)),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("i"),r.getLocal("n"))),r.call(a,r.getLocal("itIn1"),r.getLocal("itIn2"),r.getLocal("itOut")),r.setLocal("itIn1",r.i32_add(r.getLocal("itIn1"),r.i32_const(i))),r.setLocal("itIn2",r.i32_add(r.getLocal("itIn2"),r.i32_const(i))),r.setLocal("itOut",r.i32_add(r.getLocal("itOut"),r.i32_const(o))),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0))))};var W={};function Y(t,e){return t===e?0:t>e?1:-1}function J(t){return t*t}function X(t){return t%2n!==0n}function tt(t){return t%2n===0n}function et(t){return t<0n}function at(t){return t>0n}function it(t){return et(t)?t.toString(2).length-1:t.toString(2).length}function ot(t){return t<0n?-t:t}function nt(t){return 1n===ot(t)}function lt(t,e){for(var a,i,o,n=0n,l=1n,r=e,s=ot(t);0n!==s;)a=r/s,i=n,o=r,n=l,r=s,l=i-a*l,s=o-a*s;if(!nt(r))throw new Error(t.toString()+" and "+e.toString()+" are not co-prime");return-1===Y(n,0n)&&(n+=e),et(t)?-n:n}function rt(t,e,a){if(0n===a)throw new Error("Cannot take modPow with modulus 0");var i=1n,o=t%a;for(et(e)&&(e*=-1n,o=lt(o,a));at(e);){if(0n===o)return 0n;X(e)&&(i=i*o%a),e/=2n,o=J(o)%a}return i}function st(t,e){return 0n!==e&&(!!nt(e)||(0===function(t,e){return(t=t>=0n?t:-t)===(e=e>=0n?e:-e)?0:t>e?1:-1}(e,2n)?tt(t):t%e===0n))}function ct(t,e){for(var a,i,o,n=function(t){return t-1n}(t),l=n,r=0;tt(l);)l/=2n,r++;t:for(i=0;i<e.length;i++)if(!(t<e[i]||nt(o=rt(BigInt(e[i]),l,t))||o===n)){for(a=r-1;0!=a;a--){if(nt(o=J(o)%t))return!1;if(o===n)continue t}return!1}return!0}W.bitLength=it,W.isOdd=X,W.isNegative=et,W.abs=ot,W.isUnit=nt,W.compare=Y,W.modInv=lt,W.modPow=rt,W.isPrime=function(t){var e=function(t){var e=ot(t);return!nt(e)&&(2n===e||3n===e||5n===e||!(tt(e)||st(e,3n)||st(e,5n))&&(e<49n||void 0))}(t);if(void 0!==e)return e;var a=ot(t),i=it(a);if(i<=64)return ct(a,[2,3,5,7,11,13,17,19,23,29,31,37]);for(var o=Math.log(2)*Number(i),n=Math.ceil(o),l=[],r=0;r<n;r++)l.push(BigInt(r+2));return ct(a,l)},W.square=J;const dt=function(t,e,a){const i=a||"int";if(t.modules[i])return i;t.modules[i]={};const o=2*e,n=8*e;return function(){const a=t.addFunction(i+"_copy");a.addParam("px","i32"),a.addParam("pr","i32");const o=a.getCodeBuilder();for(let t=0;t<e;t++)a.addCode(o.i64_store(o.getLocal("pr"),8*t,o.i64_load(o.getLocal("px"),8*t)))}(),function(){const a=t.addFunction(i+"_zero");a.addParam("pr","i32");const o=a.getCodeBuilder();for(let t=0;t<e;t++)a.addCode(o.i64_store(o.getLocal("pr"),8*t,o.i64_const(0)))}(),function(){const a=t.addFunction(i+"_isZero");a.addParam("px","i32"),a.setReturnType("i32");const o=a.getCodeBuilder();a.addCode(function t(e){return 0==e?o.ret(o.i64_eqz(o.i64_load(o.getLocal("px")))):o.if(o.i64_eqz(o.i64_load(o.getLocal("px"),8*e)),t(e-1),o.ret(o.i32_const(0)))}(e-1)),a.addCode(o.ret(o.i32_const(0)))}(),function(){const a=t.addFunction(i+"_one");a.addParam("pr","i32");const o=a.getCodeBuilder();a.addCode(o.i64_store(o.getLocal("pr"),0,o.i64_const(1)));for(let t=1;t<e;t++)a.addCode(o.i64_store(o.getLocal("pr"),8*t,o.i64_const(0)))}(),function(){const a=t.addFunction(i+"_eq");a.addParam("px","i32"),a.addParam("py","i32"),a.setReturnType("i32");const o=a.getCodeBuilder();a.addCode(function t(e){return 0==e?o.ret(o.i64_eq(o.i64_load(o.getLocal("px")),o.i64_load(o.getLocal("py")))):o.if(o.i64_eq(o.i64_load(o.getLocal("px"),8*e),o.i64_load(o.getLocal("py"),8*e)),t(e-1),o.ret(o.i32_const(0)))}(e-1)),a.addCode(o.ret(o.i32_const(0)))}(),function(){const a=t.addFunction(i+"_gte");a.addParam("px","i32"),a.addParam("py","i32"),a.setReturnType("i32");const o=a.getCodeBuilder();a.addCode(function t(e){return 0==e?o.ret(o.i64_ge_u(o.i64_load(o.getLocal("px")),o.i64_load(o.getLocal("py")))):o.if(o.i64_lt_u(o.i64_load(o.getLocal("px"),8*e),o.i64_load(o.getLocal("py"),8*e)),o.ret(o.i32_const(0)),o.if(o.i64_gt_u(o.i64_load(o.getLocal("px"),8*e),o.i64_load(o.getLocal("py"),8*e)),o.ret(o.i32_const(1)),t(e-1)))}(e-1)),a.addCode(o.ret(o.i32_const(0)))}(),function(){const e=t.addFunction(i+"_add");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32"),e.setReturnType("i32"),e.addLocal("c","i64");const a=e.getCodeBuilder();e.addCode(a.setLocal("c",a.i64_add(a.i64_load32_u(a.getLocal("x")),a.i64_load32_u(a.getLocal("y"))))),e.addCode(a.i64_store32(a.getLocal("r"),a.getLocal("c")));for(let t=1;t<o;t++)e.addCode(a.setLocal("c",a.i64_add(a.i64_add(a.i64_load32_u(a.getLocal("x"),4*t),a.i64_load32_u(a.getLocal("y"),4*t)),a.i64_shr_u(a.getLocal("c"),a.i64_const(32))))),e.addCode(a.i64_store32(a.getLocal("r"),4*t,a.getLocal("c")));e.addCode(a.i32_wrap_i64(a.i64_shr_u(a.getLocal("c"),a.i64_const(32))))}(),function(){const e=t.addFunction(i+"_sub");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32"),e.setReturnType("i32"),e.addLocal("c","i64");const a=e.getCodeBuilder();e.addCode(a.setLocal("c",a.i64_sub(a.i64_load32_u(a.getLocal("x")),a.i64_load32_u(a.getLocal("y"))))),e.addCode(a.i64_store32(a.getLocal("r"),a.i64_and(a.getLocal("c"),a.i64_const("0xFFFFFFFF"))));for(let t=1;t<o;t++)e.addCode(a.setLocal("c",a.i64_add(a.i64_sub(a.i64_load32_u(a.getLocal("x"),4*t),a.i64_load32_u(a.getLocal("y"),4*t)),a.i64_shr_s(a.getLocal("c"),a.i64_const(32))))),e.addCode(a.i64_store32(a.getLocal("r"),4*t,a.i64_and(a.getLocal("c"),a.i64_const("0xFFFFFFFF"))));e.addCode(a.i32_wrap_i64(a.i64_shr_s(a.getLocal("c"),a.i64_const(32))))}(),function(){const e=t.addFunction(i+"_mul");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32"),e.addLocal("c0","i64"),e.addLocal("c1","i64");for(let t=0;t<o;t++)e.addLocal("x"+t,"i64"),e.addLocal("y"+t,"i64");const a=e.getCodeBuilder(),n=[],l=[];function r(t,e){let i,o;return n[t]?i=a.getLocal("x"+t):(i=a.teeLocal("x"+t,a.i64_load32_u(a.getLocal("x"),4*t)),n[t]=!0),l[e]?o=a.getLocal("y"+e):(o=a.teeLocal("y"+e,a.i64_load32_u(a.getLocal("y"),4*e)),l[e]=!0),a.i64_mul(i,o)}let s="c0",c="c1";for(let t=0;t<2*o-1;t++){for(let i=Math.max(0,t-o+1);i<=t&&i<o;i++){const o=t-i;e.addCode(a.setLocal(s,a.i64_add(a.i64_and(a.getLocal(s),a.i64_const(4294967295)),r(i,o)))),e.addCode(a.setLocal(c,a.i64_add(a.getLocal(c),a.i64_shr_u(a.getLocal(s),a.i64_const(32)))))}e.addCode(a.i64_store32(a.getLocal("r"),4*t,a.getLocal(s))),[s,c]=[c,s],e.addCode(a.setLocal(c,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+"_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");for(let t=0;t<o;t++)e.addLocal("x"+t,"i64");const a=e.getCodeBuilder(),n=[];function l(t,e){let i,o;return n[t]?i=a.getLocal("x"+t):(i=a.teeLocal("x"+t,a.i64_load32_u(a.getLocal("x"),4*t)),n[t]=!0),n[e]?o=a.getLocal("x"+e):(o=a.teeLocal("x"+e,a.i64_load32_u(a.getLocal("x"),4*e)),n[e]=!0),a.i64_mul(i,o)}let r="c0",s="c1",c="c0_old",d="c1_old";for(let t=0;t<2*o-1;t++){e.addCode(a.setLocal(r,a.i64_const(0)),a.setLocal(s,a.i64_const(0)));for(let i=Math.max(0,t-o+1);i<t+1>>1&&i<o;i++){const o=t-i;e.addCode(a.setLocal(r,a.i64_add(a.i64_and(a.getLocal(r),a.i64_const(4294967295)),l(i,o)))),e.addCode(a.setLocal(s,a.i64_add(a.getLocal(s),a.i64_shr_u(a.getLocal(r),a.i64_const(32)))))}e.addCode(a.setLocal(r,a.i64_shl(a.i64_and(a.getLocal(r),a.i64_const(4294967295)),a.i64_const(1)))),e.addCode(a.setLocal(s,a.i64_add(a.i64_shl(a.getLocal(s),a.i64_const(1)),a.i64_shr_u(a.getLocal(r),a.i64_const(32))))),t%2==0&&(e.addCode(a.setLocal(r,a.i64_add(a.i64_and(a.getLocal(r),a.i64_const(4294967295)),l(t>>1,t>>1)))),e.addCode(a.setLocal(s,a.i64_add(a.getLocal(s),a.i64_shr_u(a.getLocal(r),a.i64_const(32)))))),t>0&&(e.addCode(a.setLocal(r,a.i64_add(a.i64_and(a.getLocal(r),a.i64_const(4294967295)),a.i64_and(a.getLocal(c),a.i64_const(4294967295))))),e.addCode(a.setLocal(s,a.i64_add(a.i64_add(a.getLocal(s),a.i64_shr_u(a.getLocal(r),a.i64_const(32))),a.getLocal(d))))),e.addCode(a.i64_store32(a.getLocal("r"),4*t,a.getLocal(r))),e.addCode(a.setLocal(c,a.getLocal(s)),a.setLocal(d,a.i64_shr_u(a.getLocal(c),a.i64_const(32))))}e.addCode(a.i64_store32(a.getLocal("r"),4*o*2-4,a.getLocal(c)))}(),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<o;t++)e.addCode(a.setLocal("c",a.i64_add(a.i64_mul(a.i64_load32_u(a.getLocal("px"),4*t,0),a.getLocal("y")),a.i64_shr_u(a.getLocal("c"),a.i64_const(32))))),e.addCode(a.i64_store32(a.getLocal("pr"),4*t,0,a.getLocal("c")))}(),function(){const e=t.addFunction(i+"__add1");e.addParam("x","i32"),e.addParam("y","i64"),e.addLocal("c","i64"),e.addLocal("px","i32");const a=e.getCodeBuilder();e.addCode(a.setLocal("px",a.getLocal("x"))),e.addCode(a.setLocal("c",a.i64_add(a.i64_load32_u(a.getLocal("px"),0,0),a.getLocal("y")))),e.addCode(a.i64_store32(a.getLocal("px"),0,0,a.getLocal("c"))),e.addCode(a.setLocal("c",a.i64_shr_u(a.getLocal("c"),a.i64_const(32)))),e.addCode(a.block(a.loop(a.br_if(1,a.i64_eqz(a.getLocal("c"))),a.setLocal("px",a.i32_add(a.getLocal("px"),a.i32_const(4))),a.setLocal("c",a.i64_add(a.i64_load32_u(a.getLocal("px"),0,0),a.getLocal("c"))),a.i64_store32(a.getLocal("px"),0,0,a.getLocal("c")),a.setLocal("c",a.i64_shr_u(a.getLocal("c"),a.i64_const(32))),a.br(0))))}();const e=t.addFunction(i+"_div");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("c","i32"),e.addParam("r","i32"),e.addLocal("rr","i32"),e.addLocal("cc","i32"),e.addLocal("eX","i32"),e.addLocal("eY","i32"),e.addLocal("sy","i64"),e.addLocal("sx","i64"),e.addLocal("ec","i32");const a=e.getCodeBuilder(),l=a.i32_const(t.alloc(n)),r=a.i32_const(t.alloc(n)),s=a.i32_const(t.alloc(n)),c=a.getLocal("cc"),d=a.getLocal("rr"),u=t.alloc(2*n),g=a.i32_const(u),f=a.i32_const(u+n);e.addCode(a.if(a.getLocal("c"),a.setLocal("cc",a.getLocal("c")),a.setLocal("cc",r))),e.addCode(a.if(a.getLocal("r"),a.setLocal("rr",a.getLocal("r")),a.setLocal("rr",s))),e.addCode(a.call(i+"_copy",a.getLocal("x"),d)),e.addCode(a.call(i+"_copy",a.getLocal("y"),l)),e.addCode(a.call(i+"_zero",c)),e.addCode(a.call(i+"_zero",g)),e.addCode(a.setLocal("eX",a.i32_const(n-1))),e.addCode(a.setLocal("eY",a.i32_const(n-1))),e.addCode(a.block(a.loop(a.br_if(1,a.i32_or(a.i32_load8_u(a.i32_add(l,a.getLocal("eY")),0,0),a.i32_eq(a.getLocal("eY"),a.i32_const(3)))),a.setLocal("eY",a.i32_sub(a.getLocal("eY"),a.i32_const(1))),a.br(0)))),e.addCode(a.setLocal("sy",a.i64_add(a.i64_load32_u(a.i32_sub(a.i32_add(l,a.getLocal("eY")),a.i32_const(3)),0,0),a.i64_const(1)))),e.addCode(a.if(a.i64_eq(a.getLocal("sy"),a.i64_const(1)),a.drop(a.i64_div_u(a.i64_const(0),a.i64_const(0))))),e.addCode(a.block(a.loop(a.block(a.loop(a.br_if(1,a.i32_or(a.i32_load8_u(a.i32_add(d,a.getLocal("eX")),0,0),a.i32_eq(a.getLocal("eX"),a.i32_const(7)))),a.setLocal("eX",a.i32_sub(a.getLocal("eX"),a.i32_const(1))),a.br(0))),a.setLocal("sx",a.i64_load(a.i32_sub(a.i32_add(d,a.getLocal("eX")),a.i32_const(7)),0,0)),a.setLocal("sx",a.i64_div_u(a.getLocal("sx"),a.getLocal("sy"))),a.setLocal("ec",a.i32_sub(a.i32_sub(a.getLocal("eX"),a.getLocal("eY")),a.i32_const(4))),a.block(a.loop(a.br_if(1,a.i32_and(a.i64_eqz(a.i64_and(a.getLocal("sx"),a.i64_const("0xFFFFFFFF00000000"))),a.i32_ge_s(a.getLocal("ec"),a.i32_const(0)))),a.setLocal("sx",a.i64_shr_u(a.getLocal("sx"),a.i64_const(8))),a.setLocal("ec",a.i32_add(a.getLocal("ec"),a.i32_const(1))),a.br(0))),a.if(a.i64_eqz(a.getLocal("sx")),[...a.br_if(2,a.i32_eqz(a.call(i+"_gte",d,l))),...a.setLocal("sx",a.i64_const(1)),...a.setLocal("ec",a.i32_const(0))]),a.call(i+"__mul1",l,a.getLocal("sx"),f),a.drop(a.call(i+"_sub",d,a.i32_sub(f,a.getLocal("ec")),d)),a.call(i+"__add1",a.i32_add(c,a.getLocal("ec")),a.getLocal("sx")),a.br(0))))}(),function(){const e=t.addFunction(i+"_inverseMod");e.addParam("px","i32"),e.addParam("pm","i32"),e.addParam("pr","i32"),e.addLocal("t","i32"),e.addLocal("newt","i32"),e.addLocal("r","i32"),e.addLocal("qq","i32"),e.addLocal("qr","i32"),e.addLocal("newr","i32"),e.addLocal("swp","i32"),e.addLocal("x","i32"),e.addLocal("signt","i32"),e.addLocal("signnewt","i32"),e.addLocal("signx","i32");const a=e.getCodeBuilder(),o=a.i32_const(t.alloc(n)),l=a.i32_const(t.alloc(n)),r=a.i32_const(t.alloc(n)),s=a.i32_const(t.alloc(n)),c=a.i32_const(t.alloc(n)),d=a.i32_const(t.alloc(n)),u=a.i32_const(t.alloc(2*n)),g=a.i32_const(t.alloc(n));e.addCode(a.setLocal("t",o),a.call(i+"_zero",o),a.setLocal("signt",a.i32_const(0))),e.addCode(a.setLocal("r",l),a.call(i+"_copy",a.getLocal("pm"),l)),e.addCode(a.setLocal("newt",r),a.call(i+"_one",r),a.setLocal("signnewt",a.i32_const(0))),e.addCode(a.setLocal("newr",s),a.call(i+"_copy",a.getLocal("px"),s)),e.addCode(a.setLocal("qq",c)),e.addCode(a.setLocal("qr",d)),e.addCode(a.setLocal("x",g)),e.addCode(a.block(a.loop(a.br_if(1,a.call(i+"_isZero",a.getLocal("newr"))),a.call(i+"_div",a.getLocal("r"),a.getLocal("newr"),a.getLocal("qq"),a.getLocal("qr")),a.call(i+"_mul",a.getLocal("qq"),a.getLocal("newt"),u),a.if(a.getLocal("signt"),a.if(a.getLocal("signnewt"),a.if(a.call(i+"_gte",u,a.getLocal("t")),[...a.drop(a.call(i+"_sub",u,a.getLocal("t"),a.getLocal("x"))),...a.setLocal("signx",a.i32_const(0))],[...a.drop(a.call(i+"_sub",a.getLocal("t"),u,a.getLocal("x"))),...a.setLocal("signx",a.i32_const(1))]),[...a.drop(a.call(i+"_add",u,a.getLocal("t"),a.getLocal("x"))),...a.setLocal("signx",a.i32_const(1))]),a.if(a.getLocal("signnewt"),[...a.drop(a.call(i+"_add",u,a.getLocal("t"),a.getLocal("x"))),...a.setLocal("signx",a.i32_const(0))],a.if(a.call(i+"_gte",a.getLocal("t"),u),[...a.drop(a.call(i+"_sub",a.getLocal("t"),u,a.getLocal("x"))),...a.setLocal("signx",a.i32_const(0))],[...a.drop(a.call(i+"_sub",u,a.getLocal("t"),a.getLocal("x"))),...a.setLocal("signx",a.i32_const(1))]))),a.setLocal("swp",a.getLocal("t")),a.setLocal("t",a.getLocal("newt")),a.setLocal("newt",a.getLocal("x")),a.setLocal("x",a.getLocal("swp")),a.setLocal("signt",a.getLocal("signnewt")),a.setLocal("signnewt",a.getLocal("signx")),a.setLocal("swp",a.getLocal("r")),a.setLocal("r",a.getLocal("newr")),a.setLocal("newr",a.getLocal("qr")),a.setLocal("qr",a.getLocal("swp")),a.br(0)))),e.addCode(a.if(a.getLocal("signt"),a.drop(a.call(i+"_sub",a.getLocal("pm"),a.getLocal("t"),a.getLocal("pr"))),a.call(i+"_copy",a.getLocal("t"),a.getLocal("pr"))))}(),t.exportFunction(i+"_copy"),t.exportFunction(i+"_zero"),t.exportFunction(i+"_one"),t.exportFunction(i+"_isZero"),t.exportFunction(i+"_eq"),t.exportFunction(i+"_gte"),t.exportFunction(i+"_add"),t.exportFunction(i+"_sub"),t.exportFunction(i+"_mul"),t.exportFunction(i+"_square"),t.exportFunction(i+"_squareOld"),t.exportFunction(i+"_div"),t.exportFunction(i+"_inverseMod"),i},ut=V,gt=K,ft=j,ht=H,_t=Z,{bitLength:pt,modInv:mt,modPow:wt,isPrime:Lt,isOdd:bt,square:yt}=W;var At=function(t,e,a,i){const o=BigInt(e),n=Math.floor((pt(o-1n)-1)/64)+1,l=2*n,r=8*n,s=a||"f1m";if(t.modules[s])return s;const c=dt(t,n,i),d=t.alloc(r,ut.bigInt2BytesLE(o,r)),u=t.alloc(ut.bigInt2BytesLE(yt(1n<<BigInt(64*n))%o,r)),g=t.alloc(ut.bigInt2BytesLE((1n<<BigInt(64*n))%o,r)),f=t.alloc(ut.bigInt2BytesLE(0n,r)),h=o-1n,_=h>>1n,p=t.alloc(r,ut.bigInt2BytesLE(_,r)),m=_+1n,w=t.alloc(r,ut.bigInt2BytesLE(m,r));t.modules[s]={pq:d,pR2:u,n64:n,q:o,pOne:g,pZero:f,pePlusOne:w};let L=2n;if(Lt(o))for(;wt(L,_,o)!==h;)L+=1n;let b=0,y=h;for(;!bt(y)&&0n!==y;)b++,y>>=1n;const A=t.alloc(r,ut.bigInt2BytesLE(y,r)),C=wt(L,y,o),I=t.alloc(ut.bigInt2BytesLE((C<<BigInt(64*n))%o,r)),F=y+1n>>1n,x=t.alloc(r,ut.bigInt2BytesLE(F,r));return t.exportFunction(c+"_copy",s+"_copy"),t.exportFunction(c+"_zero",s+"_zero"),t.exportFunction(c+"_isZero",s+"_isZero"),t.exportFunction(c+"_eq",s+"_eq"),function(){const e=t.addFunction(s+"_isOne");e.addParam("x","i32"),e.setReturnType("i32");const a=e.getCodeBuilder();e.addCode(a.ret(a.call(c+"_eq",a.getLocal("x"),a.i32_const(g))))}(),function(){const e=t.addFunction(s+"_add");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.if(a.call(c+"_add",a.getLocal("x"),a.getLocal("y"),a.getLocal("r")),a.drop(a.call(c+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))),a.if(a.call(c+"_gte",a.getLocal("r"),a.i32_const(d)),a.drop(a.call(c+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))))))}(),function(){const e=t.addFunction(s+"_sub");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.if(a.call(c+"_sub",a.getLocal("x"),a.getLocal("y"),a.getLocal("r")),a.drop(a.call(c+"_add",a.getLocal("r"),a.i32_const(d),a.getLocal("r")))))}(),function(){const e=t.addFunction(s+"_neg");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(s+"_sub",a.i32_const(f),a.getLocal("x"),a.getLocal("r")))}(),function(){const e=t.alloc(l*l*8),a=t.addFunction(s+"_mReduct");a.addParam("t","i32"),a.addParam("r","i32"),a.addLocal("np32","i64"),a.addLocal("c","i64"),a.addLocal("m","i64");const i=a.getCodeBuilder(),n=Number(0x100000000n-mt(o,0x100000000n));a.addCode(i.setLocal("np32",i.i64_const(n)));for(let t=0;t<l;t++){a.addCode(i.setLocal("c",i.i64_const(0))),a.addCode(i.setLocal("m",i.i64_and(i.i64_mul(i.i64_load32_u(i.getLocal("t"),4*t),i.getLocal("np32")),i.i64_const("0xFFFFFFFF"))));for(let e=0;e<l;e++)a.addCode(i.setLocal("c",i.i64_add(i.i64_add(i.i64_load32_u(i.getLocal("t"),4*(t+e)),i.i64_shr_u(i.getLocal("c"),i.i64_const(32))),i.i64_mul(i.i64_load32_u(i.i32_const(d),4*e),i.getLocal("m"))))),a.addCode(i.i64_store32(i.getLocal("t"),4*(t+e),i.getLocal("c")));a.addCode(i.i64_store32(i.i32_const(e),4*t,i.i64_shr_u(i.getLocal("c"),i.i64_const(32))))}a.addCode(i.call(s+"_add",i.i32_const(e),i.i32_add(i.getLocal("t"),i.i32_const(4*l)),i.getLocal("r")))}(),function(){const e=t.addFunction(s+"_mul");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32"),e.addLocal("c0","i64"),e.addLocal("c1","i64"),e.addLocal("np32","i64");for(let t=0;t<l;t++)e.addLocal("x"+t,"i64"),e.addLocal("y"+t,"i64"),e.addLocal("m"+t,"i64"),e.addLocal("q"+t,"i64");const a=e.getCodeBuilder(),i=Number(0x100000000n-mt(o,0x100000000n));e.addCode(a.setLocal("np32",a.i64_const(i)));const n=[],r=[],u=[];function g(t,e){let i,o;return n[t]?i=a.getLocal("x"+t):(i=a.teeLocal("x"+t,a.i64_load32_u(a.getLocal("x"),4*t)),n[t]=!0),r[e]?o=a.getLocal("y"+e):(o=a.teeLocal("y"+e,a.i64_load32_u(a.getLocal("y"),4*e)),r[e]=!0),a.i64_mul(i,o)}function f(t,e){let i,o;return u[t]?i=a.getLocal("q"+t):(i=a.teeLocal("q"+t,a.i64_load32_u(a.i32_const(0),d+4*t)),u[t]=!0),o=a.getLocal("m"+e),a.i64_mul(i,o)}let h="c0",_="c1";for(let t=0;t<2*l-1;t++){for(let i=Math.max(0,t-l+1);i<=t&&i<l;i++){const o=t-i;e.addCode(a.setLocal(h,a.i64_add(a.i64_and(a.getLocal(h),a.i64_const(4294967295)),g(i,o)))),e.addCode(a.setLocal(_,a.i64_add(a.getLocal(_),a.i64_shr_u(a.getLocal(h),a.i64_const(32)))))}for(let i=Math.max(1,t-l+1);i<=t&&i<l;i++){const o=t-i;e.addCode(a.setLocal(h,a.i64_add(a.i64_and(a.getLocal(h),a.i64_const(4294967295)),f(i,o)))),e.addCode(a.setLocal(_,a.i64_add(a.getLocal(_),a.i64_shr_u(a.getLocal(h),a.i64_const(32)))))}t<l&&(e.addCode(a.setLocal("m"+t,a.i64_and(a.i64_mul(a.i64_and(a.getLocal(h),a.i64_const(4294967295)),a.getLocal("np32")),a.i64_const("0xFFFFFFFF")))),e.addCode(a.setLocal(h,a.i64_add(a.i64_and(a.getLocal(h),a.i64_const(4294967295)),f(0,t)))),e.addCode(a.setLocal(_,a.i64_add(a.getLocal(_),a.i64_shr_u(a.getLocal(h),a.i64_const(32)))))),t>=l&&e.addCode(a.i64_store32(a.getLocal("r"),4*(t-l),a.getLocal(h))),[h,_]=[_,h],e.addCode(a.setLocal(_,a.i64_shr_u(a.getLocal(h),a.i64_const(32))))}e.addCode(a.i64_store32(a.getLocal("r"),4*l-4,a.getLocal(h))),e.addCode(a.if(a.i32_wrap_i64(a.getLocal(_)),a.drop(a.call(c+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))),a.if(a.call(c+"_gte",a.getLocal("r"),a.i32_const(d)),a.drop(a.call(c+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))))))}(),function(){const e=t.addFunction(s+"_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<l;t++)e.addLocal("x"+t,"i64"),e.addLocal("m"+t,"i64"),e.addLocal("q"+t,"i64");const a=e.getCodeBuilder(),i=Number(0x100000000n-mt(o,0x100000000n));e.addCode(a.setLocal("np32",a.i64_const(i)));const n=[],r=[];function u(t,e){let i,o;return n[t]?i=a.getLocal("x"+t):(i=a.teeLocal("x"+t,a.i64_load32_u(a.getLocal("x"),4*t)),n[t]=!0),n[e]?o=a.getLocal("x"+e):(o=a.teeLocal("x"+e,a.i64_load32_u(a.getLocal("x"),4*e)),n[e]=!0),a.i64_mul(i,o)}function g(t,e){let i,o;return r[t]?i=a.getLocal("q"+t):(i=a.teeLocal("q"+t,a.i64_load32_u(a.i32_const(0),d+4*t)),r[t]=!0),o=a.getLocal("m"+e),a.i64_mul(i,o)}let f="c0",h="c1",_="c0_old",p="c1_old";for(let t=0;t<2*l-1;t++){e.addCode(a.setLocal(f,a.i64_const(0)),a.setLocal(h,a.i64_const(0)));for(let i=Math.max(0,t-l+1);i<t+1>>1&&i<l;i++){const o=t-i;e.addCode(a.setLocal(f,a.i64_add(a.i64_and(a.getLocal(f),a.i64_const(4294967295)),u(i,o)))),e.addCode(a.setLocal(h,a.i64_add(a.getLocal(h),a.i64_shr_u(a.getLocal(f),a.i64_const(32)))))}e.addCode(a.setLocal(f,a.i64_shl(a.i64_and(a.getLocal(f),a.i64_const(4294967295)),a.i64_const(1)))),e.addCode(a.setLocal(h,a.i64_add(a.i64_shl(a.getLocal(h),a.i64_const(1)),a.i64_shr_u(a.getLocal(f),a.i64_const(32))))),t%2==0&&(e.addCode(a.setLocal(f,a.i64_add(a.i64_and(a.getLocal(f),a.i64_const(4294967295)),u(t>>1,t>>1)))),e.addCode(a.setLocal(h,a.i64_add(a.getLocal(h),a.i64_shr_u(a.getLocal(f),a.i64_const(32)))))),t>0&&(e.addCode(a.setLocal(f,a.i64_add(a.i64_and(a.getLocal(f),a.i64_const(4294967295)),a.i64_and(a.getLocal(_),a.i64_const(4294967295))))),e.addCode(a.setLocal(h,a.i64_add(a.i64_add(a.getLocal(h),a.i64_shr_u(a.getLocal(f),a.i64_const(32))),a.getLocal(p)))));for(let i=Math.max(1,t-l+1);i<=t&&i<l;i++){const o=t-i;e.addCode(a.setLocal(f,a.i64_add(a.i64_and(a.getLocal(f),a.i64_const(4294967295)),g(i,o)))),e.addCode(a.setLocal(h,a.i64_add(a.getLocal(h),a.i64_shr_u(a.getLocal(f),a.i64_const(32)))))}t<l&&(e.addCode(a.setLocal("m"+t,a.i64_and(a.i64_mul(a.i64_and(a.getLocal(f),a.i64_const(4294967295)),a.getLocal("np32")),a.i64_const("0xFFFFFFFF")))),e.addCode(a.setLocal(f,a.i64_add(a.i64_and(a.getLocal(f),a.i64_const(4294967295)),g(0,t)))),e.addCode(a.setLocal(h,a.i64_add(a.getLocal(h),a.i64_shr_u(a.getLocal(f),a.i64_const(32)))))),t>=l&&e.addCode(a.i64_store32(a.getLocal("r"),4*(t-l),a.getLocal(f))),e.addCode(a.setLocal(_,a.getLocal(h)),a.setLocal(p,a.i64_shr_u(a.getLocal(_),a.i64_const(32))))}e.addCode(a.i64_store32(a.getLocal("r"),4*l-4,a.getLocal(_))),e.addCode(a.if(a.i32_wrap_i64(a.getLocal(p)),a.drop(a.call(c+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))),a.if(a.call(c+"_gte",a.getLocal("r"),a.i32_const(d)),a.drop(a.call(c+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))))))}(),function(){const e=t.addFunction(s+"_squareOld");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(s+"_mul",a.getLocal("x"),a.getLocal("x"),a.getLocal("r")))}(),function(){const e=t.addFunction(s+"_toMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(s+"_mul",a.getLocal("x"),a.i32_const(u),a.getLocal("r")))}(),function(){const e=t.alloc(2*r),a=t.addFunction(s+"_fromMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const i=a.getCodeBuilder();a.addCode(i.call(c+"_copy",i.getLocal("x"),i.i32_const(e))),a.addCode(i.call(c+"_zero",i.i32_const(e+r))),a.addCode(i.call(s+"_mReduct",i.i32_const(e),i.getLocal("r")))}(),function(){const e=t.addFunction(s+"_isNegative");e.addParam("x","i32"),e.setReturnType("i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(r));e.addCode(a.call(s+"_fromMontgomery",a.getLocal("x"),i),a.call(c+"_gte",i,a.i32_const(w)))}(),function(){const e=t.addFunction(s+"_sign");e.addParam("x","i32"),e.setReturnType("i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(r));e.addCode(a.if(a.call(c+"_isZero",a.getLocal("x")),a.ret(a.i32_const(0))),a.call(s+"_fromMontgomery",a.getLocal("x"),i),a.if(a.call(c+"_gte",i,a.i32_const(w)),a.ret(a.i32_const(-1))),a.ret(a.i32_const(1)))}(),function(){const e=t.addFunction(s+"_inverse");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(s+"_fromMontgomery",a.getLocal("x"),a.getLocal("r"))),e.addCode(a.call(c+"_inverseMod",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))),e.addCode(a.call(s+"_toMontgomery",a.getLocal("r"),a.getLocal("r")))}(),function(){const e=t.addFunction(s+"_one");e.addParam("pr","i32");const a=e.getCodeBuilder();e.addCode(a.call(c+"_copy",a.i32_const(g),a.getLocal("pr")))}(),function(){const e=t.addFunction(s+"_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(r)),o=t.alloc(r),n=a.i32_const(o);e.addCode(a.call(c+"_zero",a.getLocal("r")),a.setLocal("i",a.i32_const(r)),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(r)),a.call(s+"_one",i),a.call(s+"_mul",i,a.i32_const(u),i)),a.call(s+"_mul",a.getLocal("p"),i,n),a.call(s+"_add",a.getLocal("r"),n,a.getLocal("r")),a.setLocal("p",a.i32_add(a.getLocal("p"),a.i32_const(r))),a.setLocal("i",a.i32_add(a.getLocal("i"),a.i32_const(r))),a.br(0))),a.setLocal("l",a.i32_rem_u(a.getLocal("scalarLen"),a.i32_const(r))),a.if(a.i32_eqz(a.getLocal("l")),a.ret([])),a.call(c+"_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(r)),a.call(s+"_one",i),a.call(s+"_mul",i,a.i32_const(u),i)),a.call(s+"_mul",n,i,n),a.call(s+"_add",a.getLocal("r"),n,a.getLocal("r")))}(),function(){const e=t.addFunction(s+"_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(r));e.addCode(a.call(s+"_load",a.getLocal("scalar"),a.getLocal("scalarLen"),i),a.call(s+"_toMontgomery",i,i),a.call(s+"_mul",a.getLocal("x"),i,a.getLocal("r")))}(),ft(t,s),ht(t,s+"_batchToMontgomery",s+"_toMontgomery",r,r),ht(t,s+"_batchFromMontgomery",s+"_fromMontgomery",r,r),ht(t,s+"_batchNeg",s+"_neg",r,r),_t(t,s+"_batchAdd",s+"_add",r,r),_t(t,s+"_batchSub",s+"_sub",r,r),_t(t,s+"_batchMul",s+"_mul",r,r),t.exportFunction(s+"_add"),t.exportFunction(s+"_sub"),t.exportFunction(s+"_neg"),t.exportFunction(s+"_isNegative"),t.exportFunction(s+"_isOne"),t.exportFunction(s+"_sign"),t.exportFunction(s+"_mReduct"),t.exportFunction(s+"_mul"),t.exportFunction(s+"_square"),t.exportFunction(s+"_squareOld"),t.exportFunction(s+"_fromMontgomery"),t.exportFunction(s+"_toMontgomery"),t.exportFunction(s+"_inverse"),t.exportFunction(s+"_one"),t.exportFunction(s+"_load"),t.exportFunction(s+"_timesScalar"),gt(t,s+"_exp",r,s+"_mul",s+"_square",c+"_copy",s+"_one"),t.exportFunction(s+"_exp"),t.exportFunction(s+"_batchInverse"),Lt(o)&&(!function(){const e=t.addFunction(s+"_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(g),o=a.i32_const(t.alloc(r)),n=a.i32_const(t.alloc(r)),l=a.i32_const(t.alloc(r)),c=a.i32_const(t.alloc(r)),d=a.i32_const(t.alloc(r));e.addCode(a.if(a.call(s+"_isZero",a.getLocal("n")),a.ret(a.call(s+"_zero",a.getLocal("r")))),a.setLocal("m",a.i32_const(b)),a.call(s+"_copy",a.i32_const(I),o),a.call(s+"_exp",a.getLocal("n"),a.i32_const(A),a.i32_const(r),n),a.call(s+"_exp",a.getLocal("n"),a.i32_const(x),a.i32_const(r),l),a.block(a.loop(a.br_if(1,a.call(s+"_eq",n,i)),a.call(s+"_square",n,c),a.setLocal("i",a.i32_const(1)),a.block(a.loop(a.br_if(1,a.call(s+"_eq",c,i)),a.call(s+"_square",c,c),a.setLocal("i",a.i32_add(a.getLocal("i"),a.i32_const(1))),a.br(0))),a.call(s+"_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(s+"_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(s+"_square",d,o),a.call(s+"_mul",n,o,n),a.call(s+"_mul",l,d,l),a.br(0))),a.if(a.call(s+"_isNegative",l),a.call(s+"_neg",l,a.getLocal("r")),a.call(s+"_copy",l,a.getLocal("r"))))}(),function(){const e=t.addFunction(s+"_isSquare");e.addParam("n","i32"),e.setReturnType("i32");const a=e.getCodeBuilder(),i=a.i32_const(g),o=a.i32_const(t.alloc(r));e.addCode(a.if(a.call(s+"_isZero",a.getLocal("n")),a.ret(a.i32_const(1))),a.call(s+"_exp",a.getLocal("n"),a.i32_const(p),a.i32_const(r),o),a.call(s+"_eq",o,i))}(),t.exportFunction(s+"_sqrt"),t.exportFunction(s+"_isSquare")),t.exportFunction(s+"_batchToMontgomery"),t.exportFunction(s+"_batchFromMontgomery"),s};const Ct=At,{bitLength:It}=W;var Ft=function(t,e,a,i,o){const n=BigInt(e),l=Math.floor((It(n-1n)-1)/64)+1,r=8*l,s=a||"f1";if(t.modules[s])return s;t.modules[s]={n64:l};const c=o||"int",d=Ct(t,n,i,c),u=t.modules[d].pR2,g=t.modules[d].pq,f=t.modules[d].pePlusOne;return function(){const e=t.alloc(r),a=t.addFunction(s+"_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(u),i.getLocal("r")))}(),function(){const e=t.addFunction(s+"_square");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(s+"_mul",a.getLocal("x"),a.getLocal("x"),a.getLocal("r")))}(),function(){const e=t.addFunction(s+"_inverse");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(c+"_inverseMod",a.getLocal("x"),a.i32_const(g),a.getLocal("r")))}(),function(){const e=t.addFunction(s+"_isNegative");e.addParam("x","i32"),e.setReturnType("i32");const a=e.getCodeBuilder();e.addCode(a.call(c+"_gte",a.getLocal("x"),a.i32_const(f)))}(),t.exportFunction(d+"_add",s+"_add"),t.exportFunction(d+"_sub",s+"_sub"),t.exportFunction(d+"_neg",s+"_neg"),t.exportFunction(s+"_mul"),t.exportFunction(s+"_square"),t.exportFunction(s+"_inverse"),t.exportFunction(s+"_isNegative"),t.exportFunction(d+"_copy",s+"_copy"),t.exportFunction(d+"_zero",s+"_zero"),t.exportFunction(d+"_one",s+"_one"),t.exportFunction(d+"_isZero",s+"_isZero"),t.exportFunction(d+"_eq",s+"_eq"),s};const xt=K,Et=j,vt=V;var Bt=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(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.i32_and(n.call(i+"_isZero",l),n.call(i+"_isZero",r)))}(),function(){const e=t.addFunction(a+"_isOne");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.ret(n.i32_and(n.call(i+"_isOne",l),n.call(i+"_isZero",r))))}(),function(){const e=t.addFunction(a+"_zero");e.addParam("x","i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.call(i+"_zero",l),n.call(i+"_zero",r))}(),function(){const e=t.addFunction(a+"_one");e.addParam("x","i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.call(i+"_one",l),n.call(i+"_zero",r))}(),function(){const e=t.addFunction(a+"_copy");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.getLocal("r"),c=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_copy",l,s),n.call(i+"_copy",r,c))}(),function(){const n=t.addFunction(a+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),r=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(o)),c=l.getLocal("y"),d=l.i32_add(l.getLocal("y"),l.i32_const(o)),u=l.getLocal("r"),g=l.i32_add(l.getLocal("r"),l.i32_const(o)),f=l.i32_const(t.alloc(o)),h=l.i32_const(t.alloc(o)),_=l.i32_const(t.alloc(o)),p=l.i32_const(t.alloc(o));n.addCode(l.call(i+"_mul",r,c,f),l.call(i+"_mul",s,d,h),l.call(i+"_add",r,s,_),l.call(i+"_add",c,d,p),l.call(i+"_mul",_,p,_),l.call(e,h,u),l.call(i+"_add",f,u,u),l.call(i+"_add",f,h,g),l.call(i+"_sub",_,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(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.getLocal("y"),c=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_mul",l,s,c),n.call(i+"_mul",r,s,d))}(),function(){const n=t.addFunction(a+"_square");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),r=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(o)),c=l.getLocal("r"),d=l.i32_add(l.getLocal("r"),l.i32_const(o)),u=l.i32_const(t.alloc(o)),g=l.i32_const(t.alloc(o)),f=l.i32_const(t.alloc(o)),h=l.i32_const(t.alloc(o));n.addCode(l.call(i+"_mul",r,s,u),l.call(i+"_add",r,s,g),l.call(e,s,f),l.call(i+"_add",r,f,f),l.call(e,u,h),l.call(i+"_add",h,u,h),l.call(i+"_mul",g,f,c),l.call(i+"_sub",c,h,c),l.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(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.getLocal("y"),c=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",l,s,d),n.call(i+"_add",r,c,u))}(),function(){const e=t.addFunction(a+"_sub");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.getLocal("y"),c=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",l,s,d),n.call(i+"_sub",r,c,u))}(),function(){const e=t.addFunction(a+"_neg");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.getLocal("r"),c=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_neg",l,s),n.call(i+"_neg",r,c))}(),function(){const e=t.addFunction(a+"_conjugate");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.getLocal("r"),c=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_copy",l,s),n.call(i+"_neg",r,c))}(),function(){const e=t.addFunction(a+"_toMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.getLocal("r"),c=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_toMontgomery",l,s),n.call(i+"_toMontgomery",r,c))}(),function(){const e=t.addFunction(a+"_fromMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.getLocal("r"),c=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_fromMontgomery",l,s),n.call(i+"_fromMontgomery",r,c))}(),function(){const e=t.addFunction(a+"_eq");e.addParam("x","i32"),e.addParam("y","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.getLocal("y"),c=n.i32_add(n.getLocal("y"),n.i32_const(o));e.addCode(n.i32_and(n.call(i+"_eq",l,s),n.call(i+"_eq",r,c)))}(),function(){const n=t.addFunction(a+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),r=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(o)),c=l.getLocal("r"),d=l.i32_add(l.getLocal("r"),l.i32_const(o)),u=l.i32_const(t.alloc(o)),g=l.i32_const(t.alloc(o)),f=l.i32_const(t.alloc(o)),h=l.i32_const(t.alloc(o));n.addCode(l.call(i+"_square",r,u),l.call(i+"_square",s,g),l.call(e,g,f),l.call(i+"_sub",u,f,f),l.call(i+"_inverse",f,h),l.call(i+"_mul",r,h,c),l.call(i+"_mul",s,h,d),l.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(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.getLocal("r"),c=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_timesScalar",l,n.getLocal("scalar"),n.getLocal("scalarLen"),s),n.call(i+"_timesScalar",r,n.getLocal("scalar"),n.getLocal("scalarLen"),c))}(),function(){const e=t.addFunction(a+"_sign");e.addParam("x","i32"),e.addLocal("s","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.setLocal("s",n.call(i+"_sign",r)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(i+"_sign",l)))}(),function(){const e=t.addFunction(a+"_isNegative");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.if(n.call(i+"_isZero",r),n.ret(n.call(i+"_isNegative",l))),n.ret(n.call(i+"_isNegative",r)))}(),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"),Et(t,a),xt(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 l=e.getCodeBuilder(),r=l.i32_const(t.alloc(vt.bigInt2BytesLE((BigInt(n||0)-3n)/4n,o))),s=l.i32_const(t.alloc(vt.bigInt2BytesLE((BigInt(n||0)-1n)/2n,o))),c=l.getLocal("a"),d=l.i32_const(t.alloc(2*o)),u=l.i32_const(t.alloc(2*o)),g=l.i32_const(t.alloc(2*o)),f=t.alloc(2*o),h=l.i32_const(f),_=l.i32_const(f),p=l.i32_const(f+o),m=l.i32_const(t.alloc(2*o)),w=l.i32_const(t.alloc(2*o));e.addCode(l.call(a+"_one",h),l.call(a+"_neg",h,h),l.call(a+"_exp",c,r,l.i32_const(o),d),l.call(a+"_square",d,u),l.call(a+"_mul",c,u,u),l.call(a+"_conjugate",u,g),l.call(a+"_mul",g,u,g),l.if(l.call(a+"_eq",g,h),l.unreachable()),l.call(a+"_mul",d,c,m),l.if(l.call(a+"_eq",u,h),[...l.call(i+"_zero",_),...l.call(i+"_one",p),...l.call(a+"_mul",h,m,l.getLocal("pr"))],[...l.call(a+"_one",w),...l.call(a+"_add",w,u,w),...l.call(a+"_exp",w,s,l.i32_const(o),w),...l.call(a+"_mul",w,m,l.getLocal("pr"))]))}(),function(){const e=t.addFunction(a+"_isSquare");e.addParam("a","i32"),e.setReturnType("i32");const i=e.getCodeBuilder(),l=i.i32_const(t.alloc(vt.bigInt2BytesLE((BigInt(n||0)-3n)/4n,o))),r=i.getLocal("a"),s=i.i32_const(t.alloc(2*o)),c=i.i32_const(t.alloc(2*o)),d=i.i32_const(t.alloc(2*o)),u=t.alloc(2*o),g=i.i32_const(u);e.addCode(i.call(a+"_one",g),i.call(a+"_neg",g,g),i.call(a+"_exp",r,l,i.i32_const(o),s),i.call(a+"_square",s,c),i.call(a+"_mul",r,c,c),i.call(a+"_conjugate",c,d),i.call(a+"_mul",d,c,d),i.if(i.call(a+"_eq",d,g),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};const St=K,Pt=j;var Gt=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(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.i32_and(n.i32_and(n.call(i+"_isZero",l),n.call(i+"_isZero",r)),n.call(i+"_isZero",s)))}(),function(){const e=t.addFunction(a+"_isOne");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=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",l),n.call(i+"_isZero",r)),n.call(i+"_isZero",s))))}(),function(){const e=t.addFunction(a+"_zero");e.addParam("x","i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.call(i+"_zero",l),n.call(i+"_zero",r),n.call(i+"_zero",s))}(),function(){const e=t.addFunction(a+"_one");e.addParam("x","i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.call(i+"_one",l),n.call(i+"_zero",r),n.call(i+"_zero",s))}(),function(){const e=t.addFunction(a+"_copy");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),c=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",l,c),n.call(i+"_copy",r,d),n.call(i+"_copy",s,u))}(),function(){const n=t.addFunction(a+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),r=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(o)),c=l.i32_add(l.getLocal("x"),l.i32_const(2*o)),d=l.getLocal("y"),u=l.i32_add(l.getLocal("y"),l.i32_const(o)),g=l.i32_add(l.getLocal("y"),l.i32_const(2*o)),f=l.getLocal("r"),h=l.i32_add(l.getLocal("r"),l.i32_const(o)),_=l.i32_add(l.getLocal("r"),l.i32_const(2*o)),p=l.i32_const(t.alloc(o)),m=l.i32_const(t.alloc(o)),w=l.i32_const(t.alloc(o)),L=l.i32_const(t.alloc(o)),b=l.i32_const(t.alloc(o)),y=l.i32_const(t.alloc(o)),A=l.i32_const(t.alloc(o)),C=l.i32_const(t.alloc(o)),I=l.i32_const(t.alloc(o)),F=l.i32_const(t.alloc(o)),x=l.i32_const(t.alloc(o)),E=l.i32_const(t.alloc(o)),v=l.i32_const(t.alloc(o));n.addCode(l.call(i+"_mul",r,d,p),l.call(i+"_mul",s,u,m),l.call(i+"_mul",c,g,w),l.call(i+"_add",r,s,L),l.call(i+"_add",d,u,b),l.call(i+"_add",r,c,y),l.call(i+"_add",d,g,A),l.call(i+"_add",s,c,C),l.call(i+"_add",u,g,I),l.call(i+"_add",p,m,F),l.call(i+"_add",p,w,x),l.call(i+"_add",m,w,E),l.call(i+"_mul",C,I,f),l.call(i+"_sub",f,E,f),l.call(e,f,f),l.call(i+"_add",p,f,f),l.call(i+"_mul",L,b,h),l.call(i+"_sub",h,F,h),l.call(e,w,v),l.call(i+"_add",h,v,h),l.call(i+"_mul",y,A,_),l.call(i+"_sub",_,x,_),l.call(i+"_add",_,m,_))}(),function(){const n=t.addFunction(a+"_square");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),r=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(o)),c=l.i32_add(l.getLocal("x"),l.i32_const(2*o)),d=l.getLocal("r"),u=l.i32_add(l.getLocal("r"),l.i32_const(o)),g=l.i32_add(l.getLocal("r"),l.i32_const(2*o)),f=l.i32_const(t.alloc(o)),h=l.i32_const(t.alloc(o)),_=l.i32_const(t.alloc(o)),p=l.i32_const(t.alloc(o)),m=l.i32_const(t.alloc(o)),w=l.i32_const(t.alloc(o)),L=l.i32_const(t.alloc(o));n.addCode(l.call(i+"_square",r,f),l.call(i+"_mul",r,s,h),l.call(i+"_add",h,h,_),l.call(i+"_sub",r,s,p),l.call(i+"_add",p,c,p),l.call(i+"_square",p,p),l.call(i+"_mul",s,c,m),l.call(i+"_add",m,m,w),l.call(i+"_square",c,L),l.call(e,w,d),l.call(i+"_add",f,d,d),l.call(e,L,u),l.call(i+"_add",_,u,u),l.call(i+"_add",f,L,g),l.call(i+"_sub",w,g,g),l.call(i+"_add",p,g,g),l.call(i+"_add",_,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(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),c=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)),h=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_add",l,c,g),n.call(i+"_add",r,d,f),n.call(i+"_add",s,u,h))}(),function(){const e=t.addFunction(a+"_sub");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),c=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)),h=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_sub",l,c,g),n.call(i+"_sub",r,d,f),n.call(i+"_sub",s,u,h))}(),function(){const e=t.addFunction(a+"_neg");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),c=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",l,c),n.call(i+"_neg",r,d),n.call(i+"_neg",s,u))}(),function(){const e=t.addFunction(a+"_sign");e.addParam("x","i32"),e.addLocal("s","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.setLocal("s",n.call(i+"_sign",s)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.setLocal("s",n.call(i+"_sign",r)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(i+"_sign",l)))}(),function(){const e=t.addFunction(a+"_toMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),c=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",l,c),n.call(i+"_toMontgomery",r,d),n.call(i+"_toMontgomery",s,u))}(),function(){const e=t.addFunction(a+"_fromMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),c=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",l,c),n.call(i+"_fromMontgomery",r,d),n.call(i+"_fromMontgomery",s,u))}(),function(){const e=t.addFunction(a+"_eq");e.addParam("x","i32"),e.addParam("y","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),c=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",l,c),n.call(i+"_eq",r,d)),n.call(i+"_eq",s,u)))}(),function(){const n=t.addFunction(a+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),r=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(o)),c=l.i32_add(l.getLocal("x"),l.i32_const(2*o)),d=l.getLocal("r"),u=l.i32_add(l.getLocal("r"),l.i32_const(o)),g=l.i32_add(l.getLocal("r"),l.i32_const(2*o)),f=l.i32_const(t.alloc(o)),h=l.i32_const(t.alloc(o)),_=l.i32_const(t.alloc(o)),p=l.i32_const(t.alloc(o)),m=l.i32_const(t.alloc(o)),w=l.i32_const(t.alloc(o)),L=l.i32_const(t.alloc(o)),b=l.i32_const(t.alloc(o)),y=l.i32_const(t.alloc(o)),A=l.i32_const(t.alloc(o)),C=l.i32_const(t.alloc(o));n.addCode(l.call(i+"_square",r,f),l.call(i+"_square",s,h),l.call(i+"_square",c,_),l.call(i+"_mul",r,s,p),l.call(i+"_mul",r,c,m),l.call(i+"_mul",s,c,w),l.call(e,w,L),l.call(i+"_sub",f,L,L),l.call(e,_,b),l.call(i+"_sub",b,p,b),l.call(i+"_sub",h,m,y),l.call(i+"_mul",c,b,A),l.call(i+"_mul",s,y,C),l.call(i+"_add",A,C,A),l.call(e,A,A),l.call(i+"_mul",r,L,C),l.call(i+"_add",C,A,A),l.call(i+"_inverse",A,A),l.call(i+"_mul",A,L,d),l.call(i+"_mul",A,b,u),l.call(i+"_mul",A,y,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(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),c=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",l,n.getLocal("scalar"),n.getLocal("scalarLen"),c),n.call(i+"_timesScalar",r,n.getLocal("scalar"),n.getLocal("scalarLen"),d),n.call(i+"_timesScalar",s,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(),l=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.if(n.call(i+"_isZero",s),n.if(n.call(i+"_isZero",r),n.ret(n.call(i+"_isNegative",l)),n.ret(n.call(i+"_isNegative",r)))),n.ret(n.call(i+"_isNegative",s)))}(),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"),Pt(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};const Ot=function(t,e,a,i,o,n,l,r){const s=t.addFunction(e);s.addParam("base","i32"),s.addParam("scalar","i32"),s.addParam("scalarLength","i32"),s.addParam("r","i32"),s.addLocal("old0","i32"),s.addLocal("nbits","i32"),s.addLocal("i","i32"),s.addLocal("last","i32"),s.addLocal("cur","i32"),s.addLocal("carry","i32"),s.addLocal("p","i32");const c=s.getCodeBuilder(),d=c.i32_const(t.alloc(a));function u(t){return c.i32_and(c.i32_shr_u(c.i32_load(c.i32_add(c.getLocal("scalar"),c.i32_and(c.i32_shr_u(t,c.i32_const(3)),c.i32_const(4294967292)))),c.i32_and(t,c.i32_const(31))),c.i32_const(1))}function g(t){return[...c.i32_store8(c.getLocal("p"),c.i32_const(t)),...c.setLocal("p",c.i32_add(c.getLocal("p"),c.i32_const(1)))]}s.addCode(c.if(c.i32_eqz(c.getLocal("scalarLength")),[...c.call(r,c.getLocal("r")),...c.ret([])]),c.setLocal("nbits",c.i32_shl(c.getLocal("scalarLength"),c.i32_const(3))),c.setLocal("old0",c.i32_load(c.i32_const(0))),c.setLocal("p",c.getLocal("old0")),c.i32_store(c.i32_const(0),c.i32_and(c.i32_add(c.i32_add(c.getLocal("old0"),c.i32_const(32)),c.getLocal("nbits")),c.i32_const(4294967288))),c.setLocal("i",c.i32_const(1)),c.setLocal("last",u(c.i32_const(0))),c.setLocal("carry",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("i"),c.getLocal("nbits"))),c.setLocal("cur",u(c.getLocal("i"))),c.if(c.getLocal("last"),c.if(c.getLocal("cur"),c.if(c.getLocal("carry"),[...c.setLocal("last",c.i32_const(0)),...c.setLocal("carry",c.i32_const(1)),...g(1)],[...c.setLocal("last",c.i32_const(0)),...c.setLocal("carry",c.i32_const(1)),...g(255)]),c.if(c.getLocal("carry"),[...c.setLocal("last",c.i32_const(0)),...c.setLocal("carry",c.i32_const(1)),...g(255)],[...c.setLocal("last",c.i32_const(0)),...c.setLocal("carry",c.i32_const(0)),...g(1)])),c.if(c.getLocal("cur"),c.if(c.getLocal("carry"),[...c.setLocal("last",c.i32_const(0)),...c.setLocal("carry",c.i32_const(1)),...g(0)],[...c.setLocal("last",c.i32_const(1)),...c.setLocal("carry",c.i32_const(0)),...g(0)]),c.if(c.getLocal("carry"),[...c.setLocal("last",c.i32_const(1)),...c.setLocal("carry",c.i32_const(0)),...g(0)],[...c.setLocal("last",c.i32_const(0)),...c.setLocal("carry",c.i32_const(0)),...g(0)]))),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0))),c.if(c.getLocal("last"),c.if(c.getLocal("carry"),[...g(255),...g(0),...g(1)],[...g(1)]),c.if(c.getLocal("carry"),[...g(0),...g(1)])),c.setLocal("p",c.i32_sub(c.getLocal("p"),c.i32_const(1))),c.call(l,c.getLocal("base"),d),c.call(r,c.getLocal("r")),c.block(c.loop(c.call(o,c.getLocal("r"),c.getLocal("r")),c.setLocal("cur",c.i32_load8_u(c.getLocal("p"))),c.if(c.getLocal("cur"),c.if(c.i32_eq(c.getLocal("cur"),c.i32_const(1)),c.call(i,c.getLocal("r"),d,c.getLocal("r")),c.call(n,c.getLocal("r"),d,c.getLocal("r")))),c.br_if(1,c.i32_eq(c.getLocal("old0"),c.getLocal("p"))),c.setLocal("p",c.i32_sub(c.getLocal("p"),c.i32_const(1))),c.br(0))),c.i32_store(c.i32_const(0),c.getLocal("old0")))},Tt=H,Ut=function(t,e,a,i,o){const n=8*t.modules[e].n64;function l(){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(),l=o.i32_const(t.alloc(n)),r=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")),r)),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"),l),o.call(e+"_add",o.getLocal("pr"),l,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 l=t.addFunction(a+"_chunk");l.addParam("pBases","i32"),l.addParam("pScalars","i32"),l.addParam("scalarSize","i32"),l.addParam("n","i32"),l.addParam("startBit","i32"),l.addParam("chunkSize","i32"),l.addParam("pr","i32"),l.addLocal("nChunks","i32"),l.addLocal("itScalar","i32"),l.addLocal("endScalar","i32"),l.addLocal("itBase","i32"),l.addLocal("i","i32"),l.addLocal("j","i32"),l.addLocal("nTable","i32"),l.addLocal("pTable","i32"),l.addLocal("idx","i32"),l.addLocal("pIdxTable","i32");const r=l.getCodeBuilder();l.addCode(r.if(r.i32_eqz(r.getLocal("n")),[...r.call(e+"_zero",r.getLocal("pr")),...r.ret([])]),r.setLocal("nTable",r.i32_shl(r.i32_const(1),r.getLocal("chunkSize"))),r.setLocal("pTable",r.i32_load(r.i32_const(0))),r.i32_store(r.i32_const(0),r.i32_add(r.getLocal("pTable"),r.i32_mul(r.getLocal("nTable"),r.i32_const(n)))),r.setLocal("j",r.i32_const(0)),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("j"),r.getLocal("nTable"))),r.call(e+"_zero",r.i32_add(r.getLocal("pTable"),r.i32_mul(r.getLocal("j"),r.i32_const(n)))),r.setLocal("j",r.i32_add(r.getLocal("j"),r.i32_const(1))),r.br(0))),r.setLocal("itBase",r.getLocal("pBases")),r.setLocal("itScalar",r.getLocal("pScalars")),r.setLocal("endScalar",r.i32_add(r.getLocal("pScalars"),r.i32_mul(r.getLocal("n"),r.getLocal("scalarSize")))),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("itScalar"),r.getLocal("endScalar"))),r.setLocal("idx",r.call(a+"_getChunk",r.getLocal("itScalar"),r.getLocal("scalarSize"),r.getLocal("startBit"),r.getLocal("chunkSize"))),r.if(r.getLocal("idx"),[...r.setLocal("pIdxTable",r.i32_add(r.getLocal("pTable"),r.i32_mul(r.i32_sub(r.getLocal("idx"),r.i32_const(1)),r.i32_const(n)))),...r.call(i,r.getLocal("pIdxTable"),r.getLocal("itBase"),r.getLocal("pIdxTable"))]),r.setLocal("itScalar",r.i32_add(r.getLocal("itScalar"),r.getLocal("scalarSize"))),r.setLocal("itBase",r.i32_add(r.getLocal("itBase"),r.i32_const(o))),r.br(0))),r.call(a+"_reduceTable",r.getLocal("pTable"),r.getLocal("chunkSize")),r.call(e+"_copy",r.getLocal("pTable"),r.getLocal("pr")),r.i32_store(r.i32_const(0),r.getLocal("pTable")))}(),l(),t.exportFunction(a),t.exportFunction(a+"_chunk")};var zt=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(),l=o.getLocal("p1"),r=o.i32_add(o.getLocal("p1"),o.i32_const(n)),s=o.getLocal("pr"),c=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",r,c),...o.call(a+"_copy",l,s)]))}(),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(),l=o.getLocal("p1"),r=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 s=o.getLocal("z1"),c=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)),h=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",s),o.ret(o.call(e+"_eqAffine",o.getLocal("p1"),o.getLocal("p2")))),o.call(a+"_square",s,u),o.call(a+"_mul",c,u,g),o.call(a+"_mul",s,u,f),o.call(a+"_mul",d,f,h),o.if(o.call(a+"_eq",l,g),o.if(o.call(a+"_eq",r,h),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(),l=o.getLocal("p1"),r=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 s=o.getLocal("z1"),c=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)),h=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n)),L=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",s),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",s,g),o.call(a+"_square",u,f),o.call(a+"_mul",l,f,h),o.call(a+"_mul",c,g,_),o.call(a+"_mul",s,g,p),o.call(a+"_mul",u,f,m),o.call(a+"_mul",r,m,w),o.call(a+"_mul",d,p,L),o.if(o.call(a+"_eq",h,_),o.if(o.call(a+"_eq",w,L),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(),l=o.getLocal("p1"),r=o.i32_add(o.getLocal("p1"),o.i32_const(n)),s=o.getLocal("pr"),c=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)),h=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n)),p=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",l,u),o.call(a+"_square",r,g),o.call(a+"_square",g,f),o.call(a+"_add",l,g,h),o.call(a+"_square",h,h),o.call(a+"_sub",h,u,h),o.call(a+"_sub",h,f,h),o.call(a+"_add",h,h,h),o.call(a+"_add",u,u,_),o.call(a+"_add",_,u,_),o.call(a+"_add",r,r,d),o.call(a+"_square",_,s),o.call(a+"_sub",s,h,s),o.call(a+"_sub",s,h,s),o.call(a+"_add",f,f,p),o.call(a+"_add",p,p,p),o.call(a+"_add",p,p,p),o.call(a+"_sub",h,s,c),o.call(a+"_mul",c,_,c),o.call(a+"_sub",c,p,c))}(),function(){const i=t.addFunction(e+"_double");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),l=o.getLocal("p1"),r=o.i32_add(o.getLocal("p1"),o.i32_const(n)),s=o.i32_add(o.getLocal("p1"),o.i32_const(2*n)),c=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)),h=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n)),L=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",s),[...o.ret(o.call(e+"_doubleAffine",o.getLocal("p1"),o.getLocal("pr"))),...o.ret([])]),o.call(a+"_square",l,g),o.call(a+"_square",r,f),o.call(a+"_square",f,h),o.call(a+"_add",l,f,_),o.call(a+"_square",_,_),o.call(a+"_sub",_,g,_),o.call(a+"_sub",_,h,_),o.call(a+"_add",_,_,_),o.call(a+"_add",g,g,p),o.call(a+"_add",p,g,p),o.call(a+"_square",p,m),o.call(a+"_mul",r,s,w),o.call(a+"_add",_,_,c),o.call(a+"_sub",m,c,c),o.call(a+"_add",h,h,L),o.call(a+"_add",L,L,L),o.call(a+"_add",L,L,L),o.call(a+"_sub",_,c,d),o.call(a+"_mul",d,p,d),o.call(a+"_sub",d,L,d),o.call(a+"_add",w,w,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(),l=o.getLocal("p1"),r=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 s=o.getLocal("p2"),c=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)),h=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n)),L=o.i32_const(t.alloc(n)),b=o.i32_const(t.alloc(n)),y=o.i32_const(t.alloc(n)),A=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",l,s),o.if(o.call(a+"_eq",r,c),[...o.call(e+"_doubleAffine",o.getLocal("p2"),o.getLocal("pr")),...o.ret([])])),o.call(a+"_sub",s,l,f),o.call(a+"_sub",c,r,_),o.call(a+"_square",f,h),o.call(a+"_add",h,h,p),o.call(a+"_add",p,p,p),o.call(a+"_mul",f,p,m),o.call(a+"_add",_,_,w),o.call(a+"_mul",l,p,b),o.call(a+"_square",w,L),o.call(a+"_add",b,b,y),o.call(a+"_sub",L,m,d),o.call(a+"_sub",d,y,d),o.call(a+"_mul",r,m,A),o.call(a+"_add",A,A,A),o.call(a+"_sub",b,d,u),o.call(a+"_mul",u,w,u),o.call(a+"_sub",u,A,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(),l=o.getLocal("p1"),r=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 s=o.getLocal("z1"),c=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)),h=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n)),L=o.i32_const(t.alloc(n)),b=o.i32_const(t.alloc(n)),y=o.i32_const(t.alloc(n)),A=o.i32_const(t.alloc(n)),C=o.i32_const(t.alloc(n)),I=o.i32_const(t.alloc(n)),F=o.i32_const(t.alloc(n)),x=o.i32_const(t.alloc(n)),E=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",s),[...o.call(e+"_addAffine",l,c,u),...o.ret([])]),o.call(a+"_square",s,h),o.call(a+"_mul",c,h,_),o.call(a+"_mul",s,h,p),o.call(a+"_mul",d,p,m),o.if(o.call(a+"_eq",l,_),o.if(o.call(a+"_eq",r,m),[...o.call(e+"_doubleAffine",o.getLocal("p2"),o.getLocal("pr")),...o.ret([])])),o.call(a+"_sub",_,l,w),o.call(a+"_sub",m,r,b),o.call(a+"_square",w,L),o.call(a+"_add",L,L,y),o.call(a+"_add",y,y,y),o.call(a+"_mul",w,y,A),o.call(a+"_add",b,b,C),o.call(a+"_mul",l,y,F),o.call(a+"_square",C,I),o.call(a+"_add",F,F,x),o.call(a+"_sub",I,A,u),o.call(a+"_sub",u,x,u),o.call(a+"_mul",r,A,E),o.call(a+"_add",E,E,E),o.call(a+"_sub",F,u,g),o.call(a+"_mul",g,C,g),o.call(a+"_sub",g,E,g),o.call(a+"_add",s,w,f),o.call(a+"_square",f,f),o.call(a+"_sub",f,h,f),o.call(a+"_sub",f,L,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(),l=o.getLocal("p1"),r=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 s=o.getLocal("z1"),c=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)),h=o.i32_add(o.getLocal("pr"),o.i32_const(2*n)),_=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n)),L=o.i32_const(t.alloc(n)),b=o.i32_const(t.alloc(n)),y=o.i32_const(t.alloc(n)),A=o.i32_const(t.alloc(n)),C=o.i32_const(t.alloc(n)),I=o.i32_const(t.alloc(n)),F=o.i32_const(t.alloc(n)),x=o.i32_const(t.alloc(n)),E=o.i32_const(t.alloc(n)),v=o.i32_const(t.alloc(n)),B=o.i32_const(t.alloc(n)),S=o.i32_const(t.alloc(n)),P=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",s),[...o.call(e+"_addMixed",c,l,g),...o.ret([])]),o.if(o.call(a+"_isOne",u),[...o.call(e+"_addMixed",l,c,g),...o.ret([])]),o.call(a+"_square",s,_),o.call(a+"_square",u,p),o.call(a+"_mul",l,p,m),o.call(a+"_mul",c,_,w),o.call(a+"_mul",s,_,L),o.call(a+"_mul",u,p,b),o.call(a+"_mul",r,b,y),o.call(a+"_mul",d,L,A),o.if(o.call(a+"_eq",m,w),o.if(o.call(a+"_eq",y,A),[...o.call(e+"_double",o.getLocal("p1"),o.getLocal("pr")),...o.ret([])])),o.call(a+"_sub",w,m,C),o.call(a+"_sub",A,y,I),o.call(a+"_add",C,C,F),o.call(a+"_square",F,F),o.call(a+"_mul",C,F,x),o.call(a+"_add",I,I,E),o.call(a+"_mul",m,F,B),o.call(a+"_square",E,v),o.call(a+"_add",B,B,S),o.call(a+"_sub",v,x,g),o.call(a+"_sub",g,S,g),o.call(a+"_mul",y,x,P),o.call(a+"_add",P,P,P),o.call(a+"_sub",B,g,f),o.call(a+"_mul",f,E,f),o.call(a+"_sub",f,P,f),o.call(a+"_add",s,u,h),o.call(a+"_square",h,h),o.call(a+"_sub",h,_,h),o.call(a+"_sub",h,p,h),o.call(a+"_mul",h,C,h))}(),function(){const i=t.addFunction(e+"_negAffine");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),l=o.getLocal("p1"),r=o.i32_add(o.getLocal("p1"),o.i32_const(n)),s=o.getLocal("pr"),c=o.i32_add(o.getLocal("pr"),o.i32_const(n));i.addCode(o.call(a+"_copy",l,s),o.call(a+"_neg",r,c))}(),function(){const i=t.addFunction(e+"_neg");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),l=o.getLocal("p1"),r=o.i32_add(o.getLocal("p1"),o.i32_const(n)),s=o.i32_add(o.getLocal("p1"),o.i32_const(2*n)),c=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",l,c),o.call(a+"_neg",r,d),o.call(a+"_copy",s,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(),l=o.getLocal("p1"),r=o.i32_add(o.getLocal("p1"),o.i32_const(n)),s=o.i32_add(o.getLocal("p1"),o.i32_const(2*n)),c=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",c),...o.call(a+"_zero",d)],[...o.call(a+"_inverse",s,u),...o.call(a+"_square",u,g),...o.call(a+"_mul",u,g,f),...o.call(a+"_mul",l,g,c),...o.call(a+"_mul",r,f,d)]))}(),function(){const o=t.addFunction(e+"_inCurveAffine");o.addParam("pIn","i32"),o.setReturnType("i32");const l=o.getCodeBuilder(),r=l.getLocal("pIn"),s=l.i32_add(l.getLocal("pIn"),l.i32_const(n)),c=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(n));o.addCode(l.call(a+"_square",s,c),l.call(a+"_square",r,d),l.call(a+"_mul",r,d,d),l.call(a+"_add",d,l.i32_const(i),d),l.ret(l.call(a+"_eq",c,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(),l=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)),l),...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"),l,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(),l=o.getLocal("p1"),r=o.i32_add(o.getLocal("p1"),o.i32_const(n)),s=o.i32_add(o.getLocal("p1"),o.i32_const(2*n)),c=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)),h=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",s,g),...o.call(a+"_square",g,f),...o.call(a+"_mul",g,f,h),...o.call(a+"_mul",l,f,c),...o.call(a+"_mul",r,h,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),l=i.i32_const(o),r=i.i32_const(o),s=i.i32_const(o+n);a.addCode(i.if(i.call(e+"_isZeroAffine",i.getLocal("pIn")),[...i.call(e+"_zeroAffine",i.getLocal("pOut")),...i.ret([])]),i.call(e+"_fromMontgomeryAffine",i.getLocal("pIn"),l),i.call(e+"__reverseBytes",r,i.i32_const(n),i.getLocal("pOut")),i.call(e+"__reverseBytes",s,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(),l=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZeroAffine",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"),l),o.call(e+"__reverseBytes",l,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),l=i.i32_const(o),r=i.i32_const(o),s=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),r),i.call(e+"__reverseBytes",i.i32_add(i.getLocal("pIn"),i.i32_const(n)),i.i32_const(n),s),i.call(e+"_toMontgomeryAffine",l,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 l=o.getCodeBuilder(),r=t.alloc(2*n),s=l.i32_const(r),c=l.i32_const(r+n);o.addCode(l.setLocal("firstByte",l.i32_load8_u(l.getLocal("pIn"))),l.if(l.i32_and(l.getLocal("firstByte"),l.i32_const(64)),[...l.call(e+"_zeroAffine",l.getLocal("pOut")),...l.ret([])]),l.setLocal("greatest",l.i32_and(l.getLocal("firstByte"),l.i32_const(128))),l.call(a+"_copy",l.getLocal("pIn"),c),l.i32_store8(c,l.i32_and(l.getLocal("firstByte"),l.i32_const(63))),l.call(e+"__reverseBytes",c,l.i32_const(n),s),l.call(a+"_toMontgomery",s,l.getLocal("pOut")),l.call(a+"_square",l.getLocal("pOut"),c),l.call(a+"_mul",l.getLocal("pOut"),c,c),l.call(a+"_add",c,l.i32_const(i),c),l.call(a+"_sqrt",c,c),l.call(a+"_neg",c,s),l.if(l.i32_eq(l.call(a+"_sign",c),l.i32_const(-1)),l.if(l.getLocal("greatest"),l.call(a+"_copy",c,l.i32_add(l.getLocal("pOut"),l.i32_const(n))),l.call(a+"_neg",c,l.i32_add(l.getLocal("pOut"),l.i32_const(n)))),l.if(l.getLocal("greatest"),l.call(a+"_neg",c,l.i32_add(l.getLocal("pOut"),l.i32_const(n))),l.call(a+"_copy",c,l.i32_add(l.getLocal("pOut"),l.i32_const(n))))))}(),Tt(t,e+"_batchLEMtoU",e+"_LEMtoU",2*n,2*n),Tt(t,e+"_batchLEMtoC",e+"_LEMtoC",2*n,n),Tt(t,e+"_batchUtoLEM",e+"_UtoLEM",2*n,2*n),Tt(t,e+"_batchCtoLEM",e+"_CtoLEM",n,2*n,!0),Tt(t,e+"_batchToJacobian",e+"_toJacobian",2*n,3*n,!0),Ut(t,e,e+"_multiexp",e+"_add",3*n),Ut(t,e,e+"_multiexpAffine",e+"_addMixed",2*n),Ot(t,e+"_timesScalar",3*n,e+"_add",e+"_double",e+"_sub",e+"_copy",e+"_zero"),Ot(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};const{isOdd:Qt,modInv:qt,modPow:Mt}=W,kt=V;var Rt=function(t,e,a,i,o){const n=8*t.modules[i].n64,l=8*t.modules[a].n64,r=t.modules[i].q;let s=r-1n,c=0;for(;!Qt(s);)c++,s>>=1n;let d=2n;for(;1n===Mt(d,r>>1n,r);)d+=1n;const u=new Array(c+1);u[c]=Mt(d,s,r);let g=c-1;for(;g>=0;)u[g]=Mt(u[g+1],2n,r),g--;const f=[],h=(1n<<BigInt(8*n))%r;for(let t=0;t<u.length;t++){const e=u[t]*h%r;f.push(...kt.bigInt2BytesLE(e,n))}const _=t.alloc(f),p=new Array(c+1);p[0]=1n;for(let t=1;t<=c;t++)p[t]=2n*p[t-1];const m=[];for(let t=0;t<=c;t++){const e=qt(p[t],r)*h%r;m.push(...kt.bigInt2BytesLE(e,n))}const w=t.alloc(m),L=Mt(d,2n,r),b=[],y=[];for(let t=0;t<=c;t++){const e=Mt(L,2n**BigInt(t),r),a=qt(r+1n-e,r);b.push(...kt.bigInt2BytesLE(e*h%r,n)),y.push(...kt.bigInt2BytesLE(a*h%r,n))}const A=t.alloc(b),C=t.alloc(y);function I(t){let e=0;for(let a=0;a<8;a++)t&1<<a&&(e|=128>>a);return e}const F=Array(256);for(let t=0;t<256;t++)F[t]=I(t);const x=t.alloc(F);function E(){const a=t.addFunction(e+"_fft");a.addParam("px","i32"),a.addParam("n","i32"),a.addLocal("bits","i32");const o=a.getCodeBuilder(),l=o.i32_const(t.alloc(n));a.addCode(o.setLocal("bits",o.call(e+"__log2",o.getLocal("n"))),o.call(i+"_one",l),o.call(e+"_rawfft",o.getLocal("px"),o.getLocal("bits"),o.i32_const(0),l))}!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)),x,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)),x,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)),x,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)),x,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(l));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(l)))),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(l)))),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 r=n.getCodeBuilder(),s=r.i32_const(t.alloc(l));n.addCode(r.if(r.i32_and(r.i32_eqz(r.getLocal("reverse")),r.call(i+"_isOne",r.getLocal("mulFactor"))),r.ret([])),r.setLocal("n",r.i32_shl(r.i32_const(1),r.getLocal("bits"))),r.setLocal("mask",r.i32_sub(r.getLocal("n"),r.i32_const(1))),r.setLocal("i",r.i32_const(1)),r.setLocal("ndiv2",r.i32_shr_u(r.getLocal("n"),r.i32_const(1))),r.block(r.loop(r.br_if(1,r.i32_ge_u(r.getLocal("i"),r.getLocal("ndiv2"))),r.setLocal("idx1",r.i32_add(r.getLocal("px"),r.i32_mul(r.getLocal("i"),r.i32_const(l)))),r.setLocal("idx2",r.i32_add(r.getLocal("px"),r.i32_mul(r.i32_sub(r.getLocal("n"),r.getLocal("i")),r.i32_const(l)))),r.if(r.getLocal("reverse"),r.if(r.call(i+"_isOne",r.getLocal("mulFactor")),[...r.call(a+"_copy",r.getLocal("idx1"),s),...r.call(a+"_copy",r.getLocal("idx2"),r.getLocal("idx1")),...r.call(a+"_copy",s,r.getLocal("idx2"))],[...r.call(a+"_copy",r.getLocal("idx1"),s),...r.call(o,r.getLocal("idx2"),r.getLocal("mulFactor"),r.getLocal("idx1")),...r.call(o,s,r.getLocal("mulFactor"),r.getLocal("idx2"))]),r.if(r.call(i+"_isOne",r.getLocal("mulFactor")),[],[...r.call(o,r.getLocal("idx1"),r.getLocal("mulFactor"),r.getLocal("idx1")),...r.call(o,r.getLocal("idx2"),r.getLocal("mulFactor"),r.getLocal("idx2"))])),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0))),r.if(r.call(i+"_isOne",r.getLocal("mulFactor")),[],[...r.call(o,r.getLocal("px"),r.getLocal("mulFactor"),r.getLocal("px")),...r.setLocal("idx2",r.i32_add(r.getLocal("px"),r.i32_mul(r.getLocal("ndiv2"),r.i32_const(l)))),...r.call(o,r.getLocal("idx2"),r.getLocal("mulFactor"),r.getLocal("idx2"))]))}(),function(){const r=t.addFunction(e+"_rawfft");r.addParam("px","i32"),r.addParam("bits","i32"),r.addParam("reverse","i32"),r.addParam("mulFactor","i32"),r.addLocal("s","i32"),r.addLocal("k","i32"),r.addLocal("j","i32"),r.addLocal("m","i32"),r.addLocal("mdiv2","i32"),r.addLocal("n","i32"),r.addLocal("pwm","i32"),r.addLocal("idx1","i32"),r.addLocal("idx2","i32");const s=r.getCodeBuilder(),c=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));r.addCode(s.call(e+"__reversePermutation",s.getLocal("px"),s.getLocal("bits")),s.setLocal("n",s.i32_shl(s.i32_const(1),s.getLocal("bits"))),s.setLocal("s",s.i32_const(1)),s.block(s.loop(s.br_if(1,s.i32_gt_u(s.getLocal("s"),s.getLocal("bits"))),s.setLocal("m",s.i32_shl(s.i32_const(1),s.getLocal("s"))),s.setLocal("pwm",s.i32_add(s.i32_const(_),s.i32_mul(s.getLocal("s"),s.i32_const(n)))),s.setLocal("k",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_ge_u(s.getLocal("k"),s.getLocal("n"))),s.call(i+"_one",c),s.setLocal("mdiv2",s.i32_shr_u(s.getLocal("m"),s.i32_const(1))),s.setLocal("j",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_ge_u(s.getLocal("j"),s.getLocal("mdiv2"))),s.setLocal("idx1",s.i32_add(s.getLocal("px"),s.i32_mul(s.i32_add(s.getLocal("k"),s.getLocal("j")),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("idx1"),s.i32_mul(s.getLocal("mdiv2"),s.i32_const(l)))),s.call(o,s.getLocal("idx2"),c,d),s.call(a+"_copy",s.getLocal("idx1"),u),s.call(a+"_add",u,d,s.getLocal("idx1")),s.call(a+"_sub",u,d,s.getLocal("idx2")),s.call(i+"_mul",c,s.getLocal("pwm"),c),s.setLocal("j",s.i32_add(s.getLocal("j"),s.i32_const(1))),s.br(0))),s.setLocal("k",s.i32_add(s.getLocal("k"),s.getLocal("m"))),s.br(0))),s.setLocal("s",s.i32_add(s.getLocal("s"),s.i32_const(1))),s.br(0))),s.call(e+"__fftFinal",s.getLocal("px"),s.getLocal("bits"),s.getLocal("reverse"),s.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(c)),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 r=t.addFunction(e+"_fftJoin");r.addParam("pBuff1","i32"),r.addParam("pBuff2","i32"),r.addParam("n","i32"),r.addParam("first","i32"),r.addParam("inc","i32"),r.addLocal("idx1","i32"),r.addLocal("idx2","i32"),r.addLocal("i","i32");const s=r.getCodeBuilder(),c=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));r.addCode(s.call(i+"_copy",s.getLocal("first"),c),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.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(o,s.getLocal("idx2"),c,d),s.call(a+"_copy",s.getLocal("idx1"),u),s.call(a+"_add",u,d,s.getLocal("idx1")),s.call(a+"_sub",u,d,s.getLocal("idx2")),s.call(i+"_mul",c,s.getLocal("inc"),c),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const r=t.addFunction(e+"_fftJoinExt");r.addParam("pBuff1","i32"),r.addParam("pBuff2","i32"),r.addParam("n","i32"),r.addParam("first","i32"),r.addParam("inc","i32"),r.addParam("totalBits","i32"),r.addLocal("idx1","i32"),r.addLocal("idx2","i32"),r.addLocal("i","i32"),r.addLocal("pShiftToM","i32");const s=r.getCodeBuilder(),c=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));r.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(A),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.call(i+"_copy",s.getLocal("first"),c),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.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(a+"_add",s.getLocal("idx1"),s.getLocal("idx2"),d),s.call(o,s.getLocal("idx2"),s.getLocal("pShiftToM"),s.getLocal("idx2")),s.call(a+"_add",s.getLocal("idx1"),s.getLocal("idx2"),s.getLocal("idx2")),s.call(o,s.getLocal("idx2"),c,s.getLocal("idx2")),s.call(a+"_copy",d,s.getLocal("idx1")),s.call(i+"_mul",c,s.getLocal("inc"),c),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const r=t.addFunction(e+"_fftJoinExtInv");r.addParam("pBuff1","i32"),r.addParam("pBuff2","i32"),r.addParam("n","i32"),r.addParam("first","i32"),r.addParam("inc","i32"),r.addParam("totalBits","i32"),r.addLocal("idx1","i32"),r.addLocal("idx2","i32"),r.addLocal("i","i32"),r.addLocal("pShiftToM","i32"),r.addLocal("pSConst","i32");const s=r.getCodeBuilder(),c=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));r.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(A),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.setLocal("pSConst",s.i32_add(s.i32_const(C),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.call(i+"_copy",s.getLocal("first"),c),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.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(o,s.getLocal("idx2"),c,d),s.call(a+"_sub",s.getLocal("idx1"),d,s.getLocal("idx2")),s.call(o,s.getLocal("idx2"),s.getLocal("pSConst"),s.getLocal("idx2")),s.call(o,s.getLocal("idx1"),s.getLocal("pShiftToM"),s.getLocal("idx1")),s.call(a+"_sub",d,s.getLocal("idx1"),s.getLocal("idx1")),s.call(o,s.getLocal("idx1"),s.getLocal("pSConst"),s.getLocal("idx1")),s.call(i+"_mul",c,s.getLocal("inc"),c),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const r=t.addFunction(e+"_fftMix");r.addParam("pBuff","i32"),r.addParam("n","i32"),r.addParam("exp","i32"),r.addLocal("nGroups","i32"),r.addLocal("nPerGroup","i32"),r.addLocal("nPerGroupDiv2","i32"),r.addLocal("pairOffset","i32"),r.addLocal("idx1","i32"),r.addLocal("idx2","i32"),r.addLocal("i","i32"),r.addLocal("j","i32"),r.addLocal("pwm","i32");const s=r.getCodeBuilder(),c=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));r.addCode(s.setLocal("nPerGroup",s.i32_shl(s.i32_const(1),s.getLocal("exp"))),s.setLocal("nPerGroupDiv2",s.i32_shr_u(s.getLocal("nPerGroup"),s.i32_const(1))),s.setLocal("nGroups",s.i32_shr_u(s.getLocal("n"),s.getLocal("exp"))),s.setLocal("pairOffset",s.i32_mul(s.getLocal("nPerGroupDiv2"),s.i32_const(l))),s.setLocal("pwm",s.i32_add(s.i32_const(_),s.i32_mul(s.getLocal("exp"),s.i32_const(n)))),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("nGroups"))),s.call(i+"_one",c),s.setLocal("j",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("j"),s.getLocal("nPerGroupDiv2"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff"),s.i32_mul(s.i32_add(s.i32_mul(s.getLocal("i"),s.getLocal("nPerGroup")),s.getLocal("j")),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("idx1"),s.getLocal("pairOffset"))),s.call(o,s.getLocal("idx2"),c,d),s.call(a+"_copy",s.getLocal("idx1"),u),s.call(a+"_add",u,d,s.getLocal("idx1")),s.call(a+"_sub",u,d,s.getLocal("idx2")),s.call(i+"_mul",c,s.getLocal("pwm"),c),s.setLocal("j",s.i32_add(s.getLocal("j"),s.i32_const(1))),s.br(0))),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.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(),r=n.i32_const(t.alloc(l));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(l))),n.getLocal("factor"),n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("ndiv2"),n.i32_const(l))))),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(l)))),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(l)))),n.call(o,n.getLocal("idx2"),n.getLocal("factor"),r),n.call(o,n.getLocal("idx1"),n.getLocal("factor"),n.getLocal("idx2")),n.call(a+"_copy",r,n.getLocal("idx1")),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))}(),function(){const r=t.addFunction(e+"_prepareLagrangeEvaluation");r.addParam("pBuff1","i32"),r.addParam("pBuff2","i32"),r.addParam("n","i32"),r.addParam("first","i32"),r.addParam("inc","i32"),r.addParam("totalBits","i32"),r.addLocal("idx1","i32"),r.addLocal("idx2","i32"),r.addLocal("i","i32"),r.addLocal("pShiftToM","i32"),r.addLocal("pSConst","i32");const s=r.getCodeBuilder(),c=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));r.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(A),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.setLocal("pSConst",s.i32_add(s.i32_const(C),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.call(i+"_copy",s.getLocal("first"),c),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.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(o,s.getLocal("idx1"),s.getLocal("pShiftToM"),d),s.call(a+"_sub",s.getLocal("idx2"),d,d),s.call(a+"_sub",s.getLocal("idx1"),s.getLocal("idx2"),s.getLocal("idx2")),s.call(o,d,s.getLocal("pSConst"),s.getLocal("idx1")),s.call(o,s.getLocal("idx2"),c,s.getLocal("idx2")),s.call(i+"_mul",c,s.getLocal("inc"),c),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.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")},Dt=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(),l=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"),l),n.call(a+"_add",l,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},Nt=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(),l=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)),l),n.call(a+"_add",n.getLocal("pOut"),l,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(),l=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"),l),n.call(a+"_sub",l,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},$t=function(t,e,a,i,o,n,l,r){const s=t.addFunction(e);s.addParam("pIn","i32"),s.addParam("n","i32"),s.addParam("pFirst","i32"),s.addParam("pInc","i32"),s.addParam("pOut","i32"),s.addLocal("pOldFree","i32"),s.addLocal("i","i32"),s.addLocal("pFrom","i32"),s.addLocal("pTo","i32");const c=s.getCodeBuilder(),d=c.i32_const(t.alloc(l));s.addCode(c.setLocal("pFrom",c.getLocal("pIn")),c.setLocal("pTo",c.getLocal("pOut"))),s.addCode(c.call(i+"_copy",c.getLocal("pFirst"),d)),s.addCode(c.setLocal("i",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("i"),c.getLocal("n"))),c.call(r,c.getLocal("pFrom"),d,c.getLocal("pTo")),c.setLocal("pFrom",c.i32_add(c.getLocal("pFrom"),c.i32_const(o))),c.setLocal("pTo",c.i32_add(c.getLocal("pTo"),c.i32_const(n))),c.call(i+"_mul",d,c.getLocal("pInc"),d),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0)))),t.exportFunction(e)};const Vt=V,Kt=At,jt=Ft,Ht=Bt,Zt=Gt,Wt=zt,Yt=Rt,Jt=Dt,Xt=Nt,te=$t,{bitLength:ee,modInv:ae,isOdd:ie,isNegative:oe}=W;const ne=V,le=At,re=Ft,se=Bt,ce=Gt,de=zt,ue=Rt,ge=Dt,fe=Nt,he=$t,{bitLength:_e,isOdd:pe,isNegative:me}=W;var we=function(t,e){const a=e||"bn128";if(t.modules[a])return a;const i=21888242871839275222246405745257275088696311157297823662689037894645226208583n,o=21888242871839275222246405745257275088548364400416034343698204186575808495617n,n=Math.floor((ee(i-1n)-1)/64)+1,l=8*n,r=l,s=l,c=2*s,d=12*s,u=t.alloc(Vt.bigInt2BytesLE(o,r)),g=Kt(t,i,"f1m");jt(t,o,"fr","frm");const f=t.alloc(Vt.bigInt2BytesLE(L(3n),s)),h=Wt(t,"g1m","f1m",f);Yt(t,"frm","frm","frm","frm_mul"),Jt(t,"pol","frm"),Xt(t,"qap","frm");const _=Ht(t,"f1m_neg","f2m","f1m"),p=t.alloc([...Vt.bigInt2BytesLE(L(19485874751759354771024239261021720505790618469301721065564631296452457478373n),s),...Vt.bigInt2BytesLE(L(266929791119991161246907387137283842545076965332900288569378510910307636690n),s)]),m=Wt(t,"g2m","f2m",p);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(l));i.addCode(o.call("frm_fromMontgomery",o.getLocal("pFr"),n),o.call(a,o.getLocal("pG"),n,o.i32_const(l),o.getLocal("pr"))),t.exportFunction(e)}function L(t){return BigInt(t)*(1n<<BigInt(8*s))%i}w("g1m_timesFr","g1m_timesScalar"),Yt(t,"g1m","g1m","frm","g1m_timesFr"),w("g2m_timesFr","g2m_timesScalar"),Yt(t,"g2m","g2m","frm","g2m_timesFr"),w("g1m_timesFrAffine","g1m_timesScalarAffine"),w("g2m_timesFrAffine","g2m_timesScalarAffine"),te(t,"frm_batchApplyKey","fmr","frm",l,l,l,"frm_mul"),te(t,"g1m_batchApplyKey","g1m","frm",3*l,3*l,l,"g1m_timesFr"),te(t,"g1m_batchApplyKeyMixed","g1m","frm",2*l,3*l,l,"g1m_timesFrAffine"),te(t,"g2m_batchApplyKey","g2m","frm",2*l*3,3*l*2,l,"g2m_timesFr"),te(t,"g2m_batchApplyKeyMixed","g2m","frm",2*l*2,3*l*2,l,"g2m_timesFrAffine");const b=[1n,2n,1n],y=t.alloc([...Vt.bigInt2BytesLE(L(b[0]),s),...Vt.bigInt2BytesLE(L(b[1]),s),...Vt.bigInt2BytesLE(L(b[2]),s)]),A=[0n,1n,0n],C=t.alloc([...Vt.bigInt2BytesLE(L(A[0]),s),...Vt.bigInt2BytesLE(L(A[1]),s),...Vt.bigInt2BytesLE(L(A[2]),s)]),I=[[10857046999023057135944570762232829481370756359578518086990519993285655852781n,11559732032986387107991004021392285783925812861821192530917403151452391805634n],[8495653923123431417604973247489272438418190587263600148770280649306958101930n,4082367875863433681332203403145435568316851327593401208105741076214120093531n],[1n,0n]],F=t.alloc([...Vt.bigInt2BytesLE(L(I[0][0]),s),...Vt.bigInt2BytesLE(L(I[0][1]),s),...Vt.bigInt2BytesLE(L(I[1][0]),s),...Vt.bigInt2BytesLE(L(I[1][1]),s),...Vt.bigInt2BytesLE(L(I[2][0]),s),...Vt.bigInt2BytesLE(L(I[2][1]),s)]),x=[[0n,0n],[1n,0n],[0n,0n]],E=t.alloc([...Vt.bigInt2BytesLE(L(x[0][0]),s),...Vt.bigInt2BytesLE(L(x[0][1]),s),...Vt.bigInt2BytesLE(L(x[1][0]),s),...Vt.bigInt2BytesLE(L(x[1][1]),s),...Vt.bigInt2BytesLE(L(x[2][0]),s),...Vt.bigInt2BytesLE(L(x[2][1]),s)]),v=t.alloc([...Vt.bigInt2BytesLE(L(1),s),...Vt.bigInt2BytesLE(L(0),s),...Vt.bigInt2BytesLE(L(0),s),...Vt.bigInt2BytesLE(L(0),s),...Vt.bigInt2BytesLE(L(0),s),...Vt.bigInt2BytesLE(L(0),s),...Vt.bigInt2BytesLE(L(0),s),...Vt.bigInt2BytesLE(L(0),s),...Vt.bigInt2BytesLE(L(0),s),...Vt.bigInt2BytesLE(L(0),s),...Vt.bigInt2BytesLE(L(0),s),...Vt.bigInt2BytesLE(L(0),s)]),B=t.alloc([...Vt.bigInt2BytesLE(L(9),s),...Vt.bigInt2BytesLE(L(1),s)]),S=t.alloc([...Vt.bigInt2BytesLE(L(ae(2n,i)),s),...Vt.bigInt2BytesLE(0n,s)]),P=B,G=t.alloc([...Vt.bigInt2BytesLE(L(19485874751759354771024239261021720505790618469301721065564631296452457478373n),s),...Vt.bigInt2BytesLE(L(266929791119991161246907387137283842545076965332900288569378510910307636690n),s)]);!function(){const e=t.addFunction(a+"_mulNR6");e.addParam("x","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder();e.addCode(i.call(_+"_mul",i.i32_const(B),i.getLocal("x"),i.getLocal("pr")))}();const O=Zt(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(_+"_mul",i.i32_const(B),i.i32_add(i.getLocal("x"),i.i32_const(4*l)),i.getLocal("pr")),i.call(_+"_copy",i.getLocal("x"),i.i32_add(i.getLocal("pr"),i.i32_const(2*l))),i.call(_+"_copy",i.i32_add(i.getLocal("x"),i.i32_const(2*l)),i.i32_add(i.getLocal("pr"),i.i32_const(4*l))))}();const T=Ht(t,a+"_mulNR12","ftm",O),U=function(t){let e=t;const a=[];for(;e>0n;)ie(e)?a.push(1):a.push(0),e>>=1n;return a}(29793968203157093288n),z=t.alloc(U),Q=3*c,q=U.length-1,M=U.reduce(((t,e)=>t+(0!=e?1:0)),0),k=6*l,R=3*l*2+(M+q+1)*Q;t.modules[a]={n64:n,pG1gen:y,pG1zero:C,pG1b:f,pG2gen:F,pG2zero:E,pG2b:p,pq:t.modules.f1m.pq,pr:u,pOneT:v,prePSize:k,preQSize:R,r:o.toString(),q:i.toString()};const D=4965661367192848881n;function N(e){const o=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[8376118865763821496583973867626364092589906065868298776909617916018768340080n,16469823323077808223889137241176536799009286646108169935659301613961712198316n],[21888242871839275220042445260109153167277707414472061641714758635765020556617n,0n],[11697423496358154304825782922584725312912383441159505038794027105778954184319n,303847389135065887422783454877609941456349188919719272345083954437860409601n],[21888242871839275220042445260109153167277707414472061641714758635765020556616n,0n],[3321304630594332808241809054958361220322477375291206261884409189760185844239n,5722266937896532885780051958958348231143373700109372999374820235121374419868n],[21888242871839275222246405745257275088696311157297823662689037894645226208582n,0n],[13512124006075453725662431877630910996106405091429524885779419978626457868503n,5418419548761466998357268504080738289687024511189653727029736280683514010267n],[2203960485148121921418603742825762020974279258880205651966n,0n],[10190819375481120917420622822672549775783927716138318623895010788866272024264n,21584395482704209334823622290379665147239961968378104390343953940207365798982n],[2203960485148121921418603742825762020974279258880205651967n,0n],[18566938241244942414004596690298913868373833782006617400804628704885040364344n,16165975933942742336466353786298926857552937457188450663314217659523851788715n]]],n=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[21575463638280843010398324269430826099269044274347216827212613867836435027261n,10307601595873709700152284273816112264069230130616436755625194854815875713954n],[21888242871839275220042445260109153167277707414472061641714758635765020556616n,0n],[3772000881919853776433695186713858239009073593817195771773381919316419345261n,2236595495967245188281701248203181795121068902605861227855261137820944008926n],[2203960485148121921418603742825762020974279258880205651966n,0n],[18429021223477853657660792034369865839114504446431234726392080002137598044644n,9344045779998320333812420223237981029506012124075525679208581902008406485703n]],[[1n,0n],[2581911344467009335267311115468803099551665605076196740867805258568234346338n,19937756971775647987995932169929341994314640652964949448313374472400716661030n],[2203960485148121921418603742825762020974279258880205651966n,0n],[5324479202449903542726783395506214481928257762400643279780343368557297135718n,16208900380737693084919495127334387981393726419856888799917914180988844123039n],[21888242871839275220042445260109153167277707414472061641714758635765020556616n,0n],[13981852324922362344252311234282257507216387789820983642040889267519694726527n,7629828391165209371577384193250820201684255241773809077146787135900891633097n]]],l=t.addFunction(a+"__frobeniusMap"+e);l.addParam("x","i32"),l.addParam("r","i32");const r=l.getCodeBuilder();for(let a=0;a<6;a++){const i=0==a?r.getLocal("x"):r.i32_add(r.getLocal("x"),r.i32_const(a*c)),u=i,f=r.i32_add(r.getLocal("x"),r.i32_const(a*c+s)),h=0==a?r.getLocal("r"):r.i32_add(r.getLocal("r"),r.i32_const(a*c)),p=h,m=r.i32_add(r.getLocal("r"),r.i32_const(a*c+s)),w=d(o[Math.floor(a/3)][e%12],n[a%3][e%6]),b=t.alloc([...Vt.bigInt2BytesLE(L(w[0]),32),...Vt.bigInt2BytesLE(L(w[1]),32)]);e%2==1?l.addCode(r.call(g+"_copy",u,p),r.call(g+"_neg",f,m),r.call(_+"_mul",h,r.i32_const(b),h)):l.addCode(r.call(_+"_mul",i,r.i32_const(b),h))}function d(t,e){const a=BigInt(t[0]),o=BigInt(t[1]),n=BigInt(e[0]),l=BigInt(e[1]),r=[(a*n-o*l)%i,(a*l+o*n)%i];return oe(r[0])&&(r[0]=r[0]+i),r}}function $(e,i){const o=function(t){let e=t;const a=[];for(;e>0n;){if(ie(e)){const t=2-Number(e%4n);a.push(t),e-=BigInt(t)}else a.push(0);e>>=1n}return a}(e).map((t=>-1==t?255:t)),n=t.alloc(o),l=t.addFunction(a+"__cyclotomicExp_"+i);l.addParam("x","i32"),l.addParam("r","i32"),l.addLocal("bit","i32"),l.addLocal("i","i32");const r=l.getCodeBuilder(),s=r.getLocal("x"),c=r.getLocal("r"),u=r.i32_const(t.alloc(d));l.addCode(r.call(T+"_conjugate",s,u),r.call(T+"_one",c),r.if(r.teeLocal("bit",r.i32_load8_s(r.i32_const(o.length-1),n)),r.if(r.i32_eq(r.getLocal("bit"),r.i32_const(1)),r.call(T+"_mul",c,s,c),r.call(T+"_mul",c,u,c))),r.setLocal("i",r.i32_const(o.length-2)),r.block(r.loop(r.call(a+"__cyclotomicSquare",c,c),r.if(r.teeLocal("bit",r.i32_load8_s(r.getLocal("i"),n)),r.if(r.i32_eq(r.getLocal("bit"),r.i32_const(1)),r.call(T+"_mul",c,s,c),r.call(T+"_mul",c,u,c))),r.br_if(1,r.i32_eqz(r.getLocal("i"))),r.setLocal("i",r.i32_sub(r.getLocal("i"),r.i32_const(1))),r.br(0))))}function V(){!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(c)),l=i.i32_add(i.getLocal("x"),i.i32_const(2*c)),r=i.i32_add(i.getLocal("x"),i.i32_const(3*c)),s=i.i32_add(i.getLocal("x"),i.i32_const(4*c)),d=i.i32_add(i.getLocal("x"),i.i32_const(5*c)),u=i.getLocal("r"),g=i.i32_add(i.getLocal("r"),i.i32_const(c)),f=i.i32_add(i.getLocal("r"),i.i32_const(2*c)),h=i.i32_add(i.getLocal("r"),i.i32_const(3*c)),p=i.i32_add(i.getLocal("r"),i.i32_const(4*c)),m=i.i32_add(i.getLocal("r"),i.i32_const(5*c)),w=i.i32_const(t.alloc(c)),L=i.i32_const(t.alloc(c)),b=i.i32_const(t.alloc(c)),y=i.i32_const(t.alloc(c)),A=i.i32_const(t.alloc(c)),C=i.i32_const(t.alloc(c)),I=i.i32_const(t.alloc(c)),F=i.i32_const(t.alloc(c));e.addCode(i.call(_+"_mul",o,s,I),i.call(_+"_mul",s,i.i32_const(B),w),i.call(_+"_add",o,w,w),i.call(_+"_add",o,s,F),i.call(_+"_mul",F,w,w),i.call(_+"_mul",i.i32_const(B),I,F),i.call(_+"_add",I,F,F),i.call(_+"_sub",w,F,w),i.call(_+"_add",I,I,L),i.call(_+"_mul",r,l,I),i.call(_+"_mul",l,i.i32_const(B),b),i.call(_+"_add",r,b,b),i.call(_+"_add",r,l,F),i.call(_+"_mul",F,b,b),i.call(_+"_mul",i.i32_const(B),I,F),i.call(_+"_add",I,F,F),i.call(_+"_sub",b,F,b),i.call(_+"_add",I,I,y),i.call(_+"_mul",n,d,I),i.call(_+"_mul",d,i.i32_const(B),A),i.call(_+"_add",n,A,A),i.call(_+"_add",n,d,F),i.call(_+"_mul",F,A,A),i.call(_+"_mul",i.i32_const(B),I,F),i.call(_+"_add",I,F,F),i.call(_+"_sub",A,F,A),i.call(_+"_add",I,I,C),i.call(_+"_sub",w,o,u),i.call(_+"_add",u,u,u),i.call(_+"_add",w,u,u),i.call(_+"_add",L,s,p),i.call(_+"_add",p,p,p),i.call(_+"_add",L,p,p),i.call(_+"_mul",C,i.i32_const(P),F),i.call(_+"_add",F,r,h),i.call(_+"_add",h,h,h),i.call(_+"_add",F,h,h),i.call(_+"_sub",A,l,f),i.call(_+"_add",f,f,f),i.call(_+"_add",A,f,f),i.call(_+"_sub",b,n,g),i.call(_+"_add",g,g,g),i.call(_+"_add",b,g,g),i.call(_+"_add",y,d,m),i.call(_+"_add",m,m,m),i.call(_+"_add",y,m,m))}(),$(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"),l=i.i32_const(t.alloc(d)),r=i.i32_const(t.alloc(d)),s=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)),h=i.i32_const(t.alloc(d)),p=i.i32_const(t.alloc(d)),m=i.i32_const(t.alloc(d)),w=i.i32_const(t.alloc(d)),L=i.i32_const(t.alloc(d)),b=i.i32_const(t.alloc(d)),y=i.i32_const(t.alloc(d)),A=i.i32_const(t.alloc(d)),C=i.i32_const(t.alloc(d)),I=i.i32_const(t.alloc(d)),F=i.i32_const(t.alloc(d)),x=i.i32_const(t.alloc(d)),E=i.i32_const(t.alloc(d)),v=i.i32_const(t.alloc(d)),S=i.i32_const(t.alloc(d));e.addCode(i.call(a+"__cyclotomicExp_w0",o,l),i.call(T+"_conjugate",l,l),i.call(a+"__cyclotomicSquare",l,r),i.call(a+"__cyclotomicSquare",r,s),i.call(T+"_mul",s,r,u),i.call(a+"__cyclotomicExp_w0",u,g),i.call(T+"_conjugate",g,g),i.call(a+"__cyclotomicSquare",g,f),i.call(a+"__cyclotomicExp_w0",f,h),i.call(T+"_conjugate",h,h),i.call(T+"_conjugate",u,p),i.call(T+"_conjugate",h,m),i.call(T+"_mul",m,g,w),i.call(T+"_mul",w,p,L),i.call(T+"_mul",L,r,b),i.call(T+"_mul",L,g,y),i.call(T+"_mul",y,o,A),i.call(a+"__frobeniusMap1",b,C),i.call(T+"_mul",C,A,I),i.call(a+"__frobeniusMap2",L,F),i.call(T+"_mul",F,I,x),i.call(T+"_conjugate",o,E),i.call(T+"_mul",E,b,v),i.call(a+"__frobeniusMap3",v,S),i.call(T+"_mul",S,x,n))}const K=t.alloc(k),j=t.alloc(R);function H(e){const i=t.addFunction(a+"_pairingEq"+e);for(let t=0;t<e;t++)i.addParam("p_"+t,"i32"),i.addParam("q_"+t,"i32");i.addParam("c","i32"),i.setReturnType("i32");const o=i.getCodeBuilder(),n=o.i32_const(t.alloc(d)),l=o.i32_const(t.alloc(d));i.addCode(o.call(T+"_one",n));for(let t=0;t<e;t++)i.addCode(o.call(a+"_prepareG1",o.getLocal("p_"+t),o.i32_const(K))),i.addCode(o.call(a+"_prepareG2",o.getLocal("q_"+t),o.i32_const(j))),i.addCode(o.call(a+"_millerLoop",o.i32_const(K),o.i32_const(j),l)),i.addCode(o.call(T+"_mul",n,l,n));i.addCode(o.call(a+"_finalExponentiation",n,n)),i.addCode(o.call(T+"_eq",n,o.getLocal("c")))}!function(){const e=t.addFunction(a+"_prepAddStep");e.addParam("pQ","i32"),e.addParam("pR","i32"),e.addParam("pCoef","i32");const i=e.getCodeBuilder(),o=i.getLocal("pQ"),n=i.i32_add(i.getLocal("pQ"),i.i32_const(c)),l=i.getLocal("pR"),r=i.i32_add(i.getLocal("pR"),i.i32_const(c)),s=i.i32_add(i.getLocal("pR"),i.i32_const(2*c)),d=i.getLocal("pCoef"),u=i.i32_add(i.getLocal("pCoef"),i.i32_const(c)),g=i.i32_add(i.getLocal("pCoef"),i.i32_const(2*c)),f=u,h=i.i32_const(t.alloc(c)),p=i.i32_const(t.alloc(c)),m=i.i32_const(t.alloc(c)),w=i.i32_const(t.alloc(c)),L=i.i32_const(t.alloc(c)),b=i.i32_const(t.alloc(c)),y=i.i32_const(t.alloc(c));e.addCode(i.call(_+"_mul",o,s,f),i.call(_+"_sub",l,f,f),i.call(_+"_mul",n,s,h),i.call(_+"_sub",r,h,h),i.call(_+"_square",f,p),i.call(_+"_square",h,m),i.call(_+"_mul",f,p,w),i.call(_+"_mul",l,p,L),i.call(_+"_add",L,L,y),i.call(_+"_mul",s,m,b),i.call(_+"_add",w,b,b),i.call(_+"_sub",b,y,b),i.call(_+"_mul",f,b,l),i.call(_+"_mul",w,r,r),i.call(_+"_sub",L,b,y),i.call(_+"_mul",h,y,y),i.call(_+"_sub",y,r,r),i.call(_+"_mul",s,w,s),i.call(_+"_mul",f,n,y),i.call(_+"_mul",h,o,d),i.call(_+"_sub",d,y,d),i.call(_+"_mul",d,i.i32_const(P),d),i.call(_+"_neg",h,g))}(),function(){const e=t.addFunction(a+"_prepDblStep");e.addParam("pR","i32"),e.addParam("pCoef","i32");const i=e.getCodeBuilder(),o=i.getLocal("pR"),n=i.i32_add(i.getLocal("pR"),i.i32_const(c)),l=i.i32_add(i.getLocal("pR"),i.i32_const(2*c)),r=i.getLocal("pCoef"),s=i.i32_add(i.getLocal("pCoef"),i.i32_const(c)),d=i.i32_add(i.getLocal("pCoef"),i.i32_const(2*c)),u=i.i32_const(t.alloc(c)),g=i.i32_const(t.alloc(c)),f=i.i32_const(t.alloc(c)),h=i.i32_const(t.alloc(c)),p=i.i32_const(t.alloc(c)),m=i.i32_const(t.alloc(c)),w=i.i32_const(t.alloc(c)),L=i.i32_const(t.alloc(c)),b=i.i32_const(t.alloc(c)),y=i.i32_const(t.alloc(c)),A=i.i32_const(t.alloc(c)),C=i.i32_const(t.alloc(c));e.addCode(i.call(_+"_mul",n,i.i32_const(S),u),i.call(_+"_mul",o,u,u),i.call(_+"_square",n,g),i.call(_+"_square",l,f),i.call(_+"_add",f,f,h),i.call(_+"_add",h,f,h),i.call(_+"_mul",i.i32_const(G),h,p),i.call(_+"_add",p,p,m),i.call(_+"_add",p,m,m),i.call(_+"_add",g,m,w),i.call(_+"_mul",w,i.i32_const(S),w),i.call(_+"_add",g,f,C),i.call(_+"_add",n,l,L),i.call(_+"_square",L,L),i.call(_+"_sub",L,C,L),i.call(_+"_sub",p,g,b),i.call(_+"_square",o,y),i.call(_+"_square",p,A),i.call(_+"_sub",g,m,C),i.call(_+"_mul",u,C,o),i.call(_+"_add",A,A,C),i.call(_+"_add",A,C,C),i.call(_+"_square",w,n),i.call(_+"_sub",n,C,n),i.call(_+"_mul",g,L,l),i.call(_+"_mul",i.i32_const(P),b,r),i.call(_+"_neg",L,s),i.call(_+"_add",y,y,d),i.call(_+"_add",y,d,d))}(),function(){const e=t.addFunction(a+"_prepareG1");e.addParam("pP","i32"),e.addParam("ppreP","i32");const i=e.getCodeBuilder();e.addCode(i.call(h+"_normalize",i.getLocal("pP"),i.getLocal("ppreP")))}(),function(){!function(){const e=t.addFunction(a+"_mulByQ");e.addParam("p1","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder(),o=i.getLocal("p1"),n=i.i32_add(i.getLocal("p1"),i.i32_const(c)),l=i.i32_add(i.getLocal("p1"),i.i32_const(2*c)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(c)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*c)),g=i.i32_const(t.alloc([...Vt.bigInt2BytesLE(L("21575463638280843010398324269430826099269044274347216827212613867836435027261"),s),...Vt.bigInt2BytesLE(L("10307601595873709700152284273816112264069230130616436755625194854815875713954"),s)])),f=i.i32_const(t.alloc([...Vt.bigInt2BytesLE(L("2821565182194536844548159561693502659359617185244120367078079554186484126554"),s),...Vt.bigInt2BytesLE(L("3505843767911556378687030309984248845540243509899259641013678093033130930403"),s)]));e.addCode(i.call(_+"_conjugate",o,r),i.call(_+"_mul",g,r,r),i.call(_+"_conjugate",n,d),i.call(_+"_mul",f,d,d),i.call(_+"_conjugate",l,u))}();const e=t.addFunction(a+"_prepareG2");e.addParam("pQ","i32"),e.addParam("ppreQ","i32"),e.addLocal("pCoef","i32"),e.addLocal("i","i32");const i=e.getCodeBuilder(),o=i.getLocal("pQ"),n=t.alloc(3*c),l=i.i32_const(n),r=i.i32_const(n),d=i.i32_const(n+c),u=i.i32_const(n+2*c),g=i.i32_add(i.getLocal("ppreQ"),i.i32_const(0)),f=i.i32_add(i.getLocal("ppreQ"),i.i32_const(c)),h=t.alloc(3*c),p=i.i32_const(h),w=t.alloc(3*c),b=i.i32_const(w),y=i.i32_const(w+c);e.addCode(i.call(m+"_normalize",o,g),i.call(_+"_copy",g,r),i.call(_+"_copy",f,d),i.call(_+"_one",u)),e.addCode(i.setLocal("pCoef",i.i32_add(i.getLocal("ppreQ"),i.i32_const(3*c))),i.setLocal("i",i.i32_const(U.length-2)),i.block(i.loop(i.call(a+"_prepDblStep",l,i.getLocal("pCoef")),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(Q))),i.if(i.i32_load8_s(i.getLocal("i"),z),[...i.call(a+"_prepAddStep",g,l,i.getLocal("pCoef")),...i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(Q)))]),i.br_if(1,i.i32_eqz(i.getLocal("i"))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0)))),e.addCode(i.call(a+"_mulByQ",g,p),i.call(a+"_mulByQ",p,b)),e.addCode(i.call(_+"_neg",y,y),i.call(a+"_prepAddStep",p,l,i.getLocal("pCoef")),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(Q))),i.call(a+"_prepAddStep",b,l,i.getLocal("pCoef")),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(Q))))}(),function(){const e=t.addFunction(a+"__mulBy024");e.addParam("pEll0","i32"),e.addParam("pEllVW","i32"),e.addParam("pEllVV","i32"),e.addParam("pR","i32");const i=e.getCodeBuilder(),o=i.getLocal("pEll0"),n=i.getLocal("pEllVV"),r=i.getLocal("pEllVW"),s=i.getLocal("pR"),d=i.i32_add(i.getLocal("pR"),i.i32_const(2*l)),u=i.i32_add(i.getLocal("pR"),i.i32_const(4*l)),g=i.i32_add(i.getLocal("pR"),i.i32_const(6*l)),f=i.i32_add(i.getLocal("pR"),i.i32_const(8*l)),h=i.i32_add(i.getLocal("pR"),i.i32_const(10*l)),p=i.i32_const(t.alloc(c)),m=i.i32_const(t.alloc(c)),w=i.i32_const(t.alloc(c)),L=i.i32_const(t.alloc(c)),b=i.i32_const(t.alloc(c)),y=i.i32_const(t.alloc(c)),A=i.i32_const(t.alloc(c)),C=i.i32_const(t.alloc(c)),I=i.i32_const(t.alloc(c)),F=i.i32_const(t.alloc(c)),x=i.i32_const(t.alloc(c));e.addCode(i.call(_+"_mul",s,o,A),i.call(_+"_mul",u,n,C),i.call(_+"_mul",f,r,I),i.call(_+"_add",s,f,w),i.call(_+"_add",s,u,m),i.call(_+"_add",d,g,L),i.call(_+"_add",L,h,L),i.call(_+"_mul",d,n,F),i.call(_+"_add",F,I,b),i.call(_+"_mul",i.i32_const(B),b,y),i.call(_+"_add",y,A,s),i.call(_+"_mul",h,r,b),i.call(_+"_add",F,b,F),i.call(_+"_add",b,C,b),i.call(_+"_mul",i.i32_const(B),b,y),i.call(_+"_mul",d,o,b),i.call(_+"_add",F,b,F),i.call(_+"_add",y,b,d),i.call(_+"_add",o,n,p),i.call(_+"_mul",m,p,b),i.call(_+"_add",A,C,x),i.call(_+"_sub",b,x,b),i.call(_+"_mul",g,r,y),i.call(_+"_add",F,y,F),i.call(_+"_add",u,f,p),i.call(_+"_add",b,y,u),i.call(_+"_add",n,r,m),i.call(_+"_mul",m,p,b),i.call(_+"_add",C,I,x),i.call(_+"_sub",b,x,b),i.call(_+"_mul",i.i32_const(B),b,y),i.call(_+"_mul",g,o,b),i.call(_+"_add",F,b,F),i.call(_+"_add",y,b,g),i.call(_+"_mul",h,n,b),i.call(_+"_add",F,b,F),i.call(_+"_mul",i.i32_const(B),b,y),i.call(_+"_add",o,r,p),i.call(_+"_mul",w,p,b),i.call(_+"_add",A,I,x),i.call(_+"_sub",b,x,b),i.call(_+"_add",y,b,f),i.call(_+"_add",o,n,p),i.call(_+"_add",p,r,p),i.call(_+"_mul",L,p,b),i.call(_+"_sub",b,F,h))}(),function(){const e=t.addFunction(a+"__mulBy024Old");e.addParam("pEll0","i32"),e.addParam("pEllVW","i32"),e.addParam("pEllVV","i32"),e.addParam("pR","i32");const i=e.getCodeBuilder(),o=i.getLocal("pEll0"),n=i.getLocal("pEllVV"),l=i.getLocal("pEllVW"),r=i.getLocal("pR"),s=t.alloc(d),u=i.i32_const(s),g=i.i32_const(s),f=i.i32_const(s+c),h=i.i32_const(s+2*c),p=i.i32_const(s+3*c),m=i.i32_const(s+4*c),w=i.i32_const(s+5*c);e.addCode(i.call(_+"_copy",o,g),i.call(_+"_zero",f),i.call(_+"_copy",n,h),i.call(_+"_zero",p),i.call(_+"_copy",l,m),i.call(_+"_zero",w),i.call(T+"_mul",u,r,r))}(),function(){const e=t.addFunction(a+"_millerLoop");e.addParam("ppreP","i32"),e.addParam("ppreQ","i32"),e.addParam("r","i32"),e.addLocal("pCoef","i32"),e.addLocal("i","i32");const i=e.getCodeBuilder(),o=i.getLocal("ppreP"),n=i.i32_add(i.getLocal("ppreP"),i.i32_const(s)),l=i.getLocal("pCoef"),r=i.i32_add(i.getLocal("pCoef"),i.i32_const(c)),d=i.i32_add(i.getLocal("pCoef"),i.i32_const(2*c)),u=t.alloc(c),g=i.i32_const(u),f=t.alloc(c),h=i.i32_const(f),p=i.getLocal("r");e.addCode(i.call(T+"_one",p),i.setLocal("pCoef",i.i32_add(i.getLocal("ppreQ"),i.i32_const(3*c))),i.setLocal("i",i.i32_const(U.length-2)),i.block(i.loop(i.call(T+"_square",p,p),i.call(_+"_mul1",r,n,g),i.call(_+"_mul1",d,o,h),i.call(a+"__mulBy024",l,g,h,p),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(Q))),i.if(i.i32_load8_s(i.getLocal("i"),z),[...i.call(_+"_mul1",r,n,g),...i.call(_+"_mul1",d,o,h),...i.call(a+"__mulBy024",l,g,h,p),...i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(Q)))]),i.br_if(1,i.i32_eqz(i.getLocal("i"))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0)))),e.addCode(i.call(_+"_mul1",r,n,g),i.call(_+"_mul1",d,o,h),i.call(a+"__mulBy024",l,g,h,p),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(Q))),i.call(_+"_mul1",r,n,g),i.call(_+"_mul1",d,o,h),i.call(a+"__mulBy024",l,g,h,p),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(Q))))}();for(let e=0;e<10;e++)N(e),t.exportFunction(a+"__frobeniusMap"+e);!function(){const e=t.addFunction(a+"_finalExponentiationOld");e.addParam("x","i32"),e.addParam("r","i32");const i=t.alloc(Vt.bigInt2BytesLE(552484233613224096312617126783173147097382103762957654188882734314196910839907541213974502761540629817009608548654680343627701153829446747810907373256841551006201639677726139946029199968412598804882391702273019083653272047566316584365559776493027495458238373902875937659943504873220554161550525926302303331747463515644711876653177129578303191095900909191624817826566688241804408081892785725967931714097716709526092261278071952560171111444072049229123565057483750161460024353346284167282452756217662335528813519139808291170539072125381230815729071544861602750936964829313608137325426383735122175229541155376346436093930287402089517426973178917569713384748081827255472576937471496195752727188261435633271238710131736096299798168852925540549342330775279877006784354801422249722573783561685179618816480037695005515426162362431072245638324744480n,352)),o=e.getCodeBuilder();e.addCode(o.call(T+"_exp",o.getLocal("x"),o.i32_const(i),o.i32_const(352),o.getLocal("r")))}(),function(){!function(){const e=t.addFunction(a+"__finalExponentiationFirstChunk");e.addParam("x","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("x"),n=o,r=i.i32_add(o,i.i32_const(6*l)),s=i.getLocal("r"),c=t.alloc(d),u=i.i32_const(c),g=u,f=i.i32_const(c+6*l),h=i.i32_const(t.alloc(d)),_=i.i32_const(t.alloc(d)),p=i.i32_const(t.alloc(d));e.addCode(i.call(O+"_copy",n,g),i.call(O+"_neg",r,f),i.call(T+"_inverse",o,h),i.call(T+"_mul",u,h,_),i.call(a+"__frobeniusMap2",_,p),i.call(T+"_mul",_,p,s))}(),V();const e=t.addFunction(a+"_finalExponentiation");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));e.addCode(i.call(a+"__finalExponentiationFirstChunk",o,r),i.call(a+"__finalExponentiationLastChunk",r,n))}();for(let e=1;e<=5;e++)H(e),t.exportFunction(a+"_pairingEq"+e);!function(){const e=t.addFunction(a+"_pairing");e.addParam("p","i32"),e.addParam("q","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.i32_const(t.alloc(d));e.addCode(i.call(a+"_prepareG1",i.getLocal("p"),i.i32_const(K))),e.addCode(i.call(a+"_prepareG2",i.getLocal("q"),i.i32_const(j))),e.addCode(i.call(a+"_millerLoop",i.i32_const(K),i.i32_const(j),o)),e.addCode(i.call(a+"_finalExponentiation",o,i.getLocal("r")))}(),t.exportFunction(a+"_pairing"),t.exportFunction(a+"_prepareG1"),t.exportFunction(a+"_prepareG2"),t.exportFunction(a+"_millerLoop"),t.exportFunction(a+"_finalExponentiation"),t.exportFunction(a+"_finalExponentiationOld"),t.exportFunction(a+"__mulBy024"),t.exportFunction(a+"__mulBy024Old"),t.exportFunction(a+"__cyclotomicSquare"),t.exportFunction(a+"__cyclotomicExp_w0")},Le=function(t,e){const a=e||"bls12381";if(t.modules[a])return a;const i=0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaabn,o=0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001n,n=Math.floor((_e(i-1n)-1)/64)+1,l=8*n,r=l,s=2*r,c=12*r,d=Math.floor((_e(o-1n)-1)/64)+1,u=8*d,g=u,f=t.alloc(ne.bigInt2BytesLE(o,g)),h=le(t,i,"f1m","intq");re(t,o,"fr","frm","intr");const _=t.alloc(ne.bigInt2BytesLE(y(4n),r)),p=de(t,"g1m","f1m",_);ue(t,"frm","frm","frm","frm_mul"),ge(t,"pol","frm"),fe(t,"qap","frm");const m=se(t,"f1m_neg","f2m","f1m"),w=t.alloc([...ne.bigInt2BytesLE(y(4n),r),...ne.bigInt2BytesLE(y(4n),r)]),L=de(t,"g2m","f2m",w);function b(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(u));i.addCode(o.call("frm_fromMontgomery",o.getLocal("pFr"),n),o.call(a,o.getLocal("pG"),n,o.i32_const(u),o.getLocal("pr"))),t.exportFunction(e)}function y(t){return BigInt(t)*(1n<<BigInt(8*r))%i}b("g1m_timesFr","g1m_timesScalar"),ue(t,"g1m","g1m","frm","g1m_timesFr"),b("g2m_timesFr","g2m_timesScalar"),ue(t,"g2m","g2m","frm","g2m_timesFr"),b("g1m_timesFrAffine","g1m_timesScalarAffine"),b("g2m_timesFrAffine","g2m_timesScalarAffine"),he(t,"frm_batchApplyKey","fmr","frm",u,u,u,"frm_mul"),he(t,"g1m_batchApplyKey","g1m","frm",3*l,3*l,u,"g1m_timesFr"),he(t,"g1m_batchApplyKeyMixed","g1m","frm",2*l,3*l,u,"g1m_timesFrAffine"),he(t,"g2m_batchApplyKey","g2m","frm",2*l*3,3*l*2,u,"g2m_timesFr"),he(t,"g2m_batchApplyKeyMixed","g2m","frm",2*l*2,3*l*2,u,"g2m_timesFrAffine");const A=[3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507n,1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569n,1n],C=t.alloc([...ne.bigInt2BytesLE(y(A[0]),r),...ne.bigInt2BytesLE(y(A[1]),r),...ne.bigInt2BytesLE(y(A[2]),r)]),I=[0n,1n,0n],F=t.alloc([...ne.bigInt2BytesLE(y(I[0]),r),...ne.bigInt2BytesLE(y(I[1]),r),...ne.bigInt2BytesLE(y(I[2]),r)]),x=[[352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160n,3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758n],[1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905n,927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582n],[1n,0n]],E=t.alloc([...ne.bigInt2BytesLE(y(x[0][0]),r),...ne.bigInt2BytesLE(y(x[0][1]),r),...ne.bigInt2BytesLE(y(x[1][0]),r),...ne.bigInt2BytesLE(y(x[1][1]),r),...ne.bigInt2BytesLE(y(x[2][0]),r),...ne.bigInt2BytesLE(y(x[2][1]),r)]),v=[[0n,0n],[1n,0n],[0n,0n]],B=t.alloc([...ne.bigInt2BytesLE(y(v[0][0]),r),...ne.bigInt2BytesLE(y(v[0][1]),r),...ne.bigInt2BytesLE(y(v[1][0]),r),...ne.bigInt2BytesLE(y(v[1][1]),r),...ne.bigInt2BytesLE(y(v[2][0]),r),...ne.bigInt2BytesLE(y(v[2][1]),r)]),S=t.alloc([...ne.bigInt2BytesLE(y(1n),r),...ne.bigInt2BytesLE(y(0n),r),...ne.bigInt2BytesLE(y(0n),r),...ne.bigInt2BytesLE(y(0n),r),...ne.bigInt2BytesLE(y(0n),r),...ne.bigInt2BytesLE(y(0n),r),...ne.bigInt2BytesLE(y(0n),r),...ne.bigInt2BytesLE(y(0n),r),...ne.bigInt2BytesLE(y(0n),r),...ne.bigInt2BytesLE(y(0n),r),...ne.bigInt2BytesLE(y(0n),r),...ne.bigInt2BytesLE(y(0n),r)]),P=t.alloc([...ne.bigInt2BytesLE(y(1n),r),...ne.bigInt2BytesLE(y(1n),r)]);!function(){const e=t.addFunction(m+"_mulNR");e.addParam("x","i32"),e.addParam("pr","i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(r)),o=a.getLocal("x"),n=a.i32_add(a.getLocal("x"),a.i32_const(r)),l=a.getLocal("pr"),s=a.i32_add(a.getLocal("pr"),a.i32_const(r));e.addCode(a.call(h+"_copy",o,i),a.call(h+"_sub",o,n,l),a.call(h+"_add",i,n,s))}();const G=ce(t,m+"_mulNR","f6m","f2m");!function(){const e=t.addFunction(G+"_mulNR");e.addParam("x","i32"),e.addParam("pr","i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(2*r));e.addCode(a.call(m+"_copy",a.getLocal("x"),i),a.call(m+"_mulNR",a.i32_add(a.getLocal("x"),a.i32_const(4*l)),a.getLocal("pr")),a.call(m+"_copy",a.i32_add(a.getLocal("x"),a.i32_const(2*l)),a.i32_add(a.getLocal("pr"),a.i32_const(4*l))),a.call(m+"_copy",i,a.i32_add(a.getLocal("pr"),a.i32_const(2*l))))}();const O=se(t,G+"_mulNR","ftm",G),T=function(t){let e=t;const a=[];for(;e>0n;)pe(e)?a.push(1):a.push(0),e>>=1n;return a}(0xd201000000010000n),U=t.alloc(T),z=3*s,Q=T.length-1,q=T.reduce(((t,e)=>t+(0!=e?1:0)),0),M=6*l,k=3*l*2+(q+Q+1)*z,R=15132376222941642752n;function D(e){const a=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760n,151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351n,0n],[2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530n,1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n,0n],[3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557n,877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230n],[4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559786n,0n],[151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027n,3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n,0n],[1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257n,2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437n,0n],[877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230n,3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557n]]],o=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[0n,4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n,0n],[0n,1n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n,0n],[0n,793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n]],[[1n,0n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437n,0n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n,0n],[4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559786n,0n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n,0n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351n,0n]]],n=t.addFunction(O+"_frobeniusMap"+e);n.addParam("x","i32"),n.addParam("r","i32");const c=n.getCodeBuilder();for(let i=0;i<6;i++){const u=0==i?c.getLocal("x"):c.i32_add(c.getLocal("x"),c.i32_const(i*s)),g=u,f=c.i32_add(c.getLocal("x"),c.i32_const(i*s+r)),_=0==i?c.getLocal("r"):c.i32_add(c.getLocal("r"),c.i32_const(i*s)),p=_,w=c.i32_add(c.getLocal("r"),c.i32_const(i*s+r)),L=d(a[Math.floor(i/3)][e%12],o[i%3][e%6]),b=t.alloc([...ne.bigInt2BytesLE(y(L[0]),l),...ne.bigInt2BytesLE(y(L[1]),l)]);e%2==1?n.addCode(c.call(h+"_copy",g,p),c.call(h+"_neg",f,w),c.call(m+"_mul",_,c.i32_const(b),_)):n.addCode(c.call(m+"_mul",u,c.i32_const(b),_))}function d(t,e){const a=t[0],o=t[1],n=e[0],l=e[1],r=[(a*n-o*l)%i,(a*l+o*n)%i];return me(r[0])&&(r[0]=r[0]+i),r}}function N(e,i,o){const n=function(t){let e=t;const a=[];for(;e>0n;){if(pe(e)){const t=2-Number(e%4n);a.push(t),e-=BigInt(t)}else a.push(0);e>>=1n}return a}(e).map((t=>-1==t?255:t)),l=t.alloc(n),r=t.addFunction(a+"__cyclotomicExp_"+o);r.addParam("x","i32"),r.addParam("r","i32"),r.addLocal("bit","i32"),r.addLocal("i","i32");const s=r.getCodeBuilder(),d=s.getLocal("x"),u=s.getLocal("r"),g=s.i32_const(t.alloc(c));r.addCode(s.call(O+"_conjugate",d,g),s.call(O+"_one",u),s.if(s.teeLocal("bit",s.i32_load8_s(s.i32_const(n.length-1),l)),s.if(s.i32_eq(s.getLocal("bit"),s.i32_const(1)),s.call(O+"_mul",u,d,u),s.call(O+"_mul",u,g,u))),s.setLocal("i",s.i32_const(n.length-2)),s.block(s.loop(s.call(a+"__cyclotomicSquare",u,u),s.if(s.teeLocal("bit",s.i32_load8_s(s.getLocal("i"),l)),s.if(s.i32_eq(s.getLocal("bit"),s.i32_const(1)),s.call(O+"_mul",u,d,u),s.call(O+"_mul",u,g,u))),s.br_if(1,s.i32_eqz(s.getLocal("i"))),s.setLocal("i",s.i32_sub(s.getLocal("i"),s.i32_const(1))),s.br(0)))),i&&r.addCode(s.call(O+"_conjugate",u,u))}t.modules[a]={n64q:n,n64r:d,n8q:l,n8r:u,pG1gen:C,pG1zero:F,pG1b:_,pG2gen:E,pG2zero:B,pG2b:w,pq:t.modules.f1m.pq,pr:f,pOneT:S,r:o,q:i,prePSize:M,preQSize:k},function(){const e=t.addFunction(G+"_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*r)),n=a.i32_add(a.getLocal("pA"),a.i32_const(4*r)),l=a.getLocal("pC1"),s=a.getLocal("pR"),c=a.i32_add(a.getLocal("pR"),a.i32_const(2*r)),d=a.i32_add(a.getLocal("pR"),a.i32_const(4*r)),u=a.i32_const(t.alloc(2*r)),g=a.i32_const(t.alloc(2*r));e.addCode(a.call(m+"_add",i,o,u),a.call(m+"_add",o,n,g),a.call(m+"_mul",o,l,d),a.call(m+"_mul",g,l,s),a.call(m+"_sub",s,d,s),a.call(m+"_mulNR",s,s),a.call(m+"_mul",u,l,c),a.call(m+"_sub",c,d,c))}(),function(){const e=t.addFunction(G+"_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*r)),n=a.i32_add(a.getLocal("pA"),a.i32_const(4*r)),l=a.getLocal("pC0"),s=a.getLocal("pC1"),c=a.getLocal("pR"),d=a.i32_add(a.getLocal("pR"),a.i32_const(2*r)),u=a.i32_add(a.getLocal("pR"),a.i32_const(4*r)),g=a.i32_const(t.alloc(2*r)),f=a.i32_const(t.alloc(2*r)),h=a.i32_const(t.alloc(2*r)),_=a.i32_const(t.alloc(2*r));e.addCode(a.call(m+"_mul",i,l,g),a.call(m+"_mul",o,s,f),a.call(m+"_add",i,o,h),a.call(m+"_add",i,n,_),a.call(m+"_add",o,n,c),a.call(m+"_mul",c,s,c),a.call(m+"_sub",c,f,c),a.call(m+"_mulNR",c,c),a.call(m+"_add",c,g,c),a.call(m+"_add",l,s,d),a.call(m+"_mul",d,h,d),a.call(m+"_sub",d,g,d),a.call(m+"_sub",d,f,d),a.call(m+"_mul",_,l,u),a.call(m+"_sub",u,g,u),a.call(m+"_add",u,f,u))}(),function(){const e=t.addFunction(O+"_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*r)),n=a.getLocal("pC0"),l=a.getLocal("pC1"),s=a.getLocal("pC4"),c=a.i32_const(t.alloc(6*r)),d=a.i32_const(t.alloc(6*r)),u=a.i32_const(t.alloc(2*r)),g=a.getLocal("pR"),f=a.i32_add(a.getLocal("pR"),a.i32_const(6*r));e.addCode(a.call(G+"_mul01",i,n,l,c),a.call(G+"_mul1",o,s,d),a.call(m+"_add",l,s,u),a.call(G+"_add",o,i,f),a.call(G+"_mul01",f,n,u,f),a.call(G+"_sub",f,c,f),a.call(G+"_sub",f,d,f),a.call(G+"_copy",d,g),a.call(G+"_mulNR",g,g),a.call(G+"_add",g,c,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(l)),s=i.getLocal("pF"),c=i.getLocal("pCoefs"),d=i.i32_add(i.getLocal("pCoefs"),i.i32_const(r)),u=i.i32_add(i.getLocal("pCoefs"),i.i32_const(2*r)),g=i.i32_add(i.getLocal("pCoefs"),i.i32_const(3*r)),f=i.i32_add(i.getLocal("pCoefs"),i.i32_const(4*r)),_=t.alloc(2*r),p=i.i32_const(_),m=i.i32_const(_),w=i.i32_const(_+r),L=t.alloc(2*r),b=i.i32_const(L),y=i.i32_const(L),A=i.i32_const(L+r);e.addCode(i.call(h+"_mul",c,n,m),i.call(h+"_mul",d,n,w),i.call(h+"_mul",u,o,y),i.call(h+"_mul",g,o,A),i.call(O+"_mul014",s,f,b,p,s))}();const $=t.alloc(M),V=t.alloc(k);function K(e){const i=t.addFunction(a+"_pairingEq"+e);for(let t=0;t<e;t++)i.addParam("p_"+t,"i32"),i.addParam("q_"+t,"i32");i.addParam("c","i32"),i.setReturnType("i32");const o=i.getCodeBuilder(),n=o.i32_const(t.alloc(c)),l=o.i32_const(t.alloc(c));i.addCode(o.call(O+"_one",n));for(let t=0;t<e;t++)i.addCode(o.call(a+"_prepareG1",o.getLocal("p_"+t),o.i32_const($))),i.addCode(o.call(a+"_prepareG2",o.getLocal("q_"+t),o.i32_const(V))),i.addCode(o.if(o.i32_eqz(o.call(p+"_inGroupAffine",o.i32_const($))),o.ret(o.i32_const(0))),o.if(o.i32_eqz(o.call(L+"_inGroupAffine",o.i32_const(V))),o.ret(o.i32_const(0)))),i.addCode(o.call(a+"_millerLoop",o.i32_const($),o.i32_const(V),l)),i.addCode(o.call(O+"_mul",n,l,n));i.addCode(o.call(a+"_finalExponentiation",n,n)),i.addCode(o.call(O+"_eq",n,o.getLocal("c")))}for(let e=0;e<10;e++)D(e),t.exportFunction(O+"_frobeniusMap"+e);!function(){const e=t.addFunction(p+"_inGroupAffine");e.addParam("p","i32"),e.setReturnType("i32");const a=e.getCodeBuilder(),i=(R*R-1n)/3n,o=a.i32_const(t.alloc(ne.bigInt2BytesLE(y(4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n),l))),n=a.i32_const(t.alloc(ne.bigInt2BytesLE(y(793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n),l))),s=a.i32_const(t.alloc(ne.bigInt2BytesLE(i,16))),c=a.getLocal("p"),d=a.i32_add(a.getLocal("p"),a.i32_const(r)),u=t.alloc(3*r),g=a.i32_const(u),f=a.i32_const(u),_=a.i32_const(u+r),m=t.alloc(2*r),w=a.i32_const(m),L=a.i32_const(m),b=a.i32_const(m+r);e.addCode(a.if(a.call(p+"_isZeroAffine",a.getLocal("p")),a.ret(a.i32_const(1))),a.if(a.i32_eqz(a.call(p+"_inCurveAffine",a.getLocal("p"))),a.ret(a.i32_const(0))),a.call(h+"_mul",c,o,f),a.call(h+"_copy",d,_),a.call(h+"_mul",c,n,L),a.call(h+"_copy",d,b),a.call(p+"_doubleAffine",g,g),a.call(p+"_subMixed",g,a.getLocal("p"),g),a.call(p+"_subMixed",g,w,g),a.call(p+"_timesScalar",g,s,a.i32_const(16),g),a.ret(a.call(p+"_eqMixed",g,w)));const A=t.addFunction(p+"_inGroup");A.addParam("pIn","i32"),A.setReturnType("i32");const C=A.getCodeBuilder(),I=C.i32_const(t.alloc(2*r));A.addCode(C.call(p+"_toAffine",C.getLocal("pIn"),I),C.ret(C.call(p+"_inGroupAffine",I)))}(),function(){const e=t.addFunction(L+"_inGroupAffine");e.addParam("p","i32"),e.setReturnType("i32");const a=e.getCodeBuilder(),i=[2001204777610833696708894912867952078278441409969503942666029068062015825245418932221343814564507832018947136279894n,2001204777610833696708894912867952078278441409969503942666029068062015825245418932221343814564507832018947136279893n],o=[2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530n,2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530n],n=a.i32_const(t.alloc([...ne.bigInt2BytesLE(y(i[0]),l),...ne.bigInt2BytesLE(y(i[1]),l)])),c=a.i32_const(t.alloc(ne.bigInt2BytesLE(y(4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n),l))),d=a.i32_const(t.alloc([...ne.bigInt2BytesLE(y(o[0]),l),...ne.bigInt2BytesLE(y(o[1]),l)])),u=a.i32_const(t.alloc(ne.bigInt2BytesLE(R,8))),g=a.getLocal("p"),f=a.i32_add(a.getLocal("p"),a.i32_const(s)),_=a.i32_const(t.alloc(r)),p=a.i32_const(t.alloc(s)),w=a.i32_const(t.alloc(s)),b=t.alloc(2*s),A=a.i32_const(b),C=a.i32_const(b),I=a.i32_const(b),F=a.i32_const(b+r),x=a.i32_const(b+s),E=a.i32_const(b+s),v=a.i32_const(b+s+r),B=t.alloc(3*s),S=a.i32_const(B),P=a.i32_const(B),G=a.i32_const(B),O=a.i32_const(B+r),T=a.i32_const(B+s),U=a.i32_const(B+s),z=a.i32_const(B+s+r),Q=a.i32_const(B+2*s);e.addCode(a.if(a.call(L+"_isZeroAffine",a.getLocal("p")),a.ret(a.i32_const(1))),a.if(a.i32_eqz(a.call(L+"_inCurveAffine",a.getLocal("p"))),a.ret(a.i32_const(0))),a.call(m+"_mul",g,n,p),a.call(m+"_mul",f,n,w),a.call(m+"_mul1",p,c,C),a.call(m+"_neg",w,x),a.call(m+"_neg",p,P),a.call(m+"_mul",w,d,T),a.call(h+"_sub",I,F,_),a.call(h+"_add",I,F,F),a.call(h+"_copy",_,I),a.call(h+"_sub",E,v,_),a.call(h+"_add",E,v,v),a.call(h+"_copy",_,E),a.call(h+"_add",G,O,_),a.call(h+"_sub",G,O,O),a.call(h+"_copy",_,G),a.call(h+"_sub",z,U,_),a.call(h+"_add",U,z,z),a.call(h+"_copy",_,U),a.call(m+"_one",Q),a.call(L+"_timesScalar",S,u,a.i32_const(8),S),a.call(L+"_addMixed",S,A,S),a.ret(a.call(L+"_eqMixed",S,a.getLocal("p"))));const q=t.addFunction(L+"_inGroup");q.addParam("pIn","i32"),q.setReturnType("i32");const M=q.getCodeBuilder(),k=M.i32_const(t.alloc(2*s));q.addCode(M.call(L+"_toAffine",M.getLocal("pIn"),k),M.ret(M.call(L+"_inGroupAffine",k)))}(),function(){const e=t.addFunction(a+"_prepAddStep");e.addParam("R","i32"),e.addParam("Q","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("R"),n=i.i32_add(i.getLocal("R"),i.i32_const(2*l)),r=i.i32_add(i.getLocal("R"),i.i32_const(4*l)),c=i.getLocal("Q"),d=i.i32_add(i.getLocal("Q"),i.i32_const(2*l)),u=i.getLocal("r"),g=i.i32_add(i.getLocal("r"),i.i32_const(2*l)),f=i.i32_add(i.getLocal("r"),i.i32_const(4*l)),h=i.i32_const(t.alloc(s)),_=i.i32_const(t.alloc(s)),p=i.i32_const(t.alloc(s)),w=i.i32_const(t.alloc(s)),L=i.i32_const(t.alloc(s)),b=i.i32_const(t.alloc(s)),y=i.i32_const(t.alloc(s)),A=i.i32_const(t.alloc(s)),C=i.i32_const(t.alloc(s)),I=i.i32_const(t.alloc(s)),F=i.i32_const(t.alloc(s));e.addCode(i.call(m+"_square",r,h),i.call(m+"_square",d,_),i.call(m+"_mul",h,c,w),i.call(m+"_add",d,r,g),i.call(m+"_square",g,g),i.call(m+"_sub",g,_,g),i.call(m+"_sub",g,h,g),i.call(m+"_mul",g,h,g),i.call(m+"_sub",w,o,L),i.call(m+"_square",L,b),i.call(m+"_add",b,b,y),i.call(m+"_add",y,y,y),i.call(m+"_mul",y,L,A),i.call(m+"_sub",g,n,C),i.call(m+"_sub",C,n,C),i.call(m+"_mul",C,c,f),i.call(m+"_mul",y,o,I),i.call(m+"_square",C,o),i.call(m+"_sub",o,A,o),i.call(m+"_sub",o,I,o),i.call(m+"_sub",o,I,o),i.call(m+"_add",r,L,r),i.call(m+"_square",r,r),i.call(m+"_sub",r,h,r),i.call(m+"_sub",r,b,r),i.call(m+"_add",d,r,u),i.call(m+"_sub",I,o,F),i.call(m+"_mul",F,C,F),i.call(m+"_mul",n,A,w),i.call(m+"_add",w,w,w),i.call(m+"_sub",F,w,n),i.call(m+"_square",u,u),i.call(m+"_sub",u,_,u),i.call(m+"_square",r,p),i.call(m+"_sub",u,p,u),i.call(m+"_add",f,f,f),i.call(m+"_sub",f,u,f),i.call(m+"_add",r,r,u),i.call(m+"_neg",C,C),i.call(m+"_add",C,C,g))}(),function(){const e=t.addFunction(a+"_prepDblStep");e.addParam("R","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("R"),n=i.i32_add(i.getLocal("R"),i.i32_const(2*l)),r=i.i32_add(i.getLocal("R"),i.i32_const(4*l)),c=i.getLocal("r"),d=i.i32_add(i.getLocal("r"),i.i32_const(2*l)),u=i.i32_add(i.getLocal("r"),i.i32_const(4*l)),g=i.i32_const(t.alloc(s)),f=i.i32_const(t.alloc(s)),h=i.i32_const(t.alloc(s)),_=i.i32_const(t.alloc(s)),p=i.i32_const(t.alloc(s));e.addCode(i.call(m+"_square",o,c),i.call(m+"_square",n,f),i.call(m+"_square",f,h),i.call(m+"_add",f,o,d),i.call(m+"_square",d,d),i.call(m+"_sub",d,c,d),i.call(m+"_sub",d,h,d),i.call(m+"_add",d,d,d),i.call(m+"_add",c,c,_),i.call(m+"_add",_,c,_),i.call(m+"_add",o,_,u),i.call(m+"_square",_,p),i.call(m+"_square",r,g),i.call(m+"_sub",p,d,o),i.call(m+"_sub",o,d,o),i.call(m+"_add",r,n,r),i.call(m+"_square",r,r),i.call(m+"_sub",r,f,r),i.call(m+"_sub",r,g,r),i.call(m+"_sub",d,o,n),i.call(m+"_mul",n,_,n),i.call(m+"_add",h,h,h),i.call(m+"_add",h,h,h),i.call(m+"_add",h,h,h),i.call(m+"_sub",n,h,n),i.call(m+"_mul",_,g,d),i.call(m+"_add",d,d,d),i.call(m+"_neg",d,d),i.call(m+"_square",u,u),i.call(m+"_sub",u,c,u),i.call(m+"_sub",u,p,u),i.call(m+"_add",f,f,f),i.call(m+"_add",f,f,f),i.call(m+"_sub",u,f,u),i.call(m+"_mul",r,g,c),i.call(m+"_add",c,c,c))}(),function(){const e=t.addFunction(a+"_prepareG1");e.addParam("pP","i32"),e.addParam("ppreP","i32");const i=e.getCodeBuilder();e.addCode(i.call(p+"_normalize",i.getLocal("pP"),i.getLocal("ppreP")))}(),function(){const e=t.addFunction(a+"_prepareG2");e.addParam("pQ","i32"),e.addParam("ppreQ","i32"),e.addLocal("pCoef","i32"),e.addLocal("i","i32");const i=e.getCodeBuilder(),o=i.getLocal("pQ"),n=t.alloc(3*s),l=i.i32_const(n),r=i.getLocal("ppreQ");e.addCode(i.call(L+"_normalize",o,r),i.if(i.call(L+"_isZero",r),i.ret([])),i.call(L+"_copy",r,l),i.setLocal("pCoef",i.i32_add(i.getLocal("ppreQ"),i.i32_const(3*s)))),e.addCode(i.setLocal("i",i.i32_const(T.length-2)),i.block(i.loop(i.call(a+"_prepDblStep",l,i.getLocal("pCoef")),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(z))),i.if(i.i32_load8_s(i.getLocal("i"),U),[...i.call(a+"_prepAddStep",l,r,i.getLocal("pCoef")),...i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(z)))]),i.br_if(1,i.i32_eqz(i.getLocal("i"))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0))))}(),function(){const e=t.addFunction(a+"_millerLoop");e.addParam("ppreP","i32"),e.addParam("ppreQ","i32"),e.addParam("r","i32"),e.addLocal("pCoef","i32"),e.addLocal("i","i32");const i=e.getCodeBuilder(),o=i.getLocal("ppreP"),n=i.getLocal("pCoef"),l=i.getLocal("r");e.addCode(i.call(O+"_one",l),i.if(i.call(p+"_isZero",o),i.ret([])),i.if(i.call(p+"_isZero",i.getLocal("ppreQ")),i.ret([])),i.setLocal("pCoef",i.i32_add(i.getLocal("ppreQ"),i.i32_const(3*s))),i.setLocal("i",i.i32_const(T.length-2)),i.block(i.loop(i.call(a+"_ell",o,n,l),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(z))),i.if(i.i32_load8_s(i.getLocal("i"),U),[...i.call(a+"_ell",o,n,l),...i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(z)))]),i.call(O+"_square",l,l),i.br_if(1,i.i32_eq(i.getLocal("i"),i.i32_const(1))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0))),i.call(a+"_ell",o,n,l)),e.addCode(i.call(O+"_conjugate",l,l))}(),function(){const e=t.addFunction(a+"_finalExponentiationOld");e.addParam("x","i32"),e.addParam("r","i32");const i=t.alloc(ne.bigInt2BytesLE(322277361516934140462891564586510139908379969514828494218366688025288661041104682794998680497580008899973249814104447692778988208376779573819485263026159588510513834876303014016798809919343532899164848730280942609956670917565618115867287399623286813270357901731510188149934363360381614501334086825442271920079363289954510565375378443704372994881406797882676971082200626541916413184642520269678897559532260949334760604962086348898118982248842634379637598665468817769075878555493752214492790122785850202957575200176084204422751485957336465472324810982833638490904279282696134323072515220044451592646885410572234451732790590013479358343841220074174848221722017083597872017638514103174122784843925578370430843522959600095676285723737049438346544753168912974976791528535276317256904336520179281145394686565050419250614107803233314658825463117900250701199181529205942363159325765991819433914303908860460720581408201373164047773794825411011922305820065611121544561808414055302212057471395719432072209245600258134364584636810093520285711072578721435517884103526483832733289802426157301542744476740008494780363354305116978805620671467071400711358839553375340724899735460480144599782014906586543813292157922220645089192130209334926661588737007768565838519456601560804957985667880395221049249803753582637708560n,544)),o=e.getCodeBuilder();e.addCode(o.call(O+"_exp",o.getLocal("x"),o.i32_const(i),o.i32_const(544),o.getLocal("r")))}(),function(){!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)),l=i.i32_add(i.getLocal("x"),i.i32_const(2*s)),r=i.i32_add(i.getLocal("x"),i.i32_const(3*s)),c=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)),h=i.i32_add(i.getLocal("r"),i.i32_const(3*s)),_=i.i32_add(i.getLocal("r"),i.i32_const(4*s)),p=i.i32_add(i.getLocal("r"),i.i32_const(5*s)),w=i.i32_const(t.alloc(s)),L=i.i32_const(t.alloc(s)),b=i.i32_const(t.alloc(s)),y=i.i32_const(t.alloc(s)),A=i.i32_const(t.alloc(s)),C=i.i32_const(t.alloc(s)),I=i.i32_const(t.alloc(s)),F=i.i32_const(t.alloc(s));e.addCode(i.call(m+"_mul",o,c,I),i.call(m+"_mulNR",c,w),i.call(m+"_add",o,w,w),i.call(m+"_add",o,c,F),i.call(m+"_mul",F,w,w),i.call(m+"_mulNR",I,F),i.call(m+"_add",I,F,F),i.call(m+"_sub",w,F,w),i.call(m+"_add",I,I,L),i.call(m+"_mul",r,l,I),i.call(m+"_mulNR",l,b),i.call(m+"_add",r,b,b),i.call(m+"_add",r,l,F),i.call(m+"_mul",F,b,b),i.call(m+"_mulNR",I,F),i.call(m+"_add",I,F,F),i.call(m+"_sub",b,F,b),i.call(m+"_add",I,I,y),i.call(m+"_mul",n,d,I),i.call(m+"_mulNR",d,A),i.call(m+"_add",n,A,A),i.call(m+"_add",n,d,F),i.call(m+"_mul",F,A,A),i.call(m+"_mulNR",I,F),i.call(m+"_add",I,F,F),i.call(m+"_sub",A,F,A),i.call(m+"_add",I,I,C),i.call(m+"_sub",w,o,u),i.call(m+"_add",u,u,u),i.call(m+"_add",w,u,u),i.call(m+"_add",L,c,_),i.call(m+"_add",_,_,_),i.call(m+"_add",L,_,_),i.call(m+"_mul",C,i.i32_const(P),F),i.call(m+"_add",F,r,h),i.call(m+"_add",h,h,h),i.call(m+"_add",F,h,h),i.call(m+"_sub",A,l,f),i.call(m+"_add",f,f,f),i.call(m+"_add",A,f,f),i.call(m+"_sub",b,n,g),i.call(m+"_add",g,g,g),i.call(m+"_add",b,g,g),i.call(m+"_add",y,d,p),i.call(m+"_add",p,p,p),i.call(m+"_add",y,p,p))}(),N(R,true,"w0");const e=t.addFunction(a+"_finalExponentiation");e.addParam("x","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("x"),n=i.getLocal("r"),l=i.i32_const(t.alloc(c)),r=i.i32_const(t.alloc(c)),d=i.i32_const(t.alloc(c)),u=i.i32_const(t.alloc(c)),g=i.i32_const(t.alloc(c)),f=i.i32_const(t.alloc(c)),h=i.i32_const(t.alloc(c));e.addCode(i.call(O+"_frobeniusMap6",o,l),i.call(O+"_inverse",o,r),i.call(O+"_mul",l,r,d),i.call(O+"_copy",d,r),i.call(O+"_frobeniusMap2",d,d),i.call(O+"_mul",d,r,d),i.call(a+"__cyclotomicSquare",d,r),i.call(O+"_conjugate",r,r),i.call(a+"__cyclotomicExp_w0",d,u),i.call(a+"__cyclotomicSquare",u,g),i.call(O+"_mul",r,u,f),i.call(a+"__cyclotomicExp_w0",f,r),i.call(a+"__cyclotomicExp_w0",r,l),i.call(a+"__cyclotomicExp_w0",l,h),i.call(O+"_mul",h,g,h),i.call(a+"__cyclotomicExp_w0",h,g),i.call(O+"_conjugate",f,f),i.call(O+"_mul",g,f,g),i.call(O+"_mul",g,d,g),i.call(O+"_conjugate",d,f),i.call(O+"_mul",r,d,r),i.call(O+"_frobeniusMap3",r,r),i.call(O+"_mul",h,f,h),i.call(O+"_frobeniusMap1",h,h),i.call(O+"_mul",u,l,u),i.call(O+"_frobeniusMap2",u,u),i.call(O+"_mul",u,r,u),i.call(O+"_mul",u,h,u),i.call(O+"_mul",u,g,n))}();for(let e=1;e<=5;e++)K(e),t.exportFunction(a+"_pairingEq"+e);!function(){const e=t.addFunction(a+"_pairing");e.addParam("p","i32"),e.addParam("q","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.i32_const(t.alloc(c));e.addCode(i.call(a+"_prepareG1",i.getLocal("p"),i.i32_const($))),e.addCode(i.call(a+"_prepareG2",i.getLocal("q"),i.i32_const(V))),e.addCode(i.call(a+"_millerLoop",i.i32_const($),i.i32_const(V),o)),e.addCode(i.call(a+"_finalExponentiation",o,i.getLocal("r")))}(),t.exportFunction(a+"_pairing"),t.exportFunction(a+"_prepareG1"),t.exportFunction(a+"_prepareG2"),t.exportFunction(a+"_millerLoop"),t.exportFunction(a+"_finalExponentiation"),t.exportFunction(a+"_finalExponentiationOld"),t.exportFunction(a+"__cyclotomicSquare"),t.exportFunction(a+"__cyclotomicExp_w0"),t.exportFunction(G+"_mul1"),t.exportFunction(G+"_mul01"),t.exportFunction(O+"_mul014"),t.exportFunction(p+"_inGroupAffine"),t.exportFunction(p+"_inGroup"),t.exportFunction(L+"_inGroupAffine"),t.exportFunction(L+"_inGroup")};function be(t,e){let a=t;void 0===e&&0==(e=Math.floor((o(t)-1)/8)+1)&&(e=1);const i=new Uint8Array(e),n=new DataView(i.buffer);let l=0;for(;l<e;)l+4<=e?(n.setUint32(l,Number(a&BigInt(4294967295)),!0),l+=4,a>>=BigInt(32)):l+2<=e?(n.setUint16(l,Number(a&BigInt(65535)),!0),l+=2,a>>=BigInt(16)):(n.setUint8(l,Number(a&BigInt(255)),!0),l+=1,a>>=BigInt(8));if(a)throw new Error("Number does not fit in this length");return i}const ye=[];for(let t=0;t<256;t++)ye[t]=Ae(t,8);function Ae(t,e){let a=0,i=t;for(let t=0;t<e;t++)a<<=1,a|=1&i,i>>=1;return a}function Ce(t,e){return(ye[t>>>24]|ye[t>>>16&255]<<8|ye[t>>>8&255]<<16|ye[255&t]<<24)>>>32-e}function Ie(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 Fe(t,e){const a=t.byteLength/e,i=Ie(a);if(a!=1<<i)throw new Error("Invalid number of pointers");for(let o=0;o<a;o++){const a=Ce(o,i);if(o>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)}}}function xe(t,e){const a=new Uint8Array(e*t.length);for(let i=0;i<t.length;i++)a.set(t[i],i*e);return a}function Ee(t,e){const a=t.byteLength/e,i=new Array(a);for(let o=0;o<a;o++)i[o]=t.slice(o*e,o*e+e);return i}var ve=Object.freeze({__proto__:null,array2buffer:xe,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))<<BigInt(8*i),i+=4):a>=2?(a-=2,e+=BigInt(o.getUint16(a))<<BigInt(8*i),i+=2):(a-=1,e+=BigInt(o.getUint8(a))<<BigInt(8*i),i+=1);return e},beInt2Buff:function(t,e){let a=t;const i=new Uint8Array(e),o=new DataView(i.buffer);let n=e;for(;n>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},bitReverse:Ce,buffReverseBits:Fe,buffer2array:Ee,leBuff2int:function(t){let e=BigInt(0),a=0;const i=new DataView(t.buffer,t.byteOffset,t.byteLength);for(;a<t.length;)a+4<=t.length?(e+=BigInt(i.getUint32(a,!0))<<BigInt(8*a),a+=4):a+2<=t.length?(e+=BigInt(i.getUint16(a,!0))<<BigInt(8*a),a+=2):(e+=BigInt(i.getUint8(a,!0))<<BigInt(8*a),a+=1);return e},leInt2Buff:be,log2:Ie,stringifyBigInts:function t(e){if("bigint"==typeof e||void 0!==e.eq)return e.toString(10);if(e instanceof Uint8Array)return E(e,0);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},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},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},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}});const Be=1<<30;class Se{constructor(t){this.buffers=[],this.byteLength=t;for(let e=0;e<t;e+=Be){const a=Math.min(t-e,Be);this.buffers.push(new Uint8Array(a))}}slice(t,e){void 0===e&&(e=this.byteLength),void 0===t&&(t=0);const a=e-t,i=Math.floor(t/Be);if(i==Math.floor((t+a-1)/Be)||0==a)return this.buffers[i].slice(t%Be,t%Be+a);let o,n=i,l=t%Be,r=a;for(;r>0;){const t=l+r>Be?Be-l:r,e=new Uint8Array(this.buffers[n].buffer,this.buffers[n].byteOffset+l,t);if(t==a)return e.slice();o||(o=a<=Be?new Uint8Array(a):new Se(a)),o.set(e,a-r),r-=t,n++,l=0}return o}set(t,e){void 0===e&&(e=0);const a=t.byteLength;if(0==a)return;const i=Math.floor(e/Be);if(i==Math.floor((e+a-1)/Be))return t instanceof Se&&1==t.buffers.length?this.buffers[i].set(t.buffers[0],e%Be):this.buffers[i].set(t,e%Be);let o=i,n=e%Be,l=a;for(;l>0;){const e=n+l>Be?Be-n:l,i=t.slice(a-l,a-l+e);new Uint8Array(this.buffers[o].buffer,this.buffers[o].byteOffset+n,e).set(i),l-=e,o++,n=0}}}function Pe(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 l=Math.floor(n/t.concurrency),r=[];for(let s=0;s<t.concurrency;s++){let c;if(c=s<t.concurrency-1?l:n-s*l,0==c)continue;const d=[{cmd:"ALLOCSET",var:0,buff:o.slice(s*l*a,s*l*a+c*a)},{cmd:"ALLOC",var:1,len:i*c},{cmd:"CALL",fnName:e,params:[{var:0},{val:c},{var:1}]},{cmd:"GET",out:0,var:1,len:i*c}];r.push(t.queueAction(d))}const s=await Promise.all(r);let c;c=o instanceof Se?new Se(n*i):new Uint8Array(n*i);let d=0;for(let t=0;t<s.length;t++)c.set(s[t][0],d),d+=s[t][0].byteLength;return c}}class Ge{constructor(t,e,a,i){if(this.tm=t,this.prefix=e,this.p=i,this.n8=a,this.type="F1",this.m=1,this.half=s(i,G),this.bitLength=o(i),this.mask=_(r(G,this.bitLength),G),this.pOp1=t.alloc(a),this.pOp2=t.alloc(a),this.pOp3=t.alloc(a),this.tm.instance.exports[e+"_zero"](this.pOp1),this.zero=this.tm.getBuff(this.pOp1,this.n8),this.tm.instance.exports[e+"_one"](this.pOp1),this.one=this.tm.getBuff(this.pOp1,this.n8),this.negone=this.neg(this.one),this.two=this.add(this.one,this.one),this.n64=Math.floor(a/8),this.n32=Math.floor(a/4),8*this.n64!=this.n8)throw new Error("n8 must be a multiple of 8");this.half=s(this.p,G),this.nqr=this.two;let n=this.exp(this.nqr,this.half);for(;!this.eq(n,this.negone);)this.nqr=this.add(this.nqr,this.one),n=this.exp(this.nqr,this.half);this.shift=this.mul(this.nqr,this.nqr),this.shiftInv=this.inv(this.shift),this.s=0;let l=_(this.p,G);for(;!u(l);)this.s=this.s+1,l=s(l,G);this.w=[],this.w[this.s]=this.exp(this.nqr,l);for(let t=this.s-1;t>=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=Pe(t,e+"_batchToMontgomery",this.n8,this.n8),this.batchFromMontgomery=Pe(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=S(i(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=i(t,e);n(a)?(a=p(a),A(a,this.p)&&(a=b(a,this.p)),a=_(this.p,a)):A(a,this.p)&&(a=b(a,this.p));const o=be(a,this.n8);return this.toMontgomery(o)}toString(t,e){return B(E(this.fromMontgomery(t),0),e)}fromRng(t){let e;const a=new Uint8Array(this.n8);do{e=P;for(let a=0;a<this.n64;a++)e=h(e,r(t.nextU64(),64*a));e=I(e,this.mask)}while(C(e,this.p));return F(a,0,e,this.n8),a}random(){return this.fromRng(k())}toObject(t){return E(this.fromMontgomery(t),0)}fromObject(t){const e=new Uint8Array(this.n8);return F(e,0,t,this.n8),this.toMontgomery(e)}toRprLE(t,e,a){t.set(this.fromMontgomery(a),e)}toRprBE(t,e,a){const i=this.fromMontgomery(a);for(let t=0;t<this.n8/2;t++){const e=i[t];i[t]=i[this.n8-1-t],i[this.n8-1-t]=e}t.set(i,e)}fromRprLE(t,e){e=e||0;const a=t.slice(e,e+this.n8);return this.toMontgomery(a)}async batchInverse(t){let e=!1;const a=this.n8,i=this.n8;Array.isArray(t)?(t=xe(t,a),e=!0):t=t.slice(0,t.byteLength);const o=Math.floor(t.byteLength/a);if(o*a!==t.byteLength)throw new Error("Invalid buffer size");const n=Math.floor(o/this.tm.concurrency),l=[];for(let e=0;e<this.tm.concurrency;e++){let r;if(r=e<this.tm.concurrency-1?n:o-e*n,0==r)continue;const s=[{cmd:"ALLOCSET",var:0,buff:t.slice(e*n*a,e*n*a+r*a)},{cmd:"ALLOC",var:1,len:i*r},{cmd:"CALL",fnName:this.prefix+"_batchInverse",params:[{var:0},{val:a},{val:r},{var:1},{val:i}]},{cmd:"GET",out:0,var:1,len:i*r}];l.push(this.tm.queueAction(s))}const r=await Promise.all(l);let s;s=t instanceof Se?new Se(o*i):new Uint8Array(o*i);let c=0;for(let t=0;t<r.length;t++)s.set(r[t][0],c),c+=r[t][0].byteLength;return e?Ee(s,i):s}}class Oe{constructor(t,e,a){this.tm=t,this.prefix=e,this.F=a,this.type="F2",this.m=2*a.m,this.n8=2*this.F.n8,this.n32=2*this.F.n32,this.n64=2*this.F.n64,this.pOp1=t.alloc(2*a.n8),this.pOp2=t.alloc(2*a.n8),this.pOp3=t.alloc(2*a.n8),this.tm.instance.exports[e+"_zero"](this.pOp1),this.zero=t.getBuff(this.pOp1,this.n8),this.tm.instance.exports[e+"_one"](this.pOp1),this.one=t.getBuff(this.pOp1,this.n8),this.negone=this.neg(this.one),this.two=this.add(this.one,this.one)}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)}isNegative(t){return this.op1Bool("_isNegative",t)}toMontgomery(t){return this.op1("_toMontgomery",t)}fromMontgomery(t){return this.op1("_fromMontgomery",t)}mul(t,e){return this.op2("_mul",t,e)}mul1(t,e){return this.op2("_mul1",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=S(i(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)}e(t,e){if(t instanceof Uint8Array)return t;if(Array.isArray(t)&&2==t.length){const a=this.F.e(t[0],e),i=this.F.e(t[1],e),o=new Uint8Array(2*this.F.n8);return o.set(a),o.set(i,2*this.F.n8),o}throw new Error("invalid F2")}toString(t,e){return`[${this.F.toString(t.slice(0,this.F.n8),e)}, ${this.F.toString(t.slice(this.F.n8),e)}]`}fromRng(t){const e=this.F.fromRng(t),a=this.F.fromRng(t),i=new Uint8Array(2*this.F.n8);return i.set(e),i.set(a,this.F.n8),i}random(){return this.fromRng(k())}toObject(t){return[this.F.toObject(t.slice(0,this.F.n8)),this.F.toObject(t.slice(this.F.n8,2*this.F.n8))]}fromObject(t){const e=new Uint8Array(2*this.F.n8),a=this.F.fromObject(t[0]),i=this.F.fromObject(t[1]);return e.set(a),e.set(i,this.F.n8),e}c1(t){return t.slice(0,this.F.n8)}c2(t){return t.slice(this.F.n8)}}class Te{constructor(t,e,a){this.tm=t,this.prefix=e,this.F=a,this.type="F3",this.m=3*a.m,this.n8=3*this.F.n8,this.n32=3*this.F.n32,this.n64=3*this.F.n64,this.pOp1=t.alloc(3*a.n8),this.pOp2=t.alloc(3*a.n8),this.pOp3=t.alloc(3*a.n8),this.tm.instance.exports[e+"_zero"](this.pOp1),this.zero=t.getBuff(this.pOp1,this.n8),this.tm.instance.exports[e+"_one"](this.pOp1),this.one=t.getBuff(this.pOp1,this.n8),this.negone=this.neg(this.one),this.two=this.add(this.one,this.one)}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)}eq(t,e){return this.op2Bool("_eq",t,e)}isZero(t){return this.op1Bool("_isZero",t)}add(t,e){return this.op2("_add",t,e)}sub(t,e){return this.op2("_sub",t,e)}neg(t){return this.op1("_neg",t)}inv(t){return this.op1("_inverse",t)}isNegative(t){return this.op1Bool("_isNegative",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=S(i(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.getBuff(this.pOp3,this.n8)}e(t,e){if(t instanceof Uint8Array)return t;if(Array.isArray(t)&&3==t.length){const a=this.F.e(t[0],e),i=this.F.e(t[1],e),o=this.F.e(t[2],e),n=new Uint8Array(3*this.F.n8);return n.set(a),n.set(i,this.F.n8),n.set(o,2*this.F.n8),n}throw new Error("invalid F3")}toString(t,e){return`[${this.F.toString(t.slice(0,this.F.n8),e)}, ${this.F.toString(t.slice(this.F.n8,2*this.F.n8),e)}, ${this.F.toString(t.slice(2*this.F.n8),e)}]`}fromRng(t){const e=this.F.fromRng(t),a=this.F.fromRng(t),i=this.F.fromRng(t),o=new Uint8Array(3*this.F.n8);return o.set(e),o.set(a,this.F.n8),o.set(i,2*this.F.n8),o}random(){return this.fromRng(k())}toObject(t){return[this.F.toObject(t.slice(0,this.F.n8)),this.F.toObject(t.slice(this.F.n8,2*this.F.n8)),this.F.toObject(t.slice(2*this.F.n8,3*this.F.n8))]}fromObject(t){const e=new Uint8Array(3*this.F.n8),a=this.F.fromObject(t[0]),i=this.F.fromObject(t[1]),o=this.F.fromObject(t[2]);return e.set(a),e.set(i,this.F.n8),e.set(o,2*this.F.n8),e}c1(t){return t.slice(0,this.F.n8)}c2(t){return t.slice(this.F.n8,2*this.F.n8)}c3(t){return t.slice(2*this.F.n8)}}class Ue{constructor(t,e,a,i,o,n){this.tm=t,this.prefix=e,this.F=a,this.pOp1=t.alloc(3*a.n8),this.pOp2=t.alloc(3*a.n8),this.pOp3=t.alloc(3*a.n8),this.tm.instance.exports[e+"_zero"](this.pOp1),this.zero=this.tm.getBuff(this.pOp1,3*a.n8),this.tm.instance.exports[e+"_zeroAffine"](this.pOp1),this.zeroAffine=this.tm.getBuff(this.pOp1,2*a.n8),this.one=this.tm.getBuff(i,3*a.n8),this.g=this.one,this.oneAffine=this.tm.getBuff(i,2*a.n8),this.gAffine=this.oneAffine,this.b=this.tm.getBuff(o,a.n8),n&&(this.cofactor=S(n)),this.negone=this.neg(this.one),this.two=this.add(this.one,this.one),this.batchLEMtoC=Pe(t,e+"_batchLEMtoC",2*a.n8,a.n8),this.batchLEMtoU=Pe(t,e+"_batchLEMtoU",2*a.n8,2*a.n8),this.batchCtoLEM=Pe(t,e+"_batchCtoLEM",a.n8,2*a.n8),this.batchUtoLEM=Pe(t,e+"_batchUtoLEM",2*a.n8,2*a.n8),this.batchToJacobian=Pe(t,e+"_batchToJacobian",2*a.n8,3*a.n8),this.batchToAffine=Pe(t,e+"_batchToAffine",3*a.n8,2*a.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,3*this.F.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,this.pOp3)}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,3*this.F.n8)}op1Affine(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,2*this.F.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){if(t.byteLength==3*this.F.n8){if(e.byteLength==3*this.F.n8)return this.op2("_add",t,e);if(e.byteLength==2*this.F.n8)return this.op2("_addMixed",t,e);throw new Error("invalid point size")}if(t.byteLength==2*this.F.n8){if(e.byteLength==3*this.F.n8)return this.op2("_addMixed",e,t);if(e.byteLength==2*this.F.n8)return this.op2("_addAffine",t,e);throw new Error("invalid point size")}throw new Error("invalid point size")}sub(t,e){if(t.byteLength==3*this.F.n8){if(e.byteLength==3*this.F.n8)return this.op2("_sub",t,e);if(e.byteLength==2*this.F.n8)return this.op2("_subMixed",t,e);throw new Error("invalid point size")}if(t.byteLength==2*this.F.n8){if(e.byteLength==3*this.F.n8)return this.op2("_subMixed",e,t);if(e.byteLength==2*this.F.n8)return this.op2("_subAffine",t,e);throw new Error("invalid point size")}throw new Error("invalid point size")}neg(t){if(t.byteLength==3*this.F.n8)return this.op1("_neg",t);if(t.byteLength==2*this.F.n8)return this.op1Affine("_negAffine",t);throw new Error("invalid point size")}double(t){if(t.byteLength==3*this.F.n8)return this.op1("_double",t);if(t.byteLength==2*this.F.n8)return this.op1("_doubleAffine",t);throw new Error("invalid point size")}isZero(t){if(t.byteLength==3*this.F.n8)return this.op1Bool("_isZero",t);if(t.byteLength==2*this.F.n8)return this.op1Bool("_isZeroAffine",t);throw new Error("invalid point size")}timesScalar(t,e){let a;if(e instanceof Uint8Array||(e=S(i(e))),t.byteLength==3*this.F.n8)a=this.prefix+"_timesScalar";else{if(t.byteLength!=2*this.F.n8)throw new Error("invalid point size");a=this.prefix+"_timesScalarAffine"}return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[a](this.pOp1,this.pOp2,e.byteLength,this.pOp3),this.tm.getBuff(this.pOp3,3*this.F.n8)}timesFr(t,e){let a;if(t.byteLength==3*this.F.n8)a=this.prefix+"_timesFr";else{if(t.byteLength!=2*this.F.n8)throw new Error("invalid point size");a=this.prefix+"_timesFrAffine"}return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[a](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,3*this.F.n8)}eq(t,e){if(t.byteLength==3*this.F.n8){if(e.byteLength==3*this.F.n8)return this.op2bool("_eq",t,e);if(e.byteLength==2*this.F.n8)return this.op2bool("_eqMixed",t,e);throw new Error("invalid point size")}if(t.byteLength==2*this.F.n8){if(e.byteLength==3*this.F.n8)return this.op2bool("_eqMixed",e,t);if(e.byteLength==2*this.F.n8)return this.op2bool("_eqAffine",t,e);throw new Error("invalid point size")}throw new Error("invalid point size")}toAffine(t){if(t.byteLength==3*this.F.n8)return this.op1Affine("_toAffine",t);if(t.byteLength==2*this.F.n8)return t;throw new Error("invalid point size")}toJacobian(t){if(t.byteLength==3*this.F.n8)return t;if(t.byteLength==2*this.F.n8)return this.op1("_toJacobian",t);throw new Error("invalid point size")}toRprUncompressed(t,e,a){if(this.tm.setBuff(this.pOp1,a),a.byteLength==3*this.F.n8)this.tm.instance.exports[this.prefix+"_toAffine"](this.pOp1,this.pOp1);else if(a.byteLength!=2*this.F.n8)throw new Error("invalid point size");this.tm.instance.exports[this.prefix+"_LEMtoU"](this.pOp1,this.pOp1);const i=this.tm.getBuff(this.pOp1,2*this.F.n8);t.set(i,e)}fromRprUncompressed(t,e){const a=t.slice(e,e+2*this.F.n8);return this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+"_UtoLEM"](this.pOp1,this.pOp1),this.tm.getBuff(this.pOp1,2*this.F.n8)}toRprCompressed(t,e,a){if(this.tm.setBuff(this.pOp1,a),a.byteLength==3*this.F.n8)this.tm.instance.exports[this.prefix+"_toAffine"](this.pOp1,this.pOp1);else if(a.byteLength!=2*this.F.n8)throw new Error("invalid point size");this.tm.instance.exports[this.prefix+"_LEMtoC"](this.pOp1,this.pOp1);const i=this.tm.getBuff(this.pOp1,this.F.n8);t.set(i,e)}fromRprCompressed(t,e){const a=t.slice(e,e+this.F.n8);return this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+"_CtoLEM"](this.pOp1,this.pOp2),this.tm.getBuff(this.pOp2,2*this.F.n8)}toUncompressed(t){const e=new Uint8Array(2*this.F.n8);return this.toRprUncompressed(e,0,t),e}toRprLEM(t,e,a){if(a.byteLength!=2*this.F.n8){if(a.byteLength!=3*this.F.n8)throw new Error("invalid point size");{this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+"_toAffine"](this.pOp1,this.pOp1);const i=this.tm.getBuff(this.pOp1,2*this.F.n8);t.set(i,e)}}else t.set(a,e)}fromRprLEM(t,e){return e=e||0,t.slice(e,e+2*this.F.n8)}toString(t,e){if(t.byteLength==3*this.F.n8){return`[ ${this.F.toString(t.slice(0,this.F.n8),e)}, ${this.F.toString(t.slice(this.F.n8,2*this.F.n8),e)}, ${this.F.toString(t.slice(2*this.F.n8),e)} ]`}if(t.byteLength==2*this.F.n8){return`[ ${this.F.toString(t.slice(0,this.F.n8),e)}, ${this.F.toString(t.slice(this.F.n8),e)} ]`}throw new Error("invalid point size")}isValid(t){if(this.isZero(t))return!0;const e=this.F,a=this.toAffine(t),i=a.slice(0,this.F.n8),o=a.slice(this.F.n8,2*this.F.n8),n=e.add(e.mul(e.square(i),i),this.b),l=e.square(o);return e.eq(n,l)}fromRng(t){const e=this.F;let a,i,o=[];do{o[0]=e.fromRng(t),a=t.nextBool(),i=e.add(e.mul(e.square(o[0]),o[0]),this.b)}while(!e.isSquare(i));o[1]=e.sqrt(i);a^e.isNegative(o[1])&&(o[1]=e.neg(o[1]));let n=new Uint8Array(2*this.F.n8);return n.set(o[0]),n.set(o[1],this.F.n8),this.cofactor&&(n=this.timesScalar(n,this.cofactor)),n}toObject(t){if(this.isZero(t))return[this.F.toObject(this.F.zero),this.F.toObject(this.F.one),this.F.toObject(this.F.zero)];const e=this.F.toObject(t.slice(0,this.F.n8)),a=this.F.toObject(t.slice(this.F.n8,2*this.F.n8));let i;return i=t.byteLength==3*this.F.n8?this.F.toObject(t.slice(2*this.F.n8,3*this.F.n8)):this.F.toObject(this.F.one),[e,a,i]}fromObject(t){const e=this.F.fromObject(t[0]),a=this.F.fromObject(t[1]);let i;if(i=3==t.length?this.F.fromObject(t[2]):this.F.one,this.F.isZero(i,this.F.one))return this.zeroAffine;if(this.F.eq(i,this.F.one)){const t=new Uint8Array(2*this.F.n8);return t.set(e),t.set(a,this.F.n8),t}{const t=new Uint8Array(3*this.F.n8);return t.set(e),t.set(a,this.F.n8),t.set(i,2*this.F.n8),t}}e(t){return t instanceof Uint8Array?t:this.fromObject(t)}x(t){return this.toAffine(t).slice(0,this.F.n8)}y(t){return this.toAffine(t).slice(this.F.n8)}}const ze=25;class Qe{constructor(){this.promise=new Promise(((t,e)=>{this.reject=e,this.resolve=t}))}}let qe;const Me='(function thread(self) {\n const MAXMEM = 32767;\n let instance;\n let memory;\n\n if (self) {\n self.onmessage = function(e) {\n let data;\n if (e.data) {\n data = e.data;\n } else {\n data = e;\n }\n\n if (data[0].cmd == "INIT") {\n init(data[0]).then(function() {\n self.postMessage(data.result);\n });\n } else if (data[0].cmd == "TERMINATE") {\n self.close();\n } else {\n const res = runTask(data);\n self.postMessage(res);\n }\n };\n }\n\n async function init(data) {\n const code = new Uint8Array(data.code);\n const wasmModule = await WebAssembly.compile(code);\n memory = new WebAssembly.Memory({initial:data.init, maximum: MAXMEM});\n\n instance = await WebAssembly.instantiate(wasmModule, {\n env: {\n "memory": memory\n }\n });\n }\n\n\n\n function alloc(length) {\n const u32 = new Uint32Array(memory.buffer, 0, 1);\n while (u32[0] & 3) u32[0]++; // Return always aligned pointers\n const res = u32[0];\n u32[0] += length;\n if (u32[0] + length > memory.buffer.byteLength) {\n const currentPages = memory.buffer.byteLength / 0x10000;\n let requiredPages = Math.floor((u32[0] + length) / 0x10000)+1;\n if (requiredPages>MAXMEM) requiredPages=MAXMEM;\n memory.grow(requiredPages-currentPages);\n }\n return res;\n }\n\n function allocBuffer(buffer) {\n const p = alloc(buffer.byteLength);\n setBuffer(p, buffer);\n return p;\n }\n\n function getBuffer(pointer, length) {\n const u8 = new Uint8Array(memory.buffer);\n return new Uint8Array(u8.buffer, u8.byteOffset + pointer, length);\n }\n\n function setBuffer(pointer, buffer) {\n const u8 = new Uint8Array(memory.buffer);\n u8.set(new Uint8Array(buffer), pointer);\n }\n\n function runTask(task) {\n if (task[0].cmd == "INIT") {\n return init(task[0]);\n }\n const ctx = {\n vars: [],\n out: []\n };\n const u32a = new Uint32Array(memory.buffer, 0, 1);\n const oldAlloc = u32a[0];\n for (let i=0; i<task.length; i++) {\n switch (task[i].cmd) {\n case "ALLOCSET":\n ctx.vars[task[i].var] = allocBuffer(task[i].buff);\n break;\n case "ALLOC":\n ctx.vars[task[i].var] = alloc(task[i].len);\n break;\n case "SET":\n setBuffer(ctx.vars[task[i].var], task[i].buff);\n break;\n case "CALL": {\n const params = [];\n for (let j=0; j<task[i].params.length; j++) {\n const p = task[i].params[j];\n if (typeof p.var !== "undefined") {\n params.push(ctx.vars[p.var] + (p.offset || 0));\n } else if (typeof p.val != "undefined") {\n params.push(p.val);\n }\n }\n instance.exports[task[i].fnName](...params);\n break;\n }\n case "GET":\n ctx.out[task[i].out] = getBuffer(ctx.vars[task[i].var], task[i].len).slice();\n break;\n default:\n throw new Error("Invalid cmd");\n }\n }\n const u32b = new Uint32Array(memory.buffer, 0, 1);\n u32b[0] = oldAlloc;\n return ctx.out;\n }\n\n\n return runTask;\n})(self)';if(globalThis?.Blob){const t=(new TextEncoder).encode(Me),e=new Blob([t],{type:"application/javascript"});qe=URL.createObjectURL(e)}else qe="data:application/javascript;base64,"+globalThis.btoa(Me);async function ke(t,e){const a=new Re;a.memory=new WebAssembly.Memory({initial:ze}),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}}),globalThis?.Worker||(e=!0),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=function(t){const e=32767;let a,i;async function o(t){const o=new Uint8Array(t.code),n=await WebAssembly.compile(o);i=new WebAssembly.Memory({initial:t.init,maximum:e}),a=await WebAssembly.instantiate(n,{env:{memory:i}})}function n(t){const a=new Uint32Array(i.buffer,0,1);for(;3&a[0];)a[0]++;const o=a[0];if(a[0]+=t,a[0]+t>i.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 l(t){const e=n(t.byteLength);return s(e,t),e}function r(t,e){const a=new Uint8Array(i.buffer);return new Uint8Array(a.buffer,a.byteOffset+t,e)}function s(t,e){new Uint8Array(i.buffer).set(new Uint8Array(e),t)}function c(t){if("INIT"==t[0].cmd)return o(t[0]);const e={vars:[],out:[]},c=new Uint32Array(i.buffer,0,1)[0];for(let i=0;i<t.length;i++)switch(t[i].cmd){case"ALLOCSET":e.vars[t[i].var]=l(t[i].buff);break;case"ALLOC":e.vars[t[i].var]=n(t[i].len);break;case"SET":s(e.vars[t[i].var],t[i].buff);break;case"CALL":{const o=[];for(let a=0;a<t[i].params.length;a++){const n=t[i].params[a];void 0!==n.var?o.push(e.vars[n.var]+(n.offset||0)):void 0!==n.val&&o.push(n.val)}a.exports[t[i].fnName](...o);break}case"GET":e.out[t[i].out]=r(e.vars[t[i].var],t[i].len).slice();break;default:throw new Error("Invalid cmd")}return new Uint32Array(i.buffer,0,1)[0]=c,e.out}return t&&(t.onmessage=function(e){let a;if(a=e.data?e.data:e,"INIT"==a[0].cmd)o(a[0]).then((function(){t.postMessage(a.result)}));else if("TERMINATE"==a[0].cmd)t.close();else{const e=c(a);t.postMessage(e)}}),c}(),await a.taskManager([{cmd:"INIT",init:ze,code:a.code.slice()}]),a.concurrency=1;else{a.workers=[],a.pendingDeferreds=[],a.working=[];let e=2;"object"==typeof navigator&&navigator.hardwareConcurrency&&(e=navigator.hardwareConcurrency),0==e&&(e=2),e>64&&(e=64),a.concurrency=e;for(let t=0;t<e;t++)a.workers[t]=new Worker(qe),a.workers[t].addEventListener("message",o(t)),a.working[t]=!1;const i=[];for(let e=0;e<a.workers.length;e++){const o=t.code.slice();i.push(a.postAction(e,[{cmd:"INIT",init:ze,code:o}],[o.buffer]))}await Promise.all(i)}return a;function o(t){return function(e){let i;i=e&&e.data?e.data:e,a.working[t]=!1,a.pendingDeferreds[t].resolve(i),a.processWorks()}}}class Re{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 Qe,this.workers[t].postMessage(e,a),this.pendingDeferreds[t].promise}processWorks(){for(let t=0;t<this.workers.length&&this.actionQueue.length>0;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 Qe;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;t<this.workers.length;t++)this.workers[t].postMessage([{cmd:"TERMINATE"}]);var t;await(t=200,new Promise((e=>setTimeout(e,t))))}}function De(t,e){const a=t[e],i=t.Fr,o=t.tm;t[e].batchApplyKey=async function(t,n,l,r,s){let c,d,u,g,f;if(r=r||"affine",s=s||"affine","G1"==e)"jacobian"==r?(u=3*a.F.n8,c="g1m_batchApplyKey"):(u=2*a.F.n8,c="g1m_batchApplyKeyMixed"),g=3*a.F.n8,"jacobian"==s?f=3*a.F.n8:(d="g1m_batchToAffine",f=2*a.F.n8);else if("G2"==e)"jacobian"==r?(u=3*a.F.n8,c="g2m_batchApplyKey"):(u=2*a.F.n8,c="g2m_batchApplyKeyMixed"),g=3*a.F.n8,"jacobian"==s?f=3*a.F.n8:(d="g2m_batchToAffine",f=2*a.F.n8);else{if("Fr"!=e)throw new Error("Invalid group: "+e);c="frm_batchApplyKey",u=a.n8,g=a.n8,f=a.n8}const h=Math.floor(t.byteLength/u),_=Math.floor(h/o.concurrency),p=[];l=i.e(l);let m=i.e(n);for(let e=0;e<o.concurrency;e++){let a;if(a=e<o.concurrency-1?_:h-e*_,0==a)continue;const n=[];n.push({cmd:"ALLOCSET",var:0,buff:t.slice(e*_*u,e*_*u+a*u)}),n.push({cmd:"ALLOCSET",var:1,buff:m}),n.push({cmd:"ALLOCSET",var:2,buff:l}),n.push({cmd:"ALLOC",var:3,len:a*Math.max(g,f)}),n.push({cmd:"CALL",fnName:c,params:[{var:0},{val:a},{var:1},{var:2},{var:3}]}),d&&n.push({cmd:"CALL",fnName:d,params:[{var:3},{val:a},{var:3}]}),n.push({cmd:"GET",out:0,var:3,len:a*f}),p.push(o.queueAction(n)),m=i.mul(m,i.exp(l,a))}const w=await Promise.all(p);let L;L=t instanceof Se?new Se(h*f):new Uint8Array(h*f);let b=0;for(let t=0;t<w.length;t++)L.set(w[t][0],b),b+=w[t][0].byteLength;return L}}const Ne=[1,1,1,1,2,3,4,5,6,7,7,8,9,10,11,12,13,13,14,15,16,16,17,17,17,17,17,17,17,17,17,17];function $e(t,e){const a=t[e],i=a.tm;async function o(t,i,o,n,l){if(!(t instanceof Uint8Array))throw n&&n.error(`${l} _multiExpChunk buffBases is not Uint8Array`),new Error(`${l} _multiExpChunk buffBases is not Uint8Array`);if(!(i instanceof Uint8Array))throw n&&n.error(`${l} _multiExpChunk buffScalars is not Uint8Array`),new Error(`${l} _multiExpChunk buffScalars is not Uint8Array`);let r,s;if(o=o||"affine","G1"==e)"affine"==o?(s="g1m_multiexpAffine_chunk",r=2*a.F.n8):(s="g1m_multiexp_chunk",r=3*a.F.n8);else{if("G2"!=e)throw new Error("Invalid group");"affine"==o?(s="g2m_multiexpAffine_chunk",r=2*a.F.n8):(s="g2m_multiexp_chunk",r=3*a.F.n8)}const c=Math.floor(t.byteLength/r);if(0==c)return a.zero;const d=Math.floor(i.byteLength/c);if(d*c!=i.byteLength)throw new Error("Scalar size does not match");const u=Ne[Ie(c)],g=Math.floor((8*d-1)/u)+1,f=[];for(let e=0;e<g;e++){const o=[{cmd:"ALLOCSET",var:0,buff:t},{cmd:"ALLOCSET",var:1,buff:i},{cmd:"ALLOC",var:2,len:3*a.F.n8},{cmd:"CALL",fnName:s,params:[{var:0},{var:1},{val:d},{val:c},{val:e*u},{val:Math.min(8*d-e*u,u)},{var:2}]},{cmd:"GET",out:0,var:2,len:3*a.F.n8}];f.push(a.tm.queueAction(o))}const h=await Promise.all(f);let _=a.zero;for(let t=h.length-1;t>=0;t--){if(!a.isZero(_))for(let t=0;t<u;t++)_=a.double(_);_=a.add(_,h[t][0])}return _}async function n(t,n,l,r,s){const c=1<<22;let d;if("G1"==e)d="affine"==l?2*a.F.n8:3*a.F.n8;else{if("G2"!=e)throw new Error("Invalid group");d="affine"==l?2*a.F.n8:3*a.F.n8}const u=Math.floor(t.byteLength/d),g=Math.floor(n.byteLength/u);if(g*u!=n.byteLength)throw new Error("Scalar size does not match");const f=Ne[Ie(u)],h=Math.floor((8*g-1)/f)+1;let _;_=Math.floor(u/(i.concurrency/h)),_>c&&(_=c),_<1024&&(_=1024);const p=[];for(let e=0;e<u;e+=_){r&&r.debug(`Multiexp start: ${s}: ${e}/${u}`);const a=Math.min(u-e,_),i=t.slice(e*d,(e+a)*d),c=n.slice(e*g,(e+a)*g);p.push(o(i,c,l,r,s).then((t=>(r&&r.debug(`Multiexp end: ${s}: ${e}/${u}`),t))))}const m=await Promise.all(p);let w=a.zero;for(let t=m.length-1;t>=0;t--)w=a.add(w,m[t]);return w}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 Ve(t,e){const a=t[e],i=t.Fr,o=a.tm;async function n(t,r,s,c,d,u){s=s||"affine",c=c||"affine";let g,f,h,_,p,m,w,L;"G1"==e?("affine"==s?(g=2*a.F.n8,_="g1m_batchToJacobian"):g=3*a.F.n8,f=3*a.F.n8,r&&(L="g1m_fftFinal"),w="g1m_fftJoin",m="g1m_fftMix","affine"==c?(h=2*a.F.n8,p="g1m_batchToAffine"):h=3*a.F.n8):"G2"==e?("affine"==s?(g=2*a.F.n8,_="g2m_batchToJacobian"):g=3*a.F.n8,f=3*a.F.n8,r&&(L="g2m_fftFinal"),w="g2m_fftJoin",m="g2m_fftMix","affine"==c?(h=2*a.F.n8,p="g2m_batchToAffine"):h=3*a.F.n8):"Fr"==e&&(g=a.n8,f=a.n8,h=a.n8,r&&(L="frm_fftFinal"),m="frm_fftMix",w="frm_fftJoin");let b=!1;Array.isArray(t)?(t=xe(t,g),b=!0):t=t.slice(0,t.byteLength);const y=t.byteLength/g,A=Ie(y);if(1<<A!=y)throw new Error("fft must be multiple of 2");if(A==i.s+1){let e;return e=r?await async function(t,e,a,o,r){let s,c;s=t.slice(0,t.byteLength/2),c=t.slice(t.byteLength/2,t.byteLength);const d=[];d.push(n(s,!0,e,"jacobian",o,r)),d.push(n(c,!0,e,"jacobian",o,r)),[s,c]=await Promise.all(d);const u=await l(s,c,"fftJoinExtInv",i.one,i.shiftInv,"jacobian",a,o,r);let g;g=u[0].byteLength>1<<28?new Se(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return g.set(u[0]),g.set(u[1],u[0].byteLength),g}(t,s,c,d,u):await async function(t,e,a,o,r){let s,c;s=t.slice(0,t.byteLength/2),c=t.slice(t.byteLength/2,t.byteLength);const d=[];[s,c]=await l(s,c,"fftJoinExt",i.one,i.shift,e,"jacobian",o,r),d.push(n(s,!1,"jacobian",a,o,r)),d.push(n(c,!1,"jacobian",a,o,r));const u=await Promise.all(d);let g;g=u[0].byteLength>1<<28?new Se(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return g.set(u[0]),g.set(u[1],u[0].byteLength),g}(t,s,c,d,u),b?Ee(e,h):e}let C,I,F;r&&(C=i.inv(i.e(y))),Fe(t,g);let x=Math.min(16384,y),E=y/x;for(;E<o.concurrency&&x>=16;)E*=2,x/=2;const v=Ie(x),B=[];for(let e=0;e<E;e++){d&&d.debug(`${u}: fft ${A} mix start: ${e}/${E}`);const a=[];a.push({cmd:"ALLOC",var:0,len:f*x});const i=t.slice(x*e*g,x*(e+1)*g);a.push({cmd:"SET",var:0,buff:i}),_&&a.push({cmd:"CALL",fnName:_,params:[{var:0},{val:x},{var:0}]});for(let t=1;t<=v;t++)a.push({cmd:"CALL",fnName:m,params:[{var:0},{val:x},{val:t}]});v==A?(L&&(a.push({cmd:"ALLOCSET",var:1,buff:C}),a.push({cmd:"CALL",fnName:L,params:[{var:0},{val:x},{var:1}]})),p&&a.push({cmd:"CALL",fnName:p,params:[{var:0},{val:x},{var:0}]}),a.push({cmd:"GET",out:0,var:0,len:x*h})):a.push({cmd:"GET",out:0,var:0,len:f*x}),B.push(o.queueAction(a).then((t=>(d&&d.debug(`${u}: fft ${A} mix end: ${e}/${E}`),t))))}F=await Promise.all(B);for(let t=0;t<E;t++)F[t]=F[t][0];for(let t=v+1;t<=A;t++){d&&d.debug(`${u}: fft ${A} join: ${t}/${A}`);const e=1<<A-t,a=E/e,n=[];for(let l=0;l<e;l++)for(let r=0;r<a/2;r++){const s=i.exp(i.w[t],r*x),c=i.w[t],g=l*a+r,_=l*a+r+a/2,m=[];m.push({cmd:"ALLOCSET",var:0,buff:F[g]}),m.push({cmd:"ALLOCSET",var:1,buff:F[_]}),m.push({cmd:"ALLOCSET",var:2,buff:s}),m.push({cmd:"ALLOCSET",var:3,buff:c}),m.push({cmd:"CALL",fnName:w,params:[{var:0},{var:1},{val:x},{var:2},{var:3}]}),t==A?(L&&(m.push({cmd:"ALLOCSET",var:4,buff:C}),m.push({cmd:"CALL",fnName:L,params:[{var:0},{val:x},{var:4}]}),m.push({cmd:"CALL",fnName:L,params:[{var:1},{val:x},{var:4}]})),p&&(m.push({cmd:"CALL",fnName:p,params:[{var:0},{val:x},{var:0}]}),m.push({cmd:"CALL",fnName:p,params:[{var:1},{val:x},{var:1}]})),m.push({cmd:"GET",out:0,var:0,len:x*h}),m.push({cmd:"GET",out:1,var:1,len:x*h})):(m.push({cmd:"GET",out:0,var:0,len:x*f}),m.push({cmd:"GET",out:1,var:1,len:x*f})),n.push(o.queueAction(m).then((i=>(d&&d.debug(`${u}: fft ${A} join ${t}/${A} ${l+1}/${e} ${r}/${a/2}`),i))))}const l=await Promise.all(n);for(let t=0;t<e;t++)for(let e=0;e<a/2;e++){const i=t*a+e,o=t*a+e+a/2,n=l.shift();F[i]=n[0],F[o]=n[1]}}if(I=t instanceof Se?new Se(y*h):new Uint8Array(y*h),r){I.set(F[0].slice((x-1)*h));let t=h;for(let e=E-1;e>0;e--)I.set(F[e],t),t+=x*h,delete F[e];I.set(F[0].slice(0,(x-1)*h),t),delete F[0]}else for(let t=0;t<E;t++)I.set(F[t],x*h*t),delete F[t];return b?Ee(I,h):I}async function l(t,n,l,r,s,c,d,u,g){let f,h,_,p,m,w;if("G1"==e)"affine"==c?(m=2*a.F.n8,h="g1m_batchToJacobian"):m=3*a.F.n8,w=3*a.F.n8,f="g1m_"+l,"affine"==d?(_="g1m_batchToAffine",p=2*a.F.n8):p=3*a.F.n8;else if("G2"==e)"affine"==c?(m=2*a.F.n8,h="g2m_batchToJacobian"):m=3*a.F.n8,f="g2m_"+l,w=3*a.F.n8,"affine"==d?(_="g2m_batchToAffine",p=2*a.F.n8):p=3*a.F.n8;else{if("Fr"!=e)throw new Error("Invalid group");m=i.n8,p=i.n8,w=i.n8,f="frm_"+l}if(t.byteLength!=n.byteLength)throw new Error("Invalid buffer size");const L=Math.floor(t.byteLength/m);if(L!=1<<Ie(L))throw new Error("Invalid number of points");let b=Math.floor(L/o.concurrency);b<16&&(b=16),b>65536&&(b=65536);const y=[];for(let e=0;e<L;e+=b){u&&u.debug(`${g}: fftJoinExt Start: ${e}/${L}`);const a=Math.min(L-e,b),l=i.mul(r,i.exp(s,e)),c=[],d=t.slice(e*m,(e+a)*m),A=n.slice(e*m,(e+a)*m);c.push({cmd:"ALLOC",var:0,len:w*a}),c.push({cmd:"SET",var:0,buff:d}),c.push({cmd:"ALLOC",var:1,len:w*a}),c.push({cmd:"SET",var:1,buff:A}),c.push({cmd:"ALLOCSET",var:2,buff:l}),c.push({cmd:"ALLOCSET",var:3,buff:s}),h&&(c.push({cmd:"CALL",fnName:h,params:[{var:0},{val:a},{var:0}]}),c.push({cmd:"CALL",fnName:h,params:[{var:1},{val:a},{var:1}]})),c.push({cmd:"CALL",fnName:f,params:[{var:0},{var:1},{val:a},{var:2},{var:3},{val:i.s}]}),_&&(c.push({cmd:"CALL",fnName:_,params:[{var:0},{val:a},{var:0}]}),c.push({cmd:"CALL",fnName:_,params:[{var:1},{val:a},{var:1}]})),c.push({cmd:"GET",out:0,var:0,len:a*p}),c.push({cmd:"GET",out:1,var:1,len:a*p}),y.push(o.queueAction(c).then((t=>(u&&u.debug(`${g}: fftJoinExt End: ${e}/${L}`),t))))}const A=await Promise.all(y);let C,I;L*p>1<<28?(C=new Se(L*p),I=new Se(L*p)):(C=new Uint8Array(L*p),I=new Uint8Array(L*p));let F=0;for(let t=0;t<A.length;t++)C.set(A[t][0],F),I.set(A[t][1],F),F+=A[t][0].byteLength;return[C,I]}a.fft=async function(t,e,a,i,o){return await n(t,!1,e,a,i,o)},a.ifft=async function(t,e,a,i,o){return await n(t,!0,e,a,i,o)},a.lagrangeEvaluations=async function(t,o,r,s,c){let d;if(o=o||"affine",r=r||"affine","G1"==e)d="affine"==o?2*a.F.n8:3*a.F.n8;else if("G2"==e)d="affine"==o?2*a.F.n8:3*a.F.n8;else{if("Fr"!=e)throw new Error("Invalid group");d=i.n8}const u=t.byteLength/d,g=Ie(u);if(2**g*d!=t.byteLength)throw s&&s.error("lagrangeEvaluations iinvalid input size"),new Error("lagrangeEvaluations invalid Input size");if(g<=i.s)return await a.ifft(t,o,r,s,c);if(g>i.s+1)throw s&&s.error("lagrangeEvaluations input too big"),new Error("lagrangeEvaluations input too big");let f=t.slice(0,t.byteLength/2),h=t.slice(t.byteLength/2,t.byteLength);const _=i.exp(i.shift,u/2),p=i.inv(i.sub(i.one,_));[f,h]=await l(f,h,"prepareLagrangeEvaluation",p,i.shiftInv,o,"jacobian",s,c+" prep");const m=[];let w;return m.push(n(f,!0,"jacobian",r,s,c+" t0")),m.push(n(h,!0,"jacobian",r,s,c+" t1")),[f,h]=await Promise.all(m),w=f.byteLength>1<<28?new Se(2*f.byteLength):new Uint8Array(2*f.byteLength),w.set(f),w.set(h,f.byteLength),w},a.fftMix=async function(t){const n=3*a.F.n8;let l,r;if("G1"==e)l="g1m_fftMix",r="g1m_fftJoin";else if("G2"==e)l="g2m_fftMix",r="g2m_fftJoin";else{if("Fr"!=e)throw new Error("Invalid group");l="frm_fftMix",r="frm_fftJoin"}const s=Math.floor(t.byteLength/n),c=Ie(s);let d=1<<Ie(o.concurrency);s<=2*d&&(d=1);const u=s/d,g=Ie(u),f=[];for(let e=0;e<d;e++){const a=[],i=t.slice(e*u*n,(e+1)*u*n);a.push({cmd:"ALLOCSET",var:0,buff:i});for(let t=1;t<=g;t++)a.push({cmd:"CALL",fnName:l,params:[{var:0},{val:u},{val:t}]});a.push({cmd:"GET",out:0,var:0,len:u*n}),f.push(o.queueAction(a))}const h=await Promise.all(f),_=[];for(let t=0;t<h.length;t++)_[t]=h[t][0];for(let t=g+1;t<=c;t++){const e=1<<c-t,a=d/e,l=[];for(let s=0;s<e;s++)for(let e=0;e<a/2;e++){const c=i.exp(i.w[t],e*u),d=i.w[t],g=s*a+e,f=s*a+e+a/2,h=[];h.push({cmd:"ALLOCSET",var:0,buff:_[g]}),h.push({cmd:"ALLOCSET",var:1,buff:_[f]}),h.push({cmd:"ALLOCSET",var:2,buff:c}),h.push({cmd:"ALLOCSET",var:3,buff:d}),h.push({cmd:"CALL",fnName:r,params:[{var:0},{var:1},{val:u},{var:2},{var:3}]}),h.push({cmd:"GET",out:0,var:0,len:u*n}),h.push({cmd:"GET",out:1,var:1,len:u*n}),l.push(o.queueAction(h))}const s=await Promise.all(l);for(let t=0;t<e;t++)for(let e=0;e<a/2;e++){const i=t*a+e,o=t*a+e+a/2,n=s.shift();_[i]=n[0],_[o]=n[1]}}let p;p=t instanceof Se?new Se(s*n):new Uint8Array(s*n);let m=0;for(let t=0;t<d;t++)p.set(_[t],m),m+=_[t].byteLength;return p},a.fftJoin=async function(t,n,l,r){const s=3*a.F.n8;let c;if("G1"==e)c="g1m_fftJoin";else if("G2"==e)c="g2m_fftJoin";else{if("Fr"!=e)throw new Error("Invalid group");c="frm_fftJoin"}if(t.byteLength!=n.byteLength)throw new Error("Invalid buffer size");const d=Math.floor(t.byteLength/s);if(d!=1<<Ie(d))throw new Error("Invalid number of points");let u=1<<Ie(o.concurrency);d<=2*u&&(u=1);const g=d/u,f=[];for(let e=0;e<u;e++){const a=[],d=i.mul(l,i.exp(r,e*g)),u=t.slice(e*g*s,(e+1)*g*s),h=n.slice(e*g*s,(e+1)*g*s);a.push({cmd:"ALLOCSET",var:0,buff:u}),a.push({cmd:"ALLOCSET",var:1,buff:h}),a.push({cmd:"ALLOCSET",var:2,buff:d}),a.push({cmd:"ALLOCSET",var:3,buff:r}),a.push({cmd:"CALL",fnName:c,params:[{var:0},{var:1},{val:g},{var:2},{var:3}]}),a.push({cmd:"GET",out:0,var:0,len:g*s}),a.push({cmd:"GET",out:1,var:1,len:g*s}),f.push(o.queueAction(a))}const h=await Promise.all(f);let _,p;t instanceof Se?(_=new Se(d*s),p=new Se(d*s)):(_=new Uint8Array(d*s),p=new Uint8Array(d*s));let m=0;for(let t=0;t<h.length;t++)_.set(h[t][0],m),p.set(h[t][1],m),m+=h[t][0].byteLength;return[_,p]},a.fftFinal=async function(t,i){const n=3*a.F.n8,l=2*a.F.n8;let r,s;if("G1"==e)r="g1m_fftFinal",s="g1m_batchToAffine";else{if("G2"!=e)throw new Error("Invalid group");r="g2m_fftFinal",s="g2m_batchToAffine"}const c=Math.floor(t.byteLength/n);if(c!=1<<Ie(c))throw new Error("Invalid number of points");const d=Math.floor(c/o.concurrency),u=[];for(let e=0;e<o.concurrency;e++){let a;if(a=e<o.concurrency-1?d:c-e*d,0==a)continue;const g=[],f=t.slice(e*d*n,(e*d+a)*n);g.push({cmd:"ALLOCSET",var:0,buff:f}),g.push({cmd:"ALLOCSET",var:1,buff:i}),g.push({cmd:"CALL",fnName:r,params:[{var:0},{val:a},{var:1}]}),g.push({cmd:"CALL",fnName:s,params:[{var:0},{val:a},{var:0}]}),g.push({cmd:"GET",out:0,var:0,len:a*l}),u.push(o.queueAction(g))}const g=await Promise.all(u);let f;f=t instanceof Se?new Se(c*l):new Uint8Array(c*l);let h=0;for(let t=g.length-1;t>=0;t--)f.set(g[t][0],h),h+=g[t][0].byteLength;return f}}async function Ke(t){const e=await ke(t.wasm,t.singleThread),a={};return a.q=i(t.wasm.q.toString()),a.r=i(t.wasm.r.toString()),a.name=t.name,a.tm=e,a.prePSize=t.wasm.prePSize,a.preQSize=t.wasm.preQSize,a.Fr=new Ge(e,"frm",t.n8r,t.r),a.F1=new Ge(e,"f1m",t.n8q,t.q),a.F2=new Oe(e,"f2m",a.F1),a.G1=new Ue(e,"g1m",a.F1,t.wasm.pG1gen,t.wasm.pG1b,t.cofactorG1),a.G2=new Ue(e,"g2m",a.F2,t.wasm.pG2gen,t.wasm.pG2b,t.cofactorG2),a.F6=new Te(e,"f6m",a.F2),a.F12=new Oe(e,"ftm",a.F6),a.Gt=a.F12,De(a,"G1"),De(a,"G2"),De(a,"Fr"),$e(a,"G1"),$e(a,"G2"),Ve(a,"G1"),Ve(a,"G2"),Ve(a,"Fr"),function(t){const e=t.tm;t.pairing=function(a,i){e.startSyncOp();const o=e.allocBuff(t.G1.toJacobian(a)),n=e.allocBuff(t.G2.toJacobian(i)),l=e.alloc(t.Gt.n8);e.instance.exports[t.name+"_pairing"](o,n,l);const r=e.getBuff(l,t.Gt.n8);return e.endSyncOp(),r},t.pairingEq=async function(){let a,i;arguments.length%2==1?(a=arguments[arguments.length-1],i=(arguments.length-1)/2):(a=t.Gt.one,i=arguments.length/2);const o=[];for(let a=0;a<i;a++){const i=[],n=t.G1.toJacobian(arguments[2*a]);i.push({cmd:"ALLOCSET",var:0,buff:n}),i.push({cmd:"ALLOC",var:1,len:t.prePSize});const l=t.G2.toJacobian(arguments[2*a+1]);i.push({cmd:"ALLOCSET",var:2,buff:l}),i.push({cmd:"ALLOC",var:3,len:t.preQSize}),i.push({cmd:"ALLOC",var:4,len:t.Gt.n8}),i.push({cmd:"CALL",fnName:t.name+"_prepareG1",params:[{var:0},{var:1}]}),i.push({cmd:"CALL",fnName:t.name+"_prepareG2",params:[{var:2},{var:3}]}),i.push({cmd:"CALL",fnName:t.name+"_millerLoop",params:[{var:1},{var:3},{var:4}]}),i.push({cmd:"GET",out:0,var:4,len:t.Gt.n8}),o.push(e.queueAction(i))}const n=await Promise.all(o);e.startSyncOp();const l=e.alloc(t.Gt.n8);e.instance.exports.ftm_one(l);for(let t=0;t<n.length;t++){const a=e.allocBuff(n[t][0]);e.instance.exports.ftm_mul(l,a,l)}e.instance.exports[t.name+"_finalExponentiation"](l,l);const r=e.allocBuff(a),s=!!e.instance.exports.ftm_eq(l,r);return e.endSyncOp(),s},t.prepareG1=function(t){this.tm.startSyncOp();const e=this.tm.allocBuff(t),a=this.tm.alloc(this.prePSize);this.tm.instance.exports[this.name+"_prepareG1"](e,a);const i=this.tm.getBuff(a,this.prePSize);return this.tm.endSyncOp(),i},t.prepareG2=function(t){this.tm.startSyncOp();const e=this.tm.allocBuff(t),a=this.tm.alloc(this.preQSize);this.tm.instance.exports[this.name+"_prepareG2"](e,a);const i=this.tm.getBuff(a,this.preQSize);return this.tm.endSyncOp(),i},t.millerLoop=function(t,e){this.tm.startSyncOp();const a=this.tm.allocBuff(t),i=this.tm.allocBuff(e),o=this.tm.alloc(this.Gt.n8);this.tm.instance.exports[this.name+"_millerLoop"](a,i,o);const n=this.tm.getBuff(o,this.Gt.n8);return this.tm.endSyncOp(),n},t.finalExponentiation=function(t){this.tm.startSyncOp();const e=this.tm.allocBuff(t),a=this.tm.alloc(this.Gt.n8);this.tm.instance.exports[this.name+"_finalExponentiation"](e,a);const i=this.tm.getBuff(a,this.Gt.n8);return this.tm.endSyncOp(),i}}(a),a.array2buffer=function(t,e){const a=new Uint8Array(e*t.length);for(let i=0;i<t.length;i++)a.set(t[i],i*e);return a},a.buffer2array=function(t,e){const a=t.byteLength/e,i=new Array(a);for(let o=0;o<a;o++)i[o]=t.slice(o*e,o*e+e);return i},a}function je(t){return BigInt(t)}function He(t){return t<0n}function Ze(t){return 0n===t}function We(t){const e=[],a=je(t);return e.push(Number(0xFFn&a)),e.push(Number(a>>8n&0xFFn)),e.push(Number(a>>16n&0xFFn)),e.push(Number(a>>24n&0xFFn)),e}function Ye(t){const e=function(t){for(var e=[],a=0;a<t.length;a++){var i=t.charCodeAt(a);i<128?e.push(i):i<2048?e.push(192|i>>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[...aa(e.length),...e]}function Je(t){const e=[];let a=je(t);if(He(a))throw new Error("Number cannot be negative");for(;!Ze(a);)e.push(Number(0x7Fn&a)),a>>=7n;0==e.length&&e.push(0);for(let t=0;t<e.length-1;t++)e[t]=128|e[t];return e}function Xe(t){let e,a;const i=function(t){return He(t)?t.toString(2).length-1:t.toString(2).length}(t);t<0?(a=!0,e=(1n<<BigInt(i))+t):(a=!1,e=je(t));const o=7-i%7,n=(1<<7-o)-1|128,l=Je(e+((1n<<BigInt(o))-1n<<BigInt(i)));return a||(l[l.length-1]=l[l.length-1]&n),l}function ta(t){let e=je(t);if(e>0xFFFFFFFFn)throw new Error("Number too big");if(e>0x7FFFFFFFn&&(e-=0x100000000n),e<-2147483648n)throw new Error("Number too small");return Xe(e)}function ea(t){let e=je(t);if(e>0xFFFFFFFFFFFFFFFFn)throw new Error("Number too big");if(e>0x7FFFFFFFFFFFFFFFn&&(e-=0x10000000000000000n),e<-9223372036854775808n)throw new Error("Number too small");return Xe(e)}function aa(t){let e=je(t);if(e>0xFFFFFFFFn)throw new Error("Number too big");return Je(e)}function ia(t){return Array.from(t,(function(t){return("0"+(255&t).toString(16)).slice(-2)})).join("")}class oa{constructor(t){this.func=t,this.functionName=t.functionName,this.module=t.module}setLocal(t,e){const a=this.func.localIdxByName[t];if(void 0===a)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[...e,33,...aa(a)]}teeLocal(t,e){const a=this.func.localIdxByName[t];if(void 0===a)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[...e,34,...aa(a)]}getLocal(t){const e=this.func.localIdxByName[t];if(void 0===e)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[32,...aa(e)]}i64_load8_s(t,e,a){return[...t,48,void 0===a?0:a,...aa(e||0)]}i64_load8_u(t,e,a){return[...t,49,void 0===a?0:a,...aa(e||0)]}i64_load16_s(t,e,a){return[...t,50,void 0===a?1:a,...aa(e||0)]}i64_load16_u(t,e,a){return[...t,51,void 0===a?1:a,...aa(e||0)]}i64_load32_s(t,e,a){return[...t,52,void 0===a?2:a,...aa(e||0)]}i64_load32_u(t,e,a){return[...t,53,void 0===a?2:a,...aa(e||0)]}i64_load(t,e,a){return[...t,41,void 0===a?3:a,...aa(e||0)]}i64_store(t,e,a,i){let o,n,l;return Array.isArray(e)?(o=0,n=3,l=e):Array.isArray(a)?(o=e,n=3,l=a):Array.isArray(i)&&(o=e,n=a,l=i),[...t,...l,55,n,...aa(o)]}i64_store32(t,e,a,i){let o,n,l;return Array.isArray(e)?(o=0,n=2,l=e):Array.isArray(a)?(o=e,n=2,l=a):Array.isArray(i)&&(o=e,n=a,l=i),[...t,...l,62,n,...aa(o)]}i64_store16(t,e,a,i){let o,n,l;return Array.isArray(e)?(o=0,n=1,l=e):Array.isArray(a)?(o=e,n=1,l=a):Array.isArray(i)&&(o=e,n=a,l=i),[...t,...l,61,n,...aa(o)]}i64_store8(t,e,a,i){let o,n,l;return Array.isArray(e)?(o=0,n=0,l=e):Array.isArray(a)?(o=e,n=0,l=a):Array.isArray(i)&&(o=e,n=a,l=i),[...t,...l,60,n,...aa(o)]}i32_load8_s(t,e,a){return[...t,44,void 0===a?0:a,...aa(e||0)]}i32_load8_u(t,e,a){return[...t,45,void 0===a?0:a,...aa(e||0)]}i32_load16_s(t,e,a){return[...t,46,void 0===a?1:a,...aa(e||0)]}i32_load16_u(t,e,a){return[...t,47,void 0===a?1:a,...aa(e||0)]}i32_load(t,e,a){return[...t,40,void 0===a?2:a,...aa(e||0)]}i32_store(t,e,a,i){let o,n,l;return Array.isArray(e)?(o=0,n=2,l=e):Array.isArray(a)?(o=e,n=2,l=a):Array.isArray(i)&&(o=e,n=a,l=i),[...t,...l,54,n,...aa(o)]}i32_store16(t,e,a,i){let o,n,l;return Array.isArray(e)?(o=0,n=1,l=e):Array.isArray(a)?(o=e,n=1,l=a):Array.isArray(i)&&(o=e,n=a,l=i),[...t,...l,59,n,...aa(o)]}i32_store8(t,e,a,i){let o,n,l;return Array.isArray(e)?(o=0,n=0,l=e):Array.isArray(a)?(o=e,n=0,l=a):Array.isArray(i)&&(o=e,n=a,l=i),[...t,...l,58,n,...aa(o)]}call(t,...e){const a=this.module.functionIdxByName[t];if(void 0===a)throw new Error(`Function not defined: Function: ${t}`);return[...[].concat(...e),16,...aa(a)]}call_indirect(t,...e){return[...[].concat(...e),...t,17,0,0]}if(t,e,a){return a?[...t,4,64,...e,5,...a,11]:[...t,4,64,...e,11]}block(t){return[2,64,...t,11]}loop(...t){return[3,64,...[].concat(...t),11]}br_if(t,e){return[...e,13,...aa(t)]}br(t){return[12,...aa(t)]}ret(t){return[...t,15]}drop(t){return[...t,26]}i64_const(t){return[66,...ea(t)]}i32_const(t){return[65,...ta(t)]}i64_eqz(t){return[...t,80]}i64_eq(t,e){return[...t,...e,81]}i64_ne(t,e){return[...t,...e,82]}i64_lt_s(t,e){return[...t,...e,83]}i64_lt_u(t,e){return[...t,...e,84]}i64_gt_s(t,e){return[...t,...e,85]}i64_gt_u(t,e){return[...t,...e,86]}i64_le_s(t,e){return[...t,...e,87]}i64_le_u(t,e){return[...t,...e,88]}i64_ge_s(t,e){return[...t,...e,89]}i64_ge_u(t,e){return[...t,...e,90]}i64_add(t,e){return[...t,...e,124]}i64_sub(t,e){return[...t,...e,125]}i64_mul(t,e){return[...t,...e,126]}i64_div_s(t,e){return[...t,...e,127]}i64_div_u(t,e){return[...t,...e,128]}i64_rem_s(t,e){return[...t,...e,129]}i64_rem_u(t,e){return[...t,...e,130]}i64_and(t,e){return[...t,...e,131]}i64_or(t,e){return[...t,...e,132]}i64_xor(t,e){return[...t,...e,133]}i64_shl(t,e){return[...t,...e,134]}i64_shr_s(t,e){return[...t,...e,135]}i64_shr_u(t,e){return[...t,...e,136]}i64_extend_i32_s(t){return[...t,172]}i64_extend_i32_u(t){return[...t,173]}i64_clz(t){return[...t,121]}i64_ctz(t){return[...t,122]}i32_eqz(t){return[...t,69]}i32_eq(t,e){return[...t,...e,70]}i32_ne(t,e){return[...t,...e,71]}i32_lt_s(t,e){return[...t,...e,72]}i32_lt_u(t,e){return[...t,...e,73]}i32_gt_s(t,e){return[...t,...e,74]}i32_gt_u(t,e){return[...t,...e,75]}i32_le_s(t,e){return[...t,...e,76]}i32_le_u(t,e){return[...t,...e,77]}i32_ge_s(t,e){return[...t,...e,78]}i32_ge_u(t,e){return[...t,...e,79]}i32_add(t,e){return[...t,...e,106]}i32_sub(t,e){return[...t,...e,107]}i32_mul(t,e){return[...t,...e,108]}i32_div_s(t,e){return[...t,...e,109]}i32_div_u(t,e){return[...t,...e,110]}i32_rem_s(t,e){return[...t,...e,111]}i32_rem_u(t,e){return[...t,...e,112]}i32_and(t,e){return[...t,...e,113]}i32_or(t,e){return[...t,...e,114]}i32_xor(t,e){return[...t,...e,115]}i32_shl(t,e){return[...t,...e,116]}i32_shr_s(t,e){return[...t,...e,117]}i32_shr_u(t,e){return[...t,...e,118]}i32_rotl(t,e){return[...t,...e,119]}i32_rotr(t,e){return[...t,...e,120]}i32_wrap_i64(t){return[...t,167]}i32_clz(t){return[...t,103]}i32_ctz(t){return[...t,104]}unreachable(){return[0]}current_memory(){return[63,0]}comment(){return[]}}const na={i32:127,i64:126,f32:125,f64:124,anyfunc:112,func:96,emptyblock:64};class la{constructor(t,e,a,i,o){if("import"==a)this.fnType="import",this.moduleName=i,this.fieldName=o;else{if("internal"!=a)throw new Error("Invalid function fnType: "+a);this.fnType="internal"}this.module=t,this.fnName=e,this.params=[],this.locals=[],this.localIdxByName={},this.code=[],this.returnType=null,this.nextLocal=0}addParam(t,e){if(this.localIdxByName[t])throw new Error(`param already exists. Function: ${this.fnName}, Param: ${t} `);const a=this.nextLocal++;this.localIdxByName[t]=a,this.params.push({type:e})}addLocal(t,e,a){const i=a||1;if(this.localIdxByName[t])throw new Error(`local already exists. Function: ${this.fnName}, Param: ${t} `);const o=this.nextLocal++;this.localIdxByName[t]=o,this.locals.push({type:e,length:i})}setReturnType(t){if(this.returnType)throw new Error(`returnType already defined. Function: ${this.fnName}`);this.returnType=t}getSignature(){return[96,...[...aa(this.params.length),...this.params.map((t=>na[t.type]))],...this.returnType?[1,na[this.returnType]]:[0]]}getBody(){const t=this.locals.map((t=>[...aa(t.length),na[t.type]])),e=[...aa(this.locals.length),...[].concat(...t),...this.code,11];return[...aa(e.length),...e]}addCode(...t){this.code.push(...[].concat(...t))}getCodeBuilder(){return new oa(this)}}class ra{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([...We(1836278016),...We(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 la(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 la(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_"+ia(e)]=0,this.signatures.push(e)}for(let e=0;e<this.functions.length;e++){const a=this.functions[e].getSignature(),i="s_"+ia(a);void 0===t[i]&&(t[i]=this.signatures.length,this.signatures.push(a)),this.functions[e].signatureIdx=t[i]}}_buildSection(t,e){return[t,...aa(e.length),...e]}_buildType(){return this._buildSection(1,[...aa(this.signatures.length),...[].concat(...this.signatures)])}_buildImport(){const t=[];t.push([...Ye(this.memory.moduleName),...Ye(this.memory.fieldName),2,0,...aa(this.memory.pagesSize)]);for(let e=0;e<this.nImportFunctions;e++)t.push([...Ye(this.functions[e].moduleName),...Ye(this.functions[e].fieldName),0,...aa(this.functions[e].signatureIdx)]);return this._buildSection(2,aa(t.length).concat(...t))}_buildFunctionDeclarations(){const t=[];for(let e=this.nImportFunctions;e<this.nImportFunctions+this.nInternalFunctions;e++)t.push(...aa(this.functions[e].signatureIdx));return this._buildSection(3,[...aa(t.length),...t])}_buildFunctionsTable(){return 0==this.functionsTable.length?[]:this._buildSection(4,[...aa(1),112,0,...aa(this.functionsTable.length)])}_buildElements(){if(0==this.functionsTable.length)return[];const t=[];for(let e=0;e<this.functionsTable.length;e++)t.push(...aa(this.functionsTable[e]));return this._buildSection(9,[...aa(1),...aa(0),65,...ta(0),11,...aa(this.functionsTable.length),...t])}_buildExports(){const t=[];for(let e=0;e<this.exports.length;e++)t.push([...Ye(this.exports[e].exportName),0,...aa(this.exports[e].idx)]);return this._buildSection(7,aa(t.length).concat(...t))}_buildCode(){const t=[];for(let e=this.nImportFunctions;e<this.nImportFunctions+this.nInternalFunctions;e++)t.push(this.functions[e].getBody());return this._buildSection(10,aa(t.length).concat(...t))}_buildData(){const t=[];t.push([0,65,0,11,4,...We(this.free)]);for(let e=0;e<this.datas.length;e++)t.push([0,65,...ta(this.datas[e].offset),11,...aa(this.datas[e].bytes.length),...this.datas[e].bytes]);return this._buildSection(11,aa(t.length).concat(...t))}}async function sa(t,e){if(!t&&globalThis.curve_bn128)return globalThis.curve_bn128;const a=new ra;a.setMemory(25),we(a),e&&e(a);const o={};o.code=a.build(),o.pq=a.modules.f1m.pq,o.pr=a.modules.frm.pq,o.pG1gen=a.modules.bn128.pG1gen,o.pG1zero=a.modules.bn128.pG1zero,o.pG1b=a.modules.bn128.pG1b,o.pG2gen=a.modules.bn128.pG2gen,o.pG2zero=a.modules.bn128.pG2zero,o.pG2b=a.modules.bn128.pG2b,o.pOneT=a.modules.bn128.pOneT,o.prePSize=a.modules.bn128.prePSize,o.preQSize=a.modules.bn128.preQSize,o.n8q=32,o.n8r=32,o.q=a.modules.bn128.q,o.r=a.modules.bn128.r;const n={name:"bn128",wasm:o,q:i("21888242871839275222246405745257275088696311157297823662689037894645226208583"),r:i("21888242871839275222246405745257275088548364400416034343698204186575808495617"),n8q:32,n8r:32,cofactorG2:i("30644e72e131a029b85045b68181585e06ceecda572a2489345f2299c0f9fa8d",16),singleThread:!!t},l=await Ke(n);return l.terminate=async function(){n.singleThread||(globalThis.curve_bn128=null,await this.tm.terminate())},t||(globalThis.curve_bn128=l),l}async function ca(t,e){if(!t&&globalThis.curve_bls12381)return globalThis.curve_bls12381;const a=new ra;a.setMemory(25),Le(a),e&&e(a);const o={};o.code=a.build(),o.pq=a.modules.f1m.pq,o.pr=a.modules.frm.pq,o.pG1gen=a.modules.bls12381.pG1gen,o.pG1zero=a.modules.bls12381.pG1zero,o.pG1b=a.modules.bls12381.pG1b,o.pG2gen=a.modules.bls12381.pG2gen,o.pG2zero=a.modules.bls12381.pG2zero,o.pG2b=a.modules.bls12381.pG2b,o.pOneT=a.modules.bls12381.pOneT,o.prePSize=a.modules.bls12381.prePSize,o.preQSize=a.modules.bls12381.preQSize,o.n8q=48,o.n8r=32,o.q=a.modules.bls12381.q,o.r=a.modules.bls12381.r;const n={name:"bls12381",wasm:o,q:i("1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab",16),r:i("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",16),n8q:48,n8r:32,cofactorG1:i("0x396c8c005555e1568c00aaab0000aaab",16),cofactorG2:i("0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5",16),singleThread:!!t},l=await Ke(n);return l.terminate=async function(){n.singleThread||(globalThis.curve_bls12381=null,await this.tm.terminate())},t||(globalThis.curve_bls12381=l),l}globalThis.curve_bn128=null,globalThis.curve_bls12381=null;const da=i("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",16),ua=i("21888242871839275222246405745257275088548364400416034343698204186575808495617");i("1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab",16),i("21888242871839275222246405745257275088696311157297823662689037894645226208583");const ga=O,fa=ve;var ha={};async function _a(t,e,a,i){if(a=a||262144,"number"!=typeof e&&["w+","wx+","r","ax+","a+"].indexOf(e)<0)throw new Error("Invalid open option");const o=await ha.promises.open(t,e),n=await o.stat();return new pa(o,n,a,i,t)}class pa{constructor(t,e,a,i,o){for(this.fileName=o,this.fd=t,this.pos=0,this.pageSize=i||256;this.pageSize<e.blksize;)this.pageSize*=2;this.totalSize=e.size,this.totalPages=Math.floor((e.size-1)/this.pageSize)+1,this.maxPagesLoaded=Math.floor(a/this.pageSize)+1,this.pages={},this.pendingLoads=[],this.writing=!1,this.reading=!1,this.avBuffs=[],this.history={}}_loadPage(t){const e=this,a=new Promise(((a,i)=>{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<i.pendingLoads.length;t++)i.pendingLoads[t].page==e&&(o=o+" "+t);if(o&&a.push("Pending loads:"+o),void 0!==i.pages[e]){const t=i.pages[e];a.push("Loaded"),a.push("pendingOps: "+t.pendingOps),t.loading&&a.push("loading: "+t.loading),t.writing&&a.push("writing"),t.dirty&&a.push("dirty")}a.push("=="),i.history[e]||(i.history[e]=[]),i.history[e].push(a)}__printHistory(t){const e=this;e.history[t]||console.log("Empty History ",t),console.log("History "+t);for(let a=0;a<e.history[t].length;a++)for(let i=0;i<e.history[t][a].length;i++)console.log("-> "+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;i<e.length;i++){const o=t.pages[parseInt(e[i])];0!=o.dirty||0!=o.pendingOps||o.writing||o.loading||a.push(parseInt(e[i]))}let i=t.maxPagesLoaded-e.length;const o=[];for(;t.pendingLoads.length>0&&(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<i.length;t++)i[t].resolve();return t.__statusPage("After Load (loaded): ",e.page),a}),(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<e.length;i++){const o=t.pages[parseInt(e[i])];o.dirty&&(o.dirty=!1,o.writing=!0,t.writing=!0,a.push(t.fd.write(o.buff,0,o.size,parseInt(e[i])*t.pageSize).then((()=>{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.totalSize<e+t.byteLength&&(a.totalSize=e+t.byteLength),a.pendingClose)throw new Error("Writing a closing file");const i=Math.floor(e/a.pageSize),o=Math.floor((e+t.byteLength-1)/a.pageSize),n=[];for(let t=i;t<=o;t++)n.push(a._loadPage(t));a._triggerLoad();let l=i,r=e%a.pageSize,s=t.byteLength;for(;s>0;){await n[l-i];const e=r+s>a.pageSize?a.pageSize-r:s,o=t.slice(t.byteLength-s,t.byteLength-s+e);new Uint8Array(a.pages[l].buff.buffer,r,e).set(o),a.pages[l].dirty=!0,a.pages[l].pendingOps--,a.pages[l].size=Math.max(r+e,a.pages[l].size),l>=a.totalPages&&(a.totalPages=l+1),s-=e,l++,r=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),l=Math.floor((i+a-1)/o.pageSize),r=[];for(let t=n;t<=l;t++)r.push(o._loadPage(t));o._triggerLoad();let s=n,c=i%o.pageSize,d=i+a>o.totalSize?a-(i+a-o.totalSize):a;for(;d>0;){await r[s-n],o.__statusPage("After Await (read): ",s);const i=c+d>o.pageSize?o.pageSize-c:d,l=new Uint8Array(o.pages[s].buff.buffer,o.pages[s].buff.byteOffset+c,i);t.set(l,e+a-d),o.pages[s].pendingOps--,o.__statusPage("After Op done: ",s),d-=i,s++,c=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 ha.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]}async readString(t){const e=this;if(e.pendingClose)throw new Error("Reading a closing file");let a=void 0===t?e.pos:t,i=Math.floor(a/e.pageSize),o=!1,n="";for(;!o;){let t=e._loadPage(i);e._triggerLoad(),await t,e.__statusPage("After Await (read): ",i);let l=a%e.pageSize;const r=new Uint8Array(e.pages[i].buff.buffer,e.pages[i].buff.byteOffset+l,e.pageSize-l);let s=r.findIndex((t=>0===t));o=-1!==s,o?(n+=(new TextDecoder).decode(r.slice(0,s)),e.pos=i*this.pageSize+l+s+1):(n+=(new TextDecoder).decode(r),e.pos=i*this.pageSize+l+r.length),e.pages[i].pendingOps--,e.__statusPage("After Op done: ",i),a=e.pos,i++,e.pendingLoads.length>0&&setImmediate(e._triggerLoad.bind(e))}return n}}const ma=new Uint8Array(4),wa=new DataView(ma.buffer),La=new Uint8Array(8),ba=new DataView(La.buffer);class ya{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){wa.setUint32(0,t,!0),await this.write(ma,e)}async writeUBE32(t,e){wa.setUint32(0,t,!1),await this.write(ma,e)}async writeULE64(t,e){ba.setUint32(0,4294967295&t,!0),ba.setUint32(4,Math.floor(t/4294967296),!0),await this.write(La,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 readString(t){const e=this;let a=void 0===t?e.pos:t;if(a>this.totalSize){if(this.readOnly)throw new Error("Reading out of bounds");this._resizeIfNeeded(t)}const i=new Uint8Array(e.o.data.buffer,a,this.totalSize-a);let o=i.findIndex((t=>0===t)),n="";return-1!==o?(n=(new TextDecoder).decode(i.slice(0,o)),e.pos=a+o+1):e.pos=a,n}}const Aa=1<<22;const Ca=new Uint8Array(4),Ia=new DataView(Ca.buffer),Fa=new Uint8Array(8),xa=new DataView(Fa.buffer);class Ea{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)/Aa)+1;for(let a=Math.max(this.o.data.length-1,0);a<e;a++){const i=new Uint8Array(a<e-1?Aa:t-(e-1)*Aa);a==this.o.data.length-1&&i.set(this.o.data[a]),this.o.data[a]=i}this.totalSize=t}async write(t,e){const a=this;if(void 0===e&&(e=a.pos),this.readOnly)throw new Error("Writing a read only file");this._resizeIfNeeded(e+t.byteLength);let i=Math.floor(e/Aa),o=e%Aa,n=t.byteLength;for(;n>0;){const e=o+n>Aa?Aa-o:n,l=t.slice(t.byteLength-n,t.byteLength-n+e);new Uint8Array(a.o.data[i].buffer,o,e).set(l),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/Aa),l=i%Aa,r=a;for(;r>0;){const i=l+r>Aa?Aa-l:r,s=new Uint8Array(o.o.data[n].buffer,l,i);t.set(s,e+a-r),r-=i,n++,l=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){Ia.setUint32(0,t,!0),await this.write(Ca,e)}async writeUBE32(t,e){Ia.setUint32(0,t,!1),await this.write(Ca,e)}async writeULE64(t,e){xa.setUint32(0,4294967295&t,!0),xa.setUint32(4,Math.floor(t/4294967296),!0),await this.write(Fa,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 readString(t){const e=this;let a=void 0===t?e.pos:t;if(a>this.totalSize){if(this.readOnly)throw new Error("Reading out of bounds");this._resizeIfNeeded(t)}let i=!1,o="";for(;!i;){let t=Math.floor(a/Aa),n=a%Aa;if(void 0===e.o.data[t])throw new Error("ERROR");let l=Math.min(2048,e.o.data[t].length-n);const r=new Uint8Array(e.o.data[t].buffer,n,l);let s=r.findIndex((t=>0===t));i=-1!==s,i?(o+=(new TextDecoder).decode(r.slice(0,s)),e.pos=t*Aa+n+s+1):(o+=(new TextDecoder).decode(r),e.pos=t*Aa+n+r.length),a=e.pos}return o}}const va=1024,Ba=512,Sa=2,Pa=0,Ga=65536,Oa=8192;async function Ta(t,e,a){if("string"==typeof t&&(t={type:"file",fileName:t,cacheSize:e||Ga,pageSize:a||Oa}),"file"==t.type)return await _a(t.fileName,va|Ba|Sa,t.cacheSize,t.pageSize);if("mem"==t.type)return function(t){const e=t.initialSize||1<<20,a=new ya;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 Ea;a.o=t;const i=e?Math.floor((e-1)/Aa)+1:0;a.o.data=[];for(let t=0;t<i-1;t++)a.o.data.push(new Uint8Array(Aa));return i&&a.o.data.push(new Uint8Array(e-Aa*(i-1))),a.totalSize=0,a.readOnly=!1,a.pos=0,a}(t);throw new Error("Invalid FastFile type: "+t.type)}async function Ua(t,e,a){if(t instanceof Uint8Array&&(t={type:"mem",data:t}),"string"==typeof t){t={type:"mem",data:await fetch(t).then((function(t){return t.arrayBuffer()})).then((function(t){return new Uint8Array(t)}))}}if("file"==t.type)return await _a(t.fileName,Pa,t.cacheSize,t.pageSize);if("mem"==t.type)return await function(t){const e=new ya;return e.o=t,e.allocSize=t.data.byteLength,e.totalSize=t.data.byteLength,e.readOnly=!0,e.pos=0,e}(t);if("bigMem"==t.type)return await function(t){const e=new Ea;return e.o=t,e.totalSize=(t.data.length-1)*Aa+t.data[t.data.length-1].byteLength,e.readOnly=!0,e.pos=0,e}(t);throw new Error("Invalid FastFile type: "+t.type)}async function za(t,e,a,i,o){const n=await Ua(t),l=await n.read(4);let r="";for(let t=0;t<4;t++)r+=String.fromCharCode(l[t]);if(r!=e)throw new Error(t+": Invalid File format");if(await n.readULE32()>a)throw new Error("Version not supported");const s=await n.readULE32();let c=[];for(let t=0;t<s;t++){let t=await n.readULE32(),e=await n.readULE64();void 0===c[t]&&(c[t]=[]),c[t].push({p:n.pos,size:e}),n.pos+=e}return{fd:n,sections:c}}async function Qa(t,e,a,i,o,n){const l=await Ta(t,o,n),r=new Uint8Array(4);for(let t=0;t<4;t++)r[t]=e.charCodeAt(t);return await l.write(r,0),await l.writeULE32(a),await l.writeULE32(i),l}async function qa(t,e){if(void 0!==t.writingSection)throw new Error("Already writing a section");await t.writeULE32(e),t.writingSection={pSectionSize:t.pos},await t.writeULE64(0)}async function Ma(t){if(void 0===t.writingSection)throw new Error("Not writing a section");const e=t.pos-t.writingSection.pSectionSize-8,a=t.pos;t.pos=t.writingSection.pSectionSize,await t.writeULE64(e),t.pos=a,delete t.writingSection}async function ka(t,e,a){if(void 0!==t.readingSection)throw new Error("Already reading a section");if(!e[a])throw new Error(t.fileName+": Missing section "+a);if(e[a].length>1)throw new Error(t.fileName+": Section Duplicated "+a);t.pos=e[a][0].p,t.readingSection=e[a][0]}async function Ra(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 Da(t,e,a,i){const o=new Uint8Array(a);ga.toRprLE(o,0,e,a),await t.write(o,i)}async function Na(t,e,a){const i=await t.read(e,a);return ga.fromRprLE(i,0,e)}async function $a(t,e,a,i,o){void 0===o&&(o=e[i][0].size);const n=t.pageSize;await ka(t,e,i),await qa(a,i);for(let e=0;e<o;e+=n){const i=Math.min(o-e,n),l=await t.read(i);await a.write(l)}await Ma(a),await Ra(t,o!=e[i][0].size)}async function Va(t,e,a,i,o){if((i=void 0===i?0:i)+(o=void 0===o?e[a][0].size-i:o)>e[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 Se(o),await t.readToBuffer(n,0,o,e[a][0].p+i),n}async function Ka(t,e,a,i,o){const n=16*t.pageSize;if(await ka(t,e,o),await ka(a,i,o),e[o][0].size!=i[o][0].size)return!1;const l=e[o][0].size;for(let e=0;e<l;e+=n){const i=Math.min(l-e,n),o=await t.read(i),r=await a.read(i);for(let t=0;t<i;t++)if(o[t]!=r[t])return!1}return await Ra(t),await Ra(a),!0}const ja=ga.e("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",16),Ha=ga.e("21888242871839275222246405745257275088548364400416034343698204186575808495617"),Za=ga.e("1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab",16),Wa=ga.e("21888242871839275222246405745257275088696311157297823662689037894645226208583");async function Ya(t){let e;if(ga.eq(t,Wa))e=await sa();else{if(!ga.eq(t,Za))throw new Error(`Curve not supported: ${ga.toString(t)}`);e=await ca()}return e}async function Ja(t){let e;const a=t.toUpperCase().match(/[A-Za-z0-9]+/g).join("");if(["BN128","BN254","ALTBN128"].indexOf(a)>=0)e=await sa();else{if(!(["BLS12381"].indexOf(a)>=0))throw new Error(`Curve not supported: ${t}`);e=await ca()}return e}var Xa="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},ti={exports:{}},ei=function t(e,a){if(!e){var i=new ai(a);throw Error.captureStackTrace&&Error.captureStackTrace(i,t),i}};class ai extends Error{}ai.prototype.name="AssertionError";var ii={exports:{}};function oi(t){return t.length}var ni={byteLength:oi,toString:function(t){const e=t.byteLength;let a="";for(let i=0;i<e;i++)a+=String.fromCharCode(t[i]);return a},write:function(t,e,a=0,i=oi(e)){const o=Math.min(i,t.byteLength-a);for(let i=0;i<o;i++)t[a+i]=e.charCodeAt(i);return o}};const li="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ri=new Uint8Array(256);for(let t=0;t<64;t++)ri[li.charCodeAt(t)]=t;function si(t){let e=t.length;return 61===t.charCodeAt(e-1)&&e--,e>1&&61===t.charCodeAt(e-1)&&e--,3*e>>>2}ri[45]=62,ri[95]=63;var ci={byteLength:si,toString:function(t){const e=t.byteLength;let a="";for(let i=0;i<e;i+=3)a+=li[t[i]>>2]+li[(3&t[i])<<4|t[i+1]>>4]+li[(15&t[i+1])<<2|t[i+2]>>6]+li[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=si(e)){const o=Math.min(i,t.byteLength-a);for(let a=0,i=0;i<o;a+=4){const o=ri[e.charCodeAt(a)],n=ri[e.charCodeAt(a+1)],l=ri[e.charCodeAt(a+2)],r=ri[e.charCodeAt(a+3)];t[i++]=o<<2|n>>4,t[i++]=(15&n)<<4|l>>2,t[i++]=(3&l)<<6|63&r}return o}};function di(t){return t.length>>>1}var ui={byteLength:di,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<o;i+=4)a+=t.getUint32(i).toString(16).padStart(8,"0");for(;i<e;i++)a+=t.getUint8(i).toString(16).padStart(2,"0");return a},write:function(t,e,a=0,i=di(e)){const o=Math.min(i,t.byteLength-a);for(let i=0;i<o;i++){const o=gi(e.charCodeAt(2*i)),n=gi(e.charCodeAt(2*i+1));if(void 0===o||void 0===n)return t.subarray(0,i);t[a+i]=o<<4|n}return o}};function gi(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-65+10:t>=97&&t<=102?t-97+10:void 0}function fi(t){let e=0;for(let a=0,i=t.length;a<i;a++){const o=t.charCodeAt(a);if(o>=55296&&o<=56319&&a+1<i){const i=t.charCodeAt(a+1);if(i>=56320&&i<=57343){e+=4,a++;continue}}e+=o<=127?1:o<=2047?2:3}return e}let hi,_i;if("undefined"!=typeof TextDecoder){const t=new TextDecoder;hi=function(e){return t.decode(e)}}else hi=function(t){const e=t.byteLength;let a="",i=0;for(;i<e;){let o=t[i];if(o<=127){a+=String.fromCharCode(o),i++;continue}let n=0,l=0;if(o<=223?(n=1,l=31&o):o<=239?(n=2,l=15&o):o<=244&&(n=3,l=7&o),e-i-n>0){let e=0;for(;e<n;)o=t[i+e+1],l=l<<6|63&o,e+=1}else l=65533,n=e-i;a+=String.fromCodePoint(l),i+=n+1}return a};if("undefined"!=typeof TextEncoder){const t=new TextEncoder;_i=function(e,a,i=0,o=fi(a)){const n=Math.min(o,e.byteLength-i);return t.encodeInto(a,e.subarray(i,i+n)),n}}else _i=function(t,e,a=0,i=fi(e)){const o=Math.min(i,t.byteLength-a);t=t.subarray(a,a+o);let n=0,l=0;for(;n<e.length;){const a=e.codePointAt(n);if(a<=127){t[l++]=a,n++;continue}let i=0,o=0;for(a<=2047?(i=6,o=192):a<=65535?(i=12,o=224):a<=2097151&&(i=18,o=240),t[l++]=o|a>>i,i-=6;i>=0;)t[l++]=128|a>>i&63,i-=6;n+=a>=65536?2:1}return o};var pi={byteLength:fi,toString:hi,write:_i};function mi(t){return 2*t.length}var wi,Li,bi={byteLength:mi,toString:function(t){const e=t.byteLength;let a="";for(let i=0;i<e-1;i+=2)a+=String.fromCharCode(t[i]+256*t[i+1]);return a},write:function(t,e,a=0,i=mi(e)){const o=Math.min(i,t.byteLength-a);let n=o;for(let i=0;i<e.length&&!((n-=2)<0);++i){const o=e.charCodeAt(i),n=o>>8,l=o%256;t[a+2*i]=l,t[a+2*i+1]=n}return o}};!function(t,e){const a=ni,i=ci,o=ui,n=pi,l=bi,r=255===new Uint8Array(Uint16Array.of(255).buffer)[0];function s(t){switch(t){case"ascii":return a;case"base64":return i;case"hex":return o;case"utf8":case"utf-8":case void 0:return n;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return l;default:throw new Error(`Unknown encoding: ${t}`)}}function c(t){return t instanceof Uint8Array}function d(t,e,a){return"string"==typeof t?function(t,e){const a=s(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 u(t,e,a,i,o){if(0===t.byteLength)return-1;if("string"==typeof a?(i=a,a=0):void 0===a?a=o?0:t.length-1:a<0&&(a+=t.byteLength),a>=t.byteLength){if(o)return-1;a=t.byteLength-1}else if(a<0){if(!o)return-1;a=0}if("string"==typeof e)e=d(e,i);else if("number"==typeof e)return e&=255,o?t.indexOf(e,a):t.lastIndexOf(e,a);if(0===e.byteLength)return-1;if(o){let i=-1;for(let o=a;o<t.byteLength;o++)if(t[o]===e[-1===i?0:o-i]){if(-1===i&&(i=o),o-i+1===e.byteLength)return i}else-1!==i&&(o-=o-i),i=-1}else{a+e.byteLength>t.byteLength&&(a=t.byteLength-e.byteLength);for(let i=a;i>=0;i--){let a=!0;for(let o=0;o<e.byteLength;o++)if(t[i+o]!==e[o]){a=!1;break}if(a)return i}}return-1}function g(t,e,a,i){return u(t,e,a,i,!0)}function f(t,e,a){const i=t[e];t[e]=t[a],t[a]=i}t.exports=e={isBuffer:c,isEncoding:function(t){try{return s(t),!0}catch{return!1}},alloc:function(t,a,i){const o=new Uint8Array(t);return void 0!==a&&e.fill(o,a,0,o.byteLength,i),o},allocUnsafe:function(t){return new Uint8Array(t)},allocUnsafeSlow:function(t){return new Uint8Array(t)},byteLength:function(t,e){return s(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;i<o;i+=4){if(t.getUint32(i,r)!==e.getUint32(i,r))break}for(;i<a;i++){const a=t.getUint8(i),o=e.getUint8(i);if(a<o)return-1;if(a>o)return 1}return t.byteLength>e.byteLength?1:t.byteLength<e.byteLength?-1:0},concat:function(t,e){void 0===e&&(e=t.reduce(((t,e)=>t+e.byteLength),0));const a=new Uint8Array(e);let i=0;for(const e of t){if(i+e.byteLength>a.byteLength){const t=e.subarray(0,a.byteLength-i);return a.set(t,i),a}a.set(e,i),i+=e.byteLength}return a},copy:function(t,e,a=0,i=0,o=t.byteLength){if(o>0&&o<i)return 0;if(o===i)return 0;if(0===t.byteLength||0===e.byteLength)return 0;if(a<0)throw new RangeError("targetStart is out of range");if(i<0||i>=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&&(o=e.length-a+i);const n=o-i;return t===e?e.copyWithin(a,i,o):e.set(t.subarray(i,o),a),n},equals:function(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;const a=t.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;i<o;i+=4)if(t.getUint32(i,r)!==e.getUint32(i,r))return!1;for(;i<a;i++)if(t.getUint8(i)!==e.getUint8(i))return!1;return!0},fill:function(t,e,a,i,o){if("string"==typeof e?"string"==typeof a?(o=a,a=0,i=t.byteLength):"string"==typeof i&&(o=i,i=t.byteLength):"number"==typeof e?e&=255:"boolean"==typeof e&&(e=+e),a<0||t.byteLength<a||t.byteLength<i)throw new RangeError("Out of range index");if(void 0===a&&(a=0),void 0===i&&(i=t.byteLength),i<=a)return t;if(e||(e=0),"number"==typeof e)for(let o=a;o<i;++o)t[o]=e;else{const n=(e=c(e)?e:d(e,o)).byteLength;for(let o=0;o<i-a;++o)t[o+a]=e[o%n]}return t},from:d,includes:function(t,e,a,i){return-1!==g(t,e,a,i)},indexOf:g,lastIndexOf:function(t,e,a,i){return u(t,e,a,i,!1)},swap16:function(t){const e=t.byteLength;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let a=0;a<e;a+=2)f(t,a,a+1);return t},swap32:function(t){const e=t.byteLength;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let a=0;a<e;a+=4)f(t,a,a+3),f(t,a+1,a+2);return t},swap64:function(t){const e=t.byteLength;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let a=0;a<e;a+=8)f(t,a,a+7),f(t,a+1,a+6),f(t,a+2,a+5),f(t,a+3,a+4);return t},toBuffer:function(t){return t},toString:function(t,e,a=0,i=t.byteLength){const o=t.byteLength;return a>=o||i<=a?"":(a<0&&(a=0),i>o&&(i=o),(0!==a||i<o)&&(t=t.subarray(a,i)),s(e).toString(t))},write:function(t,e,a,i,o){return void 0===a?o="utf8":void 0===i&&"string"==typeof a?(o=a,a=void 0):void 0===o&&"string"==typeof i&&(o=i,i=void 0),s(o).write(t,e,a,i)},writeDoubleLE:function(t,e,a){return void 0===a&&(a=0),new DataView(t.buffer,t.byteOffset,t.byteLength).setFloat64(a,e,!0),a+8},writeFloatLE:function(t,e,a){return void 0===a&&(a=0),new DataView(t.buffer,t.byteOffset,t.byteLength).setFloat32(a,e,!0),a+4},writeUInt32LE:function(t,e,a){return void 0===a&&(a=0),new DataView(t.buffer,t.byteOffset,t.byteLength).setUint32(a,e,!0),a+4},writeInt32LE:function(t,e,a){return void 0===a&&(a=0),new DataView(t.buffer,t.byteOffset,t.byteLength).setInt32(a,e,!0),a+4},readDoubleLE:function(t,e){return void 0===e&&(e=0),new DataView(t.buffer,t.byteOffset,t.byteLength).getFloat64(e,!0)},readFloatLE:function(t,e){return void 0===e&&(e=0),new DataView(t.buffer,t.byteOffset,t.byteLength).getFloat32(e,!0)},readUInt32LE:function(t,e){return void 0===e&&(e=0),new DataView(t.buffer,t.byteOffset,t.byteLength).getUint32(e,!0)},readInt32LE:function(t,e){return void 0===e&&(e=0),new DataView(t.buffer,t.byteOffset,t.byteLength).getInt32(e,!0)}}}(ii,ii.exports);var yi=ei,Ai=ii.exports,Ci=null,Ii="undefined"!=typeof WebAssembly&&function(){if(Li)return wi;Li=1;var t=(()=>{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<a;){var l=t[e.charCodeAt(o++)],r=t[e.charCodeAt(o++)],s=t[e.charCodeAt(o++)],c=t[e.charCodeAt(o++)];i[n++]=l<<2|r>>4,i[n++]=r<<4|s>>2,i[n++]=s<<6|c}return i}})(),e=((t,e)=>function(){return e||(0,t[Object.keys(t)[0]])((e={exports:{}}).exports,e),e.exports})({"wasm-binary:./blake2b.wat"(e,a){a.exports=t("AGFzbQEAAAABEANgAn9/AGADf39/AGABfwADBQQAAQICBQUBAQroBwdNBQZtZW1vcnkCAAxibGFrZTJiX2luaXQAAA5ibGFrZTJiX3VwZGF0ZQABDWJsYWtlMmJfZmluYWwAAhBibGFrZTJiX2NvbXByZXNzAAMKvz8EwAIAIABCADcDACAAQgA3AwggAEIANwMQIABCADcDGCAAQgA3AyAgAEIANwMoIABCADcDMCAAQgA3AzggAEIANwNAIABCADcDSCAAQgA3A1AgAEIANwNYIABCADcDYCAAQgA3A2ggAEIANwNwIABCADcDeCAAQoiS853/zPmE6gBBACkDAIU3A4ABIABCu86qptjQ67O7f0EIKQMAhTcDiAEgAEKr8NP0r+68tzxBECkDAIU3A5ABIABC8e30+KWn/aelf0EYKQMAhTcDmAEgAELRhZrv+s+Uh9EAQSApAwCFNwOgASAAQp/Y+dnCkdqCm39BKCkDAIU3A6gBIABC6/qG2r+19sEfQTApAwCFNwOwASAAQvnC+JuRo7Pw2wBBOCkDAIU3A7gBIABCADcDwAEgAEIANwPIASAAQgA3A9ABC20BA38gAEHAAWohAyAAQcgBaiEEIAQpAwCnIQUCQANAIAEgAkYNASAFQYABRgRAIAMgAykDACAFrXw3AwBBACEFIAAQAwsgACAFaiABLQAAOgAAIAVBAWohBSABQQFqIQEMAAsLIAQgBa03AwALYQEDfyAAQcABaiEBIABByAFqIQIgASABKQMAIAIpAwB8NwMAIABCfzcD0AEgAikDAKchAwJAA0AgA0GAAUYNASAAIANqQQA6AAAgA0EBaiEDDAALCyACIAOtNwMAIAAQAwuqOwIgfgl/IABBgAFqISEgAEGIAWohIiAAQZABaiEjIABBmAFqISQgAEGgAWohJSAAQagBaiEmIABBsAFqIScgAEG4AWohKCAhKQMAIQEgIikDACECICMpAwAhAyAkKQMAIQQgJSkDACEFICYpAwAhBiAnKQMAIQcgKCkDACEIQoiS853/zPmE6gAhCUK7zqqm2NDrs7t/IQpCq/DT9K/uvLc8IQtC8e30+KWn/aelfyEMQtGFmu/6z5SH0QAhDUKf2PnZwpHagpt/IQ5C6/qG2r+19sEfIQ9C+cL4m5Gjs/DbACEQIAApAwAhESAAKQMIIRIgACkDECETIAApAxghFCAAKQMgIRUgACkDKCEWIAApAzAhFyAAKQM4IRggACkDQCEZIAApA0ghGiAAKQNQIRsgACkDWCEcIAApA2AhHSAAKQNoIR4gACkDcCEfIAApA3ghICANIAApA8ABhSENIA8gACkD0AGFIQ8gASAFIBF8fCEBIA0gAYVCIIohDSAJIA18IQkgBSAJhUIYiiEFIAEgBSASfHwhASANIAGFQhCKIQ0gCSANfCEJIAUgCYVCP4ohBSACIAYgE3x8IQIgDiAChUIgiiEOIAogDnwhCiAGIAqFQhiKIQYgAiAGIBR8fCECIA4gAoVCEIohDiAKIA58IQogBiAKhUI/iiEGIAMgByAVfHwhAyAPIAOFQiCKIQ8gCyAPfCELIAcgC4VCGIohByADIAcgFnx8IQMgDyADhUIQiiEPIAsgD3whCyAHIAuFQj+KIQcgBCAIIBd8fCEEIBAgBIVCIIohECAMIBB8IQwgCCAMhUIYiiEIIAQgCCAYfHwhBCAQIASFQhCKIRAgDCAQfCEMIAggDIVCP4ohCCABIAYgGXx8IQEgECABhUIgiiEQIAsgEHwhCyAGIAuFQhiKIQYgASAGIBp8fCEBIBAgAYVCEIohECALIBB8IQsgBiALhUI/iiEGIAIgByAbfHwhAiANIAKFQiCKIQ0gDCANfCEMIAcgDIVCGIohByACIAcgHHx8IQIgDSAChUIQiiENIAwgDXwhDCAHIAyFQj+KIQcgAyAIIB18fCEDIA4gA4VCIIohDiAJIA58IQkgCCAJhUIYiiEIIAMgCCAefHwhAyAOIAOFQhCKIQ4gCSAOfCEJIAggCYVCP4ohCCAEIAUgH3x8IQQgDyAEhUIgiiEPIAogD3whCiAFIAqFQhiKIQUgBCAFICB8fCEEIA8gBIVCEIohDyAKIA98IQogBSAKhUI/iiEFIAEgBSAffHwhASANIAGFQiCKIQ0gCSANfCEJIAUgCYVCGIohBSABIAUgG3x8IQEgDSABhUIQiiENIAkgDXwhCSAFIAmFQj+KIQUgAiAGIBV8fCECIA4gAoVCIIohDiAKIA58IQogBiAKhUIYiiEGIAIgBiAZfHwhAiAOIAKFQhCKIQ4gCiAOfCEKIAYgCoVCP4ohBiADIAcgGnx8IQMgDyADhUIgiiEPIAsgD3whCyAHIAuFQhiKIQcgAyAHICB8fCEDIA8gA4VCEIohDyALIA98IQsgByALhUI/iiEHIAQgCCAefHwhBCAQIASFQiCKIRAgDCAQfCEMIAggDIVCGIohCCAEIAggF3x8IQQgECAEhUIQiiEQIAwgEHwhDCAIIAyFQj+KIQggASAGIBJ8fCEBIBAgAYVCIIohECALIBB8IQsgBiALhUIYiiEGIAEgBiAdfHwhASAQIAGFQhCKIRAgCyAQfCELIAYgC4VCP4ohBiACIAcgEXx8IQIgDSAChUIgiiENIAwgDXwhDCAHIAyFQhiKIQcgAiAHIBN8fCECIA0gAoVCEIohDSAMIA18IQwgByAMhUI/iiEHIAMgCCAcfHwhAyAOIAOFQiCKIQ4gCSAOfCEJIAggCYVCGIohCCADIAggGHx8IQMgDiADhUIQiiEOIAkgDnwhCSAIIAmFQj+KIQggBCAFIBZ8fCEEIA8gBIVCIIohDyAKIA98IQogBSAKhUIYiiEFIAQgBSAUfHwhBCAPIASFQhCKIQ8gCiAPfCEKIAUgCoVCP4ohBSABIAUgHHx8IQEgDSABhUIgiiENIAkgDXwhCSAFIAmFQhiKIQUgASAFIBl8fCEBIA0gAYVCEIohDSAJIA18IQkgBSAJhUI/iiEFIAIgBiAdfHwhAiAOIAKFQiCKIQ4gCiAOfCEKIAYgCoVCGIohBiACIAYgEXx8IQIgDiAChUIQiiEOIAogDnwhCiAGIAqFQj+KIQYgAyAHIBZ8fCEDIA8gA4VCIIohDyALIA98IQsgByALhUIYiiEHIAMgByATfHwhAyAPIAOFQhCKIQ8gCyAPfCELIAcgC4VCP4ohByAEIAggIHx8IQQgECAEhUIgiiEQIAwgEHwhDCAIIAyFQhiKIQggBCAIIB58fCEEIBAgBIVCEIohECAMIBB8IQwgCCAMhUI/iiEIIAEgBiAbfHwhASAQIAGFQiCKIRAgCyAQfCELIAYgC4VCGIohBiABIAYgH3x8IQEgECABhUIQiiEQIAsgEHwhCyAGIAuFQj+KIQYgAiAHIBR8fCECIA0gAoVCIIohDSAMIA18IQwgByAMhUIYiiEHIAIgByAXfHwhAiANIAKFQhCKIQ0gDCANfCEMIAcgDIVCP4ohByADIAggGHx8IQMgDiADhUIgiiEOIAkgDnwhCSAIIAmFQhiKIQggAyAIIBJ8fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSAafHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgFXx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgASAFIBh8fCEBIA0gAYVCIIohDSAJIA18IQkgBSAJhUIYiiEFIAEgBSAafHwhASANIAGFQhCKIQ0gCSANfCEJIAUgCYVCP4ohBSACIAYgFHx8IQIgDiAChUIgiiEOIAogDnwhCiAGIAqFQhiKIQYgAiAGIBJ8fCECIA4gAoVCEIohDiAKIA58IQogBiAKhUI/iiEGIAMgByAefHwhAyAPIAOFQiCKIQ8gCyAPfCELIAcgC4VCGIohByADIAcgHXx8IQMgDyADhUIQiiEPIAsgD3whCyAHIAuFQj+KIQcgBCAIIBx8fCEEIBAgBIVCIIohECAMIBB8IQwgCCAMhUIYiiEIIAQgCCAffHwhBCAQIASFQhCKIRAgDCAQfCEMIAggDIVCP4ohCCABIAYgE3x8IQEgECABhUIgiiEQIAsgEHwhCyAGIAuFQhiKIQYgASAGIBd8fCEBIBAgAYVCEIohECALIBB8IQsgBiALhUI/iiEGIAIgByAWfHwhAiANIAKFQiCKIQ0gDCANfCEMIAcgDIVCGIohByACIAcgG3x8IQIgDSAChUIQiiENIAwgDXwhDCAHIAyFQj+KIQcgAyAIIBV8fCEDIA4gA4VCIIohDiAJIA58IQkgCCAJhUIYiiEIIAMgCCARfHwhAyAOIAOFQhCKIQ4gCSAOfCEJIAggCYVCP4ohCCAEIAUgIHx8IQQgDyAEhUIgiiEPIAogD3whCiAFIAqFQhiKIQUgBCAFIBl8fCEEIA8gBIVCEIohDyAKIA98IQogBSAKhUI/iiEFIAEgBSAafHwhASANIAGFQiCKIQ0gCSANfCEJIAUgCYVCGIohBSABIAUgEXx8IQEgDSABhUIQiiENIAkgDXwhCSAFIAmFQj+KIQUgAiAGIBZ8fCECIA4gAoVCIIohDiAKIA58IQogBiAKhUIYiiEGIAIgBiAYfHwhAiAOIAKFQhCKIQ4gCiAOfCEKIAYgCoVCP4ohBiADIAcgE3x8IQMgDyADhUIgiiEPIAsgD3whCyAHIAuFQhiKIQcgAyAHIBV8fCEDIA8gA4VCEIohDyALIA98IQsgByALhUI/iiEHIAQgCCAbfHwhBCAQIASFQiCKIRAgDCAQfCEMIAggDIVCGIohCCAEIAggIHx8IQQgECAEhUIQiiEQIAwgEHwhDCAIIAyFQj+KIQggASAGIB98fCEBIBAgAYVCIIohECALIBB8IQsgBiALhUIYiiEGIAEgBiASfHwhASAQIAGFQhCKIRAgCyAQfCELIAYgC4VCP4ohBiACIAcgHHx8IQIgDSAChUIgiiENIAwgDXwhDCAHIAyFQhiKIQcgAiAHIB18fCECIA0gAoVCEIohDSAMIA18IQwgByAMhUI/iiEHIAMgCCAXfHwhAyAOIAOFQiCKIQ4gCSAOfCEJIAggCYVCGIohCCADIAggGXx8IQMgDiADhUIQiiEOIAkgDnwhCSAIIAmFQj+KIQggBCAFIBR8fCEEIA8gBIVCIIohDyAKIA98IQogBSAKhUIYiiEFIAQgBSAefHwhBCAPIASFQhCKIQ8gCiAPfCEKIAUgCoVCP4ohBSABIAUgE3x8IQEgDSABhUIgiiENIAkgDXwhCSAFIAmFQhiKIQUgASAFIB18fCEBIA0gAYVCEIohDSAJIA18IQkgBSAJhUI/iiEFIAIgBiAXfHwhAiAOIAKFQiCKIQ4gCiAOfCEKIAYgCoVCGIohBiACIAYgG3x8IQIgDiAChUIQiiEOIAogDnwhCiAGIAqFQj+KIQYgAyAHIBF8fCEDIA8gA4VCIIohDyALIA98IQsgByALhUIYiiEHIAMgByAcfHwhAyAPIAOFQhCKIQ8gCyAPfCELIAcgC4VCP4ohByAEIAggGXx8IQQgECAEhUIgiiEQIAwgEHwhDCAIIAyFQhiKIQggBCAIIBR8fCEEIBAgBIVCEIohECAMIBB8IQwgCCAMhUI/iiEIIAEgBiAVfHwhASAQIAGFQiCKIRAgCyAQfCELIAYgC4VCGIohBiABIAYgHnx8IQEgECABhUIQiiEQIAsgEHwhCyAGIAuFQj+KIQYgAiAHIBh8fCECIA0gAoVCIIohDSAMIA18IQwgByAMhUIYiiEHIAIgByAWfHwhAiANIAKFQhCKIQ0gDCANfCEMIAcgDIVCP4ohByADIAggIHx8IQMgDiADhUIgiiEOIAkgDnwhCSAIIAmFQhiKIQggAyAIIB98fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSASfHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgGnx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgASAFIB18fCEBIA0gAYVCIIohDSAJIA18IQkgBSAJhUIYiiEFIAEgBSAWfHwhASANIAGFQhCKIQ0gCSANfCEJIAUgCYVCP4ohBSACIAYgEnx8IQIgDiAChUIgiiEOIAogDnwhCiAGIAqFQhiKIQYgAiAGICB8fCECIA4gAoVCEIohDiAKIA58IQogBiAKhUI/iiEGIAMgByAffHwhAyAPIAOFQiCKIQ8gCyAPfCELIAcgC4VCGIohByADIAcgHnx8IQMgDyADhUIQiiEPIAsgD3whCyAHIAuFQj+KIQcgBCAIIBV8fCEEIBAgBIVCIIohECAMIBB8IQwgCCAMhUIYiiEIIAQgCCAbfHwhBCAQIASFQhCKIRAgDCAQfCEMIAggDIVCP4ohCCABIAYgEXx8IQEgECABhUIgiiEQIAsgEHwhCyAGIAuFQhiKIQYgASAGIBh8fCEBIBAgAYVCEIohECALIBB8IQsgBiALhUI/iiEGIAIgByAXfHwhAiANIAKFQiCKIQ0gDCANfCEMIAcgDIVCGIohByACIAcgFHx8IQIgDSAChUIQiiENIAwgDXwhDCAHIAyFQj+KIQcgAyAIIBp8fCEDIA4gA4VCIIohDiAJIA58IQkgCCAJhUIYiiEIIAMgCCATfHwhAyAOIAOFQhCKIQ4gCSAOfCEJIAggCYVCP4ohCCAEIAUgGXx8IQQgDyAEhUIgiiEPIAogD3whCiAFIAqFQhiKIQUgBCAFIBx8fCEEIA8gBIVCEIohDyAKIA98IQogBSAKhUI/iiEFIAEgBSAefHwhASANIAGFQiCKIQ0gCSANfCEJIAUgCYVCGIohBSABIAUgHHx8IQEgDSABhUIQiiENIAkgDXwhCSAFIAmFQj+KIQUgAiAGIBh8fCECIA4gAoVCIIohDiAKIA58IQogBiAKhUIYiiEGIAIgBiAffHwhAiAOIAKFQhCKIQ4gCiAOfCEKIAYgCoVCP4ohBiADIAcgHXx8IQMgDyADhUIgiiEPIAsgD3whCyAHIAuFQhiKIQcgAyAHIBJ8fCEDIA8gA4VCEIohDyALIA98IQsgByALhUI/iiEHIAQgCCAUfHwhBCAQIASFQiCKIRAgDCAQfCEMIAggDIVCGIohCCAEIAggGnx8IQQgECAEhUIQiiEQIAwgEHwhDCAIIAyFQj+KIQggASAGIBZ8fCEBIBAgAYVCIIohECALIBB8IQsgBiALhUIYiiEGIAEgBiARfHwhASAQIAGFQhCKIRAgCyAQfCELIAYgC4VCP4ohBiACIAcgIHx8IQIgDSAChUIgiiENIAwgDXwhDCAHIAyFQhiKIQcgAiAHIBV8fCECIA0gAoVCEIohDSAMIA18IQwgByAMhUI/iiEHIAMgCCAZfHwhAyAOIAOFQiCKIQ4gCSAOfCEJIAggCYVCGIohCCADIAggF3x8IQMgDiADhUIQiiEOIAkgDnwhCSAIIAmFQj+KIQggBCAFIBN8fCEEIA8gBIVCIIohDyAKIA98IQogBSAKhUIYiiEFIAQgBSAbfHwhBCAPIASFQhCKIQ8gCiAPfCEKIAUgCoVCP4ohBSABIAUgF3x8IQEgDSABhUIgiiENIAkgDXwhCSAFIAmFQhiKIQUgASAFICB8fCEBIA0gAYVCEIohDSAJIA18IQkgBSAJhUI/iiEFIAIgBiAffHwhAiAOIAKFQiCKIQ4gCiAOfCEKIAYgCoVCGIohBiACIAYgGnx8IQIgDiAChUIQiiEOIAogDnwhCiAGIAqFQj+KIQYgAyAHIBx8fCEDIA8gA4VCIIohDyALIA98IQsgByALhUIYiiEHIAMgByAUfHwhAyAPIAOFQhCKIQ8gCyAPfCELIAcgC4VCP4ohByAEIAggEXx8IQQgECAEhUIgiiEQIAwgEHwhDCAIIAyFQhiKIQggBCAIIBl8fCEEIBAgBIVCEIohECAMIBB8IQwgCCAMhUI/iiEIIAEgBiAdfHwhASAQIAGFQiCKIRAgCyAQfCELIAYgC4VCGIohBiABIAYgE3x8IQEgECABhUIQiiEQIAsgEHwhCyAGIAuFQj+KIQYgAiAHIB58fCECIA0gAoVCIIohDSAMIA18IQwgByAMhUIYiiEHIAIgByAYfHwhAiANIAKFQhCKIQ0gDCANfCEMIAcgDIVCP4ohByADIAggEnx8IQMgDiADhUIgiiEOIAkgDnwhCSAIIAmFQhiKIQggAyAIIBV8fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSAbfHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgFnx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgASAFIBt8fCEBIA0gAYVCIIohDSAJIA18IQkgBSAJhUIYiiEFIAEgBSATfHwhASANIAGFQhCKIQ0gCSANfCEJIAUgCYVCP4ohBSACIAYgGXx8IQIgDiAChUIgiiEOIAogDnwhCiAGIAqFQhiKIQYgAiAGIBV8fCECIA4gAoVCEIohDiAKIA58IQogBiAKhUI/iiEGIAMgByAYfHwhAyAPIAOFQiCKIQ8gCyAPfCELIAcgC4VCGIohByADIAcgF3x8IQMgDyADhUIQiiEPIAsgD3whCyAHIAuFQj+KIQcgBCAIIBJ8fCEEIBAgBIVCIIohECAMIBB8IQwgCCAMhUIYiiEIIAQgCCAWfHwhBCAQIASFQhCKIRAgDCAQfCEMIAggDIVCP4ohCCABIAYgIHx8IQEgECABhUIgiiEQIAsgEHwhCyAGIAuFQhiKIQYgASAGIBx8fCEBIBAgAYVCEIohECALIBB8IQsgBiALhUI/iiEGIAIgByAafHwhAiANIAKFQiCKIQ0gDCANfCEMIAcgDIVCGIohByACIAcgH3x8IQIgDSAChUIQiiENIAwgDXwhDCAHIAyFQj+KIQcgAyAIIBR8fCEDIA4gA4VCIIohDiAJIA58IQkgCCAJhUIYiiEIIAMgCCAdfHwhAyAOIAOFQhCKIQ4gCSAOfCEJIAggCYVCP4ohCCAEIAUgHnx8IQQgDyAEhUIgiiEPIAogD3whCiAFIAqFQhiKIQUgBCAFIBF8fCEEIA8gBIVCEIohDyAKIA98IQogBSAKhUI/iiEFIAEgBSARfHwhASANIAGFQiCKIQ0gCSANfCEJIAUgCYVCGIohBSABIAUgEnx8IQEgDSABhUIQiiENIAkgDXwhCSAFIAmFQj+KIQUgAiAGIBN8fCECIA4gAoVCIIohDiAKIA58IQogBiAKhUIYiiEGIAIgBiAUfHwhAiAOIAKFQhCKIQ4gCiAOfCEKIAYgCoVCP4ohBiADIAcgFXx8IQMgDyADhUIgiiEPIAsgD3whCyAHIAuFQhiKIQcgAyAHIBZ8fCEDIA8gA4VCEIohDyALIA98IQsgByALhUI/iiEHIAQgCCAXfHwhBCAQIASFQiCKIRAgDCAQfCEMIAggDIVCGIohCCAEIAggGHx8IQQgECAEhUIQiiEQIAwgEHwhDCAIIAyFQj+KIQggASAGIBl8fCEBIBAgAYVCIIohECALIBB8IQsgBiALhUIYiiEGIAEgBiAafHwhASAQIAGFQhCKIRAgCyAQfCELIAYgC4VCP4ohBiACIAcgG3x8IQIgDSAChUIgiiENIAwgDXwhDCAHIAyFQhiKIQcgAiAHIBx8fCECIA0gAoVCEIohDSAMIA18IQwgByAMhUI/iiEHIAMgCCAdfHwhAyAOIAOFQiCKIQ4gCSAOfCEJIAggCYVCGIohCCADIAggHnx8IQMgDiADhUIQiiEOIAkgDnwhCSAIIAmFQj+KIQggBCAFIB98fCEEIA8gBIVCIIohDyAKIA98IQogBSAKhUIYiiEFIAQgBSAgfHwhBCAPIASFQhCKIQ8gCiAPfCEKIAUgCoVCP4ohBSABIAUgH3x8IQEgDSABhUIgiiENIAkgDXwhCSAFIAmFQhiKIQUgASAFIBt8fCEBIA0gAYVCEIohDSAJIA18IQkgBSAJhUI/iiEFIAIgBiAVfHwhAiAOIAKFQiCKIQ4gCiAOfCEKIAYgCoVCGIohBiACIAYgGXx8IQIgDiAChUIQiiEOIAogDnwhCiAGIAqFQj+KIQYgAyAHIBp8fCEDIA8gA4VCIIohDyALIA98IQsgByALhUIYiiEHIAMgByAgfHwhAyAPIAOFQhCKIQ8gCyAPfCELIAcgC4VCP4ohByAEIAggHnx8IQQgECAEhUIgiiEQIAwgEHwhDCAIIAyFQhiKIQggBCAIIBd8fCEEIBAgBIVCEIohECAMIBB8IQwgCCAMhUI/iiEIIAEgBiASfHwhASAQIAGFQiCKIRAgCyAQfCELIAYgC4VCGIohBiABIAYgHXx8IQEgECABhUIQiiEQIAsgEHwhCyAGIAuFQj+KIQYgAiAHIBF8fCECIA0gAoVCIIohDSAMIA18IQwgByAMhUIYiiEHIAIgByATfHwhAiANIAKFQhCKIQ0gDCANfCEMIAcgDIVCP4ohByADIAggHHx8IQMgDiADhUIgiiEOIAkgDnwhCSAIIAmFQhiKIQggAyAIIBh8fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSAWfHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgFHx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgISAhKQMAIAEgCYWFNwMAICIgIikDACACIAqFhTcDACAjICMpAwAgAyALhYU3AwAgJCAkKQMAIAQgDIWFNwMAICUgJSkDACAFIA2FhTcDACAmICYpAwAgBiAOhYU3AwAgJyAnKQMAIAcgD4WFNwMAICggKCkDACAIIBCFhTcDAAs=")}}),a=e(),i=WebAssembly.compile(a);return wi=async t=>(await WebAssembly.instantiate(await i,t)).exports}()().then((t=>{Ci=t})),Fi=64,xi=[];ti.exports=Oi;var Ei=ti.exports.BYTES_MIN=16,vi=ti.exports.BYTES_MAX=64;ti.exports.BYTES=32;var Bi=ti.exports.KEYBYTES_MIN=16,Si=ti.exports.KEYBYTES_MAX=64;ti.exports.KEYBYTES=32;var Pi=ti.exports.SALTBYTES=16,Gi=ti.exports.PERSONALBYTES=16;function Oi(t,e,a,i,o){if(!(this instanceof Oi))return new Oi(t,e,a,i,o);if(!Ci)throw new Error("WASM not loaded. Wait for Blake2b.ready(cb)");t||(t=32),!0!==o&&(yi(t>=Ei,"digestLength must be at least "+Ei+", was given "+t),yi(t<=vi,"digestLength must be at most "+vi+", was given "+t),null!=e&&(yi(e instanceof Uint8Array,"key must be Uint8Array or Buffer"),yi(e.length>=Bi,"key must be at least "+Bi+", was given "+e.length),yi(e.length<=Si,"key must be at least "+Si+", was given "+e.length)),null!=a&&(yi(a instanceof Uint8Array,"salt must be Uint8Array or Buffer"),yi(a.length===Pi,"salt must be exactly "+Pi+", was given "+a.length)),null!=i&&(yi(i instanceof Uint8Array,"personal must be Uint8Array or Buffer"),yi(i.length===Gi,"personal must be exactly "+Gi+", was given "+i.length))),xi.length||(xi.push(Fi),Fi+=216),this.digestLength=t,this.finalized=!1,this.pointer=xi.pop(),this._memory=new Uint8Array(Ci.memory.buffer),this._memory.fill(0,0,64),this._memory[0]=this.digestLength,this._memory[1]=e?e.length:0,this._memory[2]=1,this._memory[3]=1,a&&this._memory.set(a,32),i&&this._memory.set(i,48),this.pointer+216>this._memory.length&&this._realloc(this.pointer+216),Ci.blake2b_init(this.pointer,this.digestLength),e&&(this.update(e),this._memory.fill(0,Fi,Fi+e.length),this._memory[this.pointer+200]=128)}function Ti(){}function Ui(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 zi(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 Qi(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 qi(t){const e=t.getPartialHash(),a=ti.exports(64);return a.setPartialHash(e),a}async function Mi(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)}function ki(t){let e=new Uint8Array(t);return globalThis.crypto.getRandomValues(e),e}async function Ri(t){{const e=await globalThis.crypto.subtle.digest("SHA-256",t.buffer);return new Uint8Array(e)}}function Di(t,e){return new DataView(t.buffer).getUint32(e,!1)}async function Ni(t){for(;!t;)t=await window.prompt("Enter a random text. (Entropy): ","");const e=ti.exports(64);e.update(ki(64));const a=new TextEncoder;e.update(a.encode(t));const i=e.digest(),o=[];for(let t=0;t<8;t++)o[t]=Di(i,4*t);return new Q(o)}async function $i(t,e){let a,i;e<32?(a=1<<e>>>0,i=1):(a=4294967296,i=1<<e-32>>>0);let o=t;for(let t=0;t<i;t++)for(let t=0;t<a;t++)o=await Ri(o);const n=new DataView(o.buffer,o.byteOffset,o.byteLength),l=[];for(let t=0;t<8;t++)l[t]=n.getUint32(4*t,!1);return new Q(l)}function Vi(t){return t instanceof Uint8Array?t:("0x"==t.slice(0,2)&&(t=t.slice(2)),new Uint8Array(t.match(/[\da-f]{2}/gi).map((function(t){return parseInt(t,16)}))))}function Ki(t){return Array.prototype.map.call(t,(function(t){return("0"+(255&t).toString(16)).slice(-2)})).join("")}function ji(t,e){if(e instanceof Uint8Array)return t.toString(e);if(Array.isArray(e))return e.map(ji.bind(null,t));if("object"==typeof e){const a={};return Object.keys(e).forEach((i=>{a[i]=ji(t,e[i])})),a}return"bigint"==typeof e||void 0!==e.eq?e.toString(10):e}Oi.prototype._realloc=function(t){Ci.memory.grow(Math.max(0,Math.ceil(Math.abs(t-this._memory.length)/65536))),this._memory=new Uint8Array(Ci.memory.buffer)},Oi.prototype.update=function(t){return yi(!1===this.finalized,"Hash instance finalized"),yi(t instanceof Uint8Array,"input must be Uint8Array or Buffer"),Fi+t.length>this._memory.length&&this._realloc(Fi+t.length),this._memory.set(t,Fi),Ci.blake2b_update(this.pointer,Fi,Fi+t.length),this},Oi.prototype.digest=function(t){if(yi(!1===this.finalized,"Hash instance finalized"),this.finalized=!0,xi.push(this.pointer),Ci.blake2b_final(this.pointer),!t||"binary"===t)return this._memory.slice(this.pointer+128,this.pointer+128+this.digestLength);if("string"==typeof t)return Ai.toString(this._memory,t,this.pointer+128,this.pointer+128+this.digestLength);yi(t instanceof Uint8Array&&t.length>=this.digestLength,"input must be Uint8Array or Buffer");for(var e=0;e<this.digestLength;e++)t[e]=this._memory[this.pointer+128+e];return t},Oi.prototype.final=Oi.prototype.digest,Oi.WASM=Ci,Oi.SUPPORTED="undefined"!=typeof WebAssembly,Oi.ready=function(t){return t||(t=Ti),Ii?Ii.then((()=>t()),t):t(new Error("WebAssembly not supported"))},Oi.prototype.ready=Oi.ready,Oi.prototype.getPartialHash=function(){return this._memory.slice(this.pointer,this.pointer+216)},Oi.prototype.setPartialHash=function(t){this._memory.set(t,this.pointer)};const Hi=1,Zi=2,Wi=10,Yi=2,Ji=3,Xi=4,to=5,eo=6,ao=7,io=8,oo=9,no=10,lo=11,ro=12,so=13,co=14,uo=15,go=16,fo=17;async function ho(t,e){await qa(t,1),await t.writeULE32(1),await Ma(t);const a=await Ya(e.q);await qa(t,2);const i=a.q,o=8*(Math.floor((ga.bitLength(i)-1)/64)+1),n=a.r,l=8*(Math.floor((ga.bitLength(n)-1)/64)+1);await t.writeULE32(o),await Da(t,i,o),await t.writeULE32(l),await Da(t,n,l),await t.writeULE32(e.nVars),await t.writeULE32(e.nPublic),await t.writeULE32(e.domainSize),await _o(t,a,e.vk_alpha_1),await _o(t,a,e.vk_beta_1),await po(t,a,e.vk_beta_2),await po(t,a,e.vk_gamma_2),await _o(t,a,e.vk_delta_1),await po(t,a,e.vk_delta_2),await Ma(t)}async function _o(t,e,a){const i=new Uint8Array(2*e.G1.F.n8);e.G1.toRprLEM(i,0,a),await t.write(i)}async function po(t,e,a){const i=new Uint8Array(2*e.G2.F.n8);e.G2.toRprLEM(i,0,a),await t.write(i)}async function mo(t,e,a){const i=await t.read(2*e.G1.F.n8),o=e.G1.fromRprLEM(i,0);return a?e.G1.toObject(o):o}async function wo(t,e,a){const i=await t.read(2*e.G2.F.n8),o=e.G2.fromRprLEM(i,0);return a?e.G2.toObject(o):o}async function Lo(t,e,a){await ka(t,e,1);const i=await t.readULE32();if(await Ra(t),i===Hi)return await async function(t,e,a){const i={protocol:"groth16"};await ka(t,e,2);const o=await t.readULE32();i.n8q=o,i.q=await Na(t,o);const n=await t.readULE32();return i.n8r=n,i.r=await Na(t,n),i.curve=await Ya(i.q),i.nVars=await t.readULE32(),i.nPublic=await t.readULE32(),i.domainSize=await t.readULE32(),i.power=Ui(i.domainSize),i.vk_alpha_1=await mo(t,i.curve,a),i.vk_beta_1=await mo(t,i.curve,a),i.vk_beta_2=await wo(t,i.curve,a),i.vk_gamma_2=await wo(t,i.curve,a),i.vk_delta_1=await mo(t,i.curve,a),i.vk_delta_2=await wo(t,i.curve,a),await Ra(t),i}(t,e,a);if(i===Zi)return await async function(t,e,a){const i={protocol:"plonk"};await ka(t,e,2);const o=await t.readULE32();i.n8q=o,i.q=await Na(t,o);const n=await t.readULE32();return i.n8r=n,i.r=await Na(t,n),i.curve=await Ya(i.q),i.nVars=await t.readULE32(),i.nPublic=await t.readULE32(),i.domainSize=await t.readULE32(),i.power=Ui(i.domainSize),i.nAdditions=await t.readULE32(),i.nConstraints=await t.readULE32(),i.k1=await t.read(n),i.k2=await t.read(n),i.Qm=await mo(t,i.curve,a),i.Ql=await mo(t,i.curve,a),i.Qr=await mo(t,i.curve,a),i.Qo=await mo(t,i.curve,a),i.Qc=await mo(t,i.curve,a),i.S1=await mo(t,i.curve,a),i.S2=await mo(t,i.curve,a),i.S3=await mo(t,i.curve,a),i.X_2=await wo(t,i.curve,a),await Ra(t),i}(t,e,a);if(i===Wi)return await async function(t,e,a){const i={protocol:"fflonk"};i.protocolId=Wi,await ka(t,e,Yi);const o=await t.readULE32();i.n8q=o,i.q=await Na(t,o),i.curve=await Ya(i.q);const n=await t.readULE32();return i.n8r=n,i.r=await Na(t,n),i.nVars=await t.readULE32(),i.nPublic=await t.readULE32(),i.domainSize=await t.readULE32(),i.power=Ui(i.domainSize),i.nAdditions=await t.readULE32(),i.nConstraints=await t.readULE32(),i.k1=await t.read(n),i.k2=await t.read(n),i.w3=await t.read(n),i.w4=await t.read(n),i.w8=await t.read(n),i.wr=await t.read(n),i.X_2=await wo(t,i.curve,a),i.C0=await mo(t,i.curve,a),await Ra(t),i}(t,e,a);throw new Error("Protocol not supported: ")}async function bo(t,e,a){const i={delta:{}};i.deltaAfter=await mo(t,e,a),i.delta.g1_s=await mo(t,e,a),i.delta.g1_sx=await mo(t,e,a),i.delta.g2_spx=await wo(t,e,a),i.transcript=await t.read(64),i.type=await t.readULE32();const o=await t.readULE32(),n=t.pos;let l=0;for(;t.pos-n<o;){const e=await t.read(1);if(e[0]<=l)throw new Error("Parameters in the contribution must be sorted");if(l=e[0],1==e[0]){const e=await t.read(1),a=await t.read(e[0]);i.name=(new TextDecoder).decode(a)}else if(2==e[0]){const e=await t.read(1);i.numIterationsExp=e[0]}else{if(3!=e[0])throw new Error("Parameter not recognized");{const e=await t.read(1);i.beaconHash=await t.read(e[0])}}}if(t.pos!=n+o)throw new Error("Parametes do not match");return i}async function yo(t,e,a){await ka(t,a,10);const i={contributions:[]};i.csHash=await t.read(64);const o=await t.readULE32();for(let a=0;a<o;a++){const a=await bo(t,e);i.contributions.push(a)}return await Ra(t),i}async function Ao(t,e,a){await _o(t,e,a.deltaAfter),await _o(t,e,a.delta.g1_s),await _o(t,e,a.delta.g1_sx),await po(t,e,a.delta.g2_spx),await t.write(a.transcript),await t.writeULE32(a.type||0);const i=[];if(a.name){i.push(1);const t=new TextEncoder("utf-8").encode(a.name.substring(0,64));i.push(t.byteLength);for(let e=0;e<t.byteLength;e++)i.push(t[e])}if(1==a.type){i.push(2),i.push(a.numIterationsExp),i.push(3),i.push(a.beaconHash.byteLength);for(let t=0;t<a.beaconHash.byteLength;t++)i.push(a.beaconHash[t])}if(i.length>0){const e=new Uint8Array(i);await t.writeULE32(e.byteLength),await t.write(e)}else await t.writeULE32(0)}async function Co(t,e,a){await qa(t,10),await t.write(a.csHash),await t.writeULE32(a.contributions.length);for(let i=0;i<a.contributions.length;i++)await Ao(t,e,a.contributions[i]);await Ma(t)}function Io(t,e,a){const i=new Uint8Array(2*e.G1.F.n8);e.G1.toRprUncompressed(i,0,a),t.update(i)}function Fo(t,e,a){Io(t,e,a.deltaAfter),Io(t,e,a.delta.g1_s),Io(t,e,a.delta.g1_sx),function(t,e,a){const i=new Uint8Array(2*e.G2.F.n8);e.G2.toRprUncompressed(i,0,a),t.update(i)}(t,e,a.delta.g2_spx),t.update(a.transcript)}async function xo(t,e){await ka(t,e,1);const a=await t.readULE32(),i=await Na(t,a),o=await t.readULE32();return await Ra(t),{n8:a,q:i,nWitness:o}}const{stringifyBigInts:Eo}=fa;async function vo(t,e,a){const{fd:i,sections:o}=await za(e,"wtns",2),n=await xo(i,o),{fd:l,sections:r}=await za(t,"zkey",2),s=await Lo(l,r);if("groth16"!=s.protocol)throw new Error("zkey file is not groth16");if(!ga.eq(s.r,n.q))throw new Error("Curve of the witness does not match the curve of the proving key");if(n.nWitness!=s.nVars)throw new Error(`Invalid witness length. Circuit: ${s.nVars}, witness: ${n.nWitness}`);const c=s.curve,d=c.Fr,u=c.G1,g=c.G2,f=Ui(s.domainSize);a&&a.debug("Reading Wtns");const h=await Va(i,o,2);a&&a.debug("Reading Coeffs");const _=await Va(l,r,4);a&&a.debug("Building ABC");const[p,m,w]=await async function(t,e,a,i,o){const n=t.Fr.n8,l=12+e.n8r,r=(i.byteLength-4)/l,s=new Se(e.domainSize*n),c=new Se(e.domainSize*n),d=new Se(e.domainSize*n),u=[s,c];for(let e=0;e<r;e++){o&&e%1e6==0&&o.debug(`QAP AB: ${e}/${r}`);const s=i.slice(4+e*l,4+e*l+l),c=new DataView(s.buffer),d=c.getUint32(0,!0),g=c.getUint32(4,!0),f=c.getUint32(8,!0),h=s.slice(12,12+n);u[d].set(t.Fr.add(u[d].slice(g*n,g*n+n),t.Fr.mul(h,a.slice(f*n,f*n+n))),g*n)}for(let a=0;a<e.domainSize;a++)o&&a%1e6==0&&o.debug(`QAP C: ${a}/${e.domainSize}`),d.set(t.Fr.mul(s.slice(a*n,a*n+n),c.slice(a*n,a*n+n)),a*n);return[s,c,d]}(c,s,h,_,a),L=f==d.s?c.Fr.shift:c.Fr.w[f+1],b=await d.ifft(p,"","",a,"IFFT_A"),y=await d.batchApplyKey(b,d.e(1),L),A=await d.fft(y,"","",a,"FFT_A"),C=await d.ifft(m,"","",a,"IFFT_B"),I=await d.batchApplyKey(C,d.e(1),L),F=await d.fft(I,"","",a,"FFT_B"),x=await d.ifft(w,"","",a,"IFFT_C"),E=await d.batchApplyKey(x,d.e(1),L),v=await d.fft(E,"","",a,"FFT_C");a&&a.debug("Join ABC");const B=await async function(t,e,a,i,o,n){const l=1<<22,r=t.Fr.n8,s=Math.floor(a.byteLength/t.Fr.n8),c=[];for(let e=0;e<s;e+=l){n&&n.debug(`JoinABC: ${e}/${s}`);const d=Math.min(s-e,l),u=[],g=a.slice(e*r,(e+d)*r),f=i.slice(e*r,(e+d)*r),h=o.slice(e*r,(e+d)*r);u.push({cmd:"ALLOCSET",var:0,buff:g}),u.push({cmd:"ALLOCSET",var:1,buff:f}),u.push({cmd:"ALLOCSET",var:2,buff:h}),u.push({cmd:"ALLOC",var:3,len:d*r}),u.push({cmd:"CALL",fnName:"qap_joinABC",params:[{var:0},{var:1},{var:2},{val:d},{var:3}]}),u.push({cmd:"CALL",fnName:"frm_batchFromMontgomery",params:[{var:3},{val:d},{var:3}]}),u.push({cmd:"GET",out:0,var:3,len:d*r}),c.push(t.tm.queueAction(u))}const d=await Promise.all(c);let u;u=a instanceof Se?new Se(a.byteLength):new Uint8Array(a.byteLength);let g=0;for(let t=0;t<d.length;t++)u.set(d[t][0],g),g+=d[t][0].byteLength;return u}(c,0,A,F,v,a);let S={};a&&a.debug("Reading A Points");const P=await Va(l,r,5);S.pi_a=await c.G1.multiExpAffine(P,h,a,"multiexp A"),a&&a.debug("Reading B1 Points");const G=await Va(l,r,6);let O=await c.G1.multiExpAffine(G,h,a,"multiexp B1");a&&a.debug("Reading B2 Points");const T=await Va(l,r,7);S.pi_b=await c.G2.multiExpAffine(T,h,a,"multiexp B2"),a&&a.debug("Reading C Points");const U=await Va(l,r,8);S.pi_c=await c.G1.multiExpAffine(U,h.slice((s.nPublic+1)*c.Fr.n8),a,"multiexp C"),a&&a.debug("Reading H Points");const z=await Va(l,r,9),Q=await c.G1.multiExpAffine(z,B,a,"multiexp H"),q=c.Fr.random(),M=c.Fr.random();S.pi_a=u.add(S.pi_a,s.vk_alpha_1),S.pi_a=u.add(S.pi_a,u.timesFr(s.vk_delta_1,q)),S.pi_b=g.add(S.pi_b,s.vk_beta_2),S.pi_b=g.add(S.pi_b,g.timesFr(s.vk_delta_2,M)),O=u.add(O,s.vk_beta_1),O=u.add(O,u.timesFr(s.vk_delta_1,M)),S.pi_c=u.add(S.pi_c,Q),S.pi_c=u.add(S.pi_c,u.timesFr(S.pi_a,M)),S.pi_c=u.add(S.pi_c,u.timesFr(O,q)),S.pi_c=u.add(S.pi_c,u.timesFr(s.vk_delta_1,d.neg(d.mul(q,M))));let k=[];for(let t=1;t<=s.nPublic;t++){const e=h.slice(t*d.n8,t*d.n8+d.n8);k.push(ga.fromRprLE(e))}return S.pi_a=u.toObject(u.toAffine(S.pi_a)),S.pi_b=g.toObject(g.toAffine(S.pi_b)),S.pi_c=u.toObject(u.toAffine(S.pi_c)),S.protocol="groth16",S.curve=c.name,await l.close(),await i.close(),S=Eo(S),k=Eo(k),{proof:S,publicSignals:k}}function Bo(t){var e=[];return function t(e,a){if(Array.isArray(a))for(let i=0;i<a.length;i++)t(e,a[i]);else e.push(a)}(e,t),e}function So(t,e){let a=BigInt(t)%e;return a<0&&(a+=e),a}function Po(t){const e=BigInt(2)**BigInt(64);let a=BigInt("0xCBF29CE484222325");for(var i=0;i<t.length;i++)a^=BigInt(t[i].charCodeAt()),a*=BigInt(1099511628211),a%=e;let o=a.toString(16),n=16-o.length;return o="0".repeat(n).concat(o),o}function Go(t,e){const a=[];let i=BigInt(t);const o=BigInt(4294967296);for(;i;)a.unshift(Number(i%o)),i/=o;if(e)for(var n=e-a.length;n>0;)a.unshift(0),n--;return a}async function Oo(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 l,r="",s="",c=1,d=0,u=0;const g=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. ":6==t?"Input signal array access exceeds the size. ":"Unknown error. ",console.error("ERROR: ",t,r),new Error(e+r)},printErrorMessage:function(){r+=h()+"\n"},writeBufferMessage:function(){const t=h();"\n"===t?(console.log(s),s=""):(""!==s&&(s+=" "),s+=t)},showSharedRWMemory:function(){const t=g.exports.getFieldNumLen32(),e=new Uint32Array(t);for(let a=0;a<t;a++)e[t-1-a]=g.exports.readSharedRWMemory(a);if(c>=2&&(d>=1||u>=7)){""!==s&&(s+=" ");const t=ga.fromArray(e,4294967296).toString();s+=t}else console.log(ga.fromArray(e,4294967296))},error:function(t,a,i,o,n,r){let s;throw s=7==t?_(a)+" "+l.getFr(o).toString()+" != "+l.getFr(n).toString()+" "+_(r):9==t?_(a)+" "+l.getFr(o).toString()+" "+_(n):5==t&&e.sym?_(a)+" "+e.sym.labelIdx2Name[n]:_(a)+" "+i+" "+o+" "+n+" "+r,console.log("ERROR: ",t,s),new Error(s)},log:function(t){console.log(l.getFr(t).toString())},logGetSignal:function(t,a){e.logGetSignal&&e.logGetSignal(t,l.getFr(a))},logSetSignal:function(t,a){e.logSetSignal&&e.logSetSignal(t,l.getFr(a))},logStartComponent:function(t){e.logStartComponent&&e.logStartComponent(t)},logFinishComponent:function(t){e.logFinishComponent&&e.logFinishComponent(t)}}});"function"==typeof g.exports.getVersion&&(c=g.exports.getVersion()),"function"==typeof g.exports.getMinorVersion&&(d=g.exports.getMinorVersion()),"function"==typeof g.exports.getPatchVersion&&(u=g.exports.getPatchVersion());const f=e&&(e.sanityCheck||e.logGetSignal||e.logSetSignal||e.logStartComponent||e.logFinishComponent);return l=2===c?new Uo(g,f):new To(a,g,f),l;function h(){for(var t="",e=g.exports.getMessageChar();0!=e;)t+=String.fromCharCode(e),e=g.exports.getMessageChar();return t}function _(t){const e=new Uint8Array(a.buffer),i=[];for(let a=0;e[t+a]>0;a++)i.push(e[t+a]);return String.fromCharCode.apply(null,i)}}class To{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<this.n32;t++)o[this.n32-1-t]=this.i32[(i>>2)+t];this.prime=ga.fromArray(o,4294967296),this.Fr=new $(this.prime),this.mask32=ga.fromString("FFFFFFFF",16),this.NVars=this.instance.exports.getNVars(),this.n64=Math.floor((this.Fr.bitLength-1)/64)+1,this.R=this.Fr.e(ga.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=Po(e),n=parseInt(o.slice(0,8),16),l=parseInt(o.slice(8,16),16);try{this.instance.exports.getSignalOffset32(a,0,n,l)}catch(t){throw new Error(`Signal ${e} is not an input of the circuit.`)}const r=this.getInt(a),s=Bo(t[e]);for(let t=0;t<s.length;t++)this.setFr(i,s[t]),this.instance.exports.setSignal(0,0,r+t,i)}))}async calculateWitness(t,e){const a=this,i=a.i32[0],o=[];await a._doCalculateWitness(t,e);for(let t=0;t<a.NVars;t++){const e=a.instance.exports.getPWitness(t);o.push(a.getFr(e))}return a.i32[0]=i,o}async calculateBinWitness(t,e){const a=this,i=a.i32[0];await a._doCalculateWitness(t,e);const o=a.instance.exports.getWitnessBuffer();a.i32[0]=i;const n=a.memory.buffer.slice(o,o+a.NVars*a.n64*8);return new Uint8Array(n)}allocInt(){const t=this.i32[0];return this.i32[0]=t+8,t}allocFr(){const t=this.i32[0];return this.i32[0]=t+4*this.n32+8,t}getInt(t){return this.i32[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<e.n32;i++)t[e.n32-1-i]=e.i32[a+2+i];const o=e.Fr.e(ga.fromArray(t,4294967296));return 1073741824&e.i32[a+1]?(i=o,e.Fr.mul(e.RInv,i)):o}return 2147483648&e.i32[a]?e.Fr.e(e.i32[a]-4294967296):e.Fr.e(e.i32[a]);var i}setFr(t,e){const a=this;e=a.Fr.e(e);const i=a.Fr.neg(a.Fr.e("80000000",16)),o=a.Fr.e("7FFFFFFF",16);if(a.Fr.geq(e,i)&&a.Fr.leq(e,o)){let o;return a.Fr.geq(e,a.Fr.zero)?o=ga.toNumber(e):(o=ga.toNumber(a.Fr.sub(e,i)),o-=2147483648,o=4294967296+o),a.i32[t>>2]=o,void(a.i32[1+(t>>2)]=0)}a.i32[t>>2]=0,a.i32[1+(t>>2)]=2147483648;const n=ga.toArray(e,4294967296);for(let e=0;e<a.n32;e++){const i=n.length-1-e;a.i32[2+(t>>2)+e]=i>=0?n[i]:0}}}class Uo{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 Uint32Array(this.n32);for(let t=0;t<this.n32;t++)a[this.n32-1-t]=this.instance.exports.readSharedRWMemory(t);this.prime=ga.fromArray(a,4294967296),this.witnessSize=this.instance.exports.getWitnessSize(),this.sanityCheck=e}circom_version(){return this.instance.exports.getVersion()}async _doCalculateWitness(t,e){this.instance.exports.init(this.sanityCheck||e?1:0);const a=Object.keys(t);var i=0;if(a.forEach((e=>{const a=Po(e),o=parseInt(a.slice(0,8),16),n=parseInt(a.slice(8,16),16),l=Bo(t[e]);if("function"==typeof this.instance.exports.getInputSignalSize){let t=this.instance.exports.getInputSignalSize(o,n);if(t<0)throw new Error(`Signal ${e} not found\n`);if(l.length<t)throw new Error(`Not enough values for input signal ${e}\n`);if(l.length>t)throw new Error(`Too many values for input signal ${e}\n`)}for(let t=0;t<l.length;t++){const e=Go(So(l[t],this.prime),this.n32);for(let t=0;t<this.n32;t++)this.instance.exports.writeSharedRWMemory(t,e[this.n32-1-t]);try{this.instance.exports.setInputSignal(o,n,t),i++}catch(t){throw new Error(t)}}})),i<this.instance.exports.getInputSize())throw new Error(`Not all inputs have been set. Only ${i} out of ${this.instance.exports.getInputSize()}`)}async calculateWitness(t,e){const a=[];await this._doCalculateWitness(t,e);for(let t=0;t<this.witnessSize;t++){this.instance.exports.getWitness(t);const e=new Uint32Array(this.n32);for(let t=0;t<this.n32;t++)e[this.n32-1-t]=this.instance.exports.readSharedRWMemory(t);a.push(ga.fromArray(e,4294967296))}return a}async calculateWTNSBin(t,e){const a=new Uint32Array(this.witnessSize*this.n32+this.n32+11),i=new Uint8Array(a.buffer);await this._doCalculateWitness(t,e),i[0]="w".charCodeAt(0),i[1]="t".charCodeAt(0),i[2]="n".charCodeAt(0),i[3]="s".charCodeAt(0),a[1]=2,a[2]=2,a[3]=1;const o=4*this.n32,n=(8+o).toString(16);a[4]=parseInt(n.slice(0,8),16),a[5]=parseInt(n.slice(8,16),16),a[6]=o,this.instance.exports.getRawPrime();var l=7;for(let t=0;t<this.n32;t++)a[l+t]=this.instance.exports.readSharedRWMemory(t);a[l+=this.n32]=this.witnessSize,a[++l]=2,l++;const r=(o*this.witnessSize).toString(16);a[l]=parseInt(r.slice(0,8),16),a[l+1]=parseInt(r.slice(8,16),16),l+=2;for(let t=0;t<this.witnessSize;t++){this.instance.exports.getWitness(t);for(let t=0;t<this.n32;t++)a[l+t]=this.instance.exports.readSharedRWMemory(t);l+=this.n32}return i}}const{unstringifyBigInts:zo}=fa;async function Qo(t,e,a,i){const o=zo(t),n=await Ua(e),l=await n.read(n.totalSize);await n.close();const r=await Oo(l);if(1==r.circom_version()){const t=await r.calculateBinWitness(o),e=await Qa(a,"wtns",2,2);await async function(t,e,a){await qa(t,1);const i=8*(Math.floor((ga.bitLength(a)-1)/64)+1);if(await t.writeULE32(i),await Da(t,a,i),e.byteLength%i!=0)throw new Error("Invalid witness length");await t.writeULE32(e.byteLength/i),await Ma(t),await qa(t,2),await t.write(e),await Ma(t)}(e,t,r.prime),await e.close()}else{const t=await Ta(a),e=await r.calculateWTNSBin(o);await t.write(e),await t.close()}}const{unstringifyBigInts:qo}=fa;const{unstringifyBigInts:Mo}=fa;const{unstringifyBigInts:ko}=fa;function Ro(t){let e=t.toString(16);for(;e.length<64;)e="0"+e;return e=`"0x${e}"`,e}var Do=Object.freeze({__proto__:null,fullProve:async function(t,e,a,i){const o=qo(t),n={type:"mem"};return await Qo(o,e,n),await vo(a,n,i)},prove:vo,verify:async function(t,e,a,i){const o=Mo(t),n=Mo(a),l=Mo(e),r=await Ja(o.curve),s=r.G1.fromObject(o.IC[0]),c=new Uint8Array(2*r.G1.F.n8*l.length),d=new Uint8Array(r.Fr.n8*l.length);if(!function(t,e){for(let a=0;a<e.length;a++)if(!ga.lt(e[a],t.r))return!1;return!0}(r,l))return i&&i.error("Public inputs are not valid."),!1;for(let t=0;t<l.length;t++){const e=r.G1.fromObject(o.IC[t+1]);c.set(e,t*r.G1.F.n8*2),ga.toRprLE(d,r.Fr.n8*t,l[t],r.Fr.n8)}let u=await r.G1.multiExpAffine(c,d);u=r.G1.add(u,s);const g=r.G1.fromObject(n.pi_a),f=r.G2.fromObject(n.pi_b),h=r.G1.fromObject(n.pi_c);if(!function(t,e){const a=t.G1,i=t.G2;return a.isValid(e.pi_a)&&i.isValid(e.pi_b)&&a.isValid(e.pi_c)}(r,{pi_a:g,pi_b:f,pi_c:h}))return i&&i.error("Proof commitments are not valid."),!1;const _=r.G2.fromObject(o.vk_gamma_2),p=r.G2.fromObject(o.vk_delta_2),m=r.G1.fromObject(o.vk_alpha_1),w=r.G2.fromObject(o.vk_beta_2);return await r.pairingEq(r.G1.neg(g),f,u,_,h,p,m,w)?(i&&i.info("OK!"),!0):(i&&i.error("Invalid proof"),!1)},exportSolidityCallData:async function(t,e){const a=ko(t),i=ko(e);let o,n="";for(let t=0;t<i.length;t++)""!=n&&(n+=","),n+=Ro(i[t]);return o=`[${Ro(a.pi_a[0])}, ${Ro(a.pi_a[1])}],[[${Ro(a.pi_b[0][1])}, ${Ro(a.pi_b[0][0])}],[${Ro(a.pi_b[1][1])}, ${Ro(a.pi_b[1][0])}]],[${Ro(a.pi_c[0])}, ${Ro(a.pi_c[1])}],[${n}]`,o}});function No(t,e){const a=new DataView(e.buffer,e.byteOffset,e.byteLength),i=[];for(let t=0;t<8;t++)i[t]=a.getUint32(4*t);const o=new Q(i);return t.G2.fromRng(o)}function $o(t,e,a,i,o){const n=ti.exports(64),l=new Uint8Array([e]);n.update(l),n.update(a);const r=t.G1.toUncompressed(i);n.update(r);const s=t.G1.toUncompressed(o);n.update(s);return No(t,n.digest())}function Vo(t,e,a,i,o){return t.g1_s=e.G1.toAffine(e.G1.fromRng(o)),t.g1_sx=e.G1.toAffine(e.G1.timesFr(t.g1_s,t.prvKey)),t.g2_sp=e.G2.toAffine($o(e,a,i,t.g1_s,t.g1_sx)),t.g2_spx=e.G2.toAffine(e.G2.timesFr(t.g2_sp,t.prvKey)),t}function Ko(t,e,a){const i={tau:{},alpha:{},beta:{}};return i.tau.prvKey=t.Fr.fromRng(a),i.alpha.prvKey=t.Fr.fromRng(a),i.beta.prvKey=t.Fr.fromRng(a),Vo(i.tau,t,0,e,a),Vo(i.alpha,t,1,e,a),Vo(i.beta,t,2,e,a),i}async function jo(t,e,a,i){i||(i=a),await t.writeULE32(1);const o=t.pos;await t.writeULE64(0),await t.writeULE32(8*e.F1.n64);const n=new Uint8Array(e.F1.n8);ga.toRprLE(n,0,e.q,e.F1.n8),await t.write(n),await t.writeULE32(a),await t.writeULE32(i);const l=t.pos-o-8,r=t.pos;await t.writeULE64(l,o),t.pos=r}async function Ho(t,e){if(!e[1])throw new Error(t.fileName+": File has no header");if(e[1].length>1)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=ga.fromRprLE(i),n=await Ya(o);if(8*n.F1.n64!=a)throw new Error(t.fileName+": Invalid size");const l=await t.readULE32(),r=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:l,ceremonyPower:r}}function Zo(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=l(),o.alpha.g2_spx=l(),o.beta.g2_spx=l(),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 l(){let o;return o=i?a.G2.fromRprLEM(t,e):a.G2.fromRprUncompressed(t,e),e+=2*a.G2.F.n8,o}}function Wo(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 l(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),l(i.tau.g2_spx),l(i.alpha.g2_spx),l(i.beta.g2_spx),t}async function Yo(t,e){const a={};a.tauG1=await s(),a.tauG2=await c(),a.alphaG1=await s(),a.betaG1=await s(),a.betaG2=await c(),a.key=await async function(t,e,a){return Zo(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);Wo(i,0,e,a.key,!1);const o=ti.exports(64);o.setPartialHash(a.partialHash),o.update(i),a.responseHash=o.digest();const n=await t.readULE32(),l=t.pos;let r=0;for(;t.pos-l<n;){const t=await d(1);if(t[0]<=r)throw new Error("Parameters in the contribution must be sorted");if(r=t[0],1==t[0]){const t=await d(1),e=await d(t[0]);a.name=(new TextDecoder).decode(e)}else if(2==t[0]){const t=await d(1);a.numIterationsExp=t[0]}else{if(3!=t[0])throw new Error("Parameter not recognized");{const t=await d(1);a.beaconHash=await d(t[0])}}}if(t.pos!=l+n)throw new Error("Parametes do not match");return a;async function s(){const a=await t.read(2*e.G1.F.n8);return e.G1.fromRprLEM(a)}async function c(){const a=await t.read(2*e.G2.F.n8);return e.G2.fromRprLEM(a)}async function d(e){const a=await t.read(e);return new Uint8Array(a)}}async function Jo(t,e,a){if(!a[7])throw new Error(t.fileName+": File has no contributions");if(a[7][0].length>1)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;a<i;a++){const i=await Yo(t,e);i.id=a+1,o.push(i)}if(t.pos-a[7][0].p!=a[7][0].size)throw new Error("Invalid contribution section size");return o}async function Xo(t,e,a){const i=new Uint8Array(2*e.F1.n8),o=new Uint8Array(2*e.F2.n8);await l(a.tauG1),await r(a.tauG2),await l(a.alphaG1),await l(a.betaG1),await r(a.betaG2),await async function(t,e,a,i){const o=new Uint8Array(2*e.F1.n8*6+2*e.F2.n8*3);Wo(o,0,e,a,i),await t.write(o)}(t,e,a.key,!0),await t.write(a.partialHash),await t.write(a.nextChallenge),await t.writeULE32(a.type||0);const n=[];if(a.name){n.push(1);const t=new TextEncoder("utf-8").encode(a.name.substring(0,64));n.push(t.byteLength);for(let e=0;e<t.byteLength;e++)n.push(t[e])}if(1==a.type){n.push(2),n.push(a.numIterationsExp),n.push(3),n.push(a.beaconHash.byteLength);for(let t=0;t<a.beaconHash.byteLength;t++)n.push(a.beaconHash[t])}if(n.length>0){const e=new Uint8Array(n);await t.writeULE32(e.byteLength),await t.write(e)}else await t.writeULE32(0);async function l(a){e.G1.toRprLEM(i,0,a),await t.write(i)}async function r(a){e.G2.toRprLEM(o,0,a),await t.write(o)}}async function tn(t,e,a){await t.writeULE32(7);const i=t.pos;await t.writeULE64(0),await t.writeULE32(a.length);for(let i=0;i<a.length;i++)await Xo(t,e,a[i]);const o=t.pos-i-8,n=t.pos;await t.writeULE64(o,i),t.pos=n}function en(t,e,a){a&&a.debug("Calculating First Challenge Hash");const i=new ti.exports(64),o=new Uint8Array(2*t.G1.F.n8),n=new Uint8Array(2*t.G2.F.n8);let l;return t.G1.toRprUncompressed(o,0,t.G1.g),t.G2.toRprUncompressed(n,0,t.G2.g),i.update(ti.exports(64).digest()),l=2**e*2-1,a&&a.debug("Calculate Initial Hash: tauG1"),r(o,l),l=2**e,a&&a.debug("Calculate Initial Hash: tauG2"),r(n,l),a&&a.debug("Calculate Initial Hash: alphaTauG1"),r(o,l),a&&a.debug("Calculate Initial Hash: betaTauG1"),r(o,l),i.update(n),i.digest();function r(t,e){const o=341e3,n=Math.floor(e/o),l=e%o,r=new Uint8Array(o*t.byteLength);for(let e=0;e<o;e++)r.set(t,e*t.byteLength);for(let t=0;t<n;t++)i.update(r),a&&a.debug("Initial hash: "+t*o);for(let e=0;e<l;e++)i.update(t)}}async function an(t,e,a,i){return Ko(t,e,await $i(a,i))}const on=Mi;async function nn(t,e,a,i){let o;if(1==e.type){const o=await an(t,a.nextChallenge,e.beaconHash,e.numIterationsExp);if(!t.G1.eq(e.key.tau.g1_s,o.tau.g1_s))return i&&i.error(`BEACON key (tauG1_s) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G1.eq(e.key.tau.g1_sx,o.tau.g1_sx))return i&&i.error(`BEACON key (tauG1_sx) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G2.eq(e.key.tau.g2_spx,o.tau.g2_spx))return i&&i.error(`BEACON key (tauG2_spx) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G1.eq(e.key.alpha.g1_s,o.alpha.g1_s))return i&&i.error(`BEACON key (alphaG1_s) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G1.eq(e.key.alpha.g1_sx,o.alpha.g1_sx))return i&&i.error(`BEACON key (alphaG1_sx) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G2.eq(e.key.alpha.g2_spx,o.alpha.g2_spx))return i&&i.error(`BEACON key (alphaG2_spx) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G1.eq(e.key.beta.g1_s,o.beta.g1_s))return i&&i.error(`BEACON key (betaG1_s) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G1.eq(e.key.beta.g1_sx,o.beta.g1_sx))return i&&i.error(`BEACON key (betaG1_sx) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G2.eq(e.key.beta.g2_spx,o.beta.g2_spx))return i&&i.error(`BEACON key (betaG2_spx) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1}return e.key.tau.g2_sp=t.G2.toAffine($o(t,0,a.nextChallenge,e.key.tau.g1_s,e.key.tau.g1_sx)),e.key.alpha.g2_sp=t.G2.toAffine($o(t,1,a.nextChallenge,e.key.alpha.g1_s,e.key.alpha.g1_sx)),e.key.beta.g2_sp=t.G2.toAffine($o(t,2,a.nextChallenge,e.key.beta.g1_s,e.key.beta.g1_sx)),o=await on(t,e.key.tau.g1_s,e.key.tau.g1_sx,e.key.tau.g2_sp,e.key.tau.g2_spx),!0!==o?(i&&i.error("INVALID key (tau) in challenge #"+e.id),!1):(o=await on(t,e.key.alpha.g1_s,e.key.alpha.g1_sx,e.key.alpha.g2_sp,e.key.alpha.g2_spx),!0!==o?(i&&i.error("INVALID key (alpha) in challenge #"+e.id),!1):(o=await on(t,e.key.beta.g1_s,e.key.beta.g1_sx,e.key.beta.g2_sp,e.key.beta.g2_spx),!0!==o?(i&&i.error("INVALID key (beta) in challenge #"+e.id),!1):(o=await on(t,a.tauG1,e.tauG1,e.key.tau.g2_sp,e.key.tau.g2_spx),!0!==o?(i&&i.error("INVALID tau*G1. challenge #"+e.id+" It does not follow the previous contribution"),!1):(o=await on(t,e.key.tau.g1_s,e.key.tau.g1_sx,a.tauG2,e.tauG2),!0!==o?(i&&i.error("INVALID tau*G2. challenge #"+e.id+" It does not follow the previous contribution"),!1):(o=await on(t,a.alphaG1,e.alphaG1,e.key.alpha.g2_sp,e.key.alpha.g2_spx),!0!==o?(i&&i.error("INVALID alpha*G1. challenge #"+e.id+" It does not follow the previous contribution"),!1):(o=await on(t,a.betaG1,e.betaG1,e.key.beta.g2_sp,e.key.beta.g2_spx),!0!==o?(i&&i.error("INVALID beta*G1. challenge #"+e.id+" It does not follow the previous contribution"),!1):(o=await on(t,e.key.beta.g1_s,e.key.beta.g1_sx,a.betaG2,e.betaG2),!0!==o?(i&&i.error("INVALID beta*G2. challenge #"+e.id+"It does not follow the previous contribution"),!1):(i&&i.info("Powers Of tau file OK!"),!0))))))))}async function ln(t,e,a,i,o,n,l,r,s,c){const d=o[n],u=2*d.F.n8,g=e[i][0].size/u;await ka(t,e,i),await qa(a,i);let f=l;for(let e=0;e<g;e+=65536){c&&c.debug(`Applying key: ${s}: ${e}/${g}`);const i=Math.min(g-e,65536);let n;n=await t.read(i*u),n=await d.batchApplyKey(n,f,r),await a.write(n),f=o.Fr.mul(f,o.Fr.exp(r,i))}await Ma(a),await Ra(t)}async function rn(t,e,a,i,o,n,l,r,s,c,d){const u=i[o],g=2*u.F.n8,f=Math.floor((1<<20)/g);let h=l;for(let o=0;o<n;o+=f){d&&d.debug(`Applying key ${c}: ${o}/${n}`);const l=Math.min(n-o,f),_=await t.read(l*g),p=await u.batchUtoLEM(_),m=await u.batchApplyKey(p,h,r);let w;w="COMPRESSED"==s?await u.batchLEMtoC(m):await u.batchLEMtoU(m),a&&a.update(w),await e.write(w),h=i.Fr.mul(h,i.Fr.exp(r,l))}}var sn=Object.freeze({__proto__:null,newAccumulator:async function(t,e,a,i){await ti.exports.ready();const o=await Qa(a,"ptau",1,7);await jo(o,t,e,0);const n=t.G1.oneAffine,l=t.G2.oneAffine;await qa(o,2);const r=2**e*2-1;for(let t=0;t<r;t++)await o.write(n),i&&t%1e5==0&&t&&i.log("tauG1: "+t);await Ma(o),await qa(o,3);const s=2**e;for(let t=0;t<s;t++)await o.write(l),i&&t%1e5==0&&t&&i.log("tauG2: "+t);await Ma(o),await qa(o,4);const c=2**e;for(let t=0;t<c;t++)await o.write(n),i&&t%1e5==0&&t&&i.log("alphaTauG1: "+t);await Ma(o),await qa(o,5);const d=2**e;for(let t=0;t<d;t++)await o.write(n),i&&t%1e5==0&&t&&i.log("betaTauG1: "+t);await Ma(o),await qa(o,6),await o.write(l),await Ma(o),await qa(o,7),await o.writeULE32(0),await Ma(o),await o.close();const u=en(t,e,i);return i&&i.debug(zi(ti.exports(64).digest(),"Blank Contribution Hash:")),i&&i.info(zi(u,"First Contribution Hash:")),u},exportChallenge:async function(t,e,a){await ti.exports.ready();const{fd:i,sections:o}=await za(t,"ptau",1),{curve:n,power:l}=await Ho(i,o),r=await Jo(i,n,o);let s,c;0==r.length?(s=ti.exports(64).digest(),c=en(n,l)):(s=r[r.length-1].responseHash,c=r[r.length-1].nextChallenge),a&&a.info(zi(s,"Last Response Hash: ")),a&&a.info(zi(c,"New Challenge Hash: "));const d=await Ta(e),u=ti.exports(64);await d.write(s),u.update(s),await f(2,"G1",2**l*2-1,"tauG1"),await f(3,"G2",2**l,"tauG2"),await f(4,"G1",2**l,"alphaTauG1"),await f(5,"G1",2**l,"betaTauG1"),await f(6,"G2",1,"betaG2"),await i.close(),await d.close();const g=u.digest();if(!Qi(c,g))throw a&&a.info(zi(g,"Calc Curret Challenge Hash: ")),a&&a.error("PTau file is corrupted. Calculated new challenge hash does not match with the eclared one"),new Error("PTau file is corrupted. Calculated new challenge hash does not match with the eclared one");return c;async function f(t,e,l,r){const s=n[e],c=2*s.F.n8,g=Math.floor((1<<24)/c);await ka(i,o,t);for(let t=0;t<l;t+=g){a&&a.debug(`Exporting ${r}: ${t}/${l}`);const e=Math.min(l-t,g);let o;o=await i.read(e*c),o=await s.batchLEMtoU(o),await d.write(o),u.update(o)}await Ra(i)}},importResponse:async function(t,e,a,i,o,n){await ti.exports.ready();const l=new Uint8Array(64);for(let t=0;t<64;t++)l[t]=255;const{fd:r,sections:s}=await za(t,"ptau",1),{curve:c,power:d}=await Ho(r,s),u=await Jo(r,c,s),g={};i&&(g.name=i);const f=2*c.F1.n8,h=c.F1.n8,_=2*c.F2.n8,p=c.F2.n8,m=await Ua(e);if(m.totalSize!=64+(2**d*2-1)*h+2**d*p+2**d*h+2**d*h+p+6*f+3*_)throw new Error("Size of the contribution is invalid");let w;w=u.length>0?u[u.length-1].nextChallenge:en(c,d,n);const L=await Qa(a,"ptau",1,o?7:2);await jo(L,c,d);const b=await m.read(64);if(Qi(l,w)&&(w=b,u[u.length-1].nextChallenge=w),!Qi(b,w))throw new Error("Wrong contribution. this contribution is not based on the previus hash");const y=new ti.exports(64);y.update(b);const A=[];let C;C=await x(m,L,"G1",2,2**d*2-1,[1],"tauG1"),g.tauG1=C[0],C=await x(m,L,"G2",3,2**d,[1],"tauG2"),g.tauG2=C[0],C=await x(m,L,"G1",4,2**d,[0],"alphaG1"),g.alphaG1=C[0],C=await x(m,L,"G1",5,2**d,[0],"betaG1"),g.betaG1=C[0],C=await x(m,L,"G2",6,1,[0],"betaG2"),g.betaG2=C[0],g.partialHash=y.getPartialHash();const I=await m.read(2*c.F1.n8*6+2*c.F2.n8*3);g.key=Zo(I,0,c,!1),y.update(new Uint8Array(I));const F=y.digest();if(n&&n.info(zi(F,"Contribution Response Hash imported: ")),o){const t=new ti.exports(64);t.update(F),await E(t,L,"G1",2,2**d*2-1,"tauG1",n),await E(t,L,"G2",3,2**d,"tauG2",n),await E(t,L,"G1",4,2**d,"alphaTauG1",n),await E(t,L,"G1",5,2**d,"betaTauG1",n),await E(t,L,"G2",6,1,"betaG2",n),g.nextChallenge=t.digest(),n&&n.info(zi(g.nextChallenge,"Next Challenge Hash: "))}else g.nextChallenge=l;return u.push(g),await tn(L,c,u),await m.close(),await L.close(),await r.close(),g.nextChallenge;async function x(t,e,a,i,l,r,s){return o?await async function(t,e,a,i,o,l,r){const s=c[a],d=s.F.n8,u=2*s.F.n8,g=[];await qa(e,i);const f=Math.floor((1<<24)/u);A[i]=e.pos;for(let a=0;a<o;a+=f){n&&n.debug(`Importing ${r}: ${a}/${o}`);const i=Math.min(o-a,f),c=await t.read(i*d);y.update(c);const h=await s.batchCtoLEM(c);await e.write(h);for(let t=0;t<l.length;t++){const e=l[t];if(e>=a&&e<a+i){const t=s.fromRprLEM(h,(e-a)*u);g.push(t)}}}return await Ma(e),g}(t,e,a,i,l,r,s):await async function(t,e,a,i,o,l,r){const s=c[a],d=s.F.n8,u=[],g=Math.floor((1<<24)/d);for(let e=0;e<o;e+=g){n&&n.debug(`Importing ${r}: ${e}/${o}`);const a=Math.min(o-e,g),i=await t.read(a*d);y.update(i);for(let t=0;t<l.length;t++){const o=l[t];if(o>=e&&o<e+a){const t=s.fromRprCompressed(i,(o-e)*d);u.push(t)}}}return u}(t,0,a,0,l,r,s)}async function E(t,e,a,i,o,n,l){const r=c[a],s=2*r.F.n8,d=Math.floor((1<<24)/s),u=e.pos;e.pos=A[i];for(let a=0;a<o;a+=d){l&&l.debug(`Hashing ${n}: ${a}/${o}`);const i=Math.min(o-a,d),c=await e.read(i*s),u=await r.batchLEMtoU(c);t.update(u)}e.pos=u}},verify:async function(t,e){let a;await ti.exports.ready();const{fd:i,sections:o}=await za(t,"ptau",1),{curve:n,power:l,ceremonyPower:r}=await Ho(i,o),s=await Jo(i,n,o);e&&e.debug("power: 2**"+l),e&&e.debug("Computing initial contribution hash");const c={tauG1:n.G1.g,tauG2:n.G2.g,alphaG1:n.G1.g,betaG1:n.G1.g,betaG2:n.G2.g,nextChallenge:en(n,r,e),responseHash:ti.exports(64).digest()};if(0==s.length)return e&&e.error("This file has no contribution! It cannot be used in production"),!1;let d;d=s.length>1?s[s.length-2]:c;const u=s[s.length-1];if(e&&e.debug("Validating contribution #"+s[s.length-1].id),!await nn(n,u,d,e))return!1;const g=ti.exports(64);g.update(u.responseHash),e&&e.debug("Verifying powers in tau*G1 section");const f=await b(2,"G1","tauG1",2**l*2-1,[0,1],e);if(a=await on(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 h=await b(3,"G2","tauG2",2**l,[0,1],e);if(a=await on(n,n.G1.g,u.tauG1,h.R1,h.R2),!0!==a)return e&&e.error("tauG2 section. Powers do not match"),!1;if(!n.G2.eq(n.G2.g,h.singularPoints[0]))return e&&e.error("First element of tau*G2 section must be the generator"),!1;if(!n.G2.eq(u.tauG2,h.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 _=await b(4,"G1","alphatauG1",2**l,[0],e);if(a=await on(n,_.R1,_.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,_.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 p=await b(5,"G1","betatauG1",2**l,[0],e);if(a=await on(n,p.R1,p.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,p.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,l=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 r=await i.read(a),s=e.fromRprLEM(r);return e.toRprUncompressed(l,0,s),g.update(l),s}(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 w=g.digest();if(l==r&&!Qi(w,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(zi(w,"Next challenge hash: ")),L(u,d);for(let t=s.length-2;t>=0;t--){const a=s[t],i=t>0?s[t-1]:c;if(!await nn(n,a,i,e))return!1;L(a,i)}if(e&&e.info("-----------------------------------------------------"),o[12]&&o[13]&&o[14]&&o[15]){let t;if(t=await y("G1",2,12,"tauG1",e),!t)return!1;if(t=await y("G2",3,13,"tauG2",e),!t)return!1;if(t=await y("G1",4,14,"alphaTauG1",e),!t)return!1;if(t=await y("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 L(t,a){if(!e)return;e.info("-----------------------------------------------------"),e.info(`Contribution #${t.id}: ${t.name||""}`),e.info(zi(t.nextChallenge,"Next Challenge: "));const i=new Uint8Array(2*n.G1.F.n8*6+2*n.G2.F.n8*3);Wo(i,0,n,t.key,!1);const o=ti.exports(64);o.setPartialHash(t.partialHash),o.update(i);const l=o.digest();e.info(zi(l,"Response Hash:")),e.info(zi(a.nextChallenge,"Response Hash:")),1==t.type&&(e.info(`Beacon generator: ${Ki(t.beaconHash)}`),e.info(`Beacon iterations Exp: ${t.numIterationsExp}`))}async function b(t,e,a,l,r,s){const c=n[e],d=2*c.F.n8;await ka(i,o,t);const u=[];let f=c.zero,h=c.zero,_=c.zero;for(let t=0;t<l;t+=65536){s&&s.debug(`points relations: ${a}: ${t}/${l} `);const e=Math.min(l-t,65536),o=await i.read(e*d),n=await c.batchLEMtoU(o);g.update(n);const p=ki(4*(e-1));if(t>0){const t=c.fromRprLEM(o,0),e=Di(ki(4),0);f=c.add(f,c.timesScalar(_,e)),h=c.add(h,c.timesScalar(t,e))}const m=await c.multiExpAffine(o.slice(0,(e-1)*d),p),w=await c.multiExpAffine(o.slice(d),p);f=c.add(f,m),h=c.add(h,w),_=c.fromRprLEM(o,(e-1)*d);for(let a=0;a<r.length;a++){const i=r[a];if(i>=t&&i<t+e){const e=c.fromRprLEM(o,(i-t)*d);u.push(e)}}}return await Ra(i),{R1:f,R2:h,singularPoints:u}}async function y(t,e,a,r,s){s&&s.debug(`Verifying phase2 calculated values ${r}...`);const c=n[t],d=2*c.F.n8,u=new Array(8);for(let t=0;t<8;t++)u[t]=Di(ki(4),0);for(let t=0;t<=l;t++){if(!await g(t))return!1}if(2==e){if(!await g(l+1))return!1}return!0;async function g(t){s&&s.debug(`Power ${t}...`);const g=n.Fr.n8,f=2**t;let h,_=new Uint32Array(f),p=new Q(u);s&&s.debug(`Creating random numbers Powers${t}...`);for(let e=0;e<f;e++)_[e]=t==l+1&&e==f-1?0:p.nextU32();_=new Uint8Array(_.buffer,_.byteOffset,_.byteLength),s&&s.debug(`reading points Powers${t}...`),await ka(i,o,e),h=new Se(f*d),t==l+1?(await i.readToBuffer(h,0,(f-1)*d),h.set(n.G1.zeroAffine,(f-1)*d)):await i.readToBuffer(h,0,f*d),await Ra(i,!0);const m=await c.multiExpAffine(h,_,s,r+"_"+t);_=new Se(f*g),p=new Q(u);const w=new Uint8Array(4),L=new DataView(w.buffer);s&&s.debug(`Creating random numbers Powers${t}...`);for(let e=0;e<f;e++)e==f-1&&t==l+1||(L.setUint32(0,p.nextU32(),!0),_.set(w,e*g));s&&s.debug(`batchToMontgomery ${t}...`),_=await n.Fr.batchToMontgomery(_),s&&s.debug(`fft ${t}...`),_=await n.Fr.fft(_),s&&s.debug(`batchFromMontgomery ${t}...`),_=await n.Fr.batchFromMontgomery(_),s&&s.debug(`reading points Lagrange${t}...`),await ka(i,o,a),i.pos+=d*(2**t-1),await i.readToBuffer(h,0,f*d),await Ra(i,!0);const b=await c.multiExpAffine(h,_,s,r+"_"+t+"_transformed");return!!c.eq(m,b)||(s&&s.error("Phase2 caclutation does not match with powers of tau"),!1)}}},challengeContribute:async function(t,e,a,i,o){await ti.exports.ready();const n=await Ua(e),l=8*t.F1.n64*2,r=8*t.F2.n64*2,s=(n.totalSize+l-64-r)/(4*l+r);let c=s,d=0;for(;c>1;)c/=2,d+=1;if(2**d!=s)throw new Error("Invalid file size");o&&o.debug("Power to tau size: "+d);const u=await Ni(i),g=await Ta(a),f=ti.exports(64);for(let t=0;t<n.totalSize;t+=n.pageSize){o&&o.debug(`Hashing challenge ${t}/${n.totalSize}`);const e=Math.min(n.totalSize-t,n.pageSize),a=await n.read(e);f.update(a)}const h=await n.read(64,0);o&&o.info(zi(h,"Claimed Previous Response Hash: "));const _=f.digest();o&&o.info(zi(_,"Current Challenge Hash: "));const p=Ko(t,_,u);o&&["tau","alpha","beta"].forEach((e=>{o.debug(e+".g1_s: "+t.G1.toString(p[e].g1_s,16)),o.debug(e+".g1_sx: "+t.G1.toString(p[e].g1_sx,16)),o.debug(e+".g2_sp: "+t.G2.toString(p[e].g2_sp,16)),o.debug(e+".g2_spx: "+t.G2.toString(p[e].g2_spx,16)),o.debug("")}));const m=ti.exports(64);await g.write(_),m.update(_),await rn(n,g,m,t,"G1",2**d*2-1,t.Fr.one,p.tau.prvKey,"COMPRESSED","tauG1",o),await rn(n,g,m,t,"G2",2**d,t.Fr.one,p.tau.prvKey,"COMPRESSED","tauG2",o),await rn(n,g,m,t,"G1",2**d,p.alpha.prvKey,p.tau.prvKey,"COMPRESSED","alphaTauG1",o),await rn(n,g,m,t,"G1",2**d,p.beta.prvKey,p.tau.prvKey,"COMPRESSED","betaTauG1",o),await rn(n,g,m,t,"G2",1,p.beta.prvKey,p.tau.prvKey,"COMPRESSED","betaTauG2",o);const w=new Uint8Array(2*t.F1.n8*6+2*t.F2.n8*3);Wo(w,0,t,p,!1),await g.write(w),m.update(w);const L=m.digest();o&&o.info(zi(L,"Contribution Response Hash: ")),await g.close(),await n.close()},beacon:async function(t,e,a,i,o,n){const l=Vi(i);if(0==l.byteLength||2*l.byteLength!=i.length)return n&&n.error("Invalid Beacon Hash. (It must be a valid hexadecimal sequence)"),!1;if(l.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 ti.exports.ready();const{fd:r,sections:s}=await za(t,"ptau",1),{curve:c,power:d,ceremonyPower:u}=await Ho(r,s);if(d!=u)return n&&n.error("This file has been reduced. You cannot contribute into a reduced file."),!1;s[12]&&n&&n.warn("Contributing into a file that has phase2 calculated. You will have to prepare phase2 again.");const g=await Jo(r,c,s),f={name:a,type:1,numIterationsExp:o,beaconHash:l};let h;h=g.length>0?g[g.length-1].nextChallenge:en(c,d,n),f.key=await an(c,h,l,o);const _=new ti.exports(64);_.update(h);const p=await Qa(e,"ptau",1,7);await jo(p,c,d);const m=[];let w;w=await A(2,"G1",2**d*2-1,c.Fr.e(1),f.key.tau.prvKey,"tauG1",n),f.tauG1=w[1],w=await A(3,"G2",2**d,c.Fr.e(1),f.key.tau.prvKey,"tauG2",n),f.tauG2=w[1],w=await A(4,"G1",2**d,f.key.alpha.prvKey,f.key.tau.prvKey,"alphaTauG1",n),f.alphaG1=w[0],w=await A(5,"G1",2**d,f.key.beta.prvKey,f.key.tau.prvKey,"betaTauG1",n),f.betaG1=w[0],w=await A(6,"G2",1,f.key.beta.prvKey,f.key.tau.prvKey,"betaTauG2",n),f.betaG2=w[0],f.partialHash=_.getPartialHash();const L=new Uint8Array(2*c.F1.n8*6+2*c.F2.n8*3);Wo(L,0,c,f.key,!1),_.update(new Uint8Array(L));const b=_.digest();n&&n.info(zi(b,"Contribution Response Hash imported: "));const y=new ti.exports(64);return y.update(b),await C(p,"G1",2,2**d*2-1,"tauG1",n),await C(p,"G2",3,2**d,"tauG2",n),await C(p,"G1",4,2**d,"alphaTauG1",n),await C(p,"G1",5,2**d,"betaTauG1",n),await C(p,"G2",6,1,"betaG2",n),f.nextChallenge=y.digest(),n&&n.info(zi(f.nextChallenge,"Next Challenge Hash: ")),g.push(f),await tn(p,c,g),await r.close(),await p.close(),b;async function A(t,e,a,i,o,n,l){const d=[];r.pos=s[t][0].p,await qa(p,t),m[t]=p.pos;const u=c[e],g=2*u.F.n8,f=Math.floor((1<<20)/g);let h=i;for(let t=0;t<a;t+=f){l&&l.debug(`applying key${n}: ${t}/${a}`);const e=Math.min(a-t,f),i=await r.read(e*g),s=await u.batchApplyKey(i,h,o),m=p.write(s),w=await u.batchLEMtoC(s);if(_.update(w),await m,0==t)for(let t=0;t<Math.min(2,a);t++)d.push(u.fromRprLEM(s,t*g));h=c.Fr.mul(h,c.Fr.exp(o,e))}return await Ma(p),d}async function C(t,e,a,i,o,n){const l=c[e],r=2*l.F.n8,s=Math.floor((1<<24)/r),d=t.pos;t.pos=m[a];for(let e=0;e<i;e+=s){n&&n.debug(`Hashing ${o}: ${e}/${i}`);const a=Math.min(i-e,s),c=await t.read(a*r),d=await l.batchLEMtoU(c);y.update(d)}t.pos=d}},contribute:async function(t,e,a,i,o){await ti.exports.ready();const{fd:n,sections:l}=await za(t,"ptau",1),{curve:r,power:s,ceremonyPower:c}=await Ho(n,l);if(s!=c)throw o&&o.error("This file has been reduced. You cannot contribute into a reduced file."),new Error("This file has been reduced. You cannot contribute into a reduced file.");l[12]&&o&&o.warn("WARNING: Contributing into a file that has phase2 calculated. You will have to prepare phase2 again.");const d=await Jo(n,r,l),u={name:a,type:0};let g;const f=await Ni(i);g=d.length>0?d[d.length-1].nextChallenge:en(r,s,o),u.key=Ko(r,g,f);const h=new ti.exports(64);h.update(g);const _=await Qa(e,"ptau",1,7);await jo(_,r,s);const p=[];let m;m=await y(2,"G1",2**s*2-1,r.Fr.e(1),u.key.tau.prvKey,"tauG1"),u.tauG1=m[1],m=await y(3,"G2",2**s,r.Fr.e(1),u.key.tau.prvKey,"tauG2"),u.tauG2=m[1],m=await y(4,"G1",2**s,u.key.alpha.prvKey,u.key.tau.prvKey,"alphaTauG1"),u.alphaG1=m[0],m=await y(5,"G1",2**s,u.key.beta.prvKey,u.key.tau.prvKey,"betaTauG1"),u.betaG1=m[0],m=await y(6,"G2",1,u.key.beta.prvKey,u.key.tau.prvKey,"betaTauG2"),u.betaG2=m[0],u.partialHash=h.getPartialHash();const w=new Uint8Array(2*r.F1.n8*6+2*r.F2.n8*3);Wo(w,0,r,u.key,!1),h.update(new Uint8Array(w));const L=h.digest();o&&o.info(zi(L,"Contribution Response Hash imported: "));const b=new ti.exports(64);return b.update(L),await A(_,"G1",2,2**s*2-1,"tauG1"),await A(_,"G2",3,2**s,"tauG2"),await A(_,"G1",4,2**s,"alphaTauG1"),await A(_,"G1",5,2**s,"betaTauG1"),await A(_,"G2",6,1,"betaG2"),u.nextChallenge=b.digest(),o&&o.info(zi(u.nextChallenge,"Next Challenge Hash: ")),d.push(u),await tn(_,r,d),await n.close(),await _.close(),L;async function y(t,e,a,i,s,c){const d=[];n.pos=l[t][0].p,await qa(_,t),p[t]=_.pos;const u=r[e],g=2*u.F.n8,f=Math.floor((1<<20)/g);let m=i;for(let t=0;t<a;t+=f){o&&o.debug(`processing: ${c}: ${t}/${a}`);const e=Math.min(a-t,f),i=await n.read(e*g),l=await u.batchApplyKey(i,m,s),p=_.write(l),w=await u.batchLEMtoC(l);if(h.update(w),await p,0==t)for(let t=0;t<Math.min(2,a);t++)d.push(u.fromRprLEM(l,t*g));m=r.Fr.mul(m,r.Fr.exp(s,e))}return await Ma(_),d}async function A(t,e,a,i,n){const l=r[e],s=2*l.F.n8,c=Math.floor((1<<24)/s),d=t.pos;t.pos=p[a];for(let e=0;e<i;e+=c){o&&e&&o.debug(`Hashing ${n}: `+e);const a=Math.min(i-e,c),r=await t.read(a*s),d=await l.batchLEMtoU(r);b.update(d)}t.pos=d}},preparePhase2:async function(t,e,a){const{fd:i,sections:o}=await za(t,"ptau",1),{curve:n,power:l}=await Ho(i,o),r=await Qa(e,"ptau",1,11);return await jo(r,n,l),await $a(i,o,r,2),await $a(i,o,r,3),await $a(i,o,r,4),await $a(i,o,r,5),await $a(i,o,r,6),await $a(i,o,r,7),await s(2,12,"G1","tauG1"),await s(3,13,"G2","tauG2"),await s(4,14,"G1","alphaTauG1"),await s(5,15,"G1","betaTauG1"),await i.close(),void await r.close();async function s(t,e,s,c){a&&a.debug("Starting section: "+c),await qa(r,e);for(let t=0;t<=l;t++)await d(t);async function d(e){const d=2**e,u=n[s];n.Fr;const g=2*u.F.n8;let f;u.F.n8,f=new Se(d*g),await ka(i,o,t),2==t&&e==l+1?(await i.readToBuffer(f,0,(d-1)*g),f.set(n.G1.zeroAffine,(d-1)*g)):await i.readToBuffer(f,0,d*g),await Ra(i,!0),f=await u.lagrangeEvaluations(f,"affine","affine",a,c),await r.write(f)}2==t&&await d(l+1),await Ma(r)}},truncate:async function(t,e,a){const{fd:i,sections:o}=await za(t,"ptau",1),{curve:n,power:l,ceremonyPower:r}=await Ho(i,o),s=2*n.G1.F.n8,c=2*n.G2.F.n8;for(let t=1;t<l;t++)await d(t);return await i.close(),!0;async function d(t){let l=t.toString();for(;l.length<2;)l="0"+l;a&&a.debug("Writing Power: "+l);const d=await Qa(e+l+".ptau","ptau",1,11);await jo(d,n,t,r),await $a(i,o,d,2,(2**t*2-1)*s),await $a(i,o,d,3,2**t*c),await $a(i,o,d,4,2**t*s),await $a(i,o,d,5,2**t*s),await $a(i,o,d,6,c),await $a(i,o,d,7),await $a(i,o,d,12,(2**(t+1)*2-1)*s),await $a(i,o,d,13,(2**t*2-1)*c),await $a(i,o,d,14,(2**t*2-1)*s),await $a(i,o,d,15,(2**t*2-1)*s),await d.close()}},convert:async function(t,e,a){const{fd:i,sections:o}=await za(t,"ptau",1),{curve:n,power:l}=await Ho(i,o),r=await Qa(e,"ptau",1,11);return await jo(r,n,l),await $a(i,o,r,2),await $a(i,o,r,3),await $a(i,o,r,4),await $a(i,o,r,5),await $a(i,o,r,6),await $a(i,o,r,7),await async function(t,e,s,c){a&&a.debug("Starting section: "+c);await qa(r,e);const d=o[e][0].size,u=i.pageSize;await ka(i,o,e);for(let t=0;t<d;t+=u){const e=Math.min(d-t,u),a=await i.read(e);await r.write(a)}await Ra(i),2==t&&await async function(e){const d=2**e,u=n[s],g=2*u.F.n8;let f;f=new Se(d*g),await ka(i,o,t),2==t&&e==l+1?(await i.readToBuffer(f,0,(d-1)*g),f.set(n.G1.zeroAffine,(d-1)*g)):await i.readToBuffer(f,0,d*g);await Ra(i,!0),f=await u.lagrangeEvaluations(f,"affine","affine",a,c),await r.write(f)}(l+1);await Ma(r)}(2,12,"G1","tauG1"),await $a(i,o,r,13),await $a(i,o,r,14),await $a(i,o,r,15),await i.close(),void await r.close()},exportJson:async function(t,e){const{fd:a,sections:i}=await za(t,"ptau",1),{curve:o,power:n}=await Ho(a,i),l={};return l.q=o.q,l.power=n,l.contributions=await Jo(a,o,i),l.tauG1=await r(2,"G1",2**n*2-1,"tauG1"),l.tauG2=await r(3,"G2",2**n,"tauG2"),l.alphaTauG1=await r(4,"G1",2**n,"alphaTauG1"),l.betaTauG1=await r(5,"G1",2**n,"betaTauG1"),l.betaG2=await r(6,"G2",1,"betaG2"),l.lTauG1=await s(12,"G1","lTauG1"),l.lTauG2=await s(13,"G2","lTauG2"),l.lAlphaTauG1=await s(14,"G1","lAlphaTauG2"),l.lBetaTauG1=await s(15,"G1","lBetaTauG2"),await a.close(),ji(o.Fr,l);async function r(t,n,l,r){const s=o[n],c=2*s.F.n8,d=[];await ka(a,i,t);for(let t=0;t<l;t++){e&&t&&t%1e4==0&&console.log(`${r}: `+t);const i=await a.read(c);d.push(s.fromRprLEM(i,0))}return await Ra(a),d}async function s(t,l,r){const s=o[l],c=2*s.F.n8,d=[];await ka(a,i,t);for(let t=0;t<=n;t++){e&&console.log(`${r}: Power: ${t}`),d[t]=[];const i=2**t;for(let o=0;o<i;o++){e&&o&&o%1e4==0&&console.log(`${r}: ${o}/${i}`);const n=await a.read(c);d[t].push(s.fromRprLEM(n,0))}}return await Ra(a,!0),d}}});const cn=262144,dn={get:function(t,e){return isNaN(e)?t[e]:t.getElement(e)},set:function(t,e,a){return isNaN(e)?(t[e]=a,!0):t.setElement(e,a)}};class un{constructor(t){this.length=t||0,this.arr=new Array(cn);for(let e=0;e<t;e+=cn)this.arr[e/cn]=new Array(Math.min(cn,t-e));return this}push(){for(let t=0;t<arguments.length;t++)this.setElement(this.length,arguments[t])}slice(t,e){const a=new Array(e-t);for(let i=t;i<e;i++)a[i-t]=this.getElement(i);return a}getElement(t){t=parseInt(t);const e=Math.floor(t/cn),a=t%cn;return this.arr[e]?this.arr[e][a]:void 0}setElement(t,e){t=parseInt(t);const a=Math.floor(t/cn);this.arr[a]||(this.arr[a]=new Array(cn));const i=t%cn;return this.arr[a][i]=e,t>=this.length&&(this.length=t+1),!0}getKeys(){const t=new gn;for(let e=0;e<this.arr.length;e++)if(this.arr[e])for(let a=0;a<this.arr[e].length;a++)void 0!==this.arr[e][a]&&t.push(e*cn+a);return t}}class gn{constructor(t){const e=new un(t);return new Proxy(e,dn)}}const fn=4,hn=5;async function _n(t,e,a){let i;i="object"==typeof a?a:void 0===a?{singleThread:!1}:{singleThread:a};const o={};if(await ka(t,e,1),o.n8=await t.readULE32(),o.prime=await Na(t,o.n8),i.F){if(i.F.p!=o.prime)throw new Error("Different Prime");o.F=i.F}else if(i.getFieldFromPrime)o.F=await i.getFieldFromPrime(o.prime,i.singleThread);else if(i.getCurveFromPrime)o.curve=await i.getCurveFromPrime(o.prime,i.singleThread),o.F=o.curve.Fr;else try{o.curve=await async function(t,e,a){let i;if(y(t,ua))i=await sa(e,a);else{if(!y(t,da))throw new Error(`Curve not supported: ${B(t)}`);i=await ca(e,a)}return i}(o.prime,i.singleThread),o.F=o.curve.Fr}catch(t){o.F=new $(o.prime)}return o.nVars=await t.readULE32(),o.nOutputs=await t.readULE32(),o.nPubInputs=await t.readULE32(),o.nPrvInputs=await t.readULE32(),o.nLabels=await t.readULE64(),o.nConstraints=await t.readULE32(),o.useCustomGates=void 0!==e[fn]&&null!==e[fn]&&void 0!==e[hn]&&null!==e[hn],await Ra(t),o}async function pn(t,e,a){if("object"!=typeof a)throw new Error("readR1csFd: options must be an object");a.loadConstraints=!("loadConstraints"in a)||a.loadConstraints,a.loadMap="loadMap"in a&&a.loadMap,a.loadCustomGates=!("loadCustomGates"in a)||a.loadCustomGates;const i=await _n(t,e,a);return a.loadConstraints&&(i.constraints=await async function(t,e,a,i,o){let n;n="object"==typeof i?i:void 0===i?{}:{logger:i,loggerCtx:o};const l=await Va(t,e,2);let r,s=0;r=a.nConstraints>1<<20?new gn:[];for(let t=0;t<a.nConstraints;t++){n.logger&&t%1e5==0&&n.logger.info(`${n.loggerCtx}: Loading constraints: ${t}/${a.nConstraints}`);const e=c();r.push(e)}return r;function c(){const t=[];return t[0]=d(),t[1]=d(),t[2]=d(),t}function d(){const t={},e=l.slice(s,s+4);s+=4;const i=new DataView(e.buffer).getUint32(0,!0),o=l.slice(s,s+(4+a.n8)*i);s+=(4+a.n8)*i;const n=new DataView(o.buffer);for(let e=0;e<i;e++){const i=n.getUint32(e*(4+a.n8),!0),l=a.F.fromRprLE(o,e*(4+a.n8)+4);t[i]=l}return t}}(t,e,i,a)),a.loadMap&&(i.map=await async function(t,e,a,i,o){let n;n="object"==typeof i?i:void 0===i?{}:{logger:i,loggerCtx:o};const l=await Va(t,e,3);let r,s=0;r=a.nVars>1<<20?new gn:[];for(let t=0;t<a.nVars;t++){n.logger&&t%1e4==0&&n.logger.info(`${n.loggerCtx}: Loading map: ${t}/${a.nVars}`);const e=c();r.push(e)}return r;function c(){const t=l.slice(s,s+8);s+=8;const e=new DataView(t.buffer),a=e.getUint32(0,!0);return 4294967296*e.getUint32(4,!0)+a}}(t,e,i,a)),a.loadCustomGates&&(i.useCustomGates?(i.customGates=await async function(t,e,a){await ka(t,e,fn);let i=await t.readULE32(),o=[];for(let e=0;e<i;e++){let e={};e.templateName=await t.readString();let i=await t.readULE32();e.parameters=Array(i);let n=await t.read(a.n8*i);for(let t=0;t<i;t++)e.parameters[t]=a.F.fromRprLE(n,t*a.n8,a.n8);o.push(e)}return await Ra(t),o}(t,e,i),i.customGatesUses=await async function(t,e,a){const i=await Va(t,e,hn),o=new Uint32Array(i.buffer,i.byteOffset,i.byteLength/4),n=o[0];let l,r=1;l=n>1<<20?new gn:[];for(let t=0;t<n;t++){a.logger&&t%1e5==0&&a.logger.info(`${a.loggerCtx}: Loading custom gate uses: ${t}/${n}`);let e={};e.id=o[r++];let i=o[r++];e.signals=[];for(let t=0;t<i;t++){const t=o[r++],a=o[r++];e.signals.push(4294967296*a+t)}l.push(e)}return l}(t,e,a)):(i.customGates=[],i.customGatesUses=[])),i}async function mn(t,e,a,i,o,n){let l;l="object"==typeof e?e:void 0===e?{loadConstraints:!0,loadMap:!1,loadCustomGates:!0}:{loadConstraints:e,loadMap:a,singleThread:i,logger:o,loggerCtx:n};const{fd:r,sections:s}=await za(t,"r1cs",1),c=await pn(r,s,l);return await r.close(),c}const wn=ga.e("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",16),Ln=ga.e("21888242871839275222246405745257275088548364400416034343698204186575808495617");var bn=Object.freeze({__proto__:null,print:function(t,e,a){for(let e=0;e<t.constraints.length;e++)i(t.constraints[e]);function i(i){const o=a=>{let i="";return Object.keys(a).forEach((o=>{let n=e.varIdx2Name[o];"one"==n&&(n="1");let l=t.curve.Fr.toString(a[o]);"1"==l&&(l=""),"-1"==l&&(l="-"),""!=i&&"-"!=l[0]&&(l="+"+l),""!=i&&(l=" "+l),i=i+l+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 mn(t);return ga.eq(a.prime,Ln)?e&&e.info("Curve: bn-128"):ga.eq(a.prime,wn)?e&&e.info("Curve: bls12-381"):e&&e.info(`Unknown Curve. Prime: ${ga.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 mn(t,!0,!0,!0,e),i=a.curve.Fr;return delete a.curve,delete a.F,ji(i,a)}});async function yn(t){const e={labelIdx2Name:["one"],varIdx2Name:["one"],componentIdx2Name:[]},a=await Ua(t),i=await a.read(a.totalSize),o=new TextDecoder("utf-8").decode(i).split("\n");for(let t=0;t<o.length;t++){const a=o[t].split(",");4==a.length&&(e.varIdx2Name[a[1]]?e.varIdx2Name[a[1]]+="|"+a[3]:e.varIdx2Name[a[1]]=a[3],e.labelIdx2Name[a[0]]=a[3],e.componentIdx2Name[a[2]]||(e.componentIdx2Name[a[2]]=n(a[3])))}return await a.close(),e;function n(t){const e=t.split(".");return e.pop(),e.join(".")}}const{unstringifyBigInts:An}=fa;var Cn=Object.freeze({__proto__:null,calculate:Qo,debug:async function(t,e,a,i,o,n){const l=An(t),r=await Ua(e),s=await r.read(r.totalSize);await r.close();let c={sanityCheck:!0},d=await yn(i);o.set&&(d||(d=await yn(i)),c.logSetSignal=function(t,e){n&&n.info("SET "+d.labelIdx2Name[t]+" <-- "+e.toString())}),o.get&&(d||(d=await yn(i)),c.logGetSignal=function(t,e){n&&n.info("GET "+d.labelIdx2Name[t]+" --\x3e "+e.toString())}),o.trigger&&(d||(d=await yn(i)),c.logStartComponent=function(t){n&&n.info("START: "+d.componentIdx2Name[t])},c.logFinishComponent=function(t){n&&n.info("FINISH: "+d.componentIdx2Name[t])}),c.sym=d;const u=await Oo(s,c),g=await u.calculateWitness(l),f=await Qa(a,"wtns",2,2);await async function(t,e,a){await qa(t,1);const i=8*(Math.floor((ga.bitLength(a)-1)/64)+1);await t.writeULE32(i),await Da(t,a,i),await t.writeULE32(e.length),await Ma(t),await qa(t,2);for(let a=0;a<e.length;a++)await Da(t,e[a],i);await Ma(t)}(f,g,u.prime),await f.close()},exportJson:async function(t){return await async function(t){const{fd:e,sections:a}=await za(t,"wtns",2),{n8:i,nWitness:o}=await xo(e,a);await ka(e,a,2);const n=[];for(let t=0;t<o;t++){const t=await Na(e,i);n.push(t)}return await Ra(e),await e.close(),n}(t)},check:async function(t,e,a){a&&a.info("WITNESS CHECKING STARTED"),a&&a.info("> Reading r1cs file");const{fd:i,sections:o}=await za(t,"r1cs",1),n=await pn(i,o,{loadConstraints:!1,loadCustomGates:!1});a&&a.info("> Reading witness file");const{fd:l,sections:r}=await za(e,"wtns",2),s=await xo(l,r);if(!ga.eq(n.prime,s.q))throw new Error("Curve of the witness does not match the curve of the proving key");const c=await Va(l,r,2);await l.close();const d=(await async function(t){let e;if(ga.eq(t,Ha))e=await sa();else{if(!ga.eq(t,ja))throw new Error(`Curve not supported: ${ga.toString(t)}`);e=await ca()}return e}(n.prime)).Fr,u=d.n8,g=await Va(i,o,2);a&&(a.info("----------------------------"),a.info(" WITNESS CHECK"),a.info(` Curve: ${n.curve.name}`),a.info(` Vars (wires): ${n.nVars}`),a.info(` Ouputs: ${n.nOutputs}`),a.info(` Public Inputs: ${n.nPubInputs}`),a.info(` Private Inputs: ${n.nPrvInputs}`),a.info(` Labels: ${n.nLabels}`),a.info(` Constraints: ${n.nConstraints}`),a.info(` Custom Gates: ${n.useCustomGates}`),a.info("----------------------------")),a&&a.info("> Checking witness correctness");let f=0,h=!0;for(let t=0;t<n.nConstraints;t++){a&&0!==t&&t%5e5==0&&a.info(`··· processing r1cs constraints ${t}/${n.nConstraints}`);const e=p(),i=p(),o=p(),l=_(e),r=_(i),s=_(o);if(!d.eq(d.sub(d.mul(l,r),s),d.zero)){a.warn("··· aborting checking process at constraint "+t),h=!1;break}}return i.close(),a&&(h?(a.info("WITNESS IS CORRECT"),a.info("WITNESS CHECKING FINISHED SUCCESSFULLY")):(a.warn("WITNESS IS NOT CORRECT"),a.warn("WITNESS CHECKING FINISHED UNSUCCESSFULLY"))),h;function _(t){let e=d.zero;return Object.keys(t).forEach((a=>{const i=function(t){return d.fromRprLE(c.slice(t*u,t*u+u))}(a),o=t[a];e=d.add(e,d.mul(i,o))})),e}function p(){const t={},e=g.slice(f,f+4);f+=4;const a=new DataView(e.buffer).getUint32(0,!0),i=g.slice(f,f+(4+n.n8)*a);f+=(4+n.n8)*a;const o=new DataView(i.buffer);for(let e=0;e<a;e++){const a=o.getUint32(e*(4+n.n8),!0),l=n.F.fromRprLE(i,e*(4+n.n8)+4);t[a]=l}return t}}});const In=262144,Fn={get:function(t,e){return isNaN(e)?t[e]:t.getElement(e)},set:function(t,e,a){return isNaN(e)?(t[e]=a,!0):t.setElement(e,a)}};class xn{constructor(t){this.length=t||0,this.arr=new Array(In);for(let e=0;e<t;e+=In)this.arr[e/In]=new Array(Math.min(In,t-e));return this}push(){for(let t=0;t<arguments.length;t++)this.setElement(this.length,arguments[t])}slice(t,e){const a=new Array(e-t);for(let i=t;i<e;i++)a[i-t]=this.getElement(i);return a}getElement(t){t=parseInt(t);const e=Math.floor(t/In),a=t%In;return this.arr[e]?this.arr[e][a]:void 0}setElement(t,e){t=parseInt(t);const a=Math.floor(t/In);this.arr[a]||(this.arr[a]=new Array(In));const i=t%In;return this.arr[a][i]=e,t>=this.length&&(this.length=t+1),!0}getKeys(){const t=new En;for(let e=0;e<this.arr.length;e++)if(this.arr[e])for(let a=0;a<this.arr[e].length;a++)void 0!==this.arr[e][a]&&t.push(e*In+a);return t}}class En{constructor(t){const e=new xn(t);return new Proxy(e,Fn)}}async function vn(t,e,a,i){await ti.exports.ready();const o=ti.exports(64),{fd:n,sections:l}=await za(e,"ptau",1),{curve:r,power:s}=await Ho(n,l),{fd:c,sections:d}=await za(t,"r1cs",1),u=await _n(c,d,!1),g=await Qa(a,"zkey",1,10,1<<22,1<<24),f=2*r.G1.F.n8,h=2*r.G2.F.n8;if(u.prime!=r.r)return i&&i.error("r1cs curve does not match powers of tau ceremony curve"),-1;const _=Ui(u.nConstraints+u.nPubInputs+u.nOutputs+1-1)+1;if(_>s)return i&&i.error(`circuit too big for this power of tau ceremony. ${u.nConstraints}*2 > 2**${s}`),-1;if(!l[12])return i&&i.error("Powers of tau is not prepared."),-1;const p=u.nOutputs+u.nPubInputs,m=2**_;await qa(g,1),await g.writeULE32(1),await Ma(g),await qa(g,2);const w=r.q,L=8*(Math.floor((ga.bitLength(w)-1)/64)+1),b=r.r,y=8*(Math.floor((ga.bitLength(b)-1)/64)+1),A=ga.mod(ga.shl(1,8*y),b),C=r.Fr.e(ga.mod(ga.mul(A,A),b));let I,F,x;await g.writeULE32(L),await Da(g,w,L),await g.writeULE32(y),await Da(g,b,y),await g.writeULE32(u.nVars),await g.writeULE32(p),await g.writeULE32(m),I=await n.read(f,l[4][0].p),await g.write(I),I=await r.G1.batchLEMtoU(I),o.update(I),F=await n.read(f,l[5][0].p),await g.write(F),F=await r.G1.batchLEMtoU(F),o.update(F),x=await n.read(h,l[6][0].p),await g.write(x),x=await r.G2.batchLEMtoU(x),o.update(x);const E=new Uint8Array(f);r.G1.toRprLEM(E,0,r.G1.g);const v=new Uint8Array(h);r.G2.toRprLEM(v,0,r.G2.g);const B=new Uint8Array(f);r.G1.toRprUncompressed(B,0,r.G1.g);const S=new Uint8Array(h);r.G2.toRprUncompressed(S,0,r.G2.g),await g.write(v),await g.write(E),await g.write(v),o.update(S),o.update(B),o.update(S),await Ma(g),i&&i.info("Reading r1cs");let P=await Va(c,d,2);const G=new En(u.nVars),O=new En(u.nVars),T=new En(u.nVars),U=new En(u.nVars-p-1),z=new Array(p+1);i&&i.info("Reading tauG1");let Q=await Va(n,l,12,(m-1)*f,m*f);i&&i.info("Reading tauG2");let q=await Va(n,l,13,(m-1)*h,m*h);i&&i.info("Reading alphatauG1");let M=await Va(n,l,14,(m-1)*f,m*f);i&&i.info("Reading betatauG1");let k=await Va(n,l,15,(m-1)*f,m*f);await async function(){const t=new Uint8Array(12+r.Fr.n8),e=new DataView(t.buffer),a=new Uint8Array(r.Fr.n8);r.Fr.toRprLE(a,0,r.Fr.e(1));let o=0;function n(){const t=P.slice(o,o+4);o+=4;return new DataView(t.buffer).getUint32(0,!0)}const l=new En;for(let t=0;t<u.nConstraints;t++){i&&t%1e4==0&&i.debug(`processing constraints: ${t}/${u.nConstraints}`);const e=n();for(let a=0;a<e;a++){const e=n(),a=o;o+=r.Fr.n8;const i=0,s=f*t,c=3,d=f*t;void 0===G[e]&&(G[e]=[]),G[e].push([i,s,a]),e<=p?(void 0===z[e]&&(z[e]=[]),z[e].push([c,d,a])):(void 0===U[e-p-1]&&(U[e-p-1]=[]),U[e-p-1].push([c,d,a])),l.push([0,t,e,a])}const a=n();for(let e=0;e<a;e++){const e=n(),a=o;o+=r.Fr.n8;const i=0,s=f*t,c=1,d=h*t,u=2,g=f*t;void 0===O[e]&&(O[e]=[]),O[e].push([i,s,a]),void 0===T[e]&&(T[e]=[]),T[e].push([c,d,a]),e<=p?(void 0===z[e]&&(z[e]=[]),z[e].push([u,g,a])):(void 0===U[e-p-1]&&(U[e-p-1]=[]),U[e-p-1].push([u,g,a])),l.push([1,t,e,a])}const s=n();for(let e=0;e<s;e++){const e=n(),a=o;o+=r.Fr.n8;const i=0,l=f*t;e<=p?(void 0===z[e]&&(z[e]=[]),z[e].push([i,l,a])):(void 0===U[e-p-1]&&(U[e-p-1]=[]),U[e-p-1].push([i,l,a]))}}for(let t=0;t<=p;t++){const e=0,a=f*(u.nConstraints+t),i=3,o=f*(u.nConstraints+t);void 0===G[t]&&(G[t]=[]),G[t].push([e,a,-1]),void 0===z[t]&&(z[t]=[]),z[t].push([i,o,-1]),l.push([0,u.nConstraints+t,t,-1])}await qa(g,4);const s=new Se(l.length*(12+r.Fr.n8)+4),c=new Uint8Array(4);new DataView(c.buffer).setUint32(0,l.length,!0),s.set(c);let d=4;for(let t=0;t<l.length;t++)i&&t%1e5==0&&i.debug(`writing coeffs: ${t}/${l.length}`),_(l[t]);function _(i){let o;e.setUint32(0,i[0],!0),e.setUint32(4,i[1],!0),e.setUint32(8,i[2],!0),o=i[3]>=0?r.Fr.fromRprLE(P.slice(i[3],i[3]+r.Fr.n8),0):r.Fr.fromRprLE(a,0);const n=r.Fr.mul(o,C);r.Fr.toRprLE(t,12,n),s.set(t,d),d+=t.length}await g.write(s),await Ma(g)}(),await D(3,"G1",z,"IC"),await async function(){await qa(g,9);const t=new Se(m*f);if(_<r.Fr.s){let e=await Va(n,l,12,(2*m-1)*f,2*m*f);for(let a=0;a<m;a++){i&&a%1e4==0&&i.debug(`spliting buffer: ${a}/${m}`);const o=e.slice((2*a+1)*f,(2*a+1)*f+f);t.set(o,a*f)}}else{if(_!=r.Fr.s)throw i&&i.error("Circuit too big"),new Error("Circuit too big for this curve");{const e=l[12][0].p+(2**(_+1)-1)*f;await n.readToBuffer(t,0,m*f,e+m*f)}}await g.write(t),await Ma(g)}(),await async function(){K(m-1);for(let t=0;t<m-1;t+=16384){i&&i.debug(`HashingHPoints: ${t}/${m}`);const e=Math.min(m-1,16384);await $(t,e)}}(),await D(8,"G1",U,"C"),await D(5,"G1",G,"A"),await D(6,"G1",O,"B1"),await D(7,"G2",T,"B2");const R=o.digest();return await qa(g,10),await g.write(R),await g.writeULE32(0),await Ma(g),i&&i.info(zi(R,"Circuit hash: ")),await g.close(),await c.close(),await n.close(),R;async function D(t,e,a,n){const l=r[e];K(a.length),await qa(g,t);let s=[],c=0;for(;c<a.length;){let t=0;for(;c<a.length&&t<r.tm.concurrency;){i&&i.debug(`Writing points start ${n}: ${c}/${a.length}`);let o=1,l=a[c]?a[c].length:0;for(;c+o<a.length&&l+(a[c+o]?a[c+o].length:0)<32768&&o<32768;)l+=a[c+o]?a[c+o].length:0,o++;const r=a.slice(c,c+o),d=c;s.push(N(e,r,i,n).then((t=>(i&&i.debug(`Writing points end ${n}: ${d}/${a.length}`),t)))),c+=o,t++}const d=await Promise.all(s);for(let t=0;t<d.length;t++){await g.write(d[t][0]);const e=await l.batchLEMtoU(d[t][0]);o.update(e)}s=[]}await Ma(g)}async function N(t,e,a,i){const o=r[t],n=2*o.F.n8,l=3*o.F.n8,s=2*o.F.n8;let c,d,u,g;if("G1"==t)c="g1m_timesScalarAffine",d="g1m_multiexpAffine",u="g1m_batchToAffine",g="g1m_zero";else{if("G2"!=t)throw new Error("Invalid group");c="g2m_timesScalarAffine",d="g2m_multiexpAffine",u="g2m_batchToAffine",g="g2m_zero"}let f,h,_=0;for(let t=0;t<e.length;t++)_+=e[t]?e[t].length:0;_>32768?(f=new Se(_*n),h=new Se(_*r.Fr.n8)):(f=new Uint8Array(_*n),h=new Uint8Array(_*r.Fr.n8));let p=0,m=0;const w=[Q,q,M,k],L=new Uint8Array(r.Fr.n8);r.Fr.toRprLE(L,0,r.Fr.e(1));let b=0;for(let t=0;t<e.length;t++)if(e[t])for(let o=0;o<e[t].length;o++)a&&o&&o%1e4==0&&a.debug(`Configuring big array ${i}: ${o}/${e[t].length}`),f.set(w[e[t][o][0]].slice(e[t][o][1],e[t][o][1]+n),b*n),e[t][o][2]>=0?h.set(P.slice(e[t][o][2],e[t][o][2]+r.Fr.n8),b*r.Fr.n8):h.set(L,b*r.Fr.n8),b++;if(e.length>1){const t=[];t.push({cmd:"ALLOCSET",var:0,buff:f}),t.push({cmd:"ALLOCSET",var:1,buff:h}),t.push({cmd:"ALLOC",var:2,len:e.length*l}),p=0,m=0;let a=0;for(let i=0;i<e.length;i++)e[i]?(1==e[i].length?t.push({cmd:"CALL",fnName:c,params:[{var:0,offset:p},{var:1,offset:m},{val:r.Fr.n8},{var:2,offset:a}]}):t.push({cmd:"CALL",fnName:d,params:[{var:0,offset:p},{var:1,offset:m},{val:r.Fr.n8},{val:e[i].length},{var:2,offset:a}]}),p+=n*e[i].length,m+=r.Fr.n8*e[i].length,a+=l):(t.push({cmd:"CALL",fnName:g,params:[{var:2,offset:a}]}),a+=l);t.push({cmd:"CALL",fnName:u,params:[{var:2},{val:e.length},{var:2}]}),t.push({cmd:"GET",out:0,var:2,len:e.length*s});return await r.tm.queueAction(t)}{let t=await o.multiExpAffine(f,h,a,i);return t=[o.toAffine(t)],t}}async function $(t,e){const a=await n.read(e*f,l[2][0].p+(t+m)*f),i=await n.read(e*f,l[2][0].p+t*f),s=r.tm.concurrency,c=Math.floor(e/s),d=[];for(let t=0;t<s;t++){let o;if(o=t<s-1?c:e-t*c,0==o)continue;const n=a.slice(t*c*f,(t*c+o)*f),l=i.slice(t*c*f,(t*c+o)*f);d.push(V(n,l))}const u=await Promise.all(d);for(let t=0;t<u.length;t++)o.update(u[t][0])}async function V(t,e){const a=t.byteLength/f,i=3*r.G1.F.n8,o=[];o.push({cmd:"ALLOCSET",var:0,buff:t}),o.push({cmd:"ALLOCSET",var:1,buff:e}),o.push({cmd:"ALLOC",var:2,len:a*i});for(let t=0;t<a;t++)o.push({cmd:"CALL",fnName:"g1m_subAffine",params:[{var:0,offset:t*f},{var:1,offset:t*f},{var:2,offset:t*i}]});o.push({cmd:"CALL",fnName:"g1m_batchToAffine",params:[{var:2},{val:a},{var:2}]}),o.push({cmd:"CALL",fnName:"g1m_batchLEMtoU",params:[{var:2},{val:a},{var:2}]}),o.push({cmd:"GET",out:0,var:2,len:a*f});return await r.tm.queueAction(o)}function K(t){const e=new Uint8Array(4);new DataView(e.buffer,e.byteOffset,e.byteLength).setUint32(0,t,!1),o.update(e)}}const Bn=Mi;async function Sn(t,e,a,i){let o;await ti.exports.ready();const{fd:n,sections:l}=await za(a,"zkey",2),r=await Lo(n,l,!1);if("groth16"!=r.protocol)throw new Error("zkey file is not groth16");const s=await Ya(r.q),c=2*s.G1.F.n8,d=await yo(n,s,l),u=ti.exports(64);u.update(d.csHash);let g=s.G1.g;for(let t=0;t<d.contributions.length;t++){const e=d.contributions[t],a=qi(u);if(Io(a,s,e.delta.g1_s),Io(a,s,e.delta.g1_sx),!Qi(a.digest(),e.transcript))return console.log(`INVALID(${t}): Inconsistent transcript `),!1;const i=No(s,e.transcript);if(o=await Bn(s,e.delta.g1_s,e.delta.g1_sx,i,e.delta.g2_spx),!0!==o)return console.log(`INVALID(${t}): public key G1 and G2 do not have the same ration `),!1;if(o=await Bn(s,g,e.deltaAfter,i,e.delta.g2_spx),!0!==o)return console.log(`INVALID(${t}): deltaAfter does not fillow the public key `),!1;if(1==e.type){const a=await $i(e.beaconHash,e.numIterationsExp),i=s.Fr.fromRng(a),o=s.G1.toAffine(s.G1.fromRng(a)),n=s.G1.toAffine(s.G1.timesFr(o,i));if(!0!==s.G1.eq(o,e.delta.g1_s))return console.log(`INVALID(${t}): Key of the beacon does not match. g1_s `),!1;if(!0!==s.G1.eq(n,e.delta.g1_sx))return console.log(`INVALID(${t}): Key of the beacon does not match. g1_sx `),!1}Fo(u,s,e);const n=ti.exports(64);Fo(n,s,e),e.contributionHash=n.digest(),g=e.deltaAfter}const{fd:f,sections:h}=await za(t,"zkey",2),_=await Lo(f,h,!1);if("groth16"!=_.protocol)throw new Error("zkeyinit file is not groth16");if(!ga.eq(_.q,r.q)||!ga.eq(_.r,r.r)||_.n8q!=r.n8q||_.n8r!=r.n8r)return i&&i.error("INVALID: Different curves"),!1;if(_.nVars!=r.nVars||_.nPublic!=r.nPublic||_.domainSize!=r.domainSize)return i&&i.error("INVALID: Different circuit parameters"),!1;if(!s.G1.eq(r.vk_alpha_1,_.vk_alpha_1))return i&&i.error("INVALID: Invalid alpha1"),!1;if(!s.G1.eq(r.vk_beta_1,_.vk_beta_1))return i&&i.error("INVALID: Invalid beta1"),!1;if(!s.G2.eq(r.vk_beta_2,_.vk_beta_2))return i&&i.error("INVALID: Invalid beta2"),!1;if(!s.G2.eq(r.vk_gamma_2,_.vk_gamma_2))return i&&i.error("INVALID: Invalid gamma2"),!1;if(!s.G1.eq(r.vk_delta_1,g))return i&&i.error("INVALID: Invalid delta1"),!1;if(o=await Bn(s,s.G1.g,g,s.G2.g,r.vk_delta_2),!0!==o)return i&&i.error("INVALID: Invalid delta2"),!1;const p=await yo(f,s,h);if(!Qi(d.csHash,p.csHash))return i&&i.error("INVALID: Circuit does not match"),!1;if(l[8][0].size!=c*(r.nVars-r.nPublic-1))return i&&i.error("INVALID: Invalid L section size"),!1;if(l[9][0].size!=c*r.domainSize)return i&&i.error("INVALID: Invalid H section size"),!1;let m;if(m=await Ka(n,l,f,h,3),!m)return i&&i.error("INVALID: IC section is not identical"),!1;if(m=await Ka(n,l,f,h,4),!m)return i&&i.error("Coeffs section is not identical"),!1;if(m=await Ka(n,l,f,h,5),!m)return i&&i.error("A section is not identical"),!1;if(m=await Ka(n,l,f,h,6),!m)return i&&i.error("B1 section is not identical"),!1;if(m=await Ka(n,l,f,h,7),!m)return i&&i.error("B2 section is not identical"),!1;if(o=await async function(t,e,a,n,l,r,c,d,u){const g=1<<20,f=s[t],h=2*f.F.n8;await ka(e,a,r),await ka(n,l,r);let _=f.zero,p=f.zero;const m=a[r][0].size/h;for(let t=0;t<m;t+=g){i&&i.debug(`Same ratio check ${u}: ${t}/${m}`);const a=Math.min(m-t,g),o=await e.read(a*h),l=await n.read(a*h),r=ki(4*a),s=await f.multiExpAffine(o,r),c=await f.multiExpAffine(l,r);_=f.add(_,s),p=f.add(p,c)}return await Ra(e),await Ra(n),0==m||(o=await Bn(s,_,p,c,d),!0===o)}("G1",f,h,n,l,8,r.vk_delta_2,_.vk_delta_2,"L section"),!0!==o)return i&&i.error("L section does not match"),!1;if(o=await async function(){const t=1<<20,a=s.G1,c=s.Fr,d=2*a.F.n8,{fd:u,sections:g}=await za(e,"ptau",1);let f=new Se(r.domainSize*r.n8r);const h=new Array(8);for(let t=0;t<8;t++)h[t]=Di(ki(4),0);const p=new Q(h);for(let t=0;t<r.domainSize-1;t++){const e=c.fromRng(p);c.toRprLE(f,t*r.n8r,e)}c.toRprLE(f,(r.domainSize-1)*r.n8r,c.zero);let m,L=a.zero;for(let e=0;e<r.domainSize;e+=t){i&&i.debug(`H Verificaition(tau): ${e}/${r.domainSize}`);const o=Math.min(r.domainSize-e,t),n=await u.read(d*o,g[2][0].p+r.domainSize*d+e*d),l=await u.read(d*o,g[2][0].p+e*d),s=await w(n,l),c=f.slice(e*r.n8r,(e+o)*r.n8r),h=await a.multiExpAffine(s,c);L=a.add(L,h)}if(f=await c.batchToMontgomery(f),r.power<c.s)m=c.neg(c.e(2));else{const t=2**c.s,e=c.exp(c.shift,t);m=c.sub(e,c.one)}const b=r.power<c.s?c.w[r.power+1]:c.shift;f=await c.batchApplyKey(f,m,b),f=await c.fft(f),f=await c.batchFromMontgomery(f),await ka(n,l,9);let y=a.zero;for(let e=0;e<r.domainSize;e+=t){i&&i.debug(`H Verificaition(lagrange): ${e}/${r.domainSize}`);const o=Math.min(r.domainSize-e,t),l=await n.read(d*o),s=f.slice(e*r.n8r,(e+o)*r.n8r),c=await a.multiExpAffine(l,s);y=a.add(y,c)}return await Ra(n),o=await Bn(s,L,y,r.vk_delta_2,_.vk_delta_2),!0===o}(),!0!==o)return i&&i.error("H section does not match"),!1;i&&i.info(zi(d.csHash,"Circuit Hash: ")),await n.close(),await f.close();for(let t=d.contributions.length-1;t>=0;t--){const e=d.contributions[t];i&&i.info("-------------------------"),i&&i.info(zi(e.contributionHash,`contribution #${t+1} ${e.name?e.name:""}:`)),1==e.type&&(i&&i.info(`Beacon generator: ${Ki(e.beaconHash)}`),i&&i.info(`Beacon iterations Exp: ${e.numIterationsExp}`))}return i&&i.info("-------------------------"),i&&i.info("ZKey Ok!"),!0;async function w(t,e){const a=2*s.G1.F.n8,i=t.byteLength/a,o=s.tm.concurrency,n=Math.floor(i/o),l=[];for(let a=0;a<o;a++){let r;if(r=a<o-1?n:i-a*n,0==r)continue;const s=t.slice(a*n*c,(a*n+r)*c),d=e.slice(a*n*c,(a*n+r)*c);l.push(L(s,d))}const r=await Promise.all(l),d=new Uint8Array(i*a);let u=0;for(let t=0;t<r.length;t++)d.set(r[t][0],u),u+=r[t][0].byteLength;return d}async function L(t,e){const a=2*s.G1.F.n8,i=3*s.G1.F.n8,o=t.byteLength/a,n=[];n.push({cmd:"ALLOCSET",var:0,buff:t}),n.push({cmd:"ALLOCSET",var:1,buff:e}),n.push({cmd:"ALLOC",var:2,len:o*i});for(let t=0;t<o;t++)n.push({cmd:"CALL",fnName:"g1m_subAffine",params:[{var:0,offset:t*a},{var:1,offset:t*a},{var:2,offset:t*i}]});n.push({cmd:"CALL",fnName:"g1m_batchToAffine",params:[{var:2},{val:o},{var:2}]}),n.push({cmd:"GET",out:0,var:2,len:o*a});return await s.tm.queueAction(n)}}const{stringifyBigInts:Pn}=fa;async function Gn(t,e){e&&e.info("EXPORT VERIFICATION KEY STARTED");const{fd:a,sections:i}=await za(t,"zkey",2),o=await Lo(a,i);let n;if(e&&e.info("> Detected protocol: "+o.protocol),"groth16"===o.protocol)n=await async function(t,e,a){const i=await Ya(t.q),o=2*i.G1.F.n8,n=await i.pairing(t.vk_alpha_1,t.vk_beta_2);let l={protocol:t.protocol,curve:i.name,nPublic:t.nPublic,vk_alpha_1:i.G1.toObject(t.vk_alpha_1),vk_beta_2:i.G2.toObject(t.vk_beta_2),vk_gamma_2:i.G2.toObject(t.vk_gamma_2),vk_delta_2:i.G2.toObject(t.vk_delta_2),vk_alphabeta_12:i.Gt.toObject(n)};await ka(e,a,3),l.IC=[];for(let a=0;a<=t.nPublic;a++){const t=await e.read(o),a=i.G1.toObject(t);l.IC.push(a)}return await Ra(e),l=Pn(l),l}(o,a,i);else if("plonk"===o.protocol)n=await async function(t){const e=await Ya(t.q);let a={protocol:t.protocol,curve:e.name,nPublic:t.nPublic,power:t.power,k1:e.Fr.toObject(t.k1),k2:e.Fr.toObject(t.k2),Qm:e.G1.toObject(t.Qm),Ql:e.G1.toObject(t.Ql),Qr:e.G1.toObject(t.Qr),Qo:e.G1.toObject(t.Qo),Qc:e.G1.toObject(t.Qc),S1:e.G1.toObject(t.S1),S2:e.G1.toObject(t.S2),S3:e.G1.toObject(t.S3),X_2:e.G2.toObject(t.X_2),w:e.Fr.toObject(e.Fr.w[t.power])};return a=Pn(a),a}(o);else{if(!o.protocolId||o.protocolId!==Wi)throw new Error("zkey file protocol unrecognized");n=await async function(t,e){const a=await Ya(t.q);let i={protocol:t.protocol,curve:a.name,nPublic:t.nPublic,power:t.power,k1:a.Fr.toObject(t.k1),k2:a.Fr.toObject(t.k2),w:a.Fr.toObject(a.Fr.w[t.power]),w3:a.Fr.toObject(t.w3),w4:a.Fr.toObject(t.w4),w8:a.Fr.toObject(t.w8),wr:a.Fr.toObject(t.wr),X_2:a.G2.toObject(t.X_2),C0:a.G1.toObject(t.C0)};return Pn(i)}(o)}return await a.close(),e&&e.info("EXPORT VERIFICATION KEY FINISHED"),n}var On={};const{unstringifyBigInts:Tn,stringifyBigInts:Un}=fa;async function zn(t,e,a){a&&a.info("FFLONK EXPORT SOLIDITY VERIFIER STARTED");const i=await Ja(t.curve);let o=c(t.w3);t.w3_2=d(i.Fr.square(o));let n=c(t.w4);t.w4_2=d(i.Fr.square(n)),t.w4_3=d(i.Fr.mul(i.Fr.square(n),n));let l=c(t.w8),r=i.Fr.one;for(let e=1;e<8;e++)r=i.Fr.mul(r,l),t["w8_"+e]=d(r);let s=e[t.protocol];return a&&a.info("FFLONK EXPORT SOLIDITY VERIFIER FINISHED"),On.render(s,t);function c(t){const e=Tn(t);return i.Fr.fromObject(e)}function d(t){const e=i.Fr.toObject(t);return Un(e)}}var Qn=Object.freeze({__proto__:null,newZKey:vn,exportBellman:async function(t,e,a){const{fd:i,sections:o}=await za(t,"zkey",2),n=await Lo(i,o);if("groth16"!=n.protocol)throw new Error("zkey file is not groth16");const l=await Ya(n.q),r=2*l.G1.F.n8,s=2*l.G2.F.n8,c=await yo(i,l,o),d=await Ta(e);let u;await w(n.vk_alpha_1),await w(n.vk_beta_1),await L(n.vk_beta_2),await L(n.vk_gamma_2),await w(n.vk_delta_1),await L(n.vk_delta_2),u=await Va(i,o,3),u=await l.G1.batchLEMtoU(u),await b("G1",u);const g=await Va(i,o,9);let f,h,_,p,m;f=await l.G1.fft(g,"affine","jacobian",a),f=await l.G1.batchApplyKey(f,l.Fr.neg(l.Fr.e(2)),l.Fr.w[n.power+1],"jacobian","affine",a),f=f.slice(0,f.byteLength-r),f=await l.G1.batchLEMtoU(f),await b("G1",f),h=await Va(i,o,8),h=await l.G1.batchLEMtoU(h),await b("G1",h),_=await Va(i,o,5),_=await l.G1.batchLEMtoU(_),await b("G1",_),p=await Va(i,o,6),p=await l.G1.batchLEMtoU(p),await b("G1",p),m=await Va(i,o,7),m=await l.G2.batchLEMtoU(m),await b("G2",m),await d.write(c.csHash),await async function(t){const e=new Uint8Array(4);new DataView(e.buffer,e.byteOffset,e.byteLength).setUint32(0,t,!1),await d.write(e)}(c.contributions.length);for(let t=0;t<c.contributions.length;t++){const e=c.contributions[t];await w(e.deltaAfter),await w(e.delta.g1_s),await w(e.delta.g1_sx),await L(e.delta.g2_spx),await d.write(e.transcript)}async function w(t){const e=new Uint8Array(r);l.G1.toRprUncompressed(e,0,t),await d.write(e)}async function L(t){const e=new Uint8Array(s);l.G2.toRprUncompressed(e,0,t),await d.write(e)}async function b(t,e){let a;a="G1"==t?r:s;const i=new Uint8Array(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,e.byteLength/a,!1),await d.write(i),await d.write(e)}await i.close(),await d.close()},importBellman:async function(t,e,a,i,o){const{fd:n,sections:l}=await za(t,"zkey",2),r=await Lo(n,l,!1);if("groth16"!=r.protocol)throw new Error("zkey file is not groth16");const s=await Ya(r.q),c=2*s.G1.F.n8,d=2*s.G2.F.n8,u=await yo(n,s,l),g={},f=await Ua(e);f.pos=3*c+3*d+8+c*r.nVars+4+c*(r.domainSize-1)+4+c*r.nVars+4+c*r.nVars+4+d*r.nVars,g.csHash=await f.read(64);const h=await f.readUBE32();g.contributions=[];for(let t=0;t<h;t++){const e={delta:{}};e.deltaAfter=await A(f),e.delta.g1_s=await A(f),e.delta.g1_sx=await A(f),e.delta.g2_spx=await C(f),e.transcript=await f.read(64),t<u.contributions.length&&(e.type=u.contributions[t].type,1==e.type&&(e.beaconHash=u.contributions[t].beaconHash,e.numIterationsExp=u.contributions[t].numIterationsExp),u.contributions[t].name&&(e.name=u.contributions[t].name)),g.contributions.push(e)}if(!Qi(g.csHash,u.csHash))return o&&o.error("Hash of the original circuit does not match with the MPC one"),!1;if(u.contributions.length>g.contributions.length)return o&&o.error("The impoerted file does not include new contributions"),!1;for(let t=0;t<u.contributions.length;t++)if(!I(u.contributions[t],g.contributions[t]))return o&&o.error(`Previos contribution ${t} does not match`),!1;if(i)for(let t=u.contributions.length;t<g.contributions.length;t++)g.contributions[t].name=i;const _=await Qa(a,"zkey",1,10);if(f.pos=0,f.pos+=c,f.pos+=c,f.pos+=d,f.pos+=d,r.vk_delta_1=await A(f),r.vk_delta_2=await C(f),await ho(_,r),await f.readUBE32()!=r.nPublic+1)return o&&o.error("Invalid number of points in IC"),await _.discard(),!1;if(f.pos+=c*(r.nPublic+1),await $a(n,l,_,3),await $a(n,l,_,4),await f.readUBE32()!=r.domainSize-1)return o&&o.error("Invalid number of points in H"),await _.discard(),!1;let p;const m=await f.read(c*(r.domainSize-1)),w=await s.G1.batchUtoLEM(m);p=new Uint8Array(r.domainSize*c),p.set(w),s.G1.toRprLEM(p,c*(r.domainSize-1),s.G1.zeroAffine);const L=s.Fr.neg(s.Fr.inv(s.Fr.e(2))),b=s.Fr.inv(s.Fr.w[r.power+1]);if(p=await s.G1.batchApplyKey(p,L,b,"affine","jacobian",o),p=await s.G1.ifft(p,"jacobian","affine",o),await qa(_,9),await _.write(p),await Ma(_),await f.readUBE32()!=r.nVars-r.nPublic-1)return o&&o.error("Invalid number of points in L"),await _.discard(),!1;let y;return y=await f.read(c*(r.nVars-r.nPublic-1)),y=await s.G1.batchUtoLEM(y),await qa(_,8),await _.write(y),await Ma(_),await f.readUBE32()!=r.nVars?(o&&o.error("Invalid number of points in A"),await _.discard(),!1):(f.pos+=c*r.nVars,await $a(n,l,_,5),await f.readUBE32()!=r.nVars?(o&&o.error("Invalid number of points in B1"),await _.discard(),!1):(f.pos+=c*r.nVars,await $a(n,l,_,6),await f.readUBE32()!=r.nVars?(o&&o.error("Invalid number of points in B2"),await _.discard(),!1):(f.pos+=d*r.nVars,await $a(n,l,_,7),await Co(_,s,g),await f.close(),await _.close(),await n.close(),!0)));async function A(t){const e=await t.read(2*s.G1.F.n8);return s.G1.fromRprUncompressed(e,0)}async function C(t){const e=await t.read(2*s.G2.F.n8);return s.G2.fromRprUncompressed(e,0)}function I(t,e){return!!s.G1.eq(t.deltaAfter,e.deltaAfter)&&(!!s.G1.eq(t.delta.g1_s,e.delta.g1_s)&&(!!s.G1.eq(t.delta.g1_sx,e.delta.g1_sx)&&(!!s.G2.eq(t.delta.g2_spx,e.delta.g2_spx)&&!!Qi(t.transcript,e.transcript))))}},verifyFromR1cs:async function(t,e,a,i){const o={type:"bigMem"};return await vn(t,e,o,i),await Sn(o,e,a,i)},verifyFromInit:Sn,contribute:async function(t,e,a,i,o){await ti.exports.ready();const{fd:n,sections:l}=await za(t,"zkey",2),r=await Lo(n,l);if("groth16"!=r.protocol)throw new Error("zkey file is not groth16");const s=await Ya(r.q),c=await yo(n,s,l),d=await Qa(e,"zkey",1,10),u=await Ni(i),g=ti.exports(64);g.update(c.csHash);for(let t=0;t<c.contributions.length;t++)Fo(g,s,c.contributions[t]);const f={delta:{}};f.delta.prvKey=s.Fr.fromRng(u),f.delta.g1_s=s.G1.toAffine(s.G1.fromRng(u)),f.delta.g1_sx=s.G1.toAffine(s.G1.timesFr(f.delta.g1_s,f.delta.prvKey)),Io(g,s,f.delta.g1_s),Io(g,s,f.delta.g1_sx),f.transcript=g.digest(),f.delta.g2_sp=No(s,f.transcript),f.delta.g2_spx=s.G2.toAffine(s.G2.timesFr(f.delta.g2_sp,f.delta.prvKey)),r.vk_delta_1=s.G1.timesFr(r.vk_delta_1,f.delta.prvKey),r.vk_delta_2=s.G2.timesFr(r.vk_delta_2,f.delta.prvKey),f.deltaAfter=r.vk_delta_1,f.type=0,a&&(f.name=a),c.contributions.push(f),await ho(d,r),await $a(n,l,d,3),await $a(n,l,d,4),await $a(n,l,d,5),await $a(n,l,d,6),await $a(n,l,d,7);const h=s.Fr.inv(f.delta.prvKey);await ln(n,l,d,8,s,"G1",h,s.Fr.e(1),"L Section",o),await ln(n,l,d,9,s,"G1",h,s.Fr.e(1),"H Section",o),await Co(d,s,c),await n.close(),await d.close();const _=ti.exports(64);Fo(_,s,f);const p=_.digest();return o&&o.info(zi(c.csHash,"Circuit Hash: ")),o&&o.info(zi(p,"Contribution Hash: ")),p},beacon:async function(t,e,a,i,o,n){await ti.exports.ready();const l=Vi(i);if(0==l.byteLength||2*l.byteLength!=i.length)return n&&n.error("Invalid Beacon Hash. (It must be a valid hexadecimal sequence)"),!1;if(l.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;const{fd:r,sections:s}=await za(t,"zkey",2),c=await Lo(r,s);if("groth16"!=c.protocol)throw new Error("zkey file is not groth16");const d=await Ya(c.q),u=await yo(r,d,s),g=await Qa(e,"zkey",1,10),f=await $i(l,o),h=ti.exports(64);h.update(u.csHash);for(let t=0;t<u.contributions.length;t++)Fo(h,d,u.contributions[t]);const _={delta:{}};_.delta.prvKey=d.Fr.fromRng(f),_.delta.g1_s=d.G1.toAffine(d.G1.fromRng(f)),_.delta.g1_sx=d.G1.toAffine(d.G1.timesFr(_.delta.g1_s,_.delta.prvKey)),Io(h,d,_.delta.g1_s),Io(h,d,_.delta.g1_sx),_.transcript=h.digest(),_.delta.g2_sp=No(d,_.transcript),_.delta.g2_spx=d.G2.toAffine(d.G2.timesFr(_.delta.g2_sp,_.delta.prvKey)),c.vk_delta_1=d.G1.timesFr(c.vk_delta_1,_.delta.prvKey),c.vk_delta_2=d.G2.timesFr(c.vk_delta_2,_.delta.prvKey),_.deltaAfter=c.vk_delta_1,_.type=1,_.numIterationsExp=o,_.beaconHash=l,a&&(_.name=a),u.contributions.push(_),await ho(g,c),await $a(r,s,g,3),await $a(r,s,g,4),await $a(r,s,g,5),await $a(r,s,g,6),await $a(r,s,g,7);const p=d.Fr.inv(_.delta.prvKey);await ln(r,s,g,8,d,"G1",p,d.Fr.e(1),"L Section",n),await ln(r,s,g,9,d,"G1",p,d.Fr.e(1),"H Section",n),await Co(g,d,u),await r.close(),await g.close();const m=ti.exports(64);Fo(m,d,_);const w=m.digest();return n&&n.info(zi(w,"Contribution Hash: ")),w},exportJson:async function(t){const e=await async function(t,e){const{fd:a,sections:i}=await za(t,"zkey",1),o=await Lo(a,i,e),n=new $(o.r),l=ga.mod(ga.shl(1,8*o.n8r),o.r),r=n.inv(l),s=n.mul(r,r);let c=await Ya(o.q);await ka(a,i,3),o.IC=[];for(let t=0;t<=o.nPublic;t++){const t=await mo(a,c,e);o.IC.push(t)}await Ra(a),await ka(a,i,4);const d=await a.readULE32();o.ccoefs=[];for(let t=0;t<d;t++){const t=await a.readULE32(),e=await a.readULE32(),i=await a.readULE32(),n=await u();o.ccoefs.push({matrix:t,constraint:e,signal:i,value:n})}await Ra(a),await ka(a,i,5),o.A=[];for(let t=0;t<o.nVars;t++){const i=await mo(a,c,e);o.A[t]=i}await Ra(a),await ka(a,i,6),o.B1=[];for(let t=0;t<o.nVars;t++){const i=await mo(a,c,e);o.B1[t]=i}await Ra(a),await ka(a,i,7),o.B2=[];for(let t=0;t<o.nVars;t++){const i=await wo(a,c,e);o.B2[t]=i}await Ra(a),await ka(a,i,8),o.C=[];for(let t=o.nPublic+1;t<o.nVars;t++){const i=await mo(a,c,e);o.C[t]=i}await Ra(a),await ka(a,i,9),o.hExps=[];for(let t=0;t<o.domainSize;t++){const t=await mo(a,c,e);o.hExps.push(t)}return await Ra(a),await a.close(),o;async function u(){const t=await Na(a,o.n8r);return n.mul(t,s)}}(t,!0);return delete e.curve,delete e.F,fa.stringifyBigInts(e)},bellmanContribute:async function(t,e,a,i,o){await ti.exports.ready();const n=await Ni(i),l=t.Fr.fromRng(n),r=t.Fr.inv(l),s=2*t.G1.F.n8,c=2*t.G2.F.n8,d=await Ua(e),u=await Ta(a);await v(s),await v(s),await v(c),await v(c);const g=await B(),f=t.G1.timesFr(g,l);await P(f);const h=await S(),_=t.G2.timesFr(h,l);await G(_);const p=await d.readUBE32();await u.writeUBE32(p),await v(p*s);const m=await d.readUBE32();await u.writeUBE32(m),await rn(d,u,null,t,"G1",m,r,t.Fr.e(1),"UNCOMPRESSED","H",o);const w=await d.readUBE32();await u.writeUBE32(w),await rn(d,u,null,t,"G1",w,r,t.Fr.e(1),"UNCOMPRESSED","L",o);const L=await d.readUBE32();await u.writeUBE32(L),await v(L*s);const b=await d.readUBE32();await u.writeUBE32(b),await v(b*s);const y=await d.readUBE32();await u.writeUBE32(y),await v(y*c);const A=ti.exports(64),C={};C.csHash=await d.read(64),A.update(C.csHash);const I=await d.readUBE32();C.contributions=[];for(let e=0;e<I;e++){const e={delta:{}};e.deltaAfter=await B(),e.delta.g1_s=await B(),e.delta.g1_sx=await B(),e.delta.g2_spx=await S(),e.transcript=await d.read(64),C.contributions.push(e),Fo(A,t,e)}const F={delta:{}};F.delta.prvKey=l,F.delta.g1_s=t.G1.toAffine(t.G1.fromRng(n)),F.delta.g1_sx=t.G1.toAffine(t.G1.timesFr(F.delta.g1_s,l)),Io(A,t,F.delta.g1_s),Io(A,t,F.delta.g1_sx),F.transcript=A.digest(),F.delta.g2_sp=No(t,F.transcript),F.delta.g2_spx=t.G2.toAffine(t.G2.timesFr(F.delta.g2_sp,l)),F.deltaAfter=f,F.type=0,C.contributions.push(F),await u.write(C.csHash),await u.writeUBE32(C.contributions.length);for(let t=0;t<C.contributions.length;t++){const e=C.contributions[t];await P(e.deltaAfter),await P(e.delta.g1_s),await P(e.delta.g1_sx),await G(e.delta.g2_spx),await u.write(e.transcript)}const x=ti.exports(64);Fo(x,t,F);const E=x.digest();return o&&o.info(zi(E,"Contribution Hash: ")),await u.close(),await d.close(),E;async function v(t){const e=2*d.pageSize;for(let a=0;a<t;a+=e){const i=Math.min(t-a,e),o=await d.read(i);await u.write(o)}}async function B(){const e=await d.read(2*t.G1.F.n8);return t.G1.fromRprUncompressed(e,0)}async function S(){const e=await d.read(2*t.G2.F.n8);return t.G2.fromRprUncompressed(e,0)}async function P(e){const a=new Uint8Array(s);t.G1.toRprUncompressed(a,0,e),await u.write(a)}async function G(e){const a=new Uint8Array(c);t.G2.toRprUncompressed(a,0,e),await u.write(a)}},exportVerificationKey:Gn,exportSolidityVerifier:async function(t,e,a){const i=await Gn(t,a);if("fflonk"===i.protocol)return zn(i,e,a);let o=e[i.protocol];return On.render(o,i)}});class qn{constructor(t,e){this.curve=t,this.logger=e,this.resetProof()}resetProof(){this.polynomials={},this.evaluations={}}addPolynomial(t,e){t in this.polynomials&&this.logger.warn(`proof: polynomial.${t} already exist in proof`),this.polynomials[t]=e}getPolynomial(t){return t in this.polynomials||this.logger.warn(`proof: polynomial ${t} does not exist in proof`),this.polynomials[t]}addEvaluation(t,e){t in this.evaluations&&this.logger.warn(`proof: evaluations.${t} already exist in proof`),this.evaluations[t]=e}getEvaluation(t){return t in this.evaluations||this.logger.warn(`proof: evaluation ${t} does not exist in proof`),this.evaluations[t]}toObjectProof(t=!0){let e=t?{polynomials:{},evaluations:{}}:{};return Object.keys(this.polynomials).forEach((a=>{const i=this.curve.G1.toObject(this.polynomials[a]);t?e.polynomials[a]=i:e[a]=i})),Object.keys(this.evaluations).forEach((a=>{const i=this.curve.Fr.toObject(this.evaluations[a]);t?e.evaluations[a]=i:e[a]=i})),e}fromObjectProof(t){this.resetProof(),Object.keys(t.polynomials).forEach((e=>{this.polynomials[e]=this.curve.G1.fromObject(t.polynomials[e])})),Object.keys(t.evaluations).forEach((e=>{this.evaluations[e]=this.curve.Fr.fromObject(t.evaluations[e])}))}}var Mn,kn={exports:{}};
/**
* [js-sha3]{@link https://github.com/emn178/js-sha3}
*
* @version 0.8.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2015-2018
* @license MIT
*/Mn=kn,function(){var t="input is invalid type",e="object"==typeof window,a=e?window:{};a.JS_SHA3_NO_WINDOW&&(e=!1);var i=!e&&"object"==typeof self;!a.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?a=Xa:i&&(a=self);var o=!a.JS_SHA3_NO_COMMON_JS&&Mn.exports,n=!a.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,l="0123456789abcdef".split(""),r=[4,1024,262144,67108864],s=[0,8,16,24],c=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],d=[224,256,384,512],u=[128,256],g=["hex","buffer","arrayBuffer","array","digest"],f={128:168,256:136};!a.JS_SHA3_NO_NODE_JS&&Array.isArray||(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),!n||!a.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView||(ArrayBuffer.isView=function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer});for(var h=function(t,e,a){return function(i){return new B(t,e,t).update(i)[a]()}},_=function(t,e,a){return function(i,o){return new B(t,e,o).update(i)[a]()}},p=function(t,e,a){return function(e,i,o,n){return y["cshake"+t].update(e,i,o,n)[a]()}},m=function(t,e,a){return function(e,i,o,n){return y["kmac"+t].update(e,i,o,n)[a]()}},w=function(t,e,a,i){for(var o=0;o<g.length;++o){var n=g[o];t[n]=e(a,i,n)}return t},L=function(t,e){var a=h(t,e,"hex");return a.create=function(){return new B(t,e,t)},a.update=function(t){return a.create().update(t)},w(a,h,t,e)},b=[{name:"keccak",padding:[1,256,65536,16777216],bits:d,createMethod:L},{name:"sha3",padding:[6,1536,393216,100663296],bits:d,createMethod:L},{name:"shake",padding:[31,7936,2031616,520093696],bits:u,createMethod:function(t,e){var a=_(t,e,"hex");return a.create=function(a){return new B(t,e,a)},a.update=function(t,e){return a.create(e).update(t)},w(a,_,t,e)}},{name:"cshake",padding:r,bits:u,createMethod:function(t,e){var a=f[t],i=p(t,0,"hex");return i.create=function(i,o,n){return o||n?new B(t,e,i).bytepad([o,n],a):y["shake"+t].create(i)},i.update=function(t,e,a,o){return i.create(e,a,o).update(t)},w(i,p,t,e)}},{name:"kmac",padding:r,bits:u,createMethod:function(t,e){var a=f[t],i=m(t,0,"hex");return i.create=function(i,o,n){return new S(t,e,o).bytepad(["KMAC",n],a).bytepad([i],a)},i.update=function(t,e,a,o){return i.create(t,a,o).update(e)},w(i,m,t,e)}}],y={},A=[],C=0;C<b.length;++C)for(var I=b[C],F=I.bits,x=0;x<F.length;++x){var E=I.name+"_"+F[x];if(A.push(E),y[E]=I.createMethod(F[x],I.padding),"sha3"!==I.name){var v=I.name+F[x];A.push(v),y[v]=y[E]}}function B(t,e,a){this.blocks=[],this.s=[],this.padding=e,this.outputBits=a,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(t<<1)>>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 S(t,e,a){B.call(this,t,e,a)}B.prototype.update=function(e){if(this.finalized)throw new Error("finalize already called");var a,i=typeof e;if("string"!==i){if("object"!==i)throw new Error(t);if(null===e)throw new Error(t);if(n&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||n&&ArrayBuffer.isView(e)))throw new Error(t);a=!0}for(var o,l,r=this.blocks,c=this.byteCount,d=e.length,u=this.blockCount,g=0,f=this.s;g<d;){if(this.reset)for(this.reset=!1,r[0]=this.block,o=1;o<u+1;++o)r[o]=0;if(a)for(o=this.start;g<d&&o<c;++g)r[o>>2]|=e[g]<<s[3&o++];else for(o=this.start;g<d&&o<c;++g)(l=e.charCodeAt(g))<128?r[o>>2]|=l<<s[3&o++]:l<2048?(r[o>>2]|=(192|l>>6)<<s[3&o++],r[o>>2]|=(128|63&l)<<s[3&o++]):l<55296||l>=57344?(r[o>>2]|=(224|l>>12)<<s[3&o++],r[o>>2]|=(128|l>>6&63)<<s[3&o++],r[o>>2]|=(128|63&l)<<s[3&o++]):(l=65536+((1023&l)<<10|1023&e.charCodeAt(++g)),r[o>>2]|=(240|l>>18)<<s[3&o++],r[o>>2]|=(128|l>>12&63)<<s[3&o++],r[o>>2]|=(128|l>>6&63)<<s[3&o++],r[o>>2]|=(128|63&l)<<s[3&o++]);if(this.lastByteIndex=o,o>=c){for(this.start=o-c,this.block=r[u],o=0;o<u;++o)f[o]^=r[o];P(f),this.reset=!0}else this.start=o}return this},B.prototype.encode=function(t,e){var a=255&t,i=1,o=[a];for(a=255&(t>>=8);a>0;)o.unshift(a),a=255&(t>>=8),++i;return e?o.push(i):o.unshift(i),this.update(o),o.length},B.prototype.encodeString=function(e){var a,i=typeof e;if("string"!==i){if("object"!==i)throw new Error(t);if(null===e)throw new Error(t);if(n&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||n&&ArrayBuffer.isView(e)))throw new Error(t);a=!0}var o=0,l=e.length;if(a)o=l;else for(var r=0;r<e.length;++r){var s=e.charCodeAt(r);s<128?o+=1:s<2048?o+=2:s<55296||s>=57344?o+=3:(s=65536+((1023&s)<<10|1023&e.charCodeAt(++r)),o+=4)}return o+=this.encode(8*o),this.update(e),o},B.prototype.bytepad=function(t,e){for(var a=this.encode(e),i=0;i<t.length;++i)a+=this.encodeString(t[i]);var o=e-a%e,n=[];return n.length=o,this.update(n),this},B.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex,a=this.blockCount,i=this.s;if(t[e>>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[a],e=1;e<a+1;++e)t[e]=0;for(t[a-1]|=2147483648,e=0;e<a;++e)i[e]^=t[e];P(i)}},B.prototype.toString=B.prototype.hex=function(){this.finalize();for(var t,e=this.blockCount,a=this.s,i=this.outputBlocks,o=this.extraBytes,n=0,r=0,s="";r<i;){for(n=0;n<e&&r<i;++n,++r)t=a[n],s+=l[t>>4&15]+l[15&t]+l[t>>12&15]+l[t>>8&15]+l[t>>20&15]+l[t>>16&15]+l[t>>28&15]+l[t>>24&15];r%e==0&&(P(a),n=0)}return o&&(t=a[n],s+=l[t>>4&15]+l[15&t],o>1&&(s+=l[t>>12&15]+l[t>>8&15]),o>2&&(s+=l[t>>20&15]+l[t>>16&15])),s},B.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,a=this.s,i=this.outputBlocks,o=this.extraBytes,n=0,l=0,r=this.outputBits>>3;t=o?new ArrayBuffer(i+1<<2):new ArrayBuffer(r);for(var s=new Uint32Array(t);l<i;){for(n=0;n<e&&l<i;++n,++l)s[l]=a[n];l%e==0&&P(a)}return o&&(s[n]=a[n],t=t.slice(0,r)),t},B.prototype.buffer=B.prototype.arrayBuffer,B.prototype.digest=B.prototype.array=function(){this.finalize();for(var t,e,a=this.blockCount,i=this.s,o=this.outputBlocks,n=this.extraBytes,l=0,r=0,s=[];r<o;){for(l=0;l<a&&r<o;++l,++r)t=r<<2,e=i[l],s[t]=255&e,s[t+1]=e>>8&255,s[t+2]=e>>16&255,s[t+3]=e>>24&255;r%a==0&&P(i)}return n&&(t=r<<2,e=i[l],s[t]=255&e,n>1&&(s[t+1]=e>>8&255),n>2&&(s[t+2]=e>>16&255)),s},S.prototype=new B,S.prototype.finalize=function(){return this.encode(this.outputBits,!0),B.prototype.finalize.call(this)};var P=function(t){var e,a,i,o,n,l,r,s,d,u,g,f,h,_,p,m,w,L,b,y,A,C,I,F,x,E,v,B,S,P,G,O,T,U,z,Q,q,M,k,R,D,N,$,V,K,j,H,Z,W,Y,J,X,tt,et,at,it,ot,nt,lt,rt,st,ct,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],l=t[2]^t[12]^t[22]^t[32]^t[42],r=t[3]^t[13]^t[23]^t[33]^t[43],s=t[4]^t[14]^t[24]^t[34]^t[44],d=t[5]^t[15]^t[25]^t[35]^t[45],u=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])^(l<<1|r>>>31),a=(h=t[9]^t[19]^t[29]^t[39]^t[49])^(r<<1|l>>>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^(s<<1|d>>>31),a=n^(d<<1|s>>>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=l^(u<<1|g>>>31),a=r^(g<<1|u>>>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=s^(f<<1|h>>>31),a=d^(h<<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=u^(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,_=t[0],p=t[1],j=t[11]<<4|t[10]>>>28,H=t[10]<<4|t[11]>>>28,B=t[20]<<3|t[21]>>>29,S=t[21]<<3|t[20]>>>29,rt=t[31]<<9|t[30]>>>23,st=t[30]<<9|t[31]>>>23,N=t[40]<<18|t[41]>>>14,$=t[41]<<18|t[40]>>>14,U=t[2]<<1|t[3]>>>31,z=t[3]<<1|t[2]>>>31,m=t[13]<<12|t[12]>>>20,w=t[12]<<12|t[13]>>>20,Z=t[22]<<10|t[23]>>>22,W=t[23]<<10|t[22]>>>22,P=t[33]<<13|t[32]>>>19,G=t[32]<<13|t[33]>>>19,ct=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,q=t[15]<<6|t[14]>>>26,L=t[25]<<11|t[24]>>>21,b=t[24]<<11|t[25]>>>21,Y=t[34]<<15|t[35]>>>17,J=t[35]<<15|t[34]>>>17,O=t[45]<<29|t[44]>>>3,T=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,M=t[26]<<25|t[27]>>>7,k=t[27]<<25|t[26]>>>7,y=t[36]<<21|t[37]>>>11,A=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,K=t[9]<<27|t[8]>>>5,E=t[18]<<20|t[19]>>>12,v=t[19]<<20|t[18]>>>12,nt=t[29]<<7|t[28]>>>25,lt=t[28]<<7|t[29]>>>25,R=t[38]<<8|t[39]>>>24,D=t[39]<<8|t[38]>>>24,C=t[48]<<14|t[49]>>>18,I=t[49]<<14|t[48]>>>18,t[0]=_^~m&L,t[1]=p^~w&b,t[10]=F^~E&B,t[11]=x^~v&S,t[20]=U^~Q&M,t[21]=z^~q&k,t[30]=V^~j&Z,t[31]=K^~H&W,t[40]=et^~it&nt,t[41]=at^~ot&lt,t[2]=m^~L&y,t[3]=w^~b&A,t[12]=E^~B&P,t[13]=v^~S&G,t[22]=Q^~M&R,t[23]=q^~k&D,t[32]=j^~Z&Y,t[33]=H^~W&J,t[42]=it^~nt&rt,t[43]=ot^~lt&st,t[4]=L^~y&C,t[5]=b^~A&I,t[14]=B^~P&O,t[15]=S^~G&T,t[24]=M^~R&N,t[25]=k^~D&$,t[34]=Z^~Y&X,t[35]=W^~J&tt,t[44]=nt^~rt&ct,t[45]=lt^~st&dt,t[6]=y^~C&_,t[7]=A^~I&p,t[16]=P^~O&F,t[17]=G^~T&x,t[26]=R^~N&U,t[27]=D^~$&z,t[36]=Y^~X&V,t[37]=J^~tt&K,t[46]=rt^~ct&et,t[47]=st^~dt&at,t[8]=C^~_&m,t[9]=I^~p&w,t[18]=O^~F&E,t[19]=T^~x&v,t[28]=N^~U&Q,t[29]=$^~z&q,t[38]=X^~V&j,t[39]=tt^~K&H,t[48]=ct^~et&it,t[49]=dt^~at&ot,t[0]^=c[i],t[1]^=c[i+1]};if(o)Mn.exports=y;else for(C=0;C<A.length;++C)a[A[C]]=y[A[C]]}();var Rn=kn.exports;const{keccak256:Dn}=Rn;class Nn{constructor(t){this.G1=t.G1,this.Fr=t.Fr,this.reset()}reset(){this.data=[]}addPolCommitment(t){this.data.push({type:0,data:t})}addScalar(t){this.data.push({type:1,data:t})}getChallenge(){if(0===this.data.length)throw new Error("Keccak256Transcript: No data to generate a transcript");let t=0,e=0;this.data.forEach((a=>0===a.type?t++:e++));let a=new Uint8Array(e*this.Fr.n8+t*this.G1.F.n8*2),i=0;for(let t=0;t<this.data.length;t++)0===this.data[t].type?(this.G1.toRprUncompressed(a,i,this.data[t].data),i+=2*this.G1.F.n8):(this.Fr.toRprBE(a,i,this.data[t].data),i+=this.Fr.n8);const o=ga.fromRprBE(new Uint8Array(Dn.arrayBuffer(a)));return this.Fr.e(o)}}class $n{static getZ1(t){return[t.zero,t.add(t.e(-1),t.w[2]),t.e(-2),t.sub(t.e(-1),t.w[2])]}static getZ2(t){return[t.zero,t.add(t.zero,t.mul(t.e(-2),t.w[2])),t.e(4),t.sub(t.zero,t.mul(t.e(-2),t.w[2]))]}static getZ3(t){return[t.zero,t.add(t.e(2),t.mul(t.e(2),t.w[2])),t.e(-8),t.sub(t.e(2),t.mul(t.e(2),t.w[2]))]}static mul2(t,e,a,i,o,n){const l=this.getZ1(n);let r,s;const c=n.mul(t,e),d=n.mul(t,i),u=n.mul(a,e);r=c;let g=n.mul(a,i);return s=n.add(d,u),o&&(s=n.add(s,n.mul(l[o],g))),[r,s]}static mul3(t,e,a,i,o,n,l,r){const s=this.getZ1(r),c=this.getZ2(r);let d,u;const g=r.mul(t,e),f=r.mul(t,o),h=r.mul(i,e),_=r.mul(i,o);d=r.mul(g,a);let p=r.mul(h,a);p=r.add(p,r.mul(f,a)),p=r.add(p,r.mul(g,n));let m=r.mul(_,a);if(m=r.add(m,r.mul(f,n)),m=r.add(m,r.mul(h,n)),u=p,l){const t=r.mul(_,n);u=r.add(u,r.mul(s[l],m)),u=r.add(u,r.mul(c[l],t))}return[d,u]}static mul4(t,e,a,i,o,n,l,r,s,c){const d=this.getZ1(c),u=this.getZ2(c),g=this.getZ3(c);let f,h;const _=c.mul(t,e),p=c.mul(t,n),m=c.mul(o,e),w=c.mul(o,n),L=c.mul(a,i),b=c.mul(a,r),y=c.mul(l,i),A=c.mul(l,r);f=c.mul(_,L);let C=c.mul(m,L);C=c.add(C,c.mul(p,L)),C=c.add(C,c.mul(_,y)),C=c.add(C,c.mul(_,b));let I=c.mul(w,L);I=c.add(I,c.mul(m,y)),I=c.add(I,c.mul(m,b)),I=c.add(I,c.mul(p,y)),I=c.add(I,c.mul(p,b)),I=c.add(I,c.mul(_,A));let F=c.mul(p,A);F=c.add(F,c.mul(m,A)),F=c.add(F,c.mul(w,b)),F=c.add(F,c.mul(w,y));let x=c.mul(w,A);return h=C,s&&(h=c.add(h,c.mul(d[s],I)),h=c.add(h,c.mul(u[s],F)),h=c.add(h,c.mul(g[s],x))),[f,h]}}const Vn=3,Kn=4,jn=5,Hn=6,Zn=7,Wn=8,Yn=9,Jn=10,Xn=11,tl=12,el=13,al=14;class il{constructor(t,e,a){this.coef=t,this.curve=e,this.Fr=e.Fr,this.G1=e.G1,this.logger=a}static async fromEvaluations(t,e,a){let i=await e.Fr.ifft(t);return new il(i,e,a)}static fromCoefficientsArray(t,e,a){const i=e.Fr;let o=t.length>32768?new Se(t.length*i.n8):new Uint8Array(t.length*i.n8);for(let e=0;e<t.length;e++)o.set(t[e],e*i.n8);return new il(o,e,a)}static fromPolynomial(t,e,a){let i=t.length(),o=e.Fr,n=i>32768?new Se(i*o.n8):new Uint8Array(i*o.n8);return n.set(t.coef.slice(),0),new il(n,e,a)}isEqual(t){const e=this.degree();if(e!==t.degree())return!1;for(let a=0;a<e+1;a++)if(!this.Fr.eq(this.getCoef(a),t.getCoef(a)))return!1;return!0}blindCoefficients(t){t=t||[];const e=this.length()+t.length>32768?new Se((this.length()+t.length)*this.Fr.n8):new Uint8Array((this.length()+t.length)*this.Fr.n8);e.set(this.coef,0);for(let a=0;a<t.length;a++)e.set(this.Fr.add(e.slice((this.length()+a)*this.Fr.n8,(this.length()+a+1)*this.Fr.n8),t[a]),(this.length()+a)*this.Fr.n8),e.set(this.Fr.sub(e.slice(a*this.Fr.n8,(a+1)*this.Fr.n8),t[a]),a*this.Fr.n8);this.coef=e}getCoef(t){const e=t*this.Fr.n8;return e+this.Fr.n8>this.coef.byteLength?this.Fr.zero:this.coef.slice(e,e+this.Fr.n8)}setCoef(t,e){if(t>this.length()-1)throw new Error("Coef index is not available");this.coef.set(e,t*this.Fr.n8)}static async to4T(t,e,a,i){a=a||[];let o=await i.ifft(t);const n=4*e>32768?new Se(4*e*i.n8):new Uint8Array(4*e*i.n8);n.set(o,0);const l=await i.fft(n);if(0===a.length)return[o,l];const r=e+a.length>32768?new Se((e+a.length)*i.n8):new Uint8Array((e+a.length)*i.n8);r.set(o,0);for(let t=0;t<a.length;t++)r.set(i.add(r.slice((e+t)*i.n8,(e+t+1)*i.n8),a[t]),(e+t)*i.n8),r.set(i.sub(r.slice(t*i.n8,(t+1)*i.n8),a[t]),t*i.n8);return[r,l]}length(){let t=this.coef.byteLength/this.Fr.n8;if(t!==Math.floor(this.coef.byteLength/this.Fr.n8))throw new Error("Polynomial coefficients buffer has incorrect size");return 0===t&&this.logger&&this.logger.warn("Polynomial has length zero"),t}degree(){for(let t=this.length()-1;t>0;t--){const e=t*this.Fr.n8;if(!this.Fr.eq(this.Fr.zero,this.coef.slice(e,e+this.Fr.n8)))return t}return 0}evaluate(t){let e=this.Fr.zero;for(let a=this.degree()+1;a>0;a--){let i=a*this.Fr.n8;const o=this.coef.slice(i-this.Fr.n8,i);e=this.Fr.add(o,this.Fr.mul(e,t))}return e}fastEvaluate(t){const e=this.Fr;let a=this.degree()+1,i=parseInt(a/3),o=a-3*i,n=[],l=[];l[0]=e.one;for(let a=0;a<3;a++){n[a]=e.zero;for(let r=2===a?i+o:i;r>0;r--)n[a]=e.add(this.getCoef(a*i+r-1),e.mul(n[a],t)),0===a&&(l[0]=e.mul(l[0],t))}for(let t=1;t<3;t++)n[0]=e.add(n[0],e.mul(l[t-1],n[t])),l[t]=e.mul(l[t-1],l[0]);return n[0]}add(t,e){let a=!1;t.length()>this.length()&&(a=!0);const i=this.length(),o=t.length();for(let n=0;n<Math.max(i,o);n++){const l=n*this.Fr.n8,r=n<i?this.coef.slice(l,l+this.Fr.n8):this.Fr.zero;let s=n<o?t.coef.slice(l,l+this.Fr.n8):this.Fr.zero;void 0!==e&&(s=this.Fr.mul(s,e)),a?t.coef.set(this.Fr.add(r,s),l):this.coef.set(this.Fr.add(r,s),l)}a&&(delete this.coef,this.coef=t.coef)}sub(t,e){let a=!1;t.length()>this.length()&&(a=!0);const i=this.length(),o=t.length();for(let n=0;n<Math.max(i,o);n++){const l=n*this.Fr.n8,r=n<i?this.coef.slice(l,l+this.Fr.n8):this.Fr.zero;let s=n<o?t.coef.slice(l,l+this.Fr.n8):this.Fr.zero;void 0!==e&&(s=this.Fr.mul(s,e)),a?t.coef.set(this.Fr.sub(r,s),l):this.coef.set(this.Fr.sub(r,s),l)}a&&(delete this.coef,this.coef=t.coef)}mulScalar(t){for(let e=0;e<this.length();e++){const a=e*this.Fr.n8;this.coef.set(this.Fr.mul(this.coef.slice(a,a+this.Fr.n8),t),a)}}addScalar(t){const e=0===this.length()?this.Fr.zero:this.coef.slice(0,this.Fr.n8);this.coef.set(this.Fr.add(e,t),0)}subScalar(t){const e=0===this.length()?this.Fr.zero:this.coef.slice(0,this.Fr.n8);this.coef.set(this.Fr.sub(e,t),0)}byXSubValue(t){const e=this.Fr,a=!e.eq(e.zero,this.getCoef(this.length()-1))?this.length()+1:this.length(),i=a>32768?new Se(a*e.n8):new Uint8Array(a*e.n8);let o=new il(i,this.curve,this.logger);o.coef.set(this.coef.slice(0,(a-1)*e.n8),32),this.mulScalar(e.neg(t)),o.add(this),this.coef=o.coef}byXNSubValue(t,e){const a=this.Fr,i=!(this.length()-t-1>=this.degree())?this.length()+t:this.length(),o=i>32768?new Se(i*a.n8):new Uint8Array(i*a.n8);let n=new il(o,this.curve,this.logger);n.coef.set(this.coef.slice(0,32*(this.degree()+1)),32*t),this.mulScalar(e),n.add(this),this.coef=n.coef}divBy(t){const e=this.Fr,a=this.degree(),i=t.degree();let o=new il(this.coef,this.curve,this.logger);this.coef=this.length()>32768?new Se(this.length()*e.n8):new Uint8Array(this.length()*e.n8);for(let n=a-i;n>=0;n--){this.setCoef(n,e.div(o.getCoef(n+i),t.getCoef(i)));for(let a=0;a<=i;a++)o.setCoef(n+a,e.sub(o.getCoef(n+a),e.mul(this.getCoef(n),t.getCoef(a))))}return o}divByMonic(t,e){const a=this.Fr;let i=this.degree(),o=this.length()>32768?new Se(this.length()*a.n8):new Uint8Array(this.length()*a.n8),n=new il(o,this.curve,this.logger),l=[];for(let e=0;e<t;e++)n.setCoef(i-e-t,this.getCoef(i-e)),l[e]=this.getCoef(i-e);let r=t;for(let o=0;o<r;o++)for(let s=i-2*t-o;s>=0&&!(s<0);s-=r){let i=o;l[i]=a.add(this.getCoef(s+t),a.mul(l[i],e)),n.setCoef(s,l[i])}this.coef=n.coef}divByVanishing(t,e){if(this.degree()<t)throw new Error("divByVanishing polynomial divisor must be of degree lower than the dividend polynomial");const a=this.Fr;let i=new il(this.coef,this.curve,this.logger);this.coef=this.length()>32768?new Se(this.length()*a.n8):new Uint8Array(this.length()*a.n8);for(let o=this.length()-1;o>=t;o--){let n=i.getCoef(o);a.eq(a.zero,n)||(i.setCoef(o,a.zero),i.setCoef(o-t,a.add(i.getCoef(o-t),a.mul(e,n))),this.setCoef(o-t,a.add(this.getCoef(o-t),n)))}return i}divByVanishing2(t,e){if(this.degree()<t)throw new Error("divByVanishing polynomial divisor must be of degree lower than the dividend polynomial");const a=this.Fr;let i=new il(this.coef,this.curve,this.logger);this.coef=this.length()>32768?new Se(this.length()*a.n8):new Uint8Array(this.length()*a.n8);let o=this.length()-t,n=Math.floor(o/3),l=o-2*n;console.log(o),console.log(n+" "+l);for(let o=0;o<3;o++){console.log("> Thread "+o);for(let r=0===o?l:n;r>0;r--){let s=r-1;0!==o&&(s+=(o-1)*n+l);let c=s+t,d=i.getCoef(c);a.eq(a.zero,d)||(i.setCoef(c,a.zero),i.setCoef(s,a.add(i.getCoef(s),a.mul(e,d))),this.setCoef(s,a.add(this.getCoef(s),d)),console.log(s+" <-- "+c))}}return this.print(),i}fastDivByVanishing(t){const e=this.Fr;for(let a=0;a<t.length;a++){let i=t[a][0],o=t[a][1];if(this.degree()<i)throw new Error("divByVanishing polynomial divisor must be of degree lower than the dividend polynomial");let n=5,l=this.length()-i,r=Math.floor(l/n/i),s=r*i,c=l-n*s,d=new il(this.length()>32768?new Se(this.length()*e.n8):new Uint8Array(this.length()*e.n8),this.curve,this.logger),u=this.coef;this.coef=d.coef,d.coef=u;for(let t=0;t<n;t++){let a=(t+1)*s+c;for(let t=0;t<i;t++)this.setCoef(a+t-i,d.getCoef(a+t));for(let t=0;t<s-i;t++){let n=a-t-1,l=e.add(d.getCoef(n),e.mul(o,this.getCoef(n)));this.setCoef(n-i,l)}}let g=c,f=c;for(let t=0;t<i&&f;t++)this.setCoef(g-t-1,d.getCoef(g+i-t-1)),f--;for(let t=0;t<f;t++){let a=g-t-1,n=e.add(d.getCoef(a),e.mul(o,this.getCoef(a)));this.setCoef(a-i,n)}let h=[],_=e.one;for(let t=0;t<r;t++)_=e.mul(_,o);let p=e.one;for(let t=n;t>0;t--){let a=t-1,o=a*s+c;h[a]=[];for(let l=0;l<i;l++)h[a][l]=this.getCoef(o+l),t!==n&&(h[a][l]=e.add(h[a][l],e.mul(_,h[a+1][l])));p=e.mul(p,_)}for(let t=0;t<n;t++){let a=t*s+c,n=o,l=i-1,r=0===t?c:s;for(let s=0;s<r;s++){let r=a-s-1,c=e.add(this.getCoef(r),e.mul(n,h[t][l]));this.setCoef(r,c),0===l?(l=i-1,n=e.mul(n,o)):l--}}}}divByXSubValue(t){const e=this.length()>32768?new Se(this.length()*this.Fr.n8):new Uint8Array(this.length()*this.Fr.n8);e.set(this.Fr.zero,(this.length()-1)*this.Fr.n8),e.set(this.coef.slice((this.length()-1)*this.Fr.n8,this.length()*this.Fr.n8),(this.length()-2)*this.Fr.n8);for(let a=this.length()-3;a>=0;a--){let i=a*this.Fr.n8;e.set(this.Fr.add(this.coef.slice(i+this.Fr.n8,i+2*this.Fr.n8),this.Fr.mul(t,e.slice(i+this.Fr.n8,i+2*this.Fr.n8))),a*this.Fr.n8)}if(!this.Fr.eq(this.coef.slice(0,this.Fr.n8),this.Fr.mul(this.Fr.neg(t),e.slice(0,this.Fr.n8))))throw new Error("Polynomial does not divide");this.coef=e}divZh(t,e=4){for(let e=0;e<t;e++){const t=e*this.Fr.n8;this.coef.set(this.Fr.neg(this.coef.slice(t,t+this.Fr.n8)),t)}const a=this.coef.byteLength/this.Fr.n8;for(let i=t;i<a;i++){const a=i*this.Fr.n8,o=this.Fr.sub(this.coef.slice((i-t)*this.Fr.n8,(i-t)*this.Fr.n8+this.Fr.n8),this.coef.slice(a,a+this.Fr.n8));if(this.coef.set(o,a),i>t*(e-1)-e&&!this.Fr.isZero(o))throw new Error("Polynomial is not divisible")}return this}divByZerofier(t,e){let a=this.Fr;const i=a.inv(e),o=a.neg(i);let n=a.eq(a.one,o),l=a.eq(a.negone,o);if(!n)for(let e=0;e<t;e++){const t=e*this.Fr.n8;let i;i=l?a.neg(this.coef.slice(t,t+this.Fr.n8)):a.mul(o,this.coef.slice(t,t+this.Fr.n8)),this.coef.set(i,t)}n=a.eq(a.one,i),l=a.eq(a.negone,i);for(let e=t;e<this.length();e++){const o=e*this.Fr.n8,r=(e-t)*this.Fr.n8;let s=this.Fr.sub(this.coef.slice(r,r+this.Fr.n8),this.coef.slice(o,o+this.Fr.n8));if(n||(s=l?a.neg(s):a.mul(i,s)),this.coef.set(s,o),e>this.length()-t-1&&!this.Fr.isZero(s))throw new Error("Polynomial is not divisible")}return this}byX(){const t=this.length()+1>32768?new Se(this.coef.byteLength+this.Fr.n8):new Uint8Array(this.coef.byteLength+this.Fr.n8);t.set(this.Fr.zero,0),t.set(this.coef,this.Fr.n8),this.coef=t}static async expX(t,e,a=!1){const i=t.Fr;if(e<1)throw new Error("Compute a new polynomial to a zero or negative number is not allowed");if(1===e)return await il.fromEvaluations(t.coef,curve,t.logger);const o=a?t.degree():t.length()-1,n=o*e+1>32768?new Se((o*e+1)*i.n8):new Uint8Array((o*e+1)*i.n8);n.set(t.getCoef(0),0);for(let a=1;a<=o;a++){const o=a*i.n8,l=t.getCoef(a);n.set(l,o*e)}return new il(n,t.curve,t.logger)}split(t,e,a){if(t<1)throw new Error(`Polynomials can't be split in ${t} parts`);if(1===t)return[this];if(0!==a.length&&a.length<t-1)throw new Error("Blinding factors length must be "+(t-1));const i=(e+1)*this.Fr.n8;let o=[];const n=Math.ceil((this.degree()+1)*this.Fr.n8/i);if(n<t)for(let e=n;e<t;e++)o[e]=new il(new Uint8Array(this.Fr.n8),this.curve,this.logger);t=Math.min(t,n);for(let e=0;e<t;e++){const n=t-1===e,l=n?this.coef.byteLength-(t-1)*i:i+this.Fr.n8;let r=l/this.Fr.n8>32768?new Se(l):new Uint8Array(l);o[e]=new il(r,this.curve,this.logger);const s=e*i,c=n?this.coef.byteLength:(e+1)*i;if(o[e].coef.set(this.coef.slice(s,c),0),n||o[e].coef.set(a[e],i),0!==e){const t=this.Fr.sub(o[e].coef.slice(0,this.Fr.n8),a[e-1]);o[e].coef.set(t,0)}n&&o[e].truncate()}return o}truncate(){const t=this.degree();if(t+1<this.coef.byteLength/this.Fr.n8){const e=t+1>32768?new Se((t+1)*this.Fr.n8):new Uint8Array((t+1)*this.Fr.n8);e.set(this.coef.slice(0,(t+1)*this.Fr.n8),0),this.coef=e}}static lagrangePolynomialInterpolation(t,e,a){const i=a.Fr;let o=n(0);for(let e=1;e<t.length;e++)o.add(n(e));return o;function n(o){let n;for(let e=0;e<t.length;e++)if(e!==o)if(void 0===n){let o=t.length>32768?new Se(t.length*i.n8):new Uint8Array(t.length*i.n8);n=new il(o,a),n.setCoef(0,i.neg(t[e])),n.setCoef(1,i.one)}else n.byXSubValue(t[e]);let l=n.evaluate(t[o]);l=i.inv(l);const r=i.mul(e[o],l);return n.mulScalar(r),n}}static zerofierPolynomial(t,e){const a=e.Fr;let i=t.length+1>32768?new Se((t.length+1)*a.n8):new Uint8Array((t.length+1)*a.n8),o=new il(i,e);o.setCoef(0,a.neg(t[0])),o.setCoef(1,a.one);for(let e=1;e<t.length;e++)o.byXSubValue(t[e]);return o}print(){const t=this.Fr;let e="";for(let a=this.degree();a>=0;a--){const i=this.getCoef(a);t.eq(t.zero,i)||(t.isNegative(i)?e+=" - ":a!==this.degree()&&(e+=" + "),e+=t.toString(i),a>0&&(e+=a>1?"x^"+a:"x"))}console.log(e)}async multiExponentiation(t,e){const a=this.coef.byteLength/this.Fr.n8,i=t.slice(0,a*this.G1.F.n8*2),o=await this.Fr.batchFromMontgomery(this.coef);let n=await this.G1.multiExpAffine(i,o,this.logger,e);return n=this.G1.toAffine(n),n}}class ol{constructor(t,e,a){this.eval=t,this.curve=e,this.Fr=e.Fr,this.logger=a}static async fromPolynomial(t,e,a,i){const o=new Se(t.length()*e*a.Fr.n8);o.set(t.coef,0);const n=await a.Fr.fft(o);return new ol(n,a,i)}getEvaluation(t){const e=t*this.Fr.n8;if(e+this.Fr.n8>this.eval.byteLength)throw new Error("Evaluations.getEvaluation() out of bounds");return this.eval.slice(e,e+this.Fr.n8)}length(){let t=this.eval.byteLength/this.Fr.n8;if(t!==Math.floor(this.eval.byteLength/this.Fr.n8))throw new Error("Polynomial evaluations buffer has incorrect size");return 0===t&&this.logger.warn("Polynomial has length zero"),t}}const{stringifyBigInts:nl}=fa;async function ll(t,e,a){const{fd:i,sections:o}=await za(e,"wtns",2);a&&a.debug("> Reading witness file");const n=await xo(i,o);a&&a.debug("> Reading zkey file");const{fd:l,sections:r}=await za(t,"zkey",2),s=await Lo(l,r);if("plonk"!=s.protocol)throw new Error("zkey file is not plonk");if(!ga.eq(s.r,n.q))throw new Error("Curve of the witness does not match the curve of the proving key");if(n.nWitness!=s.nVars-s.nAdditions)throw new Error(`Invalid witness length. Circuit: ${s.nVars}, witness: ${n.nWitness}, ${s.nAdditions}`);const c=s.curve,d=c.Fr,u=c.Fr.n8,g=s.domainSize*u;a&&(a.debug("----------------------------"),a.debug(" PLONK PROVE SETTINGS"),a.debug(` Curve: ${c.name}`),a.debug(` Circuit power: ${s.power}`),a.debug(` Domain size: ${s.domainSize}`),a.debug(` Vars: ${s.nVars}`),a.debug(` Public vars: ${s.nPublic}`),a.debug(` Constraints: ${s.nConstraints}`),a.debug(` Additions: ${s.nAdditions}`),a.debug("----------------------------")),a&&a.debug("> Reading witness file data");const f=await Va(i,o,2);f.set(d.zero,0);const h=new Se(u*s.nAdditions);let _={},p={},m={},w={},L=new qn(c,a);const b=new Nn(c);a&&a.debug(`> Reading Section ${Vn}. Additions`),await async function(){a&&a.debug("··· Computing additions");const t=await Va(l,r,Vn),e=8+2*u;for(let i=0;i<s.nAdditions;i++){a&&0!==i&&i%1e5==0&&a.debug(` addition ${i}/${s.nAdditions}`);let o=i*e;const n=I(t,o);o+=4;const l=I(t,o);o+=4;const r=t.slice(o,o+u);o+=u;const c=t.slice(o,o+u),g=F(n),f=F(l),_=d.add(d.mul(r,g),d.mul(c,f));h.set(_,u*i)}}(),a&&a.debug(`> Reading Section ${tl}. Sigma1, Sigma2 & Sigma 3`),a&&a.debug("··· Reading Sigma polynomials "),p.Sigma1=new il(new Se(g),c,a),p.Sigma2=new il(new Se(g),c,a),p.Sigma3=new il(new Se(g),c,a),await l.readToBuffer(p.Sigma1.coef,0,g,r[tl][0].p),await l.readToBuffer(p.Sigma2.coef,0,g,r[tl][0].p+5*g),await l.readToBuffer(p.Sigma3.coef,0,g,r[tl][0].p+10*g),a&&a.debug("··· Reading Sigma evaluations"),m.Sigma1=new ol(new Se(4*g),c,a),m.Sigma2=new ol(new Se(4*g),c,a),m.Sigma3=new ol(new Se(4*g),c,a),await l.readToBuffer(m.Sigma1.eval,0,4*g,r[tl][0].p+g),await l.readToBuffer(m.Sigma2.eval,0,4*g,r[tl][0].p+6*g),await l.readToBuffer(m.Sigma3.eval,0,4*g,r[tl][0].p+11*g),a&&a.debug(`> Reading Section ${al}. Powers of Tau`);const y=await Va(l,r,al);let A=[];for(let t=1;t<=s.nPublic;t++){const e=f.slice(t*d.n8,t*d.n8+d.n8);A.push(ga.fromRprLE(e))}a&&a.debug(""),a&&a.debug("> ROUND 1"),await async function(){w.b=[];for(let t=1;t<=11;t++)w.b[t]=c.Fr.random();a&&a.debug("> Computing A, B, C wire polynomials");await async function(){a&&a.debug("··· Reading data from zkey file");_.A=new Se(g),_.B=new Se(g),_.C=new Se(g);const t=await Va(l,r,Kn),e=await Va(l,r,jn),i=await Va(l,r,Hn);for(let a=0;a<s.nConstraints;a++){const o=a*u,n=4*a,l=I(t,n);_.A.set(F(l),o);const r=I(e,n);_.B.set(F(r),o);const s=I(i,n);_.C.set(F(s),o)}_.A=await d.batchToMontgomery(_.A),_.B=await d.batchToMontgomery(_.B),_.C=await d.batchToMontgomery(_.C),a&&a.debug("··· Computing A ifft");p.A=await il.fromEvaluations(_.A,c,a),a&&a.debug("··· Computing B ifft");p.B=await il.fromEvaluations(_.B,c,a),a&&a.debug("··· Computing C ifft");p.C=await il.fromEvaluations(_.C,c,a),a&&a.debug("··· Computing A fft");m.A=await ol.fromPolynomial(p.A,4,c,a),a&&a.debug("··· Computing B fft");m.B=await ol.fromPolynomial(p.B,4,c,a),a&&a.debug("··· Computing C fft");if(m.C=await ol.fromPolynomial(p.C,4,c,a),p.A.blindCoefficients([w.b[2],w.b[1]]),p.B.blindCoefficients([w.b[4],w.b[3]]),p.C.blindCoefficients([w.b[6],w.b[5]]),p.A.degree()>=s.domainSize+2)throw new Error("A Polynomial is not well calculated");if(p.B.degree()>=s.domainSize+2)throw new Error("B Polynomial is not well calculated");if(p.C.degree()>=s.domainSize+2)throw new Error("C Polynomial is not well calculated")}(),a&&a.debug("> Computing A, B, C MSM");let t=await p.A.multiExponentiation(y,"A"),e=await p.B.multiExponentiation(y,"B"),i=await p.C.multiExponentiation(y,"C");return L.addPolynomial("A",t),L.addPolynomial("B",e),L.addPolynomial("C",i),0}(),a&&a.debug("> ROUND 2"),await async function(){a&&a.debug("> Computing challenges beta and gamma");b.reset(),b.addPolCommitment(s.Qm),b.addPolCommitment(s.Ql),b.addPolCommitment(s.Qr),b.addPolCommitment(s.Qo),b.addPolCommitment(s.Qc),b.addPolCommitment(s.S1),b.addPolCommitment(s.S2),b.addPolCommitment(s.S3);for(let t=0;t<s.nPublic;t++)b.addScalar(_.A.slice(t*u,t*u+u));b.addPolCommitment(L.getPolynomial("A")),b.addPolCommitment(L.getPolynomial("B")),b.addPolCommitment(L.getPolynomial("C")),w.beta=b.getChallenge(),a&&a.debug("··· challenges.beta: "+d.toString(w.beta,16));b.reset(),b.addScalar(w.beta),w.gamma=b.getChallenge(),a&&a.debug("··· challenges.gamma: "+d.toString(w.gamma,16));a&&a.debug("> Computing Z polynomial");await async function(){a&&a.debug("··· Computing Z evaluations");let t=new Se(g),e=new Se(g);t.set(d.one,0),e.set(d.one,0);let i=d.one;for(let a=0;a<s.domainSize;a++){const o=a*u,n=_.A.slice(o,o+u),l=_.B.slice(o,o+u),r=_.C.slice(o,o+u),c=d.mul(w.beta,i);let g=d.add(n,c);g=d.add(g,w.gamma);let f=d.add(l,d.mul(s.k1,c));f=d.add(f,w.gamma);let h=d.add(r,d.mul(s.k2,c));h=d.add(h,w.gamma);let p=d.mul(g,d.mul(f,h)),L=d.add(n,d.mul(m.Sigma1.getEvaluation(4*a),w.beta));L=d.add(L,w.gamma);let b=d.add(l,d.mul(m.Sigma2.getEvaluation(4*a),w.beta));b=d.add(b,w.gamma);let y=d.add(r,d.mul(m.Sigma3.getEvaluation(4*a),w.beta));y=d.add(y,w.gamma);let A=d.mul(L,d.mul(b,y));p=d.mul(t.slice(o,o+u),p),t.set(p,(a+1)%s.domainSize*u),A=d.mul(e.slice(o,o+u),A),e.set(A,(a+1)%s.domainSize*u),i=d.mul(i,d.w[s.power])}e=await d.batchInverse(e);for(let a=0;a<s.domainSize;a++){const i=a*u,o=d.mul(t.slice(i,i+u),e.slice(i,i+u));t.set(o,i)}if(_.Z=t,!d.eq(t.slice(0,u),d.one))throw new Error("Copy constraints does not match");a&&a.debug("··· Computing Z ifft");p.Z=await il.fromEvaluations(_.Z,c,a),a&&a.debug("··· Computing Z fft");if(m.Z=await ol.fromPolynomial(p.Z,4,c,a),p.Z.blindCoefficients([w.b[9],w.b[8],w.b[7]]),p.Z.degree()>=s.domainSize+3)throw new Error("Z Polynomial is not well calculated");delete _.Z}(),a&&a.debug("> Computing Z MSM");let t=await p.Z.multiExponentiation(y,"Z");L.addPolynomial("Z",t)}(),a&&a.debug("> ROUND 3"),await async function(){a&&a.debug("> Computing challenge alpha");b.reset(),b.addScalar(w.beta),b.addScalar(w.gamma),b.addPolCommitment(L.getPolynomial("Z")),w.alpha=b.getChallenge(),w.alpha2=d.square(w.alpha),a&&a.debug("··· challenges.alpha: "+d.toString(w.alpha,16));a&&a.debug("> Computing T polynomial");await async function(){a&&a.debug(`··· Reading sections ${Wn}, ${Yn}, ${Zn}, ${Jn}, ${Xn}. Q selectors`);m.QL=new ol(new Se(4*g),c,a),m.QR=new ol(new Se(4*g),c,a),m.QM=new ol(new Se(4*g),c,a),m.QO=new ol(new Se(4*g),c,a),m.QC=new ol(new Se(4*g),c,a),await l.readToBuffer(m.QL.eval,0,4*g,r[Wn][0].p+g),await l.readToBuffer(m.QR.eval,0,4*g,r[Yn][0].p+g),await l.readToBuffer(m.QM.eval,0,4*g,r[Zn][0].p+g),await l.readToBuffer(m.QO.eval,0,4*g,r[Jn][0].p+g),await l.readToBuffer(m.QC.eval,0,4*g,r[Xn][0].p+g),m.Lagrange=new ol(new Se(4*g*s.nPublic),c,a);for(let t=0;t<s.nPublic;t++)await l.readToBuffer(m.Lagrange.eval,t*g*4,4*g,r[el][0].p+5*t*g+g);_.T=new Se(4*g),_.Tz=new Se(4*g),a&&a.debug("··· Computing T evaluations");let t=d.one;for(let e=0;e<4*s.domainSize;e++){a&&0!==e&&e%1e5==0&&a.debug(` T evaluation ${e}/${4*s.domainSize}`);const i=m.A.getEvaluation(e),o=m.B.getEvaluation(e),n=m.C.getEvaluation(e),l=m.Z.getEvaluation(e),r=m.Z.getEvaluation((4*s.domainSize+4+e)%(4*s.domainSize)),c=m.QM.getEvaluation(e),g=m.QL.getEvaluation(e),f=m.QR.getEvaluation(e),h=m.QO.getEvaluation(e),p=m.QC.getEvaluation(e),L=m.Sigma1.getEvaluation(e),b=m.Sigma2.getEvaluation(e),y=m.Sigma3.getEvaluation(e),A=d.add(w.b[2],d.mul(w.b[1],t)),C=d.add(w.b[4],d.mul(w.b[3],t)),I=d.add(w.b[6],d.mul(w.b[5],t)),F=d.square(t),x=d.add(d.add(d.mul(w.b[7],F),d.mul(w.b[8],t)),w.b[9]),E=d.mul(t,d.w[s.power]),v=d.square(E),B=d.add(d.add(d.mul(w.b[7],v),d.mul(w.b[8],E)),w.b[9]);let S=d.zero;for(let t=0;t<s.nPublic;t++){const a=4*t*s.domainSize+e,i=m.Lagrange.getEvaluation(a),o=_.A.slice(t*u,(t+1)*u);S=d.sub(S,d.mul(i,o))}let[P,G]=$n.mul2(i,o,A,C,e%4,d);P=d.mul(P,c),G=d.mul(G,c),P=d.add(P,d.mul(i,g)),G=d.add(G,d.mul(A,g)),P=d.add(P,d.mul(o,f)),G=d.add(G,d.mul(C,f)),P=d.add(P,d.mul(n,h)),G=d.add(G,d.mul(I,h)),P=d.add(P,S),P=d.add(P,p);const O=d.mul(w.beta,t);let T=i;T=d.add(T,O),T=d.add(T,w.gamma);let U=o;U=d.add(U,d.mul(O,s.k1)),U=d.add(U,w.gamma);let z=n;z=d.add(z,d.mul(O,s.k2)),z=d.add(z,w.gamma);let Q=l,[q,M]=$n.mul4(T,U,z,Q,A,C,I,x,e%4,d);q=d.mul(q,w.alpha),M=d.mul(M,w.alpha);let k=i;k=d.add(k,d.mul(w.beta,L)),k=d.add(k,w.gamma);let R=o;R=d.add(R,d.mul(w.beta,b)),R=d.add(R,w.gamma);let D=n;D=d.add(D,d.mul(w.beta,y)),D=d.add(D,w.gamma);let N=r,[$,V]=$n.mul4(k,R,D,N,A,C,I,B,e%4,d);$=d.mul($,w.alpha),V=d.mul(V,w.alpha);let K=d.sub(l,d.one);K=d.mul(K,m.Lagrange.getEvaluation(e)),K=d.mul(K,w.alpha2);let j=d.mul(x,m.Lagrange.getEvaluation(e));j=d.mul(j,w.alpha2);let H=d.add(d.sub(d.add(P,q),$),K),Z=d.add(d.sub(d.add(G,M),V),j);_.T.set(H,e*u),_.Tz.set(Z,e*u),t=d.mul(t,d.w[s.power+2])}a&&a.debug("··· Computing T ifft");p.T=await il.fromEvaluations(_.T,c,a),a&&a.debug("··· Computing T / ZH");p.T.divZh(s.domainSize,4),a&&a.debug("··· Computing Tz ifft");if(p.Tz=await il.fromEvaluations(_.Tz,c,a),p.T.add(p.Tz),p.T.degree()>=3*s.domainSize+6)throw new Error("T Polynomial is not well calculated");a&&a.debug("··· Computing T1, T2, T3 polynomials");p.T1=new il(new Se((s.domainSize+1)*u),c,a),p.T2=new il(new Se((s.domainSize+1)*u),c,a),p.T3=new il(new Se((s.domainSize+6)*u),c,a),p.T1.coef.set(p.T.coef.slice(0,g),0),p.T2.coef.set(p.T.coef.slice(g,2*g),0),p.T3.coef.set(p.T.coef.slice(2*g,3*g+6*u),0),p.T1.setCoef(s.domainSize,w.b[10]);const e=d.sub(p.T2.getCoef(0),w.b[10]);p.T2.setCoef(0,e),p.T2.setCoef(s.domainSize,w.b[11]);const i=d.sub(p.T3.getCoef(0),w.b[11]);p.T3.setCoef(0,i)}(),a&&a.debug("> Computing T MSM");let t=await p.T1.multiExponentiation(y,"T1"),e=await p.T2.multiExponentiation(y,"T2"),i=await p.T3.multiExponentiation(y,"T3");L.addPolynomial("T1",t),L.addPolynomial("T2",e),L.addPolynomial("T3",i)}(),a&&a.debug("> ROUND 4"),await async function(){a&&a.debug("> Computing challenge xi");b.reset(),b.addScalar(w.alpha),b.addPolCommitment(L.getPolynomial("T1")),b.addPolCommitment(L.getPolynomial("T2")),b.addPolCommitment(L.getPolynomial("T3")),w.xi=b.getChallenge(),w.xiw=d.mul(w.xi,d.w[s.power]),a&&a.debug("··· challenges.xi: "+d.toString(w.xi,16));L.addEvaluation("eval_a",p.A.evaluate(w.xi)),L.addEvaluation("eval_b",p.B.evaluate(w.xi)),L.addEvaluation("eval_c",p.C.evaluate(w.xi)),L.addEvaluation("eval_s1",p.Sigma1.evaluate(w.xi)),L.addEvaluation("eval_s2",p.Sigma2.evaluate(w.xi)),L.addEvaluation("eval_zw",p.Z.evaluate(w.xiw))}(),a&&a.debug("> ROUND 5"),await async function(){a&&a.debug("> Computing challenge v");b.reset(),b.addScalar(w.xi),b.addScalar(L.getEvaluation("eval_a")),b.addScalar(L.getEvaluation("eval_b")),b.addScalar(L.getEvaluation("eval_c")),b.addScalar(L.getEvaluation("eval_s1")),b.addScalar(L.getEvaluation("eval_s2")),b.addScalar(L.getEvaluation("eval_zw")),w.v=[],w.v[1]=b.getChallenge(),a&&a.debug("··· challenges.v: "+d.toString(w.v[1],16));for(let t=2;t<6;t++)w.v[t]=d.mul(w.v[t-1],w.v[1]);a&&a.debug("> Computing linearisation polynomial R(X)");await async function(){const t=c.Fr;p.QL=new il(new Se(g),c,a),p.QR=new il(new Se(g),c,a),p.QM=new il(new Se(g),c,a),p.QO=new il(new Se(g),c,a),p.QC=new il(new Se(g),c,a),await l.readToBuffer(p.QL.coef,0,g,r[Wn][0].p),await l.readToBuffer(p.QR.coef,0,g,r[Yn][0].p),await l.readToBuffer(p.QM.coef,0,g,r[Zn][0].p),await l.readToBuffer(p.QO.coef,0,g,r[Jn][0].p),await l.readToBuffer(p.QC.coef,0,g,r[Xn][0].p),w.xin=w.xi;for(let e=0;e<s.power;e++)w.xin=t.square(w.xin);w.zh=t.sub(w.xin,t.one);const e=[],i=t.e(s.domainSize);let o=t.one;for(let a=1;a<=Math.max(1,s.nPublic);a++)e[a]=t.div(t.mul(o,w.zh),t.mul(i,t.sub(w.xi,o))),o=t.mul(o,t.w[s.power]);const n=t.div(t.sub(w.xin,t.one),t.mul(i,t.sub(w.xi,t.one)));if(a){a.debug("Lagrange Evaluations: ");for(let i=1;i<e.length;i++)a.debug(`L${i}(xi)=`+t.toString(e[i],16))}let d=t.zero;for(let a=0;a<A.length;a++){const i=t.e(A[a]);d=t.sub(d,t.mul(i,e[a+1]))}a&&a.debug("PI: "+t.toString(d,16));const f=t.mul(L.evaluations.eval_a,L.evaluations.eval_b);let h=L.evaluations.eval_a;const _=t.mul(w.beta,w.xi);h=t.add(h,_),h=t.add(h,w.gamma);let m=L.evaluations.eval_b;m=t.add(m,t.mul(_,s.k1)),m=t.add(m,w.gamma);let b=L.evaluations.eval_c;b=t.add(b,t.mul(_,s.k2)),b=t.add(b,w.gamma);const y=t.mul(t.mul(t.mul(h,m),b),w.alpha);let C=L.evaluations.eval_a;C=t.add(C,t.mul(w.beta,L.evaluations.eval_s1)),C=t.add(C,w.gamma);let I=L.evaluations.eval_b;I=t.add(I,t.mul(w.beta,L.evaluations.eval_s2)),I=t.add(I,w.gamma);let F=t.mul(C,I);F=t.mul(F,L.evaluations.eval_zw),F=t.mul(F,w.alpha);const x=t.mul(n,w.alpha2);p.R=new il(new Se((s.domainSize+6)*u),c,a),p.R.add(p.QM,f),p.R.add(p.QL,L.evaluations.eval_a),p.R.add(p.QR,L.evaluations.eval_b),p.R.add(p.QO,L.evaluations.eval_c),p.R.add(p.QC),p.R.add(p.Z,y),p.R.sub(p.Sigma3,t.mul(F,w.beta)),p.R.add(p.Z,x);let E=il.fromPolynomial(p.T3,c,a);E.mulScalar(t.square(w.xin)),E.add(p.T2,w.xin),E.add(p.T1),E.mulScalar(w.zh),p.R.sub(E);let v=t.sub(d,t.mul(F,t.add(L.evaluations.eval_c,w.gamma)));v=t.sub(v,x),a&&a.debug("r0: "+t.toString(v,16));p.R.addScalar(v)}(),a&&a.debug("> Computing opening proof polynomial Wxi(X) polynomial");p.Wxi=new il(new Se(g+6*u),c,a),p.Wxi.add(p.R),p.Wxi.add(p.A,w.v[1]),p.Wxi.add(p.B,w.v[2]),p.Wxi.add(p.C,w.v[3]),p.Wxi.add(p.Sigma1,w.v[4]),p.Wxi.add(p.Sigma2,w.v[5]),p.Wxi.subScalar(d.mul(w.v[1],L.evaluations.eval_a)),p.Wxi.subScalar(d.mul(w.v[2],L.evaluations.eval_b)),p.Wxi.subScalar(d.mul(w.v[3],L.evaluations.eval_c)),p.Wxi.subScalar(d.mul(w.v[4],L.evaluations.eval_s1)),p.Wxi.subScalar(d.mul(w.v[5],L.evaluations.eval_s2)),void p.Wxi.divByZerofier(1,w.xi),a&&a.debug("> Computing opening proof polynomial Wxiw(X) polynomial");(async function(){p.Wxiw=il.fromPolynomial(p.Z,c,a),p.Wxiw.subScalar(L.evaluations.eval_zw),p.Wxiw.divByZerofier(1,w.xiw)})(),a&&a.debug("> Computing Wxi, Wxiw MSM");let t=await p.Wxi.multiExponentiation(y,"Wxi"),e=await p.Wxiw.multiExponentiation(y,"Wxiw");L.addPolynomial("Wxi",t),L.addPolynomial("Wxiw",e)}(),await l.close(),await i.close();let C=L.toObjectProof(!1);return C.protocol="plonk",C.curve=c.name,a&&a.debug("PLONK PROVER FINISHED"),{proof:nl(C),publicSignals:nl(A)};function I(t,e){const a=t.slice(e,e+4);return new DataView(a.buffer,a.byteOffset,a.byteLength).getUint32(0,!0)}function F(t){return t<s.nVars-s.nAdditions?f.slice(t*u,t*u+u):t<s.nVars?h.slice((t-(s.nVars-s.nAdditions))*u,(t-(s.nVars-s.nAdditions))*u+u):c.Fr.zero}}const{unstringifyBigInts:rl}=fa;const{unstringifyBigInts:sl}=fa;const{unstringifyBigInts:cl}=fa;function dl(t){let e=t.toString(16);for(;e.length<64;)e="0"+e;return e=`"0x${e}"`,e}var ul=Object.freeze({__proto__:null,setup:async function(t,e,a,i){globalThis.gc&&globalThis.gc(),await ti.exports.ready();const{fd:o,sections:n}=await za(e,"ptau",1),{curve:l,power:r}=await Ho(o,n),{fd:s,sections:c}=await za(t,"r1cs",1),d=await pn(s,c,{loadConstraints:!0,loadCustomGates:!0}),u=2*l.G1.F.n8,g=l.G1,f=2*l.G2.F.n8,h=l.Fr,_=l.Fr.n8;i&&i.info("Reading r1cs"),await Va(s,c,2);const p=new En,m=new En;let w=d.nVars;const L=d.nOutputs+d.nPubInputs;await async function(t,e,a){function i(t){const e=Object.keys(t);for(let a=0;a<e.length;a++)0n==t[e[a]]&&delete t[e[a]]}function o(e,a,o){const n={};for(let i in e)void 0===n[i]?n[i]=t.mul(a,e[i]):n[i]=t.add(n[i],t.mul(a,e[i]));for(let e in o)void 0===n[e]?n[e]=o[e]:n[e]=t.add(n[e],o[e]);return i(n),n}function n(e,a){const i={k:t.zero,s:[],coefs:[]},o=[];for(let a in e)0==a?i.k=t.add(i.k,e[a]):0n!=e[a]&&o.push([Number(a),e[a]]);for(;o.length>a;){const e=o.shift(),a=o.shift(),i=e[0],n=a[0],l=w++,r=t.zero,s=t.neg(e[1]),c=t.neg(a[1]),d=t.one,u=t.zero;p.push([i,n,l,r,s,c,d,u]),m.push([i,n,e[1],a[1]]),o.push([l,t.one])}for(let t=0;t<o.length;t++)i.s[t]=o[t][0],i.coefs[t]=o[t][1];for(;i.coefs.length<a;)i.s.push(0),i.coefs.push(t.zero);return i}function l(e){const a=n(e,3),i=a.s[0],o=a.s[1],l=a.s[2],r=t.zero,s=a.coefs[0],c=a.coefs[1],d=a.coefs[2],u=a.k;p.push([i,o,l,r,s,c,d,u])}function r(e){let a=t.zero,i=0;const o=Object.keys(e);for(let n=0;n<o.length;n++)0n==e[o[n]]?delete e[o[n]]:0==o[n]?a=t.add(a,e[o[n]]):i++;return i>0?i.toString():a!=t.zero?"k":"0"}function s(e,a,s){const c=r(e),d=r(a);if("0"===c||"0"===d)i(s),l(s);else if("k"===c){l(o(a,e[0],s))}else if("k"===d){l(o(e,a[0],s))}else!function(e,a,i){const o=n(e,1),l=n(a,1),r=n(i,1),s=o.s[0],c=l.s[0],d=r.s[0],u=t.mul(o.coefs[0],l.coefs[0]),g=t.mul(o.coefs[0],l.k),f=t.mul(o.k,l.coefs[0]),h=t.neg(r.coefs[0]),_=t.sub(t.mul(o.k,l.k),r.k);p.push([s,c,d,u,g,f,h,_])}(e,a,s)}for(let e=1;e<=L;e++){const a=e,i=0,o=0,n=t.zero,l=t.one,r=t.zero,s=t.zero,c=t.zero;p.push([a,i,o,n,l,r,s,c])}for(let t=0;t<e.constraints.length;t++)a&&t%1e4==0&&a.debug(`processing constraints: ${t}/${e.nConstraints}`),s(...e.constraints[t])}(l.Fr,d,i),globalThis.gc&&globalThis.gc();const b=await Qa(a,"zkey",1,14,1<<22,1<<24);if(d.prime!=l.r)return i&&i.error("r1cs curve does not match powers of tau ceremony curve"),-1;let y=Ui(p.length-1)+1;y<3&&(y=3);const A=2**y;if(i&&i.info("Plonk constraints: "+p.length),y>r)return i&&i.error(`circuit too big for this power of tau ceremony. ${p.length} > 2**${r}`),-1;if(!n[12])return i&&i.error("Powers of tau is not prepared."),-1;const C=new Se(A*u),I=n[12][0].p+(2**y-1)*u;await o.readToBuffer(C,0,A*u,I);const[F,x]=function(){let t=h.two;for(;a(t,[],y);)h.add(t,h.one);let e=h.add(t,h.one);for(;a(e,[t],y);)h.add(e,h.one);return[t,e];function a(t,e,a){const i=2**a;let o=h.one;for(let n=0;n<i;n++){if(h.eq(t,o))return!0;for(let a=0;a<e.length;a++)if(h.eq(t,h.mul(e[a],o)))return!0;o=h.mul(o,h.w[a])}return!1}}(),E={};await async function(t,e){await qa(b,t);const a=new Uint8Array(8+2*_),o=new DataView(a.buffer);for(let t=0;t<m.length;t++){const n=m[t];let l=0;o.setUint32(l,n[0],!0),l+=4,o.setUint32(l,n[1],!0),l+=4,a.set(n[2],l),l+=_,a.set(n[3],l),l+=_,await b.write(a),i&&t%1e6==0&&i.debug(`writing ${e}: ${t}/${m.length}`)}await Ma(b)}(3,"Additions"),globalThis.gc&&globalThis.gc(),await B(4,0,"Amap"),globalThis.gc&&globalThis.gc(),await B(5,1,"Bmap"),globalThis.gc&&globalThis.gc(),await B(6,2,"Cmap"),globalThis.gc&&globalThis.gc(),await S(7,3,"Qm"),globalThis.gc&&globalThis.gc(),await S(8,4,"Ql"),globalThis.gc&&globalThis.gc(),await S(9,5,"Qr"),globalThis.gc&&globalThis.gc(),await S(10,6,"Qo"),globalThis.gc&&globalThis.gc(),await S(11,7,"Qc"),globalThis.gc&&globalThis.gc(),await async function(t,e){const a=new Se(_*A*3),o=new En(w),n=new En(w);let r=h.one;for(let t=0;t<A;t++)t<p.length?(u(p[t][0],t),u(p[t][1],A+t),u(p[t][2],2*A+t)):(u(0,t),u(0,A+t),u(0,2*A+t)),r=h.mul(r,h.w[y]),i&&t%1e6==0&&i.debug(`writing ${e} phase1: ${t}/${p.length}`);for(let t=0;t<w;t++)void 0!==n[t]?a.set(o[t],n[t]*_):console.log("Variable not used"),i&&t%1e6==0&&i.debug(`writing ${e} phase2: ${t}/${w}`);globalThis.gc&&globalThis.gc();await qa(b,t);let s=a.slice(0,A*_);await P(s),globalThis.gc&&globalThis.gc();let c=a.slice(A*_,A*_*2);await P(c),globalThis.gc&&globalThis.gc();let d=a.slice(A*_*2,A*_*3);await P(d),globalThis.gc&&globalThis.gc();await Ma(b),s=await h.batchFromMontgomery(s),c=await h.batchFromMontgomery(c),d=await h.batchFromMontgomery(d),E.S1=await l.G1.multiExpAffine(C,s,i,"multiexp S1"),globalThis.gc&&globalThis.gc();E.S2=await l.G1.multiExpAffine(C,c,i,"multiexp S2"),globalThis.gc&&globalThis.gc();E.S3=await l.G1.multiExpAffine(C,d,i,"multiexp S3"),globalThis.gc&&globalThis.gc();function u(t,e){let i;void 0===o[t]?n[t]=e:a.set(o[t],e*_),i=e<A?r:e<2*A?h.mul(r,F):h.mul(r,x),o[t]=i}}(12,"sigma"),globalThis.gc&&globalThis.gc(),await async function(t,e){await qa(b,t);const a=Math.max(L,1);for(let t=0;t<a;t++){let o=new Se(A*_);o.set(h.one,t*_),await P(o),i&&i.debug(`writing ${e} ${t}/${a}`)}await Ma(b)}(13,"lagrange polynomials"),globalThis.gc&&globalThis.gc(),await qa(b,14);const v=new Se((A+6)*u);return await o.readToBuffer(v,0,(A+6)*u,n[2][0].p),await b.write(v),await Ma(b),globalThis.gc&&globalThis.gc(),await async function(){await qa(b,1),await b.writeULE32(2),await Ma(b),await qa(b,2);const t=l.q,e=8*(Math.floor((ga.bitLength(t)-1)/64)+1),a=l.r,i=8*(Math.floor((ga.bitLength(a)-1)/64)+1);let r;await b.writeULE32(e),await Da(b,t,e),await b.writeULE32(i),await Da(b,a,i),await b.writeULE32(w),await b.writeULE32(L),await b.writeULE32(A),await b.writeULE32(m.length),await b.writeULE32(p.length),await b.write(F),await b.write(x),await b.write(g.toAffine(E.Qm)),await b.write(g.toAffine(E.Ql)),await b.write(g.toAffine(E.Qr)),await b.write(g.toAffine(E.Qo)),await b.write(g.toAffine(E.Qc)),await b.write(g.toAffine(E.S1)),await b.write(g.toAffine(E.S2)),await b.write(g.toAffine(E.S3)),r=await o.read(f,n[3][0].p+f),await b.write(r),await Ma(b)}(),await b.close(),await s.close(),await o.close(),void(i&&i.info("Setup Finished"));async function B(t,e,a){await qa(b,t);for(let t=0;t<p.length;t++)await b.writeULE32(p[t][e]),i&&t%1e6==0&&i.debug(`writing ${a}: ${t}/${p.length}`);await Ma(b)}async function S(t,e,a){let o=new Se(A*_);for(let t=0;t<p.length;t++)o.set(p[t][e],t*_),i&&t%1e6==0&&i.debug(`writing ${a}: ${t}/${p.length}`);await qa(b,t),await P(o),await Ma(b),o=await h.batchFromMontgomery(o),E[a]=await l.G1.multiExpAffine(C,o,i,"multiexp "+a)}async function P(t){const e=await h.ifft(t),a=new Se(A*_*4);a.set(e,0);const i=await h.fft(a);await b.write(e),await b.write(i)}},fullProve:async function(t,e,a,i){const o=rl(t),n={type:"mem"};return await Qo(o,e,n),await ll(a,n,i)},prove:ll,verify:async function(t,e,a,i){let o=sl(t);a=sl(a);let n=sl(e);const l=await Ja(o.curve),r=l.Fr,s=l.G1;i&&i.info("PLONK VERIFIER STARTED");let c=function(t,e){const a=t.G1,i=t.Fr,o={};return o.A=a.fromObject(e.A),o.B=a.fromObject(e.B),o.C=a.fromObject(e.C),o.Z=a.fromObject(e.Z),o.T1=a.fromObject(e.T1),o.T2=a.fromObject(e.T2),o.T3=a.fromObject(e.T3),o.eval_a=i.fromObject(e.eval_a),o.eval_b=i.fromObject(e.eval_b),o.eval_c=i.fromObject(e.eval_c),o.eval_zw=i.fromObject(e.eval_zw),o.eval_s1=i.fromObject(e.eval_s1),o.eval_s2=i.fromObject(e.eval_s2),o.Wxi=a.fromObject(e.Wxi),o.Wxiw=a.fromObject(e.Wxiw),o}(l,a);if(o=function(t,e){const a=t.G1,i=t.G2,o=t.Fr,n=e;return n.Qm=a.fromObject(e.Qm),n.Ql=a.fromObject(e.Ql),n.Qr=a.fromObject(e.Qr),n.Qo=a.fromObject(e.Qo),n.Qc=a.fromObject(e.Qc),n.S1=a.fromObject(e.S1),n.S2=a.fromObject(e.S2),n.S3=a.fromObject(e.S3),n.k1=o.fromObject(e.k1),n.k2=o.fromObject(e.k2),n.X_2=i.fromObject(e.X_2),n}(l,o),!function(t,e){const a=t.G1;return!!a.isValid(e.A)&&(!!a.isValid(e.B)&&(!!a.isValid(e.C)&&(!!a.isValid(e.Z)&&(!!a.isValid(e.T1)&&(!!a.isValid(e.T2)&&(!!a.isValid(e.T3)&&(!!a.isValid(e.Wxi)&&!!a.isValid(e.Wxiw))))))))}(l,c))return i.error("Proof is not well constructed"),!1;if(n.length!=o.nPublic)return i.error("Invalid number of public inputs"),!1;const d=function(t,e,a,i){const o=t.Fr,n={},l=new Nn(t);l.addPolCommitment(i.Qm),l.addPolCommitment(i.Ql),l.addPolCommitment(i.Qr),l.addPolCommitment(i.Qo),l.addPolCommitment(i.Qc),l.addPolCommitment(i.S1),l.addPolCommitment(i.S2),l.addPolCommitment(i.S3);for(let t=0;t<a.length;t++)l.addScalar(o.e(a[t]));l.addPolCommitment(e.A),l.addPolCommitment(e.B),l.addPolCommitment(e.C),n.beta=l.getChallenge(),l.reset(),l.addScalar(n.beta),n.gamma=l.getChallenge(),l.reset(),l.addScalar(n.beta),l.addScalar(n.gamma),l.addPolCommitment(e.Z),n.alpha=l.getChallenge(),l.reset(),l.addScalar(n.alpha),l.addPolCommitment(e.T1),l.addPolCommitment(e.T2),l.addPolCommitment(e.T3),n.xi=l.getChallenge(),l.reset(),l.addScalar(n.xi),l.addScalar(e.eval_a),l.addScalar(e.eval_b),l.addScalar(e.eval_c),l.addScalar(e.eval_s1),l.addScalar(e.eval_s2),l.addScalar(e.eval_zw),n.v=[],n.v[1]=l.getChallenge();for(let t=2;t<6;t++)n.v[t]=o.mul(n.v[t-1],n.v[1]);return l.reset(),l.addPolCommitment(e.Wxi),l.addPolCommitment(e.Wxiw),n.u=l.getChallenge(),n}(l,c,n,o);if(i){i.debug("beta: "+r.toString(d.beta,16)),i.debug("gamma: "+r.toString(d.gamma,16)),i.debug("alpha: "+r.toString(d.alpha,16)),i.debug("xi: "+r.toString(d.xi,16));for(let t=1;t<6;t++)i&&i.debug("v: "+r.toString(d.v[t],16));i.debug("u: "+r.toString(d.u,16))}const u=function(t,e,a){const i=t.Fr;let o=e.xi,n=1;for(let t=0;t<a.power;t++)o=i.square(o),n*=2;e.xin=o,e.zh=i.sub(o,i.one);const l=[],r=i.e(n);let s=i.one;for(let t=1;t<=Math.max(1,a.nPublic);t++)l[t]=i.div(i.mul(s,e.zh),i.mul(r,i.sub(e.xi,s))),s=i.mul(s,i.w[a.power]);return l}(l,d,o);if(i)for(let t=1;t<u.length;t++)i.debug(`L${t}(xi)=`+r.toString(u[t],16));if(n.length!=o.nPublic)return i.error("Number of public signals does not match with vk"),!1;const g=function(t,e,a){const i=t.Fr;let o=i.zero;for(let t=0;t<e.length;t++){const n=i.e(e[t]);o=i.sub(o,i.mul(n,a[t+1]))}return o}(l,n,u);i&&i.debug("PI(xi): "+r.toString(g,16));const f=function(t,e,a,i,o){const n=t.Fr,l=i,r=n.mul(o,n.square(a.alpha));let s=n.add(e.eval_a,n.mul(a.beta,e.eval_s1));s=n.add(s,a.gamma);let c=n.add(e.eval_b,n.mul(a.beta,e.eval_s2));c=n.add(c,a.gamma);let d=n.add(e.eval_c,a.gamma),u=n.mul(n.mul(s,c),d);u=n.mul(u,e.eval_zw),u=n.mul(u,a.alpha);const g=n.sub(n.sub(l,r),u);return g}(l,c,d,g,u[1]);i&&i.debug("r0: "+r.toString(f,16));const h=function(t,e,a,i,o){const n=t.G1,l=t.Fr;let r=n.timesFr(i.Qm,l.mul(e.eval_a,e.eval_b));r=n.add(r,n.timesFr(i.Ql,e.eval_a)),r=n.add(r,n.timesFr(i.Qr,e.eval_b)),r=n.add(r,n.timesFr(i.Qo,e.eval_c)),r=n.add(r,i.Qc);const s=l.mul(a.beta,a.xi),c=l.add(l.add(e.eval_a,s),a.gamma),d=l.add(l.add(e.eval_b,l.mul(s,i.k1)),a.gamma),u=l.add(l.add(e.eval_c,l.mul(s,i.k2)),a.gamma),g=l.mul(l.mul(l.mul(c,d),u),a.alpha),f=l.mul(o,l.square(a.alpha)),h=n.timesFr(e.Z,l.add(l.add(g,f),a.u)),_=l.add(l.add(e.eval_a,l.mul(a.beta,e.eval_s1)),a.gamma),p=l.add(l.add(e.eval_b,l.mul(a.beta,e.eval_s2)),a.gamma),m=l.mul(l.mul(a.alpha,a.beta),e.eval_zw),w=n.timesFr(i.S3,l.mul(l.mul(_,p),m)),L=e.T1,b=n.timesFr(e.T2,a.xin),y=n.timesFr(e.T3,l.square(a.xin));let A=n.add(L,n.add(b,y));A=n.timesFr(A,a.zh);const C=n.sub(n.sub(n.add(r,h),w),A);return C}(l,c,d,o,u[1]);i&&i.debug("D: "+s.toString(s.toAffine(h),16));const _=function(t,e,a,i,o){const n=t.G1;let l=n.add(o,n.timesFr(e.A,a.v[1]));return l=n.add(l,n.timesFr(e.B,a.v[2])),l=n.add(l,n.timesFr(e.C,a.v[3])),l=n.add(l,n.timesFr(i.S1,a.v[4])),l=n.add(l,n.timesFr(i.S2,a.v[5])),l}(l,c,d,o,h);i&&i.debug("F: "+s.toString(s.toAffine(_),16));const p=function(t,e,a,i){const o=t.G1,n=t.Fr;let l=n.add(n.neg(i),n.mul(a.v[1],e.eval_a));l=n.add(l,n.mul(a.v[2],e.eval_b)),l=n.add(l,n.mul(a.v[3],e.eval_c)),l=n.add(l,n.mul(a.v[4],e.eval_s1)),l=n.add(l,n.mul(a.v[5],e.eval_s2)),l=n.add(l,n.mul(a.u,e.eval_zw));const r=o.timesFr(o.one,l);return r}(l,c,d,f);i&&i.debug("E: "+s.toString(s.toAffine(p),16));const m=await async function(t,e,a,i,o,n){const l=t.G1,r=t.Fr;let s=e.Wxi;s=l.add(s,l.timesFr(e.Wxiw,a.u));let c=l.timesFr(e.Wxi,a.xi);const d=r.mul(r.mul(a.u,a.xi),r.w[i.power]);c=l.add(c,l.timesFr(e.Wxiw,d)),c=l.add(c,n),c=l.sub(c,o);const u=await t.pairingEq(l.neg(s),i.X_2,c,t.G2.one);return u}(l,c,d,o,p,_);return i&&(m?i.info("OK!"):i.warn("Invalid Proof")),m},exportSolidityCallData:async function(t,e){const a=cl(t),i=cl(e),o=await Ja(a.curve);o.G1,o.Fr;let n="";for(let t=0;t<i.length;t++)""!=n&&(n+=","),n+=dl(i[t]);return`[${dl(a.A[0])}, ${dl(a.A[1])},${dl(a.B[0])},${dl(a.B[1])},${dl(a.C[0])},${dl(a.C[1])},${dl(a.Z[0])},${dl(a.Z[1])},${dl(a.T1[0])},${dl(a.T1[1])},${dl(a.T2[0])},${dl(a.T2[1])},${dl(a.T3[0])},${dl(a.T3[1])},${dl(a.Wxi[0])},${dl(a.Wxi[1])},${dl(a.Wxiw[0])},${dl(a.Wxiw[1])},${dl(a.eval_a)},${dl(a.eval_b)},${dl(a.eval_c)},${dl(a.eval_s1)},${dl(a.eval_s2)},${dl(a.eval_zw)}][${n}]`}});function gl(t,e){return[t,0,0,e.one,e.zero,e.zero,e.zero,e.zero]}function fl(t,e,a,i,o,n,l,r){return[t,e,a,i,o,n,l,r]}function hl(t,e,a,i,o,n,l,r,s){return[t,e,a,i,o,n,l,r]}class _l{constructor(t,e,a,i,o){this.Fr=t,this.logger=o,this.fnGetAdditionConstraint=a,this.fnGetMultiplicationConstraint=i}processR1csConstraint(t,e,a,i){this.normalizeLinearCombination(e),this.normalizeLinearCombination(a),this.normalizeLinearCombination(i);const o=this.getLinearCombinationType(e),n=this.getLinearCombinationType(a);if(0===o||0===n)return this.processR1csAdditionConstraint(t,i);if(1===o){const o=this.joinLinearCombinations(a,i,e[0]);return this.processR1csAdditionConstraint(t,o)}if(1===n){const o=this.joinLinearCombinations(e,i,a[0]);return this.processR1csAdditionConstraint(t,o)}return this.processR1csMultiplicationConstraint(t,e,a,i)}getLinearCombinationType(t){let e=this.Fr.zero,a=0;const i=Object.keys(t);for(let o=0;o<i.length;o++)0n==t[i[o]]?delete t[i[o]]:0==i[o]?e=this.Fr.add(e,t[i[o]]):a++;return a>0?2:this.Fr.isZero(e)?0:1}normalizeLinearCombination(t){const e=Object.keys(t);for(let a=0;a<e.length;a++)this.Fr.isZero(t[e[a]])&&delete t[e[a]];return t}joinLinearCombinations(t,e,a){const i={};for(let e in t)void 0===i[e]?i[e]=this.Fr.mul(a,t[e]):i[e]=this.Fr.add(i[e],this.Fr.mul(a,t[e]));for(let t in e)void 0===i[t]?i[t]=e[t]:i[t]=this.Fr.add(i[t],e[t]);return this.normalizeLinearCombination(i)}reduceCoefs(t,e,a,i,o){const n={k:this.Fr.zero,signals:[],coefs:[]},l=[];for(let t in i)0==t?n.k=this.Fr.add(n.k,i[t]):0n!=i[t]&&l.push([Number(t),i[t]]);for(;l.length>o;){const i=l.shift(),o=l.shift(),n=t.nVars++,r=this.fnGetAdditionConstraint(i[0],o[0],n,this.Fr.neg(i[1]),this.Fr.neg(o[1]),this.Fr.zero,this.Fr.one,this.Fr.zero);e.push(r),a.push([i[0],o[0],i[1],o[1]]),l.push([n,this.Fr.one])}for(let t=0;t<l.length;t++)n.signals[t]=l[t][0],n.coefs[t]=l[t][1];for(;n.coefs.length<o;)n.signals.push(0),n.coefs.push(this.Fr.zero);return n}processR1csAdditionConstraint(t,e){const a=[],i=[],o=this.reduceCoefs(t,a,i,e,3),n=this.fnGetAdditionConstraint(o.signals[0],o.signals[1],o.signals[2],o.coefs[0],o.coefs[1],this.Fr.zero,o.coefs[2],o.k);return a.push(n),[a,i]}processR1csMultiplicationConstraint(t,e,a,i){const o=[],n=[],l=this.reduceCoefs(t,o,n,e,1),r=this.reduceCoefs(t,o,n,a,1),s=this.reduceCoefs(t,o,n,i,1),c=this.fnGetMultiplicationConstraint(l.signals[0],r.signals[0],s.signals[0],this.Fr.mul(l.coefs[0],r.k),this.Fr.mul(l.k,r.coefs[0]),this.Fr.mul(l.coefs[0],r.coefs[0]),this.Fr.neg(s.coefs[0]),this.Fr.sub(this.Fr.mul(l.k,r.k),s.k));return o.push(c),[o,n]}}class pl{constructor(t,e,a){this.n=t,this.polynomials=Array(t).fill(void 0),this.curve=e,this.Fr=e.Fr,this.G1=e.G1,this.logger=a}addPolynomial(t,e){if(t>this.n-1)throw new Error("CPolynomial:addPolynomial, cannot add a polynomial to a position greater than n-1");this.polynomials[t]=e}degree(){let t=this.polynomials.map(((t,e)=>void 0===t?0:t.degree()*this.n+e));return Math.max(...t)}getPolynomial(){let t=this.polynomials.map((t=>void 0===t?0:t.degree()));const e=this.degree(),a=2**(Ui(e-1)+1),i=this.Fr.n8;let o=new il(new Se(a*i),this.curve,this.logger);for(let a=0;a<e;a++){const e=a*i,n=e*this.n;for(let l=0;l<this.n;l++)void 0!==this.polynomials[l]&&a<=t[l]&&o.coef.set(this.polynomials[l].coef.slice(e,e+i),n+l*i)}return o}async multiExponentiation(t,e){let a=this.getPolynomial();const i=a.coef.byteLength/this.Fr.n8,o=t.slice(0,i*this.G1.F.n8*2),n=await this.Fr.batchFromMontgomery(a.coef);let l=await this.G1.multiExpAffine(o,n,this.logger,e);return l=this.G1.toAffine(l),l}}const{stringifyBigInts:ml}=fa;async function wl(t,e,a){a&&a.info("FFLONK PROVER STARTED"),a&&a.info("> Reading witness file");const{fd:i,sections:o}=await za(e,"wtns",2),n=await xo(i,o);a&&a.info("> Reading zkey file");const{fd:l,sections:r}=await za(t,"zkey",2),s=await Lo(l,r);if(s.protocolId!==Wi)throw new Error("zkey file is not fflonk");if(!ga.eq(s.r,n.q))throw new Error("Curve of the witness does not match the curve of the proving key");if(n.nWitness!==s.nVars-s.nAdditions)throw new Error(`Invalid witness length. Circuit: ${s.nVars}, witness: ${n.nWitness}, ${s.nAdditions}`);const c=s.curve,d=c.Fr,u=c.Fr.n8,g=2*c.G1.F.n8,f=s.domainSize*u;a&&(a.info("----------------------------"),a.info(" FFLONK PROVE SETTINGS"),a.info(` Curve: ${c.name}`),a.info(` Circuit power: ${s.power}`),a.info(` Domain size: ${s.domainSize}`),a.info(` Vars: ${s.nVars}`),a.info(` Public vars: ${s.nPublic}`),a.info(` Constraints: ${s.nConstraints}`),a.info(` Additions: ${s.nAdditions}`),a.info("----------------------------")),a&&a.info("> Reading witness file data");const h=await Va(i,o,2);await i.close(),h.set(d.zero,0);const _=new Se(s.nAdditions*u);let p={},m={},w={},L={},b={},y={},A=new qn(c,a);a&&a.info(`> Reading Section ${Ji}. Additions`),await async function(){a&&a.info("··· Computing additions");const t=await Va(l,r,Ji),e=8+2*u;for(let i=0;i<s.nAdditions;i++){a&&0!==i&&i%1e5==0&&a.info(` addition ${i}/${s.nAdditions}`);let o=i*e;const n=x(t,o);o+=4;const l=x(t,o);o+=4;const r=t.slice(o,o+u);o+=u;const c=t.slice(o,o+u),g=E(n),f=E(l),h=d.add(d.mul(r,g),d.mul(c,f));_.set(h,u*i)}}(),a&&a.info(`> Reading Sections ${ro},${so},${co}. Sigma1, Sigma2 & Sigma 3`),a&&a.info("··· Reading Sigma polynomials "),m.Sigma1=new il(new Se(f),c,a),m.Sigma2=new il(new Se(f),c,a),m.Sigma3=new il(new Se(f),c,a),await l.readToBuffer(m.Sigma1.coef,0,f,r[ro][0].p),await l.readToBuffer(m.Sigma2.coef,0,f,r[so][0].p),await l.readToBuffer(m.Sigma3.coef,0,f,r[co][0].p),a&&a.info("··· Reading Sigma evaluations"),w.Sigma1=new ol(new Se(4*f),c,a),w.Sigma2=new ol(new Se(4*f),c,a),w.Sigma3=new ol(new Se(4*f),c,a),await l.readToBuffer(w.Sigma1.eval,0,4*f,r[ro][0].p+f),await l.readToBuffer(w.Sigma2.eval,0,4*f,r[so][0].p+f),await l.readToBuffer(w.Sigma3.eval,0,4*f,r[co][0].p+f),a&&a.info(`> Reading Section ${go}. Powers of Tau`);const C=new Se(16*s.domainSize*g);await l.readToBuffer(C,0,(9*s.domainSize+18)*g,r[go][0].p),globalThis.gc&&globalThis.gc(),a&&a.info(""),a&&a.info("> ROUND 1"),await async function(){b.b=[];for(let t=1;t<=9;t++)b.b[t]=d.random();a&&a.info("> Computing A, B, C wire polynomials");await async function(){a&&a.info("··· Reading data from zkey file");p.A=new Se(f),p.B=new Se(f),p.C=new Se(f);const t=await Va(l,r,Xi),e=await Va(l,r,to),i=await Va(l,r,eo);for(let a=0;a<s.nConstraints;a++){const o=a*u,n=4*a,l=x(t,n);p.A.set(E(l),o);const r=x(e,n);p.B.set(E(r),o);const s=x(i,n);p.C.set(E(s),o)}p.A.set(b.b[1],f-64),p.A.set(b.b[2],f-32),p.B.set(b.b[3],f-64),p.B.set(b.b[4],f-32),p.C.set(b.b[5],f-64),p.C.set(b.b[6],f-32),p.A=await d.batchToMontgomery(p.A),p.B=await d.batchToMontgomery(p.B),p.C=await d.batchToMontgomery(p.C),a&&a.info("··· Computing A ifft");m.A=await il.fromEvaluations(p.A,c,a),a&&a.info("··· Computing B ifft");m.B=await il.fromEvaluations(p.B,c,a),a&&a.info("··· Computing C ifft");m.C=await il.fromEvaluations(p.C,c,a),a&&a.info("··· Computing A fft");w.A=await ol.fromPolynomial(m.A,4,c,a),a&&a.info("··· Computing B fft");w.B=await ol.fromPolynomial(m.B,4,c,a),a&&a.info("··· Computing C fft");if(w.C=await ol.fromPolynomial(m.C,4,c,a),m.A.degree()>=s.domainSize)throw new Error("A Polynomial is not well calculated");if(m.B.degree()>=s.domainSize)throw new Error("B Polynomial is not well calculated");if(m.C.degree()>=s.domainSize)throw new Error("C Polynomial is not well calculated")}(),a&&a.info("> Computing T0 polynomial");await async function(){a&&a.info(`··· Reading sections ${ao}, ${io}, ${oo}, ${no}, ${lo}. Q selectors`);w.QL=new ol(new Se(4*f),c,a),w.QR=new ol(new Se(4*f),c,a),w.QM=new ol(new Se(4*f),c,a),w.QO=new ol(new Se(4*f),c,a),w.QC=new ol(new Se(4*f),c,a),await l.readToBuffer(w.QL.eval,0,4*f,r[ao][0].p+f),await l.readToBuffer(w.QR.eval,0,4*f,r[io][0].p+f),await l.readToBuffer(w.QM.eval,0,4*f,r[oo][0].p+f),await l.readToBuffer(w.QO.eval,0,4*f,r[no][0].p+f),await l.readToBuffer(w.QC.eval,0,4*f,r[lo][0].p+f);const t=await Va(l,r,uo);w.lagrange1=new ol(t,c,a),p.T0=new Se(4*f),a&&a.info("··· Computing T0 evaluations");for(let t=0;t<4*s.domainSize;t++){a&&0!==t&&t%1e5==0&&a.info(` T0 evaluation ${t}/${4*s.domainSize}`);const e=w.A.getEvaluation(t),i=w.B.getEvaluation(t),o=w.C.getEvaluation(t),n=w.QL.getEvaluation(t),l=w.QR.getEvaluation(t),r=w.QM.getEvaluation(t),c=w.QO.getEvaluation(t),g=w.QC.getEvaluation(t);let f=d.zero;for(let e=0;e<s.nPublic;e++){const a=5*e*s.domainSize+s.domainSize+t,i=w.lagrange1.getEvaluation(a),o=p.A.slice(e*u,(e+1)*u);f=d.sub(f,d.mul(i,o))}const h=d.mul(e,n),_=d.mul(i,l),m=d.mul(d.mul(e,i),r),L=d.mul(o,c),b=d.add(h,d.add(_,d.add(m,d.add(L,d.add(g,f)))));p.T0.set(b,t*u)}a&&a.info("buffer T0: "+p.T0.byteLength/u);a&&a.info("··· Computing T0 ifft");m.T0=await il.fromEvaluations(p.T0,c,a),a&&a.info("T0 length: "+m.T0.length());a&&a.info("T0 degree: "+m.T0.degree());a&&a.info("··· Computing T0 / ZH");if(m.T0.divByZerofier(s.domainSize,d.one),m.T0.degree()>=2*s.domainSize-2)throw new Error(`T0 Polynomial is not well calculated (degree is ${m.T0.degree()} and must be less than ${2*s.domainSize+2}`);delete p.T0}(),a&&a.info("> Computing C1 polynomial");await async function(){let t=new pl(4,c,a);if(t.addPolynomial(0,m.A),t.addPolynomial(1,m.B),t.addPolynomial(2,m.C),t.addPolynomial(3,m.T0),m.C1=t.getPolynomial(),m.C1.degree()>=8*s.domainSize-8)throw new Error("C1 Polynomial is not well calculated")}(),a&&a.info("> Computing C1 multi exponentiation");let t=await m.C1.multiExponentiation(C,"C1");return A.addPolynomial("C1",t),0}(),delete m.T0,delete w.QL,delete w.QR,delete w.QM,delete w.QO,delete w.QC,globalThis.gc&&globalThis.gc(),a&&a.info("> ROUND 2"),await async function(){a&&a.info("> Computing challenges beta and gamma");const t=new Nn(c);t.addPolCommitment(s.C0);for(let e=0;e<s.nPublic;e++)t.addScalar(p.A.slice(e*u,e*u+u));t.addPolCommitment(A.getPolynomial("C1")),b.beta=t.getChallenge(),a&&a.info("··· challenges.beta: "+d.toString(b.beta));t.reset(),t.addScalar(b.beta),b.gamma=t.getChallenge(),a&&a.info("··· challenges.gamma: "+d.toString(b.gamma));a&&a.info("> Computing Z polynomial");await async function(){a&&a.info("··· Computing Z evaluations");let t=new Se(f),e=new Se(f);t.set(d.one,0),e.set(d.one,0);let i=d.one;for(let o=0;o<s.domainSize;o++){a&&0!==o&&o%1e5==0&&a.info(` Z evaluation ${o}/${s.domainSize}`);const n=o*u,l=d.mul(b.beta,i);let r=p.A.slice(n,n+u);r=d.add(r,l),r=d.add(r,b.gamma);let c=p.B.slice(n,n+u);c=d.add(c,d.mul(s.k1,l)),c=d.add(c,b.gamma);let g=p.C.slice(n,n+u);g=d.add(g,d.mul(s.k2,l)),g=d.add(g,b.gamma);let f=d.mul(r,d.mul(c,g)),h=p.A.slice(n,n+u);h=d.add(h,d.mul(b.beta,w.Sigma1.getEvaluation(4*o))),h=d.add(h,b.gamma);let _=p.B.slice(n,n+u);_=d.add(_,d.mul(b.beta,w.Sigma2.getEvaluation(4*o))),_=d.add(_,b.gamma);let m=p.C.slice(n,n+u);m=d.add(m,d.mul(b.beta,w.Sigma3.getEvaluation(4*o))),m=d.add(m,b.gamma);let L=d.mul(h,d.mul(_,m));f=d.mul(t.slice(n,n+u),f),t.set(f,(o+1)%s.domainSize*u),L=d.mul(e.slice(n,n+u),L),e.set(L,(o+1)%s.domainSize*u),i=d.mul(i,d.w[s.power])}e=await d.batchInverse(e);for(let a=0;a<s.domainSize;a++){const i=a*u,o=d.mul(t.slice(i,i+u),e.slice(i,i+u));t.set(o,i)}if(p.Z=t,!d.eq(t.slice(0,u),d.one))throw new Error("Copy constraints does not match");a&&a.info("··· Computing Z ifft");m.Z=await il.fromEvaluations(p.Z,c,a),a&&a.info("··· Computing Z fft");if(w.Z=await ol.fromPolynomial(m.Z,4,c,a),m.Z.blindCoefficients([b.b[9],b.b[8],b.b[7]]),m.Z.degree()>=s.domainSize+3)throw new Error("Z Polynomial is not well calculated");delete p.Z}(),a&&a.info("> Computing T1 polynomial");await async function(){a&&a.info("··· Computing T1 evaluations");p.T1=new Se(2*f),p.T1z=new Se(2*f);let t=d.one;for(let e=0;e<2*s.domainSize;e++){a&&0!==e&&e%1e5==0&&a.info(` T1 evaluation ${e}/${4*s.domainSize}`);const i=d.square(t),o=w.Z.getEvaluation(2*e),n=d.add(d.add(d.mul(b.b[7],i),d.mul(b.b[8],t)),b.b[9]),l=w.lagrange1.getEvaluation(s.domainSize+2*e);let r=d.mul(d.sub(o,d.one),l),c=d.mul(n,l);p.T1.set(r,e*u),p.T1z.set(c,e*u),t=d.mul(t,d.w[s.power+1])}a&&a.info("··· Computing T1 ifft");m.T1=await il.fromEvaluations(p.T1,c,a),m.T1.divByZerofier(s.domainSize,d.one),a&&a.info("··· Computing T1z ifft");if(m.T1z=await il.fromEvaluations(p.T1z,c,a),m.T1.add(m.T1z),m.T1.degree()>=s.domainSize+2)throw new Error("T1 Polynomial is not well calculated");delete p.T1,delete p.T1z,delete m.T1z}(),a&&a.info("> Computing T2 polynomial");await async function(){a&&a.info("··· Computing T2 evaluations");p.T2=new Se(4*f),p.T2z=new Se(4*f);let t=d.one;for(let e=0;e<4*s.domainSize;e++){a&&0!==e&&e%1e5==0&&a.info(` T2 evaluation ${e}/${4*s.domainSize}`);const i=d.square(t),o=d.mul(t,d.w[s.power]),n=d.square(o),l=w.A.getEvaluation(e),r=w.B.getEvaluation(e),c=w.C.getEvaluation(e),g=w.Z.getEvaluation(e),f=w.Z.getEvaluation((4*s.domainSize+4+e)%(4*s.domainSize)),h=d.add(d.add(d.mul(b.b[7],i),d.mul(b.b[8],t)),b.b[9]),_=d.add(d.add(d.mul(b.b[7],n),d.mul(b.b[8],o)),b.b[9]),m=w.Sigma1.getEvaluation(e),L=w.Sigma2.getEvaluation(e),y=w.Sigma3.getEvaluation(e),A=d.mul(b.beta,t);let C=d.add(l,A);C=d.add(C,b.gamma);let I=d.add(r,d.mul(A,s.k1));I=d.add(I,b.gamma);let F=d.add(c,d.mul(A,s.k2));F=d.add(F,b.gamma);let x=d.mul(d.mul(d.mul(C,I),F),g),E=d.mul(d.mul(d.mul(C,I),F),h),v=d.add(l,d.mul(b.beta,m));v=d.add(v,b.gamma);let B=d.add(r,d.mul(b.beta,L));B=d.add(B,b.gamma);let S=d.add(c,d.mul(b.beta,y));S=d.add(S,b.gamma);let P=d.mul(d.mul(d.mul(v,B),S),f),G=d.mul(d.mul(d.mul(v,B),S),_),O=d.sub(x,P),T=d.sub(E,G);p.T2.set(O,e*u),p.T2z.set(T,e*u),t=d.mul(t,d.w[s.power+2])}a&&a.info("··· Computing T2 ifft");m.T2=await il.fromEvaluations(p.T2,c,a),a&&a.info("··· Computing T2 / ZH");m.T2.divByZerofier(s.domainSize,d.one),a&&a.info("··· Computing T2z ifft");if(m.T2z=await il.fromEvaluations(p.T2z,c,a),m.T2.add(m.T2z),m.T2.degree()>=3*s.domainSize)throw new Error("T2 Polynomial is not well calculated");delete p.T2,delete p.T2z,delete m.T2z}(),a&&a.info("> Computing C2 polynomial");await async function(){let t=new pl(3,c,a);if(t.addPolynomial(0,m.Z),t.addPolynomial(1,m.T1),t.addPolynomial(2,m.T2),m.C2=t.getPolynomial(),m.C2.degree()>=9*s.domainSize)throw new Error("C2 Polynomial is not well calculated")}(),a&&a.info("> Computing C2 multi exponentiation");let e=await m.C2.multiExponentiation(C,"C2");return A.addPolynomial("C2",e),0}(),delete p.A,delete p.B,delete p.C,delete w.A,delete w.B,delete w.C,delete w.Sigma1,delete w.Sigma2,delete w.Sigma3,delete w.lagrange1,delete w.Z,globalThis.gc&&globalThis.gc(),a&&a.info("> ROUND 3"),await async function(){a&&a.info("> Computing challenge xi");const t=new Nn(c);t.addScalar(b.gamma),t.addPolCommitment(A.getPolynomial("C2")),b.xiSeed=t.getChallenge();const e=d.square(b.xiSeed);y.w8=[],y.w8[0]=d.one;for(let t=1;t<8;t++)y.w8[t]=d.mul(y.w8[t-1],s.w8);y.w4=[],y.w4[0]=d.one;for(let t=1;t<4;t++)y.w4[t]=d.mul(y.w4[t-1],s.w4);y.w3=[],y.w3[0]=d.one,y.w3[1]=s.w3,y.w3[2]=d.square(s.w3),y.S0={},y.S0.h0w8=[],y.S0.h0w8[0]=d.mul(e,b.xiSeed);for(let t=1;t<8;t++)y.S0.h0w8[t]=d.mul(y.S0.h0w8[0],y.w8[t]);y.S1={},y.S1.h1w4=[],y.S1.h1w4[0]=d.square(y.S0.h0w8[0]);for(let t=1;t<4;t++)y.S1.h1w4[t]=d.mul(y.S1.h1w4[0],y.w4[t]);y.S2={},y.S2.h2w3=[],y.S2.h2w3[0]=d.mul(y.S1.h1w4[0],e),y.S2.h2w3[1]=d.mul(y.S2.h2w3[0],y.w3[1]),y.S2.h2w3[2]=d.mul(y.S2.h2w3[0],y.w3[2]),y.S2.h3w3=[],y.S2.h3w3[0]=d.mul(y.S2.h2w3[0],s.wr),y.S2.h3w3[1]=d.mul(y.S2.h3w3[0],y.w3[1]),y.S2.h3w3[2]=d.mul(y.S2.h3w3[0],y.w3[2]),b.xi=d.mul(d.square(y.S2.h2w3[0]),y.S2.h2w3[0]),a&&a.info("··· challenges.xi: "+d.toString(b.xi));m.QL=new il(new Se(f),c,a),m.QR=new il(new Se(f),c,a),m.QM=new il(new Se(f),c,a),m.QO=new il(new Se(f),c,a),m.QC=new il(new Se(f),c,a),await l.readToBuffer(m.QL.coef,0,f,r[ao][0].p),await l.readToBuffer(m.QR.coef,0,f,r[io][0].p),await l.readToBuffer(m.QM.coef,0,f,r[oo][0].p),await l.readToBuffer(m.QO.coef,0,f,r[no][0].p),await l.readToBuffer(m.QC.coef,0,f,r[lo][0].p),a&&a.info("··· Computing evaluations");A.addEvaluation("ql",m.QL.evaluate(b.xi)),A.addEvaluation("qr",m.QR.evaluate(b.xi)),A.addEvaluation("qm",m.QM.evaluate(b.xi)),A.addEvaluation("qo",m.QO.evaluate(b.xi)),A.addEvaluation("qc",m.QC.evaluate(b.xi)),A.addEvaluation("s1",m.Sigma1.evaluate(b.xi)),A.addEvaluation("s2",m.Sigma2.evaluate(b.xi)),A.addEvaluation("s3",m.Sigma3.evaluate(b.xi)),A.addEvaluation("a",m.A.evaluate(b.xi)),A.addEvaluation("b",m.B.evaluate(b.xi)),A.addEvaluation("c",m.C.evaluate(b.xi)),A.addEvaluation("z",m.Z.evaluate(b.xi)),b.xiw=d.mul(b.xi,d.w[s.power]),A.addEvaluation("zw",m.Z.evaluate(b.xiw)),A.addEvaluation("t1w",m.T1.evaluate(b.xiw)),A.addEvaluation("t2w",m.T2.evaluate(b.xiw))}(),delete m.A,delete m.B,delete m.C,delete m.Z,delete m.T1,delete m.T2,delete m.Sigma1,delete m.Sigma2,delete m.Sigma3,delete m.QL,delete m.QR,delete m.QM,delete m.QC,delete m.QO,globalThis.gc&&globalThis.gc(),a&&a.info("> ROUND 4"),await async function(){a&&a.info("> Computing challenge alpha");const t=new Nn(c);t.addScalar(b.xiSeed),t.addScalar(A.getEvaluation("ql")),t.addScalar(A.getEvaluation("qr")),t.addScalar(A.getEvaluation("qm")),t.addScalar(A.getEvaluation("qo")),t.addScalar(A.getEvaluation("qc")),t.addScalar(A.getEvaluation("s1")),t.addScalar(A.getEvaluation("s2")),t.addScalar(A.getEvaluation("s3")),t.addScalar(A.getEvaluation("a")),t.addScalar(A.getEvaluation("b")),t.addScalar(A.getEvaluation("c")),t.addScalar(A.getEvaluation("z")),t.addScalar(A.getEvaluation("zw")),t.addScalar(A.getEvaluation("t1w")),t.addScalar(A.getEvaluation("t2w")),b.alpha=t.getChallenge(),a&&a.info("··· challenges.alpha: "+d.toString(b.alpha));a&&a.info("> Reading C0 polynomial");m.C0=new il(new Se(8*f),c,a),await l.readToBuffer(m.C0.coef,0,8*f,r[fo][0].p),a&&a.info("> Computing R0 polynomial");(function(){if(m.R0=il.lagrangePolynomialInterpolation([y.S0.h0w8[0],y.S0.h0w8[1],y.S0.h0w8[2],y.S0.h0w8[3],y.S0.h0w8[4],y.S0.h0w8[5],y.S0.h0w8[6],y.S0.h0w8[7]],[m.C0.evaluate(y.S0.h0w8[0]),m.C0.evaluate(y.S0.h0w8[1]),m.C0.evaluate(y.S0.h0w8[2]),m.C0.evaluate(y.S0.h0w8[3]),m.C0.evaluate(y.S0.h0w8[4]),m.C0.evaluate(y.S0.h0w8[5]),m.C0.evaluate(y.S0.h0w8[6]),m.C0.evaluate(y.S0.h0w8[7])],c),m.R0.degree()>7)throw new Error("R0 Polynomial is not well calculated")})(),a&&a.info("> Computing R1 polynomial");(function(){if(m.R1=il.lagrangePolynomialInterpolation([y.S1.h1w4[0],y.S1.h1w4[1],y.S1.h1w4[2],y.S1.h1w4[3]],[m.C1.evaluate(y.S1.h1w4[0]),m.C1.evaluate(y.S1.h1w4[1]),m.C1.evaluate(y.S1.h1w4[2]),m.C1.evaluate(y.S1.h1w4[3])],c),m.R1.degree()>3)throw new Error("R1 Polynomial is not well calculated")})(),a&&a.info("> Computing R2 polynomial");(function(){if(m.R2=il.lagrangePolynomialInterpolation([y.S2.h2w3[0],y.S2.h2w3[1],y.S2.h2w3[2],y.S2.h3w3[0],y.S2.h3w3[1],y.S2.h3w3[2]],[m.C2.evaluate(y.S2.h2w3[0]),m.C2.evaluate(y.S2.h2w3[1]),m.C2.evaluate(y.S2.h2w3[2]),m.C2.evaluate(y.S2.h3w3[0]),m.C2.evaluate(y.S2.h3w3[1]),m.C2.evaluate(y.S2.h3w3[2])],c),m.R2.degree()>5)throw new Error("R2 Polynomial is not well calculated")})(),a&&a.info("> Computing F polynomial");await async function(){a&&a.info("··· Computing F polynomial");m.F=il.fromPolynomial(m.C0,c,a),m.F.sub(m.R0),m.F.divByZerofier(8,b.xi);let t=il.fromPolynomial(m.C1,c,a);t.sub(m.R1),t.mulScalar(b.alpha),t.divByZerofier(4,b.xi);let e=il.fromPolynomial(m.C2,c,a);if(e.sub(m.R2),e.mulScalar(d.square(b.alpha)),e.divByZerofier(3,b.xi),e.divByZerofier(3,b.xiw),m.F.add(t),m.F.add(e),m.F.degree()>=9*s.domainSize-6)throw new Error("F Polynomial is not well calculated")}(),a&&a.info("> Computing W1 multi exponentiation");let e=await m.F.multiExponentiation(C,"W1");return A.addPolynomial("W1",e),0}(),globalThis.gc&&globalThis.gc(),a&&a.info("> ROUND 5"),await async function(){a&&a.info("> Computing challenge y");const t=new Nn(c);t.addScalar(b.alpha),t.addPolCommitment(A.getPolynomial("W1")),b.y=t.getChallenge(),a&&a.info("··· challenges.y: "+d.toString(b.y));a&&a.info("> Computing L polynomial");await async function(){a&&a.info("··· Computing L polynomial");const t=m.R0.evaluate(b.y),e=m.R1.evaluate(b.y),i=m.R2.evaluate(b.y);let o=d.sub(b.y,y.S0.h0w8[0]);for(let t=1;t<8;t++)o=d.mul(o,d.sub(b.y,y.S0.h0w8[t]));let n=d.sub(b.y,y.S1.h1w4[0]);for(let t=1;t<4;t++)n=d.mul(n,d.sub(b.y,y.S1.h1w4[t]));let l=d.sub(b.y,y.S2.h2w3[0]);for(let t=1;t<3;t++)l=d.mul(l,d.sub(b.y,y.S2.h2w3[t]));for(let t=0;t<3;t++)l=d.mul(l,d.sub(b.y,y.S2.h3w3[t]));let r=d.mul(n,l),u=d.mul(b.alpha,d.mul(o,l)),g=d.mul(d.square(b.alpha),d.mul(o,n));L.denH1=n,L.denH2=l,m.L=il.fromPolynomial(m.C0,c,a),m.L.subScalar(t),m.L.mulScalar(r);let f=il.fromPolynomial(m.C1,c,a);f.subScalar(e),f.mulScalar(u);let h=il.fromPolynomial(m.C2,c,a);h.subScalar(i),h.mulScalar(g),m.L.add(f),m.L.add(h),a&&a.info("> Computing ZT polynomial");await async function(){m.ZT=il.zerofierPolynomial([y.S0.h0w8[0],y.S0.h0w8[1],y.S0.h0w8[2],y.S0.h0w8[3],y.S0.h0w8[4],y.S0.h0w8[5],y.S0.h0w8[6],y.S0.h0w8[7],y.S1.h1w4[0],y.S1.h1w4[1],y.S1.h1w4[2],y.S1.h1w4[3],y.S2.h2w3[0],y.S2.h2w3[1],y.S2.h2w3[2],y.S2.h3w3[0],y.S2.h3w3[1],y.S2.h3w3[2]],c)}();const _=m.ZT.evaluate(b.y);if(m.F.mulScalar(_),m.L.sub(m.F),m.L.degree()>=9*s.domainSize)throw new Error("L Polynomial is not well calculated");delete p.L}(),a&&a.info("> Computing ZTS2 polynomial");await async function(){m.ZTS2=il.zerofierPolynomial([y.S1.h1w4[0],y.S1.h1w4[1],y.S1.h1w4[2],y.S1.h1w4[3],y.S2.h2w3[0],y.S2.h2w3[1],y.S2.h2w3[2],y.S2.h3w3[0],y.S2.h3w3[1],y.S2.h3w3[2]],c)}();let e=m.ZTS2.evaluate(b.y);e=d.inv(e),m.L.mulScalar(e);const i=il.fromCoefficientsArray([d.neg(b.y),d.one],c);a&&a.info("> Computing W' = L / ZTS2 polynomial");const o=m.L.divBy(i);if(o.degree()>0)throw new Error(`Degree of L(X)/(ZTS2(y)(X-y)) remainder is ${o.degree()} and should be 0`);if(m.L.degree()>=9*s.domainSize-1)throw new Error("Degree of L(X)/(ZTS2(y)(X-y)) is not correct");a&&a.info("> Computing W' multi exponentiation");let n=await m.L.multiExponentiation(C,"W2");return A.addPolynomial("W2",n),0}(),delete m.C0,delete m.C1,delete m.C2,delete m.R1,delete m.R2,delete m.F,delete m.L,delete m.ZT,delete m.ZTS2,await l.close(),globalThis.gc&&globalThis.gc(),A.addEvaluation("inv",function(){let t=b.xi;for(let e=0;e<s.power;e++)t=d.square(t);L.zh=d.sub(t,d.one),function(t,e,a,i){const o=i.Fr,n=e.length,l=o.mul(o.e(n),o.exp(e[0],n-2)),r=[];for(let i=0;i<n;i++){const r=e[(n-1)*i%n],s=o.sub(a,e[i]);t[["LiS0_"+(i+1)]]=o.mul(o.mul(l,r),s)}}(L,y.S0.h0w8,b.y,c),function(t,e,a,i){const o=i.Fr,n=e.length,l=o.mul(o.e(n),o.exp(e[0],n-2)),r=[];for(let i=0;i<n;i++){const r=e[(n-1)*i%n],s=o.sub(a,e[i]);t[["LiS1_"+(i+1)]]=o.mul(o.mul(l,r),s)}}(L,y.S1.h1w4,b.y,c),function(t,e,a,i,o,n,l){const r=l.Fr,s=[],c=r.mul(r.e(3),e[0]),d=r.sub(o,n);let u=r.mul(c,d);for(let a=0;a<3;a++){const o=e[2*a%3],n=r.sub(i,e[a]);t[["LiS2_"+(a+1)]]=r.mul(u,r.mul(o,n))}const g=r.mul(r.e(3),a[0]),f=r.sub(n,o);u=r.mul(g,f);for(let e=0;e<3;e++){const o=a[2*e%3],n=r.sub(i,a[e]);t[["LiS2_"+(e+1+3)]]=r.mul(u,r.mul(o,n))}}(L,y.S2.h2w3,y.S2.h3w3,b.y,b.xi,b.xiw,c);const e=Math.max(1,s.nPublic);let a=d.one;for(let t=0;t<e;t++)L["Li_"+(t+1)]=d.mul(d.e(s.domainSize),d.sub(b.xi,a)),a=d.mul(a,d.w[s.power]);let i=d.one;for(const t of Object.values(L))if(Array.isArray(t))for(const e of t)i=d.mul(i,e);else i=d.mul(i,t);return d.inv(i)}());let I=A.toObjectProof();I.protocol="fflonk",I.curve=c.name;let F=[];for(let t=1;t<=s.nPublic;t++){const e=t*u,a=h.slice(e,e+u);F.push(ga.fromRprLE(a))}return a&&a.info("FFLONK PROVER FINISHED"),{proof:ml(I),publicSignals:ml(F)};function x(t,e){const a=t.slice(e,e+4);return new DataView(a.buffer,a.byteOffset,a.byteLength).getUint32(0,!0)}function E(t){let e=s.nVars-s.nAdditions;if(t<e)return h.slice(t*u,t*u+u);if(t<s.nVars){const a=(t-e)*u;return _.slice(a,a+u)}return d.zero}}const{unstringifyBigInts:Ll}=fa;const{unstringifyBigInts:bl}=fa;function yl(t,e){return ga.lt(e,t.r)}function Al(t,e){return yl(t,ga.fromRprLE(e))}function Cl(t,e,a,i){const o=i.Fr,n=t.length,l=o.sub(o.exp(e,n),a),r=o.mul(o.e(n),o.exp(t[0],n-2)),s=[];for(let a=0;a<n;a++){const i=t[(n-1)*a%n],c=o.sub(e,t[a]);s[a]=o.div(l,o.mul(o.mul(r,i),c))}return s}const{unstringifyBigInts:Il}=fa;function Fl(t){let e=t.toString(16);for(;e.length<64;)e="0"+e;return e=`0x${e}`,e}var xl=Object.freeze({__proto__:null,setup:async function(t,e,a,i){i&&i.info("FFLONK SETUP STARTED"),globalThis.gc&&globalThis.gc(),i&&i.info("> Reading PTau file");const{fd:o,sections:n}=await za(e,"ptau",1);if(!n[12])throw new Error("Powers of Tau is not well prepared. Section 12 missing.");i&&i.info("> Getting curve from PTau settings");const{curve:l}=await Ho(o,n);i&&i.info("> Reading r1cs file");const{fd:r,sections:s}=await za(t,"r1cs",1),c=await pn(r,s,{loadConstraints:!1,loadCustomGates:!0});if(c.prime!==l.r)throw new Error("r1cs curve does not match powers of tau ceremony curve");const d=l.Fr,u=l.Fr.n8,g=2*l.G1.F.n8,f=2*l.G2.F.n8;let h,_={},p={},m={nVars:c.nVars,nPublic:c.nOutputs+c.nPubInputs};const w=new En;let L=new En;if(i&&i.info("> Processing FFlonk constraints"),await async function(t,e,a){for(let e=0;e<m.nPublic;e++)w.push(gl(e+1,t));const i=new _l(t,gl,fl,hl,a),o=await Va(r,s,2);let n=0;for(let t=0;t<e.nConstraints;t++){a&&0!==t&&t%5e5==0&&a.info(` processing r1cs constraints ${t}/${e.nConstraints}`);const[o,n]=i.processR1csConstraint(m,...l());w.push(...o),L.push(...n)}function l(){const t=[];return t[0]=c(),t[1]=c(),t[2]=c(),t}function c(){const t={},a=o.slice(n,n+4);n+=4;const i=new DataView(a.buffer).getUint32(0,!0),l=o.slice(n,n+(4+e.n8)*i);n+=(4+e.n8)*i;const r=new DataView(l.buffer);for(let a=0;a<i;a++){const i=r.getUint32(a*(4+e.n8),!0),o=e.F.fromRprLE(l,a*(4+e.n8)+4);t[i]=o}return t}return 0}(l.Fr,c,i),globalThis.gc&&globalThis.gc(),m.cirPower=Math.max(3,Ui(w.length+2-1)+1),m.domainSize=2**m.cirPower,n[2][0].size<(9*m.domainSize+18)*g)throw new Error("Powers of Tau is not big enough for this circuit size. Section 2 too small.");if(n[3][0].size<f)throw new Error("Powers of Tau is not well prepared. Section 3 too small.");i&&(i.info("----------------------------"),i.info(" FFLONK SETUP SETTINGS"),i.info(` Curve: ${l.name}`),i.info(` Circuit power: ${m.cirPower}`),i.info(` Domain size: ${m.domainSize}`),i.info(` Vars: ${m.nVars}`),i.info(` Public vars: ${m.nPublic}`),i.info(` Constraints: ${w.length}`),i.info(` Additions: ${L.length}`),i.info("----------------------------")),i&&i.info("> computing k1 and k2");const[b,y]=function(){let t=d.two;for(;a(t,[],m.cirPower);)d.add(t,d.one);let e=d.add(t,d.one);for(;a(e,[t],m.cirPower);)d.add(e,d.one);return[t,e];function a(t,e,a){const i=2**a;let o=d.one;for(let n=0;n<i;n++){if(d.eq(t,o))return!0;for(let a=0;a<e.length;a++)if(d.eq(t,d.mul(e[a],o)))return!0;o=d.mul(o,d.w[a])}return!1}}();i&&i.info("> computing w3");const A=function(){let t=d.e(31624),e=ga.div(3648040478639879203707734290876212514758060733402672390616367364429301415936n,ga.e(3));return d.exp(t,e)}();i&&i.info("> computing w4");const C=d.w[2];i&&i.info("> computing w8");const I=d.w[3];i&&i.info("> computing wr");const F=function(t,e){const a=e.e(467799165886069610036046866799264026481344299079011762026774533774345988080n);return e.exp(a,2**(28-t))}(m.cirPower,l.Fr);return await async function(){i&&i.info("> Writing the zkey file");const t=await Qa(a,"zkey",1,17,1<<22,1<<24);i&&i.info("··· Writing Section 1. Zkey Header");await async function(t){await qa(t,1),await t.writeULE32(Wi),await Ma(t)}(t),i&&i.info(`··· Writing Section ${Ji}. Additions`);await async function(t){await qa(t,Ji);const e=new Uint8Array(8+2*u),a=new DataView(e.buffer);for(let o=0;o<L.length;o++){i&&0!==o&&o%5e5==0&&i.info(` writing Additions: ${o}/${L.length}`);const n=L[o];a.setUint32(0,n[0],!0),a.setUint32(4,n[1],!0),e.set(n[2],8),e.set(n[3],8+u),await t.write(e)}await Ma(t)}(t),globalThis.gc&&globalThis.gc();i&&i.info(`··· Writing Section ${Xi}. A Map`);await x(t,Xi,0,"A map"),globalThis.gc&&globalThis.gc();i&&i.info(`··· Writing Section ${to}. B Map`);await x(t,to,1,"B map"),globalThis.gc&&globalThis.gc();i&&i.info(`··· Writing Section ${eo}. C Map`);await x(t,eo,2,"C map"),globalThis.gc&&globalThis.gc();i&&i.info(`··· Writing Section ${ao}. QL`);await E(t,ao,3,"QL"),globalThis.gc&&globalThis.gc();i&&i.info(`··· Writing Section ${io}. QR`);await E(t,io,4,"QR"),globalThis.gc&&globalThis.gc();i&&i.info(`··· Writing Section ${oo}. QM`);await E(t,oo,5,"QM"),globalThis.gc&&globalThis.gc();i&&i.info(`··· Writing Section ${no}. QO`);await E(t,no,6,"QO"),globalThis.gc&&globalThis.gc();i&&i.info(`··· Writing Section ${lo}. QC`);await E(t,lo,7,"QC"),globalThis.gc&&globalThis.gc();i&&i.info(`··· Writing Sections ${ro},${so},${co}. Sigma1, Sigma2 & Sigma 3`);await async function(t){const e=new Se(u*m.domainSize*3),a=new En(m.nVars),o=new En(m.nVars);let n=d.one;for(let t=0;t<m.domainSize;t++)t<w.length?(r(w[t][0],t),r(w[t][1],m.domainSize+t),r(w[t][2],2*m.domainSize+t)):t<m.domainSize-2?(r(0,t),r(0,m.domainSize+t),r(0,2*m.domainSize+t)):(e.set(n,t*u),e.set(d.mul(n,b),(m.domainSize+t)*u),e.set(d.mul(n,y),(2*m.domainSize+t)*u)),n=d.mul(n,d.w[m.cirPower]),i&&0!==t&&t%5e5==0&&i.info(` writing sigma phase1: ${t}/${w.length}`);for(let t=0;t<m.nVars;t++)void 0!==o[t]?e.set(a[t],o[t]*u):console.log("Variable not used"),i&&0!==t&&t%5e5==0&&i.info(` writing sigma phase2: ${t}/${m.nVars}`);globalThis.gc&&globalThis.gc();for(let a=0;a<3;a++){const o=0===a?ro:1===a?so:co;let n="S"+(a+1);_[n]=await il.fromEvaluations(e.slice(m.domainSize*u*a,m.domainSize*u*(a+1)),l,i),p[n]=await ol.fromPolynomial(_[n],4,l,i),await qa(t,o),await t.write(_[n].coef),await t.write(p[n].eval),await Ma(t),globalThis.gc&&globalThis.gc()}return 0;function r(t,i){let l;void 0===a[t]?o[t]=i:e.set(a[t],i*u),l=i<m.domainSize?n:i<2*m.domainSize?d.mul(n,b):d.mul(n,y),a[t]=l}}(t),globalThis.gc&&globalThis.gc();i&&i.info(`··· Writing Section ${uo}. Lagrange Polynomials`);await async function(t){await qa(t,uo);const e=Math.max(m.nPublic,1);for(let a=0;a<e;a++){let e=new Se(m.domainSize*u);e.set(d.one,a*u),await v(t,e)}await Ma(t)}(t),globalThis.gc&&globalThis.gc();i&&i.info(`··· Writing Section ${go}. Powers of Tau`);await async function(t){await qa(t,go),h=new Se((9*m.domainSize+18)*g),await o.readToBuffer(h,0,(9*m.domainSize+18)*g,n[2][0].p),await t.write(h),await Ma(t)}(t),globalThis.gc&&globalThis.gc();i&&i.info(`··· Writing Section ${fo}. C0`);await async function(t){let e=new pl(8,l,i);if(e.addPolynomial(0,_.QL),e.addPolynomial(1,_.QR),e.addPolynomial(2,_.QO),e.addPolynomial(3,_.QM),e.addPolynomial(4,_.QC),e.addPolynomial(5,_.S1),e.addPolynomial(6,_.S2),e.addPolynomial(7,_.S3),_.C0=e.getPolynomial(),_.C0.degree()>=8*m.domainSize)throw new Error("C0 Polynomial is not well calculated");await qa(t,fo),await t.write(_.C0.coef),await Ma(t)}(t),globalThis.gc&&globalThis.gc();i&&i.info(`··· Writing Section ${Yi}. FFlonk Header`);await async function(t){await qa(t,Yi);const e=l.q,a=8*(Math.floor((ga.bitLength(e)-1)/64)+1);await t.writeULE32(a),await Da(t,e,a);const i=l.r,r=8*(Math.floor((ga.bitLength(i)-1)/64)+1);let s;await t.writeULE32(r),await Da(t,i,r),await t.writeULE32(m.nVars),await t.writeULE32(m.nPublic),await t.writeULE32(m.domainSize),await t.writeULE32(L.length),await t.writeULE32(w.length),await t.write(b),await t.write(y),await t.write(A),await t.write(C),await t.write(I),await t.write(F),s=await o.read(f,n[3][0].p+f),await t.write(s);let c=await _.C0.multiExponentiation(h,"C0");await t.write(c),await Ma(t)}(t),globalThis.gc&&globalThis.gc();i&&i.info("> Writing the zkey file finished");await t.close()}(),await r.close(),await o.close(),i&&i.info("FFLONK SETUP FINISHED"),0;async function x(t,e,a,o){await qa(t,e);for(let e=0;e<w.length;e++)i&&0!==e&&e%5e5==0&&i.info(` writing witness ${o}: ${e}/${w.length}`),await t.writeULE32(w[e][a]);await Ma(t)}async function E(t,e,a,o){let n=new Se(m.domainSize*u);for(let t=0;t<w.length;t++)n.set(w[t][a],t*u),i&&0!==t&&t%5e5==0&&i.info(` writing ${o}: ${t}/${w.length}`);_[o]=await il.fromEvaluations(n,l,i),p[o]=await ol.fromPolynomial(_[o],4,l,i),await qa(t,e),await t.write(_[o].coef),await t.write(p[o].eval),await Ma(t)}async function v(t,e){const[a,i]=await il.to4T(e,m.domainSize,[],d);return await t.write(a),await t.write(i),[a,i]}},prove:wl,fullProve:async function(t,e,a,i){const o=Ll(t),n={type:"mem"};return await Qo(o,e,n),await wl(a,n,i)},verify:async function(t,e,a,i){i&&i.info("FFLONK VERIFIER STARTED"),t=bl(t),a=bl(a);const o=await Ja(t.curve),n=function(t,e){const a=e;return a.k1=t.Fr.fromObject(e.k1),a.k2=t.Fr.fromObject(e.k2),a.w=t.Fr.fromObject(e.w),a.w3=t.Fr.fromObject(e.w3),a.w4=t.Fr.fromObject(e.w4),a.w8=t.Fr.fromObject(e.w8),a.wr=t.Fr.fromObject(e.wr),a.X_2=t.G2.fromObject(e.X_2),a.C0=t.G1.fromObject(e.C0),a}(o,t),l=new qn(o,i);l.fromObjectProof(a);const r=bl(e);if(r.length!==n.nPublic)return i.error("Number of public signals does not match with vk"),!1;const s=o.Fr;if(i&&(i.info("----------------------------"),i.info(" FFLONK VERIFY SETTINGS"),i.info(` Curve: ${o.name}`),i.info(` Circuit power: ${n.power}`),i.info(` Domain size: ${2**n.power}`),i.info(` Public vars: ${n.nPublic}`),i.info("----------------------------")),i&&i.info("> Checking commitments belong to G1"),!function(t,e,a){const i=t.G1;return i.isValid(e.polynomials.C1)&&i.isValid(e.polynomials.C2)&&i.isValid(e.polynomials.W1)&&i.isValid(e.polynomials.W2)&&i.isValid(a.C0)}(o,l,n))return i&&i.error("Proof commitments are not valid"),!1;if(i&&i.info("> Checking evaluations belong to F"),!function(t,e){return Al(t,e.evaluations.ql)&&Al(t,e.evaluations.qr)&&Al(t,e.evaluations.qm)&&Al(t,e.evaluations.qo)&&Al(t,e.evaluations.qc)&&Al(t,e.evaluations.s1)&&Al(t,e.evaluations.s2)&&Al(t,e.evaluations.s3)&&Al(t,e.evaluations.a)&&Al(t,e.evaluations.b)&&Al(t,e.evaluations.c)&&Al(t,e.evaluations.z)&&Al(t,e.evaluations.zw)&&Al(t,e.evaluations.t1w)&&Al(t,e.evaluations.t2w)}(o,l))return i&&i.error("Proof evaluations are not valid."),!1;if(i&&i.info("> Checking public inputs belong to F"),!function(t,e){for(let a=0;a<e.length;a++)if(!yl(t,e[a]))return!1;return!0}(o,r))return i&&i.error("Public inputs are not valid."),!1;i&&i.info("> Computing challenges");const{challenges:c,roots:d}=function(t,e,a,i,o){const n=t.Fr,l={},r={},s=new Nn(t);s.addPolCommitment(a.C0);for(let t=0;t<i.length;t++)s.addScalar(n.e(i[t]));s.addPolCommitment(e.polynomials.C1),l.beta=s.getChallenge(),s.reset(),s.addScalar(l.beta),l.gamma=s.getChallenge(),s.reset(),s.addScalar(l.gamma),s.addPolCommitment(e.polynomials.C2);const c=s.getChallenge(),d=n.square(c);let u=[];u[1]=a.w8,u[2]=n.square(a.w8),u[3]=n.mul(u[2],a.w8),u[4]=n.mul(u[3],a.w8),u[5]=n.mul(u[4],a.w8),u[6]=n.mul(u[5],a.w8),u[7]=n.mul(u[6],a.w8);let g=[];g[1]=a.w4,g[2]=n.square(a.w4),g[3]=n.mul(g[2],a.w4);let f=[];f[1]=a.w3,f[2]=n.square(a.w3),r.S0={},r.S0.h0w8=[],r.S0.h0w8[0]=n.mul(d,c);for(let t=1;t<8;t++)r.S0.h0w8[t]=n.mul(r.S0.h0w8[0],u[t]);r.S1={},r.S1.h1w4=[],r.S1.h1w4[0]=n.square(r.S0.h0w8[0]);for(let t=1;t<4;t++)r.S1.h1w4[t]=n.mul(r.S1.h1w4[0],g[t]);r.S2={},r.S2.h2w3=[],r.S2.h2w3[0]=n.mul(r.S1.h1w4[0],d),r.S2.h2w3[1]=n.mul(r.S2.h2w3[0],f[1]),r.S2.h2w3[2]=n.mul(r.S2.h2w3[0],f[2]),r.S2.h3w3=[],r.S2.h3w3[0]=n.mul(r.S2.h2w3[0],a.wr),r.S2.h3w3[1]=n.mul(r.S2.h3w3[0],f[1]),r.S2.h3w3[2]=n.mul(r.S2.h3w3[0],f[2]),l.xi=n.mul(n.square(r.S2.h2w3[0]),r.S2.h2w3[0]),l.xiw=n.mul(l.xi,n.w[a.power]),l.xiN=l.xi,a.domainSize=1;for(let t=0;t<a.power;t++)l.xiN=n.square(l.xiN),a.domainSize*=2;s.reset(),s.addScalar(c),s.addScalar(e.evaluations.ql),s.addScalar(e.evaluations.qr),s.addScalar(e.evaluations.qm),s.addScalar(e.evaluations.qo),s.addScalar(e.evaluations.qc),s.addScalar(e.evaluations.s1),s.addScalar(e.evaluations.s2),s.addScalar(e.evaluations.s3),s.addScalar(e.evaluations.a),s.addScalar(e.evaluations.b),s.addScalar(e.evaluations.c),s.addScalar(e.evaluations.z),s.addScalar(e.evaluations.zw),s.addScalar(e.evaluations.t1w),s.addScalar(e.evaluations.t2w),l.alpha=s.getChallenge(),s.reset(),s.addScalar(l.alpha),s.addPolCommitment(e.polynomials.W1),l.y=s.getChallenge(),o&&(o.info("··· challenges.beta: "+n.toString(l.beta)),o.info("··· challenges.gamma: "+n.toString(l.gamma)),o.info("··· challenges.xi: "+n.toString(l.xi)),o.info("··· challenges.alpha: "+n.toString(l.alpha)),o.info("··· challenges.y: "+n.toString(l.y)));return{challenges:l,roots:r}}(o,l,n,r,i);i&&i.info("> Computing Zero polynomial evaluation Z_H(xi)"),c.zh=s.sub(c.xiN,s.one),c.invzh=s.inv(c.zh),i&&i.info("> Computing Lagrange evaluations");const u=await async function(t,e,a){const i=t.Fr,o=Math.max(1,a.nPublic),n=new Se(o*i.n8);let l=new Se(o*i.n8),r=i.one;for(let t=0;t<o;t++){const o=t*i.n8;n.set(i.mul(r,e.zh),o),l.set(i.mul(i.e(a.domainSize),i.sub(e.xi,r)),o),r=i.mul(r,a.w)}l=await i.batchInverse(l);let s=[];for(let t=0;t<o;t++){const e=t*i.n8;s[t+1]=i.mul(n.slice(e,e+i.n8),l.slice(e,e+i.n8))}return s}(o,c,n);i&&i.info("> Computing polynomial identities PI(X)");const g=function(t,e,a){const i=t.Fr;let o=i.zero;for(let t=0;t<e.length;t++){const n=i.e(e[t]);o=i.sub(o,i.mul(n,a[t+1]))}return o}(o,r,u);i&&i.info("> Computing r0(y)");const f=function(t,e,a,i,o){const n=i.Fr,l=Cl(a.S0.h0w8,e.y,e.xi,i);o&&o.info("··· Computing r0(y)");let r=n.zero;for(let e=0;e<8;e++){let i=[];i[1]=a.S0.h0w8[e];for(let t=2;t<8;t++)i[t]=n.mul(i[t-1],a.S0.h0w8[e]);let o=n.add(t.evaluations.ql,n.mul(t.evaluations.qr,i[1]));o=n.add(o,n.mul(t.evaluations.qo,i[2])),o=n.add(o,n.mul(t.evaluations.qm,i[3])),o=n.add(o,n.mul(t.evaluations.qc,i[4])),o=n.add(o,n.mul(t.evaluations.s1,i[5])),o=n.add(o,n.mul(t.evaluations.s2,i[6])),o=n.add(o,n.mul(t.evaluations.s3,i[7])),r=n.add(r,n.mul(o,l[e]))}return r}(l,c,d,o,i);i&&i.info("> Computing r1(y)");const h=function(t,e,a,i,o,n){const l=o.Fr,r=Cl(a.S1.h1w4,e.y,e.xi,o);n&&n.info("··· Computing T0(xi)");let s=l.mul(t.evaluations.ql,t.evaluations.a);s=l.add(s,l.mul(t.evaluations.qr,t.evaluations.b)),s=l.add(s,l.mul(t.evaluations.qm,l.mul(t.evaluations.a,t.evaluations.b))),s=l.add(s,l.mul(t.evaluations.qo,t.evaluations.c)),s=l.add(s,t.evaluations.qc),s=l.add(s,i),s=l.mul(s,e.invzh),n&&n.info("··· Computing C1(h_1ω_4^i) values");let c=l.zero;for(let e=0;e<4;e++){let i=t.evaluations.a;i=l.add(i,l.mul(a.S1.h1w4[e],t.evaluations.b));const o=l.square(a.S1.h1w4[e]);i=l.add(i,l.mul(o,t.evaluations.c)),i=l.add(i,l.mul(l.mul(o,a.S1.h1w4[e]),s)),c=l.add(c,l.mul(i,r[e]))}return c}(l,c,d,g,o,i);i&&i.info("> Computing r2(y)");const _=function(t,e,a,i,o,n,l){const r=n.Fr,s=function(t,e,a,i,o){const n=o.Fr,l=[],r=t[0].length,s=r*t.length,c=n.exp(e,s),d=n.mul(n.add(a,i),n.exp(e,r)),u=n.mul(a,i),g=n.add(n.sub(c,d),u);let f=n.mul(n.mul(n.e(r),t[0][0]),n.sub(a,i));for(let a=0;a<r;a++){const i=t[0][(r-1)*a%r],o=n.sub(e,t[0][a]),s=n.mul(f,n.mul(i,o));l[a]=n.div(g,s)}f=n.mul(n.mul(n.e(r),t[1][0]),n.sub(i,a));for(let a=0;a<r;a++){const i=t[1][(r-1)*a%r],o=n.sub(e,t[1][a]),s=n.mul(f,n.mul(i,o));l[a+r]=n.div(g,s)}return l}([a.S2.h2w3,a.S2.h3w3],e.y,e.xi,e.xiw,n);l&&l.info("··· Computing T1(xi)");let c=r.sub(t.evaluations.z,r.one);c=r.mul(c,i),c=r.mul(c,e.invzh),l&&l.info("··· Computing T2(xi)");const d=r.mul(e.beta,e.xi),u=r.add(t.evaluations.a,r.add(d,e.gamma)),g=r.add(t.evaluations.b,r.add(r.mul(d,o.k1),e.gamma)),f=r.add(t.evaluations.c,r.add(r.mul(d,o.k2),e.gamma)),h=r.mul(u,r.mul(g,r.mul(f,t.evaluations.z))),_=r.add(t.evaluations.a,r.add(r.mul(e.beta,t.evaluations.s1),e.gamma)),p=r.add(t.evaluations.b,r.add(r.mul(e.beta,t.evaluations.s2),e.gamma)),m=r.add(t.evaluations.c,r.add(r.mul(e.beta,t.evaluations.s3),e.gamma)),w=r.mul(_,r.mul(p,r.mul(m,t.evaluations.zw)));let L=r.sub(h,w);L=r.mul(L,e.invzh),l&&l.info("··· Computing C2(h_2ω_3^i) values");let b=r.zero;for(let e=0;e<3;e++){let i=r.add(t.evaluations.z,r.mul(a.S2.h2w3[e],c));i=r.add(i,r.mul(r.square(a.S2.h2w3[e]),L)),b=r.add(b,r.mul(i,s[e]))}l&&l.info("··· Computing C2(h_3ω_3^i) values");for(let e=0;e<3;e++){let i=r.add(t.evaluations.zw,r.mul(a.S2.h3w3[e],t.evaluations.t1w));i=r.add(i,r.mul(r.square(a.S2.h3w3[e]),t.evaluations.t2w)),b=r.add(b,r.mul(i,s[e+3]))}return b}(l,c,d,u[1],n,o,i);i&&i.info("> Computing F");const p=function(t,e,a,i,o){const n=t.G1,l=t.Fr;let r=l.sub(i.y,o.S0.h0w8[0]);for(let t=1;t<8;t++)r=l.mul(r,l.sub(i.y,o.S0.h0w8[t]));i.temp=r;let s=l.sub(i.y,o.S1.h1w4[0]);for(let t=1;t<4;t++)s=l.mul(s,l.sub(i.y,o.S1.h1w4[t]));let c=l.sub(i.y,o.S2.h2w3[0]);for(let t=1;t<3;t++)c=l.mul(c,l.sub(i.y,o.S2.h2w3[t]));for(let t=0;t<3;t++)c=l.mul(c,l.sub(i.y,o.S2.h3w3[t]));i.quotient1=l.mul(i.alpha,l.div(r,s)),i.quotient2=l.mul(l.square(i.alpha),l.div(r,c));let d=n.timesFr(e.polynomials.C1,i.quotient1),u=n.timesFr(e.polynomials.C2,i.quotient2);return n.add(a.C0,n.add(d,u))}(o,l,n,c,d);i&&i.info("> Computing E");const m=function(t,e,a,i,o,n,l){const r=t.G1,s=t.Fr;let c=s.mul(n,a.quotient1),d=s.mul(l,a.quotient2);return r.timesFr(r.one,s.add(o,s.add(c,d)))}(o,0,c,0,f,h,_);i&&i.info("> Computing J");const w=function(t,e,a){const i=t.G1;return i.timesFr(e.polynomials.W1,a.temp)}(o,l,c);i&&i.info("> Validate all evaluations with a pairing");const L=await async function(t,e,a,i,o,n,l){const r=t.G1;let s=r.timesFr(e.polynomials.W2,a.y);s=r.add(r.sub(r.sub(o,n),l),s);const c=t.G2.one,d=e.polynomials.W2,u=i.X_2;return await t.pairingEq(r.neg(s),c,d,u)}(o,l,c,n,p,m,w);return i&&(L?i.info("PROOF VERIFIED SUCCESSFULLY"):i.warn("Invalid Proof")),i&&i.info("FFLONK VERIFIER FINISHED"),L},exportSolidityVerifier:zn,exportSolidityCallData:async function(t,e){const a=Il(e),i=Il(t),o=await Ja(a.curve);o.G1,o.Fr;let n="";for(let t=0;t<i.length;t++)""!==n&&(n+=","),n+=Fl(i[t]);return`[${Fl(a.polynomials.C1[0])}, ${Fl(a.polynomials.C1[1])},${Fl(a.polynomials.C2[0])},${Fl(a.polynomials.C2[1])},${Fl(a.polynomials.W1[0])},${Fl(a.polynomials.W1[1])},${Fl(a.polynomials.W2[0])},${Fl(a.polynomials.W2[1])},${Fl(a.evaluations.ql)},${Fl(a.evaluations.qr)},${Fl(a.evaluations.qm)},${Fl(a.evaluations.qo)},${Fl(a.evaluations.qc)},${Fl(a.evaluations.s1)},${Fl(a.evaluations.s2)},${Fl(a.evaluations.s3)},${Fl(a.evaluations.a)},${Fl(a.evaluations.b)},${Fl(a.evaluations.c)},${Fl(a.evaluations.z)},${Fl(a.evaluations.zw)},${Fl(a.evaluations.t1w)},${Fl(a.evaluations.t2w)},${Fl(a.evaluations.inv)}],[${n}]`}});return t.fflonk=xl,t.groth16=Do,t.plonk=ul,t.powersOfTau=sn,t.r1cs=bn,t.wtns=Cn,t.zKey=Qn,Object.defineProperty(t,"__esModule",{value:!0}),t}({});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment