diff --git a/README.md b/README.md index 53cd9fa..515af4c 100644 --- a/README.md +++ b/README.md @@ -64,3 +64,12 @@ $ docker-compose up -d 1. The `current.params` file is your initial challenge file. 1. copy `current.params`, `withdraw.json` and `phase1radix*` to `./server/snark_files` folder. 1. `mv withdraw.json circuit.json` + + +## In case of WASM module changes +1. go to `phase2` folder in [phase2-bn254](https://github.com/tornadocash/phase2-bn254) (ceremony branch for now) and run the following command: +1. `wasm-pack build --release --target web -- --no-default-features --features wasm` +1. it will generate wasm modules in `pkg` folder, then you need to copy it to this project +1. `cp -r pkg/* /lib/phase2 && cp pkg/phase2_bg.wasm /static/_nuxt/lib/phase2/` + +Example: `wasm-pack build --release --target web -- --no-default-features --features wasm && cp -r pkg/* ../../trusted-setup-nuxt/lib/phase2 && cp pkg/phase2_bg.wasm ../../trusted-setup-nuxt/static/_nuxt/lib/phase2/` diff --git a/lib/phase2/package.json b/lib/phase2/package.json index 009df67..6b87fdf 100644 --- a/lib/phase2/package.json +++ b/lib/phase2/package.json @@ -20,5 +20,5 @@ "module": "phase2.js", "homepage": "https://github.com/ebfull/phase2", "types": "phase2.d.ts", - "sideEffects": "false" + "sideEffects": false } \ No newline at end of file diff --git a/lib/phase2/phase2.d.ts b/lib/phase2/phase2.d.ts index 40dd600..6fd0f61 100644 --- a/lib/phase2/phase2.d.ts +++ b/lib/phase2/phase2.d.ts @@ -2,9 +2,10 @@ /* eslint-disable */ /** * @param {Uint8Array} params +* @param {Uint8Array} entropy * @returns {Uint8Array} */ -export function contribute(params: Uint8Array): Uint8Array; +export function contribute(params: Uint8Array, entropy: Uint8Array): Uint8Array; /** * If `module_or_path` is {RequestInfo}, makes a request and diff --git a/lib/phase2/phase2.js b/lib/phase2/phase2.js index c0241df..ac76c91 100644 --- a/lib/phase2/phase2.js +++ b/lib/phase2/phase2.js @@ -70,17 +70,20 @@ function getArrayU8FromWasm0(ptr, len) { } /** * @param {Uint8Array} params +* @param {Uint8Array} entropy * @returns {Uint8Array} */ -export function contribute(params) { +export function contribute(params, entropy) { var ptr0 = passArray8ToWasm0(params, wasm.__wbindgen_malloc); var len0 = WASM_VECTOR_LEN; - wasm.contribute(8, ptr0, len0); + var ptr1 = passArray8ToWasm0(entropy, wasm.__wbindgen_malloc); + var len1 = WASM_VECTOR_LEN; + wasm.contribute(8, ptr0, len0, ptr1, len1); var r0 = getInt32Memory0()[8 / 4 + 0]; var r1 = getInt32Memory0()[8 / 4 + 1]; - var v1 = getArrayU8FromWasm0(r0, r1).slice(); + var v2 = getArrayU8FromWasm0(r0, r1).slice(); wasm.__wbindgen_free(r0, r1 * 1); - return v1; + return v2; } let cachedTextEncoder = new TextEncoder('utf-8'); diff --git a/lib/phase2/phase2_bg.d.ts b/lib/phase2/phase2_bg.d.ts index 65c9b40..acde345 100644 --- a/lib/phase2/phase2_bg.d.ts +++ b/lib/phase2/phase2_bg.d.ts @@ -1,7 +1,7 @@ /* tslint:disable */ /* eslint-disable */ export const memory: WebAssembly.Memory; -export function contribute(a: number, b: number, c: number): void; +export function contribute(a: number, b: number, c: number, d: number, e: number): void; export function __wbindgen_malloc(a: number): number; export function __wbindgen_free(a: number, b: number): void; export function __wbindgen_realloc(a: number, b: number, c: number): number; diff --git a/lib/phase2/phase2_bg.wasm b/lib/phase2/phase2_bg.wasm index 14f9c46..01ee364 100644 Binary files a/lib/phase2/phase2_bg.wasm and b/lib/phase2/phase2_bg.wasm differ diff --git a/pages/make-contribution.vue b/pages/make-contribution.vue index cb816b2..ac4c77c 100644 --- a/pages/make-contribution.vue +++ b/pages/make-contribution.vue @@ -60,7 +60,7 @@
{ + this.makeContribution({ userInput }) + } + }) + }, + async makeContribution({ userInput, retry = 0 } = {}) { try { + const contribute = await this.$contribute() this.isContributeBtnSnown = true this.status.msg = '' this.status.type = '' @@ -162,12 +176,22 @@ export default { this.$root.$emit('enableLoading', 'Generating random contribution') await timeout(100) // allow UI to update before freezing in wasm console.log('Source params', data) - const contribute = await this.$contribute() - const result = contribute(data) + + const encoder = new TextEncoder(userInput) + const entropyFromUser = encoder.encode(userInput) + + const entropy = new Uint8Array(userInput.length) + const entropyFromBrowser = window.crypto.getRandomValues(entropy) + // suffle the browser and user random + for (let i = 0; i < entropyFromBrowser.length; i++) { + entropy[i] = entropyFromBrowser[i] + entropyFromUser[i] + } + + console.log('entropy', entropy) + const result = contribute(data, entropy) console.log('Updated params', result) this.$root.$emit('enableLoading', 'Uploading and verifying your contribution') - console.log('this.user.name', this.userName, this.userHandle, this.userCompany) const formData = new FormData() formData.append('response', new Blob([result], { type: 'application/octet-stream' })) if (this.contributionType !== 'anonymous') { @@ -202,7 +226,7 @@ export default { this.isContributeBtnSnown = false } } catch (e) { - console.error(e.message) + console.error(e) this.status.msg = e.message this.status.type = 'is-danger' this.isContributeBtnSnown = false diff --git a/static/_nuxt/lib/phase2/phase2_bg.wasm b/static/_nuxt/lib/phase2/phase2_bg.wasm index 14f9c46..01ee364 100644 Binary files a/static/_nuxt/lib/phase2/phase2_bg.wasm and b/static/_nuxt/lib/phase2/phase2_bg.wasm differ