Skip to content

Commit 0cdf1d6

Browse files
authored
Some API Optimizations (#23)
* Switch order of precompute and trustedSetup init arguments for comfortability * Set precompute to 0 (faster initialization)
1 parent cdb6a3c commit 0cdf1d6

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The `loadKZG()` function returns an object that implements the KZG interface wit
3535

3636
#### `loadTrustedSetup(trustedSetup?, precompute?)`
3737
```ts
38-
loadTrustedSetup(trustedSetup: TrustedSetup = mainnetTrustedSetup, precompute: number = 8): number
38+
loadTrustedSetup(trustedSetup: TrustedSetup = mainnetTrustedSetup, precompute: number = 0): number
3939
```
4040
Loads a trusted setup for KZG operations. Returns 0 on success, non-zero on failure.
4141

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const BYTES_PER_CELL = 2048
2929
*
3030
* @returns object - the KZG methods required for all 4844 related operations
3131
*/
32-
export const loadKZG = async (trustedSetup: TrustedSetup = mainnetTrustedSetup, precompute: number = 8) => {
32+
export const loadKZG = async (precompute: number = 0, trustedSetup: TrustedSetup = mainnetTrustedSetup) => {
3333
// In Node.js environment, preload the WASM binary to avoid path resolution issues
3434
let wasmBinary = await loadWasmModule();
3535

@@ -55,7 +55,7 @@ export const loadKZG = async (trustedSetup: TrustedSetup = mainnetTrustedSetup,
5555
* @param trustedSetup - an optional trusted setup parameter provided by the user
5656
* @returns 0 if loaded successfully or non zero otherwise
5757
*/
58-
const loadTrustedSetup = (trustedSetup: TrustedSetup = mainnetTrustedSetup, precompute: number = 8) => {
58+
const loadTrustedSetup = (precompute: number = 0, trustedSetup: TrustedSetup = mainnetTrustedSetup) => {
5959
if(trustedSetup.g1_monomial.length != 48 * 4096 * 2) {
6060
throw new Error(`trusted setup g1_monomial must be 48 * 4096 bytes long, not ${trustedSetup.g1_monomial.length}`)
6161
}
@@ -293,7 +293,7 @@ export const loadKZG = async (trustedSetup: TrustedSetup = mainnetTrustedSetup,
293293
return res === 'true'
294294
}
295295

296-
const loadResult = loadTrustedSetup(trustedSetup, precompute);
296+
const loadResult = loadTrustedSetup(precompute, trustedSetup);
297297
if (loadResult !== 0) {
298298
throw new Error(`Failed to load trusted setup, error code: ${loadResult}`);
299299
}

test/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const BYTES_PER_CELL = 2048
1010
const BYTES_PER_G1 = 48
1111

1212
describe('kzg initialization', () => {
13-
let kzg: any
13+
let kzg: Awaited<ReturnType<typeof loadKZG>>
1414
beforeAll(async () => {
1515
kzg = await loadKZG()
1616
})
@@ -22,7 +22,7 @@ describe('kzg initialization', () => {
2222

2323
it('should throw when invalid trusted setup is provided', () => {
2424
assert.throws(() => {
25-
kzg.loadTrustedSetup({ g1_monomial: 'x12', g1_lagrange: 'bad coordinates', g2_monomial: 'x12'})
25+
kzg.loadTrustedSetup(0, { g1_monomial: 'x12', g1_lagrange: 'bad coordinates', g2_monomial: 'x12'})
2626
})
2727
})
2828
})

0 commit comments

Comments
 (0)