From bb28855001c3eeaef99fd43a208543a76372a9d6 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Tue, 22 Aug 2023 16:59:02 +0100 Subject: [PATCH 01/26] Initialize circom UI --- .../src/app/actions/dispatch.ts | 6 ++++ .../circuit-compiler/src/app/actions/index.ts | 1 + apps/circuit-compiler/src/app/app.tsx | 28 ++++++++++++++----- .../src/app/contexts/index.ts | 4 +++ .../src/app/reducers/index.ts | 18 ++++++++++++ apps/circuit-compiler/src/app/types/index.ts | 21 ++++++++++++++ 6 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 apps/circuit-compiler/src/app/actions/dispatch.ts create mode 100644 apps/circuit-compiler/src/app/actions/index.ts create mode 100644 apps/circuit-compiler/src/app/contexts/index.ts create mode 100644 apps/circuit-compiler/src/app/reducers/index.ts create mode 100644 apps/circuit-compiler/src/app/types/index.ts diff --git a/apps/circuit-compiler/src/app/actions/dispatch.ts b/apps/circuit-compiler/src/app/actions/dispatch.ts new file mode 100644 index 0000000000..a13bf90c8a --- /dev/null +++ b/apps/circuit-compiler/src/app/actions/dispatch.ts @@ -0,0 +1,6 @@ +import {Dispatch} from 'react' +import {Action} from '../types' + +export const dispatchCheckRemixd = (status: boolean) => (dispatch: Dispatch>) => { + dispatch({type: 'SET_REMIXD_CONNECTION_STATUS', payload: status}) +} diff --git a/apps/circuit-compiler/src/app/actions/index.ts b/apps/circuit-compiler/src/app/actions/index.ts new file mode 100644 index 0000000000..fd98d7d8ae --- /dev/null +++ b/apps/circuit-compiler/src/app/actions/index.ts @@ -0,0 +1 @@ +import {Dispatch} from 'react' diff --git a/apps/circuit-compiler/src/app/app.tsx b/apps/circuit-compiler/src/app/app.tsx index e922fb0bf9..5d3226e0e9 100644 --- a/apps/circuit-compiler/src/app/app.tsx +++ b/apps/circuit-compiler/src/app/app.tsx @@ -1,17 +1,31 @@ -import React, { useEffect } from 'react' +import React, {useEffect, useReducer, useState} from 'react' +import {RenderIf, RenderIfNot} from '@remix-ui/helper' +import {Alert, Button, Tabs, Tab} from 'react-bootstrap' -import { CircomPluginClient } from './services/circomPluginClient' +import {AppContext} from './contexts' +import {appInitialState, appReducer} from './reducers' +import {CircomPluginClient} from './services/circomPluginClient' function App() { + const [appState, dispatch] = useReducer(appReducer, appInitialState) + const [plugin, setPlugin] = useState(null) useEffect(() => { - new CircomPluginClient() + const plugin = new CircomPluginClient() + + setPlugin(plugin) }, []) - + + const value = { + appState, + dispatch + } + return ( -
-
+ +
+
) } -export default App \ No newline at end of file +export default App diff --git a/apps/circuit-compiler/src/app/contexts/index.ts b/apps/circuit-compiler/src/app/contexts/index.ts new file mode 100644 index 0000000000..c551d39cc1 --- /dev/null +++ b/apps/circuit-compiler/src/app/contexts/index.ts @@ -0,0 +1,4 @@ +import {createContext} from 'react' +import {IAppContext} from '../types' + +export const AppContext = createContext({} as IAppContext) diff --git a/apps/circuit-compiler/src/app/reducers/index.ts b/apps/circuit-compiler/src/app/reducers/index.ts new file mode 100644 index 0000000000..7046c976f4 --- /dev/null +++ b/apps/circuit-compiler/src/app/reducers/index.ts @@ -0,0 +1,18 @@ +import {Actions, AppState} from '../types' + +export const appInitialState: AppState = { + isRemixdConnected: null +} + +export const appReducer = (state = appInitialState, action: Actions): AppState => { + switch (action.type) { + case 'SET_REMIXD_CONNECTION_STATUS': + return { + ...state, + isRemixdConnected: action.payload + } + + default: + throw new Error() + } +} diff --git a/apps/circuit-compiler/src/app/types/index.ts b/apps/circuit-compiler/src/app/types/index.ts new file mode 100644 index 0000000000..b77a266838 --- /dev/null +++ b/apps/circuit-compiler/src/app/types/index.ts @@ -0,0 +1,21 @@ +import {Dispatch} from 'react' + +export interface IAppContext { + appState: AppState + dispatch: Dispatch +} + +export interface ActionPayloadTypes { + SET_REMIXD_CONNECTION_STATUS: boolean +} + +export interface Action { + type: T + payload: ActionPayloadTypes[T] +} + +export type Actions = {[A in keyof ActionPayloadTypes]: Action}[keyof ActionPayloadTypes] + +export interface AppState { + isRemixdConnected: boolean +} From 7773a829e798db5995cbed93e3631be61b13006c Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Mon, 28 Aug 2023 12:16:39 +0100 Subject: [PATCH 02/26] Compile circom code with play button --- libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx b/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx index a5055f794b..6ea63767d3 100644 --- a/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx +++ b/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx @@ -179,6 +179,9 @@ export const TabsUI = (props: TabsUIProps) => { } else if (tabsState.currentExt === 'sol' || tabsState.currentExt === 'yul') { await props.plugin.call('solidity', 'compile', path) _paq.push(['trackEvent', 'editor', 'clickRunFromEditor', tabsState.currentExt]) + } else if (tabsState.currentExt === 'circom') { + await props.plugin.call('circuit-compiler', 'compile', path) + _paq.push(['trackEvent', 'editor', 'clickRunFromEditor', tabsState.currentExt]) } }} > @@ -189,7 +192,7 @@ export const TabsUI = (props: TabsUIProps) => { {tabsState.currentExt === 'js' || tabsState.currentExt === 'ts' ? ( - ) : tabsState.currentExt === 'sol' || tabsState.currentExt === 'yul' ? ( + ) : tabsState.currentExt === 'sol' || tabsState.currentExt === 'yul' || tabsState.currentExt === 'circom' ? ( ) : ( From 8f8b56e326ca9974f38303da69e068acd6957738 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Wed, 30 Aug 2023 08:54:29 +0100 Subject: [PATCH 03/26] Fetch compile wasm binaries --- .../src/app/services/circomPluginClient.ts | 137 ++++++------------ 1 file changed, 47 insertions(+), 90 deletions(-) diff --git a/apps/circuit-compiler/src/app/services/circomPluginClient.ts b/apps/circuit-compiler/src/app/services/circomPluginClient.ts index f94b1317f4..c5965b4ed2 100644 --- a/apps/circuit-compiler/src/app/services/circomPluginClient.ts +++ b/apps/circuit-compiler/src/app/services/circomPluginClient.ts @@ -1,8 +1,8 @@ -import {PluginClient} from '@remixproject/plugin' -import {createClient} from '@remixproject/plugin-webview' +import { PluginClient } from '@remixproject/plugin' +import { createClient } from '@remixproject/plugin-webview' import EventManager from 'events' import pathModule from 'path' -import {parse} from 'circom_wasm' +import { parse, compile } from 'circom_wasm' export class CircomPluginClient extends PluginClient { public internalEvents: EventManager @@ -11,7 +11,7 @@ export class CircomPluginClient extends PluginClient { super() createClient(this) this.internalEvents = new EventManager() - this.methods = ['init', 'parse'] + this.methods = ['init', 'parse', 'compile'] this.onload() } @@ -30,7 +30,7 @@ export class CircomPluginClient extends PluginClient { async parse(path: string, fileContent: string): Promise { let buildFiles = { - [path]: fileContent + [path]: fileContent, } buildFiles = await this.resolveDependencies(path, fileContent, buildFiles) @@ -49,21 +49,19 @@ export class CircomPluginClient extends PluginClient { for (const label in report.labels) { if (report.labels[label].file_id === '0') { // @ts-ignore - const startPosition: {lineNumber: number; column: number} = - await this.call( - 'editor', - // @ts-ignore - 'getPositionAt', - report.labels[label].range.start - ) + const startPosition: { lineNumber: number; column: number } = await this.call( + 'editor', + // @ts-ignore + 'getPositionAt', + report.labels[label].range.start + ) // @ts-ignore - const endPosition: {lineNumber: number; column: number} = - await this.call( - 'editor', - // @ts-ignore - 'getPositionAt', - report.labels[label].range.end - ) + const endPosition: { lineNumber: number; column: number } = await this.call( + 'editor', + // @ts-ignore + 'getPositionAt', + report.labels[label].range.end + ) markers.push({ message: report.message, @@ -71,14 +69,14 @@ export class CircomPluginClient extends PluginClient { position: { start: { line: startPosition.lineNumber, - column: startPosition.column + column: startPosition.column, }, end: { line: endPosition.lineNumber, - column: endPosition.column - } + column: endPosition.column, + }, }, - file: path + file: path, }) } } @@ -97,17 +95,21 @@ export class CircomPluginClient extends PluginClient { } } - async resolveDependencies( - filePath: string, - fileContent: string, - output = {}, - depPath: string = '', - blackPath: string[] = [] - ): Promise> { + async compile(path: string): Promise { + const fileContent = await this.call('fileManager', 'readFile', path) + let buildFiles = { + [path]: fileContent, + } + + buildFiles = await this.resolveDependencies(path, fileContent, buildFiles) + const compiledOutput = compile(path, buildFiles, { prime: 'bn128' }) + + console.log('compiled wasm binaries: ', compiledOutput) + } + + async resolveDependencies(filePath: string, fileContent: string, output = {}, depPath: string = '', blackPath: string[] = []): Promise> { // extract all includes - const includes = (fileContent.match(/include ['"].*['"]/g) || []).map( - (include) => include.replace(/include ['"]/g, '').replace(/['"]/g, '') - ) + const includes = (fileContent.match(/include ['"].*['"]/g) || []).map((include) => include.replace(/include ['"]/g, '').replace(/['"]/g, '')) await Promise.all( includes.map(async (include) => { @@ -123,12 +125,8 @@ export class CircomPluginClient extends PluginClient { dependencyContent = await this.call('fileManager', 'readFile', path) } else { // if include import (path) does not exist, try to construct relative path using the original file path (current file opened in editor) - let relativePath = pathModule.resolve( - filePath.slice(0, filePath.lastIndexOf('/')), - include - ) - if (relativePath.indexOf('/') === 0) - relativePath = relativePath.slice(1) + let relativePath = pathModule.resolve(filePath.slice(0, filePath.lastIndexOf('/')), include) + if (relativePath.indexOf('/') === 0) relativePath = relativePath.slice(1) const relativePathExists = await this.call( 'fileManager', // @ts-ignore @@ -138,25 +136,13 @@ export class CircomPluginClient extends PluginClient { if (relativePathExists) { // fetch file content if include import exists as a relative path - dependencyContent = await this.call( - 'fileManager', - 'readFile', - relativePath - ) + dependencyContent = await this.call('fileManager', 'readFile', relativePath) } else { if (depPath) { // if depPath is provided, try to resolve include import from './deps' folder in remix - path = pathModule.resolve( - depPath.slice(0, depPath.lastIndexOf('/')), - include - ) + path = pathModule.resolve(depPath.slice(0, depPath.lastIndexOf('/')), include) if (path.indexOf('/') === 0) path = path.slice(1) - dependencyContent = await this.call( - 'contentImport', - 'resolveAndSave', - path, - null - ) + dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) } else { if (include.startsWith('circomlib')) { // try to resolve include import from github if it is a circomlib dependency @@ -164,55 +150,26 @@ export class CircomPluginClient extends PluginClient { const version = splitInclude[1].match(/v[0-9]+.[0-9]+.[0-9]+/g) if (version && version[0]) { - path = `https://raw.githubusercontent.com/iden3/circomlib/${ - version[0] - }/circuits/${splitInclude.slice(2).join('/')}` - dependencyContent = await this.call( - 'contentImport', - 'resolveAndSave', - path, - null - ) + path = `https://raw.githubusercontent.com/iden3/circomlib/${version[0]}/circuits/${splitInclude.slice(2).join('/')}` + dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) } else { - path = `https://raw.githubusercontent.com/iden3/circomlib/master/circuits/${splitInclude - .slice(1) - .join('/')}` - dependencyContent = await this.call( - 'contentImport', - 'resolveAndSave', - path, - null - ) + path = `https://raw.githubusercontent.com/iden3/circomlib/master/circuits/${splitInclude.slice(1).join('/')}` + dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) } } else { // If all import cases are not true, use the default import to try fetching from node_modules and unpkg - dependencyContent = await this.call( - 'contentImport', - 'resolveAndSave', - path, - null - ) + dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) } } } } // extract all includes from the dependency content - const dependencyIncludes = ( - dependencyContent.match(/include ['"].*['"]/g) || [] - ).map((include) => - include.replace(/include ['"]/g, '').replace(/['"]/g, '') - ) + const dependencyIncludes = (dependencyContent.match(/include ['"].*['"]/g) || []).map((include) => include.replace(/include ['"]/g, '').replace(/['"]/g, '')) blackPath.push(include) // recursively resolve all dependencies of the dependency if (dependencyIncludes.length > 0) { - await this.resolveDependencies( - filePath, - dependencyContent, - output, - path, - blackPath - ) + await this.resolveDependencies(filePath, dependencyContent, output, path, blackPath) output[include] = dependencyContent } else { output[include] = dependencyContent From 4a40340f4170216bd752a3bd271c56abddd70c01 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Wed, 27 Sep 2023 16:45:46 +0100 Subject: [PATCH 04/26] Compile and generate R1CS UI --- apps/circuit-compiler/project.json | 4 +- .../src/app/actions/dispatch.ts | 6 - .../circuit-compiler/src/app/actions/index.ts | 33 ++- apps/circuit-compiler/src/app/app.tsx | 81 +++++- .../src/app/components/actions.tsx | 11 + .../src/app/components/compileBtn.tsx | 53 ++++ .../src/app/components/configToggler.tsx | 36 +++ .../src/app/components/configurations.tsx | 46 ++++ .../src/app/components/container.tsx | 46 ++++ .../src/app/components/options.tsx | 41 +++ .../src/app/components/r1csBtn.tsx | 43 +++ .../src/app/components/versions.tsx | 33 +++ .../src/app/components/witness.tsx | 26 ++ .../src/app/components/witnessToggler.tsx | 36 +++ .../src/app/contexts/index.ts | 4 +- .../src/app/reducers/index.ts | 18 -- .../src/app/reducers/state.ts | 49 ++++ .../src/app/services/circomPluginClient.ts | 167 ++++++++++-- apps/circuit-compiler/src/app/types/index.ts | 29 ++- apps/circuit-compiler/src/css/app.css | 38 +++ apps/circuit-compiler/src/example/hash.circom | 27 ++ .../src/example/simple.circom | 2 + apps/circuit-compiler/src/index.html | 8 +- apps/circuit-compiler/src/snarkjs.min.js | 9 + apps/remix-ide/src/app/files/fileManager.ts | 22 +- apps/remix-ide/src/app/files/fileProvider.js | 10 +- .../src/app/tabs/locales/en/circuit.json | 13 + .../src/app/tabs/locales/en/index.js | 2 + .../src/app/tabs/locales/es/circuit.json | 13 + .../src/app/tabs/locales/fr/circuit.json | 13 + .../src/app/tabs/locales/zh/circuit.json | 14 + .../src/app/tabs/locales/zh/index.js | 2 + package.json | 3 +- yarn.lock | 245 +++++++++++++++++- 34 files changed, 1091 insertions(+), 92 deletions(-) delete mode 100644 apps/circuit-compiler/src/app/actions/dispatch.ts create mode 100644 apps/circuit-compiler/src/app/components/actions.tsx create mode 100644 apps/circuit-compiler/src/app/components/compileBtn.tsx create mode 100644 apps/circuit-compiler/src/app/components/configToggler.tsx create mode 100644 apps/circuit-compiler/src/app/components/configurations.tsx create mode 100644 apps/circuit-compiler/src/app/components/container.tsx create mode 100644 apps/circuit-compiler/src/app/components/options.tsx create mode 100644 apps/circuit-compiler/src/app/components/r1csBtn.tsx create mode 100644 apps/circuit-compiler/src/app/components/versions.tsx create mode 100644 apps/circuit-compiler/src/app/components/witness.tsx create mode 100644 apps/circuit-compiler/src/app/components/witnessToggler.tsx delete mode 100644 apps/circuit-compiler/src/app/reducers/index.ts create mode 100644 apps/circuit-compiler/src/app/reducers/state.ts create mode 100644 apps/circuit-compiler/src/example/hash.circom create mode 100644 apps/circuit-compiler/src/snarkjs.min.js create mode 100644 apps/remix-ide/src/app/tabs/locales/en/circuit.json create mode 100644 apps/remix-ide/src/app/tabs/locales/es/circuit.json create mode 100644 apps/remix-ide/src/app/tabs/locales/fr/circuit.json create mode 100644 apps/remix-ide/src/app/tabs/locales/zh/circuit.json diff --git a/apps/circuit-compiler/project.json b/apps/circuit-compiler/project.json index eb501cc21d..a8efde346c 100644 --- a/apps/circuit-compiler/project.json +++ b/apps/circuit-compiler/project.json @@ -3,7 +3,7 @@ "$schema": "../../node_modules/nx/schemas/project-schema.json", "sourceRoot": "apps/circuit-compiler/src", "projectType": "application", - "implicitDependencies": ["remixd"], + "implicitDependencies": [], "targets": { "build": { "executor": "@nrwl/webpack:webpack", @@ -17,7 +17,7 @@ "main": "apps/circuit-compiler/src/main.tsx", "polyfills": "apps/circuit-compiler/src/polyfills.ts", "tsConfig": "apps/circuit-compiler/tsconfig.app.json", - "assets": ["apps/circuit-compiler/src/profile.json"], + "assets": ["apps/circuit-compiler/src/profile.json", "apps/circuit-compiler/src/snarkjs.min.js"], "styles": ["apps/circuit-compiler/src/css/app.css"], "scripts": [], "webpackConfig": "apps/circuit-compiler/webpack.config.js" diff --git a/apps/circuit-compiler/src/app/actions/dispatch.ts b/apps/circuit-compiler/src/app/actions/dispatch.ts deleted file mode 100644 index a13bf90c8a..0000000000 --- a/apps/circuit-compiler/src/app/actions/dispatch.ts +++ /dev/null @@ -1,6 +0,0 @@ -import {Dispatch} from 'react' -import {Action} from '../types' - -export const dispatchCheckRemixd = (status: boolean) => (dispatch: Dispatch>) => { - dispatch({type: 'SET_REMIXD_CONNECTION_STATUS', payload: status}) -} diff --git a/apps/circuit-compiler/src/app/actions/index.ts b/apps/circuit-compiler/src/app/actions/index.ts index fd98d7d8ae..ed0e3f199a 100644 --- a/apps/circuit-compiler/src/app/actions/index.ts +++ b/apps/circuit-compiler/src/app/actions/index.ts @@ -1 +1,32 @@ -import {Dispatch} from 'react' +import { CircomPluginClient } from "../services/circomPluginClient" +import { Actions, AppState } from "../types" + +export const compileCircuit = async (plugin: CircomPluginClient, appState: AppState, dispatch: React.Dispatch) => { + try { + if (appState.status !== "compiling") { + dispatch({ type: 'SET_COMPILER_STATUS', payload: 'compiling' }) + await plugin.compile(appState.filePath, { version: appState.version, prime: appState.primeValue }) + dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' }) + } else { + console.log('Exisiting compilation in progress') + } + } catch (e) { + dispatch({ type: 'SET_COMPILER_STATUS', payload: 'errored' }) + console.error('Compiling failed: ', e) + } +} + +export const generateR1cs = async (plugin: CircomPluginClient, appState: AppState, dispatch: React.Dispatch) => { + try { + if (appState.status !== "generating") { + dispatch({ type: 'SET_COMPILER_STATUS', payload: 'generating' }) + await plugin.generateR1cs(appState.filePath, { version: appState.version, prime: appState.primeValue }) + dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' }) + } else { + console.log('Exisiting r1cs generation in progress') + } + } catch (e) { + dispatch({ type: 'SET_COMPILER_STATUS', payload: 'errored' }) + console.error('Generating R1CS failed: ', e) + } +} \ No newline at end of file diff --git a/apps/circuit-compiler/src/app/app.tsx b/apps/circuit-compiler/src/app/app.tsx index 5d3226e0e9..93c405c6c5 100644 --- a/apps/circuit-compiler/src/app/app.tsx +++ b/apps/circuit-compiler/src/app/app.tsx @@ -1,30 +1,93 @@ import React, {useEffect, useReducer, useState} from 'react' -import {RenderIf, RenderIfNot} from '@remix-ui/helper' -import {Alert, Button, Tabs, Tab} from 'react-bootstrap' +import {RenderIf} from '@remix-ui/helper' +import {IntlProvider} from 'react-intl' -import {AppContext} from './contexts' -import {appInitialState, appReducer} from './reducers' +import { Container } from './components/container' +import {CircuitAppContext} from './contexts' +import {appInitialState, appReducer} from './reducers/state' import {CircomPluginClient} from './services/circomPluginClient' +import { compileCircuit } from './actions' function App() { const [appState, dispatch] = useReducer(appReducer, appInitialState) const [plugin, setPlugin] = useState(null) + const [locale, setLocale] = useState<{code: string; messages: any}>({ + code: 'en', + messages: null + }) + const [isContentChanged, setIsContentChanged] = useState(false) + const [content, setNewContent] = useState("") useEffect(() => { const plugin = new CircomPluginClient() - setPlugin(plugin) + plugin.internalEvents.on('activated', () => { + // @ts-ignore + plugin.on('locale', 'localeChanged', (locale: any) => { + setLocale(locale) + }) + plugin.on('fileManager', 'currentFileChanged', (filePath) => { + if (filePath.endsWith('.circom')) { + dispatch({ type: 'SET_FILE_PATH', payload: filePath }) + } else { + dispatch({ type: 'SET_FILE_PATH', payload: '' }) + } + }) + // @ts-ignore + plugin.on('editor', 'contentChanged', async (filePath, content) => { + setIsContentChanged(true) + setNewContent(content) + }) + setPlugin(plugin) + }) }, []) + useEffect(() => { + if (isContentChanged) { + (async () => { + if (appState.autoCompile) await compileCircuit(plugin, appState, dispatch) + })() + setIsContentChanged(false) + setSignalInput() + } + }, [appState.autoCompile, isContentChanged]) + + useEffect(() => { + if (plugin) { + setCurrentLocale() + } + }, [plugin]) + + const setCurrentLocale = async () => { + // @ts-ignore + const currentLocale = await plugin.call('locale', 'currentLocale') + + setLocale(currentLocale) + } + + const setSignalInput = () => { + const signalMatcher = /([a-z$_][a-z0-9$_]*)(\.[a-z$_][a-z0-9$_]*)*(\[\d+\])?/g + const signals = content.match(signalMatcher) + + console.log('signals: ', signals) + } + const value = { appState, - dispatch + dispatch, + plugin } return ( - -
-
+
+ + + + + + + +
) } diff --git a/apps/circuit-compiler/src/app/components/actions.tsx b/apps/circuit-compiler/src/app/components/actions.tsx new file mode 100644 index 0000000000..2dca59f985 --- /dev/null +++ b/apps/circuit-compiler/src/app/components/actions.tsx @@ -0,0 +1,11 @@ +import { CompileBtn } from "./compileBtn"; +import { R1CSBtn } from "./r1csBtn"; + +export function CircuitActions () { + return ( +
+ + +
+ ) +} \ No newline at end of file diff --git a/apps/circuit-compiler/src/app/components/compileBtn.tsx b/apps/circuit-compiler/src/app/components/compileBtn.tsx new file mode 100644 index 0000000000..3f131224e7 --- /dev/null +++ b/apps/circuit-compiler/src/app/components/compileBtn.tsx @@ -0,0 +1,53 @@ +import { CustomTooltip, RenderIf, RenderIfNot, extractNameFromKey } from "@remix-ui/helper"; +import { useContext } from "react"; +import { CircuitAppContext } from "../contexts"; +import { FormattedMessage } from "react-intl"; +import { compileCircuit } from "../actions"; + +export function CompileBtn () { + const { plugin, appState, dispatch } = useContext(CircuitAppContext) + + + + return ( + + ) +} \ No newline at end of file diff --git a/apps/circuit-compiler/src/app/components/configToggler.tsx b/apps/circuit-compiler/src/app/components/configToggler.tsx new file mode 100644 index 0000000000..1a6c8d3e2f --- /dev/null +++ b/apps/circuit-compiler/src/app/components/configToggler.tsx @@ -0,0 +1,36 @@ +import { useState } from "react" +import { FormattedMessage } from "react-intl" +import { RenderIf, RenderIfNot } from "@remix-ui/helper" + +export function ConfigToggler ({ children }: { children: JSX.Element }) { + const [toggleExpander, setToggleExpander] = useState(false) + + const toggleConfigurations = () => { + setToggleExpander(!toggleExpander) + } + + return ( +
+
+
+ +
+
+ + + + + + + + +
+
+ + { children } + +
+ ) +} \ No newline at end of file diff --git a/apps/circuit-compiler/src/app/components/configurations.tsx b/apps/circuit-compiler/src/app/components/configurations.tsx new file mode 100644 index 0000000000..52f2abb5ff --- /dev/null +++ b/apps/circuit-compiler/src/app/components/configurations.tsx @@ -0,0 +1,46 @@ +import { CustomTooltip } from "@remix-ui/helper" +import { useContext } from "react" +import { FormattedMessage } from "react-intl" +import { CircuitAppContext } from "../contexts" +import { PrimeValue } from "../types" + +export function Configurations () { + const { appState, dispatch } = useContext(CircuitAppContext) + + const handlePrimeChange = (value: string) => { + dispatch({ type: 'SET_PRIME_VALUE', payload: value as PrimeValue }) + } + + return ( +
+
+
+ + {'To choose the prime number to use to generate the circuit. Receives the name of the curve (bn128, bls12381, goldilocks) [default: bn128]'}} + > +
+ +
+
+
+
+
+ ) +} \ No newline at end of file diff --git a/apps/circuit-compiler/src/app/components/container.tsx b/apps/circuit-compiler/src/app/components/container.tsx new file mode 100644 index 0000000000..5eb1d690a6 --- /dev/null +++ b/apps/circuit-compiler/src/app/components/container.tsx @@ -0,0 +1,46 @@ +import { useContext } from 'react' +import { CustomTooltip, RenderIf } from '@remix-ui/helper' +import {FormattedMessage} from 'react-intl' +import { CircuitAppContext } from '../contexts' +import { CompileOptions } from './options' +import { VersionList } from './versions' +import { ConfigToggler } from './configToggler' +import { Configurations } from './configurations' +import { CircuitActions } from './actions' +import { WitnessToggler } from './witnessToggler' +import { WitnessSection } from './witness' + +export function Container () { + const circuitApp = useContext(CircuitAppContext) + + const showCompilerLicense = (message = 'License not available') => { + // @ts-ignore + circuitApp.plugin.call('notification', 'modal', { id: 'modal_circuit_compiler_license', title: 'Compiler License', message }) + } + + return ( +
+
+
+
+ + + showCompilerLicense()}> + + + + + + + + + + +
+
+
+
+ ) +} \ No newline at end of file diff --git a/apps/circuit-compiler/src/app/components/options.tsx b/apps/circuit-compiler/src/app/components/options.tsx new file mode 100644 index 0000000000..c02854eb7f --- /dev/null +++ b/apps/circuit-compiler/src/app/components/options.tsx @@ -0,0 +1,41 @@ +import { useContext } from 'react' +import {FormattedMessage} from 'react-intl' +import { CircuitAppContext } from '../contexts' + +export function CompileOptions () { + const { appState, dispatch } = useContext(CircuitAppContext) + const handleCircuitAutoCompile = (value: boolean) => { + dispatch({ type: 'SET_AUTO_COMPILE', payload: value }) + } + + return ( +
+
+ handleCircuitAutoCompile(e.target.checked)} + title="Auto compile" + checked={appState.autoCompile} + id="autoCompileCircuit" + /> + +
+
+ + +
+
+ ) +} \ No newline at end of file diff --git a/apps/circuit-compiler/src/app/components/r1csBtn.tsx b/apps/circuit-compiler/src/app/components/r1csBtn.tsx new file mode 100644 index 0000000000..e1444c74c7 --- /dev/null +++ b/apps/circuit-compiler/src/app/components/r1csBtn.tsx @@ -0,0 +1,43 @@ +import { CustomTooltip, RenderIf, RenderIfNot } from "@remix-ui/helper"; +import { useContext } from "react"; +import { CircuitAppContext } from "../contexts"; +import { FormattedMessage } from "react-intl"; +import { generateR1cs } from "../actions"; + +export function R1CSBtn () { + const { plugin, appState, dispatch } = useContext(CircuitAppContext) + + return ( + + ) +} \ No newline at end of file diff --git a/apps/circuit-compiler/src/app/components/versions.tsx b/apps/circuit-compiler/src/app/components/versions.tsx new file mode 100644 index 0000000000..e4e095c26c --- /dev/null +++ b/apps/circuit-compiler/src/app/components/versions.tsx @@ -0,0 +1,33 @@ +import { RenderIf } from "@remix-ui/helper"; +import { useContext } from "react"; +import { CircuitAppContext } from "../contexts"; + +export function VersionList () { + const { appState, dispatch } = useContext(CircuitAppContext) + + const handleVersionSelect = (version: string) => { + dispatch({ type: 'SET_COMPILER_VERSION', payload: version }) + } + + const versionList = Object.keys(appState.versionList) + + return ( + + ) +} diff --git a/apps/circuit-compiler/src/app/components/witness.tsx b/apps/circuit-compiler/src/app/components/witness.tsx new file mode 100644 index 0000000000..3b87fc5562 --- /dev/null +++ b/apps/circuit-compiler/src/app/components/witness.tsx @@ -0,0 +1,26 @@ +import { CustomTooltip } from "@remix-ui/helper"; +import { FormattedMessage } from "react-intl"; + +export function WitnessSection () { + return ( +
+
+
+ + {'To choose the prime number to use to generate the circuit. Receives the name of the curve (bn128, bls12381, goldilocks) [default: bn128]'}} + > +
+ +
+
+
+
+
+ ) +} \ No newline at end of file diff --git a/apps/circuit-compiler/src/app/components/witnessToggler.tsx b/apps/circuit-compiler/src/app/components/witnessToggler.tsx new file mode 100644 index 0000000000..3910b01c1b --- /dev/null +++ b/apps/circuit-compiler/src/app/components/witnessToggler.tsx @@ -0,0 +1,36 @@ +import { useState } from "react" +import { FormattedMessage } from "react-intl" +import { RenderIf, RenderIfNot } from "@remix-ui/helper" + +export function WitnessToggler ({ children }: { children: JSX.Element }) { + const [toggleExpander, setToggleExpander] = useState(false) + + const toggleConfigurations = () => { + setToggleExpander(!toggleExpander) + } + + return ( +
+
+
+ +
+
+ + + + + + + + +
+
+ + { children } + +
+ ) +} \ No newline at end of file diff --git a/apps/circuit-compiler/src/app/contexts/index.ts b/apps/circuit-compiler/src/app/contexts/index.ts index c551d39cc1..45fe6d3aeb 100644 --- a/apps/circuit-compiler/src/app/contexts/index.ts +++ b/apps/circuit-compiler/src/app/contexts/index.ts @@ -1,4 +1,4 @@ import {createContext} from 'react' -import {IAppContext} from '../types' +import {ICircuitAppContext} from '../types' -export const AppContext = createContext({} as IAppContext) +export const CircuitAppContext = createContext({} as ICircuitAppContext) diff --git a/apps/circuit-compiler/src/app/reducers/index.ts b/apps/circuit-compiler/src/app/reducers/index.ts deleted file mode 100644 index 7046c976f4..0000000000 --- a/apps/circuit-compiler/src/app/reducers/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -import {Actions, AppState} from '../types' - -export const appInitialState: AppState = { - isRemixdConnected: null -} - -export const appReducer = (state = appInitialState, action: Actions): AppState => { - switch (action.type) { - case 'SET_REMIXD_CONNECTION_STATUS': - return { - ...state, - isRemixdConnected: action.payload - } - - default: - throw new Error() - } -} diff --git a/apps/circuit-compiler/src/app/reducers/state.ts b/apps/circuit-compiler/src/app/reducers/state.ts new file mode 100644 index 0000000000..3d15f79446 --- /dev/null +++ b/apps/circuit-compiler/src/app/reducers/state.ts @@ -0,0 +1,49 @@ +import {Actions, AppState} from '../types' +import { compiler_list } from 'circom_wasm' + +export const appInitialState: AppState = { + version: compiler_list.latest, + versionList: compiler_list.wasm_builds, + filePath: "", + status: "idle", + primeValue: "bn128", + autoCompile: false +} + +export const appReducer = (state = appInitialState, action: Actions): AppState => { + switch (action.type) { + + case 'SET_COMPILER_VERSION': + return { + ...state, + version: action.payload + } + + case 'SET_FILE_PATH': + return { + ...state, + filePath: action.payload + } + + case 'SET_COMPILER_STATUS': + return { + ...state, + status: action.payload + } + + case 'SET_PRIME_VALUE': + return { + ...state, + primeValue: action.payload + } + + case 'SET_AUTO_COMPILE': + return { + ...state, + autoCompile: action.payload + } + + default: + throw new Error() + } +} diff --git a/apps/circuit-compiler/src/app/services/circomPluginClient.ts b/apps/circuit-compiler/src/app/services/circomPluginClient.ts index c5965b4ed2..3f051cc23f 100644 --- a/apps/circuit-compiler/src/app/services/circomPluginClient.ts +++ b/apps/circuit-compiler/src/app/services/circomPluginClient.ts @@ -2,10 +2,17 @@ import { PluginClient } from '@remixproject/plugin' import { createClient } from '@remixproject/plugin-webview' import EventManager from 'events' import pathModule from 'path' -import { parse, compile } from 'circom_wasm' +// @ts-ignore +import { parse, compile, generate_witness, generate_r1cs, compiler_list } from '../../../pkg' +import { extractNameFromKey, extractParentFromKey } from '@remix-ui/helper' +import { CompilationConfig } from '../types' export class CircomPluginClient extends PluginClient { public internalEvents: EventManager + private _compilationConfig: CompilationConfig = { + version: "2.1.5", + prime: "bn128" + } constructor() { super() @@ -26,6 +33,8 @@ export class CircomPluginClient extends PluginClient { this.parse(path, fileContent) } }) + + this.internalEvents.emit('activated') } async parse(path: string, fileContent: string): Promise { @@ -39,6 +48,8 @@ export class CircomPluginClient extends PluginClient { try { const result = JSON.parse(parsedOutput) + console.log('result: ', result) + if (result.length === 0) { // @ts-ignore await this.call('editor', 'clearErrorMarkers', [path]) @@ -95,16 +106,128 @@ export class CircomPluginClient extends PluginClient { } } - async compile(path: string): Promise { + async compile(path: string, compilationConfig?: CompilationConfig): Promise { + if (compilationConfig) { + const { prime, version } = compilationConfig + + if ((prime !== "bn128") && (prime !== "bls12381") && (prime !== "goldilocks")) throw new Error('Invalid prime value') + if (!compiler_list.versions.includes(version)) throw new Error("Unsupported compiler version") + this._compilationConfig.prime = prime + this._compilationConfig.version = version + } const fileContent = await this.call('fileManager', 'readFile', path) let buildFiles = { - [path]: fileContent, + [path]: fileContent } buildFiles = await this.resolveDependencies(path, fileContent, buildFiles) - const compiledOutput = compile(path, buildFiles, { prime: 'bn128' }) + const compiledOutput = compile(path, buildFiles, { prime: this._compilationConfig.prime }) + + console.log('compiledOutput: ', compiledOutput) + console.log('compiledOutput.program: ', compiledOutput.program()) + console.log('compiledOutput.input_signals: ', compiledOutput.input_signals("Semaphore")) + + // if (compiledOutput.length < 1) { + // throw new Error("Compilation failed! See parsing errors.") + // } else { + // const fileName = extractNameFromKey(path) + // const writePath = extractParentFromKey(path) + "/.bin/" + fileName.replace('circom', 'wasm') + + // // @ts-ignore + // await this.call('fileManager', 'writeFile', writePath, new Uint8Array(compiledOutput), true) + // console.log('compilation successful!') + // } + // @ts-ignore + // const buffer = await this.call('fileManager', 'readFile', writePath, true) + // // @ts-ignore + // const dataRead = new Uint8Array(buffer) + // const witness = await generate_witness(dataRead, '{ "a": "5", "b": "77" }') + // const witness = await generate_witness(compiledOutput, '{ "identityTrapdoor": "12656283236575022300303467601783819380815431272685589718060054649894766174337", "identityNullifier": "15178877681550417450385541477607788220584140707925739215609273992582659710290", "treePathIndices": "0", "treeSiblings": "1", "externalNullifier": "5df6e0e3480d6fbc32925076897ec6b9b935d75ae8f4d9f4858a426f8f6a4ab": "signalHash": "[85, 139, 239, 32, 221, 194, 165, 19, 20, 52, 104, 144, 41, 16, 40, 204, 171, 245, 198, 77, 94, 143, 30, 112, 105, 165, 33, 15, 62, 156, 18, 118]"}') + + // const ptau_final = "https://ipfs-cluster.ethdevops.io/ipfs/QmTiT4eiYz5KF7gQrDsgfCSTRv3wBPYJ4bRN1MmTRshpnW"; + // const r1cs_ipfs = "http://127.0.0.1:8081/ipfs/QmVzKPbmyuaTUjoLqWEA5wPAMkUqe4t6WYKHeeC9Dot4ds"; + // const r1cs_ipfs1 = "http://127.0.0.1:8081/ipfs/QmXP1BC2bc8n1zPnexPoRpFCEDoG9QZc3yZn5Wik5w2TAm"; + + // const buff = await fetch(r1cs_ipfs1).then( function(res) { + // return res.arrayBuffer(); + // }).then(function (ab) { + // return new Uint8Array(ab); + // }); + + // console.log('r1cs_buff: ', buff) + // // const wasm = "http://127.0.0.1:8081/ipfs/QmUbpEvHHKaHEqYLjhn93S8rEsUGeqiTYgRjGPk7g8tBbz"; + // const zkey_0 = { type: "mem" }; + // const zkey_1 = { type: "mem" }; + // const zkey_final = { type: "mem" }; + + // console.log('newZkey') + // // @ts-ignore + // await snarkjs.zKey.newZKey(r1cs, ptau_final, zkey_0); + + // console.log('contribute') + // // @ts-ignore + // await snarkjs.zKey.contribute(zkey_0, zkey_1, "first_contribution", "entropy_QmbMk4ksBYLQzJ6TiZfzaALF8W11xvB8Wz6a2GrG9oDrXW"); + + // console.log('beacon') + // // @ts-ignore + // await snarkjs.zKey.beacon(zkey_1, zkey_final, "B3", "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20", 10); + + // console.log('verifyFromR1cs') + // // @ts-ignore + // const verifyFromR1csResult = await snarkjs.zKey.verifyFromR1cs(r1cs, ptau_final, zkey_final); + // console.assert(verifyFromR1csResult); + + // console.log('verifyFromInit') + // // @ts-ignore + // const verifyFromInit = await snarkjs.zKey.verifyFromInit(zkey_0, ptau_final, zkey_final); + // console.assert(verifyFromInit); + + // console.log('exportVerificationKey') + // // @ts-ignore + // const vKey = await snarkjs.zKey.exportVerificationKey(zkey_final) - console.log('compiled wasm binaries: ', compiledOutput) + // console.log('vKey: ', vKey) + + // const templates = { + // groth16: await remix.call('fileManager', 'readFile', './zk/templates/groth16_verifier.sol.ejs') + // } + // const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates) + + // await remix.call('fileManager', 'writeFile', './zk/build/zk_verifier.sol', solidityContract) + + // console.log('buffer', (zkey_final as any).data.length) + // await remix.call('fileManager', 'writeFile', './zk/build/zk_setup.txt', JSON.stringify(Array.from(((zkey_final as any).data)))) + + // console.log('setup done.') + } + + async generateR1cs (path: string, compilationConfig?: CompilationConfig): Promise { + if (compilationConfig) { + const { prime, version } = compilationConfig + + if ((prime !== "bn128") && (prime !== "bls12381") && (prime !== "goldilocks")) throw new Error('Invalid prime value') + if (!compiler_list.versions.includes(version)) throw new Error("Unsupported compiler version") + this._compilationConfig.prime = prime + this._compilationConfig.version = version + } + const fileContent = await this.call('fileManager', 'readFile', path) + let buildFiles = { + [path]: fileContent + } + + buildFiles = await this.resolveDependencies(path, fileContent, buildFiles) + const r1cs = generate_r1cs(path, buildFiles, { prime: this._compilationConfig.prime }) + + if (r1cs.length < 1) { + throw new Error("R1cs generation failed! See parsing errors.") + } else { + const fileName = extractNameFromKey(path) + const writePath = extractParentFromKey(path) + "/.bin/" + fileName.replace('circom', 'r1cs') + + // @ts-ignore + await this.call('fileManager', 'writeFile', writePath, new Uint8Array(r1cs), true) + console.log('R1CS generation successful!') + } } async resolveDependencies(filePath: string, fileContent: string, output = {}, depPath: string = '', blackPath: string[] = []): Promise> { @@ -138,24 +261,24 @@ export class CircomPluginClient extends PluginClient { // fetch file content if include import exists as a relative path dependencyContent = await this.call('fileManager', 'readFile', relativePath) } else { - if (depPath) { - // if depPath is provided, try to resolve include import from './deps' folder in remix - path = pathModule.resolve(depPath.slice(0, depPath.lastIndexOf('/')), include) - if (path.indexOf('/') === 0) path = path.slice(1) - dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) + if (include.startsWith('circomlib')) { + // try to resolve include import from github if it is a circomlib dependency + const splitInclude = include.split('/') + const version = splitInclude[1].match(/v[0-9]+.[0-9]+.[0-9]+/g) + + if (version && version[0]) { + path = `https://raw.githubusercontent.com/iden3/circomlib/${version[0]}/circuits/${splitInclude.slice(2).join('/')}` + dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) + } else { + path = `https://raw.githubusercontent.com/iden3/circomlib/master/circuits/${splitInclude.slice(1).join('/')}` + dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) + } } else { - if (include.startsWith('circomlib')) { - // try to resolve include import from github if it is a circomlib dependency - const splitInclude = include.split('/') - const version = splitInclude[1].match(/v[0-9]+.[0-9]+.[0-9]+/g) - - if (version && version[0]) { - path = `https://raw.githubusercontent.com/iden3/circomlib/${version[0]}/circuits/${splitInclude.slice(2).join('/')}` - dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) - } else { - path = `https://raw.githubusercontent.com/iden3/circomlib/master/circuits/${splitInclude.slice(1).join('/')}` - dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) - } + if (depPath) { + // if depPath is provided, try to resolve include import from './deps' folder in remix + path = pathModule.resolve(depPath.slice(0, depPath.lastIndexOf('/')), include) + if (path.indexOf('/') === 0) path = path.slice(1) + dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) } else { // If all import cases are not true, use the default import to try fetching from node_modules and unpkg dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) diff --git a/apps/circuit-compiler/src/app/types/index.ts b/apps/circuit-compiler/src/app/types/index.ts index b77a266838..6165413668 100644 --- a/apps/circuit-compiler/src/app/types/index.ts +++ b/apps/circuit-compiler/src/app/types/index.ts @@ -1,14 +1,21 @@ +import { compiler_list } from 'circom_wasm' import {Dispatch} from 'react' +import { CircomPluginClient } from '../services/circomPluginClient' -export interface IAppContext { +export type CompilerStatus = "compiling" | "generating" | "idle" | "errored" +export interface ICircuitAppContext { appState: AppState - dispatch: Dispatch + dispatch: Dispatch, + plugin: CircomPluginClient } export interface ActionPayloadTypes { - SET_REMIXD_CONNECTION_STATUS: boolean + SET_COMPILER_VERSION: string, + SET_FILE_PATH: string, + SET_COMPILER_STATUS: CompilerStatus, + SET_PRIME_VALUE: PrimeValue, + SET_AUTO_COMPILE: boolean } - export interface Action { type: T payload: ActionPayloadTypes[T] @@ -17,5 +24,17 @@ export interface Action { export type Actions = {[A in keyof ActionPayloadTypes]: Action
}[keyof ActionPayloadTypes] export interface AppState { - isRemixdConnected: boolean + version: string, + versionList: typeof compiler_list.wasm_builds, + filePath: string, + status: CompilerStatus, + primeValue: PrimeValue, + autoCompile: boolean +} + +export type CompilationConfig = { + prime: PrimeValue, + version: string } + +export type PrimeValue = "bn128" | "bls12381" | "goldilocks" \ No newline at end of file diff --git a/apps/circuit-compiler/src/css/app.css b/apps/circuit-compiler/src/css/app.css index e69de29bb2..523232bded 100644 --- a/apps/circuit-compiler/src/css/app.css +++ b/apps/circuit-compiler/src/css/app.css @@ -0,0 +1,38 @@ +body { + font-size : .8rem; +} +.circuit_section { + padding: 12px 24px 16px; +} +.circuit_label { + margin-bottom: 2px; + font-size: 11px; + line-height: 12px; + text-transform: uppercase; +} +.circuit_warnings_box { + display: flex; + align-items: center; +} +.circuit_warnings_box label { + margin: 0; +} +.circuit_config_section:hover { + cursor: pointer; +} +.circuit_config_section { + font-size: 1rem; +} +.circuit_config { + display: flex; + align-items: center; +} +.circuit_config label { + margin: 0; +} +.circuit_inner_label { + margin-bottom: 2px; + font-size: 11px; + line-height: 12px; + text-transform: uppercase; + } \ No newline at end of file diff --git a/apps/circuit-compiler/src/example/hash.circom b/apps/circuit-compiler/src/example/hash.circom new file mode 100644 index 0000000000..5c251a05cf --- /dev/null +++ b/apps/circuit-compiler/src/example/hash.circom @@ -0,0 +1,27 @@ +pragma circom 2.1.4; + +include "circomlib/poseidon.circom"; +// include "https://github.com/0xPARC/circom-secp256k1/blob/master/circuits/bigint.circom"; + +template Example () { + signal input a; + signal input b; + signal output c; + + var unused = 4; + c <== a * b; + assert(a > 2); + + component hash = Poseidon(2); + hash.inputs[0] <== a; + hash.inputs[1] <== b; + + log("hash", hash.out); +} + +component main { public [ a ] } = Example(); + +/* INPUT = { + "a": "5", + "b": "77" +} */ \ No newline at end of file diff --git a/apps/circuit-compiler/src/example/simple.circom b/apps/circuit-compiler/src/example/simple.circom index 9a2120df7a..d00b6b1332 100644 --- a/apps/circuit-compiler/src/example/simple.circom +++ b/apps/circuit-compiler/src/example/simple.circom @@ -4,7 +4,9 @@ template Multiplier2() { signal input a; signal input b; signal output c; + signal output d; c <== a*b; + d <== c*b; } component main = Multiplier2(); diff --git a/apps/circuit-compiler/src/index.html b/apps/circuit-compiler/src/index.html index adb93d90f1..9ce64d34c3 100644 --- a/apps/circuit-compiler/src/index.html +++ b/apps/circuit-compiler/src/index.html @@ -6,10 +6,14 @@ - - + + +
+ + diff --git a/apps/circuit-compiler/src/snarkjs.min.js b/apps/circuit-compiler/src/snarkjs.min.js new file mode 100644 index 0000000000..03f31e305f --- /dev/null +++ b/apps/circuit-compiler/src/snarkjs.min.js @@ -0,0 +1,9 @@ +var snarkjs=function(t){"use strict";const a=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4];function e(t,a){return a&&10!=a?16==a?"0x"==t.slice(0,2)?BigInt(t):BigInt("0x"+t):void 0:BigInt(t)}const o=e;function i(t){const e=t.toString(16);return 4*(e.length-1)+a[parseInt(e[0],16)]}function n(t){return BigInt(t)>BigInt(a)}const r=c,d=s;function u(t){return(BigInt(t)&BigInt(1))==BigInt(1)}function _(t){let a=BigInt(t);const e=[];for(;a;)a&BigInt(1)?e.push(1):e.push(0),a>>=BigInt(1);return e}function g(t){if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("Number too big");return Number(t)}function f(t,a){return BigInt(t)+BigInt(a)}function h(t,a){return BigInt(t)-BigInt(a)}function p(t){return-BigInt(t)}function m(t,a){return BigInt(t)*BigInt(a)}function L(t,a){return BigInt(t)**BigInt(a)}function b(t,a){return BigInt(t)/BigInt(a)}function w(t,a){return BigInt(t)%BigInt(a)}function y(t,a){return BigInt(t)==BigInt(a)}function A(t,a){return BigInt(t)>BigInt(a)}function C(t,a){return BigInt(t)>=BigInt(a)}function F(t,a){return BigInt(t)&BigInt(a)}function x(t,a,e,o){const i="0000000"+e.toString(16),n=new Uint32Array(t.buffer,t.byteOffset+a,o/4),l=1+(4*(i.length-7)-1>>5);for(let t=0;t>5);for(let t=0;tn[n.length-a-1]=t.toString(16).padStart(8,"0"))),e(n.join(""),16)}function E(t,a,o){o=o||t.byteLength,a=a||0;const i=new DataView(t.buffer,t.byteOffset+a,o),n=new Array(o/4);for(let t=0;t>=BigInt(1)}return e},bits:_,toNumber:g,toArray:function(t,a){const e=[];let o=BigInt(t);for(a=BigInt(a);o;)e.unshift(Number(o%a)),o/=a;return e},add:f,sub:h,neg:p,mul:m,square:function(t){return BigInt(t)*BigInt(t)},pow:L,exp:function(t,a){return BigInt(t)**BigInt(a)},abs:function(t){return BigInt(t)>=0?BigInt(t):-BigInt(t)},div:b,mod:w,eq:y,neq:function(t,a){return BigInt(t)!=BigInt(a)},lt:function(t,a){return BigInt(t)=0;e--)i=t.square(i),o[e]&&(i=t.mul(i,a));return i}function z(t){if(t.m%2==1)if(y(w(t.p,4),1))if(y(w(t.p,8),1))if(y(w(t.p,16),1))!function(t){t.sqrt_q=L(t.p,t.m),t.sqrt_s=0,t.sqrt_t=h(t.sqrt_q,1);for(;!u(t.sqrt_t);)t.sqrt_s=t.sqrt_s+1,t.sqrt_t=b(t.sqrt_t,2);let a=t.one;for(;t.eq(a,t.one);){const e=t.random();t.sqrt_z=t.pow(e,t.sqrt_t),a=t.pow(t.sqrt_z,2**(t.sqrt_s-1))}t.sqrt_tm1d2=b(h(t.sqrt_t,1),2),t.sqrt=function(t){const a=this;if(a.isZero(t))return a.zero;let e=a.pow(t,a.sqrt_tm1d2);const o=a.pow(a.mul(a.square(e),t),2**(a.sqrt_s-1));if(a.eq(o,a.negone))return null;let i=a.sqrt_s,n=a.mul(t,e),l=a.mul(n,e),c=a.sqrt_z;for(;!a.eq(l,a.one);){let t=a.square(l),o=1;for(;!a.eq(t,a.one);)t=a.square(t),o++;e=c;for(let t=0;t>>0,t[i]=(t[i]^t[a])>>>0,t[i]=(t[i]<<16|t[i]>>>16&65535)>>>0,t[o]=t[o]+t[i]>>>0,t[e]=(t[e]^t[o])>>>0,t[e]=(t[e]<<12|t[e]>>>20&4095)>>>0,t[a]=t[a]+t[e]>>>0,t[i]=(t[i]^t[a])>>>0,t[i]=(t[i]<<8|t[i]>>>24&255)>>>0,t[o]=t[o]+t[i]>>>0,t[e]=(t[e]^t[o])>>>0,t[e]=(t[e]<<7|t[e]>>>25&127)>>>0}class M{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 f(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 a=0;a<10;a++)T(t=this.buff,0,4,8,12),T(t,1,5,9,13),T(t,2,6,10,14),T(t,3,7,11,15),T(t,0,5,10,15),T(t,1,6,11,12),T(t,2,7,8,13),T(t,3,4,9,14);var t;for(let t=0;t<16;t++)this.buff[t]=this.buff[t]+this.state[t]>>>0;this.idx=0,this.state[12]=this.state[12]+1>>>0,0==this.state[12]&&(this.state[13]=this.state[13]+1>>>0,0==this.state[13]&&(this.state[14]=this.state[14]+1>>>0,0==this.state[14]&&(this.state[15]=this.state[15]+1>>>0)))}}var U={};function Q(t){let a=new Uint8Array(t);if(void 0!==globalThis.crypto)globalThis.crypto.getRandomValues(a);else for(let e=0;e>>0;return a}let k=null;function R(){return k||(k=new M(function(){const t=Q(32),a=new Uint32Array(t.buffer),e=[];for(let t=0;t<8;t++)e.push(a[t]);return e}()),k)}class N{constructor(t,a,e){this.F=a,this.G=t,this.opMulGF=e;let o=a.sqrt_t||a.t,i=a.sqrt_s||a.s,n=a.one;for(;a.eq(a.pow(n,a.half),a.one);)n=a.add(n,a.one);this.w=new Array(i+1),this.wi=new Array(i+1),this.w[i]=this.F.pow(n,o),this.wi[i]=this.F.inv(this.w[i]);let l=i-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(i,15))}_setRoots(t){for(let a=t;a>=0&&!this.roots[a];a--){let t=this.F.one;const e=1<>1,c=$(t,a,e-1,o,2*i),s=$(t,a,e-1,o+i,2*i),r=new Array(n);for(let a=0;a>this.one,this.bitLength=i(this.p),this.mask=(this.one<>this.one;this.nqr=this.two;let e=this.pow(this.nqr,a);for(;!this.eq(e,this.negone);)this.nqr=this.nqr+this.one,e=this.pow(this.nqr,a);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),z(this),this.FFT=new N(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,a){let e;if(a?16==a&&(e=BigInt("0x"+t)):e=BigInt(t),e<0){let t=-e;return t>=this.p&&(t%=this.p),this.p-t}return e>=this.p?e%this.p:e}add(t,a){const e=t+a;return e>=this.p?e-this.p:e}sub(t,a){return t>=a?t-a:this.p-a+t}neg(t){return t?this.p-t:t}mul(t,a){return t*a%this.p}mulScalar(t,a){return t*this.e(a)%this.p}square(t){return t*t%this.p}eq(t,a){return t==a}neq(t,a){return t!=a}lt(t,a){return(t>this.half?t-this.p:t)<(a>this.half?a-this.p:a)}gt(t,a){return(t>this.half?t-this.p:t)>(a>this.half?a-this.p:a)}leq(t,a){return(t>this.half?t-this.p:t)<=(a>this.half?a-this.p:a)}geq(t,a){return(t>this.half?t-this.p:t)>=(a>this.half?a-this.p:a)}div(t,a){return this.mul(t,this.inv(a))}idiv(t,a){if(!a)throw new Error("Division by zero");return t/a}inv(t){if(!t)throw new Error("Division by zero");let a=this.zero,e=this.p,o=this.one,i=t%this.p;for(;i;){let t=e/i;[a,o]=[o,a-t*o],[e,i]=[i,e-t*i]}return a=this.p?e-this.p:e}bor(t,a){const e=(t|a)&this.mask;return e>=this.p?e-this.p:e}bxor(t,a){const e=(t^a)&this.mask;return e>=this.p?e-this.p:e}bnot(t){const a=t^this.mask;return a>=this.p?a-this.p:a}shl(t,a){if(Number(a)=this.p?e-this.p:e}{const e=this.p-a;return Number(e)>e:this.zero}}shr(t,a){if(Number(a)>a;{const e=this.p-a;if(Number(e)=this.p?a-this.p:a}return 0}}land(t,a){return t&&a?this.one:this.zero}lor(t,a){return t||a?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 a=this.s,e=this.nqr_to_t,o=this.pow(t,this.t),i=this.pow(t,this.add(this.t,this.one)>>this.one);for(;o!=this.one;){let t=this.square(o),n=1;for(;t!=this.one;)n++,t=this.square(t);let l=e;for(let t=0;tthis.p>>this.one&&(i=this.neg(i)),i}normalize(t,a){if((t=BigInt(t,a))<0){let a=-t;return a>=this.p&&(a%=this.p),this.p-a}return t>=this.p?t%this.p:t}random(){const t=2*this.bitLength/8;let a=this.zero;for(let e=0;ethis.half&&10==a){e="-"+(this.p-t).toString(a)}else e=t.toString(a);return e}isZero(t){return t==this.zero}fromRng(t){let a;do{a=this.zero;for(let e=0;e=this.p);return a=a*this.Ri%this.p,a}fft(t){return this.FFT.fft(t)}ifft(t){return this.FFT.ifft(t)}toRprLE(t,a,e){x(t,a,e,8*this.n64)}toRprBE(t,a,e){I(t,a,e,8*this.n64)}toRprBEM(t,a,e){return this.toRprBE(t,a,this.mul(this.R,e))}toRprLEM(t,a,e){return this.toRprLE(t,a,this.mul(this.R,e))}fromRprLE(t,a){return B(t,a,this.n8)}fromRprBE(t,a){return E(t,a,this.n8)}fromRprLEM(t,a){return this.mul(this.fromRprLE(t,a),this.Ri)}fromRprBEM(t,a){return this.mul(this.fromRprBE(t,a),this.Ri)}toObject(t){return t}}var V="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},K={bigInt2BytesLE:function(t,a){const e=Array(a);let o=BigInt(t);for(let t=0;t>=8n;return e},bigInt2U32LE:function(t,a){const e=Array(a);let o=BigInt(t);for(let t=0;t>=32n;return e},isOcamNum:function(t){return!!Array.isArray(t)&&(3==t.length&&("number"==typeof t[0]&&("number"==typeof t[1]&&!!Array.isArray(t[2]))))}},H=function(t,a,e,o,i,n,l){const c=t.addFunction(a);c.addParam("base","i32"),c.addParam("scalar","i32"),c.addParam("scalarLength","i32"),c.addParam("r","i32"),c.addLocal("i","i32"),c.addLocal("b","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(e));c.addCode(s.if(s.i32_eqz(s.getLocal("scalarLength")),[...s.call(l,s.getLocal("r")),...s.ret([])])),c.addCode(s.call(n,s.getLocal("base"),r)),c.addCode(s.call(l,s.getLocal("r"))),c.addCode(s.setLocal("i",s.getLocal("scalarLength"))),c.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 a=0;a<8;a++)t.push(...s.call(i,s.getLocal("r"),s.getLocal("r")),...s.if(s.i32_ge_u(s.getLocal("b"),s.i32_const(128>>a)),[...s.setLocal("b",s.i32_sub(s.getLocal("b"),s.i32_const(128>>a))),...s.call(o,s.getLocal("r"),r,s.getLocal("r"))]));return t}(),s.br_if(1,s.i32_eqz(s.getLocal("i"))),s.br(0))))},Z=function(t,a){const e=8*t.modules[a].n64,o=t.addFunction(a+"_batchInverse");o.addParam("pIn","i32"),o.addParam("inStep","i32"),o.addParam("n","i32"),o.addParam("pOut","i32"),o.addParam("outStep","i32"),o.addLocal("itAux","i32"),o.addLocal("itIn","i32"),o.addLocal("itOut","i32"),o.addLocal("i","i32");const i=o.getCodeBuilder(),n=i.i32_const(t.alloc(e));o.addCode(i.setLocal("itAux",i.i32_load(i.i32_const(0))),i.i32_store(i.i32_const(0),i.i32_add(i.getLocal("itAux"),i.i32_mul(i.i32_add(i.getLocal("n"),i.i32_const(1)),i.i32_const(e))))),o.addCode(i.call(a+"_one",i.getLocal("itAux")),i.setLocal("itIn",i.getLocal("pIn")),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.if(i.call(a+"_isZero",i.getLocal("itIn")),i.call(a+"_copy",i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),i.getLocal("itAux")),i.call(a+"_mul",i.getLocal("itIn"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),i.getLocal("itAux"))),i.setLocal("itIn",i.i32_add(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))),i.setLocal("itIn",i.i32_sub(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itAux",i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("itOut",i.i32_add(i.getLocal("pOut"),i.i32_mul(i.i32_sub(i.getLocal("n"),i.i32_const(1)),i.getLocal("outStep")))),i.call(a+"_inverse",i.getLocal("itAux"),i.getLocal("itAux")),i.block(i.loop(i.br_if(1,i.i32_eqz(i.getLocal("i"))),i.if(i.call(a+"_isZero",i.getLocal("itIn")),[...i.call(a+"_copy",i.getLocal("itAux"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),...i.call(a+"_zero",i.getLocal("itOut"))],[...i.call(a+"_copy",i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),n),...i.call(a+"_mul",i.getLocal("itAux"),i.getLocal("itIn"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),...i.call(a+"_mul",i.getLocal("itAux"),n,i.getLocal("itOut"))]),i.setLocal("itIn",i.i32_sub(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itOut",i.i32_sub(i.getLocal("itOut"),i.getLocal("outStep"))),i.setLocal("itAux",i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0)))),o.addCode(i.i32_store(i.i32_const(0),i.getLocal("itAux")))};var W=function(t,a,e,o,i,n){void 0===n&&(n=oa?1:-1}function tt(t){return t*t}function at(t){return t%2n!==0n}function et(t){return t%2n===0n}function ot(t){return t<0n}function it(t){return t>0n}function nt(t){return ot(t)?t.toString(2).length-1:t.toString(2).length}function lt(t){return t<0n?-t:t}function ct(t){return 1n===lt(t)}function st(t,a){for(var e,o,i,n=0n,l=1n,c=a,s=lt(t);0n!==s;)e=c/s,o=n,i=c,n=l,c=s,l=o-e*l,s=i-e*s;if(!ct(c))throw new Error(t.toString()+" and "+a.toString()+" are not co-prime");return-1===X(n,0n)&&(n+=a),ot(t)?-n:n}function rt(t,a,e){if(0n===e)throw new Error("Cannot take modPow with modulus 0");var o=1n,i=t%e;for(ot(a)&&(a*=-1n,i=st(i,e));it(a);){if(0n===i)return 0n;at(a)&&(o=o*i%e),a/=2n,i=tt(i)%e}return o}function dt(t,a){return 0n!==a&&(!!ct(a)||(0===function(t,a){return(t=t>=0n?t:-t)===(a=a>=0n?a:-a)?0:t>a?1:-1}(a,2n)?et(t):t%a===0n))}function ut(t,a){for(var e,o,i,n=function(t){return t-1n}(t),l=n,c=0;et(l);)l/=2n,c++;t:for(o=0;o>1&&o>1,t>>1)))),a.addCode(e.setLocal(s,e.i64_add(e.getLocal(s),e.i64_shr_u(e.getLocal(c),e.i64_const(32)))))),t>0&&(a.addCode(e.setLocal(c,e.i64_add(e.i64_and(e.getLocal(c),e.i64_const(4294967295)),e.i64_and(e.getLocal(r),e.i64_const(4294967295))))),a.addCode(e.setLocal(s,e.i64_add(e.i64_add(e.getLocal(s),e.i64_shr_u(e.getLocal(c),e.i64_const(32))),e.getLocal(d))))),a.addCode(e.i64_store32(e.getLocal("r"),4*t,e.getLocal(c))),a.addCode(e.setLocal(r,e.getLocal(s)),e.setLocal(d,e.i64_shr_u(e.getLocal(r),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*i*2-4,e.getLocal(r)))}(),function(){const a=t.addFunction(o+"_squareOld");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(o+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){!function(){const a=t.addFunction(o+"__mul1");a.addParam("px","i32"),a.addParam("y","i64"),a.addParam("pr","i32"),a.addLocal("c","i64");const e=a.getCodeBuilder();a.addCode(e.setLocal("c",e.i64_mul(e.i64_load32_u(e.getLocal("px"),0,0),e.getLocal("y")))),a.addCode(e.i64_store32(e.getLocal("pr"),0,0,e.getLocal("c")));for(let t=1;t>1n,p=t.alloc(c,gt.bigInt2BytesLE(h,c)),m=h+1n,L=t.alloc(c,gt.bigInt2BytesLE(m,c));t.modules[s]={pq:d,pR2:u,n64:n,q:i,pOne:_,pZero:g,pePlusOne:L};let b=2n;if(yt(i))for(;wt(b,h,i)!==f;)b+=1n;let w=0,y=f;for(;!At(y)&&0n!==y;)w++,y>>=1n;const A=t.alloc(c,gt.bigInt2BytesLE(y,c)),C=wt(b,y,i),F=t.alloc(gt.bigInt2BytesLE((C<>1n,I=t.alloc(c,gt.bigInt2BytesLE(x,c));return t.exportFunction(r+"_copy",s+"_copy"),t.exportFunction(r+"_zero",s+"_zero"),t.exportFunction(r+"_isZero",s+"_isZero"),t.exportFunction(r+"_eq",s+"_eq"),function(){const a=t.addFunction(s+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder();a.addCode(e.ret(e.call(r+"_eq",e.getLocal("x"),e.i32_const(_))))}(),function(){const a=t.addFunction(s+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.if(e.call(r+"_add",e.getLocal("x"),e.getLocal("y"),e.getLocal("r")),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.if(e.call(r+"_sub",e.getLocal("x"),e.getLocal("y"),e.getLocal("r")),e.drop(e.call(r+"_add",e.getLocal("r"),e.i32_const(d),e.getLocal("r")))))}(),function(){const a=t.addFunction(s+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_sub",e.i32_const(g),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.alloc(l*l*8),e=t.addFunction(s+"_mReduct");e.addParam("t","i32"),e.addParam("r","i32"),e.addLocal("np32","i64"),e.addLocal("c","i64"),e.addLocal("m","i64");const o=e.getCodeBuilder(),n=Number(0x100000000n-bt(i,0x100000000n));e.addCode(o.setLocal("np32",o.i64_const(n)));for(let t=0;t=l&&a.addCode(e.i64_store32(e.getLocal("r"),4*(t-l),e.getLocal(f))),[f,h]=[h,f],a.addCode(e.setLocal(h,e.i64_shr_u(e.getLocal(f),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*l-4,e.getLocal(f))),a.addCode(e.if(e.i32_wrap_i64(e.getLocal(h)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_square");a.addParam("x","i32"),a.addParam("r","i32"),a.addLocal("c0","i64"),a.addLocal("c1","i64"),a.addLocal("c0_old","i64"),a.addLocal("c1_old","i64"),a.addLocal("np32","i64");for(let t=0;t>1&&o>1,t>>1)))),a.addCode(e.setLocal(f,e.i64_add(e.getLocal(f),e.i64_shr_u(e.getLocal(g),e.i64_const(32)))))),t>0&&(a.addCode(e.setLocal(g,e.i64_add(e.i64_and(e.getLocal(g),e.i64_const(4294967295)),e.i64_and(e.getLocal(h),e.i64_const(4294967295))))),a.addCode(e.setLocal(f,e.i64_add(e.i64_add(e.getLocal(f),e.i64_shr_u(e.getLocal(g),e.i64_const(32))),e.getLocal(p)))));for(let o=Math.max(1,t-l+1);o<=t&&o=l&&a.addCode(e.i64_store32(e.getLocal("r"),4*(t-l),e.getLocal(g))),a.addCode(e.setLocal(h,e.getLocal(f)),e.setLocal(p,e.i64_shr_u(e.getLocal(h),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*l-4,e.getLocal(h))),a.addCode(e.if(e.i32_wrap_i64(e.getLocal(p)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_squareOld");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.i32_const(u),e.getLocal("r")))}(),function(){const a=t.alloc(2*c),e=t.addFunction(s+"_fromMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const o=e.getCodeBuilder();e.addCode(o.call(r+"_copy",o.getLocal("x"),o.i32_const(a))),e.addCode(o.call(r+"_zero",o.i32_const(a+c))),e.addCode(o.call(s+"_mReduct",o.i32_const(a),o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.call(s+"_fromMontgomery",e.getLocal("x"),o),e.call(r+"_gte",o,e.i32_const(L)))}(),function(){const a=t.addFunction(s+"_sign");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(r+"_isZero",e.getLocal("x")),e.ret(e.i32_const(0))),e.call(s+"_fromMontgomery",e.getLocal("x"),o),e.if(e.call(r+"_gte",o,e.i32_const(L)),e.ret(e.i32_const(-1))),e.ret(e.i32_const(1)))}(),function(){const a=t.addFunction(s+"_inverse");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_fromMontgomery",e.getLocal("x"),e.getLocal("r"))),a.addCode(e.call(r+"_inverseMod",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),a.addCode(e.call(s+"_toMontgomery",e.getLocal("r"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_one");a.addParam("pr","i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_copy",e.i32_const(_),e.getLocal("pr")))}(),function(){const a=t.addFunction(s+"_load");a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32"),a.addLocal("p","i32"),a.addLocal("l","i32"),a.addLocal("i","i32"),a.addLocal("j","i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c)),i=t.alloc(c),n=e.i32_const(i);a.addCode(e.call(r+"_zero",e.getLocal("r")),e.setLocal("i",e.i32_const(c)),e.setLocal("p",e.getLocal("scalar")),e.block(e.loop(e.br_if(1,e.i32_gt_u(e.getLocal("i"),e.getLocal("scalarLen"))),e.if(e.i32_eq(e.getLocal("i"),e.i32_const(c)),e.call(s+"_one",o),e.call(s+"_mul",o,e.i32_const(u),o)),e.call(s+"_mul",e.getLocal("p"),o,n),e.call(s+"_add",e.getLocal("r"),n,e.getLocal("r")),e.setLocal("p",e.i32_add(e.getLocal("p"),e.i32_const(c))),e.setLocal("i",e.i32_add(e.getLocal("i"),e.i32_const(c))),e.br(0))),e.setLocal("l",e.i32_rem_u(e.getLocal("scalarLen"),e.i32_const(c))),e.if(e.i32_eqz(e.getLocal("l")),e.ret([])),e.call(r+"_zero",n),e.setLocal("j",e.i32_const(0)),e.block(e.loop(e.br_if(1,e.i32_eq(e.getLocal("j"),e.getLocal("l"))),e.i32_store8(e.getLocal("j"),i,e.i32_load8_u(e.getLocal("p"))),e.setLocal("p",e.i32_add(e.getLocal("p"),e.i32_const(1))),e.setLocal("j",e.i32_add(e.getLocal("j"),e.i32_const(1))),e.br(0))),e.if(e.i32_eq(e.getLocal("i"),e.i32_const(c)),e.call(s+"_one",o),e.call(s+"_mul",o,e.i32_const(u),o)),e.call(s+"_mul",n,o,n),e.call(s+"_add",e.getLocal("r"),n,e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.call(s+"_load",e.getLocal("scalar"),e.getLocal("scalarLen"),o),e.call(s+"_toMontgomery",o,o),e.call(s+"_mul",e.getLocal("x"),o,e.getLocal("r")))}(),ht(t,s),pt(t,s+"_batchToMontgomery",s+"_toMontgomery",c,c),pt(t,s+"_batchFromMontgomery",s+"_fromMontgomery",c,c),pt(t,s+"_batchNeg",s+"_neg",c,c),mt(t,s+"_batchAdd",s+"_add",c,c),mt(t,s+"_batchSub",s+"_sub",c,c),mt(t,s+"_batchMul",s+"_mul",c,c),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"),ft(t,s+"_exp",c,s+"_mul",s+"_square",r+"_copy",s+"_one"),t.exportFunction(s+"_exp"),t.exportFunction(s+"_batchInverse"),yt(i)&&(!function(){const a=t.addFunction(s+"_sqrt");a.addParam("n","i32"),a.addParam("r","i32"),a.addLocal("m","i32"),a.addLocal("i","i32"),a.addLocal("j","i32");const e=a.getCodeBuilder(),o=e.i32_const(_),i=e.i32_const(t.alloc(c)),n=e.i32_const(t.alloc(c)),l=e.i32_const(t.alloc(c)),r=e.i32_const(t.alloc(c)),d=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(s+"_isZero",e.getLocal("n")),e.ret(e.call(s+"_zero",e.getLocal("r")))),e.setLocal("m",e.i32_const(w)),e.call(s+"_copy",e.i32_const(F),i),e.call(s+"_exp",e.getLocal("n"),e.i32_const(A),e.i32_const(c),n),e.call(s+"_exp",e.getLocal("n"),e.i32_const(I),e.i32_const(c),l),e.block(e.loop(e.br_if(1,e.call(s+"_eq",n,o)),e.call(s+"_square",n,r),e.setLocal("i",e.i32_const(1)),e.block(e.loop(e.br_if(1,e.call(s+"_eq",r,o)),e.call(s+"_square",r,r),e.setLocal("i",e.i32_add(e.getLocal("i"),e.i32_const(1))),e.br(0))),e.call(s+"_copy",i,d),e.setLocal("j",e.i32_sub(e.i32_sub(e.getLocal("m"),e.getLocal("i")),e.i32_const(1))),e.block(e.loop(e.br_if(1,e.i32_eqz(e.getLocal("j"))),e.call(s+"_square",d,d),e.setLocal("j",e.i32_sub(e.getLocal("j"),e.i32_const(1))),e.br(0))),e.setLocal("m",e.getLocal("i")),e.call(s+"_square",d,i),e.call(s+"_mul",n,i,n),e.call(s+"_mul",l,d,l),e.br(0))),e.if(e.call(s+"_isNegative",l),e.call(s+"_neg",l,e.getLocal("r")),e.call(s+"_copy",l,e.getLocal("r"))))}(),function(){const a=t.addFunction(s+"_isSquare");a.addParam("n","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(_),i=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(s+"_isZero",e.getLocal("n")),e.ret(e.i32_const(1))),e.call(s+"_exp",e.getLocal("n"),e.i32_const(p),e.i32_const(c),i),e.call(s+"_eq",i,o))}(),t.exportFunction(s+"_sqrt"),t.exportFunction(s+"_isSquare")),t.exportFunction(s+"_batchToMontgomery"),t.exportFunction(s+"_batchFromMontgomery"),s};const xt=Ft,{bitLength:It}=J;var Bt=function(t,a,e,o,i){const n=BigInt(a),l=Math.floor((It(n-1n)-1)/64)+1,c=8*l,s=e||"f1";if(t.modules[s])return s;t.modules[s]={n64:l};const r=i||"int",d=xt(t,n,o,r),u=t.modules[d].pR2,_=t.modules[d].pq,g=t.modules[d].pePlusOne;return function(){const a=t.alloc(c),e=t.addFunction(s+"_mul");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const o=e.getCodeBuilder();e.addCode(o.call(d+"_mul",o.getLocal("x"),o.getLocal("y"),o.i32_const(a))),e.addCode(o.call(d+"_mul",o.i32_const(a),o.i32_const(u),o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_square");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_inverse");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_inverseMod",e.getLocal("x"),e.i32_const(_),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_gte",e.getLocal("x"),e.i32_const(g)))}(),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 Et=H,vt=Z,St=K;var Pt=function(t,a,e,o){if(t.modules[e])return e;const i=8*t.modules[o].n64,n=t.modules[o].q;return t.modules[e]={n64:2*t.modules[o].n64},function(){const a=t.addFunction(e+"_isZero");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.i32_and(n.call(o+"_isZero",l),n.call(o+"_isZero",c)))}(),function(){const a=t.addFunction(e+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.ret(n.i32_and(n.call(o+"_isOne",l),n.call(o+"_isZero",c))))}(),function(){const a=t.addFunction(e+"_zero");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.call(o+"_zero",l),n.call(o+"_zero",c))}(),function(){const a=t.addFunction(e+"_one");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.call(o+"_one",l),n.call(o+"_zero",c))}(),function(){const a=t.addFunction(e+"_copy");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_copy",l,s),n.call(o+"_copy",c,r))}(),function(){const n=t.addFunction(e+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("y"),d=l.i32_add(l.getLocal("y"),l.i32_const(i)),u=l.getLocal("r"),_=l.i32_add(l.getLocal("r"),l.i32_const(i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_mul",c,r,g),l.call(o+"_mul",s,d,f),l.call(o+"_add",c,s,h),l.call(o+"_add",r,d,p),l.call(o+"_mul",h,p,h),l.call(a,f,u),l.call(o+"_add",g,u,u),l.call(o+"_add",g,f,_),l.call(o+"_sub",h,_,_))}(),function(){const a=t.addFunction(e+"_mul1");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_mul",l,s,r),n.call(o+"_mul",c,s,d))}(),function(){const n=t.addFunction(e+"_square");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("r"),d=l.i32_add(l.getLocal("r"),l.i32_const(i)),u=l.i32_const(t.alloc(i)),_=l.i32_const(t.alloc(i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_mul",c,s,u),l.call(o+"_add",c,s,_),l.call(a,s,g),l.call(o+"_add",c,g,g),l.call(a,u,f),l.call(o+"_add",f,u,f),l.call(o+"_mul",_,g,r),l.call(o+"_sub",r,f,r),l.call(o+"_add",u,u,d))}(),function(){const a=t.addFunction(e+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.i32_add(n.getLocal("y"),n.i32_const(i)),d=n.getLocal("r"),u=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_add",l,s,d),n.call(o+"_add",c,r,u))}(),function(){const a=t.addFunction(e+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.i32_add(n.getLocal("y"),n.i32_const(i)),d=n.getLocal("r"),u=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_sub",l,s,d),n.call(o+"_sub",c,r,u))}(),function(){const a=t.addFunction(e+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_neg",l,s),n.call(o+"_neg",c,r))}(),function(){const a=t.addFunction(e+"_conjugate");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_copy",l,s),n.call(o+"_neg",c,r))}(),function(){const a=t.addFunction(e+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_toMontgomery",l,s),n.call(o+"_toMontgomery",c,r))}(),function(){const a=t.addFunction(e+"_fromMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_fromMontgomery",l,s),n.call(o+"_fromMontgomery",c,r))}(),function(){const a=t.addFunction(e+"_eq");a.addParam("x","i32"),a.addParam("y","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.i32_add(n.getLocal("y"),n.i32_const(i));a.addCode(n.i32_and(n.call(o+"_eq",l,s),n.call(o+"_eq",c,r)))}(),function(){const n=t.addFunction(e+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("r"),d=l.i32_add(l.getLocal("r"),l.i32_const(i)),u=l.i32_const(t.alloc(i)),_=l.i32_const(t.alloc(i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_square",c,u),l.call(o+"_square",s,_),l.call(a,_,g),l.call(o+"_sub",u,g,g),l.call(o+"_inverse",g,f),l.call(o+"_mul",c,f,r),l.call(o+"_mul",s,f,d),l.call(o+"_neg",d,d))}(),function(){const a=t.addFunction(e+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_timesScalar",l,n.getLocal("scalar"),n.getLocal("scalarLen"),s),n.call(o+"_timesScalar",c,n.getLocal("scalar"),n.getLocal("scalarLen"),r))}(),function(){const a=t.addFunction(e+"_sign");a.addParam("x","i32"),a.addLocal("s","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.setLocal("s",n.call(o+"_sign",c)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(o+"_sign",l)))}(),function(){const a=t.addFunction(e+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.if(n.call(o+"_isZero",c),n.ret(n.call(o+"_isNegative",l))),n.ret(n.call(o+"_isNegative",c)))}(),t.exportFunction(e+"_isZero"),t.exportFunction(e+"_isOne"),t.exportFunction(e+"_zero"),t.exportFunction(e+"_one"),t.exportFunction(e+"_copy"),t.exportFunction(e+"_mul"),t.exportFunction(e+"_mul1"),t.exportFunction(e+"_square"),t.exportFunction(e+"_add"),t.exportFunction(e+"_sub"),t.exportFunction(e+"_neg"),t.exportFunction(e+"_sign"),t.exportFunction(e+"_conjugate"),t.exportFunction(e+"_fromMontgomery"),t.exportFunction(e+"_toMontgomery"),t.exportFunction(e+"_eq"),t.exportFunction(e+"_inverse"),vt(t,e),Et(t,e+"_exp",2*i,e+"_mul",e+"_square",e+"_copy",e+"_one"),function(){const a=t.addFunction(e+"_sqrt");a.addParam("a","i32"),a.addParam("pr","i32");const l=a.getCodeBuilder(),c=l.i32_const(t.alloc(St.bigInt2BytesLE((BigInt(n||0)-3n)/4n,i))),s=l.i32_const(t.alloc(St.bigInt2BytesLE((BigInt(n||0)-1n)/2n,i))),r=l.getLocal("a"),d=l.i32_const(t.alloc(2*i)),u=l.i32_const(t.alloc(2*i)),_=l.i32_const(t.alloc(2*i)),g=t.alloc(2*i),f=l.i32_const(g),h=l.i32_const(g),p=l.i32_const(g+i),m=l.i32_const(t.alloc(2*i)),L=l.i32_const(t.alloc(2*i));a.addCode(l.call(e+"_one",f),l.call(e+"_neg",f,f),l.call(e+"_exp",r,c,l.i32_const(i),d),l.call(e+"_square",d,u),l.call(e+"_mul",r,u,u),l.call(e+"_conjugate",u,_),l.call(e+"_mul",_,u,_),l.if(l.call(e+"_eq",_,f),l.unreachable()),l.call(e+"_mul",d,r,m),l.if(l.call(e+"_eq",u,f),[...l.call(o+"_zero",h),...l.call(o+"_one",p),...l.call(e+"_mul",f,m,l.getLocal("pr"))],[...l.call(e+"_one",L),...l.call(e+"_add",L,u,L),...l.call(e+"_exp",L,s,l.i32_const(i),L),...l.call(e+"_mul",L,m,l.getLocal("pr"))]))}(),function(){const a=t.addFunction(e+"_isSquare");a.addParam("a","i32"),a.setReturnType("i32");const o=a.getCodeBuilder(),l=o.i32_const(t.alloc(St.bigInt2BytesLE((BigInt(n||0)-3n)/4n,i))),c=o.getLocal("a"),s=o.i32_const(t.alloc(2*i)),r=o.i32_const(t.alloc(2*i)),d=o.i32_const(t.alloc(2*i)),u=t.alloc(2*i),_=o.i32_const(u);a.addCode(o.call(e+"_one",_),o.call(e+"_neg",_,_),o.call(e+"_exp",c,l,o.i32_const(i),s),o.call(e+"_square",s,r),o.call(e+"_mul",c,r,r),o.call(e+"_conjugate",r,d),o.call(e+"_mul",d,r,d),o.if(o.call(e+"_eq",d,_),o.ret(o.i32_const(0))),o.ret(o.i32_const(1)))}(),t.exportFunction(e+"_exp"),t.exportFunction(e+"_timesScalar"),t.exportFunction(e+"_batchInverse"),t.exportFunction(e+"_sqrt"),t.exportFunction(e+"_isSquare"),t.exportFunction(e+"_isNegative"),e};const qt=H,Ot=Z;var Gt=function(t,a,e,o){if(t.modules[e])return e;const i=8*t.modules[o].n64;return t.modules[e]={n64:3*t.modules[o].n64},function(){const a=t.addFunction(e+"_isZero");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.i32_and(n.i32_and(n.call(o+"_isZero",l),n.call(o+"_isZero",c)),n.call(o+"_isZero",s)))}(),function(){const a=t.addFunction(e+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.ret(n.i32_and(n.i32_and(n.call(o+"_isOne",l),n.call(o+"_isZero",c)),n.call(o+"_isZero",s))))}(),function(){const a=t.addFunction(e+"_zero");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.call(o+"_zero",l),n.call(o+"_zero",c),n.call(o+"_zero",s))}(),function(){const a=t.addFunction(e+"_one");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.call(o+"_one",l),n.call(o+"_zero",c),n.call(o+"_zero",s))}(),function(){const a=t.addFunction(e+"_copy");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_copy",l,r),n.call(o+"_copy",c,d),n.call(o+"_copy",s,u))}(),function(){const n=t.addFunction(e+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("y"),u=l.i32_add(l.getLocal("y"),l.i32_const(i)),_=l.i32_add(l.getLocal("y"),l.i32_const(2*i)),g=l.getLocal("r"),f=l.i32_add(l.getLocal("r"),l.i32_const(i)),h=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),p=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i)),w=l.i32_const(t.alloc(i)),y=l.i32_const(t.alloc(i)),A=l.i32_const(t.alloc(i)),C=l.i32_const(t.alloc(i)),F=l.i32_const(t.alloc(i)),x=l.i32_const(t.alloc(i)),I=l.i32_const(t.alloc(i)),B=l.i32_const(t.alloc(i)),E=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_mul",c,d,p),l.call(o+"_mul",s,u,m),l.call(o+"_mul",r,_,L),l.call(o+"_add",c,s,b),l.call(o+"_add",d,u,w),l.call(o+"_add",c,r,y),l.call(o+"_add",d,_,A),l.call(o+"_add",s,r,C),l.call(o+"_add",u,_,F),l.call(o+"_add",p,m,x),l.call(o+"_add",p,L,I),l.call(o+"_add",m,L,B),l.call(o+"_mul",C,F,g),l.call(o+"_sub",g,B,g),l.call(a,g,g),l.call(o+"_add",p,g,g),l.call(o+"_mul",b,w,f),l.call(o+"_sub",f,x,f),l.call(a,L,E),l.call(o+"_add",f,E,f),l.call(o+"_mul",y,A,h),l.call(o+"_sub",h,I,h),l.call(o+"_add",h,m,h))}(),function(){const n=t.addFunction(e+"_square");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("r"),u=l.i32_add(l.getLocal("r"),l.i32_const(i)),_=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_square",c,g),l.call(o+"_mul",c,s,f),l.call(o+"_add",f,f,h),l.call(o+"_sub",c,s,p),l.call(o+"_add",p,r,p),l.call(o+"_square",p,p),l.call(o+"_mul",s,r,m),l.call(o+"_add",m,m,L),l.call(o+"_square",r,b),l.call(a,L,d),l.call(o+"_add",g,d,d),l.call(a,b,u),l.call(o+"_add",h,u,u),l.call(o+"_add",g,b,_),l.call(o+"_sub",L,_,_),l.call(o+"_add",p,_,_),l.call(o+"_add",h,_,_))}(),function(){const a=t.addFunction(e+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(i)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*i)),_=n.getLocal("r"),g=n.i32_add(n.getLocal("r"),n.i32_const(i)),f=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_add",l,r,_),n.call(o+"_add",c,d,g),n.call(o+"_add",s,u,f))}(),function(){const a=t.addFunction(e+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(i)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*i)),_=n.getLocal("r"),g=n.i32_add(n.getLocal("r"),n.i32_const(i)),f=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_sub",l,r,_),n.call(o+"_sub",c,d,g),n.call(o+"_sub",s,u,f))}(),function(){const a=t.addFunction(e+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_neg",l,r),n.call(o+"_neg",c,d),n.call(o+"_neg",s,u))}(),function(){const a=t.addFunction(e+"_sign");a.addParam("x","i32"),a.addLocal("s","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.setLocal("s",n.call(o+"_sign",s)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.setLocal("s",n.call(o+"_sign",c)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(o+"_sign",l)))}(),function(){const a=t.addFunction(e+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_toMontgomery",l,r),n.call(o+"_toMontgomery",c,d),n.call(o+"_toMontgomery",s,u))}(),function(){const a=t.addFunction(e+"_fromMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_fromMontgomery",l,r),n.call(o+"_fromMontgomery",c,d),n.call(o+"_fromMontgomery",s,u))}(),function(){const a=t.addFunction(e+"_eq");a.addParam("x","i32"),a.addParam("y","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(i)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*i));a.addCode(n.i32_and(n.i32_and(n.call(o+"_eq",l,r),n.call(o+"_eq",c,d)),n.call(o+"_eq",s,u)))}(),function(){const n=t.addFunction(e+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("r"),u=l.i32_add(l.getLocal("r"),l.i32_const(i)),_=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i)),w=l.i32_const(t.alloc(i)),y=l.i32_const(t.alloc(i)),A=l.i32_const(t.alloc(i)),C=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_square",c,g),l.call(o+"_square",s,f),l.call(o+"_square",r,h),l.call(o+"_mul",c,s,p),l.call(o+"_mul",c,r,m),l.call(o+"_mul",s,r,L),l.call(a,L,b),l.call(o+"_sub",g,b,b),l.call(a,h,w),l.call(o+"_sub",w,p,w),l.call(o+"_sub",f,m,y),l.call(o+"_mul",r,w,A),l.call(o+"_mul",s,y,C),l.call(o+"_add",A,C,A),l.call(a,A,A),l.call(o+"_mul",c,b,C),l.call(o+"_add",C,A,A),l.call(o+"_inverse",A,A),l.call(o+"_mul",A,b,d),l.call(o+"_mul",A,w,u),l.call(o+"_mul",A,y,_))}(),function(){const a=t.addFunction(e+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_timesScalar",l,n.getLocal("scalar"),n.getLocal("scalarLen"),r),n.call(o+"_timesScalar",c,n.getLocal("scalar"),n.getLocal("scalarLen"),d),n.call(o+"_timesScalar",s,n.getLocal("scalar"),n.getLocal("scalarLen"),u))}(),function(){const a=t.addFunction(e+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.if(n.call(o+"_isZero",s),n.if(n.call(o+"_isZero",c),n.ret(n.call(o+"_isNegative",l)),n.ret(n.call(o+"_isNegative",c)))),n.ret(n.call(o+"_isNegative",s)))}(),t.exportFunction(e+"_isZero"),t.exportFunction(e+"_isOne"),t.exportFunction(e+"_zero"),t.exportFunction(e+"_one"),t.exportFunction(e+"_copy"),t.exportFunction(e+"_mul"),t.exportFunction(e+"_square"),t.exportFunction(e+"_add"),t.exportFunction(e+"_sub"),t.exportFunction(e+"_neg"),t.exportFunction(e+"_sign"),t.exportFunction(e+"_fromMontgomery"),t.exportFunction(e+"_toMontgomery"),t.exportFunction(e+"_eq"),t.exportFunction(e+"_inverse"),Ot(t,e),qt(t,e+"_exp",3*i,e+"_mul",e+"_square",e+"_copy",e+"_one"),t.exportFunction(e+"_exp"),t.exportFunction(e+"_timesScalar"),t.exportFunction(e+"_batchInverse"),t.exportFunction(e+"_isNegative"),e};const zt=function(t,a,e,o,i,n,l,c){const s=t.addFunction(a);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 r=s.getCodeBuilder(),d=r.i32_const(t.alloc(e));function u(t){return r.i32_and(r.i32_shr_u(r.i32_load(r.i32_add(r.getLocal("scalar"),r.i32_and(r.i32_shr_u(t,r.i32_const(3)),r.i32_const(4294967292)))),r.i32_and(t,r.i32_const(31))),r.i32_const(1))}function _(t){return[...r.i32_store8(r.getLocal("p"),r.i32_const(t)),...r.setLocal("p",r.i32_add(r.getLocal("p"),r.i32_const(1)))]}s.addCode(r.if(r.i32_eqz(r.getLocal("scalarLength")),[...r.call(c,r.getLocal("r")),...r.ret([])]),r.setLocal("nbits",r.i32_shl(r.getLocal("scalarLength"),r.i32_const(3))),r.setLocal("old0",r.i32_load(r.i32_const(0))),r.setLocal("p",r.getLocal("old0")),r.i32_store(r.i32_const(0),r.i32_and(r.i32_add(r.i32_add(r.getLocal("old0"),r.i32_const(32)),r.getLocal("nbits")),r.i32_const(4294967288))),r.setLocal("i",r.i32_const(1)),r.setLocal("last",u(r.i32_const(0))),r.setLocal("carry",r.i32_const(0)),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("i"),r.getLocal("nbits"))),r.setLocal("cur",u(r.getLocal("i"))),r.if(r.getLocal("last"),r.if(r.getLocal("cur"),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(1)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(255)]),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(255)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(0)),..._(1)])),r.if(r.getLocal("cur"),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(0)],[...r.setLocal("last",r.i32_const(1)),...r.setLocal("carry",r.i32_const(0)),..._(0)]),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(1)),...r.setLocal("carry",r.i32_const(0)),..._(0)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(0)),..._(0)]))),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0))),r.if(r.getLocal("last"),r.if(r.getLocal("carry"),[..._(255),..._(0),..._(1)],[..._(1)]),r.if(r.getLocal("carry"),[..._(0),..._(1)])),r.setLocal("p",r.i32_sub(r.getLocal("p"),r.i32_const(1))),r.call(l,r.getLocal("base"),d),r.call(c,r.getLocal("r")),r.block(r.loop(r.call(i,r.getLocal("r"),r.getLocal("r")),r.setLocal("cur",r.i32_load8_u(r.getLocal("p"))),r.if(r.getLocal("cur"),r.if(r.i32_eq(r.getLocal("cur"),r.i32_const(1)),r.call(o,r.getLocal("r"),d,r.getLocal("r")),r.call(n,r.getLocal("r"),d,r.getLocal("r")))),r.br_if(1,r.i32_eq(r.getLocal("old0"),r.getLocal("p"))),r.setLocal("p",r.i32_sub(r.getLocal("p"),r.i32_const(1))),r.br(0))),r.i32_store(r.i32_const(0),r.getLocal("old0")))},Tt=W,Mt=function(t,a,e,o,i){const n=8*t.modules[a].n64;function l(){const o=t.addFunction(e);o.addParam("pBases","i32"),o.addParam("pScalars","i32"),o.addParam("scalarSize","i32"),o.addParam("n","i32"),o.addParam("pr","i32"),o.addLocal("chunkSize","i32"),o.addLocal("nChunks","i32"),o.addLocal("itScalar","i32"),o.addLocal("endScalar","i32"),o.addLocal("itBase","i32"),o.addLocal("itBit","i32"),o.addLocal("i","i32"),o.addLocal("j","i32"),o.addLocal("nTable","i32"),o.addLocal("pTable","i32"),o.addLocal("idx","i32"),o.addLocal("pIdxTable","i32");const i=o.getCodeBuilder(),l=i.i32_const(t.alloc(n)),c=t.alloc([17,17,17,17,17,17,17,17,17,17,16,16,15,14,13,13,12,11,10,9,8,7,7,6,5,4,3,2,1,1,1,1]);o.addCode(i.call(a+"_zero",i.getLocal("pr")),i.if(i.i32_eqz(i.getLocal("n")),i.ret([])),i.setLocal("chunkSize",i.i32_load8_u(i.i32_clz(i.getLocal("n")),c)),i.setLocal("nChunks",i.i32_add(i.i32_div_u(i.i32_sub(i.i32_shl(i.getLocal("scalarSize"),i.i32_const(3)),i.i32_const(1)),i.getLocal("chunkSize")),i.i32_const(1))),i.setLocal("itBit",i.i32_mul(i.i32_sub(i.getLocal("nChunks"),i.i32_const(1)),i.getLocal("chunkSize"))),i.block(i.loop(i.br_if(1,i.i32_lt_s(i.getLocal("itBit"),i.i32_const(0))),i.if(i.i32_eqz(i.call(a+"_isZero",i.getLocal("pr"))),[...i.setLocal("j",i.i32_const(0)),...i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("j"),i.getLocal("chunkSize"))),i.call(a+"_double",i.getLocal("pr"),i.getLocal("pr")),i.setLocal("j",i.i32_add(i.getLocal("j"),i.i32_const(1))),i.br(0)))]),i.call(e+"_chunk",i.getLocal("pBases"),i.getLocal("pScalars"),i.getLocal("scalarSize"),i.getLocal("n"),i.getLocal("itBit"),i.getLocal("chunkSize"),l),i.call(a+"_add",i.getLocal("pr"),l,i.getLocal("pr")),i.setLocal("itBit",i.i32_sub(i.getLocal("itBit"),i.getLocal("chunkSize"))),i.br(0))))}!function(){const a=t.addFunction(e+"_getChunk");a.addParam("pScalar","i32"),a.addParam("scalarSize","i32"),a.addParam("startBit","i32"),a.addParam("chunkSize","i32"),a.addLocal("bitsToEnd","i32"),a.addLocal("mask","i32"),a.setReturnType("i32");const o=a.getCodeBuilder();a.addCode(o.setLocal("bitsToEnd",o.i32_sub(o.i32_mul(o.getLocal("scalarSize"),o.i32_const(8)),o.getLocal("startBit"))),o.if(o.i32_gt_s(o.getLocal("chunkSize"),o.getLocal("bitsToEnd")),o.setLocal("mask",o.i32_sub(o.i32_shl(o.i32_const(1),o.getLocal("bitsToEnd")),o.i32_const(1))),o.setLocal("mask",o.i32_sub(o.i32_shl(o.i32_const(1),o.getLocal("chunkSize")),o.i32_const(1)))),o.i32_and(o.i32_shr_u(o.i32_load(o.i32_add(o.getLocal("pScalar"),o.i32_shr_u(o.getLocal("startBit"),o.i32_const(3))),0,0),o.i32_and(o.getLocal("startBit"),o.i32_const(7))),o.getLocal("mask")))}(),function(){const o=t.addFunction(e+"_reduceTable");o.addParam("pTable","i32"),o.addParam("p","i32"),o.addLocal("half","i32"),o.addLocal("it1","i32"),o.addLocal("it2","i32"),o.addLocal("pAcc","i32");const i=o.getCodeBuilder();o.addCode(i.if(i.i32_eq(i.getLocal("p"),i.i32_const(1)),i.ret([])),i.setLocal("half",i.i32_shl(i.i32_const(1),i.i32_sub(i.getLocal("p"),i.i32_const(1)))),i.setLocal("it1",i.getLocal("pTable")),i.setLocal("it2",i.i32_add(i.getLocal("pTable"),i.i32_mul(i.getLocal("half"),i.i32_const(n)))),i.setLocal("pAcc",i.i32_sub(i.getLocal("it2"),i.i32_const(n))),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("it1"),i.getLocal("pAcc"))),i.call(a+"_add",i.getLocal("it1"),i.getLocal("it2"),i.getLocal("it1")),i.call(a+"_add",i.getLocal("pAcc"),i.getLocal("it2"),i.getLocal("pAcc")),i.setLocal("it1",i.i32_add(i.getLocal("it1"),i.i32_const(n))),i.setLocal("it2",i.i32_add(i.getLocal("it2"),i.i32_const(n))),i.br(0))),i.call(e+"_reduceTable",i.getLocal("pTable"),i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.setLocal("p",i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.block(i.loop(i.br_if(1,i.i32_eqz(i.getLocal("p"))),i.call(a+"_double",i.getLocal("pAcc"),i.getLocal("pAcc")),i.setLocal("p",i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.br(0))),i.call(a+"_add",i.getLocal("pTable"),i.getLocal("pAcc"),i.getLocal("pTable")))}(),function(){const l=t.addFunction(e+"_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 c=l.getCodeBuilder();l.addCode(c.if(c.i32_eqz(c.getLocal("n")),[...c.call(a+"_zero",c.getLocal("pr")),...c.ret([])]),c.setLocal("nTable",c.i32_shl(c.i32_const(1),c.getLocal("chunkSize"))),c.setLocal("pTable",c.i32_load(c.i32_const(0))),c.i32_store(c.i32_const(0),c.i32_add(c.getLocal("pTable"),c.i32_mul(c.getLocal("nTable"),c.i32_const(n)))),c.setLocal("j",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("j"),c.getLocal("nTable"))),c.call(a+"_zero",c.i32_add(c.getLocal("pTable"),c.i32_mul(c.getLocal("j"),c.i32_const(n)))),c.setLocal("j",c.i32_add(c.getLocal("j"),c.i32_const(1))),c.br(0))),c.setLocal("itBase",c.getLocal("pBases")),c.setLocal("itScalar",c.getLocal("pScalars")),c.setLocal("endScalar",c.i32_add(c.getLocal("pScalars"),c.i32_mul(c.getLocal("n"),c.getLocal("scalarSize")))),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("itScalar"),c.getLocal("endScalar"))),c.setLocal("idx",c.call(e+"_getChunk",c.getLocal("itScalar"),c.getLocal("scalarSize"),c.getLocal("startBit"),c.getLocal("chunkSize"))),c.if(c.getLocal("idx"),[...c.setLocal("pIdxTable",c.i32_add(c.getLocal("pTable"),c.i32_mul(c.i32_sub(c.getLocal("idx"),c.i32_const(1)),c.i32_const(n)))),...c.call(o,c.getLocal("pIdxTable"),c.getLocal("itBase"),c.getLocal("pIdxTable"))]),c.setLocal("itScalar",c.i32_add(c.getLocal("itScalar"),c.getLocal("scalarSize"))),c.setLocal("itBase",c.i32_add(c.getLocal("itBase"),c.i32_const(i))),c.br(0))),c.call(e+"_reduceTable",c.getLocal("pTable"),c.getLocal("chunkSize")),c.call(a+"_copy",c.getLocal("pTable"),c.getLocal("pr")),c.i32_store(c.i32_const(0),c.getLocal("pTable")))}(),l(),t.exportFunction(e),t.exportFunction(e+"_chunk")};var Ut=function(t,a,e,o){const i=t.modules[e].n64,n=8*i;if(t.modules[a])return a;return t.modules[a]={n64:3*i},function(){const o=t.addFunction(a+"_isZeroAffine");o.addParam("p1","i32"),o.setReturnType("i32");const i=o.getCodeBuilder();o.addCode(i.i32_and(i.call(e+"_isZero",i.getLocal("p1")),i.call(e+"_isZero",i.i32_add(i.getLocal("p1"),i.i32_const(n)))))}(),function(){const o=t.addFunction(a+"_isZero");o.addParam("p1","i32"),o.setReturnType("i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_isZero",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))))}(),function(){const o=t.addFunction(a+"_zeroAffine");o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_zero",i.getLocal("pr"))),o.addCode(i.call(e+"_zero",i.i32_add(i.getLocal("pr"),i.i32_const(n))))}(),function(){const o=t.addFunction(a+"_zero");o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_zero",i.getLocal("pr"))),o.addCode(i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(n)))),o.addCode(i.call(e+"_zero",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))))}(),function(){const e=t.addFunction(a+"_copyAffine");e.addParam("ps","i32"),e.addParam("pd","i32");const o=e.getCodeBuilder();for(let t=0;t<2*i;t++)e.addCode(o.i64_store(o.getLocal("pd"),8*t,o.i64_load(o.getLocal("ps"),8*t)))}(),function(){const e=t.addFunction(a+"_copy");e.addParam("ps","i32"),e.addParam("pd","i32");const o=e.getCodeBuilder();for(let t=0;t<3*i;t++)e.addCode(o.i64_store(o.getLocal("pd"),8*t,o.i64_load(o.getLocal("ps"),8*t)))}(),function(){const o=t.addFunction(a+"_toJacobian");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(n)),d=i.i32_add(i.getLocal("pr"),i.i32_const(2*n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),i.call(a+"_zero",i.getLocal("pr")),[...i.call(e+"_one",d),...i.call(e+"_copy",c,r),...i.call(e+"_copy",l,s)]))}(),function(){const o=t.addFunction(a+"_eqAffine");o.addParam("p1","i32"),o.addParam("p2","i32"),o.setReturnType("i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder();o.addCode(i.ret(i.i32_and(i.call(e+"_eq",i.getLocal("p1"),i.getLocal("p2")),i.call(e+"_eq",i.i32_add(i.getLocal("p1"),i.i32_const(n)),i.i32_add(i.getLocal("p2"),i.i32_const(n))))))}(),function(){const o=t.addFunction(a+"_eqMixed");o.addParam("p1","i32"),o.addParam("p2","i32"),o.setReturnType("i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n)),u=i.i32_const(t.alloc(n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.ret(i.call(a+"_isZeroAffine",i.getLocal("p2")))),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),i.ret(i.i32_const(0))),i.if(i.call(e+"_isOne",s),i.ret(i.call(a+"_eqAffine",i.getLocal("p1"),i.getLocal("p2")))),i.call(e+"_square",s,u),i.call(e+"_mul",r,u,_),i.call(e+"_mul",s,u,g),i.call(e+"_mul",d,g,f),i.if(i.call(e+"_eq",l,_),i.if(i.call(e+"_eq",c,f),i.ret(i.i32_const(1)))),i.ret(i.i32_const(0)))}(),function(){const o=t.addFunction(a+"_eq");o.addParam("p1","i32"),o.addParam("p2","i32"),o.setReturnType("i32"),o.addLocal("z1","i32"),o.addLocal("z2","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n));o.addCode(i.setLocal("z2",i.i32_add(i.getLocal("p2"),i.i32_const(2*n))));const u=i.getLocal("z2"),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.ret(i.call(a+"_isZero",i.getLocal("p2")))),i.if(i.call(a+"_isZero",i.getLocal("p2")),i.ret(i.i32_const(0))),i.if(i.call(e+"_isOne",s),i.ret(i.call(a+"_eqMixed",i.getLocal("p2"),i.getLocal("p1")))),i.if(i.call(e+"_isOne",u),i.ret(i.call(a+"_eqMixed",i.getLocal("p1"),i.getLocal("p2")))),i.call(e+"_square",s,_),i.call(e+"_square",u,g),i.call(e+"_mul",l,g,f),i.call(e+"_mul",r,_,h),i.call(e+"_mul",s,_,p),i.call(e+"_mul",u,g,m),i.call(e+"_mul",c,m,L),i.call(e+"_mul",d,p,b),i.if(i.call(e+"_eq",f,h),i.if(i.call(e+"_eq",L,b),i.ret(i.i32_const(1)))),i.ret(i.i32_const(0)))}(),function(){const o=t.addFunction(a+"_doubleAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(n)),d=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),u=i.i32_const(t.alloc(n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),[...i.call(a+"_toJacobian",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.call(e+"_square",l,u),i.call(e+"_square",c,_),i.call(e+"_square",_,g),i.call(e+"_add",l,_,f),i.call(e+"_square",f,f),i.call(e+"_sub",f,u,f),i.call(e+"_sub",f,g,f),i.call(e+"_add",f,f,f),i.call(e+"_add",u,u,h),i.call(e+"_add",h,u,h),i.call(e+"_add",c,c,d),i.call(e+"_square",h,s),i.call(e+"_sub",s,f,s),i.call(e+"_sub",s,f,s),i.call(e+"_add",g,g,p),i.call(e+"_add",p,p,p),i.call(e+"_add",p,p,p),i.call(e+"_sub",f,s,r),i.call(e+"_mul",r,h,r),i.call(e+"_sub",r,p,r))}(),function(){const o=t.addFunction(a+"_double");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(e+"_isOne",s),[...i.ret(i.call(a+"_doubleAffine",i.getLocal("p1"),i.getLocal("pr"))),...i.ret([])]),i.call(e+"_square",l,_),i.call(e+"_square",c,g),i.call(e+"_square",g,f),i.call(e+"_add",l,g,h),i.call(e+"_square",h,h),i.call(e+"_sub",h,_,h),i.call(e+"_sub",h,f,h),i.call(e+"_add",h,h,h),i.call(e+"_add",_,_,p),i.call(e+"_add",p,_,p),i.call(e+"_square",p,m),i.call(e+"_mul",c,s,L),i.call(e+"_add",h,h,r),i.call(e+"_sub",m,r,r),i.call(e+"_add",f,f,b),i.call(e+"_add",b,b,b),i.call(e+"_add",b,b,b),i.call(e+"_sub",h,r,d),i.call(e+"_mul",d,p,d),i.call(e+"_sub",d,b,d),i.call(e+"_add",L,L,u))}(),function(){const o=t.addFunction(a+"_addAffine");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("p2"),r=i.i32_add(i.getLocal("p2"),i.i32_const(n)),d=i.getLocal("pr"),u=i.i32_add(i.getLocal("pr"),i.i32_const(n)),_=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n)),w=i.i32_const(t.alloc(n)),y=i.i32_const(t.alloc(n)),A=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),[...i.call(a+"_copyAffine",i.getLocal("p2"),i.getLocal("pr")),...i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))),...i.ret([])]),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),[...i.call(a+"_copyAffine",i.getLocal("p1"),i.getLocal("pr")),...i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))),...i.ret([])]),i.if(i.call(e+"_eq",l,s),i.if(i.call(e+"_eq",c,r),[...i.call(a+"_doubleAffine",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])])),i.call(e+"_sub",s,l,g),i.call(e+"_sub",r,c,h),i.call(e+"_square",g,f),i.call(e+"_add",f,f,p),i.call(e+"_add",p,p,p),i.call(e+"_mul",g,p,m),i.call(e+"_add",h,h,L),i.call(e+"_mul",l,p,w),i.call(e+"_square",L,b),i.call(e+"_add",w,w,y),i.call(e+"_sub",b,m,d),i.call(e+"_sub",d,y,d),i.call(e+"_mul",c,m,A),i.call(e+"_add",A,A,A),i.call(e+"_sub",w,d,u),i.call(e+"_mul",u,L,u),i.call(e+"_sub",u,A,u),i.call(e+"_add",g,g,_))}(),function(){const o=t.addFunction(a+"_addMixed");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n)),u=i.getLocal("pr"),_=i.i32_add(i.getLocal("pr"),i.i32_const(n)),g=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n)),w=i.i32_const(t.alloc(n)),y=i.i32_const(t.alloc(n)),A=i.i32_const(t.alloc(n)),C=i.i32_const(t.alloc(n)),F=i.i32_const(t.alloc(n)),x=i.i32_const(t.alloc(n)),I=i.i32_const(t.alloc(n)),B=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copyAffine",i.getLocal("p2"),i.getLocal("pr")),...i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))),...i.ret([])]),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(e+"_isOne",s),[...i.call(a+"_addAffine",l,r,u),...i.ret([])]),i.call(e+"_square",s,f),i.call(e+"_mul",r,f,h),i.call(e+"_mul",s,f,p),i.call(e+"_mul",d,p,m),i.if(i.call(e+"_eq",l,h),i.if(i.call(e+"_eq",c,m),[...i.call(a+"_doubleAffine",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])])),i.call(e+"_sub",h,l,L),i.call(e+"_sub",m,c,w),i.call(e+"_square",L,b),i.call(e+"_add",b,b,y),i.call(e+"_add",y,y,y),i.call(e+"_mul",L,y,A),i.call(e+"_add",w,w,C),i.call(e+"_mul",l,y,x),i.call(e+"_square",C,F),i.call(e+"_add",x,x,I),i.call(e+"_sub",F,A,u),i.call(e+"_sub",u,I,u),i.call(e+"_mul",c,A,B),i.call(e+"_add",B,B,B),i.call(e+"_sub",x,u,_),i.call(e+"_mul",_,C,_),i.call(e+"_sub",_,B,_),i.call(e+"_add",s,L,g),i.call(e+"_square",g,g),i.call(e+"_sub",g,f,g),i.call(e+"_sub",g,b,g))}(),function(){const o=t.addFunction(a+"_add");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32"),o.addLocal("z1","i32"),o.addLocal("z2","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n));o.addCode(i.setLocal("z2",i.i32_add(i.getLocal("p2"),i.i32_const(2*n))));const u=i.getLocal("z2"),_=i.getLocal("pr"),g=i.i32_add(i.getLocal("pr"),i.i32_const(n)),f=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n)),w=i.i32_const(t.alloc(n)),y=i.i32_const(t.alloc(n)),A=i.i32_const(t.alloc(n)),C=i.i32_const(t.alloc(n)),F=i.i32_const(t.alloc(n)),x=i.i32_const(t.alloc(n)),I=i.i32_const(t.alloc(n)),B=i.i32_const(t.alloc(n)),E=i.i32_const(t.alloc(n)),v=i.i32_const(t.alloc(n)),S=i.i32_const(t.alloc(n)),P=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copy",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(a+"_isZero",i.getLocal("p2")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(e+"_isOne",s),[...i.call(a+"_addMixed",r,l,_),...i.ret([])]),i.if(i.call(e+"_isOne",u),[...i.call(a+"_addMixed",l,r,_),...i.ret([])]),i.call(e+"_square",s,h),i.call(e+"_square",u,p),i.call(e+"_mul",l,p,m),i.call(e+"_mul",r,h,L),i.call(e+"_mul",s,h,b),i.call(e+"_mul",u,p,w),i.call(e+"_mul",c,w,y),i.call(e+"_mul",d,b,A),i.if(i.call(e+"_eq",m,L),i.if(i.call(e+"_eq",y,A),[...i.call(a+"_double",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])])),i.call(e+"_sub",L,m,C),i.call(e+"_sub",A,y,F),i.call(e+"_add",C,C,x),i.call(e+"_square",x,x),i.call(e+"_mul",C,x,I),i.call(e+"_add",F,F,B),i.call(e+"_mul",m,x,v),i.call(e+"_square",B,E),i.call(e+"_add",v,v,S),i.call(e+"_sub",E,I,_),i.call(e+"_sub",_,S,_),i.call(e+"_mul",y,I,P),i.call(e+"_add",P,P,P),i.call(e+"_sub",v,_,g),i.call(e+"_mul",g,B,g),i.call(e+"_sub",g,P,g),i.call(e+"_add",s,u,f),i.call(e+"_square",f,f),i.call(e+"_sub",f,h,f),i.call(e+"_sub",f,p,f),i.call(e+"_mul",f,C,f))}(),function(){const o=t.addFunction(a+"_negAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(n));o.addCode(i.call(e+"_copy",l,s),i.call(e+"_neg",c,r))}(),function(){const o=t.addFunction(a+"_neg");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*n));o.addCode(i.call(e+"_copy",l,r),i.call(e+"_neg",c,d),i.call(e+"_copy",s,u))}(),function(){const e=t.addFunction(a+"_subAffine");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(3*n));e.addCode(o.call(a+"_negAffine",o.getLocal("p2"),i),o.call(a+"_addAffine",o.getLocal("p1"),i,o.getLocal("pr")))}(),function(){const e=t.addFunction(a+"_subMixed");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(3*n));e.addCode(o.call(a+"_negAffine",o.getLocal("p2"),i),o.call(a+"_addMixed",o.getLocal("p1"),i,o.getLocal("pr")))}(),function(){const e=t.addFunction(a+"_sub");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(3*n));e.addCode(o.call(a+"_neg",o.getLocal("p2"),i),o.call(a+"_add",o.getLocal("p1"),i,o.getLocal("pr")))}(),function(){const o=t.addFunction(a+"_fromMontgomeryAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_fromMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<2;t++)o.addCode(i.call(e+"_fromMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_fromMontgomery");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_fromMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<3;t++)o.addCode(i.call(e+"_fromMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_toMontgomeryAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_toMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<2;t++)o.addCode(i.call(e+"_toMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_toMontgomery");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_toMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<3;t++)o.addCode(i.call(e+"_toMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_toAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_const(t.alloc(n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(e+"_zero",r),...i.call(e+"_zero",d)],[...i.call(e+"_inverse",s,u),...i.call(e+"_square",u,_),...i.call(e+"_mul",u,_,g),...i.call(e+"_mul",l,_,r),...i.call(e+"_mul",c,g,d)]))}(),function(){const i=t.addFunction(a+"_inCurveAffine");i.addParam("pIn","i32"),i.setReturnType("i32");const l=i.getCodeBuilder(),c=l.getLocal("pIn"),s=l.i32_add(l.getLocal("pIn"),l.i32_const(n)),r=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(n));i.addCode(l.call(e+"_square",s,r),l.call(e+"_square",c,d),l.call(e+"_mul",c,d,d),l.call(e+"_add",d,l.i32_const(o),d),l.ret(l.call(e+"_eq",r,d)))}(),function(){const e=t.addFunction(a+"_inCurve");e.addParam("pIn","i32"),e.setReturnType("i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(2*n));e.addCode(o.call(a+"_toAffine",o.getLocal("pIn"),i),o.ret(o.call(a+"_inCurveAffine",i)))}(),function(){const o=t.addFunction(a+"_batchToAffine");o.addParam("pIn","i32"),o.addParam("n","i32"),o.addParam("pOut","i32"),o.addLocal("pAux","i32"),o.addLocal("itIn","i32"),o.addLocal("itAux","i32"),o.addLocal("itOut","i32"),o.addLocal("i","i32");const i=o.getCodeBuilder(),l=i.i32_const(t.alloc(n));o.addCode(i.setLocal("pAux",i.i32_load(i.i32_const(0))),i.i32_store(i.i32_const(0),i.i32_add(i.getLocal("pAux"),i.i32_mul(i.getLocal("n"),i.i32_const(n)))),i.call(e+"_batchInverse",i.i32_add(i.getLocal("pIn"),i.i32_const(2*n)),i.i32_const(3*n),i.getLocal("n"),i.getLocal("pAux"),i.i32_const(n)),i.setLocal("itIn",i.getLocal("pIn")),i.setLocal("itAux",i.getLocal("pAux")),i.setLocal("itOut",i.getLocal("pOut")),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.if(i.call(e+"_isZero",i.getLocal("itAux")),[...i.call(e+"_zero",i.getLocal("itOut")),...i.call(e+"_zero",i.i32_add(i.getLocal("itOut"),i.i32_const(n)))],[...i.call(e+"_mul",i.getLocal("itAux"),i.i32_add(i.getLocal("itIn"),i.i32_const(n)),l),...i.call(e+"_square",i.getLocal("itAux"),i.getLocal("itAux")),...i.call(e+"_mul",i.getLocal("itAux"),i.getLocal("itIn"),i.getLocal("itOut")),...i.call(e+"_mul",i.getLocal("itAux"),l,i.i32_add(i.getLocal("itOut"),i.i32_const(n)))]),i.setLocal("itIn",i.i32_add(i.getLocal("itIn"),i.i32_const(3*n))),i.setLocal("itOut",i.i32_add(i.getLocal("itOut"),i.i32_const(2*n))),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(n))),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))),i.i32_store(i.i32_const(0),i.getLocal("pAux")))}(),function(){const o=t.addFunction(a+"_normalize");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.call(a+"_zero",i.getLocal("pr")),[...i.call(e+"_inverse",s,_),...i.call(e+"_square",_,g),...i.call(e+"_mul",_,g,f),...i.call(e+"_mul",l,g,r),...i.call(e+"_mul",c,f,d),...i.call(e+"_one",u)]))}(),function(){const e=t.addFunction(a+"__reverseBytes");e.addParam("pIn","i32"),e.addParam("n","i32"),e.addParam("pOut","i32"),e.addLocal("itOut","i32"),e.addLocal("itIn","i32");const o=e.getCodeBuilder();e.addCode(o.setLocal("itOut",o.i32_sub(o.i32_add(o.getLocal("pOut"),o.getLocal("n")),o.i32_const(1))),o.setLocal("itIn",o.getLocal("pIn")),o.block(o.loop(o.br_if(1,o.i32_lt_s(o.getLocal("itOut"),o.getLocal("pOut"))),o.i32_store8(o.getLocal("itOut"),o.i32_load8_u(o.getLocal("itIn"))),o.setLocal("itOut",o.i32_sub(o.getLocal("itOut"),o.i32_const(1))),o.setLocal("itIn",o.i32_add(o.getLocal("itIn"),o.i32_const(1))),o.br(0))))}(),function(){const e=t.addFunction(a+"_LEMtoU");e.addParam("pIn","i32"),e.addParam("pOut","i32");const o=e.getCodeBuilder(),i=t.alloc(2*n),l=o.i32_const(i),c=o.i32_const(i),s=o.i32_const(i+n);e.addCode(o.if(o.call(a+"_isZeroAffine",o.getLocal("pIn")),[...o.call(a+"_zeroAffine",o.getLocal("pOut")),...o.ret([])]),o.call(a+"_fromMontgomeryAffine",o.getLocal("pIn"),l),o.call(a+"__reverseBytes",c,o.i32_const(n),o.getLocal("pOut")),o.call(a+"__reverseBytes",s,o.i32_const(n),o.i32_add(o.getLocal("pOut"),o.i32_const(n))))}(),function(){const o=t.addFunction(a+"_LEMtoC");o.addParam("pIn","i32"),o.addParam("pOut","i32");const i=o.getCodeBuilder(),l=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("pIn")),[...i.call(e+"_zero",i.getLocal("pOut")),...i.i32_store8(i.getLocal("pOut"),i.i32_const(64)),...i.ret([])]),i.call(e+"_fromMontgomery",i.getLocal("pIn"),l),i.call(a+"__reverseBytes",l,i.i32_const(n),i.getLocal("pOut")),i.if(i.i32_eq(i.call(e+"_sign",i.i32_add(i.getLocal("pIn"),i.i32_const(n))),i.i32_const(-1)),i.i32_store8(i.getLocal("pOut"),i.i32_or(i.i32_load8_u(i.getLocal("pOut")),i.i32_const(128)))))}(),function(){const e=t.addFunction(a+"_UtoLEM");e.addParam("pIn","i32"),e.addParam("pOut","i32");const o=e.getCodeBuilder(),i=t.alloc(2*n),l=o.i32_const(i),c=o.i32_const(i),s=o.i32_const(i+n);e.addCode(o.if(o.i32_and(o.i32_load8_u(o.getLocal("pIn")),o.i32_const(64)),[...o.call(a+"_zeroAffine",o.getLocal("pOut")),...o.ret([])]),o.call(a+"__reverseBytes",o.getLocal("pIn"),o.i32_const(n),c),o.call(a+"__reverseBytes",o.i32_add(o.getLocal("pIn"),o.i32_const(n)),o.i32_const(n),s),o.call(a+"_toMontgomeryAffine",l,o.getLocal("pOut")))}(),function(){const i=t.addFunction(a+"_CtoLEM");i.addParam("pIn","i32"),i.addParam("pOut","i32"),i.addLocal("firstByte","i32"),i.addLocal("greatest","i32");const l=i.getCodeBuilder(),c=t.alloc(2*n),s=l.i32_const(c),r=l.i32_const(c+n);i.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(a+"_zeroAffine",l.getLocal("pOut")),...l.ret([])]),l.setLocal("greatest",l.i32_and(l.getLocal("firstByte"),l.i32_const(128))),l.call(e+"_copy",l.getLocal("pIn"),r),l.i32_store8(r,l.i32_and(l.getLocal("firstByte"),l.i32_const(63))),l.call(a+"__reverseBytes",r,l.i32_const(n),s),l.call(e+"_toMontgomery",s,l.getLocal("pOut")),l.call(e+"_square",l.getLocal("pOut"),r),l.call(e+"_mul",l.getLocal("pOut"),r,r),l.call(e+"_add",r,l.i32_const(o),r),l.call(e+"_sqrt",r,r),l.call(e+"_neg",r,s),l.if(l.i32_eq(l.call(e+"_sign",r),l.i32_const(-1)),l.if(l.getLocal("greatest"),l.call(e+"_copy",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n))),l.call(e+"_neg",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n)))),l.if(l.getLocal("greatest"),l.call(e+"_neg",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n))),l.call(e+"_copy",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n))))))}(),Tt(t,a+"_batchLEMtoU",a+"_LEMtoU",2*n,2*n),Tt(t,a+"_batchLEMtoC",a+"_LEMtoC",2*n,n),Tt(t,a+"_batchUtoLEM",a+"_UtoLEM",2*n,2*n),Tt(t,a+"_batchCtoLEM",a+"_CtoLEM",n,2*n,!0),Tt(t,a+"_batchToJacobian",a+"_toJacobian",2*n,3*n,!0),Mt(t,a,a+"_multiexp",a+"_add",3*n),Mt(t,a,a+"_multiexpAffine",a+"_addMixed",2*n),zt(t,a+"_timesScalar",3*n,a+"_add",a+"_double",a+"_sub",a+"_copy",a+"_zero"),zt(t,a+"_timesScalarAffine",2*n,a+"_addMixed",a+"_double",a+"_subMixed",a+"_copyAffine",a+"_zero"),t.exportFunction(a+"_isZero"),t.exportFunction(a+"_isZeroAffine"),t.exportFunction(a+"_eq"),t.exportFunction(a+"_eqMixed"),t.exportFunction(a+"_eqAffine"),t.exportFunction(a+"_copy"),t.exportFunction(a+"_copyAffine"),t.exportFunction(a+"_zero"),t.exportFunction(a+"_zeroAffine"),t.exportFunction(a+"_double"),t.exportFunction(a+"_doubleAffine"),t.exportFunction(a+"_add"),t.exportFunction(a+"_addMixed"),t.exportFunction(a+"_addAffine"),t.exportFunction(a+"_neg"),t.exportFunction(a+"_negAffine"),t.exportFunction(a+"_sub"),t.exportFunction(a+"_subMixed"),t.exportFunction(a+"_subAffine"),t.exportFunction(a+"_fromMontgomery"),t.exportFunction(a+"_fromMontgomeryAffine"),t.exportFunction(a+"_toMontgomery"),t.exportFunction(a+"_toMontgomeryAffine"),t.exportFunction(a+"_timesScalar"),t.exportFunction(a+"_timesScalarAffine"),t.exportFunction(a+"_normalize"),t.exportFunction(a+"_LEMtoU"),t.exportFunction(a+"_LEMtoC"),t.exportFunction(a+"_UtoLEM"),t.exportFunction(a+"_CtoLEM"),t.exportFunction(a+"_batchLEMtoU"),t.exportFunction(a+"_batchLEMtoC"),t.exportFunction(a+"_batchUtoLEM"),t.exportFunction(a+"_batchCtoLEM"),t.exportFunction(a+"_toAffine"),t.exportFunction(a+"_toJacobian"),t.exportFunction(a+"_batchToAffine"),t.exportFunction(a+"_batchToJacobian"),t.exportFunction(a+"_inCurve"),t.exportFunction(a+"_inCurveAffine"),a};const{isOdd:Qt,modInv:kt,modPow:Rt}=J,Nt=K;var Dt=function(t,a,e,o,i){const n=8*t.modules[o].n64,l=8*t.modules[e].n64,c=t.modules[o].q;let s=c-1n,r=0;for(;!Qt(s);)r++,s>>=1n;let d=2n;for(;1n===Rt(d,c>>1n,c);)d+=1n;const u=new Array(r+1);u[r]=Rt(d,s,c);let _=r-1;for(;_>=0;)u[_]=Rt(u[_+1],2n,c),_--;const g=[],f=(1n<>e);return a}const x=Array(256);for(let t=0;t<256;t++)x[t]=F(t);const I=t.alloc(x);function B(){const e=t.addFunction(a+"_fft");e.addParam("px","i32"),e.addParam("n","i32"),e.addLocal("bits","i32");const i=e.getCodeBuilder(),l=i.i32_const(t.alloc(n));e.addCode(i.setLocal("bits",i.call(a+"__log2",i.getLocal("n"))),i.call(o+"_one",l),i.call(a+"_rawfft",i.getLocal("px"),i.getLocal("bits"),i.i32_const(0),l))}!function(){const e=t.addFunction(a+"__rev");e.addParam("x","i32"),e.addParam("bits","i32"),e.setReturnType("i32");const o=e.getCodeBuilder();e.addCode(o.i32_rotl(o.i32_add(o.i32_add(o.i32_shl(o.i32_load8_u(o.i32_and(o.getLocal("x"),o.i32_const(255)),I,0),o.i32_const(24)),o.i32_shl(o.i32_load8_u(o.i32_and(o.i32_shr_u(o.getLocal("x"),o.i32_const(8)),o.i32_const(255)),I,0),o.i32_const(16))),o.i32_add(o.i32_shl(o.i32_load8_u(o.i32_and(o.i32_shr_u(o.getLocal("x"),o.i32_const(16)),o.i32_const(255)),I,0),o.i32_const(8)),o.i32_load8_u(o.i32_and(o.i32_shr_u(o.getLocal("x"),o.i32_const(24)),o.i32_const(255)),I,0))),o.getLocal("bits")))}(),function(){const o=t.addFunction(a+"__reversePermutation");o.addParam("px","i32"),o.addParam("bits","i32"),o.addLocal("n","i32"),o.addLocal("i","i32"),o.addLocal("ri","i32"),o.addLocal("idx1","i32"),o.addLocal("idx2","i32");const i=o.getCodeBuilder(),n=i.i32_const(t.alloc(l));o.addCode(i.setLocal("n",i.i32_shl(i.i32_const(1),i.getLocal("bits"))),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.setLocal("idx1",i.i32_add(i.getLocal("px"),i.i32_mul(i.getLocal("i"),i.i32_const(l)))),i.setLocal("ri",i.call(a+"__rev",i.getLocal("i"),i.getLocal("bits"))),i.setLocal("idx2",i.i32_add(i.getLocal("px"),i.i32_mul(i.getLocal("ri"),i.i32_const(l)))),i.if(i.i32_lt_u(i.getLocal("i"),i.getLocal("ri")),[...i.call(e+"_copy",i.getLocal("idx1"),n),...i.call(e+"_copy",i.getLocal("idx2"),i.getLocal("idx1")),...i.call(e+"_copy",n,i.getLocal("idx2"))]),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))))}(),function(){const n=t.addFunction(a+"__fftFinal");n.addParam("px","i32"),n.addParam("bits","i32"),n.addParam("reverse","i32"),n.addParam("mulFactor","i32"),n.addLocal("n","i32"),n.addLocal("ndiv2","i32"),n.addLocal("pInv2","i32"),n.addLocal("i","i32"),n.addLocal("mask","i32"),n.addLocal("idx1","i32"),n.addLocal("idx2","i32");const c=n.getCodeBuilder(),s=c.i32_const(t.alloc(l));n.addCode(c.if(c.i32_and(c.i32_eqz(c.getLocal("reverse")),c.call(o+"_isOne",c.getLocal("mulFactor"))),c.ret([])),c.setLocal("n",c.i32_shl(c.i32_const(1),c.getLocal("bits"))),c.setLocal("mask",c.i32_sub(c.getLocal("n"),c.i32_const(1))),c.setLocal("i",c.i32_const(1)),c.setLocal("ndiv2",c.i32_shr_u(c.getLocal("n"),c.i32_const(1))),c.block(c.loop(c.br_if(1,c.i32_ge_u(c.getLocal("i"),c.getLocal("ndiv2"))),c.setLocal("idx1",c.i32_add(c.getLocal("px"),c.i32_mul(c.getLocal("i"),c.i32_const(l)))),c.setLocal("idx2",c.i32_add(c.getLocal("px"),c.i32_mul(c.i32_sub(c.getLocal("n"),c.getLocal("i")),c.i32_const(l)))),c.if(c.getLocal("reverse"),c.if(c.call(o+"_isOne",c.getLocal("mulFactor")),[...c.call(e+"_copy",c.getLocal("idx1"),s),...c.call(e+"_copy",c.getLocal("idx2"),c.getLocal("idx1")),...c.call(e+"_copy",s,c.getLocal("idx2"))],[...c.call(e+"_copy",c.getLocal("idx1"),s),...c.call(i,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx1")),...c.call(i,s,c.getLocal("mulFactor"),c.getLocal("idx2"))]),c.if(c.call(o+"_isOne",c.getLocal("mulFactor")),[],[...c.call(i,c.getLocal("idx1"),c.getLocal("mulFactor"),c.getLocal("idx1")),...c.call(i,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx2"))])),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0))),c.if(c.call(o+"_isOne",c.getLocal("mulFactor")),[],[...c.call(i,c.getLocal("px"),c.getLocal("mulFactor"),c.getLocal("px")),...c.setLocal("idx2",c.i32_add(c.getLocal("px"),c.i32_mul(c.getLocal("ndiv2"),c.i32_const(l)))),...c.call(i,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx2"))]))}(),function(){const c=t.addFunction(a+"_rawfft");c.addParam("px","i32"),c.addParam("bits","i32"),c.addParam("reverse","i32"),c.addParam("mulFactor","i32"),c.addLocal("s","i32"),c.addLocal("k","i32"),c.addLocal("j","i32"),c.addLocal("m","i32"),c.addLocal("mdiv2","i32"),c.addLocal("n","i32"),c.addLocal("pwm","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));c.addCode(s.call(a+"__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(h),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(o+"_one",r),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(i,s.getLocal("idx2"),r,d),s.call(e+"_copy",s.getLocal("idx1"),u),s.call(e+"_add",u,d,s.getLocal("idx1")),s.call(e+"_sub",u,d,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("pwm"),r),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(a+"__fftFinal",s.getLocal("px"),s.getLocal("bits"),s.getLocal("reverse"),s.getLocal("mulFactor")))}(),function(){const e=t.addFunction(a+"__log2");e.addParam("n","i32"),e.setReturnType("i32"),e.addLocal("bits","i32"),e.addLocal("aux","i32");const o=e.getCodeBuilder();e.addCode(o.setLocal("aux",o.i32_shr_u(o.getLocal("n"),o.i32_const(1)))),e.addCode(o.setLocal("bits",o.i32_const(0))),e.addCode(o.block(o.loop(o.br_if(1,o.i32_eqz(o.getLocal("aux"))),o.setLocal("aux",o.i32_shr_u(o.getLocal("aux"),o.i32_const(1))),o.setLocal("bits",o.i32_add(o.getLocal("bits"),o.i32_const(1))),o.br(0)))),e.addCode(o.if(o.i32_ne(o.getLocal("n"),o.i32_shl(o.i32_const(1),o.getLocal("bits"))),o.unreachable())),e.addCode(o.if(o.i32_gt_u(o.getLocal("bits"),o.i32_const(r)),o.unreachable())),e.addCode(o.getLocal("bits"))}(),B(),function(){const e=t.addFunction(a+"_ifft");e.addParam("px","i32"),e.addParam("n","i32"),e.addLocal("bits","i32"),e.addLocal("pInv2","i32");const o=e.getCodeBuilder();e.addCode(o.setLocal("bits",o.call(a+"__log2",o.getLocal("n"))),o.setLocal("pInv2",o.i32_add(o.i32_const(L),o.i32_mul(o.getLocal("bits"),o.i32_const(n)))),o.call(a+"_rawfft",o.getLocal("px"),o.getLocal("bits"),o.i32_const(1),o.getLocal("pInv2")))}(),function(){const c=t.addFunction(a+"_fftJoin");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));c.addCode(s.call(o+"_copy",s.getLocal("first"),r),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(i,s.getLocal("idx2"),r,d),s.call(e+"_copy",s.getLocal("idx1"),u),s.call(e+"_add",u,d,s.getLocal("idx1")),s.call(e+"_sub",u,d,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const c=t.addFunction(a+"_fftJoinExt");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));c.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(A),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.call(o+"_copy",s.getLocal("first"),r),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(e+"_add",s.getLocal("idx1"),s.getLocal("idx2"),d),s.call(i,s.getLocal("idx2"),s.getLocal("pShiftToM"),s.getLocal("idx2")),s.call(e+"_add",s.getLocal("idx1"),s.getLocal("idx2"),s.getLocal("idx2")),s.call(i,s.getLocal("idx2"),r,s.getLocal("idx2")),s.call(e+"_copy",d,s.getLocal("idx1")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const c=t.addFunction(a+"_fftJoinExtInv");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32"),c.addLocal("pSConst","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));c.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(o+"_copy",s.getLocal("first"),r),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(i,s.getLocal("idx2"),r,d),s.call(e+"_sub",s.getLocal("idx1"),d,s.getLocal("idx2")),s.call(i,s.getLocal("idx2"),s.getLocal("pSConst"),s.getLocal("idx2")),s.call(i,s.getLocal("idx1"),s.getLocal("pShiftToM"),s.getLocal("idx1")),s.call(e+"_sub",d,s.getLocal("idx1"),s.getLocal("idx1")),s.call(i,s.getLocal("idx1"),s.getLocal("pSConst"),s.getLocal("idx1")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const c=t.addFunction(a+"_fftMix");c.addParam("pBuff","i32"),c.addParam("n","i32"),c.addParam("exp","i32"),c.addLocal("nGroups","i32"),c.addLocal("nPerGroup","i32"),c.addLocal("nPerGroupDiv2","i32"),c.addLocal("pairOffset","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("j","i32"),c.addLocal("pwm","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));c.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(h),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(o+"_one",r),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(i,s.getLocal("idx2"),r,d),s.call(e+"_copy",s.getLocal("idx1"),u),s.call(e+"_add",u,d,s.getLocal("idx1")),s.call(e+"_sub",u,d,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("pwm"),r),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 o=t.addFunction(a+"_fftFinal");o.addParam("pBuff","i32"),o.addParam("n","i32"),o.addParam("factor","i32"),o.addLocal("idx1","i32"),o.addLocal("idx2","i32"),o.addLocal("i","i32"),o.addLocal("ndiv2","i32");const n=o.getCodeBuilder(),c=n.i32_const(t.alloc(l));o.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(i,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(i,n.getLocal("idx2"),n.getLocal("factor"),c),n.call(i,n.getLocal("idx1"),n.getLocal("factor"),n.getLocal("idx2")),n.call(e+"_copy",c,n.getLocal("idx1")),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))}(),function(){const c=t.addFunction(a+"_prepareLagrangeEvaluation");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32"),c.addLocal("pSConst","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));c.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(o+"_copy",s.getLocal("first"),r),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(i,s.getLocal("idx1"),s.getLocal("pShiftToM"),d),s.call(e+"_sub",s.getLocal("idx2"),d,d),s.call(e+"_sub",s.getLocal("idx1"),s.getLocal("idx2"),s.getLocal("idx2")),s.call(i,d,s.getLocal("pSConst"),s.getLocal("idx1")),s.call(i,s.getLocal("idx2"),r,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),t.exportFunction(a+"_fft"),t.exportFunction(a+"_ifft"),t.exportFunction(a+"_rawfft"),t.exportFunction(a+"_fftJoin"),t.exportFunction(a+"_fftJoinExt"),t.exportFunction(a+"_fftJoinExtInv"),t.exportFunction(a+"_fftMix"),t.exportFunction(a+"_fftFinal"),t.exportFunction(a+"_prepareLagrangeEvaluation")},$t=function(t,a,e){const o=8*t.modules[e].n64;return function(){const i=t.addFunction(a+"_zero");i.addParam("px","i32"),i.addParam("n","i32"),i.addLocal("lastp","i32"),i.addLocal("p","i32");const n=i.getCodeBuilder();i.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(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("p"),n.getLocal("lastp"))),n.call(e+"_zero",n.getLocal("p")),n.setLocal("p",n.i32_add(n.getLocal("p"),n.i32_const(o))),n.br(0))))}(),function(){const i=t.addFunction(a+"_constructLC");i.addParam("ppolynomials","i32"),i.addParam("psignals","i32"),i.addParam("nSignals","i32"),i.addParam("pres","i32"),i.addLocal("i","i32"),i.addLocal("j","i32"),i.addLocal("pp","i32"),i.addLocal("ps","i32"),i.addLocal("pd","i32"),i.addLocal("ncoefs","i32");const n=i.getCodeBuilder(),l=n.i32_const(t.alloc(o));i.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(o)))),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(4))),n.call(e+"_mul",n.getLocal("ps"),n.getLocal("pp"),l),n.call(e+"_add",l,n.getLocal("pd"),n.getLocal("pd")),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(o))),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(o))),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))}(),t.exportFunction(a+"_zero"),t.exportFunction(a+"_constructLC"),a},jt=function(t,a,e){const o=8*t.modules[e].n64;return function(){const i=t.addFunction(a+"_buildABC");i.addParam("pCoefs","i32"),i.addParam("nCoefs","i32"),i.addParam("pWitness","i32"),i.addParam("pA","i32"),i.addParam("pB","i32"),i.addParam("pC","i32"),i.addParam("offsetOut","i32"),i.addParam("nOut","i32"),i.addParam("offsetWitness","i32"),i.addParam("nWitness","i32"),i.addLocal("it","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("last","i32"),i.addLocal("m","i32"),i.addLocal("c","i32"),i.addLocal("s","i32"),i.addLocal("pOut","i32");const n=i.getCodeBuilder(),l=n.i32_const(t.alloc(o));i.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(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_zero",n.getLocal("ita")),n.call(e+"_zero",n.getLocal("itb")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),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(o+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(o+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(o+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(o+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(o)))),n.call(e+"_mul",n.i32_add(n.getLocal("pWitness"),n.i32_mul(n.i32_sub(n.getLocal("s"),n.getLocal("offsetWitness")),n.i32_const(o))),n.i32_add(n.getLocal("it"),n.i32_const(12)),l),n.call(e+"_add",n.getLocal("pOut"),l,n.getLocal("pOut")),n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o+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(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_mul",n.getLocal("ita"),n.getLocal("itb"),n.getLocal("it")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o))),n.br(0))))}(),function(){const i=t.addFunction(a+"_joinABC");i.addParam("pA","i32"),i.addParam("pB","i32"),i.addParam("pC","i32"),i.addParam("n","i32"),i.addParam("pP","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("itc","i32"),i.addLocal("itp","i32"),i.addLocal("last","i32");const n=i.getCodeBuilder(),l=n.i32_const(t.alloc(o));i.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(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_mul",n.getLocal("ita"),n.getLocal("itb"),l),n.call(e+"_sub",l,n.getLocal("itc"),n.getLocal("itp")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.setLocal("itc",n.i32_add(n.getLocal("itc"),n.i32_const(o))),n.setLocal("itp",n.i32_add(n.getLocal("itp"),n.i32_const(o))),n.br(0))))}(),function(){const i=t.addFunction(a+"_batchAdd");i.addParam("pa","i32"),i.addParam("pb","i32"),i.addParam("n","i32"),i.addParam("pr","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("itr","i32"),i.addLocal("last","i32");const n=i.getCodeBuilder();i.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(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_add",n.getLocal("ita"),n.getLocal("itb"),n.getLocal("itr")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.setLocal("itr",n.i32_add(n.getLocal("itr"),n.i32_const(o))),n.br(0))))}(),t.exportFunction(a+"_buildABC"),t.exportFunction(a+"_joinABC"),t.exportFunction(a+"_batchAdd"),a},Vt=function(t,a,e,o,i,n,l,c){const s=t.addFunction(a);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 r=s.getCodeBuilder(),d=r.i32_const(t.alloc(l));s.addCode(r.setLocal("pFrom",r.getLocal("pIn")),r.setLocal("pTo",r.getLocal("pOut"))),s.addCode(r.call(o+"_copy",r.getLocal("pFirst"),d)),s.addCode(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(c,r.getLocal("pFrom"),d,r.getLocal("pTo")),r.setLocal("pFrom",r.i32_add(r.getLocal("pFrom"),r.i32_const(i))),r.setLocal("pTo",r.i32_add(r.getLocal("pTo"),r.i32_const(n))),r.call(o+"_mul",d,r.getLocal("pInc"),d),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0)))),t.exportFunction(a)};const Kt=K,Ht=Ft,Zt=Bt,Wt=Pt,Yt=Gt,Jt=Ut,Xt=Dt,ta=$t,aa=jt,ea=Vt,{bitLength:oa,modInv:ia,isOdd:na,isNegative:la}=J;const ca=K,sa=Ft,ra=Bt,da=Pt,ua=Gt,_a=Ut,ga=Dt,fa=$t,ha=jt,pa=Vt,{bitLength:ma,isOdd:La,isNegative:ba}=J;var wa=function(t,a){const e=a||"bn128";if(t.modules[e])return e;const o=21888242871839275222246405745257275088696311157297823662689037894645226208583n,i=21888242871839275222246405745257275088548364400416034343698204186575808495617n,n=Math.floor((oa(o-1n)-1)/64)+1,l=8*n,c=l,s=l,r=2*s,d=12*s,u=t.alloc(Kt.bigInt2BytesLE(i,c)),_=Ht(t,o,"f1m");Zt(t,i,"fr","frm");const g=t.alloc(Kt.bigInt2BytesLE(b(3n),s)),f=Jt(t,"g1m","f1m",g);Xt(t,"frm","frm","frm","frm_mul"),ta(t,"pol","frm"),aa(t,"qap","frm");const h=Wt(t,"f1m_neg","f2m","f1m"),p=t.alloc([...Kt.bigInt2BytesLE(b(19485874751759354771024239261021720505790618469301721065564631296452457478373n),s),...Kt.bigInt2BytesLE(b(266929791119991161246907387137283842545076965332900288569378510910307636690n),s)]),m=Jt(t,"g2m","f2m",p);function L(a,e){const o=t.addFunction(a);o.addParam("pG","i32"),o.addParam("pFr","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),n=i.i32_const(t.alloc(l));o.addCode(i.call("frm_fromMontgomery",i.getLocal("pFr"),n),i.call(e,i.getLocal("pG"),n,i.i32_const(l),i.getLocal("pr"))),t.exportFunction(a)}function b(t){return BigInt(t)*(1n<0n;)na(a)?e.push(1):e.push(0),a>>=1n;return e}(29793968203157093288n),T=t.alloc(z),M=3*r,U=z.length-1,Q=z.reduce(((t,a)=>t+(0!=a?1:0)),0),k=6*l,R=3*l*2+(Q+U+1)*M;t.modules[e]={n64:n,pG1gen:y,pG1zero:C,pG1b:g,pG2gen:x,pG2zero:B,pG2b:p,pq:t.modules.f1m.pq,pr:u,pOneT:E,prePSize:k,preQSize:R,r:i.toString(),q:o.toString()};const N=4965661367192848881n;function D(a){const i=[[[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(e+"__frobeniusMap"+a);l.addParam("x","i32"),l.addParam("r","i32");const c=l.getCodeBuilder();for(let e=0;e<6;e++){const o=0==e?c.getLocal("x"):c.i32_add(c.getLocal("x"),c.i32_const(e*r)),u=o,g=c.i32_add(c.getLocal("x"),c.i32_const(e*r+s)),f=0==e?c.getLocal("r"):c.i32_add(c.getLocal("r"),c.i32_const(e*r)),p=f,m=c.i32_add(c.getLocal("r"),c.i32_const(e*r+s)),L=d(i[Math.floor(e/3)][a%12],n[e%3][a%6]),w=t.alloc([...Kt.bigInt2BytesLE(b(L[0]),32),...Kt.bigInt2BytesLE(b(L[1]),32)]);a%2==1?l.addCode(c.call(_+"_copy",u,p),c.call(_+"_neg",g,m),c.call(h+"_mul",f,c.i32_const(w),f)):l.addCode(c.call(h+"_mul",o,c.i32_const(w),f))}function d(t,a){const e=BigInt(t[0]),i=BigInt(t[1]),n=BigInt(a[0]),l=BigInt(a[1]),c=[(e*n-i*l)%o,(e*l+i*n)%o];return la(c[0])&&(c[0]=c[0]+o),c}}function $(a,o){const i=function(t){let a=t;const e=[];for(;a>0n;){if(na(a)){const t=2-Number(a%4n);e.push(t),a-=BigInt(t)}else e.push(0);a>>=1n}return e}(a).map((t=>-1==t?255:t)),n=t.alloc(i),l=t.addFunction(e+"__cyclotomicExp_"+o);l.addParam("x","i32"),l.addParam("r","i32"),l.addLocal("bit","i32"),l.addLocal("i","i32");const c=l.getCodeBuilder(),s=c.getLocal("x"),r=c.getLocal("r"),u=c.i32_const(t.alloc(d));l.addCode(c.call(G+"_conjugate",s,u),c.call(G+"_one",r),c.if(c.teeLocal("bit",c.i32_load8_s(c.i32_const(i.length-1),n)),c.if(c.i32_eq(c.getLocal("bit"),c.i32_const(1)),c.call(G+"_mul",r,s,r),c.call(G+"_mul",r,u,r))),c.setLocal("i",c.i32_const(i.length-2)),c.block(c.loop(c.call(e+"__cyclotomicSquare",r,r),c.if(c.teeLocal("bit",c.i32_load8_s(c.getLocal("i"),n)),c.if(c.i32_eq(c.getLocal("bit"),c.i32_const(1)),c.call(G+"_mul",r,s,r),c.call(G+"_mul",r,u,r))),c.br_if(1,c.i32_eqz(c.getLocal("i"))),c.setLocal("i",c.i32_sub(c.getLocal("i"),c.i32_const(1))),c.br(0))))}function j(){!function(){const a=t.addFunction(e+"__cyclotomicSquare");a.addParam("x","i32"),a.addParam("r","i32");const o=a.getCodeBuilder(),i=o.getLocal("x"),n=o.i32_add(o.getLocal("x"),o.i32_const(r)),l=o.i32_add(o.getLocal("x"),o.i32_const(2*r)),c=o.i32_add(o.getLocal("x"),o.i32_const(3*r)),s=o.i32_add(o.getLocal("x"),o.i32_const(4*r)),d=o.i32_add(o.getLocal("x"),o.i32_const(5*r)),u=o.getLocal("r"),_=o.i32_add(o.getLocal("r"),o.i32_const(r)),g=o.i32_add(o.getLocal("r"),o.i32_const(2*r)),f=o.i32_add(o.getLocal("r"),o.i32_const(3*r)),p=o.i32_add(o.getLocal("r"),o.i32_const(4*r)),m=o.i32_add(o.getLocal("r"),o.i32_const(5*r)),L=o.i32_const(t.alloc(r)),b=o.i32_const(t.alloc(r)),w=o.i32_const(t.alloc(r)),y=o.i32_const(t.alloc(r)),A=o.i32_const(t.alloc(r)),C=o.i32_const(t.alloc(r)),F=o.i32_const(t.alloc(r)),x=o.i32_const(t.alloc(r));a.addCode(o.call(h+"_mul",i,s,F),o.call(h+"_mul",s,o.i32_const(v),L),o.call(h+"_add",i,L,L),o.call(h+"_add",i,s,x),o.call(h+"_mul",x,L,L),o.call(h+"_mul",o.i32_const(v),F,x),o.call(h+"_add",F,x,x),o.call(h+"_sub",L,x,L),o.call(h+"_add",F,F,b),o.call(h+"_mul",c,l,F),o.call(h+"_mul",l,o.i32_const(v),w),o.call(h+"_add",c,w,w),o.call(h+"_add",c,l,x),o.call(h+"_mul",x,w,w),o.call(h+"_mul",o.i32_const(v),F,x),o.call(h+"_add",F,x,x),o.call(h+"_sub",w,x,w),o.call(h+"_add",F,F,y),o.call(h+"_mul",n,d,F),o.call(h+"_mul",d,o.i32_const(v),A),o.call(h+"_add",n,A,A),o.call(h+"_add",n,d,x),o.call(h+"_mul",x,A,A),o.call(h+"_mul",o.i32_const(v),F,x),o.call(h+"_add",F,x,x),o.call(h+"_sub",A,x,A),o.call(h+"_add",F,F,C),o.call(h+"_sub",L,i,u),o.call(h+"_add",u,u,u),o.call(h+"_add",L,u,u),o.call(h+"_add",b,s,p),o.call(h+"_add",p,p,p),o.call(h+"_add",b,p,p),o.call(h+"_mul",C,o.i32_const(P),x),o.call(h+"_add",x,c,f),o.call(h+"_add",f,f,f),o.call(h+"_add",x,f,f),o.call(h+"_sub",A,l,g),o.call(h+"_add",g,g,g),o.call(h+"_add",A,g,g),o.call(h+"_sub",w,n,_),o.call(h+"_add",_,_,_),o.call(h+"_add",w,_,_),o.call(h+"_add",y,d,m),o.call(h+"_add",m,m,m),o.call(h+"_add",y,m,m))}(),$(N,"w0");const a=t.addFunction(e+"__finalExponentiationLastChunk");a.addParam("x","i32"),a.addParam("r","i32");const o=a.getCodeBuilder(),i=o.getLocal("x"),n=o.getLocal("r"),l=o.i32_const(t.alloc(d)),c=o.i32_const(t.alloc(d)),s=o.i32_const(t.alloc(d)),u=o.i32_const(t.alloc(d)),_=o.i32_const(t.alloc(d)),g=o.i32_const(t.alloc(d)),f=o.i32_const(t.alloc(d)),p=o.i32_const(t.alloc(d)),m=o.i32_const(t.alloc(d)),L=o.i32_const(t.alloc(d)),b=o.i32_const(t.alloc(d)),w=o.i32_const(t.alloc(d)),y=o.i32_const(t.alloc(d)),A=o.i32_const(t.alloc(d)),C=o.i32_const(t.alloc(d)),F=o.i32_const(t.alloc(d)),x=o.i32_const(t.alloc(d)),I=o.i32_const(t.alloc(d)),B=o.i32_const(t.alloc(d)),E=o.i32_const(t.alloc(d)),S=o.i32_const(t.alloc(d));a.addCode(o.call(e+"__cyclotomicExp_w0",i,l),o.call(G+"_conjugate",l,l),o.call(e+"__cyclotomicSquare",l,c),o.call(e+"__cyclotomicSquare",c,s),o.call(G+"_mul",s,c,u),o.call(e+"__cyclotomicExp_w0",u,_),o.call(G+"_conjugate",_,_),o.call(e+"__cyclotomicSquare",_,g),o.call(e+"__cyclotomicExp_w0",g,f),o.call(G+"_conjugate",f,f),o.call(G+"_conjugate",u,p),o.call(G+"_conjugate",f,m),o.call(G+"_mul",m,_,L),o.call(G+"_mul",L,p,b),o.call(G+"_mul",b,c,w),o.call(G+"_mul",b,_,y),o.call(G+"_mul",y,i,A),o.call(e+"__frobeniusMap1",w,C),o.call(G+"_mul",C,A,F),o.call(e+"__frobeniusMap2",b,x),o.call(G+"_mul",x,F,I),o.call(G+"_conjugate",i,B),o.call(G+"_mul",B,w,E),o.call(e+"__frobeniusMap3",E,S),o.call(G+"_mul",S,I,n))}const V=t.alloc(k),K=t.alloc(R);function H(a){const o=t.addFunction(e+"_pairingEq"+a);for(let t=0;t0n;)La(a)?e.push(1):e.push(0),a>>=1n;return e}(0xd201000000010000n),z=t.alloc(G),T=3*s,M=G.length-1,U=G.reduce(((t,a)=>t+(0!=a?1:0)),0),Q=6*l,k=3*l*2+(U+M+1)*T,R=!0,N=15132376222941642752n;function D(a){const e=[[[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]]],i=[[[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"+a);n.addParam("x","i32"),n.addParam("r","i32");const r=n.getCodeBuilder();for(let o=0;o<6;o++){const u=0==o?r.getLocal("x"):r.i32_add(r.getLocal("x"),r.i32_const(o*s)),_=u,g=r.i32_add(r.getLocal("x"),r.i32_const(o*s+c)),h=0==o?r.getLocal("r"):r.i32_add(r.getLocal("r"),r.i32_const(o*s)),p=h,L=r.i32_add(r.getLocal("r"),r.i32_const(o*s+c)),b=d(e[Math.floor(o/3)][a%12],i[o%3][a%6]),w=t.alloc([...ca.bigInt2BytesLE(y(b[0]),l),...ca.bigInt2BytesLE(y(b[1]),l)]);a%2==1?n.addCode(r.call(f+"_copy",_,p),r.call(f+"_neg",g,L),r.call(m+"_mul",h,r.i32_const(w),h)):n.addCode(r.call(m+"_mul",u,r.i32_const(w),h))}function d(t,a){const e=t[0],i=t[1],n=a[0],l=a[1],c=[(e*n-i*l)%o,(e*l+i*n)%o];return ba(c[0])&&(c[0]=c[0]+o),c}}function $(a,o,i){const n=function(t){let a=t;const e=[];for(;a>0n;){if(La(a)){const t=2-Number(a%4n);e.push(t),a-=BigInt(t)}else e.push(0);a>>=1n}return e}(a).map((t=>-1==t?255:t)),l=t.alloc(n),c=t.addFunction(e+"__cyclotomicExp_"+i);c.addParam("x","i32"),c.addParam("r","i32"),c.addLocal("bit","i32"),c.addLocal("i","i32");const s=c.getCodeBuilder(),d=s.getLocal("x"),u=s.getLocal("r"),_=s.i32_const(t.alloc(r));c.addCode(s.call(O+"_conjugate",d,_),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,_,u))),s.setLocal("i",s.i32_const(n.length-2)),s.block(s.loop(s.call(e+"__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,_,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)))),o&&c.addCode(s.call(O+"_conjugate",u,u))}t.modules[e]={n64q:n,n64r:d,n8q:l,n8r:u,pG1gen:C,pG1zero:x,pG1b:h,pG2gen:B,pG2zero:v,pG2b:L,pq:t.modules.f1m.pq,pr:g,pOneT:S,r:i,q:o,prePSize:Q,preQSize:k},function(){const a=t.addFunction(q+"_mul1");a.addParam("pA","i32"),a.addParam("pC1","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),o=e.getLocal("pA"),i=e.i32_add(e.getLocal("pA"),e.i32_const(2*c)),n=e.i32_add(e.getLocal("pA"),e.i32_const(4*c)),l=e.getLocal("pC1"),s=e.getLocal("pR"),r=e.i32_add(e.getLocal("pR"),e.i32_const(2*c)),d=e.i32_add(e.getLocal("pR"),e.i32_const(4*c)),u=e.i32_const(t.alloc(2*c)),_=e.i32_const(t.alloc(2*c));a.addCode(e.call(m+"_add",o,i,u),e.call(m+"_add",i,n,_),e.call(m+"_mul",i,l,d),e.call(m+"_mul",_,l,s),e.call(m+"_sub",s,d,s),e.call(m+"_mulNR",s,s),e.call(m+"_mul",u,l,r),e.call(m+"_sub",r,d,r))}(),function(){const a=t.addFunction(q+"_mul01");a.addParam("pA","i32"),a.addParam("pC0","i32"),a.addParam("pC1","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),o=e.getLocal("pA"),i=e.i32_add(e.getLocal("pA"),e.i32_const(2*c)),n=e.i32_add(e.getLocal("pA"),e.i32_const(4*c)),l=e.getLocal("pC0"),s=e.getLocal("pC1"),r=e.getLocal("pR"),d=e.i32_add(e.getLocal("pR"),e.i32_const(2*c)),u=e.i32_add(e.getLocal("pR"),e.i32_const(4*c)),_=e.i32_const(t.alloc(2*c)),g=e.i32_const(t.alloc(2*c)),f=e.i32_const(t.alloc(2*c)),h=e.i32_const(t.alloc(2*c));a.addCode(e.call(m+"_mul",o,l,_),e.call(m+"_mul",i,s,g),e.call(m+"_add",o,i,f),e.call(m+"_add",o,n,h),e.call(m+"_add",i,n,r),e.call(m+"_mul",r,s,r),e.call(m+"_sub",r,g,r),e.call(m+"_mulNR",r,r),e.call(m+"_add",r,_,r),e.call(m+"_add",l,s,d),e.call(m+"_mul",d,f,d),e.call(m+"_sub",d,_,d),e.call(m+"_sub",d,g,d),e.call(m+"_mul",h,l,u),e.call(m+"_sub",u,_,u),e.call(m+"_add",u,g,u))}(),function(){const a=t.addFunction(O+"_mul014");a.addParam("pA","i32"),a.addParam("pC0","i32"),a.addParam("pC1","i32"),a.addParam("pC4","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),o=e.getLocal("pA"),i=e.i32_add(e.getLocal("pA"),e.i32_const(6*c)),n=e.getLocal("pC0"),l=e.getLocal("pC1"),s=e.getLocal("pC4"),r=e.i32_const(t.alloc(6*c)),d=e.i32_const(t.alloc(6*c)),u=e.i32_const(t.alloc(2*c)),_=e.getLocal("pR"),g=e.i32_add(e.getLocal("pR"),e.i32_const(6*c));a.addCode(e.call(q+"_mul01",o,n,l,r),e.call(q+"_mul1",i,s,d),e.call(m+"_add",l,s,u),e.call(q+"_add",i,o,g),e.call(q+"_mul01",g,n,u,g),e.call(q+"_sub",g,r,g),e.call(q+"_sub",g,d,g),e.call(q+"_copy",d,_),e.call(q+"_mulNR",_,_),e.call(q+"_add",_,r,_))}(),function(){const a=t.addFunction(e+"_ell");a.addParam("pP","i32"),a.addParam("pCoefs","i32"),a.addParam("pF","i32");const o=a.getCodeBuilder(),i=o.getLocal("pP"),n=o.i32_add(o.getLocal("pP"),o.i32_const(l)),s=o.getLocal("pF"),r=o.getLocal("pCoefs"),d=o.i32_add(o.getLocal("pCoefs"),o.i32_const(c)),u=o.i32_add(o.getLocal("pCoefs"),o.i32_const(2*c)),_=o.i32_add(o.getLocal("pCoefs"),o.i32_const(3*c)),g=o.i32_add(o.getLocal("pCoefs"),o.i32_const(4*c)),h=t.alloc(2*c),p=o.i32_const(h),m=o.i32_const(h),L=o.i32_const(h+c),b=t.alloc(2*c),w=o.i32_const(b),y=o.i32_const(b),A=o.i32_const(b+c);a.addCode(o.call(f+"_mul",r,n,m),o.call(f+"_mul",d,n,L),o.call(f+"_mul",u,i,y),o.call(f+"_mul",_,i,A),o.call(O+"_mul014",s,g,w,p,s))}();const j=t.alloc(Q),V=t.alloc(k);function K(a){const o=t.addFunction(e+"_pairingEq"+a);for(let t=0;t>=BigInt(32)):l+2<=a?(n.setUint16(l,Number(e&BigInt(65535)),!0),l+=2,e>>=BigInt(16)):(n.setUint8(l,Number(e&BigInt(255)),!0),l+=1,e>>=BigInt(8));if(e)throw new Error("Number does not fit in this length");return o}const Ca=[];for(let t=0;t<256;t++)Ca[t]=Fa(t,8);function Fa(t,a){let e=0,o=t;for(let t=0;t>=1;return e}function xa(t,a){return(Ca[t>>>24]|Ca[t>>>16&255]<<8|Ca[t>>>8&255]<<16|Ca[255&t]<<24)>>>32-a}function Ia(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 Ba(t,a){const e=t.byteLength/a,o=Ia(e);if(e!=1<e){const o=t.slice(i*a,(i+1)*a);t.set(t.slice(e*a,(e+1)*a),i*a),t.set(o,e*a)}}}function Ea(t,a){const e=new Uint8Array(a*t.length);for(let o=0;o{e[o]=t(a[o])})),e}return a},unstringifyBigInts:function t(a){if("string"==typeof a&&/^[0-9]+$/.test(a))return BigInt(a);if("string"==typeof a&&/^0x[0-9a-fA-F]+$/.test(a))return BigInt(a);if(Array.isArray(a))return a.map(t);if("object"==typeof a){if(null===a)return null;const e={};return Object.keys(a).forEach((o=>{e[o]=t(a[o])})),e}return a},beBuff2int:function(t){let a=BigInt(0),e=t.length,o=0;const i=new DataView(t.buffer,t.byteOffset,t.byteLength);for(;e>0;)e>=4?(e-=4,a+=BigInt(i.getUint32(e))<=2?(e-=2,a+=BigInt(i.getUint16(e))<0;)n-4>=0?(n-=4,i.setUint32(n,Number(e&BigInt(4294967295))),e>>=BigInt(32)):n-2>=0?(n-=2,i.setUint16(n,Number(e&BigInt(65535))),e>>=BigInt(16)):(n-=1,i.setUint8(n,Number(e&BigInt(255))),e>>=BigInt(8));if(e)throw new Error("Number does not fit in this length");return o},leBuff2int:function(t){let a=BigInt(0),e=0;const o=new DataView(t.buffer,t.byteOffset,t.byteLength);for(;e{o[i]=t(a,e[i])})),o}return e},unstringifyFElements:function t(a,e){if("string"==typeof e&&/^[0-9]+$/.test(e))return a.e(e);if("string"==typeof e&&/^0x[0-9a-fA-F]+$/.test(e))return a.e(e);if(Array.isArray(e))return e.map(t.bind(this,a));if("object"==typeof e){if(null===e)return null;const o={};return Object.keys(e).forEach((i=>{o[i]=t(a,e[i])})),o}return e},bitReverse:xa,log2:Ia,buffReverseBits:Ba,array2buffer:Ea,buffer2array:va});const Pa=1<<30;class qa{constructor(t){this.buffers=[],this.byteLength=t;for(let a=0;a0;){const t=l+c>Pa?Pa-l:c,a=new Uint8Array(this.buffers[n].buffer,this.buffers[n].byteOffset+l,t);if(t==e)return a.slice();i||(i=e<=Pa?new Uint8Array(e):new qa(e)),i.set(a,e-c),c-=t,n++,l=0}return i}set(t,a){void 0===a&&(a=0);const e=t.byteLength;if(0==e)return;const o=Math.floor(a/Pa);if(o==Math.floor((a+e-1)/Pa))return t instanceof qa&&1==t.buffers.length?this.buffers[o].set(t.buffers[0],a%Pa):this.buffers[o].set(t,a%Pa);let i=o,n=a%Pa,l=e;for(;l>0;){const a=n+l>Pa?Pa-n:l,o=t.slice(e-l,e-l+a);new Uint8Array(this.buffers[i].buffer,this.buffers[i].byteOffset+n,a).set(o),l-=a,i++,n=0}}}function Oa(t,a,e,o){return async function(i){const n=Math.floor(i.byteLength/e);if(n*e!==i.byteLength)throw new Error("Invalid buffer size");const l=Math.floor(n/t.concurrency),c=[];for(let s=0;s=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=Oa(t,a+"_batchToMontgomery",this.n8,this.n8),this.batchFromMontgomery=Oa(t,a+"_batchFromMontgomery",this.n8,this.n8)}op2(t,a,e){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op2Bool(t,a,e){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,e),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2)}op1(t,a){return this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op1Bool(t,a){return this.tm.setBuff(this.pOp1,a),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3)}add(t,a){return this.op2("_add",t,a)}eq(t,a){return this.op2Bool("_eq",t,a)}isZero(t){return this.op1Bool("_isZero",t)}sub(t,a){return this.op2("_sub",t,a)}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,a){return this.op2("_mul",t,a)}div(t,a){return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),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,a){return a instanceof Uint8Array||(a=S(o(a))),this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+"_exp"](this.pOp1,this.pOp2,a.byteLength,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}isNegative(t){return this.op1Bool("_isNegative",t)}e(t,a){if(t instanceof Uint8Array)return t;let e=o(t,a);n(e)?(e=p(e),A(e,this.p)&&(e=w(e,this.p)),e=h(this.p,e)):A(e,this.p)&&(e=w(e,this.p));const i=Aa(e,this.n8);return this.toMontgomery(i)}toString(t,a){return v(B(this.fromMontgomery(t),0),a)}fromRng(t){let a;const e=new Uint8Array(this.n8);do{a=P;for(let e=0;eo.buffer.byteLength){const i=o.buffer.byteLength/65536;let n=Math.floor((e[0]+t)/65536)+1;n>a&&(n=a),o.grow(n-i)}return i}function l(t){const a=n(t.byteLength);return s(a,t),a}function c(t,a){const e=new Uint8Array(o.buffer);return new Uint8Array(e.buffer,e.byteOffset+t,a)}function s(t,a){new Uint8Array(o.buffer).set(new Uint8Array(a),t)}function r(t){if("INIT"==t[0].cmd)return i(t[0]);const a={vars:[],out:[]},r=new Uint32Array(o.buffer,0,1)[0];for(let o=0;o{this.reject=a,this.resolve=t}))}}var Da;const $a="data:application/javascript;base64,"+(Da="("+Ua.toString()+")(self)",globalThis.btoa(Da));class ja{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,a,e,o){if(this.working[t])throw new Error("Posting a job t a working worker");return this.working[t]=!0,this.pendingDeferreds[t]=o||new Na,this.workers[t].postMessage(a,e),this.pendingDeferreds[t].promise}processWorks(){for(let t=0;t0;t++)if(0==this.working[t]){const a=this.actionQueue.shift();this.postAction(t,a.data,a.transfers,a.deferred)}}queueAction(t,a){const e=new Na;if(this.singleThread){const a=this.taskManager(t);e.resolve(a)}else this.actionQueue.push({data:t,transfers:a,deferred:e}),this.processWorks();return e.promise}resetMemory(){this.u32[0]=this.initalPFree}allocBuff(t){const a=this.alloc(t.byteLength);return this.setBuff(a,t),a}getBuff(t,a){return this.u8.slice(t,t+a)}setBuff(t,a){this.u8.set(new Uint8Array(a),t)}alloc(t){for(;3&this.u32[0];)this.u32[0]++;const a=this.u32[0];return this.u32[0]+=t,a}async terminate(){for(let t=0;tsetTimeout(a,t))))}}function Va(t,a){const e=t[a],o=t.Fr,i=t.tm;t[a].batchApplyKey=async function(t,n,l,c,s){let r,d,u,_,g;if(c=c||"affine",s=s||"affine","G1"==a)"jacobian"==c?(u=3*e.F.n8,r="g1m_batchApplyKey"):(u=2*e.F.n8,r="g1m_batchApplyKeyMixed"),_=3*e.F.n8,"jacobian"==s?g=3*e.F.n8:(d="g1m_batchToAffine",g=2*e.F.n8);else if("G2"==a)"jacobian"==c?(u=3*e.F.n8,r="g2m_batchApplyKey"):(u=2*e.F.n8,r="g2m_batchApplyKeyMixed"),_=3*e.F.n8,"jacobian"==s?g=3*e.F.n8:(d="g2m_batchToAffine",g=2*e.F.n8);else{if("Fr"!=a)throw new Error("Invalid group: "+a);r="frm_batchApplyKey",u=e.n8,_=e.n8,g=e.n8}const f=Math.floor(t.byteLength/u),h=Math.floor(f/i.concurrency),p=[];l=o.e(l);let m=o.e(n);for(let a=0;a=0;t--){if(!e.isZero(h))for(let t=0;tr&&(h=r),h<1024&&(h=1024);const p=[];for(let a=0;a(c&&c.debug(`Multiexp end: ${s}: ${a}/${u}`),t))))}const m=await Promise.all(p);let L=e.zero;for(let t=m.length-1;t>=0;t--)L=e.add(L,m[t]);return L}e.multiExp=async function(t,a,e,o){return await n(t,a,"jacobian",e,o)},e.multiExpAffine=async function(t,a,e,o){return await n(t,a,"affine",e,o)}}function Za(t,a){const e=t[a],o=t.Fr,i=e.tm;async function n(t,c,s,r,d,u){s=s||"affine",r=r||"affine";let _,g,f,h,p,m,L,b;"G1"==a?("affine"==s?(_=2*e.F.n8,h="g1m_batchToJacobian"):_=3*e.F.n8,g=3*e.F.n8,c&&(b="g1m_fftFinal"),L="g1m_fftJoin",m="g1m_fftMix","affine"==r?(f=2*e.F.n8,p="g1m_batchToAffine"):f=3*e.F.n8):"G2"==a?("affine"==s?(_=2*e.F.n8,h="g2m_batchToJacobian"):_=3*e.F.n8,g=3*e.F.n8,c&&(b="g2m_fftFinal"),L="g2m_fftJoin",m="g2m_fftMix","affine"==r?(f=2*e.F.n8,p="g2m_batchToAffine"):f=3*e.F.n8):"Fr"==a&&(_=e.n8,g=e.n8,f=e.n8,c&&(b="frm_fftFinal"),m="frm_fftMix",L="frm_fftJoin");let w=!1;Array.isArray(t)?(t=Ea(t,_),w=!0):t=t.slice(0,t.byteLength);const y=t.byteLength/_,A=Ia(y);if(1<1<<28?new qa(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return _.set(u[0]),_.set(u[1],u[0].byteLength),_}(t,s,r,d,u):await async function(t,a,e,i,c){let s,r;s=t.slice(0,t.byteLength/2),r=t.slice(t.byteLength/2,t.byteLength);const d=[];[s,r]=await l(s,r,"fftJoinExt",o.one,o.shift,a,"jacobian",i,c),d.push(n(s,!1,"jacobian",e,i,c)),d.push(n(r,!1,"jacobian",e,i,c));const u=await Promise.all(d);let _;_=u[0].byteLength>1<<28?new qa(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return _.set(u[0]),_.set(u[1],u[0].byteLength),_}(t,s,r,d,u),w?va(a,f):a}let C,F,x;c&&(C=o.inv(o.e(y))),Ba(t,_);let I=Math.min(16384,y),B=y/I;for(;B=16;)B*=2,I/=2;const E=Ia(I),v=[];for(let a=0;a(d&&d.debug(`${u}: fft ${A} mix end: ${a}/${B}`),t))))}x=await Promise.all(v);for(let t=0;t(d&&d.debug(`${u}: fft ${A} join ${t}/${A} ${l+1}/${a} ${c}/${e/2}`),o))))}const l=await Promise.all(n);for(let t=0;t0;a--)F.set(x[a],t),t+=I*f,delete x[a];F.set(x[0].slice(0,(I-1)*f),t),delete x[0]}else for(let t=0;t65536&&(w=65536);const y=[];for(let a=0;a(u&&u.debug(`${_}: fftJoinExt End: ${a}/${b}`),t))))}const A=await Promise.all(y);let C,F;b*p>1<<28?(C=new qa(b*p),F=new qa(b*p)):(C=new Uint8Array(b*p),F=new Uint8Array(b*p));let x=0;for(let t=0;to.s+1)throw s&&s.error("lagrangeEvaluations input too big"),new Error("lagrangeEvaluations input too big");let g=t.slice(0,t.byteLength/2),f=t.slice(t.byteLength/2,t.byteLength);const h=o.exp(o.shift,u/2),p=o.inv(o.sub(o.one,h));[g,f]=await l(g,f,"prepareLagrangeEvaluation",p,o.shiftInv,i,"jacobian",s,r+" prep");const m=[];let L;return m.push(n(g,!0,"jacobian",c,s,r+" t0")),m.push(n(f,!0,"jacobian",c,s,r+" t1")),[g,f]=await Promise.all(m),L=g.byteLength>1<<28?new qa(2*g.byteLength):new Uint8Array(2*g.byteLength),L.set(g),L.set(f,g.byteLength),L},e.fftMix=async function(t){const n=3*e.F.n8;let l,c;if("G1"==a)l="g1m_fftMix",c="g1m_fftJoin";else if("G2"==a)l="g2m_fftMix",c="g2m_fftJoin";else{if("Fr"!=a)throw new Error("Invalid group");l="frm_fftMix",c="frm_fftJoin"}const s=Math.floor(t.byteLength/n),r=Ia(s);let d=1<=0;t--)g.set(_[t][0],f),f+=_[t][0].byteLength;return g}}async function Wa(t){const a=await async function(t,a){const e=new ja;e.memory=new WebAssembly.Memory({initial:Ra}),e.u8=new Uint8Array(e.memory.buffer),e.u32=new Uint32Array(e.memory.buffer);const o=await WebAssembly.compile(t.code);if(e.instance=await WebAssembly.instantiate(o,{env:{memory:e.memory}}),e.singleThread=a,e.initalPFree=e.u32[0],e.pq=t.pq,e.pr=t.pr,e.pG1gen=t.pG1gen,e.pG1zero=t.pG1zero,e.pG2gen=t.pG2gen,e.pG2zero=t.pG2zero,e.pOneT=t.pOneT,a)e.code=t.code,e.taskManager=Ua(),await e.taskManager([{cmd:"INIT",init:Ra,code:e.code.slice()}]),e.concurrency=1;else{let a;e.workers=[],e.pendingDeferreds=[],e.working=[],a="object"==typeof navigator&&navigator.hardwareConcurrency?navigator.hardwareConcurrency:Qa.cpus().length,0==a&&(a=2),a>64&&(a=64),e.concurrency=a;for(let t=0;t>8n&0xFFn)),a.push(Number(e>>16n&0xFFn)),a.push(Number(e>>24n&0xFFn)),a}function ae(t){const a=function(t){for(var a=[],e=0;e>6,128|63&o):o<55296||o>=57344?a.push(224|o>>12,128|o>>6&63,128|63&o):(e++,o=65536+((1023&o)<<10|1023&t.charCodeAt(e)),a.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|63&o))}return a}(t);return[...le(a.length),...a]}function ee(t){const a=[];let e=Ya(t);if(Ja(e))throw new Error("Number cannot be negative");for(;!Xa(e);)a.push(Number(0x7Fn&e)),e>>=7n;0==a.length&&a.push(0);for(let t=0;t0xFFFFFFFFn)throw new Error("Number too big");if(a>0x7FFFFFFFn&&(a-=0x100000000n),a<-2147483648n)throw new Error("Number too small");return oe(a)}function ne(t){let a=Ya(t);if(a>0xFFFFFFFFFFFFFFFFn)throw new Error("Number too big");if(a>0x7FFFFFFFFFFFFFFFn&&(a-=0x10000000000000000n),a<-9223372036854775808n)throw new Error("Number too small");return oe(a)}function le(t){let a=Ya(t);if(a>0xFFFFFFFFn)throw new Error("Number too big");return ee(a)}function ce(t){return Array.from(t,(function(t){return("0"+(255&t).toString(16)).slice(-2)})).join("")}class se{constructor(t){this.func=t,this.functionName=t.functionName,this.module=t.module}setLocal(t,a){const e=this.func.localIdxByName[t];if(void 0===e)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[...a,33,...le(e)]}teeLocal(t,a){const e=this.func.localIdxByName[t];if(void 0===e)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[...a,34,...le(e)]}getLocal(t){const a=this.func.localIdxByName[t];if(void 0===a)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[32,...le(a)]}i64_load8_s(t,a,e){return[...t,48,void 0===e?0:e,...le(a||0)]}i64_load8_u(t,a,e){return[...t,49,void 0===e?0:e,...le(a||0)]}i64_load16_s(t,a,e){return[...t,50,void 0===e?1:e,...le(a||0)]}i64_load16_u(t,a,e){return[...t,51,void 0===e?1:e,...le(a||0)]}i64_load32_s(t,a,e){return[...t,52,void 0===e?2:e,...le(a||0)]}i64_load32_u(t,a,e){return[...t,53,void 0===e?2:e,...le(a||0)]}i64_load(t,a,e){return[...t,41,void 0===e?3:e,...le(a||0)]}i64_store(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=3,l=a):Array.isArray(e)?(i=a,n=3,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,55,n,...le(i)]}i64_store32(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=2,l=a):Array.isArray(e)?(i=a,n=2,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,62,n,...le(i)]}i64_store16(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=1,l=a):Array.isArray(e)?(i=a,n=1,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,61,n,...le(i)]}i64_store8(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=0,l=a):Array.isArray(e)?(i=a,n=0,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,60,n,...le(i)]}i32_load8_s(t,a,e){return[...t,44,void 0===e?0:e,...le(a||0)]}i32_load8_u(t,a,e){return[...t,45,void 0===e?0:e,...le(a||0)]}i32_load16_s(t,a,e){return[...t,46,void 0===e?1:e,...le(a||0)]}i32_load16_u(t,a,e){return[...t,47,void 0===e?1:e,...le(a||0)]}i32_load(t,a,e){return[...t,40,void 0===e?2:e,...le(a||0)]}i32_store(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=2,l=a):Array.isArray(e)?(i=a,n=2,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,54,n,...le(i)]}i32_store16(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=1,l=a):Array.isArray(e)?(i=a,n=1,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,59,n,...le(i)]}i32_store8(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=0,l=a):Array.isArray(e)?(i=a,n=0,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,58,n,...le(i)]}call(t,...a){const e=this.module.functionIdxByName[t];if(void 0===e)throw new Error(`Function not defined: Function: ${t}`);return[...[].concat(...a),16,...le(e)]}call_indirect(t,...a){return[...[].concat(...a),...t,17,0,0]}if(t,a,e){return e?[...t,4,64,...a,5,...e,11]:[...t,4,64,...a,11]}block(t){return[2,64,...t,11]}loop(...t){return[3,64,...[].concat(...t),11]}br_if(t,a){return[...a,13,...le(t)]}br(t){return[12,...le(t)]}ret(t){return[...t,15]}drop(t){return[...t,26]}i64_const(t){return[66,...ne(t)]}i32_const(t){return[65,...ie(t)]}i64_eqz(t){return[...t,80]}i64_eq(t,a){return[...t,...a,81]}i64_ne(t,a){return[...t,...a,82]}i64_lt_s(t,a){return[...t,...a,83]}i64_lt_u(t,a){return[...t,...a,84]}i64_gt_s(t,a){return[...t,...a,85]}i64_gt_u(t,a){return[...t,...a,86]}i64_le_s(t,a){return[...t,...a,87]}i64_le_u(t,a){return[...t,...a,88]}i64_ge_s(t,a){return[...t,...a,89]}i64_ge_u(t,a){return[...t,...a,90]}i64_add(t,a){return[...t,...a,124]}i64_sub(t,a){return[...t,...a,125]}i64_mul(t,a){return[...t,...a,126]}i64_div_s(t,a){return[...t,...a,127]}i64_div_u(t,a){return[...t,...a,128]}i64_rem_s(t,a){return[...t,...a,129]}i64_rem_u(t,a){return[...t,...a,130]}i64_and(t,a){return[...t,...a,131]}i64_or(t,a){return[...t,...a,132]}i64_xor(t,a){return[...t,...a,133]}i64_shl(t,a){return[...t,...a,134]}i64_shr_s(t,a){return[...t,...a,135]}i64_shr_u(t,a){return[...t,...a,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,a){return[...t,...a,70]}i32_ne(t,a){return[...t,...a,71]}i32_lt_s(t,a){return[...t,...a,72]}i32_lt_u(t,a){return[...t,...a,73]}i32_gt_s(t,a){return[...t,...a,74]}i32_gt_u(t,a){return[...t,...a,75]}i32_le_s(t,a){return[...t,...a,76]}i32_le_u(t,a){return[...t,...a,77]}i32_ge_s(t,a){return[...t,...a,78]}i32_ge_u(t,a){return[...t,...a,79]}i32_add(t,a){return[...t,...a,106]}i32_sub(t,a){return[...t,...a,107]}i32_mul(t,a){return[...t,...a,108]}i32_div_s(t,a){return[...t,...a,109]}i32_div_u(t,a){return[...t,...a,110]}i32_rem_s(t,a){return[...t,...a,111]}i32_rem_u(t,a){return[...t,...a,112]}i32_and(t,a){return[...t,...a,113]}i32_or(t,a){return[...t,...a,114]}i32_xor(t,a){return[...t,...a,115]}i32_shl(t,a){return[...t,...a,116]}i32_shr_s(t,a){return[...t,...a,117]}i32_shr_u(t,a){return[...t,...a,118]}i32_rotl(t,a){return[...t,...a,119]}i32_rotr(t,a){return[...t,...a,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 re={i32:127,i64:126,f32:125,f64:124,anyfunc:112,func:96,emptyblock:64};class de{constructor(t,a,e,o,i){if("import"==e)this.fnType="import",this.moduleName=o,this.fieldName=i;else{if("internal"!=e)throw new Error("Invalid function fnType: "+e);this.fnType="internal"}this.module=t,this.fnName=a,this.params=[],this.locals=[],this.localIdxByName={},this.code=[],this.returnType=null,this.nextLocal=0}addParam(t,a){if(this.localIdxByName[t])throw new Error(`param already exists. Function: ${this.fnName}, Param: ${t} `);const e=this.nextLocal++;this.localIdxByName[t]=e,this.params.push({type:a})}addLocal(t,a,e){const o=e||1;if(this.localIdxByName[t])throw new Error(`local already exists. Function: ${this.fnName}, Param: ${t} `);const i=this.nextLocal++;this.localIdxByName[t]=i,this.locals.push({type:a,length:o})}setReturnType(t){if(this.returnType)throw new Error(`returnType already defined. Function: ${this.fnName}`);this.returnType=t}getSignature(){return[96,...[...le(this.params.length),...this.params.map((t=>re[t.type]))],...this.returnType?[1,re[this.returnType]]:[0]]}getBody(){const t=this.locals.map((t=>[...le(t.length),re[t.type]])),a=[...le(this.locals.length),...[].concat(...t),...this.code,11];return[...le(a.length),...a]}addCode(...t){this.code.push(...[].concat(...t))}getCodeBuilder(){return new se(this)}}class ue{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([...te(1836278016),...te(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 a=this.functions.length;return this.functionIdxByName[t]=a,this.functions.push(new de(this,t,"internal")),this.nInternalFunctions++,this.functions[a]}addIimportFunction(t,a,e){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 o=e||t;const i=this.functions.length;return this.functionIdxByName[t]=i,this.functions.push(new de(this,t,"import",a,o)),this.nImportFunctions++,this.functions[i]}setMemory(t,a,e){this.memory={pagesSize:t,moduleName:a||"env",fieldName:e||"memory"}}exportFunction(t,a){const e=a||t;if(void 0===this.functionIdxByName[t])throw new Error(`Function not defined: ${t}`);const o=this.functionIdxByName[t];e!=t&&(this.functionIdxByName[e]=o),this.exports.push({exportName:e,idx:o})}addFunctionToTable(t){const a=this.functionIdxByName[t];this.functionsTable.push(a)}addData(t,a){this.datas.push({offset:t,bytes:a})}alloc(t,a){let e,o;(Array.isArray(t)||ArrayBuffer.isView(t))&&void 0===a?(e=t.length,o=t):(e=t,o=a),e=1+(e-1>>3)<<3;const i=this.free;return this.free+=e,o&&this.addData(i,o),i}allocString(t){const a=(new globalThis.TextEncoder).encode(t);return this.alloc([...a,0])}_setSignatures(){this.signatures=[];const t={};if(this.functionsTable.length>0){const a=this.functions[this.functionsTable[0]].getSignature();t["s_"+ce(a)]=0,this.signatures.push(a)}for(let a=0;a{a.pendingLoads.push({page:t,resolve:e,reject:o})}));return a.__statusPage("After Load request: ",t),e}__statusPage(t,a){const e=[],o=this;if(!o.logHistory)return;e.push("=="+t+" "+a);let i="";for(let t=0;t "+a.history[t][e][o])}_triggerLoad(){const t=this;if(t.reading)return;if(0==t.pendingLoads.length)return;const a=Object.keys(t.pages),e=[];for(let o=0;o0&&(void 0!==t.pages[t.pendingLoads[0].page]||o>0||e.length>0);){const a=t.pendingLoads.shift();if(void 0!==t.pages[a.page]){t.pages[a.page].pendingOps++;const o=e.indexOf(a.page);o>=0&&e.splice(o,1),t.pages[a.page].loading?t.pages[a.page].loading.push(a):a.resolve(),t.__statusPage("After Load (cached): ",a.page)}else{if(o)o--;else{const a=e.shift();t.__statusPage("Before Unload: ",a),t.avBuffs.unshift(t.pages[a]),delete t.pages[a],t.__statusPage("After Unload: ",a)}a.page>=t.totalPages?(t.pages[a.page]=n(),a.resolve(),t.__statusPage("After Load (new): ",a.page)):(t.reading=!0,t.pages[a.page]=n(),t.pages[a.page].loading=[a],i.push(t.fd.read(t.pages[a.page].buff,0,t.pageSize,a.page*t.pageSize).then((e=>{t.pages[a.page].size=e.bytesRead;const o=t.pages[a.page].loading;delete t.pages[a.page].loading;for(let t=0;t{a.reject(t)}))),t.__statusPage("After Load (loading): ",a.page))}}function n(){if(t.avBuffs.length>0){const a=t.avBuffs.shift();return a.dirty=!1,a.pendingOps=1,a.size=0,a}return{dirty:!1,buff:new Uint8Array(t.pageSize),pendingOps:1,size:0}}Promise.all(i).then((()=>{t.reading=!1,t.pendingLoads.length>0&&setImmediate(t._triggerLoad.bind(t)),t._tryClose()}))}_triggerWrite(){const t=this;if(t.writing)return;const a=Object.keys(t.pages),e=[];for(let o=0;o{i.writing=!1}),(a=>{console.log("ERROR Writing: "+a),t.error=a,t._tryClose()}))))}t.writing&&Promise.all(e).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,a){if(0==t.byteLength)return;const e=this;if(void 0===a&&(a=e.pos),e.pos=a+t.byteLength,e.totalSize0;){await n[l-o];const a=c+s>e.pageSize?e.pageSize-c:s,i=t.slice(t.byteLength-s,t.byteLength-s+a);new Uint8Array(e.pages[l].buff.buffer,c,a).set(i),e.pages[l].dirty=!0,e.pages[l].pendingOps--,e.pages[l].size=Math.max(c+a,e.pages[l].size),l>=e.totalPages&&(e.totalPages=l+1),s-=a,l++,c=0,e.writing||setImmediate(e._triggerWrite.bind(e))}}async read(t,a){let e=new Uint8Array(t);return await this.readToBuffer(e,0,t,a),e}async readToBuffer(t,a,e,o){if(0==e)return;const i=this;if(e>i.pageSize*i.maxPagesLoaded*.8){const t=Math.floor(1.1*e);this.maxPagesLoaded=Math.floor(t/i.pageSize)+1}if(void 0===o&&(o=i.pos),i.pos=o+e,i.pendingClose)throw new Error("Reading a closing file");const n=Math.floor(o/i.pageSize),l=Math.floor((o+e-1)/i.pageSize),c=[];for(let t=n;t<=l;t++)c.push(i._loadPage(t));i._triggerLoad();let s=n,r=o%i.pageSize,d=o+e>i.totalSize?e-(o+e-i.totalSize):e;for(;d>0;){await c[s-n],i.__statusPage("After Await (read): ",s);const o=r+d>i.pageSize?i.pageSize-r:d,l=new Uint8Array(i.pages[s].buff.buffer,i.pages[s].buff.byteOffset+r,o);t.set(l,a+e-d),i.pages[s].pendingOps--,i.__statusPage("After Op done: ",s),d-=o,s++,r=0,i.pendingLoads.length>0&&setImmediate(i._triggerLoad.bind(i))}this.pos=o+e}_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(((a,e)=>{t.pendingClose=a,t.pendingCloseReject=e,t._tryClose()})).then((()=>{t.fd.close()}),(a=>{throw t.fd.close(),a}))}async discard(){await this.close(),await pe.promises.unlink(this.fileName)}async writeULE32(t,a){const e=new Uint8Array(4);new DataView(e.buffer).setUint32(0,t,!0),await this.write(e,a)}async writeUBE32(t,a){const e=new Uint8Array(4);new DataView(e.buffer).setUint32(0,t,!1),await this.write(e,a)}async writeULE64(t,a){const e=new Uint8Array(8),o=new DataView(e.buffer);o.setUint32(0,4294967295&t,!0),o.setUint32(4,Math.floor(t/4294967296),!0),await this.write(e,a)}async readULE32(t){const a=await this.read(4,t);return new Uint32Array(a.buffer)[0]}async readUBE32(t){const a=await this.read(4,t);return new DataView(a.buffer).getUint32(0,!1)}async readULE64(t){const a=await this.read(8,t),e=new Uint32Array(a.buffer);return 4294967296*e[1]+e[0]}async readString(t){const a=this;if(a.pendingClose)throw new Error("Reading a closing file");let e=void 0===t?a.pos:t,o=Math.floor(e/a.pageSize),i=!1,n="";for(;!i;){let t=a._loadPage(o);a._triggerLoad(),await t,a.__statusPage("After Await (read): ",o);let l=e%a.pageSize;const c=new Uint8Array(a.pages[o].buff.buffer,a.pages[o].buff.byteOffset+l,a.pageSize-l);let s=c.findIndex((t=>0===t));i=-1!==s,i?(n+=(new TextDecoder).decode(c.slice(0,s)),a.pos=o*this.pageSize+l+s+1):(n+=(new TextDecoder).decode(c),a.pos=o*this.pageSize+l+c.length),a.pages[o].pendingOps--,a.__statusPage("After Op done: ",o),e=a.pos,o++,a.pendingLoads.length>0&&setImmediate(a._triggerLoad.bind(a))}return n}}const be=new Uint8Array(4),we=new DataView(be.buffer),ye=new Uint8Array(8),Ae=new DataView(ye.buffer);class Ce{constructor(){this.pageSize=16384}_resizeIfNeeded(t){if(t>this.allocSize){const a=Math.max(this.allocSize+(1<<20),Math.floor(1.1*this.allocSize),t),e=new Uint8Array(a);e.set(this.o.data),this.o.data=e,this.allocSize=a}}async write(t,a){if(void 0===a&&(a=this.pos),this.readOnly)throw new Error("Writing a read only file");this._resizeIfNeeded(a+t.byteLength),this.o.data.set(t.slice(),a),a+t.byteLength>this.totalSize&&(this.totalSize=a+t.byteLength),this.pos=a+t.byteLength}async readToBuffer(t,a,e,o){if(void 0===o&&(o=this.pos),this.readOnly&&o+e>this.totalSize)throw new Error("Reading out of bounds");this._resizeIfNeeded(o+e);const i=new Uint8Array(this.o.data.buffer,this.o.data.byteOffset+o,e);t.set(i,a),this.pos=o+e}async read(t,a){const e=new Uint8Array(t);return await this.readToBuffer(e,0,t,a),e}close(){this.o.data.byteLength!=this.totalSize&&(this.o.data=this.o.data.slice(0,this.totalSize))}async discard(){}async writeULE32(t,a){we.setUint32(0,t,!0),await this.write(be,a)}async writeUBE32(t,a){we.setUint32(0,t,!1),await this.write(be,a)}async writeULE64(t,a){Ae.setUint32(0,4294967295&t,!0),Ae.setUint32(4,Math.floor(t/4294967296),!0),await this.write(ye,a)}async readULE32(t){const a=await this.read(4,t);return new Uint32Array(a.buffer)[0]}async readUBE32(t){const a=await this.read(4,t);return new DataView(a.buffer).getUint32(0,!1)}async readULE64(t){const a=await this.read(8,t),e=new Uint32Array(a.buffer);return 4294967296*e[1]+e[0]}async readString(t){const a=this;let e=void 0===t?a.pos:t;if(e>this.totalSize){if(this.readOnly)throw new Error("Reading out of bounds");this._resizeIfNeeded(t)}const o=new Uint8Array(a.o.data.buffer,e,this.totalSize-e);let i=o.findIndex((t=>0===t)),n="";return-1!==i?(n=(new TextDecoder).decode(o.slice(0,i)),a.pos=e+i+1):a.pos=e,n}}const Fe=1<<22;const xe=new Uint8Array(4),Ie=new DataView(xe.buffer),Be=new Uint8Array(8),Ee=new DataView(Be.buffer);class ve{constructor(){this.pageSize=16384}_resizeIfNeeded(t){if(t<=this.totalSize)return;if(this.readOnly)throw new Error("Reading out of file bounds");const a=Math.floor((t-1)/Fe)+1;for(let e=Math.max(this.o.data.length-1,0);e0;){const a=i+n>Fe?Fe-i:n,l=t.slice(t.byteLength-n,t.byteLength-n+a);new Uint8Array(e.o.data[o].buffer,i,a).set(l),n-=a,o++,i=0}this.pos=a+t.byteLength}async readToBuffer(t,a,e,o){const i=this;if(void 0===o&&(o=i.pos),this.readOnly&&o+e>this.totalSize)throw new Error("Reading out of bounds");this._resizeIfNeeded(o+e);let n=Math.floor(o/Fe),l=o%Fe,c=e;for(;c>0;){const o=l+c>Fe?Fe-l:c,s=new Uint8Array(i.o.data[n].buffer,l,o);t.set(s,a+e-c),c-=o,n++,l=0}this.pos=o+e}async read(t,a){const e=new Uint8Array(t);return await this.readToBuffer(e,0,t,a),e}close(){}async discard(){}async writeULE32(t,a){Ie.setUint32(0,t,!0),await this.write(xe,a)}async writeUBE32(t,a){Ie.setUint32(0,t,!1),await this.write(xe,a)}async writeULE64(t,a){Ee.setUint32(0,4294967295&t,!0),Ee.setUint32(4,Math.floor(t/4294967296),!0),await this.write(Be,a)}async readULE32(t){const a=await this.read(4,t);return new Uint32Array(a.buffer)[0]}async readUBE32(t){const a=await this.read(4,t);return new DataView(a.buffer).getUint32(0,!1)}async readULE64(t){const a=await this.read(8,t),e=new Uint32Array(a.buffer);return 4294967296*e[1]+e[0]}async readString(t){const a=this;let e=void 0===t?a.pos:t;if(e>this.totalSize){if(this.readOnly)throw new Error("Reading out of bounds");this._resizeIfNeeded(t)}let o=!1,i="";for(;!o;){let t=Math.floor(e/Fe),n=e%Fe;if(void 0===a.o.data[t])throw new Error("ERROR");let l=Math.min(2048,a.o.data[t].length-n);const c=new Uint8Array(a.o.data[t].buffer,n,l);let s=c.findIndex((t=>0===t));o=-1!==s,o?(i+=(new TextDecoder).decode(c.slice(0,s)),a.pos=t*Fe+n+s+1):(i+=(new TextDecoder).decode(c),a.pos=t*Fe+n+c.length),e=a.pos}return i}}const Se=1024,Pe=512,qe=2,Oe=0,Ge=65536,ze=8192;async function Te(t,a,e){if("string"==typeof t&&(t={type:"file",fileName:t,cacheSize:a||Ge,pageSize:e||ze}),"file"==t.type)return await me(t.fileName,Se|Pe|qe,t.cacheSize,t.pageSize);if("mem"==t.type)return function(t){const a=t.initialSize||1<<20,e=new Ce;return e.o=t,e.o.data=new Uint8Array(a),e.allocSize=a,e.totalSize=0,e.readOnly=!1,e.pos=0,e}(t);if("bigMem"==t.type)return function(t){const a=t.initialSize||0,e=new ve;e.o=t;const o=a?Math.floor((a-1)/Fe)+1:0;e.o.data=[];for(let t=0;te)throw new Error("Version not supported");const s=await n.readULE32();let r=[];for(let t=0;t1)throw new Error(t.fileName+": Section Duplicated "+e);t.pos=a[e][0].p,t.readingSection=a[e][0]}async function De(t,a){if(void 0===t.readingSection)throw new Error("Not reading a section");if(!a&&t.pos-t.readingSection.p!=t.readingSection.size)throw new Error("Invalid section size reading");delete t.readingSection}async function $e(t,a,e,o){const i=new Uint8Array(e);fe.toRprLE(i,0,a,e),await t.write(i,o)}async function je(t,a,e){const o=await t.read(a,e);return fe.fromRprLE(o,0,a)}async function Ve(t,a,e,o,i){void 0===i&&(i=a[o][0].size);const n=t.pageSize;await Ne(t,a,o),await ke(e,o);for(let a=0;aa[e][0].size)throw new Error("Reading out of the range of the section");let n;return n=i<1<<30?new Uint8Array(i):new qa(i),await t.readToBuffer(n,0,i,a[e][0].p+o),n}async function He(t,a,e,o,i){const n=16*t.pageSize;if(await Ne(t,a,i),await Ne(e,o,i),a[i][0].size!=o[i][0].size)return!1;const l=a[i][0].size;for(let a=0;a=0)a=await _e();else{if(!(["BLS12381"].indexOf(e)>=0))throw new Error(`Curve not supported: ${t}`);a=await ge()}return a}var ao={exports:{}},eo=function t(a,e){if(!a){var o=new oo(e);throw Error.captureStackTrace&&Error.captureStackTrace(o,t),o}};class oo extends Error{}oo.prototype.name="AssertionError";var io={exports:{}};function no(t){return t.length}var lo={byteLength:no,toString:function(t){const a=t.byteLength;let e="";for(let o=0;o1&&61===t.charCodeAt(a-1)&&a--,3*a>>>2}so[45]=62,so[95]=63;var uo={byteLength:ro,toString:function(t){const a=t.byteLength;let e="";for(let o=0;o>2]+co[(3&t[o])<<4|t[o+1]>>4]+co[(15&t[o+1])<<2|t[o+2]>>6]+co[63&t[o+2]];return a%3==2?e=e.substring(0,e.length-1)+"=":a%3==1&&(e=e.substring(0,e.length-2)+"=="),e},write:function(t,a,e=0,o=ro(a)){const i=Math.min(o,t.byteLength-e);for(let e=0,o=0;o>4,t[o++]=(15&n)<<4|l>>2,t[o++]=(3&l)<<6|63&c}return i}};function _o(t){return t.length>>>1}var go={byteLength:_o,toString:function(t){const a=t.byteLength;t=new DataView(t.buffer,t.byteOffset,a);let e="",o=0;for(let i=a-a%4;o=48&&t<=57?t-48:t>=65&&t<=70?t-65+10:t>=97&&t<=102?t-97+10:void 0}function ho(t){let a=0;for(let e=0,o=t.length;e=55296&&i<=56319&&e+1=56320&&o<=57343){a+=4,e++;continue}}a+=i<=127?1:i<=2047?2:3}return a}let po,mo;if("undefined"!=typeof TextDecoder){const t=new TextDecoder;po=function(a){return t.decode(a)}}else po=function(t){const a=t.byteLength;let e="",o=0;for(;o0){let a=0;for(;a>o,o-=6;o>=0;)t[l++]=128|e>>o&63,o-=6;n+=e>=65536?2:1}return i};var Lo={byteLength:ho,toString:po,write:mo};function bo(t){return 2*t.length}var wo,yo,Ao={byteLength:bo,toString:function(t){const a=t.byteLength;let e="";for(let o=0;o>8,l=i%256;t[e+2*o]=l,t[e+2*o+1]=n}return i}};!function(t,a){const e=lo,o=uo,i=go,n=Lo,l=Ao,c=255===new Uint8Array(Uint16Array.of(255).buffer)[0];function s(t){switch(t){case"ascii":return e;case"base64":return o;case"hex":return i;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 r(t){return t instanceof Uint8Array}function d(t,a,e){return"string"==typeof t?function(t,a){const e=s(a),o=new Uint8Array(e.byteLength(t));return e.write(o,t,0,o.byteLength),o}(t,a):Array.isArray(t)?function(t){const a=new Uint8Array(t.length);return a.set(t),a}(t):ArrayBuffer.isView(t)?function(t){const a=new Uint8Array(t.byteLength);return a.set(t),a}(t):function(t,a,e){return new Uint8Array(t,a,e)}(t,a,e)}function u(t,a,e,o,i){if(0===t.byteLength)return-1;if("string"==typeof e?(o=e,e=0):void 0===e?e=i?0:t.length-1:e<0&&(e+=t.byteLength),e>=t.byteLength){if(i)return-1;e=t.byteLength-1}else if(e<0){if(!i)return-1;e=0}if("string"==typeof a)a=d(a,o);else if("number"==typeof a)return a&=255,i?t.indexOf(a,e):t.lastIndexOf(a,e);if(0===a.byteLength)return-1;if(i){let o=-1;for(let i=e;it.byteLength&&(e=t.byteLength-a.byteLength);for(let o=e;o>=0;o--){let e=!0;for(let i=0;ii)return 1}return t.byteLength>a.byteLength?1:t.byteLengtht+a.byteLength),0));const e=new Uint8Array(a);return t.reduce(((t,a)=>(e.set(a,t),t+a.byteLength)),0),e},copy:function(t,a,e=0,o=0,i=t.byteLength){if(i>0&&i=t.byteLength)throw new RangeError("sourceStart is out of range");if(i<0)throw new RangeError("sourceEnd is out of range");e>=a.byteLength&&(e=a.byteLength),i>t.byteLength&&(i=t.byteLength),a.byteLength-e=i||o<=e?"":(e<0&&(e=0),o>i&&(o=i),(0!==e||o{for(var t=new Uint8Array(128),a=0;a<64;a++)t[a<26?a+65:a<52?a+71:a<62?a-4:4*a-205]=a;return a=>{for(var e=a.length,o=new Uint8Array(3*(e-("="==a[e-1])-("="==a[e-2]))/4|0),i=0,n=0;i>4,o[n++]=c<<4|s>>2,o[n++]=s<<6|r}return o}})(),a=((t,a)=>function(){return a||(0,t[Object.keys(t)[0]])((a={exports:{}}).exports,a),a.exports})({"wasm-binary:./blake2b.wat"(a,e){e.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=")}}),e=a(),o=WebAssembly.compile(e);return wo=async t=>(await WebAssembly.instantiate(await o,t)).exports}()().then((t=>{xo=t})),Bo=64,Eo=[];ao.exports=zo;var vo=ao.exports.BYTES_MIN=16,So=ao.exports.BYTES_MAX=64;ao.exports.BYTES=32;var Po=ao.exports.KEYBYTES_MIN=16,qo=ao.exports.KEYBYTES_MAX=64;ao.exports.KEYBYTES=32;var Oo=ao.exports.SALTBYTES=16,Go=ao.exports.PERSONALBYTES=16;function zo(t,a,e,o,i){if(!(this instanceof zo))return new zo(t,a,e,o,i);if(!xo)throw new Error("WASM not loaded. Wait for Blake2b.ready(cb)");t||(t=32),!0!==i&&(Co(t>=vo,"digestLength must be at least "+vo+", was given "+t),Co(t<=So,"digestLength must be at most "+So+", was given "+t),null!=a&&(Co(a instanceof Uint8Array,"key must be Uint8Array or Buffer"),Co(a.length>=Po,"key must be at least "+Po+", was given "+a.length),Co(a.length<=qo,"key must be at least "+qo+", was given "+a.length)),null!=e&&(Co(e instanceof Uint8Array,"salt must be Uint8Array or Buffer"),Co(e.length===Oo,"salt must be exactly "+Oo+", was given "+e.length)),null!=o&&(Co(o instanceof Uint8Array,"personal must be Uint8Array or Buffer"),Co(o.length===Go,"personal must be exactly "+Go+", was given "+o.length))),Eo.length||(Eo.push(Bo),Bo+=216),this.digestLength=t,this.finalized=!1,this.pointer=Eo.pop(),this._memory=new Uint8Array(xo.memory.buffer),this._memory.fill(0,0,64),this._memory[0]=this.digestLength,this._memory[1]=a?a.length:0,this._memory[2]=1,this._memory[3]=1,e&&this._memory.set(e,32),o&&this._memory.set(o,48),this.pointer+216>this._memory.length&&this._realloc(this.pointer+216),xo.blake2b_init(this.pointer,this.digestLength),a&&(this.update(a),this._memory.fill(0,Bo,Bo+a.length),this._memory[this.pointer+200]=128)}function To(){}function Mo(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 Uo(t,a){const e=new DataView(t.buffer,t.byteOffset,t.byteLength);let o="";for(let t=0;t<4;t++){t>0&&(o+="\n"),o+="\t\t";for(let a=0;a<4;a++)a>0&&(o+=" "),o+=e.getUint32(16*t+4*a).toString(16).padStart(8,"0")}return a&&(o=a+"\n"+o),o}function Qo(t,a){if(t.byteLength!=a.byteLength)return!1;for(var e=new Int8Array(t),o=new Int8Array(a),i=0;i!=t.byteLength;i++)if(e[i]!=o[i])return!1;return!0}function ko(t){const a=t.getPartialHash(),e=ao.exports(64);return e.setPartialHash(a),e}async function Ro(t,a,e,o,i){if(t.G1.isZero(a))return!1;if(t.G1.isZero(e))return!1;if(t.G2.isZero(o))return!1;if(t.G2.isZero(i))return!1;return await t.pairingEq(a,i,t.G1.neg(e),o)}function No(t){let a=new Uint8Array(t);return void 0!==globalThis.crypto?globalThis.crypto.getRandomValues(a):U.randomFillSync(a),a}async function Do(t){if(void 0!==globalThis.crypto&&void 0!==globalThis.crypto.subtle){const a=await globalThis.crypto.subtle.digest("SHA-256",t.buffer);return new Uint8Array(a)}return U.createHash("sha256").update(t).digest()}function $o(t,a){return new DataView(t.buffer).getUint32(a,!1)}async function jo(t){for(;!t;)t=await window.prompt("Enter a random text. (Entropy): ","");const a=ao.exports(64);a.update(No(64));const e=new TextEncoder;a.update(e.encode(t));const o=a.digest(),i=[];for(let t=0;t<8;t++)i[t]=$o(o,4*t);return new M(i)}async function Vo(t,a){let e,o;a<32?(e=1<
>>0,o=1):(e=4294967296,o=1<>>0);let i=t;for(let t=0;t{e[o]=Zo(t,a[o])})),e}return"bigint"==typeof a||void 0!==a.eq?a.toString(10):a}zo.prototype._realloc=function(t){xo.memory.grow(Math.max(0,Math.ceil(Math.abs(t-this._memory.length)/65536))),this._memory=new Uint8Array(xo.memory.buffer)},zo.prototype.update=function(t){return Co(!1===this.finalized,"Hash instance finalized"),Co(t instanceof Uint8Array,"input must be Uint8Array or Buffer"),Bo+t.length>this._memory.length&&this._realloc(Bo+t.length),this._memory.set(t,Bo),xo.blake2b_update(this.pointer,Bo,Bo+t.length),this},zo.prototype.digest=function(t){if(Co(!1===this.finalized,"Hash instance finalized"),this.finalized=!0,Eo.push(this.pointer),xo.blake2b_final(this.pointer),!t||"binary"===t)return this._memory.slice(this.pointer+128,this.pointer+128+this.digestLength);if("string"==typeof t)return Fo.toString(this._memory,t,this.pointer+128,this.pointer+128+this.digestLength);Co(t instanceof Uint8Array&&t.length>=this.digestLength,"input must be Uint8Array or Buffer");for(var a=0;at()),t):t(new Error("WebAssembly not supported"))},zo.prototype.ready=zo.ready,zo.prototype.getPartialHash=function(){return this._memory.slice(this.pointer,this.pointer+216)},zo.prototype.setPartialHash=function(t){this._memory.set(t,this.pointer)};const Wo=1,Yo=1,Jo=2,Xo=10,ti=3,ai=17,ei=2,oi=3,ii=4,ni=5,li=6,ci=7,si=8,ri=9,di=10,ui=11,_i=12,gi=13,fi=14,hi=15,pi=16,mi=17;async function Li(t,a){await ke(t,1),await t.writeULE32(1),await Re(t);const e=await Xe(a.q);await ke(t,2);const o=e.q,i=8*(Math.floor((fe.bitLength(o)-1)/64)+1),n=e.r,l=8*(Math.floor((fe.bitLength(n)-1)/64)+1);await t.writeULE32(i),await $e(t,o,i),await t.writeULE32(l),await $e(t,n,l),await t.writeULE32(a.nVars),await t.writeULE32(a.nPublic),await t.writeULE32(a.domainSize),await bi(t,e,a.vk_alpha_1),await bi(t,e,a.vk_beta_1),await wi(t,e,a.vk_beta_2),await wi(t,e,a.vk_gamma_2),await bi(t,e,a.vk_delta_1),await wi(t,e,a.vk_delta_2),await Re(t)}async function bi(t,a,e){const o=new Uint8Array(2*a.G1.F.n8);a.G1.toRprLEM(o,0,e),await t.write(o)}async function wi(t,a,e){const o=new Uint8Array(2*a.G2.F.n8);a.G2.toRprLEM(o,0,e),await t.write(o)}async function yi(t,a,e){const o=await t.read(2*a.G1.F.n8),i=a.G1.fromRprLEM(o,0);return e?a.G1.toObject(i):i}async function Ai(t,a,e){const o=await t.read(2*a.G2.F.n8),i=a.G2.fromRprLEM(o,0);return e?a.G2.toObject(i):i}async function Ci(t,a,e){await Ne(t,a,1);const o=await t.readULE32();if(await De(t),o===Yo)return await async function(t,a,e){const o={protocol:"groth16"};await Ne(t,a,2);const i=await t.readULE32();o.n8q=i,o.q=await je(t,i);const n=await t.readULE32();return o.n8r=n,o.r=await je(t,n),o.curve=await Xe(o.q),o.nVars=await t.readULE32(),o.nPublic=await t.readULE32(),o.domainSize=await t.readULE32(),o.power=Mo(o.domainSize),o.vk_alpha_1=await yi(t,o.curve,e),o.vk_beta_1=await yi(t,o.curve,e),o.vk_beta_2=await Ai(t,o.curve,e),o.vk_gamma_2=await Ai(t,o.curve,e),o.vk_delta_1=await yi(t,o.curve,e),o.vk_delta_2=await Ai(t,o.curve,e),await De(t),o}(t,a,e);if(o===Jo)return await async function(t,a,e){const o={protocol:"plonk"};await Ne(t,a,2);const i=await t.readULE32();o.n8q=i,o.q=await je(t,i);const n=await t.readULE32();return o.n8r=n,o.r=await je(t,n),o.curve=await Xe(o.q),o.nVars=await t.readULE32(),o.nPublic=await t.readULE32(),o.domainSize=await t.readULE32(),o.power=Mo(o.domainSize),o.nAdditions=await t.readULE32(),o.nConstraints=await t.readULE32(),o.k1=await t.read(n),o.k2=await t.read(n),o.Qm=await yi(t,o.curve,e),o.Ql=await yi(t,o.curve,e),o.Qr=await yi(t,o.curve,e),o.Qo=await yi(t,o.curve,e),o.Qc=await yi(t,o.curve,e),o.S1=await yi(t,o.curve,e),o.S2=await yi(t,o.curve,e),o.S3=await yi(t,o.curve,e),o.X_2=await Ai(t,o.curve,e),await De(t),o}(t,a,e);if(o===Xo)return await async function(t,a,e){const o={protocol:"fflonk"};o.protocolId=Xo,await Ne(t,a,ei);const i=await t.readULE32();o.n8q=i,o.q=await je(t,i),o.curve=await Xe(o.q);const n=await t.readULE32();return o.n8r=n,o.r=await je(t,n),o.nVars=await t.readULE32(),o.nPublic=await t.readULE32(),o.domainSize=await t.readULE32(),o.power=Mo(o.domainSize),o.nAdditions=await t.readULE32(),o.nConstraints=await t.readULE32(),o.k1=await t.read(n),o.k2=await t.read(n),o.w3=await t.read(n),o.w4=await t.read(n),o.w8=await t.read(n),o.wr=await t.read(n),o.X_2=await Ai(t,o.curve,e),o.C0=await yi(t,o.curve,e),await De(t),o}(t,a,e);throw new Error("Protocol not supported: ")}async function Fi(t,a,e){const o={delta:{}};o.deltaAfter=await yi(t,a,e),o.delta.g1_s=await yi(t,a,e),o.delta.g1_sx=await yi(t,a,e),o.delta.g2_spx=await Ai(t,a,e),o.transcript=await t.read(64),o.type=await t.readULE32();const i=await t.readULE32(),n=t.pos;let l=0;for(;t.pos-n0){const a=new Uint8Array(o);await t.writeULE32(a.byteLength),await t.write(a)}else await t.writeULE32(0)}async function Bi(t,a,e){await ke(t,10),await t.write(e.csHash),await t.writeULE32(e.contributions.length);for(let o=0;o0;)e.unshift(0),n--;return e}const Ti=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4];function Mi(t,a){return a&&10!=a?16==a?"0x"==t.slice(0,2)?BigInt(t):BigInt("0x"+t):void 0:BigInt(t)}const Ui=Mi;function Qi(t){const a=t.toString(16);return 4*(a.length-1)+Ti[parseInt(a[0],16)]}function ki(t){return!t}function Ri(t,a){return BigInt(t)<>BigInt(a)}const Di=Ri,$i=Ni;function ji(t){return(BigInt(t)&BigInt(1))==BigInt(1)}function Vi(t){let a=BigInt(t);const e=[];for(;a;)a&BigInt(1)?e.push(1):e.push(0),a>>=BigInt(1);return e}function Ki(t){if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("Number too big");return Number(t)}function Hi(t,a){return BigInt(t)-BigInt(a)}function Zi(t,a){return BigInt(t)**BigInt(a)}function Wi(t,a){return BigInt(t)/BigInt(a)}function Yi(t,a){return BigInt(t)%BigInt(a)}function Ji(t,a){return BigInt(t)==BigInt(a)}function Xi(t,a){return BigInt(t)&BigInt(a)}function tn(t,a,e,o){const i="0000000"+e.toString(16),n=new Uint32Array(t.buffer,a,o/4),l=1+(4*(i.length-7)-1>>5);for(let t=0;t>5);for(let t=0;ti[i.length-a-1]=t.toString(16).padStart(8,"0"))),Mi(i.join(""),16)}function on(t,a,e){e=e||t.byteLength,a=a||0;const o=new DataView(t.buffer,t.byteOffset+a,e),i=new Array(e/4);for(let t=0;t>=BigInt(1)}return e},bits:Vi,toNumber:Ki,toArray:function(t,a){const e=[];let o=BigInt(t);for(a=BigInt(a);o;)e.unshift(Number(o%a)),o/=a;return e},add:function(t,a){return BigInt(t)+BigInt(a)},sub:Hi,neg:function(t){return-BigInt(t)},mul:function(t,a){return BigInt(t)*BigInt(a)},square:function(t){return BigInt(t)*BigInt(t)},pow:Zi,exp:function(t,a){return BigInt(t)**BigInt(a)},abs:function(t){return BigInt(t)>=0?BigInt(t):-BigInt(t)},div:Wi,mod:Yi,eq:Ji,neq:function(t,a){return BigInt(t)!=BigInt(a)},lt:function(t,a){return BigInt(t)BigInt(a)},leq:function(t,a){return BigInt(t)<=BigInt(a)},geq:function(t,a){return BigInt(t)>=BigInt(a)},band:Xi,bor:function(t,a){return BigInt(t)|BigInt(a)},bxor:function(t,a){return BigInt(t)^BigInt(a)},land:function(t,a){return BigInt(t)&&BigInt(a)},lor:function(t,a){return BigInt(t)||BigInt(a)},lnot:function(t){return!BigInt(t)},toRprLE:tn,toRprBE:an,fromRprLE:en,fromRprBE:on,toString:function(t,a){return t.toString(a)},toLEBuff:function(t){const a=new Uint8Array(Math.floor((Qi(t)-1)/8)+1);return tn(a,0,t,a.byteLength),a},zero:nn,one:ln});function sn(t,a,e){if(ki(e))return t.one;const o=Vi(e);if(0==o.length)return t.one;let i=a;for(let e=o.length-2;e>=0;e--)i=t.square(i),o[e]&&(i=t.mul(i,a));return i}function rn(t){if(t.m%2==1)if(Ji(Yi(t.p,4),1))if(Ji(Yi(t.p,8),1))if(Ji(Yi(t.p,16),1))!function(t){t.sqrt_q=Zi(t.p,t.m),t.sqrt_s=0,t.sqrt_t=Hi(t.sqrt_q,1);for(;!ji(t.sqrt_t);)t.sqrt_s=t.sqrt_s+1,t.sqrt_t=Wi(t.sqrt_t,2);let a=t.one;for(;t.eq(a,t.one);){const e=t.random();t.sqrt_z=t.pow(e,t.sqrt_t),a=t.pow(t.sqrt_z,2**(t.sqrt_s-1))}t.sqrt_tm1d2=Wi(Hi(t.sqrt_t,1),2),t.sqrt=function(t){const a=this;if(a.isZero(t))return a.zero;let e=a.pow(t,a.sqrt_tm1d2);const o=a.pow(a.mul(a.square(e),t),2**(a.sqrt_s-1));if(a.eq(o,a.negone))return null;let i=a.sqrt_s,n=a.mul(t,e),l=a.mul(n,e),c=a.sqrt_z;for(;!a.eq(l,a.one);){let t=a.square(l),o=1;for(;!a.eq(t,a.one);)t=a.square(t),o++;e=c;for(let t=0;t>>0;return a}class un{constructor(t,a,e){this.F=a,this.G=t,this.opMulGF=e;let o=a.sqrt_t||a.t,i=a.sqrt_s||a.s,n=a.one;for(;a.eq(a.pow(n,a.half),a.one);)n=a.add(n,a.one);this.w=new Array(i+1),this.wi=new Array(i+1),this.w[i]=this.F.pow(n,o),this.wi[i]=this.F.inv(this.w[i]);let l=i-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(i,15))}_setRoots(t){for(let a=t;a>=0&&!this.roots[a];a--){let t=this.F.one;const e=1<>1,c=gn(t,a,e-1,o,2*i),s=gn(t,a,e-1,o+i,2*i),r=new Array(n);for(let a=0;a>this.one,this.bitLength=Qi(this.p),this.mask=(this.one<>this.one;this.nqr=this.two;let e=this.pow(this.nqr,a);for(;!this.eq(e,this.negone);)this.nqr=this.nqr+this.one,e=this.pow(this.nqr,a);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),rn(this),this.FFT=new un(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,a){let e;if(a?16==a&&(e=BigInt("0x"+t)):e=BigInt(t),e<0){let t=-e;return t>=this.p&&(t%=this.p),this.p-t}return e>=this.p?e%this.p:e}add(t,a){const e=t+a;return e>=this.p?e-this.p:e}sub(t,a){return t>=a?t-a:this.p-a+t}neg(t){return t?this.p-t:t}mul(t,a){return t*a%this.p}mulScalar(t,a){return t*this.e(a)%this.p}square(t){return t*t%this.p}eq(t,a){return t==a}neq(t,a){return t!=a}lt(t,a){return(t>this.half?t-this.p:t)<(a>this.half?a-this.p:a)}gt(t,a){return(t>this.half?t-this.p:t)>(a>this.half?a-this.p:a)}leq(t,a){return(t>this.half?t-this.p:t)<=(a>this.half?a-this.p:a)}geq(t,a){return(t>this.half?t-this.p:t)>=(a>this.half?a-this.p:a)}div(t,a){return this.mul(t,this.inv(a))}idiv(t,a){if(!a)throw new Error("Division by zero");return t/a}inv(t){if(!t)throw new Error("Division by zero");let a=this.zero,e=this.p,o=this.one,i=t%this.p;for(;i;){let t=e/i;[a,o]=[o,a-t*o],[e,i]=[i,e-t*i]}return a=this.p?e-this.p:e}bor(t,a){const e=(t|a)&this.mask;return e>=this.p?e-this.p:e}bxor(t,a){const e=(t^a)&this.mask;return e>=this.p?e-this.p:e}bnot(t){const a=t^this.mask;return a>=this.p?a-this.p:a}shl(t,a){if(Number(a)=this.p?e-this.p:e}{const e=this.p-a;return Number(e)>e:this.zero}}shr(t,a){if(Number(a)>a;{const e=this.p-a;if(Number(e)=this.p?a-this.p:a}return 0}}land(t,a){return t&&a?this.one:this.zero}lor(t,a){return t||a?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 a=this.s,e=this.nqr_to_t,o=this.pow(t,this.t),i=this.pow(t,this.add(this.t,this.one)>>this.one);for(;o!=this.one;){let t=this.square(o),n=1;for(;t!=this.one;)n++,t=this.square(t);let l=e;for(let t=0;tthis.p>>this.one&&(i=this.neg(i)),i}normalize(t,a){if((t=BigInt(t,a))<0){let a=-t;return a>=this.p&&(a%=this.p),this.p-a}return t>=this.p?t%this.p:t}random(){const t=2*this.bitLength/8;let a=this.zero;for(let e=0;ethis.half&&10==a){e="-"+(this.p-t).toString(a)}else e=t.toString(a);return e}isZero(t){return t==this.zero}fromRng(t){let a;do{a=this.zero;for(let e=0;e=this.p);return a=a*this.Ri%this.p,a}fft(t){return this.FFT.fft(t)}ifft(t){return this.FFT.ifft(t)}toRprLE(t,a,e){tn(t,a,e,8*this.n64)}toRprBE(t,a,e){an(t,a,e,8*this.n64)}toRprBEM(t,a,e){return this.toRprBE(t,a,this.mul(this.R,e))}toRprLEM(t,a,e){return this.toRprLE(t,a,this.mul(this.R,e))}fromRprLE(t,a){return en(t,a,this.n8)}fromRprBE(t,a){return on(t,a,this.n8)}fromRprLEM(t,a){return this.mul(this.fromRprLE(t,a),this.Ri)}fromRprBEM(t,a){return this.mul(this.fromRprBE(t,a),this.Ri)}toObject(t){return t}}!function(t){globalThis.btoa(t)}("("+function(t){const a=32767;let e,o;async function i(t){const i=new Uint8Array(t.code),n=await WebAssembly.compile(i);o=new WebAssembly.Memory({initial:t.init,maximum:a}),e=await WebAssembly.instantiate(n,{env:{memory:o}})}function n(t){const e=new Uint32Array(o.buffer,0,1);for(;3&e[0];)e[0]++;const i=e[0];if(e[0]+=t,e[0]+t>o.buffer.byteLength){const i=o.buffer.byteLength/65536;let n=Math.floor((e[0]+t)/65536)+1;n>a&&(n=a),o.grow(n-i)}return i}function l(t){const a=n(t.byteLength);return s(a,t),a}function c(t,a){const e=new Uint8Array(o.buffer);return new Uint8Array(e.buffer,e.byteOffset+t,a)}function s(t,a){new Uint8Array(o.buffer).set(new Uint8Array(a),t)}function r(t){if("INIT"==t[0].cmd)return i(t[0]);const a={vars:[],out:[]},r=new Uint32Array(o.buffer,0,1)[0];for(let o=0;o=2&&(d>=1||u>=7)){""!==s&&(s+=" ");const t=hn.fromArray(a,4294967296).toString();s+=t}else console.log(hn.fromArray(a,4294967296))},error:function(t,e,o,i,n,c){let s;throw s=7==t?h(e)+" "+l.getFr(i).toString()+" != "+l.getFr(n).toString()+" "+h(c):9==t?h(e)+" "+l.getFr(i).toString()+" "+h(n):5==t&&a.sym?h(e)+" "+a.sym.labelIdx2Name[n]:h(e)+" "+o+" "+i+" "+n+" "+c,console.log("ERROR: ",t,s),new Error(s)},log:function(t){console.log(l.getFr(t).toString())},logGetSignal:function(t,e){a.logGetSignal&&a.logGetSignal(t,l.getFr(e))},logSetSignal:function(t,e){a.logSetSignal&&a.logSetSignal(t,l.getFr(e))},logStartComponent:function(t){a.logStartComponent&&a.logStartComponent(t)},logFinishComponent:function(t){a.logFinishComponent&&a.logFinishComponent(t)}}});"function"==typeof _.exports.getVersion&&(r=_.exports.getVersion()),"function"==typeof _.exports.getMinorVersion&&(d=_.exports.getMinorVersion()),"function"==typeof _.exports.getPatchVersion&&(u=_.exports.getPatchVersion());const g=a&&(a.sanityCheck||a.logGetSignal||a.logSetSignal||a.logStartComponent||a.logFinishComponent);return l=2===r?new Ln(_,g):new mn(e,_,g),l;function f(){for(var t="",a=_.exports.getMessageChar();0!=a;)t+=String.fromCharCode(a),a=_.exports.getMessageChar();return t}function h(t){const a=new Uint8Array(e.buffer),o=[];for(let e=0;a[t+e]>0;e++)o.push(a[t+e]);return String.fromCharCode.apply(null,o)}}class mn{constructor(t,a,e){this.memory=t,this.i32=new Uint32Array(t.buffer),this.instance=a,this.n32=(this.instance.exports.getFrLen()>>2)-2;const o=this.instance.exports.getPRawPrime(),i=new Array(this.n32);for(let t=0;t>2)+t];this.prime=hn.fromArray(i,4294967296),this.Fr=new fn(this.prime),this.mask32=hn.fromString("FFFFFFFF",16),this.NVars=this.instance.exports.getNVars(),this.n64=Math.floor((this.Fr.bitLength-1)/64)+1,this.R=this.Fr.e(hn.shiftLeft(1,64*this.n64)),this.RInv=this.Fr.inv(this.R),this.sanityCheck=e}circom_version(){return 1}async _doCalculateWitness(t,a){this.instance.exports.init(this.sanityCheck||a?1:0);const e=this.allocInt(),o=this.allocFr();Object.keys(t).forEach((a=>{const i=Gi(a),n=parseInt(i.slice(0,8),16),l=parseInt(i.slice(8,16),16);try{this.instance.exports.getSignalOffset32(e,0,n,l)}catch(t){throw new Error(`Signal ${a} is not an input of the circuit.`)}const c=this.getInt(e),s=Oi(t[a]);for(let t=0;t>2]}setInt(t,a){this.i32[t>>2]=a}getFr(t){const a=this,e=t>>2;if(2147483648&a.i32[e+1]){const t=new Array(a.n32);for(let o=0;o>2]=i,void(e.i32[1+(t>>2)]=0)}e.i32[t>>2]=0,e.i32[1+(t>>2)]=2147483648;const n=hn.toArray(a,4294967296);for(let a=0;a>2)+a]=o>=0?n[o]:0}}}class Ln{constructor(t,a){this.instance=t,this.version=this.instance.exports.getVersion(),this.n32=this.instance.exports.getFieldNumLen32(),this.instance.exports.getRawPrime();const e=new Array(this.n32);for(let t=0;t{const e=Gi(a),i=parseInt(e.slice(0,8),16),n=parseInt(e.slice(8,16),16),l=Oi(t[a]);for(let t=0;t1)throw new Error(t.fileName+": File has more than one header");t.pos=a[1][0].p;const e=await t.readULE32(),o=await t.read(e),i=fe.fromRprLE(o),n=await Xe(i);if(8*n.F1.n64!=e)throw new Error(t.fileName+": Invalid size");const l=await t.readULE32(),c=await t.readULE32();if(t.pos-a[1][0].p!=a[1][0].size)throw new Error("Invalid PTau header size");return{curve:n,power:l,ceremonyPower:c}}function qn(t,a,e,o){const i={tau:{},alpha:{},beta:{}};return 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=n(),i.tau.g2_spx=l(),i.alpha.g2_spx=l(),i.beta.g2_spx=l(),i;function n(){let i;return i=o?e.G1.fromRprLEM(t,a):e.G1.fromRprUncompressed(t,a),a+=2*e.G1.F.n8,i}function l(){let i;return i=o?e.G2.fromRprLEM(t,a):e.G2.fromRprUncompressed(t,a),a+=2*e.G2.F.n8,i}}function On(t,a,e,o,i){async function n(o){i?e.G1.toRprLEM(t,a,o):e.G1.toRprUncompressed(t,a,o),a+=2*e.F1.n8}async function l(o){i?e.G2.toRprLEM(t,a,o):e.G2.toRprUncompressed(t,a,o),a+=2*e.F2.n8}return n(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),l(o.tau.g2_spx),l(o.alpha.g2_spx),l(o.beta.g2_spx),t}async function Gn(t,a){const e={};e.tauG1=await s(),e.tauG2=await r(),e.alphaG1=await s(),e.betaG1=await s(),e.betaG2=await r(),e.key=await async function(t,a,e){return qn(await t.read(2*a.F1.n8*6+2*a.F2.n8*3),0,a,e)}(t,a,!0),e.partialHash=await t.read(216),e.nextChallenge=await t.read(64),e.type=await t.readULE32();const o=new Uint8Array(2*a.G1.F.n8*6+2*a.G2.F.n8*3);On(o,0,a,e.key,!1);const i=ao.exports(64);i.setPartialHash(e.partialHash),i.update(o),e.responseHash=i.digest();const n=await t.readULE32(),l=t.pos;let c=0;for(;t.pos-l1)throw new Error(t.fileName+": File has more than one contributions section");t.pos=e[7][0].p;const o=await t.readULE32(),i=[];for(let e=0;e0){const a=new Uint8Array(n);await t.writeULE32(a.byteLength),await t.write(a)}else await t.writeULE32(0);async function l(e){a.G1.toRprLEM(o,0,e),await t.write(o)}async function c(e){a.G2.toRprLEM(i,0,e),await t.write(i)}}async function Mn(t,a,e){await t.writeULE32(7);const o=t.pos;await t.writeULE64(0),await t.writeULE32(e.length);for(let o=0;o0?u[u.length-1].nextChallenge:Un(r,d,n);const b=await Qe(e,"ptau",1,i?7:2);await Sn(b,r,d);const w=await m.read(64);if(Qo(l,L)&&(L=w,u[u.length-1].nextChallenge=L),!Qo(w,L))throw new Error("Wrong contribution. this contribution is not based on the previus hash");const y=new ao.exports(64);y.update(w);const A=[];let C;C=await I(m,b,"G1",2,2**d*2-1,[1],"tauG1"),_.tauG1=C[0],C=await I(m,b,"G2",3,2**d,[1],"tauG2"),_.tauG2=C[0],C=await I(m,b,"G1",4,2**d,[0],"alphaG1"),_.alphaG1=C[0],C=await I(m,b,"G1",5,2**d,[0],"betaG1"),_.betaG1=C[0],C=await I(m,b,"G2",6,1,[0],"betaG2"),_.betaG2=C[0],_.partialHash=y.getPartialHash();const F=await m.read(2*r.F1.n8*6+2*r.F2.n8*3);_.key=qn(F,0,r,!1),y.update(new Uint8Array(F));const x=y.digest();if(n&&n.info(Uo(x,"Contribution Response Hash imported: ")),i){const t=new ao.exports(64);t.update(x),await B(t,b,"G1",2,2**d*2-1,"tauG1",n),await B(t,b,"G2",3,2**d,"tauG2",n),await B(t,b,"G1",4,2**d,"alphaTauG1",n),await B(t,b,"G1",5,2**d,"betaTauG1",n),await B(t,b,"G2",6,1,"betaG2",n),_.nextChallenge=t.digest(),n&&n.info(Uo(_.nextChallenge,"Next Challenge Hash: "))}else _.nextChallenge=l;return u.push(_),await Mn(b,r,u),await m.close(),await b.close(),await c.close(),_.nextChallenge;async function I(t,a,e,o,l,c,s){return i?await async function(t,a,e,o,i,l,c){const s=r[e],d=s.F.n8,u=2*s.F.n8,_=[];await ke(a,o);const g=Math.floor((1<<24)/u);A[o]=a.pos;for(let e=0;e=e&&a=a&&i1?s[s.length-2]:r;const u=s[s.length-1];if(a&&a.debug("Validating contribution #"+s[s.length-1].id),!await Rn(n,u,d,a))return!1;const _=ao.exports(64);_.update(u.responseHash),a&&a.debug("Verifying powers in tau*G1 section");const g=await w(2,"G1","tauG1",2**l*2-1,[0,1],a);if(e=await kn(n,g.R1,g.R2,n.G2.g,u.tauG2),!0!==e)return a&&a.error("tauG1 section. Powers do not match"),!1;if(!n.G1.eq(n.G1.g,g.singularPoints[0]))return a&&a.error("First element of tau*G1 section must be the generator"),!1;if(!n.G1.eq(u.tauG1,g.singularPoints[1]))return a&&a.error("Second element of tau*G1 section does not match the one in the contribution section"),!1;a&&a.debug("Verifying powers in tau*G2 section");const f=await w(3,"G2","tauG2",2**l,[0,1],a);if(e=await kn(n,n.G1.g,u.tauG1,f.R1,f.R2),!0!==e)return a&&a.error("tauG2 section. Powers do not match"),!1;if(!n.G2.eq(n.G2.g,f.singularPoints[0]))return a&&a.error("First element of tau*G2 section must be the generator"),!1;if(!n.G2.eq(u.tauG2,f.singularPoints[1]))return a&&a.error("Second element of tau*G2 section does not match the one in the contribution section"),!1;a&&a.debug("Verifying powers in alpha*tau*G1 section");const h=await w(4,"G1","alphatauG1",2**l,[0],a);if(e=await kn(n,h.R1,h.R2,n.G2.g,u.tauG2),!0!==e)return a&&a.error("alphaTauG1 section. Powers do not match"),!1;if(!n.G1.eq(u.alphaG1,h.singularPoints[0]))return a&&a.error("First element of alpha*tau*G1 section (alpha*G1) does not match the one in the contribution section"),!1;a&&a.debug("Verifying powers in beta*tau*G1 section");const p=await w(5,"G1","betatauG1",2**l,[0],a);if(e=await kn(n,p.R1,p.R2,n.G2.g,u.tauG2),!0!==e)return a&&a.error("betaTauG1 section. Powers do not match"),!1;if(!n.G1.eq(u.betaG1,p.singularPoints[0]))return a&&a.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 a=n.G2,e=2*a.F.n8,l=new Uint8Array(e);if(!i[6])throw t.error("File has no BetaG2 section"),new Error("File has no BetaG2 section");if(i[6].length>1)throw t.error("File has no BetaG2 section"),new Error("File has more than one GetaG2 section");o.pos=i[6][0].p;const c=await o.read(e),s=a.fromRprLEM(c);return a.toRprUncompressed(l,0,s),_.update(l),s}(a);if(!n.G2.eq(u.betaG2,m))return a&&a.error("betaG2 element in betaG2 section does not match the one in the contribution section"),!1;const L=_.digest();if(l==c&&!Qo(L,u.nextChallenge))return a&&a.error("Hash of the values does not match the next challenge of the last contributor in the contributions section"),!1;a&&a.info(Uo(L,"Next challenge hash: ")),b(u,d);for(let t=s.length-2;t>=0;t--){const e=s[t],o=t>0?s[t-1]:r;if(!await Rn(n,e,o,a))return!1;b(e,o)}if(a&&a.info("-----------------------------------------------------"),i[12]&&i[13]&&i[14]&&i[15]){let t;if(t=await y("G1",2,12,"tauG1",a),!t)return!1;if(t=await y("G2",3,13,"tauG2",a),!t)return!1;if(t=await y("G1",4,14,"alphaTauG1",a),!t)return!1;if(t=await y("G1",5,15,"betaTauG1",a),!t)return!1}else a&&a.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 o.close(),a&&a.info("Powers of Tau Ok!"),!0;function b(t,e){if(!a)return;a.info("-----------------------------------------------------"),a.info(`Contribution #${t.id}: ${t.name||""}`),a.info(Uo(t.nextChallenge,"Next Challenge: "));const o=new Uint8Array(2*n.G1.F.n8*6+2*n.G2.F.n8*3);On(o,0,n,t.key,!1);const i=ao.exports(64);i.setPartialHash(t.partialHash),i.update(o);const l=i.digest();a.info(Uo(l,"Response Hash:")),a.info(Uo(e.nextChallenge,"Response Hash:")),1==t.type&&(a.info(`Beacon generator: ${Ho(t.beaconHash)}`),a.info(`Beacon iterations Exp: ${t.numIterationsExp}`))}async function w(t,a,e,l,c,s){const r=n[a],d=2*r.F.n8;await Ne(o,i,t);const u=[];let g=r.zero,f=r.zero,h=r.zero;for(let t=0;t0){const t=r.fromRprLEM(i,0),a=$o(No(4),0);g=r.add(g,r.timesScalar(h,a)),f=r.add(f,r.timesScalar(t,a))}const m=await r.multiExpAffine(i.slice(0,(a-1)*d),p),L=await r.multiExpAffine(i.slice(d),p);g=r.add(g,m),f=r.add(f,L),h=r.fromRprLEM(i,(a-1)*d);for(let e=0;e=t&&o1;)r/=2,d+=1;if(2**d!=s)throw new Error("Invalid file size");i&&i.debug("Power to tau size: "+d);const u=await jo(o),_=await Te(e),g=ao.exports(64);for(let t=0;t{i.debug(a+".g1_s: "+t.G1.toString(p[a].g1_s,16)),i.debug(a+".g1_sx: "+t.G1.toString(p[a].g1_sx,16)),i.debug(a+".g2_sp: "+t.G2.toString(p[a].g2_sp,16)),i.debug(a+".g2_spx: "+t.G2.toString(p[a].g2_spx,16)),i.debug("")}));const m=ao.exports(64);await _.write(h),m.update(h),await Dn(n,_,m,t,"G1",2**d*2-1,t.Fr.one,p.tau.prvKey,"COMPRESSED","tauG1",i),await Dn(n,_,m,t,"G2",2**d,t.Fr.one,p.tau.prvKey,"COMPRESSED","tauG2",i),await Dn(n,_,m,t,"G1",2**d,p.alpha.prvKey,p.tau.prvKey,"COMPRESSED","alphaTauG1",i),await Dn(n,_,m,t,"G1",2**d,p.beta.prvKey,p.tau.prvKey,"COMPRESSED","betaTauG1",i),await Dn(n,_,m,t,"G2",1,p.beta.prvKey,p.tau.prvKey,"COMPRESSED","betaTauG2",i);const L=new Uint8Array(2*t.F1.n8*6+2*t.F2.n8*3);On(L,0,t,p,!1),await _.write(L),m.update(L);const b=m.digest();i&&i.info(Uo(b,"Contribution Response Hash: ")),await _.close(),await n.close()},beacon:async function(t,a,e,o,i,n){const l=Ko(o);if(0==l.byteLength||2*l.byteLength!=o.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((i=parseInt(i))<10||i>63)return n&&n.error("Invalid numIterationsExp. (Must be between 10 and 63)"),!1;await ao.exports.ready();const{fd:c,sections:s}=await Ue(t,"ptau",1),{curve:r,power:d,ceremonyPower:u}=await Pn(c,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 _=await zn(c,r,s),g={name:e,type:1,numIterationsExp:i,beaconHash:l};let f;f=_.length>0?_[_.length-1].nextChallenge:Un(r,d,n),g.key=await Qn(r,f,l,i);const h=new ao.exports(64);h.update(f);const p=await Qe(a,"ptau",1,7);await Sn(p,r,d);const m=[];let L;L=await A(2,"G1",2**d*2-1,r.Fr.e(1),g.key.tau.prvKey,"tauG1",n),g.tauG1=L[1],L=await A(3,"G2",2**d,r.Fr.e(1),g.key.tau.prvKey,"tauG2",n),g.tauG2=L[1],L=await A(4,"G1",2**d,g.key.alpha.prvKey,g.key.tau.prvKey,"alphaTauG1",n),g.alphaG1=L[0],L=await A(5,"G1",2**d,g.key.beta.prvKey,g.key.tau.prvKey,"betaTauG1",n),g.betaG1=L[0],L=await A(6,"G2",1,g.key.beta.prvKey,g.key.tau.prvKey,"betaTauG2",n),g.betaG2=L[0],g.partialHash=h.getPartialHash();const b=new Uint8Array(2*r.F1.n8*6+2*r.F2.n8*3);On(b,0,r,g.key,!1),h.update(new Uint8Array(b));const w=h.digest();n&&n.info(Uo(w,"Contribution Response Hash imported: "));const y=new ao.exports(64);return y.update(w),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),g.nextChallenge=y.digest(),n&&n.info(Uo(g.nextChallenge,"Next Challenge Hash: ")),_.push(g),await Mn(p,r,_),await c.close(),await p.close(),w;async function A(t,a,e,o,i,n,l){const d=[];c.pos=s[t][0].p,await ke(p,t),m[t]=p.pos;const u=r[a],_=2*u.F.n8,g=Math.floor((1<<20)/_);let f=o;for(let t=0;t0?d[d.length-1].nextChallenge:Un(c,s,i),u.key=vn(c,_,g);const f=new ao.exports(64);f.update(_);const h=await Qe(a,"ptau",1,7);await Sn(h,c,s);const p=[];let m;m=await y(2,"G1",2**s*2-1,c.Fr.e(1),u.key.tau.prvKey,"tauG1"),u.tauG1=m[1],m=await y(3,"G2",2**s,c.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=f.getPartialHash();const L=new Uint8Array(2*c.F1.n8*6+2*c.F2.n8*3);On(L,0,c,u.key,!1),f.update(new Uint8Array(L));const b=f.digest();i&&i.info(Uo(b,"Contribution Response Hash imported: "));const w=new ao.exports(64);return w.update(b),await A(h,"G1",2,2**s*2-1,"tauG1"),await A(h,"G2",3,2**s,"tauG2"),await A(h,"G1",4,2**s,"alphaTauG1"),await A(h,"G1",5,2**s,"betaTauG1"),await A(h,"G2",6,1,"betaG2"),u.nextChallenge=w.digest(),i&&i.info(Uo(u.nextChallenge,"Next Challenge Hash: ")),d.push(u),await Mn(h,c,d),await n.close(),await h.close(),b;async function y(t,a,e,o,s,r){const d=[];n.pos=l[t][0].p,await ke(h,t),p[t]=h.pos;const u=c[a],_=2*u.F.n8,g=Math.floor((1<<20)/_);let m=o;for(let t=0;t>BigInt(a)}function Yn(t){return(BigInt(t)&BigInt(1))==BigInt(1)}function Jn(t){if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("Number too big");return Number(t)}function Xn(t,a){return BigInt(t)+BigInt(a)}function tl(t,a){return BigInt(t)-BigInt(a)}function al(t,a){return BigInt(t)**BigInt(a)}function el(t,a){return BigInt(t)/BigInt(a)}function ol(t,a){return BigInt(t)%BigInt(a)}function il(t,a){return BigInt(t)==BigInt(a)}function nl(t,a){return BigInt(t)>BigInt(a)}function ll(t,a){return BigInt(t)&BigInt(a)}function cl(t,a,e,o){const i="0000000"+e.toString(16),n=new Uint32Array(t.buffer,a,o/4),l=1+(4*(i.length-7)-1>>5);for(let t=0;ti[i.length-a-1]=t.toString(16).padStart(8,"0"))),Vn(i.join(""),16)}function rl(t,a){return t.toString(a)}function dl(t){const a=new Uint8Array(Math.floor((Hn(t)-1)/8)+1);return cl(a,0,t,a.byteLength),a}const ul=Kn(0),_l=Kn(1);function gl(t,a,e){if(!e)return t.one;const o=function(t){let a=BigInt(t);const e=[];for(;a;)a&BigInt(1)?e.push(1):e.push(0),a>>=BigInt(1);return e}(e);if(0==o.length)return t.one;let i=a;for(let e=o.length-2;e>=0;e--)i=t.square(i),o[e]&&(i=t.mul(i,a));return i}function fl(t){if(t.m%2==1)if(il(ol(t.p,4),1))if(il(ol(t.p,8),1))if(il(ol(t.p,16),1))!function(t){t.sqrt_q=al(t.p,t.m),t.sqrt_s=0,t.sqrt_t=tl(t.sqrt_q,1);for(;!Yn(t.sqrt_t);)t.sqrt_s=t.sqrt_s+1,t.sqrt_t=el(t.sqrt_t,2);let a=t.one;for(;t.eq(a,t.one);){const e=t.random();t.sqrt_z=t.pow(e,t.sqrt_t),a=t.pow(t.sqrt_z,2**(t.sqrt_s-1))}t.sqrt_tm1d2=el(tl(t.sqrt_t,1),2),t.sqrt=function(t){const a=this;if(a.isZero(t))return a.zero;let e=a.pow(t,a.sqrt_tm1d2);const o=a.pow(a.mul(a.square(e),t),2**(a.sqrt_s-1));if(a.eq(o,a.negone))return null;let i=a.sqrt_s,n=a.mul(t,e),l=a.mul(n,e),c=a.sqrt_z;for(;!a.eq(l,a.one);){let t=a.square(l),o=1;for(;!a.eq(t,a.one);)t=a.square(t),o++;e=c;for(let t=0;t>>0,t[i]=(t[i]^t[a])>>>0,t[i]=(t[i]<<16|t[i]>>>16&65535)>>>0,t[o]=t[o]+t[i]>>>0,t[e]=(t[e]^t[o])>>>0,t[e]=(t[e]<<12|t[e]>>>20&4095)>>>0,t[a]=t[a]+t[e]>>>0,t[i]=(t[i]^t[a])>>>0,t[i]=(t[i]<<8|t[i]>>>24&255)>>>0,t[o]=t[o]+t[i]>>>0,t[e]=(t[e]^t[o])>>>0,t[e]=(t[e]<<7|t[e]>>>25&127)>>>0}class pl{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 Xn((t=this.nextU32(),a=4294967296,BigInt(t)*BigInt(a)),this.nextU32());var t,a}nextBool(){return 1==(1&this.nextU32())}update(){for(let t=0;t<16;t++)this.buff[t]=this.state[t];for(let a=0;a<10;a++)hl(t=this.buff,0,4,8,12),hl(t,1,5,9,13),hl(t,2,6,10,14),hl(t,3,7,11,15),hl(t,0,5,10,15),hl(t,1,6,11,12),hl(t,2,7,8,13),hl(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 ml(t){let a=new Uint8Array(t);if(void 0!==globalThis.crypto)globalThis.crypto.getRandomValues(a);else for(let e=0;e>>0;return a}let Ll=null;function bl(){return Ll||(Ll=new pl(function(){const t=ml(32),a=new Uint32Array(t.buffer),e=[];for(let t=0;t<8;t++)e.push(a[t]);return e}()),Ll)}class wl{constructor(t,a,e){this.F=a,this.G=t,this.opMulGF=e;let o=a.sqrt_t||a.t,i=a.sqrt_s||a.s,n=a.one;for(;a.eq(a.pow(n,a.half),a.one);)n=a.add(n,a.one);this.w=new Array(i+1),this.wi=new Array(i+1),this.w[i]=this.F.pow(n,o),this.wi[i]=this.F.inv(this.w[i]);let l=i-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(i,15))}_setRoots(t){for(let a=t;a>=0&&!this.roots[a];a--){let t=this.F.one;const e=1<>1,c=Al(t,a,e-1,o,2*i),s=Al(t,a,e-1,o+i,2*i),r=new Array(n);for(let a=0;a>this.one,this.bitLength=Hn(this.p),this.mask=(this.one<>this.one;this.nqr=this.two;let e=this.pow(this.nqr,a);for(;!this.eq(e,this.negone);)this.nqr=this.nqr+this.one,e=this.pow(this.nqr,a);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),fl(this),this.FFT=new wl(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,a){let e;if(a?16==a&&(e=BigInt("0x"+t)):e=BigInt(t),e<0){let t=-e;return t>=this.p&&(t%=this.p),this.p-t}return e>=this.p?e%this.p:e}add(t,a){const e=t+a;return e>=this.p?e-this.p:e}sub(t,a){return t>=a?t-a:this.p-a+t}neg(t){return t?this.p-t:t}mul(t,a){return t*a%this.p}mulScalar(t,a){return t*this.e(a)%this.p}square(t){return t*t%this.p}eq(t,a){return t==a}neq(t,a){return t!=a}lt(t,a){return(t>this.half?t-this.p:t)<(a>this.half?a-this.p:a)}gt(t,a){return(t>this.half?t-this.p:t)>(a>this.half?a-this.p:a)}leq(t,a){return(t>this.half?t-this.p:t)<=(a>this.half?a-this.p:a)}geq(t,a){return(t>this.half?t-this.p:t)>=(a>this.half?a-this.p:a)}div(t,a){return this.mul(t,this.inv(a))}idiv(t,a){if(!a)throw new Error("Division by zero");return t/a}inv(t){if(!t)throw new Error("Division by zero");let a=this.zero,e=this.p,o=this.one,i=t%this.p;for(;i;){let t=e/i;[a,o]=[o,a-t*o],[e,i]=[i,e-t*i]}return a=this.p?e-this.p:e}bor(t,a){const e=(t|a)&this.mask;return e>=this.p?e-this.p:e}bxor(t,a){const e=(t^a)&this.mask;return e>=this.p?e-this.p:e}bnot(t){const a=t^this.mask;return a>=this.p?a-this.p:a}shl(t,a){if(Number(a)=this.p?e-this.p:e}{const e=this.p-a;return Number(e)>e:this.zero}}shr(t,a){if(Number(a)>a;{const e=this.p-a;if(Number(e)=this.p?a-this.p:a}return 0}}land(t,a){return t&&a?this.one:this.zero}lor(t,a){return t||a?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 a=this.s,e=this.nqr_to_t,o=this.pow(t,this.t),i=this.pow(t,this.add(this.t,this.one)>>this.one);for(;o!=this.one;){let t=this.square(o),n=1;for(;t!=this.one;)n++,t=this.square(t);let l=e;for(let t=0;tthis.p>>this.one&&(i=this.neg(i)),i}normalize(t,a){if((t=BigInt(t,a))<0){let a=-t;return a>=this.p&&(a%=this.p),this.p-a}return t>=this.p?t%this.p:t}random(){const t=2*this.bitLength/8;let a=this.zero;for(let e=0;ethis.half&&10==a){e="-"+(this.p-t).toString(a)}else e=t.toString(a);return e}isZero(t){return t==this.zero}fromRng(t){let a;do{a=this.zero;for(let e=0;e=this.p);return a=a*this.Ri%this.p,a}fft(t){return this.FFT.fft(t)}ifft(t){return this.FFT.ifft(t)}toRprLE(t,a,e){cl(t,a,e,8*this.n64)}toRprBE(t,a,e){!function(t,a,e,o){const i="0000000"+e.toString(16),n=new DataView(t.buffer,t.byteOffset+a,o),l=1+(4*(i.length-7)-1>>5);for(let t=0;t>=8n;return e},bigInt2U32LE:function(t,a){const e=Array(a);let o=BigInt(t);for(let t=0;t>=32n;return e},isOcamNum:function(t){return!!Array.isArray(t)&&(3==t.length&&("number"==typeof t[0]&&("number"==typeof t[1]&&!!Array.isArray(t[2]))))}},xl=function(t,a,e,o,i,n,l){const c=t.addFunction(a);c.addParam("base","i32"),c.addParam("scalar","i32"),c.addParam("scalarLength","i32"),c.addParam("r","i32"),c.addLocal("i","i32"),c.addLocal("b","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(e));c.addCode(s.if(s.i32_eqz(s.getLocal("scalarLength")),[...s.call(l,s.getLocal("r")),...s.ret([])])),c.addCode(s.call(n,s.getLocal("base"),r)),c.addCode(s.call(l,s.getLocal("r"))),c.addCode(s.setLocal("i",s.getLocal("scalarLength"))),c.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 a=0;a<8;a++)t.push(...s.call(i,s.getLocal("r"),s.getLocal("r")),...s.if(s.i32_ge_u(s.getLocal("b"),s.i32_const(128>>a)),[...s.setLocal("b",s.i32_sub(s.getLocal("b"),s.i32_const(128>>a))),...s.call(o,s.getLocal("r"),r,s.getLocal("r"))]));return t}(),s.br_if(1,s.i32_eqz(s.getLocal("i"))),s.br(0))))},Il=function(t,a){const e=8*t.modules[a].n64,o=t.addFunction(a+"_batchInverse");o.addParam("pIn","i32"),o.addParam("inStep","i32"),o.addParam("n","i32"),o.addParam("pOut","i32"),o.addParam("outStep","i32"),o.addLocal("itAux","i32"),o.addLocal("itIn","i32"),o.addLocal("itOut","i32"),o.addLocal("i","i32");const i=o.getCodeBuilder(),n=i.i32_const(t.alloc(e));o.addCode(i.setLocal("itAux",i.i32_load(i.i32_const(0))),i.i32_store(i.i32_const(0),i.i32_add(i.getLocal("itAux"),i.i32_mul(i.i32_add(i.getLocal("n"),i.i32_const(1)),i.i32_const(e))))),o.addCode(i.call(a+"_one",i.getLocal("itAux")),i.setLocal("itIn",i.getLocal("pIn")),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.if(i.call(a+"_isZero",i.getLocal("itIn")),i.call(a+"_copy",i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),i.getLocal("itAux")),i.call(a+"_mul",i.getLocal("itIn"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),i.getLocal("itAux"))),i.setLocal("itIn",i.i32_add(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))),i.setLocal("itIn",i.i32_sub(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itAux",i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("itOut",i.i32_add(i.getLocal("pOut"),i.i32_mul(i.i32_sub(i.getLocal("n"),i.i32_const(1)),i.getLocal("outStep")))),i.call(a+"_inverse",i.getLocal("itAux"),i.getLocal("itAux")),i.block(i.loop(i.br_if(1,i.i32_eqz(i.getLocal("i"))),i.if(i.call(a+"_isZero",i.getLocal("itIn")),[...i.call(a+"_copy",i.getLocal("itAux"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),...i.call(a+"_zero",i.getLocal("itOut"))],[...i.call(a+"_copy",i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),n),...i.call(a+"_mul",i.getLocal("itAux"),i.getLocal("itIn"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),...i.call(a+"_mul",i.getLocal("itAux"),n,i.getLocal("itOut"))]),i.setLocal("itIn",i.i32_sub(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itOut",i.i32_sub(i.getLocal("itOut"),i.getLocal("outStep"))),i.setLocal("itAux",i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0)))),o.addCode(i.i32_store(i.i32_const(0),i.getLocal("itAux")))};var Bl=function(t,a,e,o,i,n){void 0===n&&(n=oa?1:-1}function Pl(t){return t*t}function ql(t){return t%2n!==0n}function Ol(t){return t%2n===0n}function Gl(t){return t<0n}function zl(t){return t>0n}function Tl(t){return Gl(t)?t.toString(2).length-1:t.toString(2).length}function Ml(t){return t<0n?-t:t}function Ul(t){return 1n===Ml(t)}function Ql(t,a){for(var e,o,i,n=0n,l=1n,c=a,s=Ml(t);0n!==s;)e=c/s,o=n,i=c,n=l,c=s,l=o-e*l,s=i-e*s;if(!Ul(c))throw new Error(t.toString()+" and "+a.toString()+" are not co-prime");return-1===Sl(n,0n)&&(n+=a),Gl(t)?-n:n}function kl(t,a,e){if(0n===e)throw new Error("Cannot take modPow with modulus 0");var o=1n,i=t%e;for(Gl(a)&&(a*=-1n,i=Ql(i,e));zl(a);){if(0n===i)return 0n;ql(a)&&(o=o*i%e),a/=2n,i=Pl(i)%e}return o}function Rl(t,a){return 0n!==a&&(!!Ul(a)||(0===function(t,a){return(t=t>=0n?t:-t)===(a=a>=0n?a:-a)?0:t>a?1:-1}(a,2n)?Ol(t):t%a===0n))}function Nl(t,a){for(var e,o,i,n=function(t){return t-1n}(t),l=n,c=0;Ol(l);)l/=2n,c++;t:for(o=0;o>1&&o>1,t>>1)))),a.addCode(e.setLocal(s,e.i64_add(e.getLocal(s),e.i64_shr_u(e.getLocal(c),e.i64_const(32)))))),t>0&&(a.addCode(e.setLocal(c,e.i64_add(e.i64_and(e.getLocal(c),e.i64_const(4294967295)),e.i64_and(e.getLocal(r),e.i64_const(4294967295))))),a.addCode(e.setLocal(s,e.i64_add(e.i64_add(e.getLocal(s),e.i64_shr_u(e.getLocal(c),e.i64_const(32))),e.getLocal(d))))),a.addCode(e.i64_store32(e.getLocal("r"),4*t,e.getLocal(c))),a.addCode(e.setLocal(r,e.getLocal(s)),e.setLocal(d,e.i64_shr_u(e.getLocal(r),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*i*2-4,e.getLocal(r)))}(),function(){const a=t.addFunction(o+"_squareOld");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(o+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){!function(){const a=t.addFunction(o+"__mul1");a.addParam("px","i32"),a.addParam("y","i64"),a.addParam("pr","i32"),a.addLocal("c","i64");const e=a.getCodeBuilder();a.addCode(e.setLocal("c",e.i64_mul(e.i64_load32_u(e.getLocal("px"),0,0),e.getLocal("y")))),a.addCode(e.i64_store32(e.getLocal("pr"),0,0,e.getLocal("c")));for(let t=1;t>1n,p=t.alloc(c,$l.bigInt2BytesLE(h,c)),m=h+1n,L=t.alloc(c,$l.bigInt2BytesLE(m,c));t.modules[s]={pq:d,pR2:u,n64:n,q:i,pOne:_,pZero:g,pePlusOne:L};let b=2n;if(Jl(i))for(;Yl(b,h,i)!==f;)b+=1n;let w=0,y=f;for(;!Xl(y)&&0n!==y;)w++,y>>=1n;const A=t.alloc(c,$l.bigInt2BytesLE(y,c)),C=Yl(b,y,i),F=t.alloc($l.bigInt2BytesLE((C<>1n,I=t.alloc(c,$l.bigInt2BytesLE(x,c));return t.exportFunction(r+"_copy",s+"_copy"),t.exportFunction(r+"_zero",s+"_zero"),t.exportFunction(r+"_isZero",s+"_isZero"),t.exportFunction(r+"_eq",s+"_eq"),function(){const a=t.addFunction(s+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder();a.addCode(e.ret(e.call(r+"_eq",e.getLocal("x"),e.i32_const(_))))}(),function(){const a=t.addFunction(s+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.if(e.call(r+"_add",e.getLocal("x"),e.getLocal("y"),e.getLocal("r")),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.if(e.call(r+"_sub",e.getLocal("x"),e.getLocal("y"),e.getLocal("r")),e.drop(e.call(r+"_add",e.getLocal("r"),e.i32_const(d),e.getLocal("r")))))}(),function(){const a=t.addFunction(s+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_sub",e.i32_const(g),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.alloc(l*l*8),e=t.addFunction(s+"_mReduct");e.addParam("t","i32"),e.addParam("r","i32"),e.addLocal("np32","i64"),e.addLocal("c","i64"),e.addLocal("m","i64");const o=e.getCodeBuilder(),n=Number(0x100000000n-Wl(i,0x100000000n));e.addCode(o.setLocal("np32",o.i64_const(n)));for(let t=0;t=l&&a.addCode(e.i64_store32(e.getLocal("r"),4*(t-l),e.getLocal(f))),[f,h]=[h,f],a.addCode(e.setLocal(h,e.i64_shr_u(e.getLocal(f),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*l-4,e.getLocal(f))),a.addCode(e.if(e.i32_wrap_i64(e.getLocal(h)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_square");a.addParam("x","i32"),a.addParam("r","i32"),a.addLocal("c0","i64"),a.addLocal("c1","i64"),a.addLocal("c0_old","i64"),a.addLocal("c1_old","i64"),a.addLocal("np32","i64");for(let t=0;t>1&&o>1,t>>1)))),a.addCode(e.setLocal(f,e.i64_add(e.getLocal(f),e.i64_shr_u(e.getLocal(g),e.i64_const(32)))))),t>0&&(a.addCode(e.setLocal(g,e.i64_add(e.i64_and(e.getLocal(g),e.i64_const(4294967295)),e.i64_and(e.getLocal(h),e.i64_const(4294967295))))),a.addCode(e.setLocal(f,e.i64_add(e.i64_add(e.getLocal(f),e.i64_shr_u(e.getLocal(g),e.i64_const(32))),e.getLocal(p)))));for(let o=Math.max(1,t-l+1);o<=t&&o=l&&a.addCode(e.i64_store32(e.getLocal("r"),4*(t-l),e.getLocal(g))),a.addCode(e.setLocal(h,e.getLocal(f)),e.setLocal(p,e.i64_shr_u(e.getLocal(h),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*l-4,e.getLocal(h))),a.addCode(e.if(e.i32_wrap_i64(e.getLocal(p)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_squareOld");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.i32_const(u),e.getLocal("r")))}(),function(){const a=t.alloc(2*c),e=t.addFunction(s+"_fromMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const o=e.getCodeBuilder();e.addCode(o.call(r+"_copy",o.getLocal("x"),o.i32_const(a))),e.addCode(o.call(r+"_zero",o.i32_const(a+c))),e.addCode(o.call(s+"_mReduct",o.i32_const(a),o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.call(s+"_fromMontgomery",e.getLocal("x"),o),e.call(r+"_gte",o,e.i32_const(L)))}(),function(){const a=t.addFunction(s+"_sign");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(r+"_isZero",e.getLocal("x")),e.ret(e.i32_const(0))),e.call(s+"_fromMontgomery",e.getLocal("x"),o),e.if(e.call(r+"_gte",o,e.i32_const(L)),e.ret(e.i32_const(-1))),e.ret(e.i32_const(1)))}(),function(){const a=t.addFunction(s+"_inverse");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_fromMontgomery",e.getLocal("x"),e.getLocal("r"))),a.addCode(e.call(r+"_inverseMod",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),a.addCode(e.call(s+"_toMontgomery",e.getLocal("r"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_one");a.addParam("pr","i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_copy",e.i32_const(_),e.getLocal("pr")))}(),function(){const a=t.addFunction(s+"_load");a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32"),a.addLocal("p","i32"),a.addLocal("l","i32"),a.addLocal("i","i32"),a.addLocal("j","i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c)),i=t.alloc(c),n=e.i32_const(i);a.addCode(e.call(r+"_zero",e.getLocal("r")),e.setLocal("i",e.i32_const(c)),e.setLocal("p",e.getLocal("scalar")),e.block(e.loop(e.br_if(1,e.i32_gt_u(e.getLocal("i"),e.getLocal("scalarLen"))),e.if(e.i32_eq(e.getLocal("i"),e.i32_const(c)),e.call(s+"_one",o),e.call(s+"_mul",o,e.i32_const(u),o)),e.call(s+"_mul",e.getLocal("p"),o,n),e.call(s+"_add",e.getLocal("r"),n,e.getLocal("r")),e.setLocal("p",e.i32_add(e.getLocal("p"),e.i32_const(c))),e.setLocal("i",e.i32_add(e.getLocal("i"),e.i32_const(c))),e.br(0))),e.setLocal("l",e.i32_rem_u(e.getLocal("scalarLen"),e.i32_const(c))),e.if(e.i32_eqz(e.getLocal("l")),e.ret([])),e.call(r+"_zero",n),e.setLocal("j",e.i32_const(0)),e.block(e.loop(e.br_if(1,e.i32_eq(e.getLocal("j"),e.getLocal("l"))),e.i32_store8(e.getLocal("j"),i,e.i32_load8_u(e.getLocal("p"))),e.setLocal("p",e.i32_add(e.getLocal("p"),e.i32_const(1))),e.setLocal("j",e.i32_add(e.getLocal("j"),e.i32_const(1))),e.br(0))),e.if(e.i32_eq(e.getLocal("i"),e.i32_const(c)),e.call(s+"_one",o),e.call(s+"_mul",o,e.i32_const(u),o)),e.call(s+"_mul",n,o,n),e.call(s+"_add",e.getLocal("r"),n,e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.call(s+"_load",e.getLocal("scalar"),e.getLocal("scalarLen"),o),e.call(s+"_toMontgomery",o,o),e.call(s+"_mul",e.getLocal("x"),o,e.getLocal("r")))}(),Vl(t,s),Kl(t,s+"_batchToMontgomery",s+"_toMontgomery",c,c),Kl(t,s+"_batchFromMontgomery",s+"_fromMontgomery",c,c),Kl(t,s+"_batchNeg",s+"_neg",c,c),Hl(t,s+"_batchAdd",s+"_add",c,c),Hl(t,s+"_batchSub",s+"_sub",c,c),Hl(t,s+"_batchMul",s+"_mul",c,c),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"),jl(t,s+"_exp",c,s+"_mul",s+"_square",r+"_copy",s+"_one"),t.exportFunction(s+"_exp"),t.exportFunction(s+"_batchInverse"),Jl(i)&&(!function(){const a=t.addFunction(s+"_sqrt");a.addParam("n","i32"),a.addParam("r","i32"),a.addLocal("m","i32"),a.addLocal("i","i32"),a.addLocal("j","i32");const e=a.getCodeBuilder(),o=e.i32_const(_),i=e.i32_const(t.alloc(c)),n=e.i32_const(t.alloc(c)),l=e.i32_const(t.alloc(c)),r=e.i32_const(t.alloc(c)),d=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(s+"_isZero",e.getLocal("n")),e.ret(e.call(s+"_zero",e.getLocal("r")))),e.setLocal("m",e.i32_const(w)),e.call(s+"_copy",e.i32_const(F),i),e.call(s+"_exp",e.getLocal("n"),e.i32_const(A),e.i32_const(c),n),e.call(s+"_exp",e.getLocal("n"),e.i32_const(I),e.i32_const(c),l),e.block(e.loop(e.br_if(1,e.call(s+"_eq",n,o)),e.call(s+"_square",n,r),e.setLocal("i",e.i32_const(1)),e.block(e.loop(e.br_if(1,e.call(s+"_eq",r,o)),e.call(s+"_square",r,r),e.setLocal("i",e.i32_add(e.getLocal("i"),e.i32_const(1))),e.br(0))),e.call(s+"_copy",i,d),e.setLocal("j",e.i32_sub(e.i32_sub(e.getLocal("m"),e.getLocal("i")),e.i32_const(1))),e.block(e.loop(e.br_if(1,e.i32_eqz(e.getLocal("j"))),e.call(s+"_square",d,d),e.setLocal("j",e.i32_sub(e.getLocal("j"),e.i32_const(1))),e.br(0))),e.setLocal("m",e.getLocal("i")),e.call(s+"_square",d,i),e.call(s+"_mul",n,i,n),e.call(s+"_mul",l,d,l),e.br(0))),e.if(e.call(s+"_isNegative",l),e.call(s+"_neg",l,e.getLocal("r")),e.call(s+"_copy",l,e.getLocal("r"))))}(),function(){const a=t.addFunction(s+"_isSquare");a.addParam("n","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(_),i=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(s+"_isZero",e.getLocal("n")),e.ret(e.i32_const(1))),e.call(s+"_exp",e.getLocal("n"),e.i32_const(p),e.i32_const(c),i),e.call(s+"_eq",i,o))}(),t.exportFunction(s+"_sqrt"),t.exportFunction(s+"_isSquare")),t.exportFunction(s+"_batchToMontgomery"),t.exportFunction(s+"_batchFromMontgomery"),s};const ec=ac,{bitLength:oc}=vl;var ic=function(t,a,e,o,i){const n=BigInt(a),l=Math.floor((oc(n-1n)-1)/64)+1,c=8*l,s=e||"f1";if(t.modules[s])return s;t.modules[s]={n64:l};const r=i||"int",d=ec(t,n,o,r),u=t.modules[d].pR2,_=t.modules[d].pq,g=t.modules[d].pePlusOne;return function(){const a=t.alloc(c),e=t.addFunction(s+"_mul");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const o=e.getCodeBuilder();e.addCode(o.call(d+"_mul",o.getLocal("x"),o.getLocal("y"),o.i32_const(a))),e.addCode(o.call(d+"_mul",o.i32_const(a),o.i32_const(u),o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_square");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_inverse");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_inverseMod",e.getLocal("x"),e.i32_const(_),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_gte",e.getLocal("x"),e.i32_const(g)))}(),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 nc=xl,lc=Il,cc=Fl;var sc=function(t,a,e,o){if(t.modules[e])return e;const i=8*t.modules[o].n64,n=t.modules[o].q;return t.modules[e]={n64:2*t.modules[o].n64},function(){const a=t.addFunction(e+"_isZero");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.i32_and(n.call(o+"_isZero",l),n.call(o+"_isZero",c)))}(),function(){const a=t.addFunction(e+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.ret(n.i32_and(n.call(o+"_isOne",l),n.call(o+"_isZero",c))))}(),function(){const a=t.addFunction(e+"_zero");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.call(o+"_zero",l),n.call(o+"_zero",c))}(),function(){const a=t.addFunction(e+"_one");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.call(o+"_one",l),n.call(o+"_zero",c))}(),function(){const a=t.addFunction(e+"_copy");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_copy",l,s),n.call(o+"_copy",c,r))}(),function(){const n=t.addFunction(e+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("y"),d=l.i32_add(l.getLocal("y"),l.i32_const(i)),u=l.getLocal("r"),_=l.i32_add(l.getLocal("r"),l.i32_const(i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_mul",c,r,g),l.call(o+"_mul",s,d,f),l.call(o+"_add",c,s,h),l.call(o+"_add",r,d,p),l.call(o+"_mul",h,p,h),l.call(a,f,u),l.call(o+"_add",g,u,u),l.call(o+"_add",g,f,_),l.call(o+"_sub",h,_,_))}(),function(){const a=t.addFunction(e+"_mul1");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_mul",l,s,r),n.call(o+"_mul",c,s,d))}(),function(){const n=t.addFunction(e+"_square");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("r"),d=l.i32_add(l.getLocal("r"),l.i32_const(i)),u=l.i32_const(t.alloc(i)),_=l.i32_const(t.alloc(i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_mul",c,s,u),l.call(o+"_add",c,s,_),l.call(a,s,g),l.call(o+"_add",c,g,g),l.call(a,u,f),l.call(o+"_add",f,u,f),l.call(o+"_mul",_,g,r),l.call(o+"_sub",r,f,r),l.call(o+"_add",u,u,d))}(),function(){const a=t.addFunction(e+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.i32_add(n.getLocal("y"),n.i32_const(i)),d=n.getLocal("r"),u=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_add",l,s,d),n.call(o+"_add",c,r,u))}(),function(){const a=t.addFunction(e+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.i32_add(n.getLocal("y"),n.i32_const(i)),d=n.getLocal("r"),u=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_sub",l,s,d),n.call(o+"_sub",c,r,u))}(),function(){const a=t.addFunction(e+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_neg",l,s),n.call(o+"_neg",c,r))}(),function(){const a=t.addFunction(e+"_conjugate");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_copy",l,s),n.call(o+"_neg",c,r))}(),function(){const a=t.addFunction(e+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_toMontgomery",l,s),n.call(o+"_toMontgomery",c,r))}(),function(){const a=t.addFunction(e+"_fromMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_fromMontgomery",l,s),n.call(o+"_fromMontgomery",c,r))}(),function(){const a=t.addFunction(e+"_eq");a.addParam("x","i32"),a.addParam("y","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.i32_add(n.getLocal("y"),n.i32_const(i));a.addCode(n.i32_and(n.call(o+"_eq",l,s),n.call(o+"_eq",c,r)))}(),function(){const n=t.addFunction(e+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("r"),d=l.i32_add(l.getLocal("r"),l.i32_const(i)),u=l.i32_const(t.alloc(i)),_=l.i32_const(t.alloc(i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_square",c,u),l.call(o+"_square",s,_),l.call(a,_,g),l.call(o+"_sub",u,g,g),l.call(o+"_inverse",g,f),l.call(o+"_mul",c,f,r),l.call(o+"_mul",s,f,d),l.call(o+"_neg",d,d))}(),function(){const a=t.addFunction(e+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_timesScalar",l,n.getLocal("scalar"),n.getLocal("scalarLen"),s),n.call(o+"_timesScalar",c,n.getLocal("scalar"),n.getLocal("scalarLen"),r))}(),function(){const a=t.addFunction(e+"_sign");a.addParam("x","i32"),a.addLocal("s","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.setLocal("s",n.call(o+"_sign",c)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(o+"_sign",l)))}(),function(){const a=t.addFunction(e+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.if(n.call(o+"_isZero",c),n.ret(n.call(o+"_isNegative",l))),n.ret(n.call(o+"_isNegative",c)))}(),t.exportFunction(e+"_isZero"),t.exportFunction(e+"_isOne"),t.exportFunction(e+"_zero"),t.exportFunction(e+"_one"),t.exportFunction(e+"_copy"),t.exportFunction(e+"_mul"),t.exportFunction(e+"_mul1"),t.exportFunction(e+"_square"),t.exportFunction(e+"_add"),t.exportFunction(e+"_sub"),t.exportFunction(e+"_neg"),t.exportFunction(e+"_sign"),t.exportFunction(e+"_conjugate"),t.exportFunction(e+"_fromMontgomery"),t.exportFunction(e+"_toMontgomery"),t.exportFunction(e+"_eq"),t.exportFunction(e+"_inverse"),lc(t,e),nc(t,e+"_exp",2*i,e+"_mul",e+"_square",e+"_copy",e+"_one"),function(){const a=t.addFunction(e+"_sqrt");a.addParam("a","i32"),a.addParam("pr","i32");const l=a.getCodeBuilder(),c=l.i32_const(t.alloc(cc.bigInt2BytesLE((BigInt(n||0)-3n)/4n,i))),s=l.i32_const(t.alloc(cc.bigInt2BytesLE((BigInt(n||0)-1n)/2n,i))),r=l.getLocal("a"),d=l.i32_const(t.alloc(2*i)),u=l.i32_const(t.alloc(2*i)),_=l.i32_const(t.alloc(2*i)),g=t.alloc(2*i),f=l.i32_const(g),h=l.i32_const(g),p=l.i32_const(g+i),m=l.i32_const(t.alloc(2*i)),L=l.i32_const(t.alloc(2*i));a.addCode(l.call(e+"_one",f),l.call(e+"_neg",f,f),l.call(e+"_exp",r,c,l.i32_const(i),d),l.call(e+"_square",d,u),l.call(e+"_mul",r,u,u),l.call(e+"_conjugate",u,_),l.call(e+"_mul",_,u,_),l.if(l.call(e+"_eq",_,f),l.unreachable()),l.call(e+"_mul",d,r,m),l.if(l.call(e+"_eq",u,f),[...l.call(o+"_zero",h),...l.call(o+"_one",p),...l.call(e+"_mul",f,m,l.getLocal("pr"))],[...l.call(e+"_one",L),...l.call(e+"_add",L,u,L),...l.call(e+"_exp",L,s,l.i32_const(i),L),...l.call(e+"_mul",L,m,l.getLocal("pr"))]))}(),function(){const a=t.addFunction(e+"_isSquare");a.addParam("a","i32"),a.setReturnType("i32");const o=a.getCodeBuilder(),l=o.i32_const(t.alloc(cc.bigInt2BytesLE((BigInt(n||0)-3n)/4n,i))),c=o.getLocal("a"),s=o.i32_const(t.alloc(2*i)),r=o.i32_const(t.alloc(2*i)),d=o.i32_const(t.alloc(2*i)),u=t.alloc(2*i),_=o.i32_const(u);a.addCode(o.call(e+"_one",_),o.call(e+"_neg",_,_),o.call(e+"_exp",c,l,o.i32_const(i),s),o.call(e+"_square",s,r),o.call(e+"_mul",c,r,r),o.call(e+"_conjugate",r,d),o.call(e+"_mul",d,r,d),o.if(o.call(e+"_eq",d,_),o.ret(o.i32_const(0))),o.ret(o.i32_const(1)))}(),t.exportFunction(e+"_exp"),t.exportFunction(e+"_timesScalar"),t.exportFunction(e+"_batchInverse"),t.exportFunction(e+"_sqrt"),t.exportFunction(e+"_isSquare"),t.exportFunction(e+"_isNegative"),e};const rc=xl,dc=Il;var uc=function(t,a,e,o){if(t.modules[e])return e;const i=8*t.modules[o].n64;return t.modules[e]={n64:3*t.modules[o].n64},function(){const a=t.addFunction(e+"_isZero");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.i32_and(n.i32_and(n.call(o+"_isZero",l),n.call(o+"_isZero",c)),n.call(o+"_isZero",s)))}(),function(){const a=t.addFunction(e+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.ret(n.i32_and(n.i32_and(n.call(o+"_isOne",l),n.call(o+"_isZero",c)),n.call(o+"_isZero",s))))}(),function(){const a=t.addFunction(e+"_zero");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.call(o+"_zero",l),n.call(o+"_zero",c),n.call(o+"_zero",s))}(),function(){const a=t.addFunction(e+"_one");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.call(o+"_one",l),n.call(o+"_zero",c),n.call(o+"_zero",s))}(),function(){const a=t.addFunction(e+"_copy");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_copy",l,r),n.call(o+"_copy",c,d),n.call(o+"_copy",s,u))}(),function(){const n=t.addFunction(e+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("y"),u=l.i32_add(l.getLocal("y"),l.i32_const(i)),_=l.i32_add(l.getLocal("y"),l.i32_const(2*i)),g=l.getLocal("r"),f=l.i32_add(l.getLocal("r"),l.i32_const(i)),h=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),p=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i)),w=l.i32_const(t.alloc(i)),y=l.i32_const(t.alloc(i)),A=l.i32_const(t.alloc(i)),C=l.i32_const(t.alloc(i)),F=l.i32_const(t.alloc(i)),x=l.i32_const(t.alloc(i)),I=l.i32_const(t.alloc(i)),B=l.i32_const(t.alloc(i)),E=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_mul",c,d,p),l.call(o+"_mul",s,u,m),l.call(o+"_mul",r,_,L),l.call(o+"_add",c,s,b),l.call(o+"_add",d,u,w),l.call(o+"_add",c,r,y),l.call(o+"_add",d,_,A),l.call(o+"_add",s,r,C),l.call(o+"_add",u,_,F),l.call(o+"_add",p,m,x),l.call(o+"_add",p,L,I),l.call(o+"_add",m,L,B),l.call(o+"_mul",C,F,g),l.call(o+"_sub",g,B,g),l.call(a,g,g),l.call(o+"_add",p,g,g),l.call(o+"_mul",b,w,f),l.call(o+"_sub",f,x,f),l.call(a,L,E),l.call(o+"_add",f,E,f),l.call(o+"_mul",y,A,h),l.call(o+"_sub",h,I,h),l.call(o+"_add",h,m,h))}(),function(){const n=t.addFunction(e+"_square");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("r"),u=l.i32_add(l.getLocal("r"),l.i32_const(i)),_=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_square",c,g),l.call(o+"_mul",c,s,f),l.call(o+"_add",f,f,h),l.call(o+"_sub",c,s,p),l.call(o+"_add",p,r,p),l.call(o+"_square",p,p),l.call(o+"_mul",s,r,m),l.call(o+"_add",m,m,L),l.call(o+"_square",r,b),l.call(a,L,d),l.call(o+"_add",g,d,d),l.call(a,b,u),l.call(o+"_add",h,u,u),l.call(o+"_add",g,b,_),l.call(o+"_sub",L,_,_),l.call(o+"_add",p,_,_),l.call(o+"_add",h,_,_))}(),function(){const a=t.addFunction(e+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(i)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*i)),_=n.getLocal("r"),g=n.i32_add(n.getLocal("r"),n.i32_const(i)),f=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_add",l,r,_),n.call(o+"_add",c,d,g),n.call(o+"_add",s,u,f))}(),function(){const a=t.addFunction(e+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(i)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*i)),_=n.getLocal("r"),g=n.i32_add(n.getLocal("r"),n.i32_const(i)),f=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_sub",l,r,_),n.call(o+"_sub",c,d,g),n.call(o+"_sub",s,u,f))}(),function(){const a=t.addFunction(e+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_neg",l,r),n.call(o+"_neg",c,d),n.call(o+"_neg",s,u))}(),function(){const a=t.addFunction(e+"_sign");a.addParam("x","i32"),a.addLocal("s","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.setLocal("s",n.call(o+"_sign",s)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.setLocal("s",n.call(o+"_sign",c)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(o+"_sign",l)))}(),function(){const a=t.addFunction(e+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_toMontgomery",l,r),n.call(o+"_toMontgomery",c,d),n.call(o+"_toMontgomery",s,u))}(),function(){const a=t.addFunction(e+"_fromMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_fromMontgomery",l,r),n.call(o+"_fromMontgomery",c,d),n.call(o+"_fromMontgomery",s,u))}(),function(){const a=t.addFunction(e+"_eq");a.addParam("x","i32"),a.addParam("y","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(i)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*i));a.addCode(n.i32_and(n.i32_and(n.call(o+"_eq",l,r),n.call(o+"_eq",c,d)),n.call(o+"_eq",s,u)))}(),function(){const n=t.addFunction(e+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("r"),u=l.i32_add(l.getLocal("r"),l.i32_const(i)),_=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i)),w=l.i32_const(t.alloc(i)),y=l.i32_const(t.alloc(i)),A=l.i32_const(t.alloc(i)),C=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_square",c,g),l.call(o+"_square",s,f),l.call(o+"_square",r,h),l.call(o+"_mul",c,s,p),l.call(o+"_mul",c,r,m),l.call(o+"_mul",s,r,L),l.call(a,L,b),l.call(o+"_sub",g,b,b),l.call(a,h,w),l.call(o+"_sub",w,p,w),l.call(o+"_sub",f,m,y),l.call(o+"_mul",r,w,A),l.call(o+"_mul",s,y,C),l.call(o+"_add",A,C,A),l.call(a,A,A),l.call(o+"_mul",c,b,C),l.call(o+"_add",C,A,A),l.call(o+"_inverse",A,A),l.call(o+"_mul",A,b,d),l.call(o+"_mul",A,w,u),l.call(o+"_mul",A,y,_))}(),function(){const a=t.addFunction(e+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_timesScalar",l,n.getLocal("scalar"),n.getLocal("scalarLen"),r),n.call(o+"_timesScalar",c,n.getLocal("scalar"),n.getLocal("scalarLen"),d),n.call(o+"_timesScalar",s,n.getLocal("scalar"),n.getLocal("scalarLen"),u))}(),function(){const a=t.addFunction(e+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.if(n.call(o+"_isZero",s),n.if(n.call(o+"_isZero",c),n.ret(n.call(o+"_isNegative",l)),n.ret(n.call(o+"_isNegative",c)))),n.ret(n.call(o+"_isNegative",s)))}(),t.exportFunction(e+"_isZero"),t.exportFunction(e+"_isOne"),t.exportFunction(e+"_zero"),t.exportFunction(e+"_one"),t.exportFunction(e+"_copy"),t.exportFunction(e+"_mul"),t.exportFunction(e+"_square"),t.exportFunction(e+"_add"),t.exportFunction(e+"_sub"),t.exportFunction(e+"_neg"),t.exportFunction(e+"_sign"),t.exportFunction(e+"_fromMontgomery"),t.exportFunction(e+"_toMontgomery"),t.exportFunction(e+"_eq"),t.exportFunction(e+"_inverse"),dc(t,e),rc(t,e+"_exp",3*i,e+"_mul",e+"_square",e+"_copy",e+"_one"),t.exportFunction(e+"_exp"),t.exportFunction(e+"_timesScalar"),t.exportFunction(e+"_batchInverse"),t.exportFunction(e+"_isNegative"),e};const _c=function(t,a,e,o,i,n,l,c){const s=t.addFunction(a);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 r=s.getCodeBuilder(),d=r.i32_const(t.alloc(e));function u(t){return r.i32_and(r.i32_shr_u(r.i32_load(r.i32_add(r.getLocal("scalar"),r.i32_and(r.i32_shr_u(t,r.i32_const(3)),r.i32_const(4294967292)))),r.i32_and(t,r.i32_const(31))),r.i32_const(1))}function _(t){return[...r.i32_store8(r.getLocal("p"),r.i32_const(t)),...r.setLocal("p",r.i32_add(r.getLocal("p"),r.i32_const(1)))]}s.addCode(r.if(r.i32_eqz(r.getLocal("scalarLength")),[...r.call(c,r.getLocal("r")),...r.ret([])]),r.setLocal("nbits",r.i32_shl(r.getLocal("scalarLength"),r.i32_const(3))),r.setLocal("old0",r.i32_load(r.i32_const(0))),r.setLocal("p",r.getLocal("old0")),r.i32_store(r.i32_const(0),r.i32_and(r.i32_add(r.i32_add(r.getLocal("old0"),r.i32_const(32)),r.getLocal("nbits")),r.i32_const(4294967288))),r.setLocal("i",r.i32_const(1)),r.setLocal("last",u(r.i32_const(0))),r.setLocal("carry",r.i32_const(0)),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("i"),r.getLocal("nbits"))),r.setLocal("cur",u(r.getLocal("i"))),r.if(r.getLocal("last"),r.if(r.getLocal("cur"),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(1)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(255)]),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(255)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(0)),..._(1)])),r.if(r.getLocal("cur"),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(0)],[...r.setLocal("last",r.i32_const(1)),...r.setLocal("carry",r.i32_const(0)),..._(0)]),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(1)),...r.setLocal("carry",r.i32_const(0)),..._(0)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(0)),..._(0)]))),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0))),r.if(r.getLocal("last"),r.if(r.getLocal("carry"),[..._(255),..._(0),..._(1)],[..._(1)]),r.if(r.getLocal("carry"),[..._(0),..._(1)])),r.setLocal("p",r.i32_sub(r.getLocal("p"),r.i32_const(1))),r.call(l,r.getLocal("base"),d),r.call(c,r.getLocal("r")),r.block(r.loop(r.call(i,r.getLocal("r"),r.getLocal("r")),r.setLocal("cur",r.i32_load8_u(r.getLocal("p"))),r.if(r.getLocal("cur"),r.if(r.i32_eq(r.getLocal("cur"),r.i32_const(1)),r.call(o,r.getLocal("r"),d,r.getLocal("r")),r.call(n,r.getLocal("r"),d,r.getLocal("r")))),r.br_if(1,r.i32_eq(r.getLocal("old0"),r.getLocal("p"))),r.setLocal("p",r.i32_sub(r.getLocal("p"),r.i32_const(1))),r.br(0))),r.i32_store(r.i32_const(0),r.getLocal("old0")))},gc=Bl,fc=function(t,a,e,o,i){const n=8*t.modules[a].n64;function l(){const o=t.addFunction(e);o.addParam("pBases","i32"),o.addParam("pScalars","i32"),o.addParam("scalarSize","i32"),o.addParam("n","i32"),o.addParam("pr","i32"),o.addLocal("chunkSize","i32"),o.addLocal("nChunks","i32"),o.addLocal("itScalar","i32"),o.addLocal("endScalar","i32"),o.addLocal("itBase","i32"),o.addLocal("itBit","i32"),o.addLocal("i","i32"),o.addLocal("j","i32"),o.addLocal("nTable","i32"),o.addLocal("pTable","i32"),o.addLocal("idx","i32"),o.addLocal("pIdxTable","i32");const i=o.getCodeBuilder(),l=i.i32_const(t.alloc(n)),c=t.alloc([17,17,17,17,17,17,17,17,17,17,16,16,15,14,13,13,12,11,10,9,8,7,7,6,5,4,3,2,1,1,1,1]);o.addCode(i.call(a+"_zero",i.getLocal("pr")),i.if(i.i32_eqz(i.getLocal("n")),i.ret([])),i.setLocal("chunkSize",i.i32_load8_u(i.i32_clz(i.getLocal("n")),c)),i.setLocal("nChunks",i.i32_add(i.i32_div_u(i.i32_sub(i.i32_shl(i.getLocal("scalarSize"),i.i32_const(3)),i.i32_const(1)),i.getLocal("chunkSize")),i.i32_const(1))),i.setLocal("itBit",i.i32_mul(i.i32_sub(i.getLocal("nChunks"),i.i32_const(1)),i.getLocal("chunkSize"))),i.block(i.loop(i.br_if(1,i.i32_lt_s(i.getLocal("itBit"),i.i32_const(0))),i.if(i.i32_eqz(i.call(a+"_isZero",i.getLocal("pr"))),[...i.setLocal("j",i.i32_const(0)),...i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("j"),i.getLocal("chunkSize"))),i.call(a+"_double",i.getLocal("pr"),i.getLocal("pr")),i.setLocal("j",i.i32_add(i.getLocal("j"),i.i32_const(1))),i.br(0)))]),i.call(e+"_chunk",i.getLocal("pBases"),i.getLocal("pScalars"),i.getLocal("scalarSize"),i.getLocal("n"),i.getLocal("itBit"),i.getLocal("chunkSize"),l),i.call(a+"_add",i.getLocal("pr"),l,i.getLocal("pr")),i.setLocal("itBit",i.i32_sub(i.getLocal("itBit"),i.getLocal("chunkSize"))),i.br(0))))}!function(){const a=t.addFunction(e+"_getChunk");a.addParam("pScalar","i32"),a.addParam("scalarSize","i32"),a.addParam("startBit","i32"),a.addParam("chunkSize","i32"),a.addLocal("bitsToEnd","i32"),a.addLocal("mask","i32"),a.setReturnType("i32");const o=a.getCodeBuilder();a.addCode(o.setLocal("bitsToEnd",o.i32_sub(o.i32_mul(o.getLocal("scalarSize"),o.i32_const(8)),o.getLocal("startBit"))),o.if(o.i32_gt_s(o.getLocal("chunkSize"),o.getLocal("bitsToEnd")),o.setLocal("mask",o.i32_sub(o.i32_shl(o.i32_const(1),o.getLocal("bitsToEnd")),o.i32_const(1))),o.setLocal("mask",o.i32_sub(o.i32_shl(o.i32_const(1),o.getLocal("chunkSize")),o.i32_const(1)))),o.i32_and(o.i32_shr_u(o.i32_load(o.i32_add(o.getLocal("pScalar"),o.i32_shr_u(o.getLocal("startBit"),o.i32_const(3))),0,0),o.i32_and(o.getLocal("startBit"),o.i32_const(7))),o.getLocal("mask")))}(),function(){const o=t.addFunction(e+"_reduceTable");o.addParam("pTable","i32"),o.addParam("p","i32"),o.addLocal("half","i32"),o.addLocal("it1","i32"),o.addLocal("it2","i32"),o.addLocal("pAcc","i32");const i=o.getCodeBuilder();o.addCode(i.if(i.i32_eq(i.getLocal("p"),i.i32_const(1)),i.ret([])),i.setLocal("half",i.i32_shl(i.i32_const(1),i.i32_sub(i.getLocal("p"),i.i32_const(1)))),i.setLocal("it1",i.getLocal("pTable")),i.setLocal("it2",i.i32_add(i.getLocal("pTable"),i.i32_mul(i.getLocal("half"),i.i32_const(n)))),i.setLocal("pAcc",i.i32_sub(i.getLocal("it2"),i.i32_const(n))),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("it1"),i.getLocal("pAcc"))),i.call(a+"_add",i.getLocal("it1"),i.getLocal("it2"),i.getLocal("it1")),i.call(a+"_add",i.getLocal("pAcc"),i.getLocal("it2"),i.getLocal("pAcc")),i.setLocal("it1",i.i32_add(i.getLocal("it1"),i.i32_const(n))),i.setLocal("it2",i.i32_add(i.getLocal("it2"),i.i32_const(n))),i.br(0))),i.call(e+"_reduceTable",i.getLocal("pTable"),i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.setLocal("p",i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.block(i.loop(i.br_if(1,i.i32_eqz(i.getLocal("p"))),i.call(a+"_double",i.getLocal("pAcc"),i.getLocal("pAcc")),i.setLocal("p",i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.br(0))),i.call(a+"_add",i.getLocal("pTable"),i.getLocal("pAcc"),i.getLocal("pTable")))}(),function(){const l=t.addFunction(e+"_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 c=l.getCodeBuilder();l.addCode(c.if(c.i32_eqz(c.getLocal("n")),[...c.call(a+"_zero",c.getLocal("pr")),...c.ret([])]),c.setLocal("nTable",c.i32_shl(c.i32_const(1),c.getLocal("chunkSize"))),c.setLocal("pTable",c.i32_load(c.i32_const(0))),c.i32_store(c.i32_const(0),c.i32_add(c.getLocal("pTable"),c.i32_mul(c.getLocal("nTable"),c.i32_const(n)))),c.setLocal("j",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("j"),c.getLocal("nTable"))),c.call(a+"_zero",c.i32_add(c.getLocal("pTable"),c.i32_mul(c.getLocal("j"),c.i32_const(n)))),c.setLocal("j",c.i32_add(c.getLocal("j"),c.i32_const(1))),c.br(0))),c.setLocal("itBase",c.getLocal("pBases")),c.setLocal("itScalar",c.getLocal("pScalars")),c.setLocal("endScalar",c.i32_add(c.getLocal("pScalars"),c.i32_mul(c.getLocal("n"),c.getLocal("scalarSize")))),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("itScalar"),c.getLocal("endScalar"))),c.setLocal("idx",c.call(e+"_getChunk",c.getLocal("itScalar"),c.getLocal("scalarSize"),c.getLocal("startBit"),c.getLocal("chunkSize"))),c.if(c.getLocal("idx"),[...c.setLocal("pIdxTable",c.i32_add(c.getLocal("pTable"),c.i32_mul(c.i32_sub(c.getLocal("idx"),c.i32_const(1)),c.i32_const(n)))),...c.call(o,c.getLocal("pIdxTable"),c.getLocal("itBase"),c.getLocal("pIdxTable"))]),c.setLocal("itScalar",c.i32_add(c.getLocal("itScalar"),c.getLocal("scalarSize"))),c.setLocal("itBase",c.i32_add(c.getLocal("itBase"),c.i32_const(i))),c.br(0))),c.call(e+"_reduceTable",c.getLocal("pTable"),c.getLocal("chunkSize")),c.call(a+"_copy",c.getLocal("pTable"),c.getLocal("pr")),c.i32_store(c.i32_const(0),c.getLocal("pTable")))}(),l(),t.exportFunction(e),t.exportFunction(e+"_chunk")};var hc=function(t,a,e,o){const i=t.modules[e].n64,n=8*i;if(t.modules[a])return a;return t.modules[a]={n64:3*i},function(){const o=t.addFunction(a+"_isZeroAffine");o.addParam("p1","i32"),o.setReturnType("i32");const i=o.getCodeBuilder();o.addCode(i.i32_and(i.call(e+"_isZero",i.getLocal("p1")),i.call(e+"_isZero",i.i32_add(i.getLocal("p1"),i.i32_const(n)))))}(),function(){const o=t.addFunction(a+"_isZero");o.addParam("p1","i32"),o.setReturnType("i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_isZero",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))))}(),function(){const o=t.addFunction(a+"_zeroAffine");o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_zero",i.getLocal("pr"))),o.addCode(i.call(e+"_zero",i.i32_add(i.getLocal("pr"),i.i32_const(n))))}(),function(){const o=t.addFunction(a+"_zero");o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_zero",i.getLocal("pr"))),o.addCode(i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(n)))),o.addCode(i.call(e+"_zero",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))))}(),function(){const e=t.addFunction(a+"_copyAffine");e.addParam("ps","i32"),e.addParam("pd","i32");const o=e.getCodeBuilder();for(let t=0;t<2*i;t++)e.addCode(o.i64_store(o.getLocal("pd"),8*t,o.i64_load(o.getLocal("ps"),8*t)))}(),function(){const e=t.addFunction(a+"_copy");e.addParam("ps","i32"),e.addParam("pd","i32");const o=e.getCodeBuilder();for(let t=0;t<3*i;t++)e.addCode(o.i64_store(o.getLocal("pd"),8*t,o.i64_load(o.getLocal("ps"),8*t)))}(),function(){const o=t.addFunction(a+"_toJacobian");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(n)),d=i.i32_add(i.getLocal("pr"),i.i32_const(2*n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),i.call(a+"_zero",i.getLocal("pr")),[...i.call(e+"_one",d),...i.call(e+"_copy",c,r),...i.call(e+"_copy",l,s)]))}(),function(){const o=t.addFunction(a+"_eqAffine");o.addParam("p1","i32"),o.addParam("p2","i32"),o.setReturnType("i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder();o.addCode(i.ret(i.i32_and(i.call(e+"_eq",i.getLocal("p1"),i.getLocal("p2")),i.call(e+"_eq",i.i32_add(i.getLocal("p1"),i.i32_const(n)),i.i32_add(i.getLocal("p2"),i.i32_const(n))))))}(),function(){const o=t.addFunction(a+"_eqMixed");o.addParam("p1","i32"),o.addParam("p2","i32"),o.setReturnType("i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n)),u=i.i32_const(t.alloc(n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.ret(i.call(a+"_isZeroAffine",i.getLocal("p2")))),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),i.ret(i.i32_const(0))),i.if(i.call(e+"_isOne",s),i.ret(i.call(a+"_eqAffine",i.getLocal("p1"),i.getLocal("p2")))),i.call(e+"_square",s,u),i.call(e+"_mul",r,u,_),i.call(e+"_mul",s,u,g),i.call(e+"_mul",d,g,f),i.if(i.call(e+"_eq",l,_),i.if(i.call(e+"_eq",c,f),i.ret(i.i32_const(1)))),i.ret(i.i32_const(0)))}(),function(){const o=t.addFunction(a+"_eq");o.addParam("p1","i32"),o.addParam("p2","i32"),o.setReturnType("i32"),o.addLocal("z1","i32"),o.addLocal("z2","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n));o.addCode(i.setLocal("z2",i.i32_add(i.getLocal("p2"),i.i32_const(2*n))));const u=i.getLocal("z2"),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.ret(i.call(a+"_isZero",i.getLocal("p2")))),i.if(i.call(a+"_isZero",i.getLocal("p2")),i.ret(i.i32_const(0))),i.if(i.call(e+"_isOne",s),i.ret(i.call(a+"_eqMixed",i.getLocal("p2"),i.getLocal("p1")))),i.if(i.call(e+"_isOne",u),i.ret(i.call(a+"_eqMixed",i.getLocal("p1"),i.getLocal("p2")))),i.call(e+"_square",s,_),i.call(e+"_square",u,g),i.call(e+"_mul",l,g,f),i.call(e+"_mul",r,_,h),i.call(e+"_mul",s,_,p),i.call(e+"_mul",u,g,m),i.call(e+"_mul",c,m,L),i.call(e+"_mul",d,p,b),i.if(i.call(e+"_eq",f,h),i.if(i.call(e+"_eq",L,b),i.ret(i.i32_const(1)))),i.ret(i.i32_const(0)))}(),function(){const o=t.addFunction(a+"_doubleAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(n)),d=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),u=i.i32_const(t.alloc(n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),[...i.call(a+"_toJacobian",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.call(e+"_square",l,u),i.call(e+"_square",c,_),i.call(e+"_square",_,g),i.call(e+"_add",l,_,f),i.call(e+"_square",f,f),i.call(e+"_sub",f,u,f),i.call(e+"_sub",f,g,f),i.call(e+"_add",f,f,f),i.call(e+"_add",u,u,h),i.call(e+"_add",h,u,h),i.call(e+"_add",c,c,d),i.call(e+"_square",h,s),i.call(e+"_sub",s,f,s),i.call(e+"_sub",s,f,s),i.call(e+"_add",g,g,p),i.call(e+"_add",p,p,p),i.call(e+"_add",p,p,p),i.call(e+"_sub",f,s,r),i.call(e+"_mul",r,h,r),i.call(e+"_sub",r,p,r))}(),function(){const o=t.addFunction(a+"_double");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(e+"_isOne",s),[...i.ret(i.call(a+"_doubleAffine",i.getLocal("p1"),i.getLocal("pr"))),...i.ret([])]),i.call(e+"_square",l,_),i.call(e+"_square",c,g),i.call(e+"_square",g,f),i.call(e+"_add",l,g,h),i.call(e+"_square",h,h),i.call(e+"_sub",h,_,h),i.call(e+"_sub",h,f,h),i.call(e+"_add",h,h,h),i.call(e+"_add",_,_,p),i.call(e+"_add",p,_,p),i.call(e+"_square",p,m),i.call(e+"_mul",c,s,L),i.call(e+"_add",h,h,r),i.call(e+"_sub",m,r,r),i.call(e+"_add",f,f,b),i.call(e+"_add",b,b,b),i.call(e+"_add",b,b,b),i.call(e+"_sub",h,r,d),i.call(e+"_mul",d,p,d),i.call(e+"_sub",d,b,d),i.call(e+"_add",L,L,u))}(),function(){const o=t.addFunction(a+"_addAffine");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("p2"),r=i.i32_add(i.getLocal("p2"),i.i32_const(n)),d=i.getLocal("pr"),u=i.i32_add(i.getLocal("pr"),i.i32_const(n)),_=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n)),w=i.i32_const(t.alloc(n)),y=i.i32_const(t.alloc(n)),A=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),[...i.call(a+"_copyAffine",i.getLocal("p2"),i.getLocal("pr")),...i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))),...i.ret([])]),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),[...i.call(a+"_copyAffine",i.getLocal("p1"),i.getLocal("pr")),...i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))),...i.ret([])]),i.if(i.call(e+"_eq",l,s),i.if(i.call(e+"_eq",c,r),[...i.call(a+"_doubleAffine",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])])),i.call(e+"_sub",s,l,g),i.call(e+"_sub",r,c,h),i.call(e+"_square",g,f),i.call(e+"_add",f,f,p),i.call(e+"_add",p,p,p),i.call(e+"_mul",g,p,m),i.call(e+"_add",h,h,L),i.call(e+"_mul",l,p,w),i.call(e+"_square",L,b),i.call(e+"_add",w,w,y),i.call(e+"_sub",b,m,d),i.call(e+"_sub",d,y,d),i.call(e+"_mul",c,m,A),i.call(e+"_add",A,A,A),i.call(e+"_sub",w,d,u),i.call(e+"_mul",u,L,u),i.call(e+"_sub",u,A,u),i.call(e+"_add",g,g,_))}(),function(){const o=t.addFunction(a+"_addMixed");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n)),u=i.getLocal("pr"),_=i.i32_add(i.getLocal("pr"),i.i32_const(n)),g=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n)),w=i.i32_const(t.alloc(n)),y=i.i32_const(t.alloc(n)),A=i.i32_const(t.alloc(n)),C=i.i32_const(t.alloc(n)),F=i.i32_const(t.alloc(n)),x=i.i32_const(t.alloc(n)),I=i.i32_const(t.alloc(n)),B=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copyAffine",i.getLocal("p2"),i.getLocal("pr")),...i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))),...i.ret([])]),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(e+"_isOne",s),[...i.call(a+"_addAffine",l,r,u),...i.ret([])]),i.call(e+"_square",s,f),i.call(e+"_mul",r,f,h),i.call(e+"_mul",s,f,p),i.call(e+"_mul",d,p,m),i.if(i.call(e+"_eq",l,h),i.if(i.call(e+"_eq",c,m),[...i.call(a+"_doubleAffine",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])])),i.call(e+"_sub",h,l,L),i.call(e+"_sub",m,c,w),i.call(e+"_square",L,b),i.call(e+"_add",b,b,y),i.call(e+"_add",y,y,y),i.call(e+"_mul",L,y,A),i.call(e+"_add",w,w,C),i.call(e+"_mul",l,y,x),i.call(e+"_square",C,F),i.call(e+"_add",x,x,I),i.call(e+"_sub",F,A,u),i.call(e+"_sub",u,I,u),i.call(e+"_mul",c,A,B),i.call(e+"_add",B,B,B),i.call(e+"_sub",x,u,_),i.call(e+"_mul",_,C,_),i.call(e+"_sub",_,B,_),i.call(e+"_add",s,L,g),i.call(e+"_square",g,g),i.call(e+"_sub",g,f,g),i.call(e+"_sub",g,b,g))}(),function(){const o=t.addFunction(a+"_add");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32"),o.addLocal("z1","i32"),o.addLocal("z2","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n));o.addCode(i.setLocal("z2",i.i32_add(i.getLocal("p2"),i.i32_const(2*n))));const u=i.getLocal("z2"),_=i.getLocal("pr"),g=i.i32_add(i.getLocal("pr"),i.i32_const(n)),f=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n)),w=i.i32_const(t.alloc(n)),y=i.i32_const(t.alloc(n)),A=i.i32_const(t.alloc(n)),C=i.i32_const(t.alloc(n)),F=i.i32_const(t.alloc(n)),x=i.i32_const(t.alloc(n)),I=i.i32_const(t.alloc(n)),B=i.i32_const(t.alloc(n)),E=i.i32_const(t.alloc(n)),v=i.i32_const(t.alloc(n)),S=i.i32_const(t.alloc(n)),P=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copy",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(a+"_isZero",i.getLocal("p2")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(e+"_isOne",s),[...i.call(a+"_addMixed",r,l,_),...i.ret([])]),i.if(i.call(e+"_isOne",u),[...i.call(a+"_addMixed",l,r,_),...i.ret([])]),i.call(e+"_square",s,h),i.call(e+"_square",u,p),i.call(e+"_mul",l,p,m),i.call(e+"_mul",r,h,L),i.call(e+"_mul",s,h,b),i.call(e+"_mul",u,p,w),i.call(e+"_mul",c,w,y),i.call(e+"_mul",d,b,A),i.if(i.call(e+"_eq",m,L),i.if(i.call(e+"_eq",y,A),[...i.call(a+"_double",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])])),i.call(e+"_sub",L,m,C),i.call(e+"_sub",A,y,F),i.call(e+"_add",C,C,x),i.call(e+"_square",x,x),i.call(e+"_mul",C,x,I),i.call(e+"_add",F,F,B),i.call(e+"_mul",m,x,v),i.call(e+"_square",B,E),i.call(e+"_add",v,v,S),i.call(e+"_sub",E,I,_),i.call(e+"_sub",_,S,_),i.call(e+"_mul",y,I,P),i.call(e+"_add",P,P,P),i.call(e+"_sub",v,_,g),i.call(e+"_mul",g,B,g),i.call(e+"_sub",g,P,g),i.call(e+"_add",s,u,f),i.call(e+"_square",f,f),i.call(e+"_sub",f,h,f),i.call(e+"_sub",f,p,f),i.call(e+"_mul",f,C,f))}(),function(){const o=t.addFunction(a+"_negAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(n));o.addCode(i.call(e+"_copy",l,s),i.call(e+"_neg",c,r))}(),function(){const o=t.addFunction(a+"_neg");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*n));o.addCode(i.call(e+"_copy",l,r),i.call(e+"_neg",c,d),i.call(e+"_copy",s,u))}(),function(){const e=t.addFunction(a+"_subAffine");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(3*n));e.addCode(o.call(a+"_negAffine",o.getLocal("p2"),i),o.call(a+"_addAffine",o.getLocal("p1"),i,o.getLocal("pr")))}(),function(){const e=t.addFunction(a+"_subMixed");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(3*n));e.addCode(o.call(a+"_negAffine",o.getLocal("p2"),i),o.call(a+"_addMixed",o.getLocal("p1"),i,o.getLocal("pr")))}(),function(){const e=t.addFunction(a+"_sub");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(3*n));e.addCode(o.call(a+"_neg",o.getLocal("p2"),i),o.call(a+"_add",o.getLocal("p1"),i,o.getLocal("pr")))}(),function(){const o=t.addFunction(a+"_fromMontgomeryAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_fromMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<2;t++)o.addCode(i.call(e+"_fromMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_fromMontgomery");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_fromMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<3;t++)o.addCode(i.call(e+"_fromMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_toMontgomeryAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_toMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<2;t++)o.addCode(i.call(e+"_toMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_toMontgomery");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_toMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<3;t++)o.addCode(i.call(e+"_toMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_toAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_const(t.alloc(n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(e+"_zero",r),...i.call(e+"_zero",d)],[...i.call(e+"_inverse",s,u),...i.call(e+"_square",u,_),...i.call(e+"_mul",u,_,g),...i.call(e+"_mul",l,_,r),...i.call(e+"_mul",c,g,d)]))}(),function(){const i=t.addFunction(a+"_inCurveAffine");i.addParam("pIn","i32"),i.setReturnType("i32");const l=i.getCodeBuilder(),c=l.getLocal("pIn"),s=l.i32_add(l.getLocal("pIn"),l.i32_const(n)),r=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(n));i.addCode(l.call(e+"_square",s,r),l.call(e+"_square",c,d),l.call(e+"_mul",c,d,d),l.call(e+"_add",d,l.i32_const(o),d),l.ret(l.call(e+"_eq",r,d)))}(),function(){const e=t.addFunction(a+"_inCurve");e.addParam("pIn","i32"),e.setReturnType("i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(2*n));e.addCode(o.call(a+"_toAffine",o.getLocal("pIn"),i),o.ret(o.call(a+"_inCurveAffine",i)))}(),function(){const o=t.addFunction(a+"_batchToAffine");o.addParam("pIn","i32"),o.addParam("n","i32"),o.addParam("pOut","i32"),o.addLocal("pAux","i32"),o.addLocal("itIn","i32"),o.addLocal("itAux","i32"),o.addLocal("itOut","i32"),o.addLocal("i","i32");const i=o.getCodeBuilder(),l=i.i32_const(t.alloc(n));o.addCode(i.setLocal("pAux",i.i32_load(i.i32_const(0))),i.i32_store(i.i32_const(0),i.i32_add(i.getLocal("pAux"),i.i32_mul(i.getLocal("n"),i.i32_const(n)))),i.call(e+"_batchInverse",i.i32_add(i.getLocal("pIn"),i.i32_const(2*n)),i.i32_const(3*n),i.getLocal("n"),i.getLocal("pAux"),i.i32_const(n)),i.setLocal("itIn",i.getLocal("pIn")),i.setLocal("itAux",i.getLocal("pAux")),i.setLocal("itOut",i.getLocal("pOut")),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.if(i.call(e+"_isZero",i.getLocal("itAux")),[...i.call(e+"_zero",i.getLocal("itOut")),...i.call(e+"_zero",i.i32_add(i.getLocal("itOut"),i.i32_const(n)))],[...i.call(e+"_mul",i.getLocal("itAux"),i.i32_add(i.getLocal("itIn"),i.i32_const(n)),l),...i.call(e+"_square",i.getLocal("itAux"),i.getLocal("itAux")),...i.call(e+"_mul",i.getLocal("itAux"),i.getLocal("itIn"),i.getLocal("itOut")),...i.call(e+"_mul",i.getLocal("itAux"),l,i.i32_add(i.getLocal("itOut"),i.i32_const(n)))]),i.setLocal("itIn",i.i32_add(i.getLocal("itIn"),i.i32_const(3*n))),i.setLocal("itOut",i.i32_add(i.getLocal("itOut"),i.i32_const(2*n))),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(n))),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))),i.i32_store(i.i32_const(0),i.getLocal("pAux")))}(),function(){const o=t.addFunction(a+"_normalize");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.call(a+"_zero",i.getLocal("pr")),[...i.call(e+"_inverse",s,_),...i.call(e+"_square",_,g),...i.call(e+"_mul",_,g,f),...i.call(e+"_mul",l,g,r),...i.call(e+"_mul",c,f,d),...i.call(e+"_one",u)]))}(),function(){const e=t.addFunction(a+"__reverseBytes");e.addParam("pIn","i32"),e.addParam("n","i32"),e.addParam("pOut","i32"),e.addLocal("itOut","i32"),e.addLocal("itIn","i32");const o=e.getCodeBuilder();e.addCode(o.setLocal("itOut",o.i32_sub(o.i32_add(o.getLocal("pOut"),o.getLocal("n")),o.i32_const(1))),o.setLocal("itIn",o.getLocal("pIn")),o.block(o.loop(o.br_if(1,o.i32_lt_s(o.getLocal("itOut"),o.getLocal("pOut"))),o.i32_store8(o.getLocal("itOut"),o.i32_load8_u(o.getLocal("itIn"))),o.setLocal("itOut",o.i32_sub(o.getLocal("itOut"),o.i32_const(1))),o.setLocal("itIn",o.i32_add(o.getLocal("itIn"),o.i32_const(1))),o.br(0))))}(),function(){const e=t.addFunction(a+"_LEMtoU");e.addParam("pIn","i32"),e.addParam("pOut","i32");const o=e.getCodeBuilder(),i=t.alloc(2*n),l=o.i32_const(i),c=o.i32_const(i),s=o.i32_const(i+n);e.addCode(o.if(o.call(a+"_isZeroAffine",o.getLocal("pIn")),[...o.call(a+"_zeroAffine",o.getLocal("pOut")),...o.i32_store8(o.getLocal("pOut"),o.i32_const(64)),...o.ret([])]),o.call(a+"_fromMontgomeryAffine",o.getLocal("pIn"),l),o.call(a+"__reverseBytes",c,o.i32_const(n),o.getLocal("pOut")),o.call(a+"__reverseBytes",s,o.i32_const(n),o.i32_add(o.getLocal("pOut"),o.i32_const(n))))}(),function(){const o=t.addFunction(a+"_LEMtoC");o.addParam("pIn","i32"),o.addParam("pOut","i32");const i=o.getCodeBuilder(),l=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("pIn")),[...i.call(e+"_zero",i.getLocal("pOut")),...i.i32_store8(i.getLocal("pOut"),i.i32_const(64)),...i.ret([])]),i.call(e+"_fromMontgomery",i.getLocal("pIn"),l),i.call(a+"__reverseBytes",l,i.i32_const(n),i.getLocal("pOut")),i.if(i.i32_eq(i.call(e+"_sign",i.i32_add(i.getLocal("pIn"),i.i32_const(n))),i.i32_const(-1)),i.i32_store8(i.getLocal("pOut"),i.i32_or(i.i32_load8_u(i.getLocal("pOut")),i.i32_const(128)))))}(),function(){const e=t.addFunction(a+"_UtoLEM");e.addParam("pIn","i32"),e.addParam("pOut","i32");const o=e.getCodeBuilder(),i=t.alloc(2*n),l=o.i32_const(i),c=o.i32_const(i),s=o.i32_const(i+n);e.addCode(o.if(o.i32_and(o.i32_load8_u(o.getLocal("pIn")),o.i32_const(64)),[...o.call(a+"_zeroAffine",o.getLocal("pOut")),...o.ret([])]),o.call(a+"__reverseBytes",o.getLocal("pIn"),o.i32_const(n),c),o.call(a+"__reverseBytes",o.i32_add(o.getLocal("pIn"),o.i32_const(n)),o.i32_const(n),s),o.call(a+"_toMontgomeryAffine",l,o.getLocal("pOut")))}(),function(){const i=t.addFunction(a+"_CtoLEM");i.addParam("pIn","i32"),i.addParam("pOut","i32"),i.addLocal("firstByte","i32"),i.addLocal("greatest","i32");const l=i.getCodeBuilder(),c=t.alloc(2*n),s=l.i32_const(c),r=l.i32_const(c+n);i.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(a+"_zeroAffine",l.getLocal("pOut")),...l.ret([])]),l.setLocal("greatest",l.i32_and(l.getLocal("firstByte"),l.i32_const(128))),l.call(e+"_copy",l.getLocal("pIn"),r),l.i32_store8(r,l.i32_and(l.getLocal("firstByte"),l.i32_const(63))),l.call(a+"__reverseBytes",r,l.i32_const(n),s),l.call(e+"_toMontgomery",s,l.getLocal("pOut")),l.call(e+"_square",l.getLocal("pOut"),r),l.call(e+"_mul",l.getLocal("pOut"),r,r),l.call(e+"_add",r,l.i32_const(o),r),l.call(e+"_sqrt",r,r),l.call(e+"_neg",r,s),l.if(l.i32_eq(l.call(e+"_sign",r),l.i32_const(-1)),l.if(l.getLocal("greatest"),l.call(e+"_copy",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n))),l.call(e+"_neg",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n)))),l.if(l.getLocal("greatest"),l.call(e+"_neg",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n))),l.call(e+"_copy",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n))))))}(),gc(t,a+"_batchLEMtoU",a+"_LEMtoU",2*n,2*n),gc(t,a+"_batchLEMtoC",a+"_LEMtoC",2*n,n),gc(t,a+"_batchUtoLEM",a+"_UtoLEM",2*n,2*n),gc(t,a+"_batchCtoLEM",a+"_CtoLEM",n,2*n,!0),gc(t,a+"_batchToJacobian",a+"_toJacobian",2*n,3*n,!0),fc(t,a,a+"_multiexp",a+"_add",3*n),fc(t,a,a+"_multiexpAffine",a+"_addMixed",2*n),_c(t,a+"_timesScalar",3*n,a+"_add",a+"_double",a+"_sub",a+"_copy",a+"_zero"),_c(t,a+"_timesScalarAffine",2*n,a+"_addMixed",a+"_double",a+"_subMixed",a+"_copyAffine",a+"_zero"),t.exportFunction(a+"_isZero"),t.exportFunction(a+"_isZeroAffine"),t.exportFunction(a+"_eq"),t.exportFunction(a+"_eqMixed"),t.exportFunction(a+"_eqAffine"),t.exportFunction(a+"_copy"),t.exportFunction(a+"_copyAffine"),t.exportFunction(a+"_zero"),t.exportFunction(a+"_zeroAffine"),t.exportFunction(a+"_double"),t.exportFunction(a+"_doubleAffine"),t.exportFunction(a+"_add"),t.exportFunction(a+"_addMixed"),t.exportFunction(a+"_addAffine"),t.exportFunction(a+"_neg"),t.exportFunction(a+"_negAffine"),t.exportFunction(a+"_sub"),t.exportFunction(a+"_subMixed"),t.exportFunction(a+"_subAffine"),t.exportFunction(a+"_fromMontgomery"),t.exportFunction(a+"_fromMontgomeryAffine"),t.exportFunction(a+"_toMontgomery"),t.exportFunction(a+"_toMontgomeryAffine"),t.exportFunction(a+"_timesScalar"),t.exportFunction(a+"_timesScalarAffine"),t.exportFunction(a+"_normalize"),t.exportFunction(a+"_LEMtoU"),t.exportFunction(a+"_LEMtoC"),t.exportFunction(a+"_UtoLEM"),t.exportFunction(a+"_CtoLEM"),t.exportFunction(a+"_batchLEMtoU"),t.exportFunction(a+"_batchLEMtoC"),t.exportFunction(a+"_batchUtoLEM"),t.exportFunction(a+"_batchCtoLEM"),t.exportFunction(a+"_toAffine"),t.exportFunction(a+"_toJacobian"),t.exportFunction(a+"_batchToAffine"),t.exportFunction(a+"_batchToJacobian"),t.exportFunction(a+"_inCurve"),t.exportFunction(a+"_inCurveAffine"),a};const{isOdd:pc,modInv:mc,modPow:Lc}=vl,bc=Fl;var wc=function(t,a,e,o,i){const n=8*t.modules[o].n64,l=8*t.modules[e].n64,c=t.modules[o].q;let s=c-1n,r=0;for(;!pc(s);)r++,s>>=1n;let d=2n;for(;1n===Lc(d,c>>1n,c);)d+=1n;const u=new Array(r+1);u[r]=Lc(d,s,c);let _=r-1;for(;_>=0;)u[_]=Lc(u[_+1],2n,c),_--;const g=[],f=(1n<>e);return a}const x=Array(256);for(let t=0;t<256;t++)x[t]=F(t);const I=t.alloc(x);function B(){const e=t.addFunction(a+"_fft");e.addParam("px","i32"),e.addParam("n","i32"),e.addLocal("bits","i32");const i=e.getCodeBuilder(),l=i.i32_const(t.alloc(n));e.addCode(i.setLocal("bits",i.call(a+"__log2",i.getLocal("n"))),i.call(o+"_one",l),i.call(a+"_rawfft",i.getLocal("px"),i.getLocal("bits"),i.i32_const(0),l))}!function(){const e=t.addFunction(a+"__rev");e.addParam("x","i32"),e.addParam("bits","i32"),e.setReturnType("i32");const o=e.getCodeBuilder();e.addCode(o.i32_rotl(o.i32_add(o.i32_add(o.i32_shl(o.i32_load8_u(o.i32_and(o.getLocal("x"),o.i32_const(255)),I,0),o.i32_const(24)),o.i32_shl(o.i32_load8_u(o.i32_and(o.i32_shr_u(o.getLocal("x"),o.i32_const(8)),o.i32_const(255)),I,0),o.i32_const(16))),o.i32_add(o.i32_shl(o.i32_load8_u(o.i32_and(o.i32_shr_u(o.getLocal("x"),o.i32_const(16)),o.i32_const(255)),I,0),o.i32_const(8)),o.i32_load8_u(o.i32_and(o.i32_shr_u(o.getLocal("x"),o.i32_const(24)),o.i32_const(255)),I,0))),o.getLocal("bits")))}(),function(){const o=t.addFunction(a+"__reversePermutation");o.addParam("px","i32"),o.addParam("bits","i32"),o.addLocal("n","i32"),o.addLocal("i","i32"),o.addLocal("ri","i32"),o.addLocal("idx1","i32"),o.addLocal("idx2","i32");const i=o.getCodeBuilder(),n=i.i32_const(t.alloc(l));o.addCode(i.setLocal("n",i.i32_shl(i.i32_const(1),i.getLocal("bits"))),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.setLocal("idx1",i.i32_add(i.getLocal("px"),i.i32_mul(i.getLocal("i"),i.i32_const(l)))),i.setLocal("ri",i.call(a+"__rev",i.getLocal("i"),i.getLocal("bits"))),i.setLocal("idx2",i.i32_add(i.getLocal("px"),i.i32_mul(i.getLocal("ri"),i.i32_const(l)))),i.if(i.i32_lt_u(i.getLocal("i"),i.getLocal("ri")),[...i.call(e+"_copy",i.getLocal("idx1"),n),...i.call(e+"_copy",i.getLocal("idx2"),i.getLocal("idx1")),...i.call(e+"_copy",n,i.getLocal("idx2"))]),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))))}(),function(){const n=t.addFunction(a+"__fftFinal");n.addParam("px","i32"),n.addParam("bits","i32"),n.addParam("reverse","i32"),n.addParam("mulFactor","i32"),n.addLocal("n","i32"),n.addLocal("ndiv2","i32"),n.addLocal("pInv2","i32"),n.addLocal("i","i32"),n.addLocal("mask","i32"),n.addLocal("idx1","i32"),n.addLocal("idx2","i32");const c=n.getCodeBuilder(),s=c.i32_const(t.alloc(l));n.addCode(c.if(c.i32_and(c.i32_eqz(c.getLocal("reverse")),c.call(o+"_isOne",c.getLocal("mulFactor"))),c.ret([])),c.setLocal("n",c.i32_shl(c.i32_const(1),c.getLocal("bits"))),c.setLocal("mask",c.i32_sub(c.getLocal("n"),c.i32_const(1))),c.setLocal("i",c.i32_const(1)),c.setLocal("ndiv2",c.i32_shr_u(c.getLocal("n"),c.i32_const(1))),c.block(c.loop(c.br_if(1,c.i32_ge_u(c.getLocal("i"),c.getLocal("ndiv2"))),c.setLocal("idx1",c.i32_add(c.getLocal("px"),c.i32_mul(c.getLocal("i"),c.i32_const(l)))),c.setLocal("idx2",c.i32_add(c.getLocal("px"),c.i32_mul(c.i32_sub(c.getLocal("n"),c.getLocal("i")),c.i32_const(l)))),c.if(c.getLocal("reverse"),c.if(c.call(o+"_isOne",c.getLocal("mulFactor")),[...c.call(e+"_copy",c.getLocal("idx1"),s),...c.call(e+"_copy",c.getLocal("idx2"),c.getLocal("idx1")),...c.call(e+"_copy",s,c.getLocal("idx2"))],[...c.call(e+"_copy",c.getLocal("idx1"),s),...c.call(i,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx1")),...c.call(i,s,c.getLocal("mulFactor"),c.getLocal("idx2"))]),c.if(c.call(o+"_isOne",c.getLocal("mulFactor")),[],[...c.call(i,c.getLocal("idx1"),c.getLocal("mulFactor"),c.getLocal("idx1")),...c.call(i,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx2"))])),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0))),c.if(c.call(o+"_isOne",c.getLocal("mulFactor")),[],[...c.call(i,c.getLocal("px"),c.getLocal("mulFactor"),c.getLocal("px")),...c.setLocal("idx2",c.i32_add(c.getLocal("px"),c.i32_mul(c.getLocal("ndiv2"),c.i32_const(l)))),...c.call(i,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx2"))]))}(),function(){const c=t.addFunction(a+"_rawfft");c.addParam("px","i32"),c.addParam("bits","i32"),c.addParam("reverse","i32"),c.addParam("mulFactor","i32"),c.addLocal("s","i32"),c.addLocal("k","i32"),c.addLocal("j","i32"),c.addLocal("m","i32"),c.addLocal("mdiv2","i32"),c.addLocal("n","i32"),c.addLocal("pwm","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));c.addCode(s.call(a+"__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(h),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(o+"_one",r),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(i,s.getLocal("idx2"),r,d),s.call(e+"_copy",s.getLocal("idx1"),u),s.call(e+"_add",u,d,s.getLocal("idx1")),s.call(e+"_sub",u,d,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("pwm"),r),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(a+"__fftFinal",s.getLocal("px"),s.getLocal("bits"),s.getLocal("reverse"),s.getLocal("mulFactor")))}(),function(){const e=t.addFunction(a+"__log2");e.addParam("n","i32"),e.setReturnType("i32"),e.addLocal("bits","i32"),e.addLocal("aux","i32");const o=e.getCodeBuilder();e.addCode(o.setLocal("aux",o.i32_shr_u(o.getLocal("n"),o.i32_const(1)))),e.addCode(o.setLocal("bits",o.i32_const(0))),e.addCode(o.block(o.loop(o.br_if(1,o.i32_eqz(o.getLocal("aux"))),o.setLocal("aux",o.i32_shr_u(o.getLocal("aux"),o.i32_const(1))),o.setLocal("bits",o.i32_add(o.getLocal("bits"),o.i32_const(1))),o.br(0)))),e.addCode(o.if(o.i32_ne(o.getLocal("n"),o.i32_shl(o.i32_const(1),o.getLocal("bits"))),o.unreachable())),e.addCode(o.if(o.i32_gt_u(o.getLocal("bits"),o.i32_const(r)),o.unreachable())),e.addCode(o.getLocal("bits"))}(),B(),function(){const e=t.addFunction(a+"_ifft");e.addParam("px","i32"),e.addParam("n","i32"),e.addLocal("bits","i32"),e.addLocal("pInv2","i32");const o=e.getCodeBuilder();e.addCode(o.setLocal("bits",o.call(a+"__log2",o.getLocal("n"))),o.setLocal("pInv2",o.i32_add(o.i32_const(L),o.i32_mul(o.getLocal("bits"),o.i32_const(n)))),o.call(a+"_rawfft",o.getLocal("px"),o.getLocal("bits"),o.i32_const(1),o.getLocal("pInv2")))}(),function(){const c=t.addFunction(a+"_fftJoin");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));c.addCode(s.call(o+"_copy",s.getLocal("first"),r),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(i,s.getLocal("idx2"),r,d),s.call(e+"_copy",s.getLocal("idx1"),u),s.call(e+"_add",u,d,s.getLocal("idx1")),s.call(e+"_sub",u,d,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const c=t.addFunction(a+"_fftJoinExt");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));c.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(A),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.call(o+"_copy",s.getLocal("first"),r),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(e+"_add",s.getLocal("idx1"),s.getLocal("idx2"),d),s.call(i,s.getLocal("idx2"),s.getLocal("pShiftToM"),s.getLocal("idx2")),s.call(e+"_add",s.getLocal("idx1"),s.getLocal("idx2"),s.getLocal("idx2")),s.call(i,s.getLocal("idx2"),r,s.getLocal("idx2")),s.call(e+"_copy",d,s.getLocal("idx1")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const c=t.addFunction(a+"_fftJoinExtInv");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32"),c.addLocal("pSConst","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));c.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(o+"_copy",s.getLocal("first"),r),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(i,s.getLocal("idx2"),r,d),s.call(e+"_sub",s.getLocal("idx1"),d,s.getLocal("idx2")),s.call(i,s.getLocal("idx2"),s.getLocal("pSConst"),s.getLocal("idx2")),s.call(i,s.getLocal("idx1"),s.getLocal("pShiftToM"),s.getLocal("idx1")),s.call(e+"_sub",d,s.getLocal("idx1"),s.getLocal("idx1")),s.call(i,s.getLocal("idx1"),s.getLocal("pSConst"),s.getLocal("idx1")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const c=t.addFunction(a+"_fftMix");c.addParam("pBuff","i32"),c.addParam("n","i32"),c.addParam("exp","i32"),c.addLocal("nGroups","i32"),c.addLocal("nPerGroup","i32"),c.addLocal("nPerGroupDiv2","i32"),c.addLocal("pairOffset","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("j","i32"),c.addLocal("pwm","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));c.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(h),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(o+"_one",r),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(i,s.getLocal("idx2"),r,d),s.call(e+"_copy",s.getLocal("idx1"),u),s.call(e+"_add",u,d,s.getLocal("idx1")),s.call(e+"_sub",u,d,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("pwm"),r),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 o=t.addFunction(a+"_fftFinal");o.addParam("pBuff","i32"),o.addParam("n","i32"),o.addParam("factor","i32"),o.addLocal("idx1","i32"),o.addLocal("idx2","i32"),o.addLocal("i","i32"),o.addLocal("ndiv2","i32");const n=o.getCodeBuilder(),c=n.i32_const(t.alloc(l));o.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(i,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(i,n.getLocal("idx2"),n.getLocal("factor"),c),n.call(i,n.getLocal("idx1"),n.getLocal("factor"),n.getLocal("idx2")),n.call(e+"_copy",c,n.getLocal("idx1")),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))}(),function(){const c=t.addFunction(a+"_prepareLagrangeEvaluation");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32"),c.addLocal("pSConst","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));c.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(o+"_copy",s.getLocal("first"),r),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(i,s.getLocal("idx1"),s.getLocal("pShiftToM"),d),s.call(e+"_sub",s.getLocal("idx2"),d,d),s.call(e+"_sub",s.getLocal("idx1"),s.getLocal("idx2"),s.getLocal("idx2")),s.call(i,d,s.getLocal("pSConst"),s.getLocal("idx1")),s.call(i,s.getLocal("idx2"),r,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),t.exportFunction(a+"_fft"),t.exportFunction(a+"_ifft"),t.exportFunction(a+"_rawfft"),t.exportFunction(a+"_fftJoin"),t.exportFunction(a+"_fftJoinExt"),t.exportFunction(a+"_fftJoinExtInv"),t.exportFunction(a+"_fftMix"),t.exportFunction(a+"_fftFinal"),t.exportFunction(a+"_prepareLagrangeEvaluation")},yc=function(t,a,e){const o=8*t.modules[e].n64;return function(){const i=t.addFunction(a+"_zero");i.addParam("px","i32"),i.addParam("n","i32"),i.addLocal("lastp","i32"),i.addLocal("p","i32");const n=i.getCodeBuilder();i.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(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("p"),n.getLocal("lastp"))),n.call(e+"_zero",n.getLocal("p")),n.setLocal("p",n.i32_add(n.getLocal("p"),n.i32_const(o))),n.br(0))))}(),function(){const i=t.addFunction(a+"_constructLC");i.addParam("ppolynomials","i32"),i.addParam("psignals","i32"),i.addParam("nSignals","i32"),i.addParam("pres","i32"),i.addLocal("i","i32"),i.addLocal("j","i32"),i.addLocal("pp","i32"),i.addLocal("ps","i32"),i.addLocal("pd","i32"),i.addLocal("ncoefs","i32");const n=i.getCodeBuilder(),l=n.i32_const(t.alloc(o));i.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(o)))),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(4))),n.call(e+"_mul",n.getLocal("ps"),n.getLocal("pp"),l),n.call(e+"_add",l,n.getLocal("pd"),n.getLocal("pd")),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(o))),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(o))),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))}(),t.exportFunction(a+"_zero"),t.exportFunction(a+"_constructLC"),a},Ac=function(t,a,e){const o=8*t.modules[e].n64;return function(){const i=t.addFunction(a+"_buildABC");i.addParam("pCoefs","i32"),i.addParam("nCoefs","i32"),i.addParam("pWitness","i32"),i.addParam("pA","i32"),i.addParam("pB","i32"),i.addParam("pC","i32"),i.addParam("offsetOut","i32"),i.addParam("nOut","i32"),i.addParam("offsetWitness","i32"),i.addParam("nWitness","i32"),i.addLocal("it","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("last","i32"),i.addLocal("m","i32"),i.addLocal("c","i32"),i.addLocal("s","i32"),i.addLocal("pOut","i32");const n=i.getCodeBuilder(),l=n.i32_const(t.alloc(o));i.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(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_zero",n.getLocal("ita")),n.call(e+"_zero",n.getLocal("itb")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),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(o+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(o+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(o+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(o+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(o)))),n.call(e+"_mul",n.i32_add(n.getLocal("pWitness"),n.i32_mul(n.i32_sub(n.getLocal("s"),n.getLocal("offsetWitness")),n.i32_const(o))),n.i32_add(n.getLocal("it"),n.i32_const(12)),l),n.call(e+"_add",n.getLocal("pOut"),l,n.getLocal("pOut")),n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o+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(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_mul",n.getLocal("ita"),n.getLocal("itb"),n.getLocal("it")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o))),n.br(0))))}(),function(){const i=t.addFunction(a+"_joinABC");i.addParam("pA","i32"),i.addParam("pB","i32"),i.addParam("pC","i32"),i.addParam("n","i32"),i.addParam("pP","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("itc","i32"),i.addLocal("itp","i32"),i.addLocal("last","i32");const n=i.getCodeBuilder(),l=n.i32_const(t.alloc(o));i.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(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_mul",n.getLocal("ita"),n.getLocal("itb"),l),n.call(e+"_sub",l,n.getLocal("itc"),n.getLocal("itp")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.setLocal("itc",n.i32_add(n.getLocal("itc"),n.i32_const(o))),n.setLocal("itp",n.i32_add(n.getLocal("itp"),n.i32_const(o))),n.br(0))))}(),function(){const i=t.addFunction(a+"_batchAdd");i.addParam("pa","i32"),i.addParam("pb","i32"),i.addParam("n","i32"),i.addParam("pr","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("itr","i32"),i.addLocal("last","i32");const n=i.getCodeBuilder();i.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(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_add",n.getLocal("ita"),n.getLocal("itb"),n.getLocal("itr")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.setLocal("itr",n.i32_add(n.getLocal("itr"),n.i32_const(o))),n.br(0))))}(),t.exportFunction(a+"_buildABC"),t.exportFunction(a+"_joinABC"),t.exportFunction(a+"_batchAdd"),a},Cc=function(t,a,e,o,i,n,l,c){const s=t.addFunction(a);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 r=s.getCodeBuilder(),d=r.i32_const(t.alloc(l));s.addCode(r.setLocal("pFrom",r.getLocal("pIn")),r.setLocal("pTo",r.getLocal("pOut"))),s.addCode(r.call(o+"_copy",r.getLocal("pFirst"),d)),s.addCode(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(c,r.getLocal("pFrom"),d,r.getLocal("pTo")),r.setLocal("pFrom",r.i32_add(r.getLocal("pFrom"),r.i32_const(i))),r.setLocal("pTo",r.i32_add(r.getLocal("pTo"),r.i32_const(n))),r.call(o+"_mul",d,r.getLocal("pInc"),d),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0)))),t.exportFunction(a)};const Fc=Fl,xc=ac,Ic=ic,Bc=sc,Ec=uc,vc=hc,Sc=wc,Pc=yc,qc=Ac,Oc=Cc,{bitLength:Gc,modInv:zc,isOdd:Tc,isNegative:Mc}=vl;const Uc=Fl,Qc=ac,kc=ic,Rc=sc,Nc=uc,Dc=hc,$c=wc,jc=yc,Vc=Ac,Kc=Cc,{bitLength:Hc,isOdd:Zc,isNegative:Wc}=vl;var Yc=function(t,a){const e=a||"bn128";if(t.modules[e])return e;const o=21888242871839275222246405745257275088696311157297823662689037894645226208583n,i=21888242871839275222246405745257275088548364400416034343698204186575808495617n,n=Math.floor((Gc(o-1n)-1)/64)+1,l=8*n,c=l,s=l,r=2*s,d=12*s,u=t.alloc(Fc.bigInt2BytesLE(i,c)),_=xc(t,o,"f1m");Ic(t,i,"fr","frm");const g=t.alloc(Fc.bigInt2BytesLE(b(3n),s)),f=vc(t,"g1m","f1m",g);Sc(t,"frm","frm","frm","frm_mul"),Pc(t,"pol","frm"),qc(t,"qap","frm");const h=Bc(t,"f1m_neg","f2m","f1m"),p=t.alloc([...Fc.bigInt2BytesLE(b(19485874751759354771024239261021720505790618469301721065564631296452457478373n),s),...Fc.bigInt2BytesLE(b(266929791119991161246907387137283842545076965332900288569378510910307636690n),s)]),m=vc(t,"g2m","f2m",p);function L(a,e){const o=t.addFunction(a);o.addParam("pG","i32"),o.addParam("pFr","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),n=i.i32_const(t.alloc(l));o.addCode(i.call("frm_fromMontgomery",i.getLocal("pFr"),n),i.call(e,i.getLocal("pG"),n,i.i32_const(l),i.getLocal("pr"))),t.exportFunction(a)}function b(t){return BigInt(t)*(1n<0n;)Tc(a)?e.push(1):e.push(0),a>>=1n;return e}(29793968203157093288n),T=t.alloc(z),M=3*r,U=z.length-1,Q=z.reduce(((t,a)=>t+(0!=a?1:0)),0),k=6*l,R=3*l*2+(Q+U+1)*M;t.modules[e]={n64:n,pG1gen:y,pG1zero:C,pG1b:g,pG2gen:x,pG2zero:B,pG2b:p,pq:t.modules.f1m.pq,pr:u,pOneT:E,prePSize:k,preQSize:R,r:i.toString(),q:o.toString()};const N=4965661367192848881n;function D(a){const i=[[[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(e+"__frobeniusMap"+a);l.addParam("x","i32"),l.addParam("r","i32");const c=l.getCodeBuilder();for(let e=0;e<6;e++){const o=0==e?c.getLocal("x"):c.i32_add(c.getLocal("x"),c.i32_const(e*r)),u=o,g=c.i32_add(c.getLocal("x"),c.i32_const(e*r+s)),f=0==e?c.getLocal("r"):c.i32_add(c.getLocal("r"),c.i32_const(e*r)),p=f,m=c.i32_add(c.getLocal("r"),c.i32_const(e*r+s)),L=d(i[Math.floor(e/3)][a%12],n[e%3][a%6]),w=t.alloc([...Fc.bigInt2BytesLE(b(L[0]),32),...Fc.bigInt2BytesLE(b(L[1]),32)]);a%2==1?l.addCode(c.call(_+"_copy",u,p),c.call(_+"_neg",g,m),c.call(h+"_mul",f,c.i32_const(w),f)):l.addCode(c.call(h+"_mul",o,c.i32_const(w),f))}function d(t,a){const e=BigInt(t[0]),i=BigInt(t[1]),n=BigInt(a[0]),l=BigInt(a[1]),c=[(e*n-i*l)%o,(e*l+i*n)%o];return Mc(c[0])&&(c[0]=c[0]+o),c}}function $(a,o){const i=function(t){let a=t;const e=[];for(;a>0n;){if(Tc(a)){const t=2-Number(a%4n);e.push(t),a-=BigInt(t)}else e.push(0);a>>=1n}return e}(a).map((t=>-1==t?255:t)),n=t.alloc(i),l=t.addFunction(e+"__cyclotomicExp_"+o);l.addParam("x","i32"),l.addParam("r","i32"),l.addLocal("bit","i32"),l.addLocal("i","i32");const c=l.getCodeBuilder(),s=c.getLocal("x"),r=c.getLocal("r"),u=c.i32_const(t.alloc(d));l.addCode(c.call(G+"_conjugate",s,u),c.call(G+"_one",r),c.if(c.teeLocal("bit",c.i32_load8_s(c.i32_const(i.length-1),n)),c.if(c.i32_eq(c.getLocal("bit"),c.i32_const(1)),c.call(G+"_mul",r,s,r),c.call(G+"_mul",r,u,r))),c.setLocal("i",c.i32_const(i.length-2)),c.block(c.loop(c.call(e+"__cyclotomicSquare",r,r),c.if(c.teeLocal("bit",c.i32_load8_s(c.getLocal("i"),n)),c.if(c.i32_eq(c.getLocal("bit"),c.i32_const(1)),c.call(G+"_mul",r,s,r),c.call(G+"_mul",r,u,r))),c.br_if(1,c.i32_eqz(c.getLocal("i"))),c.setLocal("i",c.i32_sub(c.getLocal("i"),c.i32_const(1))),c.br(0))))}function j(){!function(){const a=t.addFunction(e+"__cyclotomicSquare");a.addParam("x","i32"),a.addParam("r","i32");const o=a.getCodeBuilder(),i=o.getLocal("x"),n=o.i32_add(o.getLocal("x"),o.i32_const(r)),l=o.i32_add(o.getLocal("x"),o.i32_const(2*r)),c=o.i32_add(o.getLocal("x"),o.i32_const(3*r)),s=o.i32_add(o.getLocal("x"),o.i32_const(4*r)),d=o.i32_add(o.getLocal("x"),o.i32_const(5*r)),u=o.getLocal("r"),_=o.i32_add(o.getLocal("r"),o.i32_const(r)),g=o.i32_add(o.getLocal("r"),o.i32_const(2*r)),f=o.i32_add(o.getLocal("r"),o.i32_const(3*r)),p=o.i32_add(o.getLocal("r"),o.i32_const(4*r)),m=o.i32_add(o.getLocal("r"),o.i32_const(5*r)),L=o.i32_const(t.alloc(r)),b=o.i32_const(t.alloc(r)),w=o.i32_const(t.alloc(r)),y=o.i32_const(t.alloc(r)),A=o.i32_const(t.alloc(r)),C=o.i32_const(t.alloc(r)),F=o.i32_const(t.alloc(r)),x=o.i32_const(t.alloc(r));a.addCode(o.call(h+"_mul",i,s,F),o.call(h+"_mul",s,o.i32_const(v),L),o.call(h+"_add",i,L,L),o.call(h+"_add",i,s,x),o.call(h+"_mul",x,L,L),o.call(h+"_mul",o.i32_const(v),F,x),o.call(h+"_add",F,x,x),o.call(h+"_sub",L,x,L),o.call(h+"_add",F,F,b),o.call(h+"_mul",c,l,F),o.call(h+"_mul",l,o.i32_const(v),w),o.call(h+"_add",c,w,w),o.call(h+"_add",c,l,x),o.call(h+"_mul",x,w,w),o.call(h+"_mul",o.i32_const(v),F,x),o.call(h+"_add",F,x,x),o.call(h+"_sub",w,x,w),o.call(h+"_add",F,F,y),o.call(h+"_mul",n,d,F),o.call(h+"_mul",d,o.i32_const(v),A),o.call(h+"_add",n,A,A),o.call(h+"_add",n,d,x),o.call(h+"_mul",x,A,A),o.call(h+"_mul",o.i32_const(v),F,x),o.call(h+"_add",F,x,x),o.call(h+"_sub",A,x,A),o.call(h+"_add",F,F,C),o.call(h+"_sub",L,i,u),o.call(h+"_add",u,u,u),o.call(h+"_add",L,u,u),o.call(h+"_add",b,s,p),o.call(h+"_add",p,p,p),o.call(h+"_add",b,p,p),o.call(h+"_mul",C,o.i32_const(P),x),o.call(h+"_add",x,c,f),o.call(h+"_add",f,f,f),o.call(h+"_add",x,f,f),o.call(h+"_sub",A,l,g),o.call(h+"_add",g,g,g),o.call(h+"_add",A,g,g),o.call(h+"_sub",w,n,_),o.call(h+"_add",_,_,_),o.call(h+"_add",w,_,_),o.call(h+"_add",y,d,m),o.call(h+"_add",m,m,m),o.call(h+"_add",y,m,m))}(),$(N,"w0");const a=t.addFunction(e+"__finalExponentiationLastChunk");a.addParam("x","i32"),a.addParam("r","i32");const o=a.getCodeBuilder(),i=o.getLocal("x"),n=o.getLocal("r"),l=o.i32_const(t.alloc(d)),c=o.i32_const(t.alloc(d)),s=o.i32_const(t.alloc(d)),u=o.i32_const(t.alloc(d)),_=o.i32_const(t.alloc(d)),g=o.i32_const(t.alloc(d)),f=o.i32_const(t.alloc(d)),p=o.i32_const(t.alloc(d)),m=o.i32_const(t.alloc(d)),L=o.i32_const(t.alloc(d)),b=o.i32_const(t.alloc(d)),w=o.i32_const(t.alloc(d)),y=o.i32_const(t.alloc(d)),A=o.i32_const(t.alloc(d)),C=o.i32_const(t.alloc(d)),F=o.i32_const(t.alloc(d)),x=o.i32_const(t.alloc(d)),I=o.i32_const(t.alloc(d)),B=o.i32_const(t.alloc(d)),E=o.i32_const(t.alloc(d)),S=o.i32_const(t.alloc(d));a.addCode(o.call(e+"__cyclotomicExp_w0",i,l),o.call(G+"_conjugate",l,l),o.call(e+"__cyclotomicSquare",l,c),o.call(e+"__cyclotomicSquare",c,s),o.call(G+"_mul",s,c,u),o.call(e+"__cyclotomicExp_w0",u,_),o.call(G+"_conjugate",_,_),o.call(e+"__cyclotomicSquare",_,g),o.call(e+"__cyclotomicExp_w0",g,f),o.call(G+"_conjugate",f,f),o.call(G+"_conjugate",u,p),o.call(G+"_conjugate",f,m),o.call(G+"_mul",m,_,L),o.call(G+"_mul",L,p,b),o.call(G+"_mul",b,c,w),o.call(G+"_mul",b,_,y),o.call(G+"_mul",y,i,A),o.call(e+"__frobeniusMap1",w,C),o.call(G+"_mul",C,A,F),o.call(e+"__frobeniusMap2",b,x),o.call(G+"_mul",x,F,I),o.call(G+"_conjugate",i,B),o.call(G+"_mul",B,w,E),o.call(e+"__frobeniusMap3",E,S),o.call(G+"_mul",S,I,n))}const V=t.alloc(k),K=t.alloc(R);function H(a){const o=t.addFunction(e+"_pairingEq"+a);for(let t=0;t0n;)Zc(a)?e.push(1):e.push(0),a>>=1n;return e}(0xd201000000010000n),z=t.alloc(G),T=3*s,M=G.length-1,U=G.reduce(((t,a)=>t+(0!=a?1:0)),0),Q=6*l,k=3*l*2+(U+M+1)*T,R=!0,N=15132376222941642752n;function D(a){const e=[[[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]]],i=[[[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"+a);n.addParam("x","i32"),n.addParam("r","i32");const r=n.getCodeBuilder();for(let o=0;o<6;o++){const u=0==o?r.getLocal("x"):r.i32_add(r.getLocal("x"),r.i32_const(o*s)),_=u,g=r.i32_add(r.getLocal("x"),r.i32_const(o*s+c)),h=0==o?r.getLocal("r"):r.i32_add(r.getLocal("r"),r.i32_const(o*s)),p=h,L=r.i32_add(r.getLocal("r"),r.i32_const(o*s+c)),b=d(e[Math.floor(o/3)][a%12],i[o%3][a%6]),w=t.alloc([...Uc.bigInt2BytesLE(y(b[0]),l),...Uc.bigInt2BytesLE(y(b[1]),l)]);a%2==1?n.addCode(r.call(f+"_copy",_,p),r.call(f+"_neg",g,L),r.call(m+"_mul",h,r.i32_const(w),h)):n.addCode(r.call(m+"_mul",u,r.i32_const(w),h))}function d(t,a){const e=t[0],i=t[1],n=a[0],l=a[1],c=[(e*n-i*l)%o,(e*l+i*n)%o];return Wc(c[0])&&(c[0]=c[0]+o),c}}function $(a,o,i){const n=function(t){let a=t;const e=[];for(;a>0n;){if(Zc(a)){const t=2-Number(a%4n);e.push(t),a-=BigInt(t)}else e.push(0);a>>=1n}return e}(a).map((t=>-1==t?255:t)),l=t.alloc(n),c=t.addFunction(e+"__cyclotomicExp_"+i);c.addParam("x","i32"),c.addParam("r","i32"),c.addLocal("bit","i32"),c.addLocal("i","i32");const s=c.getCodeBuilder(),d=s.getLocal("x"),u=s.getLocal("r"),_=s.i32_const(t.alloc(r));c.addCode(s.call(O+"_conjugate",d,_),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,_,u))),s.setLocal("i",s.i32_const(n.length-2)),s.block(s.loop(s.call(e+"__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,_,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)))),o&&c.addCode(s.call(O+"_conjugate",u,u))}t.modules[e]={n64q:n,n64r:d,n8q:l,n8r:u,pG1gen:C,pG1zero:x,pG1b:h,pG2gen:B,pG2zero:v,pG2b:L,pq:t.modules.f1m.pq,pr:g,pOneT:S,r:i,q:o,prePSize:Q,preQSize:k},function(){const a=t.addFunction(q+"_mul1");a.addParam("pA","i32"),a.addParam("pC1","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),o=e.getLocal("pA"),i=e.i32_add(e.getLocal("pA"),e.i32_const(2*c)),n=e.i32_add(e.getLocal("pA"),e.i32_const(4*c)),l=e.getLocal("pC1"),s=e.getLocal("pR"),r=e.i32_add(e.getLocal("pR"),e.i32_const(2*c)),d=e.i32_add(e.getLocal("pR"),e.i32_const(4*c)),u=e.i32_const(t.alloc(2*c)),_=e.i32_const(t.alloc(2*c));a.addCode(e.call(m+"_add",o,i,u),e.call(m+"_add",i,n,_),e.call(m+"_mul",i,l,d),e.call(m+"_mul",_,l,s),e.call(m+"_sub",s,d,s),e.call(m+"_mulNR",s,s),e.call(m+"_mul",u,l,r),e.call(m+"_sub",r,d,r))}(),function(){const a=t.addFunction(q+"_mul01");a.addParam("pA","i32"),a.addParam("pC0","i32"),a.addParam("pC1","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),o=e.getLocal("pA"),i=e.i32_add(e.getLocal("pA"),e.i32_const(2*c)),n=e.i32_add(e.getLocal("pA"),e.i32_const(4*c)),l=e.getLocal("pC0"),s=e.getLocal("pC1"),r=e.getLocal("pR"),d=e.i32_add(e.getLocal("pR"),e.i32_const(2*c)),u=e.i32_add(e.getLocal("pR"),e.i32_const(4*c)),_=e.i32_const(t.alloc(2*c)),g=e.i32_const(t.alloc(2*c)),f=e.i32_const(t.alloc(2*c)),h=e.i32_const(t.alloc(2*c));a.addCode(e.call(m+"_mul",o,l,_),e.call(m+"_mul",i,s,g),e.call(m+"_add",o,i,f),e.call(m+"_add",o,n,h),e.call(m+"_add",i,n,r),e.call(m+"_mul",r,s,r),e.call(m+"_sub",r,g,r),e.call(m+"_mulNR",r,r),e.call(m+"_add",r,_,r),e.call(m+"_add",l,s,d),e.call(m+"_mul",d,f,d),e.call(m+"_sub",d,_,d),e.call(m+"_sub",d,g,d),e.call(m+"_mul",h,l,u),e.call(m+"_sub",u,_,u),e.call(m+"_add",u,g,u))}(),function(){const a=t.addFunction(O+"_mul014");a.addParam("pA","i32"),a.addParam("pC0","i32"),a.addParam("pC1","i32"),a.addParam("pC4","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),o=e.getLocal("pA"),i=e.i32_add(e.getLocal("pA"),e.i32_const(6*c)),n=e.getLocal("pC0"),l=e.getLocal("pC1"),s=e.getLocal("pC4"),r=e.i32_const(t.alloc(6*c)),d=e.i32_const(t.alloc(6*c)),u=e.i32_const(t.alloc(2*c)),_=e.getLocal("pR"),g=e.i32_add(e.getLocal("pR"),e.i32_const(6*c));a.addCode(e.call(q+"_mul01",o,n,l,r),e.call(q+"_mul1",i,s,d),e.call(m+"_add",l,s,u),e.call(q+"_add",i,o,g),e.call(q+"_mul01",g,n,u,g),e.call(q+"_sub",g,r,g),e.call(q+"_sub",g,d,g),e.call(q+"_copy",d,_),e.call(q+"_mulNR",_,_),e.call(q+"_add",_,r,_))}(),function(){const a=t.addFunction(e+"_ell");a.addParam("pP","i32"),a.addParam("pCoefs","i32"),a.addParam("pF","i32");const o=a.getCodeBuilder(),i=o.getLocal("pP"),n=o.i32_add(o.getLocal("pP"),o.i32_const(l)),s=o.getLocal("pF"),r=o.getLocal("pCoefs"),d=o.i32_add(o.getLocal("pCoefs"),o.i32_const(c)),u=o.i32_add(o.getLocal("pCoefs"),o.i32_const(2*c)),_=o.i32_add(o.getLocal("pCoefs"),o.i32_const(3*c)),g=o.i32_add(o.getLocal("pCoefs"),o.i32_const(4*c)),h=t.alloc(2*c),p=o.i32_const(h),m=o.i32_const(h),L=o.i32_const(h+c),b=t.alloc(2*c),w=o.i32_const(b),y=o.i32_const(b),A=o.i32_const(b+c);a.addCode(o.call(f+"_mul",r,n,m),o.call(f+"_mul",d,n,L),o.call(f+"_mul",u,i,y),o.call(f+"_mul",_,i,A),o.call(O+"_mul014",s,g,w,p,s))}();const j=t.alloc(Q),V=t.alloc(k);function K(a){const o=t.addFunction(e+"_pairingEq"+a);for(let t=0;t>=1;return e}function as(t,a){return(Xc[t>>>24]|Xc[t>>>16&255]<<8|Xc[t>>>8&255]<<16|Xc[255&t]<<24)>>>32-a}function es(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 os(t,a){const e=new Uint8Array(a*t.length);for(let o=0;o0;){const t=l+c>ns?ns-l:c,a=new Uint8Array(this.buffers[n].buffer,this.buffers[n].byteOffset+l,t);if(t==e)return a.slice();i||(i=e<=ns?new Uint8Array(e):new ls(e)),i.set(a,e-c),c-=t,n++,l=0}return i}set(t,a){void 0===a&&(a=0);const e=t.byteLength;if(0==e)return;const o=Math.floor(a/ns);if(o==Math.floor((a+e-1)/ns))return t instanceof ls&&1==t.buffers.length?this.buffers[o].set(t.buffers[0],a%ns):this.buffers[o].set(t,a%ns);let i=o,n=a%ns,l=e;for(;l>0;){const a=n+l>ns?ns-n:l,o=t.slice(e-l,e-l+a);new Uint8Array(this.buffers[i].buffer,this.buffers[i].byteOffset+n,a).set(o),l-=a,i++,n=0}}}function cs(t,a,e,o){return async function(i){const n=Math.floor(i.byteLength/e);if(n*e!==i.byteLength)throw new Error("Invalid buffer size");const l=Math.floor(n/t.concurrency),c=[];for(let s=0;s=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=cs(t,a+"_batchToMontgomery",this.n8,this.n8),this.batchFromMontgomery=cs(t,a+"_batchFromMontgomery",this.n8,this.n8)}op2(t,a,e){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op2Bool(t,a,e){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,e),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2)}op1(t,a){return this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op1Bool(t,a){return this.tm.setBuff(this.pOp1,a),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3)}add(t,a){return this.op2("_add",t,a)}eq(t,a){return this.op2Bool("_eq",t,a)}isZero(t){return this.op1Bool("_isZero",t)}sub(t,a){return this.op2("_sub",t,a)}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,a){return this.op2("_mul",t,a)}div(t,a){return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),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,a){return a instanceof Uint8Array||(a=dl(Kn(a))),this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+"_exp"](this.pOp1,this.pOp2,a.byteLength,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}isNegative(t){return this.op1Bool("_isNegative",t)}e(t,a){if(t instanceof Uint8Array)return t;let e=Kn(t,a);!function(t){return BigInt(t)>=BigInt(32)):n+2<=a?(i.setUint16(n,Number(e&BigInt(65535)),!0),n+=2,e>>=BigInt(16)):(i.setUint8(n,Number(e&BigInt(255)),!0),n+=1,e>>=BigInt(8));if(e)throw new Error("Number does not fit in this length");return o}(e,this.n8);return this.toMontgomery(o)}toString(t,a){return rl(sl(this.fromMontgomery(t),0),a)}fromRng(t){let a;const e=new Uint8Array(this.n8);do{a=ul;for(let e=0;e=BigInt(i));var o,i;return cl(e,0,a,this.n8),e}random(){return this.fromRng(bl())}toObject(t){return sl(this.fromMontgomery(t),0)}fromObject(t){const a=new Uint8Array(this.n8);return cl(a,0,t,this.n8),this.toMontgomery(a)}toRprLE(t,a,e){t.set(this.fromMontgomery(e),a)}toRprBE(t,a,e){const o=this.fromMontgomery(e);for(let t=0;to.buffer.byteLength){const i=o.buffer.byteLength/65536;let n=Math.floor((e[0]+t)/65536)+1;n>a&&(n=a),o.grow(n-i)}return i}function l(t){const a=n(t.byteLength);return s(a,t),a}function c(t,a){const e=new Uint8Array(o.buffer);return new Uint8Array(e.buffer,e.byteOffset+t,a)}function s(t,a){new Uint8Array(o.buffer).set(new Uint8Array(a),t)}function r(t){if("INIT"==t[0].cmd)return i(t[0]);const a={vars:[],out:[]},r=new Uint32Array(o.buffer,0,1)[0];for(let o=0;o{this.reject=a,this.resolve=t}))}}const hs=function(t){return globalThis.btoa(t)}("("+_s.toString()+")(self)"),ps="data:application/javascript;base64,"+hs;class ms{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,a,e,o){if(this.working[t])throw new Error("Posting a job t a working worker");return this.working[t]=!0,this.pendingDeferreds[t]=o||new fs,this.workers[t].postMessage(a,e),this.pendingDeferreds[t].promise}processWorks(){for(let t=0;t0;t++)if(0==this.working[t]){const a=this.actionQueue.shift();this.postAction(t,a.data,a.transfers,a.deferred)}}queueAction(t,a){const e=new fs;if(this.singleThread){const a=this.taskManager(t);e.resolve(a)}else this.actionQueue.push({data:t,transfers:a,deferred:e}),this.processWorks();return e.promise}resetMemory(){this.u32[0]=this.initalPFree}allocBuff(t){const a=this.alloc(t.byteLength);return this.setBuff(a,t),a}getBuff(t,a){return this.u8.slice(t,t+a)}setBuff(t,a){this.u8.set(new Uint8Array(a),t)}alloc(t){for(;3&this.u32[0];)this.u32[0]++;const a=this.u32[0];return this.u32[0]+=t,a}async terminate(){for(let t=0;tsetTimeout(a,t))))}}function Ls(t,a){const e=t[a],o=t.Fr,i=t.tm;t[a].batchApplyKey=async function(t,n,l,c,s){let r,d,u,_,g;if(c=c||"affine",s=s||"affine","G1"==a)"jacobian"==c?(u=3*e.F.n8,r="g1m_batchApplyKey"):(u=2*e.F.n8,r="g1m_batchApplyKeyMixed"),_=3*e.F.n8,"jacobian"==s?g=3*e.F.n8:(d="g1m_batchToAffine",g=2*e.F.n8);else if("G2"==a)"jacobian"==c?(u=3*e.F.n8,r="g2m_batchApplyKey"):(u=2*e.F.n8,r="g2m_batchApplyKeyMixed"),_=3*e.F.n8,"jacobian"==s?g=3*e.F.n8:(d="g2m_batchToAffine",g=2*e.F.n8);else{if("Fr"!=a)throw new Error("Invalid group: "+a);r="frm_batchApplyKey",u=e.n8,_=e.n8,g=e.n8}const f=Math.floor(t.byteLength/u),h=Math.floor(f/i.concurrency),p=[];l=o.e(l);let m=o.e(n);for(let a=0;a=0;t--){if(!e.isZero(h))for(let t=0;tr&&(h=r),h<1024&&(h=1024);const p=[];for(let a=0;a(c&&c.debug(`Multiexp end: ${s}: ${a}/${u}`),t))))}const m=await Promise.all(p);let L=e.zero;for(let t=m.length-1;t>=0;t--)L=e.add(L,m[t]);return L}e.multiExp=async function(t,a,e,o){return await n(t,a,"jacobian",e,o)},e.multiExpAffine=async function(t,a,e,o){return await n(t,a,"affine",e,o)}}function ys(t,a){const e=t[a],o=t.Fr,i=e.tm;async function n(t,c,s,r,d,u){s=s||"affine",r=r||"affine";let _,g,f,h,p,m,L,b;"G1"==a?("affine"==s?(_=2*e.F.n8,h="g1m_batchToJacobian"):_=3*e.F.n8,g=3*e.F.n8,c&&(b="g1m_fftFinal"),L="g1m_fftJoin",m="g1m_fftMix","affine"==r?(f=2*e.F.n8,p="g1m_batchToAffine"):f=3*e.F.n8):"G2"==a?("affine"==s?(_=2*e.F.n8,h="g2m_batchToJacobian"):_=3*e.F.n8,g=3*e.F.n8,c&&(b="g2m_fftFinal"),L="g2m_fftJoin",m="g2m_fftMix","affine"==r?(f=2*e.F.n8,p="g2m_batchToAffine"):f=3*e.F.n8):"Fr"==a&&(_=e.n8,g=e.n8,f=e.n8,c&&(b="frm_fftFinal"),m="frm_fftMix",L="frm_fftJoin");let w=!1;Array.isArray(t)?(t=os(t,_),w=!0):t=t.slice(0,t.byteLength);const y=t.byteLength/_,A=es(y);if(1<1<<28?new ls(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return _.set(u[0]),_.set(u[1],u[0].byteLength),_}(t,s,r,d,u):await async function(t,a,e,i,c){let s,r;s=t.slice(0,t.byteLength/2),r=t.slice(t.byteLength/2,t.byteLength);const d=[];[s,r]=await l(s,r,"fftJoinExt",o.one,o.shift,a,"jacobian",i,c),d.push(n(s,!1,"jacobian",e,i,c)),d.push(n(r,!1,"jacobian",e,i,c));const u=await Promise.all(d);let _;_=u[0].byteLength>1<<28?new ls(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return _.set(u[0]),_.set(u[1],u[0].byteLength),_}(t,s,r,d,u),w?is(a,f):a}let C,F,x;c&&(C=o.inv(o.e(y))),function(t,a){const e=t.byteLength/a,o=es(e);if(e!=1<e){const o=t.slice(i*a,(i+1)*a);t.set(t.slice(e*a,(e+1)*a),i*a),t.set(o,e*a)}}}(t,_);let I=Math.min(16384,y),B=y/I;for(;B=16;)B*=2,I/=2;const E=es(I),v=[];for(let a=0;a(d&&d.debug(`${u}: fft ${A} mix end: ${a}/${B}`),t))))}x=await Promise.all(v);for(let t=0;t(d&&d.debug(`${u}: fft ${A} join ${t}/${A} ${l+1}/${a} ${c}/${e/2}`),o))))}const l=await Promise.all(n);for(let t=0;t0;a--)F.set(x[a],t),t+=I*f,delete x[a];F.set(x[0].slice(0,(I-1)*f),t),delete x[0]}else for(let t=0;t65536&&(w=65536);const y=[];for(let a=0;a(u&&u.debug(`${_}: fftJoinExt End: ${a}/${b}`),t))))}const A=await Promise.all(y);let C,F;b*p>1<<28?(C=new ls(b*p),F=new ls(b*p)):(C=new Uint8Array(b*p),F=new Uint8Array(b*p));let x=0;for(let t=0;to.s+1)throw s&&s.error("lagrangeEvaluations input too big"),new Error("lagrangeEvaluations input too big");let g=t.slice(0,t.byteLength/2),f=t.slice(t.byteLength/2,t.byteLength);const h=o.exp(o.shift,u/2),p=o.inv(o.sub(o.one,h));[g,f]=await l(g,f,"prepareLagrangeEvaluation",p,o.shiftInv,i,"jacobian",s,r+" prep");const m=[];let L;return m.push(n(g,!0,"jacobian",c,s,r+" t0")),m.push(n(f,!0,"jacobian",c,s,r+" t1")),[g,f]=await Promise.all(m),L=g.byteLength>1<<28?new ls(2*g.byteLength):new Uint8Array(2*g.byteLength),L.set(g),L.set(f,g.byteLength),L},e.fftMix=async function(t){const n=3*e.F.n8;let l,c;if("G1"==a)l="g1m_fftMix",c="g1m_fftJoin";else if("G2"==a)l="g2m_fftMix",c="g2m_fftJoin";else{if("Fr"!=a)throw new Error("Invalid group");l="frm_fftMix",c="frm_fftJoin"}const s=Math.floor(t.byteLength/n),r=es(s);let d=1<=0;t--)g.set(_[t][0],f),f+=_[t][0].byteLength;return g}}async function As(t){const a=await async function(t,a){const e=new ms;e.memory=new WebAssembly.Memory({initial:gs}),e.u8=new Uint8Array(e.memory.buffer),e.u32=new Uint32Array(e.memory.buffer);const o=await WebAssembly.compile(t.code);if(e.instance=await WebAssembly.instantiate(o,{env:{memory:e.memory}}),e.singleThread=a,e.initalPFree=e.u32[0],e.pq=t.pq,e.pr=t.pr,e.pG1gen=t.pG1gen,e.pG1zero=t.pG1zero,e.pG2gen=t.pG2gen,e.pG2zero=t.pG2zero,e.pOneT=t.pOneT,a)e.code=t.code,e.taskManager=_s(),await e.taskManager([{cmd:"INIT",init:gs,code:e.code.slice()}]),e.concurrency=1;else{let a;e.workers=[],e.pendingDeferreds=[],e.working=[],a="object"==typeof navigator&&navigator.hardwareConcurrency?navigator.hardwareConcurrency:Qa.cpus().length,0==a&&(a=2),a>64&&(a=64),e.concurrency=a;for(let t=0;t=this.length&&(this.length=t+1),!0}getKeys(){const t=new vs;for(let a=0;a1<<20?new vs:[];for(let t=0;t1<<20?new vs:[];for(let t=0;t1<<20?new vs:[];for(let t=0;t{let o="";return Object.keys(e).forEach((i=>{let n=a.varIdx2Name[i];"one"==n&&(n="1");let l=t.curve.Fr.toString(e[i]);"1"==l&&(l=""),"-1"==l&&(l="-"),""!=o&&"-"!=l[0]&&(l="+"+l),""!=o&&(l=" "+l),o=o+l+n})),o},n=`[ ${i(o[0])} ] * [ ${i(o[1])} ] - [ ${i(o[2])} ] = 0`;e&&e.info(n)}},info:async function(t,a){const e=await Gs(t);return fe.eq(e.prime,Ts)?a&&a.info("Curve: bn-128"):fe.eq(e.prime,zs)?a&&a.info("Curve: bls12-381"):a&&a.info(`Unknown Curve. Prime: ${fe.toString(e.prime)}`),a&&a.info(`# of Wires: ${e.nVars}`),a&&a.info(`# of Constraints: ${e.nConstraints}`),a&&a.info(`# of Private Inputs: ${e.nPrvInputs}`),a&&a.info(`# of Public Inputs: ${e.nPubInputs}`),a&&a.info(`# of Labels: ${e.nLabels}`),a&&a.info(`# of Outputs: ${e.nOutputs}`),e},exportJson:async function(t,a){const e=await Gs(t,!0,!0,!0,a),o=e.curve.Fr;return delete e.curve,delete e.F,Zo(o,e)}});async function Us(t){const a={labelIdx2Name:["one"],varIdx2Name:["one"],componentIdx2Name:[]},e=await Me(t),o=await e.read(e.totalSize),i=new TextDecoder("utf-8").decode(o).split("\n");for(let t=0;t Reading r1cs file");const{fd:o,sections:i}=await Ue(t,"r1cs",1),n=await Os(o,i,{loadConstraints:!1,loadCustomGates:!1});e&&e.info("> Reading witness file");const{fd:l,sections:c}=await Ue(a,"wtns",2),s=await Si(l,c);if(!fe.eq(n.prime,s.q))throw new Error("Curve of the witness does not match the curve of the proving key");const r=await Ke(l,c,2);await l.close();const d=(await async function(t){let a;if(fe.eq(t,We))a=await _e();else{if(!fe.eq(t,Ze))throw new Error(`Curve not supported: ${fe.toString(t)}`);a=await ge()}return a}(n.prime)).Fr,u=d.n8,_=await Ke(o,i,2);e&&(e.info("----------------------------"),e.info(" WITNESS CHECK"),e.info(` Curve: ${n.curve.name}`),e.info(` Vars (wires): ${n.nVars}`),e.info(` Ouputs: ${n.nOutputs}`),e.info(` Public Inputs: ${n.nPubInputs}`),e.info(` Private Inputs: ${n.nPrvInputs}`),e.info(` Labels: ${n.nLabels}`),e.info(` Constraints: ${n.nConstraints}`),e.info(` Custom Gates: ${n.useCustomGates}`),e.info("----------------------------")),e&&e.info("> Checking witness correctness");let g=0,f=!0;for(let t=0;t{const o=function(t){return d.fromRprLE(r.slice(t*u,t*u+u))}(e),i=t[e];a=d.add(a,d.mul(o,i))})),a}function p(){const t={},a=_.slice(g,g+4);g+=4;const e=new DataView(a.buffer).getUint32(0,!0),o=_.slice(g,g+(4+n.n8)*e);g+=(4+n.n8)*e;const i=new DataView(o.buffer);for(let a=0;a=this.length&&(this.length=t+1),!0}getKeys(){const t=new $s;for(let a=0;a_)return o&&o.error(`circuit too big for this power of tau ceremony. ${h.nConstraints}*2 > 2**${_}`),-1;if(!d[12])return o&&o.error("Powers of tau is not prepared."),-1;const w=h.nOutputs+h.nPubInputs,y=2**b;await ke(p,1),await p.writeULE32(1),await Re(p),await ke(p,2);const A=u.q,C=8*(Math.floor((fe.bitLength(A)-1)/64)+1),F=u.r,x=8*(Math.floor((fe.bitLength(F)-1)/64)+1),I=fe.mod(fe.shl(1,8*x),F),B=u.Fr.e(fe.mod(fe.mul(I,I),F));let E,v,S;await p.writeULE32(C),await $e(p,A,C),await p.writeULE32(x),await $e(p,F,x),await p.writeULE32(h.nVars),await p.writeULE32(w),await p.writeULE32(y),E=await r.read(m,d[4][0].p),await p.write(E),E=await u.G1.batchLEMtoU(E),s.update(E),v=await r.read(m,d[5][0].p),await p.write(v),v=await u.G1.batchLEMtoU(v),s.update(v),S=await r.read(L,d[6][0].p),await p.write(S),S=await u.G2.batchLEMtoU(S),s.update(S);const P=new Uint8Array(m);u.G1.toRprLEM(P,0,u.G1.g);const q=new Uint8Array(L);u.G2.toRprLEM(q,0,u.G2.g);const O=new Uint8Array(m);u.G1.toRprUncompressed(O,0,u.G1.g);const G=new Uint8Array(L);u.G2.toRprUncompressed(G,0,u.G2.g),await p.write(q),await p.write(P),await p.write(q),s.update(G),s.update(O),s.update(G),await Re(p),o&&o.info("Reading r1cs");let z=await Ke(g,f,2);const T=new $s(h.nVars),M=new $s(h.nVars),U=new $s(h.nVars),Q=new $s(h.nVars-w-1),k=new Array(w+1);o&&o.info("Reading tauG1");let R=await Ke(r,d,12,(y-1)*m,y*m);o&&o.info("Reading tauG2");let N=await Ke(r,d,13,(y-1)*L,y*L);o&&o.info("Reading alphatauG1");let D=await Ke(r,d,14,(y-1)*m,y*m);o&&o.info("Reading betatauG1");let $=await Ke(r,d,15,(y-1)*m,y*m);await async function(){const t=new Uint8Array(12+u.Fr.n8),a=new DataView(t.buffer),e=new Uint8Array(u.Fr.n8);u.Fr.toRprLE(e,0,u.Fr.e(1));let s=0;function r(){const t=z.slice(s,s+4);s+=4;return new DataView(t.buffer).getUint32(0,!0)}const d=new $s;for(let t=0;t=0?u.Fr.fromRprLE(z.slice(o[3],o[3]+u.Fr.n8),0):u.Fr.fromRprLE(e,0);const n=u.Fr.mul(i,B);u.Fr.toRprLE(t,12,n),_.set(t,f),f+=t.length}await p.write(_),await Re(p)}(),await V(3,"G1",k,"IC"),await async function(){await ke(p,9);const t=new qa(y*m);if(b(o&&o.debug(`Writing points end ${i}: ${d}/${e.length}`),t)))),c+=n,t++}const r=await Promise.all(l);for(let t=0;t32768?(g=new qa(h*n),f=new qa(h*u.Fr.n8)):(g=new Uint8Array(h*n),f=new Uint8Array(h*u.Fr.n8));let p=0,m=0;const L=[R,N,D,$],b=new Uint8Array(u.Fr.n8);u.Fr.toRprLE(b,0,u.Fr.e(1));let w=0;for(let t=0;t=0?f.set(z.slice(a[t][i][2],a[t][i][2]+u.Fr.n8),w*u.Fr.n8):f.set(b,w*u.Fr.n8),w++;if(a.length>1){const t=[];t.push({cmd:"ALLOCSET",var:0,buff:g}),t.push({cmd:"ALLOCSET",var:1,buff:f}),t.push({cmd:"ALLOC",var:2,len:a.length*l}),p=0,m=0;let e=0;for(let o=0;o=0;t--){const a=d.contributions[t];o&&o.info("-------------------------"),o&&o.info(Uo(a.contributionHash,`contribution #${t+1} ${a.name?a.name:""}:`)),1==a.type&&(o&&o.info(`Beacon generator: ${Ho(a.beaconHash)}`),o&&o.info(`Beacon iterations Exp: ${a.numIterationsExp}`))}return o&&o.info("-------------------------"),o&&o.info("ZKey Ok!"),!0;async function L(t,a){const e=2*s.G1.F.n8,o=t.byteLength/e,i=s.tm.concurrency,n=Math.floor(o/i),l=[];for(let e=0;e Detected protocol: "+i.protocol),"groth16"===i.protocol)n=await async function(t,a,e){const o=await Xe(t.q),i=2*o.G1.F.n8,n=await o.pairing(t.vk_alpha_1,t.vk_beta_2);let l={protocol:t.protocol,curve:o.name,nPublic:t.nPublic,vk_alpha_1:o.G1.toObject(t.vk_alpha_1),vk_beta_2:o.G2.toObject(t.vk_beta_2),vk_gamma_2:o.G2.toObject(t.vk_gamma_2),vk_delta_2:o.G2.toObject(t.vk_delta_2),vk_alphabeta_12:o.Gt.toObject(n)};await Ne(a,e,3),l.IC=[];for(let e=0;e<=t.nPublic;e++){const t=await a.read(i),e=o.G1.toObject(t);l.IC.push(e)}return await De(a),l=Hs(l),l}(i,e,o);else if("plonk"===i.protocol)n=await async function(t){const a=await Xe(t.q);let e={protocol:t.protocol,curve:a.name,nPublic:t.nPublic,power:t.power,k1:a.Fr.toObject(t.k1),k2:a.Fr.toObject(t.k2),Qm:a.G1.toObject(t.Qm),Ql:a.G1.toObject(t.Ql),Qr:a.G1.toObject(t.Qr),Qo:a.G1.toObject(t.Qo),Qc:a.G1.toObject(t.Qc),S1:a.G1.toObject(t.S1),S2:a.G1.toObject(t.S2),S3:a.G1.toObject(t.S3),X_2:a.G2.toObject(t.X_2),w:a.Fr.toObject(a.Fr.w[t.power])};return e=Hs(e),e}(i);else{if(!i.protocolId||i.protocolId!==Xo)throw new Error("zkey file protocol unrecognized");n=await async function(t,a){const e=await Xe(t.q);let o={protocol:t.protocol,curve:e.name,nPublic:t.nPublic,power:t.power,k1:e.Fr.toObject(t.k1),k2:e.Fr.toObject(t.k2),w:e.Fr.toObject(e.Fr.w[t.power]),w3:e.Fr.toObject(t.w3),w4:e.Fr.toObject(t.w4),w8:e.Fr.toObject(t.w8),wr:e.Fr.toObject(t.wr),X_2:e.G2.toObject(t.X_2),C0:e.G1.toObject(t.C0)};return Hs(o)}(i)}return await e.close(),a&&a.info("EXPORT VERIFICATION KEY FINISHED"),n}var Ws={};const{unstringifyBigInts:Ys,stringifyBigInts:Js}=he;async function Xs(t,a,e){e&&e.info("FFLONK EXPORT SOLIDITY VERIFIER STARTED");const o=await to(t.curve);let i=r(t.w3);t.w3_2=d(o.Fr.square(i));let n=r(t.w4);t.w4_2=d(o.Fr.square(n)),t.w4_3=d(o.Fr.mul(o.Fr.square(n),n));let l=r(t.w8),c=o.Fr.one;for(let a=1;a<8;a++)c=o.Fr.mul(c,l),t["w8_"+a]=d(c);let s=a[t.protocol];return e&&e.info("FFLONK EXPORT SOLIDITY VERIFIER FINISHED"),Ws.render(s,t);function r(t){const a=Ys(t);return o.Fr.fromObject(a)}function d(t){const a=o.Fr.toObject(t);return Js(a)}}var tr=Object.freeze({__proto__:null,newZKey:js,exportBellman:async function(t,a,e){const{fd:o,sections:i}=await Ue(t,"zkey",2),n=await Ci(o,i);if("groth16"!=n.protocol)throw new Error("zkey file is not groth16");const l=await Xe(n.q),c=2*l.G1.F.n8,s=2*l.G2.F.n8,r=await xi(o,l,i),d=await Te(a);let u;await L(n.vk_alpha_1),await L(n.vk_beta_1),await b(n.vk_beta_2),await b(n.vk_gamma_2),await L(n.vk_delta_1),await b(n.vk_delta_2),u=await Ke(o,i,3),u=await l.G1.batchLEMtoU(u),await w("G1",u);const _=await Ke(o,i,9);let g,f,h,p,m;g=await l.G1.fft(_,"affine","jacobian",e),g=await l.G1.batchApplyKey(g,l.Fr.neg(l.Fr.e(2)),l.Fr.w[n.power+1],"jacobian","affine",e),g=g.slice(0,g.byteLength-c),g=await l.G1.batchLEMtoU(g),await w("G1",g),f=await Ke(o,i,8),f=await l.G1.batchLEMtoU(f),await w("G1",f),h=await Ke(o,i,5),h=await l.G1.batchLEMtoU(h),await w("G1",h),p=await Ke(o,i,6),p=await l.G1.batchLEMtoU(p),await w("G1",p),m=await Ke(o,i,7),m=await l.G2.batchLEMtoU(m),await w("G2",m),await d.write(r.csHash),await async function(t){const a=new Uint8Array(4);new DataView(a.buffer,a.byteOffset,a.byteLength).setUint32(0,t,!1),await d.write(a)}(r.contributions.length);for(let t=0;t_.contributions.length)return i&&i.error("The impoerted file does not include new contributions"),!1;for(let t=0;t=256)return n&&n.error("Maximum lenght of beacon hash is 255 bytes"),!1;if((i=parseInt(i))<10||i>63)return n&&n.error("Invalid numIterationsExp. (Must be between 10 and 63)"),!1;const{fd:c,sections:s}=await Ue(t,"zkey",2),r=await Ci(c,s);if("groth16"!=r.protocol)throw new Error("zkey file is not groth16");const d=await Xe(r.q),u=await xi(c,d,s),_=await Qe(a,"zkey",1,10),g=await Vo(l,i),f=ao.exports(64);f.update(u.csHash);for(let t=0;t{const o=this.curve.G1.toObject(this.polynomials[e]);t?a.polynomials[e]=o:a[e]=o})),Object.keys(this.evaluations).forEach((e=>{const o=this.curve.Fr.toObject(this.evaluations[e]);t?a.evaluations[e]=o:a[e]=o})),a}fromObjectProof(t){this.resetProof(),Object.keys(t.polynomials).forEach((a=>{this.polynomials[a]=this.curve.G1.fromObject(t.polynomials[a])})),Object.keys(t.evaluations).forEach((a=>{this.evaluations[a]=this.curve.Fr.fromObject(t.evaluations[a])}))}}var er,or={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 + */er=or,function(){var t="input is invalid type",a="object"==typeof window,e=a?window:{};e.JS_SHA3_NO_WINDOW&&(a=!1);var o=!a&&"object"==typeof self;!e.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?e=V:o&&(e=self);var i=!e.JS_SHA3_NO_COMMON_JS&&er.exports,n=!e.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,l="0123456789abcdef".split(""),c=[4,1024,262144,67108864],s=[0,8,16,24],r=[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],_=["hex","buffer","arrayBuffer","array","digest"],g={128:168,256:136};!e.JS_SHA3_NO_NODE_JS&&Array.isArray||(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),!n||!e.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 f=function(t,a,e){return function(o){return new v(t,a,t).update(o)[e]()}},h=function(t,a,e){return function(o,i){return new v(t,a,i).update(o)[e]()}},p=function(t,a,e){return function(a,o,i,n){return y["cshake"+t].update(a,o,i,n)[e]()}},m=function(t,a,e){return function(a,o,i,n){return y["kmac"+t].update(a,o,i,n)[e]()}},L=function(t,a,e,o){for(var i=0;i<_.length;++i){var n=_[i];t[n]=a(e,o,n)}return t},b=function(t,a){var e=f(t,a,"hex");return e.create=function(){return new v(t,a,t)},e.update=function(t){return e.create().update(t)},L(e,f,t,a)},w=[{name:"keccak",padding:[1,256,65536,16777216],bits:d,createMethod:b},{name:"sha3",padding:[6,1536,393216,100663296],bits:d,createMethod:b},{name:"shake",padding:[31,7936,2031616,520093696],bits:u,createMethod:function(t,a){var e=h(t,a,"hex");return e.create=function(e){return new v(t,a,e)},e.update=function(t,a){return e.create(a).update(t)},L(e,h,t,a)}},{name:"cshake",padding:c,bits:u,createMethod:function(t,a){var e=g[t],o=p(t,0,"hex");return o.create=function(o,i,n){return i||n?new v(t,a,o).bytepad([i,n],e):y["shake"+t].create(o)},o.update=function(t,a,e,i){return o.create(a,e,i).update(t)},L(o,p,t,a)}},{name:"kmac",padding:c,bits:u,createMethod:function(t,a){var e=g[t],o=m(t,0,"hex");return o.create=function(o,i,n){return new S(t,a,i).bytepad(["KMAC",n],e).bytepad([o],e)},o.update=function(t,a,e,i){return o.create(t,e,i).update(a)},L(o,m,t,a)}}],y={},A=[],C=0;C>5,this.byteCount=this.blockCount<<2,this.outputBlocks=e>>5,this.extraBytes=(31&e)>>3;for(var o=0;o<50;++o)this.s[o]=0}function S(t,a,e){v.call(this,t,a,e)}v.prototype.update=function(a){if(this.finalized)throw new Error("finalize already called");var e,o=typeof a;if("string"!==o){if("object"!==o)throw new Error(t);if(null===a)throw new Error(t);if(n&&a.constructor===ArrayBuffer)a=new Uint8Array(a);else if(!(Array.isArray(a)||n&&ArrayBuffer.isView(a)))throw new Error(t);e=!0}for(var i,l,c=this.blocks,r=this.byteCount,d=a.length,u=this.blockCount,_=0,g=this.s;_>2]|=a[_]<>2]|=l<>2]|=(192|l>>6)<>2]|=(128|63&l)<=57344?(c[i>>2]|=(224|l>>12)<>2]|=(128|l>>6&63)<>2]|=(128|63&l)<>2]|=(240|l>>18)<>2]|=(128|l>>12&63)<>2]|=(128|l>>6&63)<>2]|=(128|63&l)<=r){for(this.start=i-r,this.block=c[u],i=0;i>=8);e>0;)i.unshift(e),e=255&(t>>=8),++o;return a?i.push(o):i.unshift(o),this.update(i),i.length},v.prototype.encodeString=function(a){var e,o=typeof a;if("string"!==o){if("object"!==o)throw new Error(t);if(null===a)throw new Error(t);if(n&&a.constructor===ArrayBuffer)a=new Uint8Array(a);else if(!(Array.isArray(a)||n&&ArrayBuffer.isView(a)))throw new Error(t);e=!0}var i=0,l=a.length;if(e)i=l;else for(var c=0;c=57344?i+=3:(s=65536+((1023&s)<<10|1023&a.charCodeAt(++c)),i+=4)}return i+=this.encode(8*i),this.update(a),i},v.prototype.bytepad=function(t,a){for(var e=this.encode(a),o=0;o>2]|=this.padding[3&a],this.lastByteIndex===this.byteCount)for(t[0]=t[e],a=1;a>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];c%a==0&&(P(e),n=0)}return i&&(t=e[n],s+=l[t>>4&15]+l[15&t],i>1&&(s+=l[t>>12&15]+l[t>>8&15]),i>2&&(s+=l[t>>20&15]+l[t>>16&15])),s},v.prototype.arrayBuffer=function(){this.finalize();var t,a=this.blockCount,e=this.s,o=this.outputBlocks,i=this.extraBytes,n=0,l=0,c=this.outputBits>>3;t=i?new ArrayBuffer(o+1<<2):new ArrayBuffer(c);for(var s=new Uint32Array(t);l>8&255,s[t+2]=a>>16&255,s[t+3]=a>>24&255;c%e==0&&P(o)}return n&&(t=c<<2,a=o[l],s[t]=255&a,n>1&&(s[t+1]=a>>8&255),n>2&&(s[t+2]=a>>16&255)),s},S.prototype=new v,S.prototype.finalize=function(){return this.encode(this.outputBits,!0),v.prototype.finalize.call(this)};var P=function(t){var a,e,o,i,n,l,c,s,d,u,_,g,f,h,p,m,L,b,w,y,A,C,F,x,I,B,E,v,S,P,q,O,G,z,T,M,U,Q,k,R,N,D,$,j,V,K,H,Z,W,Y,J,X,tt,at,et,ot,it,nt,lt,ct,st,rt,dt;for(o=0;o<48;o+=2)i=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],c=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],_=t[7]^t[17]^t[27]^t[37]^t[47],a=(g=t[8]^t[18]^t[28]^t[38]^t[48])^(l<<1|c>>>31),e=(f=t[9]^t[19]^t[29]^t[39]^t[49])^(c<<1|l>>>31),t[0]^=a,t[1]^=e,t[10]^=a,t[11]^=e,t[20]^=a,t[21]^=e,t[30]^=a,t[31]^=e,t[40]^=a,t[41]^=e,a=i^(s<<1|d>>>31),e=n^(d<<1|s>>>31),t[2]^=a,t[3]^=e,t[12]^=a,t[13]^=e,t[22]^=a,t[23]^=e,t[32]^=a,t[33]^=e,t[42]^=a,t[43]^=e,a=l^(u<<1|_>>>31),e=c^(_<<1|u>>>31),t[4]^=a,t[5]^=e,t[14]^=a,t[15]^=e,t[24]^=a,t[25]^=e,t[34]^=a,t[35]^=e,t[44]^=a,t[45]^=e,a=s^(g<<1|f>>>31),e=d^(f<<1|g>>>31),t[6]^=a,t[7]^=e,t[16]^=a,t[17]^=e,t[26]^=a,t[27]^=e,t[36]^=a,t[37]^=e,t[46]^=a,t[47]^=e,a=u^(i<<1|n>>>31),e=_^(n<<1|i>>>31),t[8]^=a,t[9]^=e,t[18]^=a,t[19]^=e,t[28]^=a,t[29]^=e,t[38]^=a,t[39]^=e,t[48]^=a,t[49]^=e,h=t[0],p=t[1],K=t[11]<<4|t[10]>>>28,H=t[10]<<4|t[11]>>>28,v=t[20]<<3|t[21]>>>29,S=t[21]<<3|t[20]>>>29,ct=t[31]<<9|t[30]>>>23,st=t[30]<<9|t[31]>>>23,D=t[40]<<18|t[41]>>>14,$=t[41]<<18|t[40]>>>14,z=t[2]<<1|t[3]>>>31,T=t[3]<<1|t[2]>>>31,m=t[13]<<12|t[12]>>>20,L=t[12]<<12|t[13]>>>20,Z=t[22]<<10|t[23]>>>22,W=t[23]<<10|t[22]>>>22,P=t[33]<<13|t[32]>>>19,q=t[32]<<13|t[33]>>>19,rt=t[42]<<2|t[43]>>>30,dt=t[43]<<2|t[42]>>>30,at=t[5]<<30|t[4]>>>2,et=t[4]<<30|t[5]>>>2,M=t[14]<<6|t[15]>>>26,U=t[15]<<6|t[14]>>>26,b=t[25]<<11|t[24]>>>21,w=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,G=t[44]<<29|t[45]>>>3,x=t[6]<<28|t[7]>>>4,I=t[7]<<28|t[6]>>>4,ot=t[17]<<23|t[16]>>>9,it=t[16]<<23|t[17]>>>9,Q=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,j=t[8]<<27|t[9]>>>5,V=t[9]<<27|t[8]>>>5,B=t[18]<<20|t[19]>>>12,E=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,N=t[39]<<8|t[38]>>>24,C=t[48]<<14|t[49]>>>18,F=t[49]<<14|t[48]>>>18,t[0]=h^~m&b,t[1]=p^~L&w,t[10]=x^~B&v,t[11]=I^~E&S,t[20]=z^~M&Q,t[21]=T^~U&k,t[30]=j^~K&Z,t[31]=V^~H&W,t[40]=at^~ot&nt,t[41]=et^~it<,t[2]=m^~b&y,t[3]=L^~w&A,t[12]=B^~v&P,t[13]=E^~S&q,t[22]=M^~Q&R,t[23]=U^~k&N,t[32]=K^~Z&Y,t[33]=H^~W&J,t[42]=ot^~nt&ct,t[43]=it^~lt&st,t[4]=b^~y&C,t[5]=w^~A&F,t[14]=v^~P&O,t[15]=S^~q&G,t[24]=Q^~R&D,t[25]=k^~N&$,t[34]=Z^~Y&X,t[35]=W^~J&tt,t[44]=nt^~ct&rt,t[45]=lt^~st&dt,t[6]=y^~C&h,t[7]=A^~F&p,t[16]=P^~O&x,t[17]=q^~G&I,t[26]=R^~D&z,t[27]=N^~$&T,t[36]=Y^~X&j,t[37]=J^~tt&V,t[46]=ct^~rt&at,t[47]=st^~dt&et,t[8]=C^~h&m,t[9]=F^~p&L,t[18]=O^~x&B,t[19]=G^~I&E,t[28]=D^~z&M,t[29]=$^~T&U,t[38]=X^~j&K,t[39]=tt^~V&H,t[48]=rt^~at&ot,t[49]=dt^~et&it,t[0]^=r[o],t[1]^=r[o+1]};if(i)er.exports=y;else for(C=0;C0===e.type?t++:a++));let e=new Uint8Array(a*this.Fr.n8+t*this.G1.F.n8*2),o=0;for(let t=0;t32768?new qa(t.length*o.n8):new Uint8Array(t.length*o.n8);for(let a=0;a32768?new qa(o*i.n8):new Uint8Array(o*i.n8);return n.set(t.coef.slice(),0),new wr(n,a,e)}isEqual(t){const a=this.degree();if(a!==t.degree())return!1;for(let e=0;e32768?new qa((this.length()+t.length)*this.Fr.n8):new Uint8Array((this.length()+t.length)*this.Fr.n8);a.set(this.coef,0);for(let e=0;ethis.coef.byteLength?this.Fr.zero:this.coef.slice(a,a+this.Fr.n8)}setCoef(t,a){if(t>this.length()-1)throw new Error("Coef index is not available");this.coef.set(a,t*this.Fr.n8)}static async to4T(t,a,e,o){e=e||[];let i=await o.ifft(t);const n=4*a>32768?new qa(4*a*o.n8):new Uint8Array(4*a*o.n8);n.set(i,0);const l=await o.fft(n);if(0===e.length)return[i,l];const c=a+e.length>32768?new qa((a+e.length)*o.n8):new Uint8Array((a+e.length)*o.n8);c.set(i,0);for(let t=0;t0;t--){const a=t*this.Fr.n8;if(!this.Fr.eq(this.Fr.zero,this.coef.slice(a,a+this.Fr.n8)))return t}return 0}evaluate(t){let a=this.Fr.zero;for(let e=this.degree()+1;e>0;e--){let o=e*this.Fr.n8;const i=this.coef.slice(o-this.Fr.n8,o);a=this.Fr.add(i,this.Fr.mul(a,t))}return a}fastEvaluate(t){const a=this.Fr;let e=this.degree()+1,o=parseInt(e/3),i=e-3*o,n=[],l=[];l[0]=a.one;for(let e=0;e<3;e++){n[e]=a.zero;for(let c=2===e?o+i:o;c>0;c--)n[e]=a.add(this.getCoef(e*o+c-1),a.mul(n[e],t)),0===e&&(l[0]=a.mul(l[0],t))}for(let t=1;t<3;t++)n[0]=a.add(n[0],a.mul(l[t-1],n[t])),l[t]=a.mul(l[t-1],l[0]);return n[0]}add(t,a){let e=!1;t.length()>this.length()&&(e=!0);const o=this.length(),i=t.length();for(let n=0;nthis.length()&&(e=!0);const o=this.length(),i=t.length();for(let n=0;n32768?new qa(e*a.n8):new Uint8Array(e*a.n8);let i=new wr(o,this.curve,this.logger);i.coef.set(this.coef.slice(0,(e-1)*a.n8),32),this.mulScalar(a.neg(t)),i.add(this),this.coef=i.coef}byXNSubValue(t,a){const e=this.Fr,o=!(this.length()-t-1>=this.degree())?this.length()+t:this.length(),i=o>32768?new qa(o*e.n8):new Uint8Array(o*e.n8);let n=new wr(i,this.curve,this.logger);n.coef.set(this.coef.slice(0,32*(this.degree()+1)),32*t),this.mulScalar(a),n.add(this),this.coef=n.coef}divBy(t){const a=this.Fr,e=this.degree(),o=t.degree();let i=new wr(this.coef,this.curve,this.logger);this.coef=this.length()>32768?new qa(this.length()*a.n8):new Uint8Array(this.length()*a.n8);for(let n=e-o;n>=0;n--){this.setCoef(n,a.div(i.getCoef(n+o),t.getCoef(o)));for(let e=0;e<=o;e++)i.setCoef(n+e,a.sub(i.getCoef(n+e),a.mul(this.getCoef(n),t.getCoef(e))))}return i}divByMonic(t,a){const e=this.Fr;let o=this.degree(),i=this.length()>32768?new qa(this.length()*e.n8):new Uint8Array(this.length()*e.n8),n=new wr(i,this.curve,this.logger),l=[];for(let a=0;a=0&&!(s<0);s-=c){let o=i;l[o]=e.add(this.getCoef(s+t),e.mul(l[o],a)),n.setCoef(s,l[o])}this.coef=n.coef}divByVanishing(t,a){if(this.degree()32768?new qa(this.length()*e.n8):new Uint8Array(this.length()*e.n8);for(let i=this.length()-1;i>=t;i--){let n=o.getCoef(i);e.eq(e.zero,n)||(o.setCoef(i,e.zero),o.setCoef(i-t,e.add(o.getCoef(i-t),e.mul(a,n))),this.setCoef(i-t,e.add(this.getCoef(i-t),n)))}return o}divByVanishing2(t,a){if(this.degree()32768?new qa(this.length()*e.n8):new Uint8Array(this.length()*e.n8);let i=this.length()-t,n=Math.floor(i/3),l=i-2*n;console.log(i),console.log(n+" "+l);for(let i=0;i<3;i++){console.log("> Thread "+i);for(let c=0===i?l:n;c>0;c--){let s=c-1;0!==i&&(s+=(i-1)*n+l);let r=s+t,d=o.getCoef(r);e.eq(e.zero,d)||(o.setCoef(r,e.zero),o.setCoef(s,e.add(o.getCoef(s),e.mul(a,d))),this.setCoef(s,e.add(this.getCoef(s),d)),console.log(s+" <-- "+r))}}return this.print(),o}fastDivByVanishing(t){const a=this.Fr;for(let e=0;e32768?new qa(this.length()*a.n8):new Uint8Array(this.length()*a.n8),this.curve,this.logger),u=this.coef;this.coef=d.coef,d.coef=u;for(let t=0;t0;t--){let e=t-1,i=e*s+r;f[e]=[];for(let l=0;l32768?new qa(this.length()*this.Fr.n8):new Uint8Array(this.length()*this.Fr.n8);a.set(this.Fr.zero,(this.length()-1)*this.Fr.n8),a.set(this.coef.slice((this.length()-1)*this.Fr.n8,this.length()*this.Fr.n8),(this.length()-2)*this.Fr.n8);for(let e=this.length()-3;e>=0;e--){let o=e*this.Fr.n8;a.set(this.Fr.add(this.coef.slice(o+this.Fr.n8,o+2*this.Fr.n8),this.Fr.mul(t,a.slice(o+this.Fr.n8,o+2*this.Fr.n8))),e*this.Fr.n8)}if(!this.Fr.eq(this.coef.slice(0,this.Fr.n8),this.Fr.mul(this.Fr.neg(t),a.slice(0,this.Fr.n8))))throw new Error("Polynomial does not divide");this.coef=a}divZh(t,a=4){for(let a=0;at*(a-1)-a&&!this.Fr.isZero(i))throw new Error("Polynomial is not divisible")}return this}divByZerofier(t,a){let e=this.Fr;const o=e.inv(a),i=e.neg(o);let n=e.eq(e.one,i),l=e.eq(e.negone,i);if(!n)for(let a=0;athis.length()-t-1&&!this.Fr.isZero(s))throw new Error("Polynomial is not divisible")}return this}byX(){const t=this.length()+1>32768?new qa(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,a,e=!1){const o=t.Fr;if(a<1)throw new Error("Compute a new polynomial to a zero or negative number is not allowed");if(1===a)return await wr.fromEvaluations(t.coef,curve,t.logger);const i=e?t.degree():t.length()-1,n=i*a+1>32768?new qa((i*a+1)*o.n8):new Uint8Array((i*a+1)*o.n8);n.set(t.getCoef(0),0);for(let e=1;e<=i;e++){const i=e*o.n8,l=t.getCoef(e);n.set(l,i*a)}return new wr(n,t.curve,t.logger)}split(t,a,e){if(t<1)throw new Error(`Polynomials can't be split in ${t} parts`);if(1===t)return[this];if(0!==e.length&&e.length32768?new qa(l):new Uint8Array(l);i[a]=new wr(c,this.curve,this.logger);const s=a*o,r=n?this.coef.byteLength:(a+1)*o;if(i[a].coef.set(this.coef.slice(s,r),0),n||i[a].coef.set(e[a],o),0!==a){const t=this.Fr.sub(i[a].coef.slice(0,this.Fr.n8),e[a-1]);i[a].coef.set(t,0)}n&&i[a].truncate()}return i}truncate(){const t=this.degree();if(t+132768?new qa((t+1)*this.Fr.n8):new Uint8Array((t+1)*this.Fr.n8);a.set(this.coef.slice(0,(t+1)*this.Fr.n8),0),this.coef=a}}static lagrangePolynomialInterpolation(t,a,e){const o=e.Fr;let i=n(0);for(let a=1;a32768?new qa(t.length*o.n8):new Uint8Array(t.length*o.n8);n=new wr(i,e),n.setCoef(0,o.neg(t[a])),n.setCoef(1,o.one)}else n.byXSubValue(t[a]);let l=n.evaluate(t[i]);l=o.inv(l);const c=o.mul(a[i],l);return n.mulScalar(c),n}}static zerofierPolynomial(t,a){const e=a.Fr;let o=t.length+1>32768?new qa((t.length+1)*e.n8):new Uint8Array((t.length+1)*e.n8),i=new wr(o,a);i.setCoef(0,e.neg(t[0])),i.setCoef(1,e.one);for(let a=1;a=0;e--){const o=this.getCoef(e);t.eq(t.zero,o)||(t.isNegative(o)?a+=" - ":e!==this.degree()&&(a+=" + "),a+=t.toString(o),e>0&&(a+=e>1?"x^"+e:"x"))}console.log(a)}async multiExponentiation(t,a){const e=this.coef.byteLength/this.Fr.n8,o=t.slice(0,e*this.G1.F.n8*2),i=await this.Fr.batchFromMontgomery(this.coef);let n=await this.G1.multiExpAffine(o,i,this.logger,a);return n=this.G1.toAffine(n),n}}class yr{constructor(t,a,e){this.eval=t,this.curve=a,this.Fr=a.Fr,this.logger=e}static async fromPolynomial(t,a,e,o){const i=new qa(t.length()*a*e.Fr.n8);i.set(t.coef,0);const n=await e.Fr.fft(i);return new yr(n,e,o)}getEvaluation(t){const a=t*this.Fr.n8;if(a+this.Fr.n8>this.eval.byteLength)throw new Error("Evaluations.getEvaluation() out of bounds");return this.eval.slice(a,a+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:Ar}=he;async function Cr(t,a,e){const{fd:o,sections:i}=await Ue(a,"wtns",2);e&&e.debug("> Reading witness file");const n=await Si(o,i);e&&e.debug("> Reading zkey file");const{fd:l,sections:c}=await Ue(t,"zkey",2),s=await Ci(l,c);if("plonk"!=s.protocol)throw new Error("zkey file is not plonk");if(!fe.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 r=s.curve,d=r.Fr,u=r.Fr.n8,_=s.domainSize*u;e&&(e.debug("----------------------------"),e.debug(" PLONK PROVE SETTINGS"),e.debug(` Curve: ${r.name}`),e.debug(` Circuit power: ${s.power}`),e.debug(` Domain size: ${s.domainSize}`),e.debug(` Vars: ${s.nVars}`),e.debug(` Public vars: ${s.nPublic}`),e.debug(` Constraints: ${s.nConstraints}`),e.debug(` Additions: ${s.nAdditions}`),e.debug("----------------------------")),e&&e.debug("> Reading witness file data");const g=await Ke(o,i,2);g.set(d.zero,0);const f=new qa(u*s.nAdditions);let h={},p={},m={},L={},b=new ar(r,e);const w=new lr(r);e&&e.debug(`> Reading Section ${sr}. Additions`),await async function(){e&&e.debug("··· Computing additions");const t=await Ke(l,c,sr),a=8+2*u;for(let o=0;o Reading Section ${mr}. Sigma1, Sigma2 & Sigma 3`),e&&e.debug("··· Reading Sigma polynomials "),p.Sigma1=new wr(new qa(_),r,e),p.Sigma2=new wr(new qa(_),r,e),p.Sigma3=new wr(new qa(_),r,e),await l.readToBuffer(p.Sigma1.coef,0,_,c[mr][0].p),await l.readToBuffer(p.Sigma2.coef,0,_,c[mr][0].p+5*_),await l.readToBuffer(p.Sigma3.coef,0,_,c[mr][0].p+10*_),e&&e.debug("··· Reading Sigma evaluations"),m.Sigma1=new yr(new qa(4*_),r,e),m.Sigma2=new yr(new qa(4*_),r,e),m.Sigma3=new yr(new qa(4*_),r,e),await l.readToBuffer(m.Sigma1.eval,0,4*_,c[mr][0].p+_),await l.readToBuffer(m.Sigma2.eval,0,4*_,c[mr][0].p+6*_),await l.readToBuffer(m.Sigma3.eval,0,4*_,c[mr][0].p+11*_),e&&e.debug(`> Reading Section ${br}. Powers of Tau`);const y=await Ke(l,c,br);let A=[];for(let t=1;t<=s.nPublic;t++){const a=g.slice(t*d.n8,t*d.n8+d.n8);A.push(fe.fromRprLE(a))}e&&e.debug(""),e&&e.debug("> ROUND 1"),await async function(){L.b=[];for(let t=1;t<=11;t++)L.b[t]=r.Fr.random();e&&e.debug("> Computing A, B, C wire polynomials");await async function(){e&&e.debug("··· Reading data from zkey file");h.A=new qa(_),h.B=new qa(_),h.C=new qa(_);const t=await Ke(l,c,rr),a=await Ke(l,c,dr),o=await Ke(l,c,ur);for(let e=0;e=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")}(),e&&e.debug("> Computing A, B, C MSM");let t=await p.A.multiExponentiation(y,"A"),a=await p.B.multiExponentiation(y,"B"),o=await p.C.multiExponentiation(y,"C");return b.addPolynomial("A",t),b.addPolynomial("B",a),b.addPolynomial("C",o),0}(),e&&e.debug("> ROUND 2"),await async function(){e&&e.debug("> Computing challenges beta and gamma");w.reset(),w.addPolCommitment(s.Qm),w.addPolCommitment(s.Ql),w.addPolCommitment(s.Qr),w.addPolCommitment(s.Qo),w.addPolCommitment(s.Qc),w.addPolCommitment(s.S1),w.addPolCommitment(s.S2),w.addPolCommitment(s.S3);for(let t=0;t Computing Z polynomial");await async function(){e&&e.debug("··· Computing Z evaluations");let t=new qa(_),a=new qa(_);t.set(d.one,0),a.set(d.one,0);let o=d.one;for(let e=0;e=s.domainSize+3)throw new Error("Z Polynomial is not well calculated");delete h.Z}(),e&&e.debug("> Computing Z MSM");let t=await p.Z.multiExponentiation(y,"Z");b.addPolynomial("Z",t)}(),e&&e.debug("> ROUND 3"),await async function(){e&&e.debug("> Computing challenge alpha");w.reset(),w.addScalar(L.beta),w.addScalar(L.gamma),w.addPolCommitment(b.getPolynomial("Z")),L.alpha=w.getChallenge(),L.alpha2=d.square(L.alpha),e&&e.debug("··· challenges.alpha: "+d.toString(L.alpha,16));e&&e.debug("> Computing T polynomial");await async function(){e&&e.debug(`··· Reading sections ${gr}, ${fr}, ${_r}, ${hr}, ${pr}. Q selectors`);m.QL=new yr(new qa(4*_),r,e),m.QR=new yr(new qa(4*_),r,e),m.QM=new yr(new qa(4*_),r,e),m.QO=new yr(new qa(4*_),r,e),m.QC=new yr(new qa(4*_),r,e),await l.readToBuffer(m.QL.eval,0,4*_,c[gr][0].p+_),await l.readToBuffer(m.QR.eval,0,4*_,c[fr][0].p+_),await l.readToBuffer(m.QM.eval,0,4*_,c[_r][0].p+_),await l.readToBuffer(m.QO.eval,0,4*_,c[hr][0].p+_),await l.readToBuffer(m.QC.eval,0,4*_,c[pr][0].p+_),m.Lagrange=new yr(new qa(4*_*s.nPublic),r,e);for(let t=0;t=3*s.domainSize+6)throw new Error("T Polynomial is not well calculated");e&&e.debug("··· Computing T1, T2, T3 polynomials");p.T1=new wr(new qa((s.domainSize+1)*u),r,e),p.T2=new wr(new qa((s.domainSize+1)*u),r,e),p.T3=new wr(new qa((s.domainSize+6)*u),r,e),p.T1.coef.set(p.T.coef.slice(0,_),0),p.T2.coef.set(p.T.coef.slice(_,2*_),0),p.T3.coef.set(p.T.coef.slice(2*_,3*_+6*u),0),p.T1.setCoef(s.domainSize,L.b[10]);const a=d.sub(p.T2.getCoef(0),L.b[10]);p.T2.setCoef(0,a),p.T2.setCoef(s.domainSize,L.b[11]);const o=d.sub(p.T3.getCoef(0),L.b[11]);p.T3.setCoef(0,o)}(),e&&e.debug("> Computing T MSM");let t=await p.T1.multiExponentiation(y,"T1"),a=await p.T2.multiExponentiation(y,"T2"),o=await p.T3.multiExponentiation(y,"T3");b.addPolynomial("T1",t),b.addPolynomial("T2",a),b.addPolynomial("T3",o)}(),e&&e.debug("> ROUND 4"),await async function(){e&&e.debug("> Computing challenge xi");w.reset(),w.addScalar(L.alpha),w.addPolCommitment(b.getPolynomial("T1")),w.addPolCommitment(b.getPolynomial("T2")),w.addPolCommitment(b.getPolynomial("T3")),L.xi=w.getChallenge(),L.xiw=d.mul(L.xi,d.w[s.power]),e&&e.debug("··· challenges.xi: "+d.toString(L.xi,16));b.addEvaluation("eval_a",p.A.evaluate(L.xi)),b.addEvaluation("eval_b",p.B.evaluate(L.xi)),b.addEvaluation("eval_c",p.C.evaluate(L.xi)),b.addEvaluation("eval_s1",p.Sigma1.evaluate(L.xi)),b.addEvaluation("eval_s2",p.Sigma2.evaluate(L.xi)),b.addEvaluation("eval_zw",p.Z.evaluate(L.xiw))}(),e&&e.debug("> ROUND 5"),await async function(){e&&e.debug("> Computing challenge v");w.reset(),w.addScalar(L.xi),w.addScalar(b.getEvaluation("eval_a")),w.addScalar(b.getEvaluation("eval_b")),w.addScalar(b.getEvaluation("eval_c")),w.addScalar(b.getEvaluation("eval_s1")),w.addScalar(b.getEvaluation("eval_s2")),w.addScalar(b.getEvaluation("eval_zw")),L.v=[],L.v[1]=w.getChallenge(),e&&e.debug("··· challenges.v: "+d.toString(L.v[1],16));for(let t=2;t<6;t++)L.v[t]=d.mul(L.v[t-1],L.v[1]);e&&e.debug("> Computing linearisation polynomial R(X)");await async function(){const t=r.Fr;p.QL=new wr(new qa(_),r,e),p.QR=new wr(new qa(_),r,e),p.QM=new wr(new qa(_),r,e),p.QO=new wr(new qa(_),r,e),p.QC=new wr(new qa(_),r,e),await l.readToBuffer(p.QL.coef,0,_,c[gr][0].p),await l.readToBuffer(p.QR.coef,0,_,c[fr][0].p),await l.readToBuffer(p.QM.coef,0,_,c[_r][0].p),await l.readToBuffer(p.QO.coef,0,_,c[hr][0].p),await l.readToBuffer(p.QC.coef,0,_,c[pr][0].p),L.xin=L.xi;for(let a=0;a Computing opening proof polynomial Wxi(X) polynomial");p.Wxi=new wr(new qa(_+6*u),r,e),p.Wxi.add(p.R),p.Wxi.add(p.A,L.v[1]),p.Wxi.add(p.B,L.v[2]),p.Wxi.add(p.C,L.v[3]),p.Wxi.add(p.Sigma1,L.v[4]),p.Wxi.add(p.Sigma2,L.v[5]),p.Wxi.subScalar(d.mul(L.v[1],b.evaluations.eval_a)),p.Wxi.subScalar(d.mul(L.v[2],b.evaluations.eval_b)),p.Wxi.subScalar(d.mul(L.v[3],b.evaluations.eval_c)),p.Wxi.subScalar(d.mul(L.v[4],b.evaluations.eval_s1)),p.Wxi.subScalar(d.mul(L.v[5],b.evaluations.eval_s2)),void p.Wxi.divByZerofier(1,L.xi),e&&e.debug("> Computing opening proof polynomial Wxiw(X) polynomial");(async function(){p.Wxiw=wr.fromPolynomial(p.Z,r,e),p.Wxiw.subScalar(b.evaluations.eval_zw),p.Wxiw.divByZerofier(1,L.xiw)})(),e&&e.debug("> Computing Wxi, Wxiw MSM");let t=await p.Wxi.multiExponentiation(y,"Wxi"),a=await p.Wxiw.multiExponentiation(y,"Wxiw");b.addPolynomial("Wxi",t),b.addPolynomial("Wxiw",a)}(),await l.close(),await o.close();let C=b.toObjectProof(!1);return C.protocol="plonk",C.curve=r.name,e&&e.debug("PLONK PROVER FINISHED"),{proof:Ar(C),publicSignals:Ar(A)};function F(t,a){const e=t.slice(a,a+4);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(0,!0)}function x(t){return te;){const a=i.shift(),e=i.shift(),o=a[0],n=e[0],l=L++,c=t.zero,s=t.neg(a[1]),r=t.neg(e[1]),d=t.one,u=t.zero;p.push([o,n,l,c,s,r,d,u]),m.push([o,n,a[1],e[1]]),i.push([l,t.one])}for(let t=0;t0?o.toString():e!=t.zero?"k":"0"}function s(a,e,s){const r=c(a),d=c(e);if("0"===r||"0"===d)o(s),l(s);else if("k"===r){l(i(e,a[0],s))}else if("k"===d){l(i(a,e[0],s))}else!function(a,e,o){const i=n(a,1),l=n(e,1),c=n(o,1),s=i.s[0],r=l.s[0],d=c.s[0],u=t.mul(i.coefs[0],l.coefs[0]),_=t.mul(i.coefs[0],l.k),g=t.mul(i.k,l.coefs[0]),f=t.neg(c.coefs[0]),h=t.sub(t.mul(i.k,l.k),c.k);p.push([s,r,d,u,_,g,f,h])}(a,e,s)}for(let a=1;a<=b;a++){const e=a,o=0,i=0,n=t.zero,l=t.one,c=t.zero,s=t.zero,r=t.zero;p.push([e,o,i,n,l,c,s,r])}for(let t=0;tc)return o&&o.error(`circuit too big for this power of tau ceremony. ${p.length} > 2**${c}`),-1;if(!n[12])return o&&o.error("Powers of tau is not prepared."),-1;const C=new qa(A*u),F=n[12][0].p+(2**y-1)*u;await i.readToBuffer(C,0,A*u,F);const[x,I]=function(){let t=f.two;for(;e(t,[],y);)f.add(t,f.one);let a=f.add(t,f.one);for(;e(a,[t],y);)f.add(a,f.one);return[t,a];function e(t,a,e){const o=2**e;let i=f.one;for(let n=0;n0?2:this.Fr.isZero(a)?0:1}normalizeLinearCombination(t){const a=Object.keys(t);for(let e=0;ei;){const o=l.shift(),i=l.shift(),n=t.nVars++,c=this.fnGetAdditionConstraint(o[0],i[0],n,this.Fr.neg(o[1]),this.Fr.neg(i[1]),this.Fr.zero,this.Fr.one,this.Fr.zero);a.push(c),e.push([o[0],i[0],o[1],i[1]]),l.push([n,this.Fr.one])}for(let t=0;tthis.n-1)throw new Error("CPolynomial:addPolynomial, cannot add a polynomial to a position greater than n-1");this.polynomials[t]=a}degree(){let t=this.polynomials.map(((t,a)=>void 0===t?0:t.degree()*this.n+a));return Math.max(...t)}getPolynomial(){let t=this.polynomials.map((t=>void 0===t?0:t.degree()));const a=this.degree(),e=2**(Mo(a-1)+1),o=this.Fr.n8;let i=new wr(new qa(e*o),this.curve,this.logger);for(let e=0;e Reading witness file");const{fd:o,sections:i}=await Ue(a,"wtns",2),n=await Si(o,i);e&&e.info("> Reading zkey file");const{fd:l,sections:c}=await Ue(t,"zkey",2),s=await Ci(l,c);if(s.protocolId!==Xo)throw new Error("zkey file is not fflonk");if(!fe.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 r=s.curve,d=r.Fr,u=r.Fr.n8,_=2*r.G1.F.n8,g=s.domainSize*u;e&&(e.info("----------------------------"),e.info(" FFLONK PROVE SETTINGS"),e.info(` Curve: ${r.name}`),e.info(` Circuit power: ${s.power}`),e.info(` Domain size: ${s.domainSize}`),e.info(` Vars: ${s.nVars}`),e.info(` Public vars: ${s.nPublic}`),e.info(` Constraints: ${s.nConstraints}`),e.info(` Additions: ${s.nAdditions}`),e.info("----------------------------")),e&&e.info("> Reading witness file data");const f=await Ke(o,i,2);await o.close(),f.set(d.zero,0);const h=new qa(s.nAdditions*u);let p={},m={},L={},b={},w={},y={},A=new ar(r,e);e&&e.info(`> Reading Section ${oi}. Additions`),await async function(){e&&e.info("··· Computing additions");const t=await Ke(l,c,oi),a=8+2*u;for(let o=0;o Reading Sections ${_i},${gi},${fi}. Sigma1, Sigma2 & Sigma 3`),e&&e.info("··· Reading Sigma polynomials "),m.Sigma1=new wr(new qa(g),r,e),m.Sigma2=new wr(new qa(g),r,e),m.Sigma3=new wr(new qa(g),r,e),await l.readToBuffer(m.Sigma1.coef,0,g,c[_i][0].p),await l.readToBuffer(m.Sigma2.coef,0,g,c[gi][0].p),await l.readToBuffer(m.Sigma3.coef,0,g,c[fi][0].p),e&&e.info("··· Reading Sigma evaluations"),L.Sigma1=new yr(new qa(4*g),r,e),L.Sigma2=new yr(new qa(4*g),r,e),L.Sigma3=new yr(new qa(4*g),r,e),await l.readToBuffer(L.Sigma1.eval,0,4*g,c[_i][0].p+g),await l.readToBuffer(L.Sigma2.eval,0,4*g,c[gi][0].p+g),await l.readToBuffer(L.Sigma3.eval,0,4*g,c[fi][0].p+g),e&&e.info(`> Reading Section ${pi}. Powers of Tau`);const C=new qa(16*s.domainSize*_);await l.readToBuffer(C,0,(9*s.domainSize+18)*_,c[pi][0].p),globalThis.gc&&globalThis.gc(),e&&e.info(""),e&&e.info("> ROUND 1"),await async function(){w.b=[];for(let t=1;t<=9;t++)w.b[t]=d.random();e&&e.info("> Computing A, B, C wire polynomials");await async function(){e&&e.info("··· Reading data from zkey file");p.A=new qa(g),p.B=new qa(g),p.C=new qa(g);const t=await Ke(l,c,ii),a=await Ke(l,c,ni),o=await Ke(l,c,li);for(let e=0;e=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")}(),e&&e.info("> Computing T0 polynomial");await async function(){e&&e.info(`··· Reading sections ${ci}, ${si}, ${ri}, ${di}, ${ui}. Q selectors`);L.QL=new yr(new qa(4*g),r,e),L.QR=new yr(new qa(4*g),r,e),L.QM=new yr(new qa(4*g),r,e),L.QO=new yr(new qa(4*g),r,e),L.QC=new yr(new qa(4*g),r,e),await l.readToBuffer(L.QL.eval,0,4*g,c[ci][0].p+g),await l.readToBuffer(L.QR.eval,0,4*g,c[si][0].p+g),await l.readToBuffer(L.QM.eval,0,4*g,c[ri][0].p+g),await l.readToBuffer(L.QO.eval,0,4*g,c[di][0].p+g),await l.readToBuffer(L.QC.eval,0,4*g,c[ui][0].p+g);const t=await Ke(l,c,hi);L.lagrange1=new yr(t,r,e),p.T0=new qa(4*g),e&&e.info("··· Computing T0 evaluations");for(let t=0;t<4*s.domainSize;t++){e&&0!==t&&t%1e5==0&&e.info(` T0 evaluation ${t}/${4*s.domainSize}`);const a=L.A.getEvaluation(t),o=L.B.getEvaluation(t),i=L.C.getEvaluation(t),n=L.QL.getEvaluation(t),l=L.QR.getEvaluation(t),c=L.QM.getEvaluation(t),r=L.QO.getEvaluation(t),_=L.QC.getEvaluation(t);let g=d.zero;for(let a=0;a=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}(),e&&e.info("> Computing C1 polynomial");await async function(){let t=new Or(4,r,e);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")}(),e&&e.info("> Computing C1 multi exponentiation");let t=await m.C1.multiExponentiation(C,"C1");return A.addPolynomial("C1",t),0}(),delete m.T0,delete L.QL,delete L.QR,delete L.QM,delete L.QO,delete L.QC,globalThis.gc&&globalThis.gc(),e&&e.info("> ROUND 2"),await async function(){e&&e.info("> Computing challenges beta and gamma");const t=new lr(r);t.addPolCommitment(s.C0);for(let a=0;a Computing Z polynomial");await async function(){e&&e.info("··· Computing Z evaluations");let t=new qa(g),a=new qa(g);t.set(d.one,0),a.set(d.one,0);let o=d.one;for(let i=0;i=s.domainSize+3)throw new Error("Z Polynomial is not well calculated");delete p.Z}(),e&&e.info("> Computing T1 polynomial");await async function(){e&&e.info("··· Computing T1 evaluations");p.T1=new qa(2*g),p.T1z=new qa(2*g);let t=d.one;for(let a=0;a<2*s.domainSize;a++){e&&0!==a&&a%1e5==0&&e.info(` T1 evaluation ${a}/${4*s.domainSize}`);const o=d.square(t),i=L.Z.getEvaluation(2*a),n=d.add(d.add(d.mul(w.b[7],o),d.mul(w.b[8],t)),w.b[9]),l=L.lagrange1.getEvaluation(s.domainSize+2*a);let c=d.mul(d.sub(i,d.one),l),r=d.mul(n,l);p.T1.set(c,a*u),p.T1z.set(r,a*u),t=d.mul(t,d.w[s.power+1])}e&&e.info("··· Computing T1 ifft");m.T1=await wr.fromEvaluations(p.T1,r,e),m.T1.divByZerofier(s.domainSize,d.one),e&&e.info("··· Computing T1z ifft");if(m.T1z=await wr.fromEvaluations(p.T1z,r,e),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}(),e&&e.info("> Computing T2 polynomial");await async function(){e&&e.info("··· Computing T2 evaluations");p.T2=new qa(4*g),p.T2z=new qa(4*g);let t=d.one;for(let a=0;a<4*s.domainSize;a++){e&&0!==a&&a%1e5==0&&e.info(` T2 evaluation ${a}/${4*s.domainSize}`);const o=d.square(t),i=d.mul(t,d.w[s.power]),n=d.square(i),l=L.A.getEvaluation(a),c=L.B.getEvaluation(a),r=L.C.getEvaluation(a),_=L.Z.getEvaluation(a),g=L.Z.getEvaluation((4*s.domainSize+4+a)%(4*s.domainSize)),f=d.add(d.add(d.mul(w.b[7],o),d.mul(w.b[8],t)),w.b[9]),h=d.add(d.add(d.mul(w.b[7],n),d.mul(w.b[8],i)),w.b[9]),m=L.Sigma1.getEvaluation(a),b=L.Sigma2.getEvaluation(a),y=L.Sigma3.getEvaluation(a),A=d.mul(w.beta,t);let C=d.add(l,A);C=d.add(C,w.gamma);let F=d.add(c,d.mul(A,s.k1));F=d.add(F,w.gamma);let x=d.add(r,d.mul(A,s.k2));x=d.add(x,w.gamma);let I=d.mul(d.mul(d.mul(C,F),x),_),B=d.mul(d.mul(d.mul(C,F),x),f),E=d.add(l,d.mul(w.beta,m));E=d.add(E,w.gamma);let v=d.add(c,d.mul(w.beta,b));v=d.add(v,w.gamma);let S=d.add(r,d.mul(w.beta,y));S=d.add(S,w.gamma);let P=d.mul(d.mul(d.mul(E,v),S),g),q=d.mul(d.mul(d.mul(E,v),S),h),O=d.sub(I,P),G=d.sub(B,q);p.T2.set(O,a*u),p.T2z.set(G,a*u),t=d.mul(t,d.w[s.power+2])}e&&e.info("··· Computing T2 ifft");m.T2=await wr.fromEvaluations(p.T2,r,e),e&&e.info("··· Computing T2 / ZH");m.T2.divByZerofier(s.domainSize,d.one),e&&e.info("··· Computing T2z ifft");if(m.T2z=await wr.fromEvaluations(p.T2z,r,e),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}(),e&&e.info("> Computing C2 polynomial");await async function(){let t=new Or(3,r,e);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")}(),e&&e.info("> Computing C2 multi exponentiation");let a=await m.C2.multiExponentiation(C,"C2");return A.addPolynomial("C2",a),0}(),delete p.A,delete p.B,delete p.C,delete L.A,delete L.B,delete L.C,delete L.Sigma1,delete L.Sigma2,delete L.Sigma3,delete L.lagrange1,delete L.Z,globalThis.gc&&globalThis.gc(),e&&e.info("> ROUND 3"),await async function(){e&&e.info("> Computing challenge xi");const t=new lr(r);t.addScalar(w.gamma),t.addPolCommitment(A.getPolynomial("C2")),w.xiSeed=t.getChallenge();const a=d.square(w.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(a,w.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],a),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]),w.xi=d.mul(d.square(y.S2.h2w3[0]),y.S2.h2w3[0]),e&&e.info("··· challenges.xi: "+d.toString(w.xi));m.QL=new wr(new qa(g),r,e),m.QR=new wr(new qa(g),r,e),m.QM=new wr(new qa(g),r,e),m.QO=new wr(new qa(g),r,e),m.QC=new wr(new qa(g),r,e),await l.readToBuffer(m.QL.coef,0,g,c[ci][0].p),await l.readToBuffer(m.QR.coef,0,g,c[si][0].p),await l.readToBuffer(m.QM.coef,0,g,c[ri][0].p),await l.readToBuffer(m.QO.coef,0,g,c[di][0].p),await l.readToBuffer(m.QC.coef,0,g,c[ui][0].p),e&&e.info("··· Computing evaluations");A.addEvaluation("ql",m.QL.evaluate(w.xi)),A.addEvaluation("qr",m.QR.evaluate(w.xi)),A.addEvaluation("qm",m.QM.evaluate(w.xi)),A.addEvaluation("qo",m.QO.evaluate(w.xi)),A.addEvaluation("qc",m.QC.evaluate(w.xi)),A.addEvaluation("s1",m.Sigma1.evaluate(w.xi)),A.addEvaluation("s2",m.Sigma2.evaluate(w.xi)),A.addEvaluation("s3",m.Sigma3.evaluate(w.xi)),A.addEvaluation("a",m.A.evaluate(w.xi)),A.addEvaluation("b",m.B.evaluate(w.xi)),A.addEvaluation("c",m.C.evaluate(w.xi)),A.addEvaluation("z",m.Z.evaluate(w.xi)),w.xiw=d.mul(w.xi,d.w[s.power]),A.addEvaluation("zw",m.Z.evaluate(w.xiw)),A.addEvaluation("t1w",m.T1.evaluate(w.xiw)),A.addEvaluation("t2w",m.T2.evaluate(w.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(),e&&e.info("> ROUND 4"),await async function(){e&&e.info("> Computing challenge alpha");const t=new lr(r);t.addScalar(w.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")),w.alpha=t.getChallenge(),e&&e.info("··· challenges.alpha: "+d.toString(w.alpha));e&&e.info("> Reading C0 polynomial");m.C0=new wr(new qa(8*g),r,e),await l.readToBuffer(m.C0.coef,0,8*g,c[mi][0].p),e&&e.info("> Computing R0 polynomial");(function(){if(m.R0=wr.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])],r),m.R0.degree()>7)throw new Error("R0 Polynomial is not well calculated")})(),e&&e.info("> Computing R1 polynomial");(function(){if(m.R1=wr.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])],r),m.R1.degree()>3)throw new Error("R1 Polynomial is not well calculated")})(),e&&e.info("> Computing R2 polynomial");(function(){if(m.R2=wr.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])],r),m.R2.degree()>5)throw new Error("R2 Polynomial is not well calculated")})(),e&&e.info("> Computing F polynomial");await async function(){e&&e.info("··· Computing F polynomial");m.F=wr.fromPolynomial(m.C0,r,e),m.F.sub(m.R0),m.F.divByZerofier(8,w.xi);let t=wr.fromPolynomial(m.C1,r,e);t.sub(m.R1),t.mulScalar(w.alpha),t.divByZerofier(4,w.xi);let a=wr.fromPolynomial(m.C2,r,e);if(a.sub(m.R2),a.mulScalar(d.square(w.alpha)),a.divByZerofier(3,w.xi),a.divByZerofier(3,w.xiw),m.F.add(t),m.F.add(a),m.F.degree()>=9*s.domainSize-6)throw new Error("F Polynomial is not well calculated")}(),e&&e.info("> Computing W1 multi exponentiation");let a=await m.F.multiExponentiation(C,"W1");return A.addPolynomial("W1",a),0}(),globalThis.gc&&globalThis.gc(),e&&e.info("> ROUND 5"),await async function(){e&&e.info("> Computing challenge y");const t=new lr(r);t.addScalar(w.alpha),t.addPolCommitment(A.getPolynomial("W1")),w.y=t.getChallenge(),e&&e.info("··· challenges.y: "+d.toString(w.y));e&&e.info("> Computing L polynomial");await async function(){e&&e.info("··· Computing L polynomial");const t=m.R0.evaluate(w.y),a=m.R1.evaluate(w.y),o=m.R2.evaluate(w.y);let i=d.sub(w.y,y.S0.h0w8[0]);for(let t=1;t<8;t++)i=d.mul(i,d.sub(w.y,y.S0.h0w8[t]));let n=d.sub(w.y,y.S1.h1w4[0]);for(let t=1;t<4;t++)n=d.mul(n,d.sub(w.y,y.S1.h1w4[t]));let l=d.sub(w.y,y.S2.h2w3[0]);for(let t=1;t<3;t++)l=d.mul(l,d.sub(w.y,y.S2.h2w3[t]));for(let t=0;t<3;t++)l=d.mul(l,d.sub(w.y,y.S2.h3w3[t]));let c=d.mul(n,l),u=d.mul(w.alpha,d.mul(i,l)),_=d.mul(d.square(w.alpha),d.mul(i,n));b.denH1=n,b.denH2=l,m.L=wr.fromPolynomial(m.C0,r,e),m.L.subScalar(t),m.L.mulScalar(c);let g=wr.fromPolynomial(m.C1,r,e);g.subScalar(a),g.mulScalar(u);let f=wr.fromPolynomial(m.C2,r,e);f.subScalar(o),f.mulScalar(_),m.L.add(g),m.L.add(f),e&&e.info("> Computing ZT polynomial");await async function(){m.ZT=wr.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]],r)}();const h=m.ZT.evaluate(w.y);if(m.F.mulScalar(h),m.L.sub(m.F),m.L.degree()>=9*s.domainSize)throw new Error("L Polynomial is not well calculated");delete p.L}(),e&&e.info("> Computing ZTS2 polynomial");await async function(){m.ZTS2=wr.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]],r)}();let a=m.ZTS2.evaluate(w.y);a=d.inv(a),m.L.mulScalar(a);const o=wr.fromCoefficientsArray([d.neg(w.y),d.one],r);e&&e.info("> Computing W' = L / ZTS2 polynomial");const i=m.L.divBy(o);if(i.degree()>0)throw new Error(`Degree of L(X)/(ZTS2(y)(X-y)) remainder is ${i.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");e&&e.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=w.xi;for(let a=0;a Reading PTau file");const{fd:i,sections:n}=await Ue(a,"ptau",1);if(!n[12])throw new Error("Powers of Tau is not well prepared. Section 12 missing.");o&&o.info("> Getting curve from PTau settings");const{curve:l}=await Pn(i,n);o&&o.info("> Reading r1cs file");const{fd:c,sections:s}=await Ue(t,"r1cs",1),r=await Os(c,s,{loadConstraints:!1,loadCustomGates:!0});if(r.prime!==l.r)throw new Error("r1cs curve does not match powers of tau ceremony curve");const d=l.Fr,u=l.Fr.n8,_=2*l.G1.F.n8,g=2*l.G2.F.n8;let f,h={},p={},m={nVars:r.nVars,nPublic:r.nOutputs+r.nPubInputs};const L=new $s;let b=new $s;if(o&&o.info("> Processing FFlonk constraints"),await async function(t,a,e){for(let a=0;a computing k1 and k2");const[w,y]=function(){let t=d.two;for(;e(t,[],m.cirPower);)d.add(t,d.one);let a=d.add(t,d.one);for(;e(a,[t],m.cirPower);)d.add(a,d.one);return[t,a];function e(t,a,e){const o=2**e;let i=d.one;for(let n=0;n computing w3");const A=function(){let t=d.e(31624),a=fe.div(3648040478639879203707734290876212514758060733402672390616367364429301415936n,fe.e(3));return d.exp(t,a)}();o&&o.info("> computing w4");const C=d.w[2];o&&o.info("> computing w8");const F=d.w[3];o&&o.info("> computing wr");const x=function(t,a){const e=a.e(467799165886069610036046866799264026481344299079011762026774533774345988080n);return a.exp(e,2**(28-t))}(m.cirPower,l.Fr);return await async function(){o&&o.info("> Writing the zkey file");const t=await Qe(e,"zkey",1,ai,1<<22,1<<24);o&&o.info(`··· Writing Section ${Wo}. Zkey Header`);await async function(t){await ke(t,Wo),await t.writeULE32(Xo),await Re(t)}(t),o&&o.info(`··· Writing Section ${oi}. Additions`);await async function(t){await ke(t,oi);const a=new Uint8Array(8+2*u),e=new DataView(a.buffer);for(let i=0;i=8*m.domainSize)throw new Error("C0 Polynomial is not well calculated");await ke(t,mi),await t.write(h.C0.coef),await Re(t)}(t),globalThis.gc&&globalThis.gc();o&&o.info(`··· Writing Section ${ei}. FFlonk Header`);await async function(t){await ke(t,ei);const a=l.q,e=8*(Math.floor((fe.bitLength(a)-1)/64)+1);await t.writeULE32(e),await $e(t,a,e);const o=l.r,c=8*(Math.floor((fe.bitLength(o)-1)/64)+1);let s;await t.writeULE32(c),await $e(t,o,c),await t.writeULE32(m.nVars),await t.writeULE32(m.nPublic),await t.writeULE32(m.domainSize),await t.writeULE32(b.length),await t.writeULE32(L.length),await t.write(w),await t.write(y),await t.write(A),await t.write(C),await t.write(F),await t.write(x),s=await i.read(g,n[3][0].p+g),await t.write(s);let r=await h.C0.multiExponentiation(f,"C0");await t.write(r),await Re(t)}(t),globalThis.gc&&globalThis.gc();o&&o.info("> Writing the zkey file finished");await t.close()}(),await c.close(),await i.close(),o&&o.info("FFLONK SETUP FINISHED"),0;async function I(t,a,e,i){await ke(t,a);for(let a=0;a Checking commitments belong to G1"),!function(t,a,e){const o=t.G1;return o.isValid(a.polynomials.C1)&&o.isValid(a.polynomials.C2)&&o.isValid(a.polynomials.W1)&&o.isValid(a.polynomials.W2)&&o.isValid(e.C0)}(i,l,n))return o&&o.error("Proof commitments are not valid"),!1;if(o&&o.info("> Checking evaluations belong to F"),!function(t,a){return Qr(t,a.evaluations.ql)&&Qr(t,a.evaluations.qr)&&Qr(t,a.evaluations.qm)&&Qr(t,a.evaluations.qo)&&Qr(t,a.evaluations.qc)&&Qr(t,a.evaluations.s1)&&Qr(t,a.evaluations.s2)&&Qr(t,a.evaluations.s3)&&Qr(t,a.evaluations.a)&&Qr(t,a.evaluations.b)&&Qr(t,a.evaluations.c)&&Qr(t,a.evaluations.z)&&Qr(t,a.evaluations.zw)&&Qr(t,a.evaluations.t1w)&&Qr(t,a.evaluations.t2w)}(i,l))return o&&o.error("Proof evaluations are not valid."),!1;if(o&&o.info("> Checking public inputs belong to F"),!function(t,a){for(let e=0;e Computing challenges");const{challenges:r,roots:d}=function(t,a,e,o,i){const n=t.Fr,l={},c={},s=new lr(t);s.addPolCommitment(e.C0);for(let t=0;t Computing Zero polynomial evaluation Z_H(xi)"),r.zh=s.sub(r.xiN,s.one),r.invzh=s.inv(r.zh),o&&o.info("> Computing Lagrange evaluations");const u=await async function(t,a,e){const o=t.Fr,i=Math.max(1,e.nPublic),n=new qa(i*o.n8);let l=new qa(i*o.n8),c=o.one;for(let t=0;t Computing polynomial identities PI(X)");const _=function(t,a,e){const o=t.Fr;let i=o.zero;for(let t=0;t Computing r0(y)");const g=function(t,a,e,o,i){const n=o.Fr,l=kr(e.S0.h0w8,a.y,a.xi,o);i&&i.info("··· Computing r0(y)");let c=n.zero;for(let a=0;a<8;a++){let o=[];o[1]=e.S0.h0w8[a];for(let t=2;t<8;t++)o[t]=n.mul(o[t-1],e.S0.h0w8[a]);let i=n.add(t.evaluations.ql,n.mul(t.evaluations.qr,o[1]));i=n.add(i,n.mul(t.evaluations.qo,o[2])),i=n.add(i,n.mul(t.evaluations.qm,o[3])),i=n.add(i,n.mul(t.evaluations.qc,o[4])),i=n.add(i,n.mul(t.evaluations.s1,o[5])),i=n.add(i,n.mul(t.evaluations.s2,o[6])),i=n.add(i,n.mul(t.evaluations.s3,o[7])),c=n.add(c,n.mul(i,l[a]))}return c}(l,r,d,i,o);o&&o.info("> Computing r1(y)");const f=function(t,a,e,o,i,n){const l=i.Fr,c=kr(e.S1.h1w4,a.y,a.xi,i);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,o),s=l.mul(s,a.invzh),n&&n.info("··· Computing C1(h_1ω_4^i) values");let r=l.zero;for(let a=0;a<4;a++){let o=t.evaluations.a;o=l.add(o,l.mul(e.S1.h1w4[a],t.evaluations.b));const i=l.square(e.S1.h1w4[a]);o=l.add(o,l.mul(i,t.evaluations.c)),o=l.add(o,l.mul(l.mul(i,e.S1.h1w4[a]),s)),r=l.add(r,l.mul(o,c[a]))}return r}(l,r,d,_,i,o);o&&o.info("> Computing r2(y)");const h=function(t,a,e,o,i,n,l){const c=n.Fr,s=function(t,a,e,o,i){const n=i.Fr,l=[],c=t[0].length,s=c*t.length,r=n.exp(a,s),d=n.mul(n.add(e,o),n.exp(a,c)),u=n.mul(e,o),_=n.add(n.sub(r,d),u);let g=n.mul(n.mul(n.e(c),t[0][0]),n.sub(e,o));for(let e=0;e Computing F");const p=function(t,a,e,o,i){const n=t.G1,l=t.Fr;let c=l.sub(o.y,i.S0.h0w8[0]);for(let t=1;t<8;t++)c=l.mul(c,l.sub(o.y,i.S0.h0w8[t]));o.temp=c;let s=l.sub(o.y,i.S1.h1w4[0]);for(let t=1;t<4;t++)s=l.mul(s,l.sub(o.y,i.S1.h1w4[t]));let r=l.sub(o.y,i.S2.h2w3[0]);for(let t=1;t<3;t++)r=l.mul(r,l.sub(o.y,i.S2.h2w3[t]));for(let t=0;t<3;t++)r=l.mul(r,l.sub(o.y,i.S2.h3w3[t]));o.quotient1=l.mul(o.alpha,l.div(c,s)),o.quotient2=l.mul(l.square(o.alpha),l.div(c,r));let d=n.timesFr(a.polynomials.C1,o.quotient1),u=n.timesFr(a.polynomials.C2,o.quotient2);return n.add(e.C0,n.add(d,u))}(i,l,n,r,d);o&&o.info("> Computing E");const m=function(t,a,e,o,i,n,l){const c=t.G1,s=t.Fr;let r=s.mul(n,e.quotient1),d=s.mul(l,e.quotient2);return c.timesFr(c.one,s.add(i,s.add(r,d)))}(i,0,r,0,g,f,h);o&&o.info("> Computing J");const L=function(t,a,e){const o=t.G1;return o.timesFr(a.polynomials.W1,e.temp)}(i,l,r);o&&o.info("> Validate all evaluations with a pairing");const b=await async function(t,a,e,o,i,n,l){const c=t.G1;let s=c.timesFr(a.polynomials.W2,e.y);s=c.add(c.sub(c.sub(i,n),l),s);const r=t.G2.one,d=a.polynomials.W2,u=o.X_2;return await t.pairingEq(c.neg(s),r,d,u)}(i,l,r,n,p,m,L);return o&&(b?o.info("PROOF VERIFIED SUCCESSFULLY"):o.warn("Invalid Proof")),o&&o.info("FFLONK VERIFIER FINISHED"),b},exportSolidityVerifier:Xs,exportSolidityCallData:async function(t,a){const e=Rr(a),o=Rr(t),i=await to(e.curve);i.G1,i.Fr;let n="";for(let t=0;t { if (err) reject(err) resolve(content) - }) + }, isBuffer) }) } - async setFileContent(path, content) { + async setFileContent(path, content, isBuffer?) { if (this.currentRequest) { const canCall = await this.askUserPermission(`writeFile`, `modifying ${path} ...`) const required = this.appManager.isRequired(this.currentRequest.from) @@ -602,10 +602,10 @@ class FileManager extends Plugin { this.call('notification', 'toast', fileChangedToastMsg(this.currentRequest.from, path)) } } - return await this._setFileInternal(path, content) + return await this._setFileInternal(path, content, isBuffer) } - _setFileInternal(path, content) { + _setFileInternal(path, content, isBuffer?) { const provider = this.fileProviderOf(path) if (!provider) throw createError({ code: 'ENOENT', message: `${path} not available` }) // TODO : Add permission @@ -616,7 +616,7 @@ class FileManager extends Plugin { this.syncEditor(path) this.emit('fileSaved', path) resolve(true) - }) + }, isBuffer) }) } diff --git a/apps/remix-ide/src/app/files/fileProvider.js b/apps/remix-ide/src/app/files/fileProvider.js index 9b7e63efdf..f2c73d149d 100644 --- a/apps/remix-ide/src/app/files/fileProvider.js +++ b/apps/remix-ide/src/app/files/fileProvider.js @@ -87,12 +87,12 @@ class FileProvider { cb() } - async get (path, cb) { + async get (path, cb, isBuffer = false) { cb = cb || function () { /* do nothing. */ } path = this.getPathFromUrl(path) || path // ensure we actually use the normalized path from here var unprefixedpath = this.removePrefix(path) try { - const content = await window.remixFileSystem.readFile(unprefixedpath, 'utf8') + const content = await window.remixFileSystem.readFile(unprefixedpath, isBuffer ? undefined : 'utf8') if (cb) cb(null, content) return content } catch (err) { @@ -101,17 +101,17 @@ class FileProvider { } } - async set (path, content, cb) { + async set (path, content, cb, isBuffer = false) { cb = cb || function () { /* do nothing. */ } var unprefixedpath = this.removePrefix(path) const exists = await window.remixFileSystem.exists(unprefixedpath) - if (exists && await window.remixFileSystem.readFile(unprefixedpath, 'utf8') === content) { + if (exists && await window.remixFileSystem.readFile(unprefixedpath, isBuffer ? undefined : 'utf8') === content) { if (cb) cb() return null } await this.createDir(path.substr(0, path.lastIndexOf('/'))) try { - await window.remixFileSystem.writeFile(unprefixedpath, content, 'utf8') + await window.remixFileSystem.writeFile(unprefixedpath, content, isBuffer ? undefined : 'utf8') } catch (e) { if (cb) cb(e) return false diff --git a/apps/remix-ide/src/app/tabs/locales/en/circuit.json b/apps/remix-ide/src/app/tabs/locales/en/circuit.json new file mode 100644 index 0000000000..32dab62880 --- /dev/null +++ b/apps/remix-ide/src/app/tabs/locales/en/circuit.json @@ -0,0 +1,13 @@ +{ + "circuit.compiler": "Compiler", + "circuit.autoCompile": "Auto compile", + "circuit.hideWarnings": "Hide warnings", + "circuit.advancedConfigurations": "Advanced Configurations", + "circuit.compilerConfiguration": "Compiler configuration", + "circuit.prime": "Prime", + "circuit.useConfigurationFile": "Use configuration file", + "circuit.compile": "Compile", + "circuit.noFileSelected": "no file selected", + "circuit.generateR1cs": "Generate R1CS", + "circuit.computeWitness": "Compute Witness" +} diff --git a/apps/remix-ide/src/app/tabs/locales/en/index.js b/apps/remix-ide/src/app/tabs/locales/en/index.js index 4d56affa4f..1b3d8cd97c 100644 --- a/apps/remix-ide/src/app/tabs/locales/en/index.js +++ b/apps/remix-ide/src/app/tabs/locales/en/index.js @@ -13,6 +13,7 @@ import permissionHandlerJson from './permissionHandler.json'; import solUmlGenJson from './solUmlGen.json' import remixAppJson from './remixApp.json' import remixUiTabsJson from './remixUiTabs.json' +import circuitJson from './circuit.json'; export default { ...debuggerJson, @@ -30,4 +31,5 @@ export default { ...solUmlGenJson, ...remixAppJson, ...remixUiTabsJson, + ...circuitJson } diff --git a/apps/remix-ide/src/app/tabs/locales/es/circuit.json b/apps/remix-ide/src/app/tabs/locales/es/circuit.json new file mode 100644 index 0000000000..32dab62880 --- /dev/null +++ b/apps/remix-ide/src/app/tabs/locales/es/circuit.json @@ -0,0 +1,13 @@ +{ + "circuit.compiler": "Compiler", + "circuit.autoCompile": "Auto compile", + "circuit.hideWarnings": "Hide warnings", + "circuit.advancedConfigurations": "Advanced Configurations", + "circuit.compilerConfiguration": "Compiler configuration", + "circuit.prime": "Prime", + "circuit.useConfigurationFile": "Use configuration file", + "circuit.compile": "Compile", + "circuit.noFileSelected": "no file selected", + "circuit.generateR1cs": "Generate R1CS", + "circuit.computeWitness": "Compute Witness" +} diff --git a/apps/remix-ide/src/app/tabs/locales/fr/circuit.json b/apps/remix-ide/src/app/tabs/locales/fr/circuit.json new file mode 100644 index 0000000000..32dab62880 --- /dev/null +++ b/apps/remix-ide/src/app/tabs/locales/fr/circuit.json @@ -0,0 +1,13 @@ +{ + "circuit.compiler": "Compiler", + "circuit.autoCompile": "Auto compile", + "circuit.hideWarnings": "Hide warnings", + "circuit.advancedConfigurations": "Advanced Configurations", + "circuit.compilerConfiguration": "Compiler configuration", + "circuit.prime": "Prime", + "circuit.useConfigurationFile": "Use configuration file", + "circuit.compile": "Compile", + "circuit.noFileSelected": "no file selected", + "circuit.generateR1cs": "Generate R1CS", + "circuit.computeWitness": "Compute Witness" +} diff --git a/apps/remix-ide/src/app/tabs/locales/zh/circuit.json b/apps/remix-ide/src/app/tabs/locales/zh/circuit.json new file mode 100644 index 0000000000..e4443c871e --- /dev/null +++ b/apps/remix-ide/src/app/tabs/locales/zh/circuit.json @@ -0,0 +1,14 @@ +{ + "circuit-compiler.displayName": "Circuit 编译器", + "circuit.compiler": "Compiler", + "circuit.autoCompile": "自动编译", + "circuit.hideWarnings": "隐藏警告", + "circuit.advancedConfigurations": "高级配置", + "circuit.compilerConfiguration": "编译器配置", + "circuit.prime": "质数", + "circuit.useConfigurationFile": "使用配置文件", + "circuit.compile": "编译", + "circuit.noFileSelected": "未选中文件", + "circuit.generateR1cs": "生成R1CS", + "circuit.computeWitness": "证人计算器" +} diff --git a/apps/remix-ide/src/app/tabs/locales/zh/index.js b/apps/remix-ide/src/app/tabs/locales/zh/index.js index ded9c45b14..1acd2ba1be 100644 --- a/apps/remix-ide/src/app/tabs/locales/zh/index.js +++ b/apps/remix-ide/src/app/tabs/locales/zh/index.js @@ -14,6 +14,7 @@ import solUmlGenJson from './solUmlGen.json' import remixAppJson from './remixApp.json' import remixUiTabsJson from './remixUiTabs.json' import enJson from '../en'; +import circuitJson from './circuit.json'; // There may have some un-translated content. Always fill in the gaps with EN JSON. // No need for a defaultMessage prop when render a FormattedMessage component. @@ -33,4 +34,5 @@ export default Object.assign({}, enJson, { ...solUmlGenJson, ...remixAppJson, ...remixUiTabsJson, + ...circuitJson }) diff --git a/package.json b/package.json index 2631a758e7..fdba9c3976 100644 --- a/package.json +++ b/package.json @@ -150,7 +150,7 @@ "brace": "^0.8.0", "change-case": "^4.1.1", "chokidar": "^2.1.8", - "circom_wasm": "^0.0.2", + "circom_wasm": "https://github.com/ioedeveloper/circom_wasm.git", "color-support": "^1.1.3", "commander": "^9.4.1", "core-js": "^3.6.5", @@ -202,6 +202,7 @@ "remark-gfm": "^3.0.1", "rss-parser": "^3.12.0", "signale": "^1.4.0", + "snarkjs": "^0.7.0", "sol2uml": "^2.4.3", "string-similarity": "^4.0.4", "svg2pdf.js": "^2.2.1", diff --git a/yarn.lock b/yarn.lock index a6e3a51be6..4aa35167a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2616,6 +2616,19 @@ resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45" integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA== +"@iden3/bigarray@0.0.2": + version "0.0.2" + resolved "https://registry.yarnpkg.com/@iden3/bigarray/-/bigarray-0.0.2.tgz#6fc4ba5be18daf8a26ee393f2fb62b80d98c05e9" + integrity sha512-Xzdyxqm1bOFF6pdIsiHLLl3HkSLjbhqJHVyqaTxXt3RqXBEnmsUmEW47H7VOi/ak7TdkRpNkxjyK5Zbkm+y52g== + +"@iden3/binfileutils@0.0.11": + version "0.0.11" + resolved "https://registry.yarnpkg.com/@iden3/binfileutils/-/binfileutils-0.0.11.tgz#9ffbbcc1279f2b2182bb6dcff4eee8a5b2167911" + integrity sha512-LylnJoZ0CTdgErnKY8OxohvW4K+p6UHD3sxt+3P9AmMyBQjYR4IpoqoYZZ+9aMj89cmCQ21UvdhndAx04er3NA== + dependencies: + fastfile "0.0.20" + ffjavascript "^0.2.48" + "@isomorphic-git/idb-keyval@3.3.2": version "3.3.2" resolved "https://registry.yarnpkg.com/@isomorphic-git/idb-keyval/-/idb-keyval-3.3.2.tgz#c0509a6c5987d8a62efb3e47f2815bcc5eda2489" @@ -7660,7 +7673,7 @@ axobject-query@^2.2.0: resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.2.0.tgz#943d47e10c0b704aa42275e20edf3722648989be" integrity sha512-Td525n+iPOOyUQIeBfcASuG6uJsDOITl7Mds5gFyerkWiX7qhUTdYUBlSgNMyVqtSJqwpt1kXGLdUt6SykLMRA== -b4a@^1.6.4: +b4a@^1.0.1, b4a@^1.6.4: version "1.6.4" resolved "https://registry.yarnpkg.com/b4a/-/b4a-1.6.4.tgz#ef1c1422cae5ce6535ec191baeed7567443f36c9" integrity sha512-fpWrvyVHEKyeEvbKZTVOeZF3VSKKWtJxFIxX/jaVPf+cLbGUSitjb49pHLqPV2BUNNZ0LcoeEGfE/YCpyDYHIw== @@ -8432,6 +8445,17 @@ before-after-hook@^2.0.0: resolved "https://registry.yarnpkg.com/before-after-hook/-/before-after-hook-2.2.2.tgz#a6e8ca41028d90ee2c24222f201c90956091613e" integrity sha512-3pZEU3NT5BFUo/AD5ERPWOgQOCZITni6iavr5AUw5AUwQjMlI0kzu5btnyD39AF0gUEsDPwJT+oY1ORBJijPjQ== +bfj@^7.0.2: + version "7.1.0" + resolved "https://registry.yarnpkg.com/bfj/-/bfj-7.1.0.tgz#c5177d522103f9040e1b12980fe8c38cf41d3f8b" + integrity sha512-I6MMLkn+anzNdCUp9hMRyui1HaNEUCco50lxbvNS4+EyXg8lN3nJ48PjPWtbH8UVS9CuMoaKE9U2V3l29DaRQw== + dependencies: + bluebird "^3.7.2" + check-types "^11.2.3" + hoopy "^0.1.4" + jsonpath "^1.1.1" + tryer "^1.0.1" + big.js@^5.2.2: version "5.2.2" resolved "https://registry.yarnpkg.com/big.js/-/big.js-5.2.2.tgz#65f0af382f578bcdc742bd9c281e9cb2d7768328" @@ -8497,6 +8521,14 @@ bl@^4.0.0, bl@^4.0.3, bl@^4.1.0: inherits "^2.0.4" readable-stream "^3.4.0" +blake2b-wasm@^2.4.0: + version "2.4.0" + resolved "https://registry.yarnpkg.com/blake2b-wasm/-/blake2b-wasm-2.4.0.tgz#9115649111edbbd87eb24ce7c04b427e4e2be5be" + integrity sha512-S1kwmW2ZhZFFFOghcx73+ZajEfKBqhP82JMssxtLVMxlaPea1p9uoLiUZ5WYyHn0KddwbLc+0vh4wR0KBNoT5w== + dependencies: + b4a "^1.0.1" + nanoassert "^2.0.0" + blakejs@^1.1.0: version "1.1.1" resolved "https://registry.yarnpkg.com/blakejs/-/blakejs-1.1.1.tgz#bf313053978b2cd4c444a48795710be05c785702" @@ -9525,6 +9557,11 @@ check-error@1.0.2, check-error@^1.0.2: resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82" integrity sha512-BrgHpW9NURQgzoNyjfq0Wu6VFO6D7IZEmJNdtgNqpzGG8RuNFHt2jQxWlAs4HMe119chBnv+34syEZtc6IhLtA== +check-types@^11.2.3: + version "11.2.3" + resolved "https://registry.yarnpkg.com/check-types/-/check-types-11.2.3.tgz#1ffdf68faae4e941fce252840b1787b8edc93b71" + integrity sha512-+67P1GkJRaxQD6PKK0Et9DhwQB+vGg3PM5+aavopCpZT1lj9jeqfvpgTLAWErNj8qApkkmXlu/Ug74kmhagkXg== + cheerio-select@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/cheerio-select/-/cheerio-select-2.1.0.tgz#4d8673286b8126ca2a8e42740d5e3c4884ae21b4" @@ -9683,10 +9720,16 @@ cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3: inherits "^2.0.1" safe-buffer "^5.0.1" -circom_wasm@^0.0.2: - version "0.0.2" - resolved "https://registry.yarnpkg.com/circom_wasm/-/circom_wasm-0.0.2.tgz#9d24866b8289a5778999270823a4cb06e64145b5" - integrity sha512-SCMP6cxHHL7MLedDrTl+nGYyE6+kE5GepbxtZm65GlR0wUMD9eNOD1shwScWaDnmBOZTrImmNeTYZA5DWCmIww== +circom_runtime@0.1.22: + version "0.1.22" + resolved "https://registry.yarnpkg.com/circom_runtime/-/circom_runtime-0.1.22.tgz#f957c47662cdd03cd3fb76979c434c719a366373" + integrity sha512-V/XYZWBhbZY8SotkaGH4FbiDYAZ8a1Md++MBiKPDOuWS/NIJB+Q+XIiTC8zKMgoDaa9cd2OiTvsC9J6te7twNg== + dependencies: + ffjavascript "0.2.57" + +"circom_wasm@https://github.com/ioedeveloper/circom_wasm.git": + version "0.0.0-alpha.7" + resolved "https://github.com/ioedeveloper/circom_wasm.git#24d26dec739297a1bd3e61f74ca3b95b20f66a25" circular-json@^0.3.0: version "0.3.3" @@ -11250,7 +11293,7 @@ deep-extend@~0.4.0: resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.4.1.tgz#efe4113d08085f4e6f9687759810f807469e2253" integrity sha1-7+QRPQgIX05vlod1mBD4B0aeIlM= -deep-is@^0.1.3: +deep-is@^0.1.3, deep-is@~0.1.3: version "0.1.4" resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.4.tgz#a6f2dce612fadd2ef1f519b73551f17e85199831" integrity sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ== @@ -11839,6 +11882,13 @@ ee-first@1.1.1: resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0= +ejs@^3.1.6: + version "3.1.9" + resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.9.tgz#03c9e8777fe12686a9effcef22303ca3d8eeb361" + integrity sha512-rC+QVNMJWv+MtPgkt0y+0rVEIdbtxVADApW9JXrUVlzHetgcyczP/E7DJmWJ4fJCZF2cPcBk0laWO9ZHMG3DmQ== + dependencies: + jake "^10.8.5" + ejs@^3.1.7, ejs@^3.1.8: version "3.1.8" resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.8.tgz#758d32910c78047585c7ef1f92f9ee041c1c190b" @@ -12248,6 +12298,18 @@ escape-string-regexp@^5.0.0: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz#4683126b500b61762f2dbebace1806e8be31b1c8" integrity sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw== +escodegen@^1.8.1: + version "1.14.3" + resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.14.3.tgz#4e7b81fba61581dc97582ed78cab7f0e8d63f503" + integrity sha512-qFcX0XJkdg+PB3xjZZG/wKSuT1PnQWx57+TVSjIMmILd2yC/6ByYElPwJnslDsuWuSAp4AwJGumarAAmJch5Kw== + dependencies: + esprima "^4.0.1" + estraverse "^4.2.0" + esutils "^2.0.2" + optionator "^0.8.1" + optionalDependencies: + source-map "~0.6.1" + escodegen@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-2.1.0.tgz#ba93bbb7a43986d29d6041f99f5262da773e2e17" @@ -12476,6 +12538,11 @@ espree@^9.4.0: acorn-jsx "^5.3.2" eslint-visitor-keys "^3.3.0" +esprima@1.2.2: + version "1.2.2" + resolved "https://registry.yarnpkg.com/esprima/-/esprima-1.2.2.tgz#76a0fd66fcfe154fd292667dc264019750b1657b" + integrity sha512-+JpPZam9w5DuJ3Q67SqsMGtiHKENSMRVoxvArfJZK01/BfLEObtZ6orJa/MtoGNR/rfMgp5837T41PAmTwAv/A== + esprima@^4.0.0, esprima@^4.0.1, esprima@~4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" @@ -12495,7 +12562,7 @@ esrecurse@^4.3.0: dependencies: estraverse "^5.2.0" -estraverse@^4.1.1: +estraverse@^4.1.1, estraverse@^4.2.0: version "4.3.0" resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.3.0.tgz#398ad3f3c5a24948be7725e83d11a7de28cdbd1d" integrity sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw== @@ -13133,7 +13200,7 @@ fast-levenshtein@^1.0.0: resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-1.1.4.tgz#e6a754cc8f15e58987aa9cbd27af66fd6f4e5af9" integrity sha1-5qdUzI8V5YmHqpy9J69m/W9OWvk= -fast-levenshtein@^2.0.6: +fast-levenshtein@^2.0.6, fast-levenshtein@~2.0.6: version "2.0.6" resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc= @@ -13163,6 +13230,11 @@ fastest-levenshtein@^1.0.12: resolved "https://registry.yarnpkg.com/fastest-levenshtein/-/fastest-levenshtein-1.0.16.tgz#210e61b6ff181de91ea9b3d1b84fdedd47e034e5" integrity sha512-eRnCtTTtGZFpQCwhJiUOuxPQWRXVKYDn0b2PeHfXL6/Zi53SLAzAHfVhVWK2AryC/WH05kGfxhFIPvTF0SXQzg== +fastfile@0.0.20: + version "0.0.20" + resolved "https://registry.yarnpkg.com/fastfile/-/fastfile-0.0.20.tgz#794a143d58cfda2e24c298e5ef619c748c8a1879" + integrity sha512-r5ZDbgImvVWCP0lA/cGNgQcZqR+aYdFx3u+CtJqUE510pBUVGMn4ulL/iRTI4tACTYsNJ736uzFxEBXesPAktA== + fastq@^1.6.0: version "1.13.0" resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.13.0.tgz#616760f88a7526bdfc596b7cab8c18938c36b98c" @@ -13226,6 +13298,33 @@ fetch-blob@^2.1.1, fetch-blob@^2.1.2: resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-2.1.2.tgz#a7805db1361bd44c1ef62bb57fb5fe8ea173ef3c" integrity sha512-YKqtUDwqLyfyMnmbw8XD6Q8j9i/HggKtPEI+pZ1+8bvheBu78biSmNaXWusx1TauGqtUUGx/cBb1mKdq2rLYow== +ffjavascript@0.2.57: + version "0.2.57" + resolved "https://registry.yarnpkg.com/ffjavascript/-/ffjavascript-0.2.57.tgz#ba1be96015b2688192e49f2f4de2cc5150fd8594" + integrity sha512-V+vxZ/zPNcthrWmqfe/1YGgqdkTamJeXiED0tsk7B84g40DKlrTdx47IqZuiygqAVG6zMw4qYuvXftIJWsmfKQ== + dependencies: + wasmbuilder "0.0.16" + wasmcurves "0.2.0" + web-worker "^1.2.0" + +ffjavascript@0.2.59: + version "0.2.59" + resolved "https://registry.yarnpkg.com/ffjavascript/-/ffjavascript-0.2.59.tgz#b2f836082587fab333dfb181b909a188f80036f3" + integrity sha512-QssOEUv+wilz9Sg7Zaj6KWAm7QceOAEsFuEBTltUsDo1cjn11rA/LGYvzFBPbzNfxRlZxwgJ7uxpCQcdDlrNfw== + dependencies: + wasmbuilder "0.0.16" + wasmcurves "0.2.1" + web-worker "^1.2.0" + +ffjavascript@^0.2.48: + version "0.2.60" + resolved "https://registry.yarnpkg.com/ffjavascript/-/ffjavascript-0.2.60.tgz#4d8ae613d6bf4e98b3cc29ba10c626f5853854cf" + integrity sha512-T/9bnEL5xAZRDbQoEMf+pM9nrhK+C3JyZNmqiWub26EQorW7Jt+jR54gpqDhceA4Nj0YctPQwYnl8xa52/A26A== + dependencies: + wasmbuilder "0.0.16" + wasmcurves "0.2.2" + web-worker "^1.2.0" + fflate@^0.4.8: version "0.4.8" resolved "https://registry.yarnpkg.com/fflate/-/fflate-0.4.8.tgz#f90b82aefbd8ac174213abb338bd7ef848f0f5ae" @@ -14883,6 +14982,11 @@ homedir-polyfill@^1.0.1: dependencies: parse-passwd "^1.0.0" +hoopy@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/hoopy/-/hoopy-0.1.4.tgz#609207d661100033a9a9402ad3dea677381c1b1d" + integrity sha512-HRcs+2mr52W0K+x8RzcLzuPPmVIKMSv97RGHy0Ea9y/mpcaK+xTrjICA04KAHi4GRzxliNqNJEFYWHghy3rSfQ== + hosted-git-info@^2.1.4, hosted-git-info@^2.7.1: version "2.8.9" resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9" @@ -17196,6 +17300,15 @@ jsonparse@^1.2.0: resolved "https://registry.yarnpkg.com/jsonparse/-/jsonparse-1.3.0.tgz#85fc245b1d9259acc6941960b905adf64e7de0e8" integrity sha1-hfwkWx2SWazGlBlguQWt9k594Og= +jsonpath@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/jsonpath/-/jsonpath-1.1.1.tgz#0ca1ed8fb65bb3309248cc9d5466d12d5b0b9901" + integrity sha512-l6Cg7jRpixfbgoWgkrl77dgEj8RPvND0wMH6TwQmi9Qs4TFfS9u5cUFnbeKTwj5ga5Y3BTGGNI28k117LJ009w== + dependencies: + esprima "1.2.2" + static-eval "2.0.2" + underscore "1.12.1" + jspdf@^2.5.1: version "2.5.1" resolved "https://registry.yarnpkg.com/jspdf/-/jspdf-2.5.1.tgz#00c85250abf5447a05f3b32ab9935ab4a56592cc" @@ -17537,6 +17650,14 @@ levn@^0.4.1: prelude-ls "^1.2.1" type-check "~0.4.0" +levn@~0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee" + integrity sha512-0OO4y2iOHix2W6ujICbKIaEQXvFQHue65vUG3pb5EUomzPI90z9hsA1VsO/dbIIpC53J8gxM9Q4Oho0jrCM/yA== + dependencies: + prelude-ls "~1.1.2" + type-check "~0.3.2" + license-webpack-plugin@^4.0.2: version "4.0.2" resolved "https://registry.yarnpkg.com/license-webpack-plugin/-/license-webpack-plugin-4.0.2.tgz#1e18442ed20b754b82f1adeff42249b81d11aec6" @@ -18033,6 +18154,11 @@ logform@^2.2.0: safe-stable-stringify "^1.1.0" triple-beam "^1.3.0" +logplease@^1.2.15: + version "1.2.15" + resolved "https://registry.yarnpkg.com/logplease/-/logplease-1.2.15.tgz#3da442e93751a5992cc19010a826b08d0293c48a" + integrity sha512-jLlHnlsPSJjpwUfcNyUxXCl33AYg2cHhIf9QhGL2T4iPT0XPB+xP1LRKFPgIg1M/sg9kAJvy94w9CzBNrfnstA== + longest-streak@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/longest-streak/-/longest-streak-3.1.0.tgz#62fa67cd958742a1574af9f39866364102d90cd4" @@ -19574,6 +19700,11 @@ nanoassert@^1.1.0: resolved "https://registry.yarnpkg.com/nanoassert/-/nanoassert-1.1.0.tgz#4f3152e09540fde28c76f44b19bbcd1d5a42478d" integrity sha1-TzFS4JVA/eKMdvRLGbvNHVpCR40= +nanoassert@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/nanoassert/-/nanoassert-2.0.0.tgz#a05f86de6c7a51618038a620f88878ed1e490c09" + integrity sha512-7vO7n28+aYO4J+8w96AzhmU8G+Y/xpPDJz/se19ICsqj/momRbb9mh9ZUtkoJ5X3nTnPdhEJyc0qnM6yAsHBaA== + nanobench@^2.1.0, nanobench@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/nanobench/-/nanobench-2.1.1.tgz#c2f23fcce116d50b4998b1954ba114674c137269" @@ -20767,6 +20898,18 @@ optimist@^0.6.1: minimist "~0.0.1" wordwrap "~0.0.2" +optionator@^0.8.1: + version "0.8.3" + resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.3.tgz#84fa1d036fe9d3c7e21d99884b601167ec8fb495" + integrity sha512-+IW9pACdk3XWmmTXG8m3upGUJst5XRGzxMRjXzAuJ1XnIFNvfhjjIuYkDvysnPQ7qzqVzLt78BCruntqRhWQbA== + dependencies: + deep-is "~0.1.3" + fast-levenshtein "~2.0.6" + levn "~0.3.0" + prelude-ls "~1.1.2" + type-check "~0.3.2" + word-wrap "~1.2.3" + optionator@^0.9.1: version "0.9.1" resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.1.tgz#4f236a6373dae0566a6d43e1326674f50c291499" @@ -21988,6 +22131,11 @@ prelude-ls@^1.2.1: resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396" integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g== +prelude-ls@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" + integrity sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w== + prepend-http@^1.0.1: version "1.0.4" resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc" @@ -22443,6 +22591,16 @@ quick-lru@^5.1.1: resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-5.1.1.tgz#366493e6b3e42a3a6885e2e99d18f80fb7a8c932" integrity sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA== +r1csfile@0.0.45: + version "0.0.45" + resolved "https://registry.yarnpkg.com/r1csfile/-/r1csfile-0.0.45.tgz#59d59a33f8b5280017fc00ee691d003a3d705fe0" + integrity sha512-YKIp4D441aZ6OoI9y+bfAyb2j4Cl+OFq/iiX6pPWDrL4ZO968h0dq0w07i65edvrTt7/G43mTnl0qEuLXyp/Yw== + dependencies: + "@iden3/bigarray" "0.0.2" + "@iden3/binfileutils" "0.0.11" + fastfile "0.0.20" + ffjavascript "0.2.57" + raf-schd@^4.0.2: version "4.0.3" resolved "https://registry.yarnpkg.com/raf-schd/-/raf-schd-4.0.3.tgz#5d6c34ef46f8b2a0e880a8fcdb743efc5bfdbc1a" @@ -24446,6 +24604,22 @@ snapdragon@^0.8.1: source-map-resolve "^0.5.0" use "^3.1.0" +snarkjs@^0.7.0: + version "0.7.0" + resolved "https://registry.yarnpkg.com/snarkjs/-/snarkjs-0.7.0.tgz#9b4d193a0535c1903e45f1508aa7ad74cd130844" + integrity sha512-Vu5W+0Va6X1xvlCllpZ2r3/S7MafnL6IrAv09lk/F+VNDHuHEHx3xopR9Kr70p2KpbBBJ/HB9VCDZWism8WGlA== + dependencies: + "@iden3/binfileutils" "0.0.11" + bfj "^7.0.2" + blake2b-wasm "^2.4.0" + circom_runtime "0.1.22" + ejs "^3.1.6" + fastfile "0.0.20" + ffjavascript "0.2.59" + js-sha3 "^0.8.0" + logplease "^1.2.15" + r1csfile "0.0.45" + sntp@1.x.x: version "1.0.9" resolved "https://registry.yarnpkg.com/sntp/-/sntp-1.0.9.tgz#6541184cc90aeea6c6e7b35e2659082443c66198" @@ -24868,6 +25042,13 @@ state-local@^1.0.6: resolved "https://registry.yarnpkg.com/state-local/-/state-local-1.0.7.tgz#da50211d07f05748d53009bee46307a37db386d5" integrity sha512-HTEHMNieakEnoe33shBYcZ7NX83ACUjCu8c40iOGEZsngj9zRnkqS9j1pqQPXwobB0ZcVTk27REb7COQ0UR59w== +static-eval@2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/static-eval/-/static-eval-2.0.2.tgz#2d1759306b1befa688938454c546b7871f806a42" + integrity sha512-N/D219Hcr2bPjLxPiV+TQE++Tsmrady7TqAJugLy7Xk1EumfDWS/f5dtBbkRCGE7wKKXuYockQoj8Rm2/pVKyg== + dependencies: + escodegen "^1.8.1" + static-extend@^0.1.1, static-extend@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6" @@ -25997,6 +26178,11 @@ truncate-utf8-bytes@^1.0.0: dependencies: utf8-byte-length "^1.0.1" +tryer@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/tryer/-/tryer-1.0.1.tgz#f2c85406800b9b0f74c9f7465b81eaad241252f8" + integrity sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA== + ts-loader@^9.2.6: version "9.2.6" resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-9.2.6.tgz#9937c4dd0a1e3dbbb5e433f8102a6601c6615d74" @@ -26166,6 +26352,13 @@ type-check@^0.4.0, type-check@~0.4.0: dependencies: prelude-ls "^1.2.1" +type-check@~0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.3.2.tgz#5884cab512cf1d355e3fb784f30804b2b520db72" + integrity sha512-ZCmOJdvOWDBYJlzAoFkC+Q0+bUyEOS1ltgp1MGU03fqHG+dbi9tBFU2Rd9QKiDZFAYrhPh2JUf7rZRIuHRKtOg== + dependencies: + prelude-ls "~1.1.2" + type-detect@4.0.8, type-detect@^4.0.0, type-detect@^4.0.5: version "4.0.8" resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" @@ -26418,6 +26611,11 @@ undefsafe@^2.0.5: resolved "https://registry.yarnpkg.com/undefsafe/-/undefsafe-2.0.5.tgz#38733b9327bdcd226db889fb723a6efd162e6e2c" integrity sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA== +underscore@1.12.1: + version "1.12.1" + resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.12.1.tgz#7bb8cc9b3d397e201cf8553336d262544ead829e" + integrity sha512-hEQt0+ZLDVUMhebKxL4x1BTtDY7bavVofhZ9KZ4aI26X9SRaE+Y3m83XUL1UP2jn8ynjndwCCpEHdUG+9pP1Tw== + undertaker-registry@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/undertaker-registry/-/undertaker-registry-1.0.1.tgz#5e4bda308e4a8a2ae584f9b9a4359a499825cc50" @@ -27072,6 +27270,32 @@ warning@^4.0.0, warning@^4.0.3: dependencies: loose-envify "^1.0.0" +wasmbuilder@0.0.16: + version "0.0.16" + resolved "https://registry.yarnpkg.com/wasmbuilder/-/wasmbuilder-0.0.16.tgz#f34c1f2c047d2f6e1065cbfec5603988f16d8549" + integrity sha512-Qx3lEFqaVvp1cEYW7Bfi+ebRJrOiwz2Ieu7ZG2l7YyeSJIok/reEQCQCuicj/Y32ITIJuGIM9xZQppGx5LrQdA== + +wasmcurves@0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/wasmcurves/-/wasmcurves-0.2.0.tgz#ccfc5a7d3778b6e0768b82a9336c80054f9bc0cf" + integrity sha512-3e2rbxdujOwaod657gxgmdhZNn+i1qKdHO3Y/bK+8E7bV8ttV/fu5FO4/WLBACF375cK0QDLOP+65Na63qYuWA== + dependencies: + wasmbuilder "0.0.16" + +wasmcurves@0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/wasmcurves/-/wasmcurves-0.2.1.tgz#416d15432a9c6a7b79ef6000eab1e8e7302624ad" + integrity sha512-9ciO7bUE5bgpbOcdK7IO3enrSVIKHwrQmPibok4GLJWaCA7Wyqc9PRYnu5HbiFv9NDFNqVKPtU5R6Is5KujBLg== + dependencies: + wasmbuilder "0.0.16" + +wasmcurves@0.2.2: + version "0.2.2" + resolved "https://registry.yarnpkg.com/wasmcurves/-/wasmcurves-0.2.2.tgz#ca444f6a6f6e2a5cbe6629d98ff478a62b4ccb2b" + integrity sha512-JRY908NkmKjFl4ytnTu5ED6AwPD+8VJ9oc94kdq7h5bIwbj0L4TDJ69mG+2aLs2SoCmGfqIesMWTEJjtYsoQXQ== + dependencies: + wasmbuilder "0.0.16" + watchify@^3.9.0: version "3.11.1" resolved "https://registry.yarnpkg.com/watchify/-/watchify-3.11.1.tgz#8e4665871fff1ef64c0430d1a2c9d084d9721881" @@ -27670,6 +27894,11 @@ word-wrap@^1.2.3: resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.4.tgz#cb4b50ec9aca570abd1f52f33cd45b6c61739a9f" integrity sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA== +word-wrap@~1.2.3: + version "1.2.5" + resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34" + integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA== + wordwrap@0.0.2: version "0.0.2" resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.2.tgz#b79669bb42ecb409f83d583cad52ca17eaa1643f" From 63620c85ddec8acba7d6c9dae270115036cf3b16 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Wed, 11 Oct 2023 15:36:11 +0100 Subject: [PATCH 05/26] Add compute witness button --- .../circuit-compiler/src/app/actions/index.ts | 11 +-- apps/circuit-compiler/src/app/app.tsx | 25 ++++--- .../src/app/components/container.tsx | 8 +- .../src/app/components/witness.tsx | 43 ++++++----- .../src/app/reducers/state.ts | 9 ++- .../src/app/services/circomPluginClient.ts | 75 ++++++++++++------- apps/circuit-compiler/src/app/types/index.ts | 8 +- apps/circuit-compiler/src/profile.json | 2 +- .../src/app/tabs/locales/en/circuit.json | 4 +- .../src/app/tabs/locales/es/circuit.json | 4 +- .../src/app/tabs/locales/fr/circuit.json | 4 +- .../src/app/tabs/locales/zh/circuit.json | 4 +- yarn.lock | 2 +- 13 files changed, 125 insertions(+), 74 deletions(-) diff --git a/apps/circuit-compiler/src/app/actions/index.ts b/apps/circuit-compiler/src/app/actions/index.ts index ed0e3f199a..440d098493 100644 --- a/apps/circuit-compiler/src/app/actions/index.ts +++ b/apps/circuit-compiler/src/app/actions/index.ts @@ -4,29 +4,24 @@ import { Actions, AppState } from "../types" export const compileCircuit = async (plugin: CircomPluginClient, appState: AppState, dispatch: React.Dispatch) => { try { if (appState.status !== "compiling") { - dispatch({ type: 'SET_COMPILER_STATUS', payload: 'compiling' }) await plugin.compile(appState.filePath, { version: appState.version, prime: appState.primeValue }) - dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' }) } else { - console.log('Exisiting compilation in progress') + console.log('Exisiting circuit compilation in progress') } } catch (e) { - dispatch({ type: 'SET_COMPILER_STATUS', payload: 'errored' }) - console.error('Compiling failed: ', e) + console.error(e) + dispatch({ type: 'SET_SIGNAL_INPUTS', payload: [] }) } } export const generateR1cs = async (plugin: CircomPluginClient, appState: AppState, dispatch: React.Dispatch) => { try { if (appState.status !== "generating") { - dispatch({ type: 'SET_COMPILER_STATUS', payload: 'generating' }) await plugin.generateR1cs(appState.filePath, { version: appState.version, prime: appState.primeValue }) - dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' }) } else { console.log('Exisiting r1cs generation in progress') } } catch (e) { - dispatch({ type: 'SET_COMPILER_STATUS', payload: 'errored' }) console.error('Generating R1CS failed: ', e) } } \ No newline at end of file diff --git a/apps/circuit-compiler/src/app/app.tsx b/apps/circuit-compiler/src/app/app.tsx index 93c405c6c5..3482ffc2ba 100644 --- a/apps/circuit-compiler/src/app/app.tsx +++ b/apps/circuit-compiler/src/app/app.tsx @@ -21,7 +21,7 @@ function App() { useEffect(() => { const plugin = new CircomPluginClient() - plugin.internalEvents.on('activated', () => { + plugin.internalEvents.on('circom_activated', () => { // @ts-ignore plugin.on('locale', 'localeChanged', (locale: any) => { setLocale(locale) @@ -40,6 +40,13 @@ function App() { }) setPlugin(plugin) }) + plugin.internalEvents.on('circuit_compiling', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'compiling' })) + plugin.internalEvents.on('circuit_done', (signalInputs) => { + signalInputs = (signalInputs || []).filter(input => input) + dispatch({ type: 'SET_SIGNAL_INPUTS', payload: signalInputs }) + dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' }) + }) + plugin.internalEvents.on('circuit_errored', (err) => dispatch({ type: 'SET_COMPILER_STATUS', payload: err.message })) }, []) useEffect(() => { @@ -48,7 +55,6 @@ function App() { if (appState.autoCompile) await compileCircuit(plugin, appState, dispatch) })() setIsContentChanged(false) - setSignalInput() } }, [appState.autoCompile, isContentChanged]) @@ -58,6 +64,14 @@ function App() { } }, [plugin]) + useEffect(() => { + if (appState.filePath) { + (async () => { + if (appState.autoCompile) await compileCircuit(plugin, appState, dispatch) + })() + } + }, [appState.filePath]) + const setCurrentLocale = async () => { // @ts-ignore const currentLocale = await plugin.call('locale', 'currentLocale') @@ -65,13 +79,6 @@ function App() { setLocale(currentLocale) } - const setSignalInput = () => { - const signalMatcher = /([a-z$_][a-z0-9$_]*)(\.[a-z$_][a-z0-9$_]*)*(\[\d+\])?/g - const signals = content.match(signalMatcher) - - console.log('signals: ', signals) - } - const value = { appState, dispatch, diff --git a/apps/circuit-compiler/src/app/components/container.tsx b/apps/circuit-compiler/src/app/components/container.tsx index 5eb1d690a6..d49bf14ab7 100644 --- a/apps/circuit-compiler/src/app/components/container.tsx +++ b/apps/circuit-compiler/src/app/components/container.tsx @@ -35,9 +35,11 @@ export function Container () { - - - + 0}> + + + + diff --git a/apps/circuit-compiler/src/app/components/witness.tsx b/apps/circuit-compiler/src/app/components/witness.tsx index 3b87fc5562..d4f3654176 100644 --- a/apps/circuit-compiler/src/app/components/witness.tsx +++ b/apps/circuit-compiler/src/app/components/witness.tsx @@ -1,25 +1,34 @@ -import { CustomTooltip } from "@remix-ui/helper"; +import { RenderIf, RenderIfNot } from "@remix-ui/helper"; import { FormattedMessage } from "react-intl"; +import { CompilerStatus } from "../types"; -export function WitnessSection () { +export function WitnessSection ({ signalInputs, status }: {signalInputs: string[], status: CompilerStatus}) { return (
-
- - {'To choose the prime number to use to generate the circuit. Receives the name of the curve (bn128, bls12381, goldilocks) [default: bn128]'}} - > -
- -
-
-
+ 0}> + <> + { + signalInputs.map((input, index) => ( +
+ + +
+ )) + } + + +
) diff --git a/apps/circuit-compiler/src/app/reducers/state.ts b/apps/circuit-compiler/src/app/reducers/state.ts index 3d15f79446..d331c41471 100644 --- a/apps/circuit-compiler/src/app/reducers/state.ts +++ b/apps/circuit-compiler/src/app/reducers/state.ts @@ -7,7 +7,8 @@ export const appInitialState: AppState = { filePath: "", status: "idle", primeValue: "bn128", - autoCompile: false + autoCompile: false, + signalInputs: [] } export const appReducer = (state = appInitialState, action: Actions): AppState => { @@ -43,6 +44,12 @@ export const appReducer = (state = appInitialState, action: Actions): AppState = autoCompile: action.payload } + case 'SET_SIGNAL_INPUTS': + return { + ...state, + signalInputs: action.payload + } + default: throw new Error() } diff --git a/apps/circuit-compiler/src/app/services/circomPluginClient.ts b/apps/circuit-compiler/src/app/services/circomPluginClient.ts index 3f051cc23f..59298beae4 100644 --- a/apps/circuit-compiler/src/app/services/circomPluginClient.ts +++ b/apps/circuit-compiler/src/app/services/circomPluginClient.ts @@ -2,8 +2,7 @@ import { PluginClient } from '@remixproject/plugin' import { createClient } from '@remixproject/plugin-webview' import EventManager from 'events' import pathModule from 'path' -// @ts-ignore -import { parse, compile, generate_witness, generate_r1cs, compiler_list } from '../../../pkg' +import { parse, compile, generate_witness, generate_r1cs, compiler_list } from 'circom_wasm' import { extractNameFromKey, extractParentFromKey } from '@remix-ui/helper' import { CompilationConfig } from '../types' @@ -13,6 +12,7 @@ export class CircomPluginClient extends PluginClient { version: "2.1.5", prime: "bn128" } + public lastCompiledCircuitPath: string = '' constructor() { super() @@ -34,7 +34,7 @@ export class CircomPluginClient extends PluginClient { } }) - this.internalEvents.emit('activated') + this.internalEvents.emit('circom_activated') } async parse(path: string, fileContent: string): Promise { @@ -107,6 +107,7 @@ export class CircomPluginClient extends PluginClient { } async compile(path: string, compilationConfig?: CompilationConfig): Promise { + this.internalEvents.emit('circuit_compiling') if (compilationConfig) { const { prime, version } = compilationConfig @@ -121,27 +122,31 @@ export class CircomPluginClient extends PluginClient { } buildFiles = await this.resolveDependencies(path, fileContent, buildFiles) - const compiledOutput = compile(path, buildFiles, { prime: this._compilationConfig.prime }) + const circuitApi = compile(path, buildFiles, { prime: this._compilationConfig.prime }) + const circuitProgram = circuitApi.program() - console.log('compiledOutput: ', compiledOutput) - console.log('compiledOutput.program: ', compiledOutput.program()) - console.log('compiledOutput.input_signals: ', compiledOutput.input_signals("Semaphore")) + if (circuitProgram.length < 1) { + const circuitErrors = circuitApi.report() - // if (compiledOutput.length < 1) { - // throw new Error("Compilation failed! See parsing errors.") - // } else { - // const fileName = extractNameFromKey(path) - // const writePath = extractParentFromKey(path) + "/.bin/" + fileName.replace('circom', 'wasm') - - // // @ts-ignore - // await this.call('fileManager', 'writeFile', writePath, new Uint8Array(compiledOutput), true) - // console.log('compilation successful!') - // } - // @ts-ignore - // const buffer = await this.call('fileManager', 'readFile', writePath, true) - // // @ts-ignore - // const dataRead = new Uint8Array(buffer) - // const witness = await generate_witness(dataRead, '{ "a": "5", "b": "77" }') + this.internalEvents.emit('circuit_errored', circuitErrors) + throw new Error(circuitErrors) + } else { + const fileName = extractNameFromKey(path) + + this.lastCompiledCircuitPath = extractParentFromKey(path) + "/.bin/" + fileName.replace('circom', 'wasm') + // @ts-ignore + await this.call('fileManager', 'writeFile', this.lastCompiledCircuitPath, circuitProgram, true) + const searchComponentName = fileContent.match(/component\s+main\s*(?:{[^{}]*})?\s*=\s*([A-Za-z_]\w*)\s*\(.*\)/) + + if (searchComponentName) { + const componentName = searchComponentName[1] + const signals = circuitApi.input_signals(componentName) + + this.internalEvents.emit('circuit_done', signals) + } else { + this.internalEvents.emit('circuit_done', []) + } + } // const witness = await generate_witness(compiledOutput, '{ "identityTrapdoor": "12656283236575022300303467601783819380815431272685589718060054649894766174337", "identityNullifier": "15178877681550417450385541477607788220584140707925739215609273992582659710290", "treePathIndices": "0", "treeSiblings": "1", "externalNullifier": "5df6e0e3480d6fbc32925076897ec6b9b935d75ae8f4d9f4858a426f8f6a4ab": "signalHash": "[85, 139, 239, 32, 221, 194, 165, 19, 20, 52, 104, 144, 41, 16, 40, 204, 171, 245, 198, 77, 94, 143, 30, 112, 105, 165, 33, 15, 62, 156, 18, 118]"}') // const ptau_final = "https://ipfs-cluster.ethdevops.io/ipfs/QmTiT4eiYz5KF7gQrDsgfCSTRv3wBPYJ4bRN1MmTRshpnW"; @@ -202,6 +207,7 @@ export class CircomPluginClient extends PluginClient { } async generateR1cs (path: string, compilationConfig?: CompilationConfig): Promise { + this.internalEvents.emit('circuit_generating') if (compilationConfig) { const { prime, version } = compilationConfig @@ -216,20 +222,35 @@ export class CircomPluginClient extends PluginClient { } buildFiles = await this.resolveDependencies(path, fileContent, buildFiles) - const r1cs = generate_r1cs(path, buildFiles, { prime: this._compilationConfig.prime }) + const r1csApi = generate_r1cs(path, buildFiles, { prime: this._compilationConfig.prime }) + const r1csProgram = r1csApi.program() + + if (r1csProgram.length < 1) { + const r1csErrors = r1csApi.report() - if (r1cs.length < 1) { - throw new Error("R1cs generation failed! See parsing errors.") + this.internalEvents.emit('circuit_errored', r1csErrors) + throw new Error(r1csErrors) } else { + this.internalEvents.emit('circuit_done') const fileName = extractNameFromKey(path) const writePath = extractParentFromKey(path) + "/.bin/" + fileName.replace('circom', 'r1cs') // @ts-ignore - await this.call('fileManager', 'writeFile', writePath, new Uint8Array(r1cs), true) - console.log('R1CS generation successful!') + await this.call('fileManager', 'writeFile', writePath, r1csProgram, true) } } + async computeWitness (input: string, wasmPath?: string): Promise { + this.internalEvents.emit('circuit_computing') + if (!wasmPath) wasmPath = this.lastCompiledCircuitPath + if (!wasmPath) throw new Error('No wasm file found') + + // @ts-ignore + const buffer: any = await this.call('fileManager', 'readFile', wasmPath, true) + const dataRead = new Uint8Array(buffer) + const witness = await generate_witness(dataRead, input) + } + async resolveDependencies(filePath: string, fileContent: string, output = {}, depPath: string = '', blackPath: string[] = []): Promise> { // extract all includes const includes = (fileContent.match(/include ['"].*['"]/g) || []).map((include) => include.replace(/include ['"]/g, '').replace(/['"]/g, '')) diff --git a/apps/circuit-compiler/src/app/types/index.ts b/apps/circuit-compiler/src/app/types/index.ts index 6165413668..277e28a67a 100644 --- a/apps/circuit-compiler/src/app/types/index.ts +++ b/apps/circuit-compiler/src/app/types/index.ts @@ -2,7 +2,7 @@ import { compiler_list } from 'circom_wasm' import {Dispatch} from 'react' import { CircomPluginClient } from '../services/circomPluginClient' -export type CompilerStatus = "compiling" | "generating" | "idle" | "errored" +export type CompilerStatus = "compiling" | "generating" | "computing" | "idle" | "errored" export interface ICircuitAppContext { appState: AppState dispatch: Dispatch, @@ -14,7 +14,8 @@ export interface ActionPayloadTypes { SET_FILE_PATH: string, SET_COMPILER_STATUS: CompilerStatus, SET_PRIME_VALUE: PrimeValue, - SET_AUTO_COMPILE: boolean + SET_AUTO_COMPILE: boolean, + SET_SIGNAL_INPUTS: string[] } export interface Action { type: T @@ -29,7 +30,8 @@ export interface AppState { filePath: string, status: CompilerStatus, primeValue: PrimeValue, - autoCompile: boolean + autoCompile: boolean, + signalInputs: string[] } export type CompilationConfig = { diff --git a/apps/circuit-compiler/src/profile.json b/apps/circuit-compiler/src/profile.json index e8395e2574..2bda2ccadb 100644 --- a/apps/circuit-compiler/src/profile.json +++ b/apps/circuit-compiler/src/profile.json @@ -9,7 +9,7 @@ "url": "", "description": "Enables circuit compilation and computing a witness for ZK proofs", "icon": "https://docs.circom.io/assets/images/favicon.png", - "location": "hiddenPanel", + "location": "sidePanel", "documentation": "", "repo": "https://github.com/ethereum/remix-project/tree/master/apps/circuit-compiler", "maintainedBy": "Remix", diff --git a/apps/remix-ide/src/app/tabs/locales/en/circuit.json b/apps/remix-ide/src/app/tabs/locales/en/circuit.json index 32dab62880..61184793f5 100644 --- a/apps/remix-ide/src/app/tabs/locales/en/circuit.json +++ b/apps/remix-ide/src/app/tabs/locales/en/circuit.json @@ -9,5 +9,7 @@ "circuit.compile": "Compile", "circuit.noFileSelected": "no file selected", "circuit.generateR1cs": "Generate R1CS", - "circuit.computeWitness": "Compute Witness" + "circuit.computeWitness": "Compute Witness", + "circuit.signalInput": "Signal Input", + "circuit.compute": "Compute" } diff --git a/apps/remix-ide/src/app/tabs/locales/es/circuit.json b/apps/remix-ide/src/app/tabs/locales/es/circuit.json index 32dab62880..61184793f5 100644 --- a/apps/remix-ide/src/app/tabs/locales/es/circuit.json +++ b/apps/remix-ide/src/app/tabs/locales/es/circuit.json @@ -9,5 +9,7 @@ "circuit.compile": "Compile", "circuit.noFileSelected": "no file selected", "circuit.generateR1cs": "Generate R1CS", - "circuit.computeWitness": "Compute Witness" + "circuit.computeWitness": "Compute Witness", + "circuit.signalInput": "Signal Input", + "circuit.compute": "Compute" } diff --git a/apps/remix-ide/src/app/tabs/locales/fr/circuit.json b/apps/remix-ide/src/app/tabs/locales/fr/circuit.json index 32dab62880..61184793f5 100644 --- a/apps/remix-ide/src/app/tabs/locales/fr/circuit.json +++ b/apps/remix-ide/src/app/tabs/locales/fr/circuit.json @@ -9,5 +9,7 @@ "circuit.compile": "Compile", "circuit.noFileSelected": "no file selected", "circuit.generateR1cs": "Generate R1CS", - "circuit.computeWitness": "Compute Witness" + "circuit.computeWitness": "Compute Witness", + "circuit.signalInput": "Signal Input", + "circuit.compute": "Compute" } diff --git a/apps/remix-ide/src/app/tabs/locales/zh/circuit.json b/apps/remix-ide/src/app/tabs/locales/zh/circuit.json index e4443c871e..73cd281a36 100644 --- a/apps/remix-ide/src/app/tabs/locales/zh/circuit.json +++ b/apps/remix-ide/src/app/tabs/locales/zh/circuit.json @@ -10,5 +10,7 @@ "circuit.compile": "编译", "circuit.noFileSelected": "未选中文件", "circuit.generateR1cs": "生成R1CS", - "circuit.computeWitness": "证人计算器" + "circuit.computeWitness": "证人计算器", + "circuit.signalInput": "输入信号", + "circuit.compute": "计算" } diff --git a/yarn.lock b/yarn.lock index 4aa35167a3..d6144d9470 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9729,7 +9729,7 @@ circom_runtime@0.1.22: "circom_wasm@https://github.com/ioedeveloper/circom_wasm.git": version "0.0.0-alpha.7" - resolved "https://github.com/ioedeveloper/circom_wasm.git#24d26dec739297a1bd3e61f74ca3b95b20f66a25" + resolved "https://github.com/ioedeveloper/circom_wasm.git#a8c53a02e97fa5e8533618a070d1b7fdb655fdc5" circular-json@^0.3.0: version "0.3.3" From f0d76b915951cf1d08cf419f87b716f42add9a5e Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Thu, 12 Oct 2023 12:16:55 +0100 Subject: [PATCH 06/26] Save witness file --- .../circuit-compiler/src/app/actions/index.ts | 26 +++++++++++++++---- apps/circuit-compiler/src/app/app.tsx | 26 +++++++++++++------ .../src/app/components/compileBtn.tsx | 6 ++--- .../src/app/components/container.tsx | 2 +- .../src/app/components/r1csBtn.tsx | 6 ++--- .../src/app/components/witness.tsx | 21 ++++++++++++--- .../src/app/services/circomPluginClient.ts | 23 ++++++++-------- yarn.lock | 2 +- 8 files changed, 76 insertions(+), 36 deletions(-) diff --git a/apps/circuit-compiler/src/app/actions/index.ts b/apps/circuit-compiler/src/app/actions/index.ts index 440d098493..55944f7bc6 100644 --- a/apps/circuit-compiler/src/app/actions/index.ts +++ b/apps/circuit-compiler/src/app/actions/index.ts @@ -1,7 +1,7 @@ -import { CircomPluginClient } from "../services/circomPluginClient" +import type { CircomPluginClient } from "../services/circomPluginClient" import { Actions, AppState } from "../types" -export const compileCircuit = async (plugin: CircomPluginClient, appState: AppState, dispatch: React.Dispatch) => { +export const compileCircuit = async (plugin: CircomPluginClient, appState: AppState) => { try { if (appState.status !== "compiling") { await plugin.compile(appState.filePath, { version: appState.version, prime: appState.primeValue }) @@ -9,12 +9,12 @@ export const compileCircuit = async (plugin: CircomPluginClient, appState: AppSt console.log('Exisiting circuit compilation in progress') } } catch (e) { + plugin.internalEvents.emit('circuit_compiling_errored', e) console.error(e) - dispatch({ type: 'SET_SIGNAL_INPUTS', payload: [] }) } } -export const generateR1cs = async (plugin: CircomPluginClient, appState: AppState, dispatch: React.Dispatch) => { +export const generateR1cs = async (plugin: CircomPluginClient, appState: AppState) => { try { if (appState.status !== "generating") { await plugin.generateR1cs(appState.filePath, { version: appState.version, prime: appState.primeValue }) @@ -22,6 +22,22 @@ export const generateR1cs = async (plugin: CircomPluginClient, appState: AppStat console.log('Exisiting r1cs generation in progress') } } catch (e) { + plugin.internalEvents.emit('circuit_generating_r1cs_errored', e) console.error('Generating R1CS failed: ', e) } -} \ No newline at end of file +} + +export const computeWitness = async (plugin: CircomPluginClient, status: string, witnessValues: Record) => { + try { + if (status !== "computing") { + const input = JSON.stringify(witnessValues) + + await plugin.computeWitness(input) + } else { + console.log('Exisiting witness computation in progress') + } + } catch (e) { + plugin.internalEvents.emit('circuit_computing_witness_errored', e) + console.error('Computing witness failed: ', e) + } +} diff --git a/apps/circuit-compiler/src/app/app.tsx b/apps/circuit-compiler/src/app/app.tsx index 3482ffc2ba..cdb36783ee 100644 --- a/apps/circuit-compiler/src/app/app.tsx +++ b/apps/circuit-compiler/src/app/app.tsx @@ -16,7 +16,6 @@ function App() { messages: null }) const [isContentChanged, setIsContentChanged] = useState(false) - const [content, setNewContent] = useState("") useEffect(() => { const plugin = new CircomPluginClient() @@ -34,25 +33,36 @@ function App() { } }) // @ts-ignore - plugin.on('editor', 'contentChanged', async (filePath, content) => { + plugin.on('editor', 'contentChanged', async () => { setIsContentChanged(true) - setNewContent(content) }) setPlugin(plugin) }) - plugin.internalEvents.on('circuit_compiling', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'compiling' })) - plugin.internalEvents.on('circuit_done', (signalInputs) => { + + // compiling events + plugin.internalEvents.on('circuit_compiling_start', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'compiling' })) + plugin.internalEvents.on('circuit_compiling_done', (signalInputs) => { signalInputs = (signalInputs || []).filter(input => input) dispatch({ type: 'SET_SIGNAL_INPUTS', payload: signalInputs }) dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' }) }) - plugin.internalEvents.on('circuit_errored', (err) => dispatch({ type: 'SET_COMPILER_STATUS', payload: err.message })) + plugin.internalEvents.on('circuit_compiling_errored', (err) => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'errored' })) + + // r1cs events + plugin.internalEvents.on('circuit_generating_r1cs_start', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'generating' })) + plugin.internalEvents.on('circuit_generating_r1cs_done', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' })) + plugin.internalEvents.on('circuit_generating_r1cs_errored', (err) => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'errored' })) + + // witness events + plugin.internalEvents.on('circuit_computing_witness_start', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'computing' })) + plugin.internalEvents.on('circuit_computing_witness_done', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' })) + plugin.internalEvents.on('circuit_computing_witness_errored', (err) => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'errored' })) }, []) useEffect(() => { if (isContentChanged) { (async () => { - if (appState.autoCompile) await compileCircuit(plugin, appState, dispatch) + if (appState.autoCompile) await compileCircuit(plugin, appState) })() setIsContentChanged(false) } @@ -67,7 +77,7 @@ function App() { useEffect(() => { if (appState.filePath) { (async () => { - if (appState.autoCompile) await compileCircuit(plugin, appState, dispatch) + if (appState.autoCompile) await compileCircuit(plugin, appState) })() } }, [appState.filePath]) diff --git a/apps/circuit-compiler/src/app/components/compileBtn.tsx b/apps/circuit-compiler/src/app/components/compileBtn.tsx index 3f131224e7..c778377cc1 100644 --- a/apps/circuit-compiler/src/app/components/compileBtn.tsx +++ b/apps/circuit-compiler/src/app/components/compileBtn.tsx @@ -5,14 +5,12 @@ import { FormattedMessage } from "react-intl"; import { compileCircuit } from "../actions"; export function CompileBtn () { - const { plugin, appState, dispatch } = useContext(CircuitAppContext) - - + const { plugin, appState } = useContext(CircuitAppContext) return (