From d137366e906ee81bf56c720ffe25ca82891543de Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Sat, 28 Oct 2023 17:51:15 +0000 Subject: [PATCH 01/29] Initial work at replacing wasm hashing with pure TS. --- .../pedersen_commitment/pedersen.test.cpp | 24 +- .../src/client/private_execution.test.ts | 4 +- .../circuits.js/src/abis/abis.test.ts | 1 + yarn-project/circuits.js/src/abis/abis.ts | 303 +++++++++++++----- .../barretenberg/crypto/pedersen/pedersen.ts | 34 +- yarn-project/foundation/src/crypto/index.ts | 1 + .../src/crypto/pedersen/index.test.ts | 8 + .../foundation/src/crypto/pedersen/index.ts | 269 +++++++++++++++- yarn-project/merkle-tree/src/pedersen.ts | 9 +- .../src/sparse_tree/sparse_tree.test.ts | 8 +- .../test/standard_indexed_tree.test.ts | 8 +- .../src/standard_tree/standard_tree.test.ts | 8 +- .../src/test/standard_based_test_suite.ts | 8 +- .../merkle-tree/src/test/test_suite.ts | 8 +- .../src/noir_test_gen.test.ts | 4 +- .../pxe/src/synchronizer/synchronizer.ts | 5 +- .../src/block_builder/solo_block_builder.ts | 2 +- .../sequencer-client/src/sequencer/utils.ts | 5 +- .../server_world_state_synchronizer.test.ts | 8 +- .../src/world-state-db/merkle_trees.ts | 9 +- 20 files changed, 549 insertions(+), 177 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/pedersen.test.cpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/pedersen.test.cpp index 84c5fc2e68fd..09015d346b91 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/pedersen.test.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/pedersen.test.cpp @@ -16,4 +16,26 @@ TEST(Pedersen, Commitment) EXPECT_EQ(r, expected); } -} // namespace crypto \ No newline at end of file +TEST(Pedersen, CommitmentWithZero) +{ + auto x = pedersen_commitment::Fq::zero(); + auto y = pedersen_commitment::Fq::one(); + auto r = pedersen_commitment::commit_native({ x, y }); + auto expected = + grumpkin::g1::affine_element(fr(uint256_t("054aa86a73cb8a34525e5bbed6e43ba1198e860f5f3950268f71df4591bde402")), + fr(uint256_t("209dcfbf2cfb57f9f6046f44d71ac6faf87254afc7407c04eb621a6287cac126"))); + EXPECT_EQ(r, expected); +} + +// Useful for pasting into ts version of pedersen. +TEST(Pedersen, GeneratorPrinter) +{ + GTEST_SKIP() << "Skipping generator-for-ts printer."; + pedersen_commitment::GeneratorContext ctx; + auto generators = ctx.generators->get_default_generators()->get(128); + for (auto g : generators) { + info("[", g.x, "n, ", g.y, "n],"); + } +} + +}; // namespace crypto \ No newline at end of file diff --git a/yarn-project/acir-simulator/src/client/private_execution.test.ts b/yarn-project/acir-simulator/src/client/private_execution.test.ts index df61888a4e60..5dcd61793685 100644 --- a/yarn-project/acir-simulator/src/client/private_execution.test.ts +++ b/yarn-project/acir-simulator/src/client/private_execution.test.ts @@ -59,7 +59,7 @@ jest.setTimeout(60_000); const createMemDown = () => (memdown as any)() as MemDown; describe('Private Execution test suite', () => { - let circuitsWasm: CircuitsWasm; + let circuitsWasm: any; let oracle: MockProxy; let acirSimulator: AcirSimulator; @@ -130,7 +130,7 @@ describe('Private Execution test suite', () => { } if (!trees[name]) { const db = levelup(createMemDown()); - const pedersen = new Pedersen(circuitsWasm); + const pedersen = new Pedersen(); trees[name] = await newTree(StandardTree, db, pedersen, name, treeHeights[name]); } await trees[name].appendLeaves(leaves.map(l => l.toBuffer())); diff --git a/yarn-project/circuits.js/src/abis/abis.test.ts b/yarn-project/circuits.js/src/abis/abis.test.ts index b630b7b50472..5c6179c4e936 100644 --- a/yarn-project/circuits.js/src/abis/abis.test.ts +++ b/yarn-project/circuits.js/src/abis/abis.test.ts @@ -111,6 +111,7 @@ describe('abis wasm bindings', () => { }); it('hashes function args', async () => { + // const args = Array.from({ length: 8 }).map((_, i) => new Fr(i)); const args = times(8, i => new Fr(i)); const res = await computeVarArgsHash(wasm, args); expect(res).toMatchSnapshot(); diff --git a/yarn-project/circuits.js/src/abis/abis.ts b/yarn-project/circuits.js/src/abis/abis.ts index f1dfc6d3dc8f..e6c1ce6aaaf4 100644 --- a/yarn-project/circuits.js/src/abis/abis.ts +++ b/yarn-project/circuits.js/src/abis/abis.ts @@ -1,37 +1,29 @@ import { padArrayEnd } from '@aztec/foundation/collection'; +import { keccak, pedersenHashWithHashIndex } from '@aztec/foundation/crypto'; +import { numToUInt32BE } from '@aztec/foundation/serialize'; import { IWasmModule } from '@aztec/foundation/wasm'; import { Buffer } from 'buffer'; import chunk from 'lodash.chunk'; -import { - abisComputeBlockHash, - abisComputeBlockHashWithGlobals, - abisComputeCommitmentNonce, - abisComputeCompleteAddress, - abisComputeGlobalsHash, - abisComputePublicDataTreeIndex, - abisComputePublicDataTreeValue, - abisComputeUniqueCommitment, - abisSiloCommitment, - abisSiloNullifier, -} from '../cbind/circuits.gen.js'; import { AztecAddress, CompleteAddress, + ContractDeploymentData, FUNCTION_SELECTOR_NUM_BYTES, Fr, FunctionData, FunctionLeafPreimage, + GeneratorIndex, GlobalVariables, NewContractData, PrivateCallStackItem, PublicCallStackItem, PublicKey, + TxContext, TxRequest, - Vector, } from '../index.js'; -import { serializeBufferArrayToVector } from '../utils/serialize.js'; +import { boolToBuffer, serializeBufferArrayToVector } from '../utils/serialize.js'; /** * Synchronously calls a wasm function. @@ -41,7 +33,7 @@ import { serializeBufferArrayToVector } from '../utils/serialize.js'; * @param expectedOutputLength - The expected length of the output buffer. * @returns The output buffer. */ -export function wasmSyncCall( +function wasmSyncCall( wasm: IWasmModule, fnName: string, input: @@ -73,28 +65,28 @@ export function wasmSyncCall( * @param expectedOutputLength - The expected length of the output buffer. * @returns The output buffer. */ -export function inputBuffersToOutputBuffer( - wasm: IWasmModule, - fnName: string, - inputBuffers: Buffer[], - expectedOutputLength: number, -) { - const offsets: number[] = []; - const totalLength = inputBuffers.reduce((total, cur) => { - offsets.push(total); - return total + cur.length; - }, 0); - - const outputBuf = wasm.call('bbmalloc', expectedOutputLength); - const inputBuf = wasm.call('bbmalloc', totalLength); - wasm.writeMemory(inputBuf, Buffer.concat(inputBuffers)); - const args = offsets.map(offset => inputBuf + offset); - wasm.call(fnName, ...args, outputBuf); - const output = Buffer.from(wasm.getMemorySlice(outputBuf, outputBuf + expectedOutputLength)); - wasm.call('bbfree', inputBuf); - wasm.call('bbfree', outputBuf); - return output; -} +// function inputBuffersToOutputBuffer( +// wasm: IWasmModule, +// fnName: string, +// inputBuffers: Buffer[], +// expectedOutputLength: number, +// ) { +// const offsets: number[] = []; +// const totalLength = inputBuffers.reduce((total, cur) => { +// offsets.push(total); +// return total + cur.length; +// }, 0); + +// const outputBuf = wasm.call('bbmalloc', expectedOutputLength); +// const inputBuf = wasm.call('bbmalloc', totalLength); +// wasm.writeMemory(inputBuf, Buffer.concat(inputBuffers)); +// const args = offsets.map(offset => inputBuf + offset); +// wasm.call(fnName, ...args, outputBuf); +// const output = Buffer.from(wasm.getMemorySlice(outputBuf, outputBuf + expectedOutputLength)); +// wasm.call('bbfree', inputBuf); +// wasm.call('bbfree', outputBuf); +// return output; +// } /** * Computes a hash of a transaction request. @@ -103,7 +95,7 @@ export function inputBuffersToOutputBuffer( * @returns The hash of the transaction request. */ export function hashTxRequest(wasm: IWasmModule, txRequest: TxRequest): Buffer { - return wasmSyncCall(wasm, 'abis__hash_tx_request', txRequest, 32); + return computeTxHash(wasm, txRequest).toBuffer(); } /** @@ -113,14 +105,7 @@ export function hashTxRequest(wasm: IWasmModule, txRequest: TxRequest): Buffer { * @returns The function selector. */ export function computeFunctionSelector(wasm: IWasmModule, funcSig: string): Buffer { - return wasmSyncCall( - wasm, - 'abis__compute_function_selector', - // Important - explicit C-string compatibility with a null terminator! - // In the future we want to move away from this fiddly C-string processing. - Buffer.from(funcSig + '\0'), - FUNCTION_SELECTOR_NUM_BYTES, - ); + return keccak(Buffer.from(funcSig)).subarray(0, FUNCTION_SELECTOR_NUM_BYTES); } /** @@ -140,7 +125,18 @@ export function hashVK(wasm: IWasmModule, vkBuf: Buffer) { * @returns The function leaf. */ export function computeFunctionLeaf(wasm: IWasmModule, fnLeaf: FunctionLeafPreimage): Fr { - return Fr.fromBuffer(wasmSyncCall(wasm, 'abis__compute_function_leaf', fnLeaf, 32)); + return Fr.fromBuffer( + pedersenHashWithHashIndex( + [ + fnLeaf.functionSelector.toBuffer(), + boolToBuffer(fnLeaf.isInternal), + boolToBuffer(fnLeaf.isPrivate), + fnLeaf.vkHash.toBuffer(), + fnLeaf.acirHash.toBuffer(), + ], + GeneratorIndex.FUNCTION_LEAF, + ), + ); } /** @@ -169,13 +165,12 @@ export function hashConstructor( argsHash: Fr, constructorVKHash: Buffer, ): Fr { - const result = inputBuffersToOutputBuffer( - wasm, - 'abis__hash_constructor', - [functionData.toBuffer(), argsHash.toBuffer(), constructorVKHash], - 32, + return Fr.fromBuffer( + pedersenHashWithHashIndex( + [computeFunctionDataHash(functionData).toBuffer(), argsHash.toBuffer(), constructorVKHash], + GeneratorIndex.CONSTRUCTOR, + ), ); - return Fr.fromBuffer(result); } /** @@ -194,7 +189,30 @@ export function computeCompleteAddress( fnTreeRoot: Fr, constructorHash: Fr, ): CompleteAddress { - return abisComputeCompleteAddress(wasm, deployerPubKey, contractAddrSalt, fnTreeRoot, constructorHash); + const partialAddress = computePartialAddress(contractAddrSalt, fnTreeRoot, constructorHash); + return new CompleteAddress( + computeContractAddressFromPartial(wasm, deployerPubKey, partialAddress), + deployerPubKey, + partialAddress, + ); +} + +/** + * + */ +function computePartialAddress(contractAddrSalt: Fr, fnTreeRoot: Fr, constructorHash: Fr) { + return Fr.fromBuffer( + pedersenHashWithHashIndex( + [ + Fr.ZERO.toBuffer(), + Fr.ZERO.toBuffer(), + contractAddrSalt.toBuffer(), + fnTreeRoot.toBuffer(), + constructorHash.toBuffer(), + ], + GeneratorIndex.PARTIAL_ADDRESS, + ), + ); } /** @@ -210,11 +228,9 @@ export function computeContractAddressFromPartial( pubKey: PublicKey, partialAddress: Fr, ): AztecAddress { - const result = inputBuffersToOutputBuffer( - wasm, - 'abis__compute_contract_address_from_partial', - [pubKey.toBuffer(), partialAddress.toBuffer()], - 32, + const result = pedersenHashWithHashIndex( + [pubKey.x.toBuffer(), pubKey.y.toBuffer(), partialAddress.toBuffer()], + GeneratorIndex.CONTRACT_ADDRESS, ); return new AztecAddress(result); } @@ -227,7 +243,12 @@ export function computeContractAddressFromPartial( * @returns A commitment nonce. */ export function computeCommitmentNonce(wasm: IWasmModule, nullifierZero: Fr, commitmentIndex: number): Fr { - return abisComputeCommitmentNonce(wasm, nullifierZero, new Fr(commitmentIndex)); + return Fr.fromBuffer( + pedersenHashWithHashIndex( + [nullifierZero.toBuffer(), numToUInt32BE(commitmentIndex, 32)], + GeneratorIndex.COMMITMENT_NONCE, + ), + ); } /** @@ -239,7 +260,9 @@ export function computeCommitmentNonce(wasm: IWasmModule, nullifierZero: Fr, com * @returns A siloed commitment. */ export function siloCommitment(wasm: IWasmModule, contract: AztecAddress, innerCommitment: Fr): Fr { - return abisSiloCommitment(wasm, contract, innerCommitment); + return Fr.fromBuffer( + pedersenHashWithHashIndex([contract.toBuffer(), innerCommitment.toBuffer()], GeneratorIndex.SILOED_COMMITMENT), + ); } /** @@ -250,7 +273,9 @@ export function siloCommitment(wasm: IWasmModule, contract: AztecAddress, innerC * @returns A unique commitment. */ export function computeUniqueCommitment(wasm: IWasmModule, nonce: Fr, siloedCommitment: Fr): Fr { - return abisComputeUniqueCommitment(wasm, nonce, siloedCommitment); + return Fr.fromBuffer( + pedersenHashWithHashIndex([nonce.toBuffer(), siloedCommitment.toBuffer()], GeneratorIndex.UNIQUE_COMMITMENT), + ); } /** @@ -262,7 +287,9 @@ export function computeUniqueCommitment(wasm: IWasmModule, nonce: Fr, siloedComm * @returns A siloed nullifier. */ export function siloNullifier(wasm: IWasmModule, contract: AztecAddress, innerNullifier: Fr): Fr { - return abisSiloNullifier(wasm, contract, innerNullifier); + return Fr.fromBuffer( + pedersenHashWithHashIndex([contract.toBuffer(), innerNullifier.toBuffer()], GeneratorIndex.OUTER_NULLIFIER), + ); } /** @@ -285,9 +312,9 @@ export function computeBlockHashWithGlobals( l1ToL2DataTreeRoot: Fr, publicDataTreeRoot: Fr, ): Fr { - return abisComputeBlockHashWithGlobals( + return computeBlockHash( wasm, - globals, + computeGlobalsHash(globals), noteHashTreeRoot, nullifierTreeRoot, contractTreeRoot, @@ -316,14 +343,18 @@ export function computeBlockHash( l1ToL2DataTreeRoot: Fr, publicDataTreeRoot: Fr, ): Fr { - return abisComputeBlockHash( - wasm, - globalsHash, - noteHashTreeRoot, - nullifierTreeRoot, - contractTreeRoot, - l1ToL2DataTreeRoot, - publicDataTreeRoot, + return Fr.fromBuffer( + pedersenHashWithHashIndex( + [ + globalsHash.toBuffer(), + noteHashTreeRoot.toBuffer(), + nullifierTreeRoot.toBuffer(), + contractTreeRoot.toBuffer(), + l1ToL2DataTreeRoot.toBuffer(), + publicDataTreeRoot.toBuffer(), + ], + GeneratorIndex.BLOCK_HASH, + ), ); } @@ -333,8 +364,18 @@ export function computeBlockHash( * @param globals - The global variables to put into the block hash. * @returns The globals hash. */ -export function computeGlobalsHash(wasm: IWasmModule, globals: GlobalVariables): Fr { - return abisComputeGlobalsHash(wasm, globals); +export function computeGlobalsHash(globals: GlobalVariables): Fr { + return Fr.fromBuffer( + pedersenHashWithHashIndex( + [ + globals.chainId.toBuffer(), + globals.version.toBuffer(), + globals.blockNumber.toBuffer(), + globals.timestamp.toBuffer(), + ], + GeneratorIndex.GLOBAL_VARIABLES, + ), + ); } /** @@ -345,7 +386,7 @@ export function computeGlobalsHash(wasm: IWasmModule, globals: GlobalVariables): */ export function computePublicDataTreeValue(wasm: IWasmModule, value: Fr): Fr { - return abisComputePublicDataTreeValue(wasm, value); + return value; } /** @@ -357,7 +398,9 @@ export function computePublicDataTreeValue(wasm: IWasmModule, value: Fr): Fr { */ export function computePublicDataTreeIndex(wasm: IWasmModule, contractAddress: AztecAddress, storageSlot: Fr): Fr { - return abisComputePublicDataTreeIndex(wasm, contractAddress, storageSlot); + return Fr.fromBuffer( + pedersenHashWithHashIndex([contractAddress.toBuffer(), storageSlot.toBuffer()], GeneratorIndex.PUBLIC_LEAF_INDEX), + ); } const ARGS_HASH_CHUNK_SIZE = 32; @@ -375,7 +418,12 @@ export function computeVarArgsHash(wasm: IWasmModule, args: Fr[]): Promise { throw new Error(`Cannot hash more than ${ARGS_HASH_CHUNK_SIZE * ARGS_HASH_CHUNK_COUNT} arguments`); const wasmComputeVarArgs = (args: Fr[]) => - Fr.fromBuffer(wasmSyncCall(wasm, 'abis__compute_var_args_hash', new Vector(args), 32)); + Fr.fromBuffer( + pedersenHashWithHashIndex( + args.map(a => a.toBuffer()), + GeneratorIndex.FUNCTION_ARGS, + ), + ); let chunksHashes = chunk(args, ARGS_HASH_CHUNK_SIZE).map(c => { if (c.length < ARGS_HASH_CHUNK_SIZE) { @@ -398,8 +446,12 @@ export function computeVarArgsHash(wasm: IWasmModule, args: Fr[]): Promise { * @returns The contract leaf. */ export function computeContractLeaf(wasm: IWasmModule, cd: NewContractData): Fr { - const value = wasmSyncCall(wasm, 'abis__compute_contract_leaf', cd, 32); - return Fr.fromBuffer(value); + return Fr.fromBuffer( + pedersenHashWithHashIndex( + [cd.contractAddress.toBuffer(), cd.portalContractAddress.toBuffer(), cd.functionTreeRoot.toBuffer()], + GeneratorIndex.CONTRACT_LEAF, + ), + ); } /** @@ -409,8 +461,72 @@ export function computeContractLeaf(wasm: IWasmModule, cd: NewContractData): Fr * @returns The transaction hash. */ export function computeTxHash(wasm: IWasmModule, txRequest: TxRequest): Fr { - const value = wasmSyncCall(wasm, 'abis__compute_transaction_hash', txRequest, 32); - return Fr.fromBuffer(value); + return Fr.fromBuffer( + pedersenHashWithHashIndex( + [ + txRequest.origin.toBuffer(), + computeFunctionDataHash(txRequest.functionData).toBuffer(), + txRequest.argsHash.toBuffer(), + computeTxContextHash(txRequest.txContext).toBuffer(), + ], + GeneratorIndex.TX_REQUEST, + ), + ); +} + +/** + * + */ +function computeFunctionDataHash(functionData: FunctionData): Fr { + return Fr.fromBuffer( + pedersenHashWithHashIndex( + [ + functionData.selector.toBuffer(), + new Fr(functionData.isInternal).toBuffer(), + new Fr(functionData.isPrivate).toBuffer(), + new Fr(functionData.isConstructor).toBuffer(), + ], + GeneratorIndex.FUNCTION_DATA, + ), + ); +} + +/** + * + */ +function computeTxContextHash(txContext: TxContext): Fr { + return Fr.fromBuffer( + pedersenHashWithHashIndex( + [ + new Fr(txContext.isFeePaymentTx).toBuffer(), + new Fr(txContext.isRebatePaymentTx).toBuffer(), + new Fr(txContext.isContractDeploymentTx).toBuffer(), + computeContractDeploymentDataHash(txContext.contractDeploymentData).toBuffer(), + txContext.chainId.toBuffer(), + txContext.version.toBuffer(), + ], + GeneratorIndex.TX_CONTEXT, + ), + ); +} + +/** + * + */ +function computeContractDeploymentDataHash(data: ContractDeploymentData): Fr { + return Fr.fromBuffer( + pedersenHashWithHashIndex( + [ + data.deployerPublicKey.x.toBuffer(), + data.deployerPublicKey.y.toBuffer(), + data.constructorVkHash.toBuffer(), + data.functionTreeRoot.toBuffer(), + data.contractAddressSalt.toBuffer(), + data.portalContractAddress.toBuffer(), + ], + GeneratorIndex.CONTRACT_DEPLOYMENT_DATA, + ), + ); } /** @@ -441,6 +557,16 @@ export function computeCallStackItemHash( export function computePrivateCallStackItemHash(wasm: IWasmModule, callStackItem: PrivateCallStackItem): Fr { const value = wasmSyncCall(wasm, 'abis__compute_private_call_stack_item_hash', callStackItem, 32); return Fr.fromBuffer(value); + // return Fr.fromBuffer( + // pedersenHashWithHashIndex( + // [ + // callStackItem.contractAddress.toBuffer(), + // computeFunctionDataHash(callStackItem.functionData).toBuffer(), + // computePublicInputsHash(callStackItem.publicInputs).toBuffer(), + // ], + // GeneratorIndex.CALL_STACK_ITEM, + // ), + // ); } /** @@ -452,6 +578,16 @@ export function computePrivateCallStackItemHash(wasm: IWasmModule, callStackItem export function computePublicCallStackItemHash(wasm: IWasmModule, callStackItem: PublicCallStackItem): Fr { const value = wasmSyncCall(wasm, 'abis__compute_public_call_stack_item_hash', callStackItem, 32); return Fr.fromBuffer(value); + // return Fr.fromBuffer( + // pedersenHashWithHashIndex( + // [ + // callStackItem.contractAddress.toBuffer(), + // callStackItem.functionData.toBuffer(), + // callStackItem.publicInputs.toBuffer(), + // ], + // GeneratorIndex.CALL_STACK_ITEM, + // ), + // ); } /** @@ -460,6 +596,5 @@ export function computePublicCallStackItemHash(wasm: IWasmModule, callStackItem: * @returns */ export function computeSecretMessageHash(wasm: IWasmModule, secretMessage: Fr) { - const value = wasmSyncCall(wasm, 'abis__compute_message_secret_hash', secretMessage, 32); - return Fr.fromBuffer(value); + return Fr.fromBuffer(pedersenHashWithHashIndex([secretMessage.toBuffer()], GeneratorIndex.L1_TO_L2_MESSAGE_SECRET)); } diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts index 5ec6c0cde01c..e003ad3577a4 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts @@ -1,9 +1,8 @@ +import { pedersenHashWithHashIndex as cryptoPedersen } from '@aztec/foundation/crypto'; import { IWasmModule } from '@aztec/foundation/wasm'; import { Buffer } from 'buffer'; -import { serializeBufferArrayToVector } from '../../serialize.js'; - /** * Hashes two arrays. * @param wasm - The barretenberg module. @@ -39,34 +38,5 @@ export function pedersenHashInputs(wasm: IWasmModule, inputs: Buffer[]): Buffer * purposes. */ export function pedersenHashWithHashIndex(wasm: IWasmModule, inputs: Buffer[], hashIndex: number): Buffer { - const data = serializeBufferArrayToVector(inputs); - - // WASM gives us 1024 bytes of scratch space which we can use without - // needing to allocate/free it ourselves. This can be useful for when we need to pass in several small variables - // when calling functions on the wasm, however it's important to not overrun this scratch space as otherwise - // the written data will begin to corrupt the stack. - // - // Using this scratch space isn't particularly safe if we have multiple threads interacting with the wasm however, - // each thread could write to the same pointer address simultaneously. - const SCRATCH_SPACE_SIZE = 1024; - - // For pedersen hashing, the case of hashing two inputs is the most common. - // so ideally we want to optimize for that. This will use 64 bytes of memory and - // can thus be optimized by checking if the input buffer is smaller than the scratch space. - let inputPtr = 0; - if (inputs.length >= SCRATCH_SPACE_SIZE) { - inputPtr = wasm.call('bbmalloc', data.length); - } - wasm.writeMemory(inputPtr, data); - - // Since the output is 32 bytes, instead of allocating memory - // we can reuse the scratch space to store the result. - const outputPtr = 0; - - wasm.call('pedersen__hash_with_hash_index', inputPtr, hashIndex, outputPtr); - const hashOutput = wasm.getMemorySlice(0, 32); - - wasm.call('bbfree', inputPtr); - - return Buffer.from(hashOutput); + return cryptoPedersen(inputs, hashIndex); } diff --git a/yarn-project/foundation/src/crypto/index.ts b/yarn-project/foundation/src/crypto/index.ts index de07953e43be..98abed1dacd0 100644 --- a/yarn-project/foundation/src/crypto/index.ts +++ b/yarn-project/foundation/src/crypto/index.ts @@ -1,3 +1,4 @@ export * from './keccak/index.js'; export * from './random/index.js'; export * from './sha256/index.js'; +export * from './pedersen/index.js'; diff --git a/yarn-project/foundation/src/crypto/pedersen/index.test.ts b/yarn-project/foundation/src/crypto/pedersen/index.test.ts index 385dadfc8ec7..2aa763e8a5d8 100644 --- a/yarn-project/foundation/src/crypto/pedersen/index.test.ts +++ b/yarn-project/foundation/src/crypto/pedersen/index.test.ts @@ -10,6 +10,14 @@ describe('pedersen', () => { ]); }); + it('pedersen commit with zero', () => { + const r = pedersenCommit([toBufferBE(0n, 32), toBufferBE(1n, 32)]); + expect(r).toEqual([ + Buffer.from('054aa86a73cb8a34525e5bbed6e43ba1198e860f5f3950268f71df4591bde402', 'hex'), + Buffer.from('209dcfbf2cfb57f9f6046f44d71ac6faf87254afc7407c04eb621a6287cac126', 'hex'), + ]); + }); + it('pedersen hash', () => { const r = pedersenHashWithHashIndex([toBufferBE(1n, 32), toBufferBE(1n, 32)]); expect(r).toEqual(Buffer.from('07ebfbf4df29888c6cd6dca13d4bb9d1a923013ddbbcbdc3378ab8845463297b', 'hex')); diff --git a/yarn-project/foundation/src/crypto/pedersen/index.ts b/yarn-project/foundation/src/crypto/pedersen/index.ts index fe63fbaf7572..3756b586e51e 100644 --- a/yarn-project/foundation/src/crypto/pedersen/index.ts +++ b/yarn-project/foundation/src/crypto/pedersen/index.ts @@ -271,6 +271,262 @@ const defaultGenerators = [ 0x15298a52895eb8c9399509dc1f0ef68a90afc29084d3a0cec6956c8420819b5cn, 0x2dc0ccd80f1bbbdf364f5b912a961332d9f5db54763745b64e0d85e33faf87c7n, ], + [ + 0x132026c02d21e2ccabf1338f0d93f4223ecca5f0f2a96208561c9d5a5ef79c88n, + 0x09224bf821c64b105233fb98964f9ee0d3365f59e054c4693492ac07956d5c87n, + ], + [ + 0x2d6c6f3d040ad0c71760e8139ed3aef03c01d86e03f4ff0919f97899649d4bden, + 0x1a186b79fdcea1c8bb184097418bc68279fc5f682c48f5f21809bd2087944935n, + ], + [ + 0x1d69440baeb72617846c275fd817a4dbf9a8d39ddd38ca87b6a9e54ec6cc2adcn, + 0x239c44e43c9a91c9d126e745b949bf87844de4f2775aad804f81b8dcd3c232c7n, + ], + [ + 0x1e80e18c68865cf7bfcc6964613ba1aa1ae749a2d6154288d9572f022b2a4dd5n, + 0x1fa00a74773c3214ed7dfd125c82192d4c24ce557f720c98827aeec194dc9a30n, + ], + [ + 0x01b1362ee72c3e3ef5d63f67b54a6c5f547db48126b640fc8356e4cc19382dd3n, + 0x13e340c7dea9488aa6f9fe7443d7d1aa4b937800dd213c8bb4b301ba4a1a583cn, + ], + [ + 0x21f121f9754a315b922f8464a6cbe5a9fe191f30cbd2218cc4997c3d028fa52dn, + 0x2b8e094f90ea155bd675e389c69c3b021095801905efcfbcfeced8d7e25d6e96n, + ], + [ + 0x0d03c9e026afecdaf0f1b68679faf85830f2e16edf65c80c04b032441935e7b1n, + 0x18a285be0228b819cdd475d2f08192c02a998c85802b10d0ab3256fe367d9cf3n, + ], + [ + 0x12db390e5305fd19780de901727bb248778b6077f75ee6f8ae9c2b8629a8c037n, + 0x16952c652e2719fd93571b55357e6533410e2cb115cb970676c5d08a39d1be87n, + ], + [ + 0x04598dbf51d48775d7acafd239192aa850b72785472238e79f65a89292ac238bn, + 0x06872dca2aac431fbcb2fc3196b516bb791afb6136cc457b3aeeb85d1b02e4ecn, + ], + [ + 0x015ae13d6981f433340a44f9d33ebfda3b7108fbed96fabbbdd96e95b9f2cf23n, + 0x269b90e34244790294b66b9699510444a01ef16661fa80a2a41d368c6371af4bn, + ], + [ + 0x0a3d1c57e4d12a2041a41cc6483b63d8616af9b11a272535e3c88a4bb0f293a7n, + 0x092cf2eec8c9c1cefcaac51028875fb2f9abc46d111c852466d479edb244d852n, + ], + [ + 0x054e837ebc7a6b5142d527fd0e0b052aca6b91dd6dc4827e0196acea8bd04af5n, + 0x294164cfdfc4ddde270ccef912a1ac370f1aced76d933f702937db9ae0f6ab13n, + ], + [ + 0x1d175a456220eaa15ac082acf8a910da24751810edad87b1d558e229064c8da4n, + 0x1c0db158fb28522527eeffec568c97f8b7bc7a3927d1ba93ffcdab8de75e7ecbn, + ], + [ + 0x254c3c07450ac82ed0479ce88ace7cc5223b7cdc07557c234620d006df28fb09n, + 0x09e22217e07537054ab2c6c3947690ec12620ab0f0e7d03b023f51160c1df68dn, + ], + [ + 0x1cf4eece13e6e8b9bfd4644614cb0df16b38f76e70b11b4e72c283bc47439ffcn, + 0x18fcd0501cc6d30faf81f21b62ab175d5b5fff6b16a80b23700c9094ee3f779an, + ], + [ + 0x2ca6acd35e2ff4527399a13876563461726f08e629bd5897dfbf9a576f4d6641n, + 0x303c6102e21ec7518cc4181436345be6af5916b8f604bb1054c02d5ee1362c6en, + ], + [ + 0x037612d11f47ede28098ea80adef547f4912031fd236c9a7e5d5cdf00ba4911fn, + 0x0d547e26bf94386d4ba5a69caa4baac73aaff2bf4abdfadaaa42b892cfa033d8n, + ], + [ + 0x2494d804f242aa8a8a7e5eaf09829b04b4c7690c810a5ab01d3fbe2dae54a1f3n, + 0x093b3e5ca5fdfdb2e58ba6649e9c13f97b79d8e7f4cf65e3255b98a14689c94an, + ], + [ + 0x020c10d95e90a551134c8ad77cfb5f11465c23efd81c7713efe22ad54c048403n, + 0x03eea8fd0ad7fc2ea2eae6a082bb199959a6a361f7e8865d251d6ff547c15207n, + ], + [ + 0x0e274ceca67b5c0ff0b8774e5c8adb780b62e3e4a1065b190c2c28da6c808f50n, + 0x21c6675fbe4ae752919ab3f92f412394c138807af9adc3a5dd81400a83db3bc5n, + ], + [ + 0x0158f7157c016635f6f878fb58e1b59f2741a2315939fea4536e056bb7f35ce7n, + 0x20b454ec327caab24f39f8eb5caf9eda33a9274a8f4bab8f03de09a3c176e7d4n, + ], + [ + 0x1fee261ad59b9bb95733b499820beb21ed40156dc89dea7f02739661eafd81a5n, + 0x003e98b3f725336c5a13aeddb2e2c1e894860365915d06733d847f3a01dced7fn, + ], + [ + 0x237e59a6bfc3ff0e1f5fada642d1d1a5c349502bed14f64a6c5b03caf3975008n, + 0x2362bf67d5eff33ec19af5ef915557363bd3aa313f3610bd6b1a93cf6bd8b045n, + ], + [ + 0x0204a6de6d1e5243dabb6485d5eb0231aa1487f417f7677fb56f398269b07fefn, + 0x01b9bbb78a97b65bd9854d56e5bd50be8ca60f18b73f012ef28775ef3fc0901bn, + ], + [ + 0x18ad002f659998c9bd8543361f97a2a454e5b87aa62893406298f3e37f2720ben, + 0x227bd053f0ba47f463cee2caa96c4d00516f579a1646ec4a2a70dc1700b06a50n, + ], + [ + 0x03a74f956daea99179061720902ed0f3206c92f215fe1dc2b1a10545803a99e9n, + 0x2a279b91188c2bd770f5b23f0cc724ec9eab26971db684d4d8a1623e150d0e4cn, + ], + [ + 0x26b3364b6285c48a552b5f1a977d9be8728a8493855bf5acc49d5815af84dd2cn, + 0x1898136f0513c863a49ba1b27f7de7452f004ebe7409dfae1f28966f918e6ba4n, + ], + [ + 0x2ead9bee2969459504a0fa26e953a7caafe76dee6da60ca921e9f78743378589n, + 0x0934d50a9d9007be2e47f077044775b50d33438443853dc1e81ba011816faccen, + ], + [ + 0x03b638cfae5057787fc620d2a8fa257b7126603402dade0789093853eca1b6a1n, + 0x1e57da2d7d7c7087e58b74ae04e3be194424a64e21ee94feb20859dc1f65438bn, + ], + [ + 0x1253e8cce9c54cc1f0c2f38eb583f48f7421b516ff629c9764bc187f768cb0d3n, + 0x1164460615286ea5972631b0e2d96f68cdbf17c327cd1a0399666e34950375a3n, + ], + [ + 0x0de7b3c645363ac23ff2c8af302e995251419b52ea1936cf58805b589485ed08n, + 0x29ac530d28441b612678ff86c9f48cbee512260e21aacb7ae1a6abc05d0df10fn, + ], + [ + 0x11ee0a33439f8e1da5fbaec6ad6368a2c1ecd2590ebe06bb0269a2c28bd389a5n, + 0x0d37b9e16c881409be41d42601fdaecfc7b67bca0f088eb0bef1c4e4c428a1f1n, + ], + [ + 0x00ef4d130e14eb610f533b395d18db4708b4154a689cd4acddac1f1b43ed6854n, + 0x2c485355a6a340b718e1a20206ec5c55da5dacc9045d3454b2947b759a1401ban, + ], + [ + 0x0b2500eddb982dc3ef2728e010260a5e33aa06e6960ac8d3926e3e4b441c978an, + 0x023919ab917efd33a4e07c3da64b5c0af384c7487e23333c43c4b62a315014cbn, + ], + [ + 0x2e9eb27d5d8f60d282cf0866e4f0fb92d045388f1d227852f85c1518dddc503an, + 0x1f0edc2cc1602d4f66b658f676446a7ebd3bab1a08cfe60184390600c2b0044dn, + ], + [ + 0x05c545ab45ef4d781e551674ce7027668b384667c7e3e04be02a921410223713n, + 0x0e8988769b7f561fd70e9a761c198ab9d5807fbe6ecd327241a8f10815ac4d76n, + ], + [ + 0x252896bd06ea09d5260c6053b96a3c9f0fe2bf520debabc1422b298e1b823ff0n, + 0x0beba0fe2d2ed0e028356ae129ba2a444a871a7aad25d5e90fc022b963e0c5e3n, + ], + [ + 0x17c2b8543fe3ba1042342557072eb30e941f8b93c879512e590a761454458694n, + 0x2de5011cc9b603ba43cfcc082671de63da3de9b9f0021879e7f482058f9fae0fn, + ], + [ + 0x0792855505a783cb49f954bccca6120e8990a7092b4ab0bd08168203932c7bacn, + 0x09e95a4c731b378b80991239ff87b90ba00b9439c287dbf01aaac56f05aa550dn, + ], + [ + 0x0d4beeb972497603c3a1d7d7ad79c45615f12844a530580ca2de18ef8fa1b1efn, + 0x004998039050599d55e744c51f8846dbc7db25a8318abcaf217ae68bff075d77n, + ], + [ + 0x12c6d0a3726a805bc04506282ce0218ce5de5386b1eb4aaa893722fe80983688n, + 0x2394def51425f2cee78f4ac1f0c04e25b60d1fdc9e84bacad67500f7ebcfca34n, + ], + [ + 0x1a19096c5c3522d45e2827449adef54d91287ede96b3d39818da08a0b93e9dc3n, + 0x27a0dde36f91156a87d746a58477553ec138d108fb471f157175e22a75a495dbn, + ], + [ + 0x0b7748b109ba5798a8d2803be7fd015f2ca5af9eaad8ddddde16d50a07a7bc10n, + 0x12214803947f2969d86455b1a47213f04a9309620d9692ec91114237acb84eebn, + ], + [ + 0x0c02dbea3ecb6bacc7390d53b6fe23feb49a58c571d95d01fabac5a42489a7can, + 0x0d73b846a5cf707f3e5abf9ba2b4f5602a55b5fbad7fbd7bd9b9ab48977c1005n, + ], + [ + 0x169623c619bc3ac95ec3315d5e01afecebafb1931826551b86c007070001fe90n, + 0x00cb91b18d7097d4fa2d7600ae1bf31a3b4df9479e39f1bf23f231773258ea3cn, + ], + [ + 0x0fd5b9f9d183b6da8ba0f99503e851450b3efb33c6a7807a6239e0707b5af271n, + 0x2a4153eb0395955d7d7ee71519d1d600bc32dd39b6283224fbc92d23b860eb54n, + ], + [ + 0x1209e1604a9b10afde568fcfe0ea9f1e09cdf13fe17747abeff0a1454dcf947bn, + 0x0e1d63b8ab7b9a4a7ef8d3d17207dcbbc22e9c21da661ddfdc1ac961e0032b57n, + ], + [ + 0x2982c7c825f0e86293b7a0c9eefea7f5383e222a054ffa4c5d4e5908c543c2a6n, + 0x151b990dec385eab48210cd7766d2de58eba95ff76faeee4eb64e6f3dbd3c139n, + ], + [ + 0x124faaed649b6df79325991151fb88952c9acfd57a6b3cb20b18f2fe63529818n, + 0x229dfd4712f46fe904c28adccd1165786e96baaa2c74a0a7744dbb4ab4300d41n, + ], + [ + 0x0963070c9042bbbbe66468d9e75a719123b52b76ee9797f4b039b5de1b5c9651n, + 0x06aa3729a947ec02394d82a46a0c2c2f8e2013e15f46cc97b96944937da731d0n, + ], + [ + 0x279040e3e8f1e0effaf0450099574e134c3eef819f04cadff27851de962da0d3n, + 0x1ee7f53a1b21c4fbd2ef56895bc274e520140858ba51eff6968eae9d0a03a2f8n, + ], + [ + 0x0502d68753a132e8b268e02362166d6c0e43494aef2a5173eff138aadfe05ad0n, + 0x21629dc5334c80a75f79a4b75169c40bb6eb665796a8c4d1024231cbc4604f1en, + ], + [ + 0x13edf560ae7a1c78296f4609233337cd8fbb009b22d89a27d2e5c94983095fe9n, + 0x039c043f9ac7c68faf473565cdcb51785597c90d8ba14dd8e577bf14d70c53e5n, + ], + [ + 0x075a3019dc700efd12e8b91be0029407d59c3dfeeeced4d8f8d35fed14900d79n, + 0x073d003f8998a46ba32780d2e50c2a287b6902ecb2b82672a817980666c406c1n, + ], + [ + 0x1e8509ab9d961e5dea389e1498be69790390a5f77c7dc68cc55858207ece11c5n, + 0x19979a1f1a22dc051a45427d70f66fc27c064fd451b64b6b609d74f0a6439b2cn, + ], + [ + 0x0dc528103070ee030c96bdfe9004693f52a22042abad186aba5616918c701f56n, + 0x05f194973a699889fecfedf291c50be0526c35c22faba00aec84b967e1a0f278n, + ], + [ + 0x1f795886933d543108a9cb86291f04ba487cd95fb6ff9a062d8e6ac9f267d3fan, + 0x127fe0e1209741e32c0a093bada5517cbab952de68241df774b6ddeabc2a6397n, + ], + [ + 0x156c18df6da11a7f9657751e43b50abea544017d347f27406cf4751e51a81e42n, + 0x28e38ee1433b9eefac4b22ba5d88f1d7979d1fce9920d20213b1c01fb204f725n, + ], + [ + 0x2341ce02c131e47cec7777567cc7996ac3b6fd6255ba880ba819ae4982465becn, + 0x0913340a3a212e4e0adb678d500a70e99e24f7a8370cab3b92df8cb6ec2766f3n, + ], + [ + 0x2ee690cd26ee66b12bfe6a7d4fe3077a8c2a41ce96216a964c1a94227b0cb8f9n, + 0x1e207e2e40816da78ca89b8d98f0ada6208f014beef4efec812f629d42e5e304n, + ], + [ + 0x086d9eebd9fbb9b6394cb155b8ee9e3558857f65053abb4a04c6d956d1fdfe95n, + 0x08deaf603a5fee68ccbf892f95f787dd437283b46362a9071ee1e73ec4e03edcn, + ], + [ + 0x0f63792ebcefa16d26dbfeb58db005dced755740bd047de3fde3013575b57022n, + 0x1cbd79e5b8ac132920b495e66d47f2969df49423452a34336796d152ac7de76bn, + ], + [ + 0x05f6732fe8526a3340e547d2a19a97a5c4538a94ce607eb0909db67c8880bdedn, + 0x1e0bbf2a4e501a83460c96e919bec020187f51ce94c328b3b38b07f34dea2cb2n, + ], + [ + 0x1f1df03870f616146c84545722f1e8064bc9db8180caf35061367af95445bb3fn, + 0x077004e054257d7389065f3f11be644084b357c1b9214a9869d5b6761ccee13cn, + ], ].map(([x, y]) => new grumpkin.ProjectivePoint(x, y, 1n)); const lengthGenerator = new grumpkin.ProjectivePoint( @@ -279,17 +535,24 @@ const lengthGenerator = new grumpkin.ProjectivePoint( 1n, ); -const pointAtInfinity = lengthGenerator.subtract(lengthGenerator); +const pointAtInfinity = new grumpkin.ProjectivePoint(0n, 1n, 0n); /** * Create a pedersen commitment (point) from an array of input fields. */ function pedersenCommitInternal(input: Buffer[], generatorOffset = 0) { if (generatorOffset + input.length > defaultGenerators.length) { - throw new Error('Pedersen commit overflowed default generators.'); + throw new Error( + `Pedersen commit overflowed default generators. offset: ${generatorOffset} length: ${input.length}`, + ); } const generators = defaultGenerators.slice(generatorOffset, generatorOffset + input.length); - return generators.reduce((a, g, i) => a.add(g.multiply(toBigIntBE(input[i]))), pointAtInfinity); + return generators.reduce((a, g, i) => { + // TODO: WARNING! Merkle tree tests fail if we don't reduce modulo p as they feed in 256 bits. + // Is it right that we accept 256 bit buffers here and reduce mod p? Is the right thing to only accept fields? + const ie = toBigIntBE(input[i]) % grumpkin.CURVE.Fp.ORDER; + return ie ? a.add(g.multiply(ie)) : a; + }, pointAtInfinity); } /** diff --git a/yarn-project/merkle-tree/src/pedersen.ts b/yarn-project/merkle-tree/src/pedersen.ts index ae6c5e74e5b3..18212da85722 100644 --- a/yarn-project/merkle-tree/src/pedersen.ts +++ b/yarn-project/merkle-tree/src/pedersen.ts @@ -1,5 +1,4 @@ -import { pedersenHash, pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; -import { IWasmModule } from '@aztec/foundation/wasm'; +import { pedersenHashWithHashIndex } from '@aztec/foundation/crypto'; import { Hasher } from '@aztec/types'; /** @@ -8,14 +7,12 @@ import { Hasher } from '@aztec/types'; * purposes. */ export class Pedersen implements Hasher { - constructor(private wasm: IWasmModule) {} - /* * @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific * purposes. */ public hash(lhs: Uint8Array, rhs: Uint8Array): Buffer { - return pedersenHash(this.wasm, lhs, rhs); + return pedersenHashWithHashIndex([Buffer.from(lhs), Buffer.from(rhs)]); } /* @@ -23,6 +20,6 @@ export class Pedersen implements Hasher { * purposes. */ public hashInputs(inputs: Buffer[]): Buffer { - return pedersenHashInputs(this.wasm, inputs); + return pedersenHashWithHashIndex(inputs); } } diff --git a/yarn-project/merkle-tree/src/sparse_tree/sparse_tree.test.ts b/yarn-project/merkle-tree/src/sparse_tree/sparse_tree.test.ts index d5ed72d5e588..bd4f1e6bd0b2 100644 --- a/yarn-project/merkle-tree/src/sparse_tree/sparse_tree.test.ts +++ b/yarn-project/merkle-tree/src/sparse_tree/sparse_tree.test.ts @@ -1,6 +1,4 @@ -import { CircuitsWasm } from '@aztec/circuits.js'; import { createDebugLogger } from '@aztec/foundation/log'; -import { IWasmModule } from '@aztec/foundation/wasm'; import { Hasher, SiblingPath } from '@aztec/types'; import { randomBytes } from 'crypto'; @@ -36,12 +34,10 @@ treeTestSuite('SparseTree', createDb, createFromName); standardBasedTreeTestSuite('SparseTree', createDb); describe('SparseTreeSpecific', () => { - let wasm: IWasmModule; let pedersen: Pedersen; - beforeEach(async () => { - wasm = await CircuitsWasm.get(); - pedersen = new Pedersen(wasm); + beforeEach(() => { + pedersen = new Pedersen(); }); it('throws when index is bigger than (2^DEPTH - 1) ', async () => { diff --git a/yarn-project/merkle-tree/src/standard_indexed_tree/test/standard_indexed_tree.test.ts b/yarn-project/merkle-tree/src/standard_indexed_tree/test/standard_indexed_tree.test.ts index d2f2c187609b..2f6db0b1ac14 100644 --- a/yarn-project/merkle-tree/src/standard_indexed_tree/test/standard_indexed_tree.test.ts +++ b/yarn-project/merkle-tree/src/standard_indexed_tree/test/standard_indexed_tree.test.ts @@ -1,6 +1,4 @@ -import { CircuitsWasm } from '@aztec/circuits.js'; import { toBufferBE } from '@aztec/foundation/bigint-buffer'; -import { IWasmModule } from '@aztec/foundation/wasm'; import { Hasher, SiblingPath } from '@aztec/types'; import { default as levelup } from 'levelup'; @@ -38,12 +36,10 @@ const TEST_TREE_DEPTH = 3; treeTestSuite('StandardIndexedTree', createDb, createFromName); describe('StandardIndexedTreeSpecific', () => { - let wasm: IWasmModule; let pedersen: Pedersen; - beforeEach(async () => { - wasm = await CircuitsWasm.get(); - pedersen = new Pedersen(wasm); + beforeEach(() => { + pedersen = new Pedersen(); }); it('produces the correct roots and sibling paths', async () => { diff --git a/yarn-project/merkle-tree/src/standard_tree/standard_tree.test.ts b/yarn-project/merkle-tree/src/standard_tree/standard_tree.test.ts index 6cae5035466a..ee3191f42ffd 100644 --- a/yarn-project/merkle-tree/src/standard_tree/standard_tree.test.ts +++ b/yarn-project/merkle-tree/src/standard_tree/standard_tree.test.ts @@ -1,6 +1,4 @@ -import { CircuitsWasm } from '@aztec/circuits.js'; import { randomBytes } from '@aztec/foundation/crypto'; -import { IWasmModule } from '@aztec/foundation/wasm'; import { Hasher } from '@aztec/types'; import { default as levelup } from 'levelup'; @@ -26,12 +24,10 @@ treeTestSuite('StandardTree', createDb, createFromName); standardBasedTreeTestSuite('StandardTree', createDb); describe('StandardTree_batchAppend', () => { - let wasm: IWasmModule; let pedersen: PedersenWithCounter; - beforeAll(async () => { - wasm = await CircuitsWasm.get(); - pedersen = new PedersenWithCounter(wasm); + beforeAll(() => { + pedersen = new PedersenWithCounter(); }); afterEach(() => { diff --git a/yarn-project/merkle-tree/src/test/standard_based_test_suite.ts b/yarn-project/merkle-tree/src/test/standard_based_test_suite.ts index a5ed2f480999..3ccbd7ff6d14 100644 --- a/yarn-project/merkle-tree/src/test/standard_based_test_suite.ts +++ b/yarn-project/merkle-tree/src/test/standard_based_test_suite.ts @@ -1,5 +1,3 @@ -import { CircuitsWasm } from '@aztec/circuits.js'; -import { IWasmModule } from '@aztec/foundation/wasm'; import { Hasher, SiblingPath } from '@aztec/types'; import { randomBytes } from 'crypto'; @@ -23,13 +21,11 @@ export const standardBasedTreeTestSuite = ( ) => Promise, ) => { describe(testName, () => { - let wasm: IWasmModule; let pedersen: Pedersen; const values: Buffer[] = []; - beforeAll(async () => { - wasm = await CircuitsWasm.get(); - pedersen = new Pedersen(wasm); + beforeAll(() => { + pedersen = new Pedersen(); for (let i = 0; i < 4; ++i) { const v = Buffer.alloc(32, i + 1); diff --git a/yarn-project/merkle-tree/src/test/test_suite.ts b/yarn-project/merkle-tree/src/test/test_suite.ts index 9192e399fd11..1940f32ce913 100644 --- a/yarn-project/merkle-tree/src/test/test_suite.ts +++ b/yarn-project/merkle-tree/src/test/test_suite.ts @@ -1,5 +1,3 @@ -import { CircuitsWasm } from '@aztec/circuits.js'; -import { IWasmModule } from '@aztec/foundation/wasm'; import { Hasher, SiblingPath } from '@aztec/types'; import { default as levelup } from 'levelup'; @@ -38,7 +36,6 @@ export const treeTestSuite = ( ) => { describe(testName, () => { const values: Buffer[] = []; - let wasm: IWasmModule; let pedersen: Pedersen; beforeAll(() => { @@ -49,9 +46,8 @@ export const treeTestSuite = ( } }); - beforeEach(async () => { - wasm = await CircuitsWasm.get(); - pedersen = new Pedersen(wasm); + beforeEach(() => { + pedersen = new Pedersen(); }); it('should revert changes on rollback', async () => { diff --git a/yarn-project/noir-private-kernel/src/noir_test_gen.test.ts b/yarn-project/noir-private-kernel/src/noir_test_gen.test.ts index c1ede73ca325..9183db2dde7f 100644 --- a/yarn-project/noir-private-kernel/src/noir_test_gen.test.ts +++ b/yarn-project/noir-private-kernel/src/noir_test_gen.test.ts @@ -64,7 +64,7 @@ describe('Data generation for noir tests', () => { const tree = new StandardTree( db, - new Pedersen(wasm), + new Pedersen(), `${MerkleTreeId[MerkleTreeId.CONTRACT_TREE]}`, CONTRACT_TREE_HEIGHT, ); @@ -86,7 +86,7 @@ describe('Data generation for noir tests', () => { const noteHashTree = new StandardTree( db, - new Pedersen(wasm), + new Pedersen(), `${MerkleTreeId[MerkleTreeId.NOTE_HASH_TREE]}`, NOTE_HASH_TREE_HEIGHT, ); diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index 56a42dc377f2..421d4a623cbb 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -1,4 +1,4 @@ -import { AztecAddress, CircuitsWasm, Fr, HistoricBlockData, PublicKey } from '@aztec/circuits.js'; +import { AztecAddress, Fr, HistoricBlockData, PublicKey } from '@aztec/circuits.js'; import { computeGlobalsHash } from '@aztec/circuits.js/abis'; import { DebugLogger, createDebugLogger } from '@aztec/foundation/log'; import { InterruptibleSleep } from '@aztec/foundation/sleep'; @@ -199,8 +199,7 @@ export class Synchronizer { const { block } = latestBlock; if (block.number < this.initialSyncBlockNumber) return; - const wasm = await CircuitsWasm.get(); - const globalsHash = computeGlobalsHash(wasm, latestBlock.block.globalVariables); + const globalsHash = computeGlobalsHash(latestBlock.block.globalVariables); const blockData = new HistoricBlockData( block.endNoteHashTreeSnapshot.root, block.endNullifierTreeSnapshot.root, diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts index eabf7066040d..b7015942be54 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts @@ -313,7 +313,7 @@ export class SoloBlockBuilder implements BlockBuilder { // Update the root trees with the latest data and contract tree roots, // and validate them against the output of the root circuit simulation this.debug(`Updating and validating root trees`); - const globalVariablesHash = computeGlobalsHash(await CircuitsWasm.get(), left[0].constants.globalVariables); + const globalVariablesHash = computeGlobalsHash(left[0].constants.globalVariables); await this.db.updateLatestGlobalVariablesHash(globalVariablesHash); await this.db.updateHistoricBlocksTree(globalVariablesHash); diff --git a/yarn-project/sequencer-client/src/sequencer/utils.ts b/yarn-project/sequencer-client/src/sequencer/utils.ts index d49536ba0609..b43747fc6442 100644 --- a/yarn-project/sequencer-client/src/sequencer/utils.ts +++ b/yarn-project/sequencer-client/src/sequencer/utils.ts @@ -1,4 +1,4 @@ -import { CircuitsWasm, Fr, GlobalVariables, HistoricBlockData } from '@aztec/circuits.js'; +import { Fr, GlobalVariables, HistoricBlockData } from '@aztec/circuits.js'; import { computeGlobalsHash } from '@aztec/circuits.js/abis'; import { MerkleTreeOperations } from '@aztec/world-state'; @@ -9,8 +9,7 @@ export async function getHistoricBlockData( db: MerkleTreeOperations, prevBlockGlobalVariables: GlobalVariables = GlobalVariables.empty(), ) { - const wasm = await CircuitsWasm.get(); - const prevGlobalsHash = computeGlobalsHash(wasm, prevBlockGlobalVariables); + const prevGlobalsHash = computeGlobalsHash(prevBlockGlobalVariables); const roots = await db.getTreeRoots(); return new HistoricBlockData( diff --git a/yarn-project/world-state/src/synchronizer/server_world_state_synchronizer.test.ts b/yarn-project/world-state/src/synchronizer/server_world_state_synchronizer.test.ts index 5dc3ec4bb1d8..4fe162c12b07 100644 --- a/yarn-project/world-state/src/synchronizer/server_world_state_synchronizer.test.ts +++ b/yarn-project/world-state/src/synchronizer/server_world_state_synchronizer.test.ts @@ -1,6 +1,5 @@ import { AppendOnlyTreeSnapshot, - CircuitsWasm, Fr, GlobalVariables, MAX_NEW_COMMITMENTS_PER_TX, @@ -125,10 +124,9 @@ describe('server_world_state_synchronizer', () => { getTreeInfo: jest.fn(() => Promise.resolve({ depth: 8, treeId: MerkleTreeId.CONTRACT_TREE, root: Buffer.alloc(32, 0), size: 0n }), ), - getSiblingPath: jest.fn(async () => { - const wasm = await CircuitsWasm.get(); - const pedersen: Pedersen = new Pedersen(wasm); - return SiblingPath.ZERO(32, INITIAL_LEAF, pedersen) as SiblingPath; + getSiblingPath: jest.fn(() => { + const pedersen: Pedersen = new Pedersen(); + return Promise.resolve(SiblingPath.ZERO(32, INITIAL_LEAF, pedersen) as SiblingPath); }), handleL2Block: jest.fn(() => Promise.resolve({ isBlockOurs: false })), }); diff --git a/yarn-project/world-state/src/world-state-db/merkle_trees.ts b/yarn-project/world-state/src/world-state-db/merkle_trees.ts index c41555b52be8..b48367539dba 100644 --- a/yarn-project/world-state/src/world-state-db/merkle_trees.ts +++ b/yarn-project/world-state/src/world-state-db/merkle_trees.ts @@ -75,8 +75,7 @@ export class MerkleTrees implements MerkleTreeDb { const fromDb = fromDbOptions !== undefined; const initializeTree = fromDb ? loadTree : newTree; - const wasm = optionalWasm ?? (await CircuitsWasm.get()); - const hasher = new Pedersen(wasm); + const hasher = new Pedersen(); const contractTree: AppendOnlyTree = await initializeTree( StandardTree, this.db, @@ -126,12 +125,12 @@ export class MerkleTrees implements MerkleTreeDb { // The first leaf in the blocks tree contains the empty roots of the other trees and empty global variables. if (!fromDb) { - const initialGlobalVariablesHash = computeGlobalsHash(wasm, GlobalVariables.empty()); + const initialGlobalVariablesHash = computeGlobalsHash(GlobalVariables.empty()); await this._updateLatestGlobalVariablesHash(initialGlobalVariablesHash); await this._updateHistoricBlocksTree(initialGlobalVariablesHash, true); await this._commit(); } else { - await this._updateLatestGlobalVariablesHash(computeGlobalsHash(wasm, fromDbOptions.globalVariables)); + await this._updateLatestGlobalVariablesHash(computeGlobalsHash(fromDbOptions.globalVariables)); } } @@ -574,7 +573,7 @@ export class MerkleTrees implements MerkleTreeDb { } // Sync and add the block to the historic blocks tree - const globalVariablesHash = computeGlobalsHash(await CircuitsWasm.get(), l2Block.globalVariables); + const globalVariablesHash = computeGlobalsHash(l2Block.globalVariables); await this._updateLatestGlobalVariablesHash(globalVariablesHash); this.log(`Synced global variables with hash ${globalVariablesHash}`); From 26ac28afefc3e1588c158481bcf2929fb527d561 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Sun, 29 Oct 2023 13:26:11 +0000 Subject: [PATCH 02/29] Plumbing. --- barretenberg/ts/src/benchmark/timer.ts | 10 +- .../src/client/client_execution_context.ts | 8 +- .../src/client/execution_note_cache.ts | 7 +- .../src/client/private_execution.test.ts | 53 +- .../src/client/view_data_oracle.ts | 5 +- .../src/common/packed_args_cache.ts | 4 +- .../acir-simulator/src/public/execution.ts | 36 +- .../acir-simulator/src/public/index.test.ts | 32 +- .../src/public/public_execution_context.ts | 2 +- yarn-project/acir-simulator/src/test/utils.ts | 10 +- yarn-project/acir-simulator/src/utils.ts | 5 +- .../aztec-node/src/aztec-node/server.ts | 6 +- .../account/defaults/entrypoint_payload.ts | 11 +- yarn-project/aztec.js/src/utils/authwit.ts | 8 +- .../aztec.js/src/utils/cheat_codes.ts | 7 +- yarn-project/aztec.js/src/utils/secrets.ts | 7 +- .../aztec.js/src/wallet/signerless_wallet.ts | 5 +- yarn-project/circuits.js/out | 0 yarn-project/circuits.js/package.json | 2 + .../circuits.js/src/abis/abis.test.ts | 32 +- yarn-project/circuits.js/src/abis/abis.ts | 82 +-- .../src/barretenberg/crypto/grumpkin/index.ts | 2 + .../crypto/pedersen/index.test.ts | 40 ++ .../barretenberg/crypto/pedersen/pedersen.ts | 52 +- .../src/contract/contract_deployment_info.ts | 12 +- .../contract/contract_tree/contract_tree.ts | 2 +- .../src/structs/complete_address.ts | 16 +- .../src/structs/public_call_request.ts | 10 +- .../end-to-end/src/e2e_block_building.test.ts | 5 +- .../src/e2e_non_contract_account.test.ts | 2 +- .../end-to-end/src/e2e_ordering.test.ts | 2 +- .../src/guides/dapp_testing.test.ts | 8 +- .../src/simulators/lending_simulator.ts | 11 +- yarn-project/foundation/package.json | 21 +- .../src/async-map/async_map.test.ts | 2 +- .../src/crypto/pedersen/index.elliptic.ts | 567 +++++++++++++++++ .../src/crypto/pedersen/index.noble.ts | 573 +++++++++++++++++ .../foundation/src/crypto/pedersen/index.ts | 574 +----------------- .../json-rpc/client/json_rpc_client.test.ts | 2 +- .../foundation/src/json-rpc/convert.test.ts | 18 +- .../json-rpc/server/json_rpc_server.test.ts | 8 +- .../foundation/src/log/log_history.test.ts | 2 - .../foundation/src/mutex/mutex.test.ts | 2 - .../src/serialize/buffer_reader.test.ts | 2 - yarn-project/foundation/src/timer/timer.ts | 13 +- .../noir-private-kernel/src/index.test.ts | 23 +- .../src/noir_test_gen.test.ts | 3 +- yarn-project/package.common.json | 1 + yarn-project/pxe/src/contract_tree/index.ts | 8 +- .../pxe/src/kernel_prover/proof_creator.ts | 5 +- .../src/note_processor/note_processor.test.ts | 8 +- .../pxe/src/note_processor/note_processor.ts | 7 +- .../pxe/src/pxe_service/pxe_service.ts | 10 +- yarn-project/sequencer-client/package.json | 1 + .../block_builder/solo_block_builder.test.ts | 12 +- .../src/block_builder/solo_block_builder.ts | 17 +- .../src/sequencer/public_processor.ts | 14 +- .../src/simulator/public_executor.ts | 9 +- yarn-project/types/src/packed_arguments.ts | 6 +- .../src/world-state-db/merkle_trees.ts | 11 +- yarn-project/yarn.lock | 498 ++++++++++++++- 61 files changed, 1955 insertions(+), 956 deletions(-) delete mode 100644 yarn-project/circuits.js/out create mode 100644 yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts create mode 100644 yarn-project/foundation/src/crypto/pedersen/index.elliptic.ts create mode 100644 yarn-project/foundation/src/crypto/pedersen/index.noble.ts diff --git a/barretenberg/ts/src/benchmark/timer.ts b/barretenberg/ts/src/benchmark/timer.ts index b74be9819ea6..81dfe37f1277 100644 --- a/barretenberg/ts/src/benchmark/timer.ts +++ b/barretenberg/ts/src/benchmark/timer.ts @@ -14,7 +14,11 @@ export class Timer { private start: number; constructor() { - this.start = new Date().getTime(); + this.start = performance.now(); + } + + public us() { + return this.ms() * 1000; } /** @@ -25,7 +29,7 @@ export class Timer { * @returns The elapsed time in milliseconds. */ public ms() { - return new Date().getTime() - this.start; + return performance.now() - this.start; } /** @@ -36,6 +40,6 @@ export class Timer { * @returns The elapsed time in seconds. */ public s() { - return (new Date().getTime() - this.start) / 1000; + return this.ms() / 1000; } } diff --git a/yarn-project/acir-simulator/src/client/client_execution_context.ts b/yarn-project/acir-simulator/src/client/client_execution_context.ts index 0b64bcfd3328..0408c6022b49 100644 --- a/yarn-project/acir-simulator/src/client/client_execution_context.ts +++ b/yarn-project/acir-simulator/src/client/client_execution_context.ts @@ -1,6 +1,5 @@ import { CallContext, - CircuitsWasm, ContractDeploymentData, FunctionData, FunctionSelector, @@ -172,7 +171,7 @@ export class ClientExecutionContext extends ViewDataOracle { * @param args - Arguments to pack */ public packArguments(args: Fr[]): Promise { - return this.packedArgsCache.pack(args); + return Promise.resolve(this.packedArgsCache.pack(args)); } /** @@ -231,11 +230,10 @@ export class ClientExecutionContext extends ViewDataOracle { .join(', ')}`, ); - const wasm = await CircuitsWasm.get(); notes.forEach(n => { if (n.index !== undefined) { - const siloedNoteHash = siloCommitment(wasm, n.contractAddress, n.innerNoteHash); - const uniqueSiloedNoteHash = computeUniqueCommitment(wasm, n.nonce, siloedNoteHash); + const siloedNoteHash = siloCommitment(n.contractAddress, n.innerNoteHash); + const uniqueSiloedNoteHash = computeUniqueCommitment(n.nonce, siloedNoteHash); // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386) // Should always be uniqueSiloedNoteHash when publicly created notes include nonces. const noteHashForReadRequest = n.nonce.isZero() ? siloedNoteHash : uniqueSiloedNoteHash; diff --git a/yarn-project/acir-simulator/src/client/execution_note_cache.ts b/yarn-project/acir-simulator/src/client/execution_note_cache.ts index 9ed21b0cb804..de471d914f10 100644 --- a/yarn-project/acir-simulator/src/client/execution_note_cache.ts +++ b/yarn-project/acir-simulator/src/client/execution_note_cache.ts @@ -1,4 +1,4 @@ -import { CircuitsWasm, EMPTY_NULLIFIED_COMMITMENT } from '@aztec/circuits.js'; +import { EMPTY_NULLIFIED_COMMITMENT } from '@aztec/circuits.js'; import { siloNullifier } from '@aztec/circuits.js/abis'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; @@ -41,9 +41,8 @@ export class ExecutionNoteCache { * @param innerNoteHash - Inner note hash of the note. If this value equals EMPTY_NULLIFIED_COMMITMENT, it means the * note being nullified is from a previous transaction (and thus not a new note). */ - public async nullifyNote(contractAddress: AztecAddress, innerNullifier: Fr, innerNoteHash: Fr) { - const wasm = await CircuitsWasm.get(); - const siloedNullifier = siloNullifier(wasm, contractAddress, innerNullifier); + public nullifyNote(contractAddress: AztecAddress, innerNullifier: Fr, innerNoteHash: Fr) { + const siloedNullifier = siloNullifier(contractAddress, innerNullifier); const nullifiers = this.getNullifiers(contractAddress); nullifiers.add(siloedNullifier.value); this.nullifiers.set(contractAddress.toBigInt(), nullifiers); diff --git a/yarn-project/acir-simulator/src/client/private_execution.test.ts b/yarn-project/acir-simulator/src/client/private_execution.test.ts index 5dcd61793685..2fb61d3679cf 100644 --- a/yarn-project/acir-simulator/src/client/private_execution.test.ts +++ b/yarn-project/acir-simulator/src/client/private_execution.test.ts @@ -59,7 +59,6 @@ jest.setTimeout(60_000); const createMemDown = () => (memdown as any)() as MemDown; describe('Private Execution test suite', () => { - let circuitsWasm: any; let oracle: MockProxy; let acirSimulator: AcirSimulator; @@ -89,7 +88,7 @@ describe('Private Execution test suite', () => { contractDeploymentData: ContractDeploymentData.empty(), }; - const runSimulator = async ({ + const runSimulator = ({ artifact, args = [], msgSender = AztecAddress.ZERO, @@ -104,7 +103,7 @@ describe('Private Execution test suite', () => { args?: any[]; txContext?: Partial>; }) => { - const packedArguments = await PackedArguments.fromArgs(encodeArguments(artifact, args), circuitsWasm); + const packedArguments = PackedArguments.fromArgs(encodeArguments(artifact, args)); const functionData = FunctionData.fromAbi(artifact); const txRequest = TxExecutionRequest.from({ origin: contractAddress, @@ -145,17 +144,10 @@ describe('Private Execution test suite', () => { return trees[name]; }; - const hash = (data: Buffer[]) => pedersenHashInputs(circuitsWasm, data); - const hashFields = (data: Fr[]) => - Fr.fromBuffer( - pedersenHashInputs( - circuitsWasm, - data.map(f => f.toBuffer()), - ), - ); + const hash = (data: Buffer[]) => pedersenHashInputs(data); + const hashFields = (data: Fr[]) => Fr.fromBuffer(pedersenHashInputs(data.map(f => f.toBuffer()))); beforeAll(async () => { - circuitsWasm = await CircuitsWasm.get(); logger = createDebugLogger('aztec:test:private_execution'); ownerCompleteAddress = await CompleteAddress.fromPrivateKeyAndPartialAddress(ownerPk, Fr.random()); @@ -205,7 +197,7 @@ describe('Private Execution test suite', () => { // array index at the output of the final kernel/ordering circuit are used to derive nonce via: // `hash(firstNullifier, noteHashIndex)` const noteHashIndex = Math.floor(Math.random()); // mock index in TX's final newNoteHashes array - const nonce = computeCommitmentNonce(circuitsWasm, mockFirstNullifier, noteHashIndex); + const nonce = computeCommitmentNonce(mockFirstNullifier, noteHashIndex); const preimage = [new Fr(amount), owner.toField(), Fr.random()]; const innerNoteHash = Fr.fromBuffer(hash(preimage.map(p => p.toBuffer()))); return { @@ -238,8 +230,8 @@ describe('Private Execution test suite', () => { // Should be the same as how we compute the values for the ValueNote in the Aztec.nr library. const valueNoteHash = hashFields(note.preimage); const innerNoteHash = hashFields([storageSlot, valueNoteHash]); - const siloedNoteHash = siloCommitment(circuitsWasm, contractAddress, innerNoteHash); - const uniqueSiloedNoteHash = computeUniqueCommitment(circuitsWasm, note.nonce, siloedNoteHash); + const siloedNoteHash = siloCommitment(contractAddress, innerNoteHash); + const uniqueSiloedNoteHash = computeUniqueCommitment(note.nonce, siloedNoteHash); const innerNullifier = hashFields([uniqueSiloedNoteHash, ownerPk.low, ownerPk.high]); const result = await acirSimulator.computeNoteHashAndNullifier( @@ -264,7 +256,7 @@ describe('Private Execution test suite', () => { expect(result.newNotes).toHaveLength(1); const newNote = result.newNotes[0]; - expect(newNote.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm)); + expect(newNote.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField())); const newCommitments = result.callStackItem.publicInputs.newCommitments.filter(field => !field.equals(Fr.ZERO)); expect(newCommitments).toHaveLength(1); @@ -282,7 +274,7 @@ describe('Private Execution test suite', () => { expect(result.newNotes).toHaveLength(1); const newNote = result.newNotes[0]; - expect(newNote.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm)); + expect(newNote.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField())); const newCommitments = result.callStackItem.publicInputs.newCommitments.filter(field => !field.equals(Fr.ZERO)); expect(newCommitments).toHaveLength(1); @@ -297,8 +289,8 @@ describe('Private Execution test suite', () => { const amountToTransfer = 100n; const artifact = getFunctionArtifact(StatefulTestContractArtifact, 'destroy_and_create'); - const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm); - const recipientStorageSlot = computeSlotForMapping(new Fr(1n), recipient.toField(), circuitsWasm); + const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField()); + const recipientStorageSlot = computeSlotForMapping(new Fr(1n), recipient.toField()); const notes = [buildNote(60n, owner, storageSlot), buildNote(80n, owner, storageSlot)]; oracle.getNotes.mockResolvedValue(notes); @@ -344,7 +336,7 @@ describe('Private Execution test suite', () => { const balance = 160n; const artifact = getFunctionArtifact(StatefulTestContractArtifact, 'destroy_and_create'); - const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm); + const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField()); const notes = [buildNote(balance, owner, storageSlot)]; oracle.getNotes.mockResolvedValue(notes); @@ -412,14 +404,14 @@ describe('Private Execution test suite', () => { let argsHash: Fr; let testCodeGenArtifact: FunctionArtifact; - beforeAll(async () => { + beforeAll(() => { // These args should match the ones hardcoded in importer contract const dummyNote = { amount: 1, secretHash: 2 }; const deepStruct = { aField: 1, aBool: true, aNote: dummyNote, manyNotes: [dummyNote, dummyNote, dummyNote] }; args = [1, true, 1, [1, 2], dummyNote, deepStruct]; testCodeGenArtifact = getFunctionArtifact(TestContractArtifact, 'test_code_gen'); const serializedArgs = encodeArguments(testCodeGenArtifact, args); - argsHash = await computeVarArgsHash(await CircuitsWasm.get(), serializedArgs); + argsHash = computeVarArgsHash(serializedArgs); }); it('test function should be directly callable', async () => { @@ -506,14 +498,13 @@ describe('Private Execution test suite', () => { const amount = 100n; const artifact = getFunctionArtifact(TokenContractArtifact, 'redeem_shield'); - const wasm = await CircuitsWasm.get(); const secret = new Fr(1n); - const secretHash = computeSecretMessageHash(wasm, secret); + const secretHash = computeSecretMessageHash(secret); const preimage = [toBufferBE(amount, 32), secretHash.toBuffer()]; const noteHash = Fr.fromBuffer(hash(preimage)); const storageSlot = new Fr(5); const innerNoteHash = Fr.fromBuffer(hash([storageSlot.toBuffer(), noteHash.toBuffer()])); - const siloedNoteHash = siloCommitment(wasm, contractAddress, innerNoteHash); + const siloedNoteHash = siloCommitment(contractAddress, innerNoteHash); oracle.getNotes.mockResolvedValue([ { contractAddress, @@ -630,7 +621,7 @@ describe('Private Execution test suite', () => { expect(result.newNotes).toHaveLength(1); const note = result.newNotes[0]; - expect(note.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm)); + expect(note.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField())); expect(note.preimage[0]).toEqual(new Fr(amountToTransfer)); @@ -638,7 +629,7 @@ describe('Private Execution test suite', () => { expect(newCommitments).toHaveLength(1); const commitment = newCommitments[0]; - const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm); + const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField()); const innerNoteHash = await acirSimulator.computeInnerNoteHash(contractAddress, storageSlot, note.preimage); expect(commitment).toEqual(innerNoteHash); @@ -701,7 +692,7 @@ describe('Private Execution test suite', () => { expect(execInsert.newNotes).toHaveLength(1); const note = execInsert.newNotes[0]; - expect(note.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm)); + expect(note.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField())); expect(note.preimage[0]).toEqual(new Fr(amountToTransfer)); @@ -711,7 +702,7 @@ describe('Private Execution test suite', () => { expect(newCommitments).toHaveLength(1); const commitment = newCommitments[0]; - const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm); + const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField()); const innerNoteHash = await acirSimulator.computeInnerNoteHash(contractAddress, storageSlot, note.preimage); expect(commitment).toEqual(innerNoteHash); @@ -749,7 +740,7 @@ describe('Private Execution test suite', () => { expect(result.newNotes).toHaveLength(1); const note = result.newNotes[0]; - expect(note.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm)); + expect(note.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField())); expect(note.preimage[0]).toEqual(new Fr(amountToTransfer)); @@ -757,7 +748,7 @@ describe('Private Execution test suite', () => { expect(newCommitments).toHaveLength(1); const commitment = newCommitments[0]; - const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm); + const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField()); expect(commitment).toEqual(await acirSimulator.computeInnerNoteHash(contractAddress, storageSlot, note.preimage)); // read requests should be empty diff --git a/yarn-project/acir-simulator/src/client/view_data_oracle.ts b/yarn-project/acir-simulator/src/client/view_data_oracle.ts index 55e1aff0206c..9677d9783baf 100644 --- a/yarn-project/acir-simulator/src/client/view_data_oracle.ts +++ b/yarn-project/acir-simulator/src/client/view_data_oracle.ts @@ -1,4 +1,4 @@ -import { CircuitsWasm, HistoricBlockData, PublicKey } from '@aztec/circuits.js'; +import { HistoricBlockData, PublicKey } from '@aztec/circuits.js'; import { siloNullifier } from '@aztec/circuits.js/abis'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; @@ -106,8 +106,7 @@ export class ViewDataOracle extends TypedOracle { * @returns A boolean indicating whether the nullifier exists in the tree or not. */ public async checkNullifierExists(innerNullifier: Fr) { - const wasm = await CircuitsWasm.get(); - const nullifier = siloNullifier(wasm, this.contractAddress, innerNullifier!); + const nullifier = siloNullifier(this.contractAddress, innerNullifier!); const index = await this.db.getNullifierIndex(nullifier); return index !== undefined; } diff --git a/yarn-project/acir-simulator/src/common/packed_args_cache.ts b/yarn-project/acir-simulator/src/common/packed_args_cache.ts index 245c8580ced4..fc120f7daf78 100644 --- a/yarn-project/acir-simulator/src/common/packed_args_cache.ts +++ b/yarn-project/acir-simulator/src/common/packed_args_cache.ts @@ -45,11 +45,11 @@ export class PackedArgsCache { * @param args - The arguments to pack. * @returns The hash of the packed arguments. */ - public async pack(args: Fr[]): Promise { + public pack(args: Fr[]) { if (args.length === 0) { return Fr.zero(); } - const packedArguments = await PackedArguments.fromArgs(args, this.wasm); + const packedArguments = PackedArguments.fromArgs(args); this.cache.set(packedArguments.hash.value, packedArguments.args); return packedArguments.hash; } diff --git a/yarn-project/acir-simulator/src/public/execution.ts b/yarn-project/acir-simulator/src/public/execution.ts index e5a8bf43aea6..46b1227a6e4c 100644 --- a/yarn-project/acir-simulator/src/public/execution.ts +++ b/yarn-project/acir-simulator/src/public/execution.ts @@ -9,7 +9,6 @@ import { PublicDataUpdateRequest, } from '@aztec/circuits.js'; import { computePublicDataTreeIndex, computePublicDataTreeValue } from '@aztec/circuits.js/abis'; -import { IWasmModule } from '@aztec/foundation/wasm'; import { FunctionL2Logs } from '@aztec/types'; /** @@ -71,16 +70,16 @@ export function isPublicExecutionResult( * @param execResult - The topmost execution result. * @returns All public data reads (in execution order). */ -export function collectPublicDataReads(wasm: IWasmModule, execResult: PublicExecutionResult): PublicDataRead[] { +export function collectPublicDataReads(execResult: PublicExecutionResult): PublicDataRead[] { // HACK(#1622): part of temporary hack - may be able to remove this function after public state ordering is fixed const contractAddress = execResult.execution.contractAddress; const thisExecPublicDataReads = execResult.contractStorageReads.map(read => - contractStorageReadToPublicDataRead(wasm, read, contractAddress), + contractStorageReadToPublicDataRead(read, contractAddress), ); const unsorted = [ ...thisExecPublicDataReads, - ...[...execResult.nestedExecutions].flatMap(result => collectPublicDataReads(wasm, result)), + ...[...execResult.nestedExecutions].flatMap(result => collectPublicDataReads(result)), ]; return unsorted.sort((a, b) => a.sideEffectCounter! - b.sideEffectCounter!); } @@ -88,62 +87,51 @@ export function collectPublicDataReads(wasm: IWasmModule, execResult: PublicExec /** * Collect all public storage update requests across all nested executions * and convert them to PublicDataUpdateRequests (to match kernel output). - * @param wasm - A module providing low-level wasm access. * @param execResult - The topmost execution result. * @returns All public data reads (in execution order). */ -export function collectPublicDataUpdateRequests( - wasm: IWasmModule, - execResult: PublicExecutionResult, -): PublicDataUpdateRequest[] { +export function collectPublicDataUpdateRequests(execResult: PublicExecutionResult): PublicDataUpdateRequest[] { // HACK(#1622): part of temporary hack - may be able to remove this function after public state ordering is fixed const contractAddress = execResult.execution.contractAddress; const thisExecPublicDataUpdateRequests = execResult.contractStorageUpdateRequests.map(update => - contractStorageUpdateRequestToPublicDataUpdateRequest(wasm, update, contractAddress), + contractStorageUpdateRequestToPublicDataUpdateRequest(update, contractAddress), ); const unsorted = [ ...thisExecPublicDataUpdateRequests, - ...[...execResult.nestedExecutions].flatMap(result => collectPublicDataUpdateRequests(wasm, result)), + ...[...execResult.nestedExecutions].flatMap(result => collectPublicDataUpdateRequests(result)), ]; return unsorted.sort((a, b) => a.sideEffectCounter! - b.sideEffectCounter!); } /** * Convert a Contract Storage Read to a Public Data Read. - * @param wasm - A module providing low-level wasm access. * @param read - the contract storage read to convert * @param contractAddress - the contract address of the read * @returns The public data read. */ -function contractStorageReadToPublicDataRead( - wasm: IWasmModule, - read: ContractStorageRead, - contractAddress: AztecAddress, -): PublicDataRead { +function contractStorageReadToPublicDataRead(read: ContractStorageRead, contractAddress: AztecAddress): PublicDataRead { return new PublicDataRead( - computePublicDataTreeIndex(wasm, contractAddress, read.storageSlot), - computePublicDataTreeValue(wasm, read.currentValue), + computePublicDataTreeIndex(contractAddress, read.storageSlot), + computePublicDataTreeValue(read.currentValue), read.sideEffectCounter!, ); } /** * Convert a Contract Storage Update Request to a Public Data Update Request. - * @param wasm - A module providing low-level wasm access. * @param update - the contract storage update request to convert * @param contractAddress - the contract address of the data update request. * @returns The public data update request. */ function contractStorageUpdateRequestToPublicDataUpdateRequest( - wasm: IWasmModule, update: ContractStorageUpdateRequest, contractAddress: AztecAddress, ): PublicDataUpdateRequest { return new PublicDataUpdateRequest( - computePublicDataTreeIndex(wasm, contractAddress, update.storageSlot), - computePublicDataTreeValue(wasm, update.oldValue), - computePublicDataTreeValue(wasm, update.newValue), + computePublicDataTreeIndex(contractAddress, update.storageSlot), + computePublicDataTreeValue(update.oldValue), + computePublicDataTreeValue(update.newValue), update.sideEffectCounter!, ); } diff --git a/yarn-project/acir-simulator/src/public/index.test.ts b/yarn-project/acir-simulator/src/public/index.test.ts index 093c823f6cc4..2123995b7437 100644 --- a/yarn-project/acir-simulator/src/public/index.test.ts +++ b/yarn-project/acir-simulator/src/public/index.test.ts @@ -1,6 +1,5 @@ import { CallContext, - CircuitsWasm, FunctionData, GlobalVariables, HistoricBlockData, @@ -32,17 +31,12 @@ import { PublicExecutor } from './executor.js'; export const createMemDown = () => (memdown as any)() as MemDown; describe('ACIR public execution simulator', () => { - let circuitsWasm: CircuitsWasm; let publicState: MockProxy; let publicContracts: MockProxy; let commitmentsDb: MockProxy; let executor: PublicExecutor; let blockData: HistoricBlockData; - beforeAll(async () => { - circuitsWasm = await CircuitsWasm.get(); - }); - beforeEach(() => { publicState = mock(); publicContracts = mock(); @@ -95,7 +89,7 @@ describe('ACIR public execution simulator', () => { expect(result.returnValues[0]).toEqual(new Fr(1n)); - const recipientBalanceStorageSlot = computeSlotForMapping(new Fr(6n), recipient.toField(), circuitsWasm); + const recipientBalanceStorageSlot = computeSlotForMapping(new Fr(6n), recipient.toField()); const totalSupplyStorageSlot = new Fr(4n); const expectedBalance = new Fr(previousBalance.value + mintAmount); @@ -117,7 +111,7 @@ describe('ACIR public execution simulator', () => { ]); const mintersStorageSlot = new Fr(2n); - const isMinterStorageSlot = computeSlotForMapping(mintersStorageSlot, msgSender.toField(), circuitsWasm); + const isMinterStorageSlot = computeSlotForMapping(mintersStorageSlot, msgSender.toField()); // Note: There is only 1 storage read (for the isMinter value) because the other 2 reads get overwritten by // the updates expect(result.contractStorageReads).toEqual([ @@ -158,8 +152,8 @@ describe('ACIR public execution simulator', () => { isStaticCall: false, }); - recipientStorageSlot = computeSlotForMapping(new Fr(6n), recipient.toField(), circuitsWasm); - senderStorageSlot = computeSlotForMapping(new Fr(6n), Fr.fromBuffer(sender.toBuffer()), circuitsWasm); + recipientStorageSlot = computeSlotForMapping(new Fr(6n), recipient.toField()); + senderStorageSlot = computeSlotForMapping(new Fr(6n), Fr.fromBuffer(sender.toBuffer())); publicContracts.getBytecode.mockResolvedValue(Buffer.from(transferArtifact.bytecode, 'base64')); @@ -298,14 +292,12 @@ describe('ACIR public execution simulator', () => { let functionData: FunctionData; let amount: Fr; let params: Fr[]; - let wasm: CircuitsWasm; - beforeEach(async () => { + beforeEach(() => { contractAddress = AztecAddress.random(); functionData = new FunctionData(FunctionSelector.empty(), false, false, false); amount = new Fr(1); params = [amount, new Fr(1)]; - wasm = await CircuitsWasm.get(); }); it('Should be able to create a commitment from the public context', async () => { @@ -335,9 +327,9 @@ describe('ACIR public execution simulator', () => { // Assert the commitment was created expect(result.newCommitments.length).toEqual(1); - const expectedNoteHash = pedersenHashInputs(wasm, [amount.toBuffer(), secretHash.toBuffer()]); + const expectedNoteHash = pedersenHashInputs([amount.toBuffer(), secretHash.toBuffer()]); const storageSlot = new Fr(5); // for pending_shields - const expectedInnerNoteHash = pedersenHashInputs(wasm, [storageSlot.toBuffer(), expectedNoteHash]); + const expectedInnerNoteHash = pedersenHashInputs([storageSlot.toBuffer(), expectedNoteHash]); expect(result.newCommitments[0].toBuffer()).toEqual(expectedInnerNoteHash); }); @@ -365,10 +357,7 @@ describe('ACIR public execution simulator', () => { // Assert the l2 to l1 message was created expect(result.newL2ToL1Messages.length).toEqual(1); - const expectedNewMessageValue = pedersenHashInputs( - wasm, - params.map(a => a.toBuffer()), - ); + const expectedNewMessageValue = pedersenHashInputs(params.map(a => a.toBuffer())); expect(result.newL2ToL1Messages[0].toBuffer()).toEqual(expectedNewMessageValue); }); @@ -452,10 +441,7 @@ describe('ACIR public execution simulator', () => { // Assert the l2 to l1 message was created expect(result.newNullifiers.length).toEqual(1); - const expectedNewMessageValue = pedersenHashInputs( - wasm, - params.map(a => a.toBuffer()), - ); + const expectedNewMessageValue = pedersenHashInputs(params.map(a => a.toBuffer())); expect(result.newNullifiers[0].toBuffer()).toEqual(expectedNewMessageValue); }); }); diff --git a/yarn-project/acir-simulator/src/public/public_execution_context.ts b/yarn-project/acir-simulator/src/public/public_execution_context.ts index 4097087e19ad..12393742c351 100644 --- a/yarn-project/acir-simulator/src/public/public_execution_context.ts +++ b/yarn-project/acir-simulator/src/public/public_execution_context.ts @@ -93,7 +93,7 @@ export class PublicExecutionContext extends TypedOracle { * @param args - Arguments to pack */ public packArguments(args: Fr[]): Promise { - return this.packedArgsCache.pack(args); + return Promise.resolve(this.packedArgsCache.pack(args)); } /** diff --git a/yarn-project/acir-simulator/src/test/utils.ts b/yarn-project/acir-simulator/src/test/utils.ts index b9b9a388c77b..70a1e311a8bf 100644 --- a/yarn-project/acir-simulator/src/test/utils.ts +++ b/yarn-project/acir-simulator/src/test/utils.ts @@ -1,4 +1,4 @@ -import { AztecAddress, CircuitsWasm, EthAddress, Fr } from '@aztec/circuits.js'; +import { AztecAddress, EthAddress, Fr } from '@aztec/circuits.js'; import { computeSecretMessageHash } from '@aztec/circuits.js/abis'; import { ContractArtifact, FunctionSelector, getFunctionDebugMetadata } from '@aztec/foundation/abi'; import { sha256ToField } from '@aztec/foundation/crypto'; @@ -14,21 +14,19 @@ import { FunctionArtifactWithDebugMetadata } from '../index.js'; * @param secret - The secret to unlock the message. * @returns The L1 to L2 message. */ -export const buildL1ToL2Message = async ( +export const buildL1ToL2Message = ( selector: string, contentPreimage: Fr[], targetContract: AztecAddress, secret: Fr, -): Promise => { - const wasm = await CircuitsWasm.get(); - +) => { // Write the selector into a buffer. const selectorBuf = Buffer.from(selector, 'hex'); const contentBuf = Buffer.concat([selectorBuf, ...contentPreimage.map(field => field.toBuffer())]); const content = sha256ToField(contentBuf); - const secretHash = computeSecretMessageHash(wasm, secret); + const secretHash = computeSecretMessageHash(secret); // Eventually the kernel will need to prove the kernel portal pair exists within the contract tree, // EthAddress.random() will need to be replaced when this happens diff --git a/yarn-project/acir-simulator/src/utils.ts b/yarn-project/acir-simulator/src/utils.ts index 45daead148b6..1398bcdecc5d 100644 --- a/yarn-project/acir-simulator/src/utils.ts +++ b/yarn-project/acir-simulator/src/utils.ts @@ -1,4 +1,4 @@ -import { CircuitsWasm, GrumpkinPrivateKey } from '@aztec/circuits.js'; +import { GrumpkinPrivateKey } from '@aztec/circuits.js'; import { Grumpkin, pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; import { Fr } from '@aztec/foundation/fields'; @@ -19,13 +19,12 @@ export type NoirPoint = { * @param bbWasm - Wasm module for computing. * @returns The slot in the contract storage where the value is stored. */ -export function computeSlotForMapping(mappingSlot: Fr, owner: NoirPoint | Fr, bbWasm: CircuitsWasm) { +export function computeSlotForMapping(mappingSlot: Fr, owner: NoirPoint | Fr) { const isFr = (owner: NoirPoint | Fr): owner is Fr => typeof (owner as Fr).value === 'bigint'; const ownerField = isFr(owner) ? owner : new Fr(owner.x); return Fr.fromBuffer( pedersenHashInputs( - bbWasm, [mappingSlot, ownerField].map(f => f.toBuffer()), ), ); diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 13f9130b959f..1dc329e37bd9 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -107,7 +107,7 @@ export class AztecNodeService implements AztecNode { // now create the merkle trees and the world state syncher const db = await openDb(config); - const merkleTrees = await MerkleTrees.new(db, await CircuitsWasm.get()); + const merkleTrees = await MerkleTrees.new(db); const worldStateConfig: WorldStateConfig = getWorldStateConfig(); const worldStateSynchronizer = await ServerWorldStateSynchronizer.new(db, merkleTrees, archiver, worldStateConfig); @@ -348,7 +348,7 @@ export class AztecNodeService implements AztecNode { */ public async getPublicStorageAt(contract: AztecAddress, slot: bigint): Promise { const committedDb = await this.#getWorldState(); - const leafIndex = computePublicDataTreeIndex(await CircuitsWasm.get(), contract, new Fr(slot)); + const leafIndex = computePublicDataTreeIndex(contract, new Fr(slot)); return committedDb.getLeafValue(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex.value); } @@ -414,7 +414,7 @@ export class AztecNodeService implements AztecNode { // TODO we should be able to remove this after https://github.com/AztecProtocol/aztec-packages/issues/1869 // So simulation of public functions doesn't affect the merkle trees. const merkleTrees = new MerkleTrees(this.merkleTreesDb, this.log); - await merkleTrees.init(await CircuitsWasm.get(), { + await merkleTrees.init({ globalVariables: prevGlobalVariables, }); diff --git a/yarn-project/aztec.js/src/account/defaults/entrypoint_payload.ts b/yarn-project/aztec.js/src/account/defaults/entrypoint_payload.ts index 3ea1c9190d77..99fc8377cb4d 100644 --- a/yarn-project/aztec.js/src/account/defaults/entrypoint_payload.ts +++ b/yarn-project/aztec.js/src/account/defaults/entrypoint_payload.ts @@ -1,4 +1,4 @@ -import { CircuitsWasm, Fr, GeneratorIndex } from '@aztec/circuits.js'; +import { Fr, GeneratorIndex } from '@aztec/circuits.js'; import { pedersenHashWithHashIndex } from '@aztec/circuits.js/barretenberg'; import { padArrayEnd } from '@aztec/foundation/collection'; import { FunctionCall, PackedArguments, emptyFunctionCall } from '@aztec/types'; @@ -32,18 +32,18 @@ export type EntrypointPayload = { }; /** Assembles an entrypoint payload from a set of private and public function calls */ -export async function buildPayload(calls: FunctionCall[]): Promise<{ +export function buildPayload(calls: FunctionCall[]): { /** The payload for the entrypoint function */ payload: EntrypointPayload; /** The packed arguments of functions called */ packedArguments: PackedArguments[]; -}> { +} { const nonce = Fr.random(); const paddedCalls = padArrayEnd(calls, emptyFunctionCall(), ACCOUNT_MAX_CALLS); const packedArguments: PackedArguments[] = []; for (const call of paddedCalls) { - packedArguments.push(await PackedArguments.fromArgs(call.args)); + packedArguments.push(PackedArguments.fromArgs(call.args)); } const formattedCalls: EntrypointFunctionCall[] = paddedCalls.map((call, index) => ({ @@ -68,9 +68,8 @@ export async function buildPayload(calls: FunctionCall[]): Promise<{ } /** Hashes an entrypoint payload to a 32-byte buffer (useful for signing) */ -export async function hashPayload(payload: EntrypointPayload) { +export function hashPayload(payload: EntrypointPayload) { return pedersenHashWithHashIndex( - await CircuitsWasm.get(), flattenPayload(payload).map(fr => fr.toBuffer()), GeneratorIndex.SIGNATURE_PAYLOAD, ); diff --git a/yarn-project/aztec.js/src/utils/authwit.ts b/yarn-project/aztec.js/src/utils/authwit.ts index 74f04862c4cf..f31f3e26b732 100644 --- a/yarn-project/aztec.js/src/utils/authwit.ts +++ b/yarn-project/aztec.js/src/utils/authwit.ts @@ -1,4 +1,4 @@ -import { AztecAddress, CircuitsWasm, GeneratorIndex } from '@aztec/circuits.js'; +import { AztecAddress, GeneratorIndex } from '@aztec/circuits.js'; import { pedersenHashWithHashIndex } from '@aztec/circuits.js/barretenberg'; import { FunctionCall, PackedArguments } from '@aztec/types'; @@ -10,15 +10,13 @@ import { FunctionCall, PackedArguments } from '@aztec/types'; * @param request - The request to be made (function call) * @returns The message hash for the witness */ -export const computeAuthWitMessageHash = async (caller: AztecAddress, request: FunctionCall) => { - const wasm = await CircuitsWasm.get(); +export const computeAuthWitMessageHash = (caller: AztecAddress, request: FunctionCall) => { return pedersenHashWithHashIndex( - wasm, [ caller.toField(), request.to.toField(), request.functionData.selector.toField(), - (await PackedArguments.fromArgs(request.args, wasm)).hash, + PackedArguments.fromArgs(request.args).hash, ].map(fr => fr.toBuffer()), GeneratorIndex.SIGNATURE_PAYLOAD, ); diff --git a/yarn-project/aztec.js/src/utils/cheat_codes.ts b/yarn-project/aztec.js/src/utils/cheat_codes.ts index 8abc6ba5ee9e..f97b47f06faf 100644 --- a/yarn-project/aztec.js/src/utils/cheat_codes.ts +++ b/yarn-project/aztec.js/src/utils/cheat_codes.ts @@ -235,12 +235,7 @@ export class AztecCheatCodes { public computeSlotInMap(baseSlot: Fr | bigint, key: Fr | bigint | AztecAddress): Fr { // Based on `at` function in // aztec3-packages/yarn-project/aztec-nr/aztec/src/state_vars/map.nr - return Fr.fromBuffer( - pedersenHashInputs( - this.wasm, - [new Fr(baseSlot), new Fr(key)].map(f => f.toBuffer()), - ), - ); + return Fr.fromBuffer(pedersenHashInputs([new Fr(baseSlot), new Fr(key)].map(f => f.toBuffer()))); } /** diff --git a/yarn-project/aztec.js/src/utils/secrets.ts b/yarn-project/aztec.js/src/utils/secrets.ts index 758bd6879e46..ac642c159167 100644 --- a/yarn-project/aztec.js/src/utils/secrets.ts +++ b/yarn-project/aztec.js/src/utils/secrets.ts @@ -1,4 +1,4 @@ -import { CircuitsWasm, Fr } from '@aztec/circuits.js'; +import { Fr } from '@aztec/circuits.js'; import { computeSecretMessageHash } from '@aztec/circuits.js/abis'; /** @@ -6,7 +6,6 @@ import { computeSecretMessageHash } from '@aztec/circuits.js/abis'; * @param secret - the secret to hash - secret could be generated however you want e.g. `Fr.random()` * @returns the hash */ -export async function computeMessageSecretHash(secret: Fr): Promise { - const wasm = await CircuitsWasm.get(); - return computeSecretMessageHash(wasm, secret); +export function computeMessageSecretHash(secret: Fr) { + return computeSecretMessageHash(secret); } diff --git a/yarn-project/aztec.js/src/wallet/signerless_wallet.ts b/yarn-project/aztec.js/src/wallet/signerless_wallet.ts index 03368dd86117..e9d04584853a 100644 --- a/yarn-project/aztec.js/src/wallet/signerless_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/signerless_wallet.ts @@ -1,4 +1,4 @@ -import { CircuitsWasm, Fr, TxContext } from '@aztec/circuits.js'; +import { Fr, TxContext } from '@aztec/circuits.js'; import { AuthWitness, FunctionCall, PackedArguments, TxExecutionRequest } from '@aztec/types'; import { CompleteAddress } from '../index.js'; @@ -13,8 +13,7 @@ export class SignerlessWallet extends BaseWallet { throw new Error(`Unexpected number of executions. Expected 1 but received ${executions.length}).`); } const [execution] = executions; - const wasm = await CircuitsWasm.get(); - const packedArguments = await PackedArguments.fromArgs(execution.args, wasm); + const packedArguments = PackedArguments.fromArgs(execution.args); const { chainId, protocolVersion } = await this.pxe.getNodeInfo(); const txContext = TxContext.empty(chainId, protocolVersion); return Promise.resolve( diff --git a/yarn-project/circuits.js/out b/yarn-project/circuits.js/out deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/yarn-project/circuits.js/package.json b/yarn-project/circuits.js/package.json index 120d66964e54..12ead497910f 100644 --- a/yarn-project/circuits.js/package.json +++ b/yarn-project/circuits.js/package.json @@ -25,6 +25,7 @@ "formatting:fix": "run -T prettier -w ./src", "remake-bindings": "DEBUG=wasm ts-node-esm src/cbind/circuits.in.ts && prettier -w src/cbind/circuits.gen.ts", "remake-constants": "ts-node-esm src/cbind/constants.in.ts && prettier -w src/cbind/constants.gen.ts", + "test:light": "NODE_NO_WARNINGS=1 NODE_OPTIONS='--loader ts-node/esm' node --experimental-vm-modules $(yarn bin jest) --runner=jest-light-runner --passWithNoTests", "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests" }, "inherits": [ @@ -62,6 +63,7 @@ "@types/lodash.mapvalues": "^4.6.7", "@types/node": "^18.7.23", "jest": "^29.5.0", + "jest-light-runner": "^0.5.1", "prettier": "^2.8.4", "ts-dedent": "^2.2.0", "ts-jest": "^29.1.0", diff --git a/yarn-project/circuits.js/src/abis/abis.test.ts b/yarn-project/circuits.js/src/abis/abis.test.ts index 5c6179c4e936..d0ef716be34d 100644 --- a/yarn-project/circuits.js/src/abis/abis.test.ts +++ b/yarn-project/circuits.js/src/abis/abis.test.ts @@ -27,13 +27,13 @@ describe('abis wasm bindings', () => { it('hashes a tx request', () => { const txRequest = makeTxRequest(); - const hash = hashTxRequest(wasm, txRequest); + const hash = hashTxRequest(txRequest); expect(hash).toMatchSnapshot(); }); it('computes a function selector', () => { const funcSig = 'transfer(address,uint256)'; - const res = computeFunctionSelector(wasm, funcSig); + const res = computeFunctionSelector(funcSig); expect(res).toMatchSnapshot(); }); @@ -45,7 +45,7 @@ describe('abis wasm bindings', () => { it('computes a function leaf', () => { const leaf = new FunctionLeafPreimage(new FunctionSelector(7837), false, true, Fr.ZERO, Fr.ZERO); - const res = computeFunctionLeaf(wasm, leaf); + const res = computeFunctionLeaf(leaf); expect(res).toMatchSnapshot(); }); @@ -58,7 +58,7 @@ describe('abis wasm bindings', () => { const functionData = new FunctionData(FunctionSelector.empty(), false, true, true); const argsHash = new Fr(42); const vkHash = Buffer.alloc(32); - const res = hashConstructor(wasm, functionData, argsHash, vkHash); + const res = hashConstructor(functionData, argsHash, vkHash); expect(res).toMatchSnapshot(); }); @@ -67,59 +67,59 @@ describe('abis wasm bindings', () => { const contractAddrSalt = new Fr(2n); const treeRoot = new Fr(3n); const constructorHash = new Fr(4n); - const res = computeCompleteAddress(wasm, deployerPubKey, contractAddrSalt, treeRoot, constructorHash); + const res = computeCompleteAddress(deployerPubKey, contractAddrSalt, treeRoot, constructorHash); expect(res).toMatchSnapshot(); }); it('computes commitment nonce', () => { const nullifierZero = new Fr(123n); const commitmentIndex = 456; - const res = computeCommitmentNonce(wasm, nullifierZero, commitmentIndex); + const res = computeCommitmentNonce(nullifierZero, commitmentIndex); expect(res).toMatchSnapshot(); }); it('computes unique commitment', () => { const nonce = new Fr(123n); const innerCommitment = new Fr(456); - const res = computeUniqueCommitment(wasm, nonce, innerCommitment); + const res = computeUniqueCommitment(nonce, innerCommitment); expect(res).toMatchSnapshot(); }); it('computes siloed commitment', () => { const contractAddress = new AztecAddress(new Fr(123n).toBuffer()); const uniqueCommitment = new Fr(456); - const res = siloCommitment(wasm, contractAddress, uniqueCommitment); + const res = siloCommitment(contractAddress, uniqueCommitment); expect(res).toMatchSnapshot(); }); it('computes siloed nullifier', () => { const contractAddress = new AztecAddress(new Fr(123n).toBuffer()); const innerNullifier = new Fr(456); - const res = siloNullifier(wasm, contractAddress, innerNullifier); + const res = siloNullifier(contractAddress, innerNullifier); expect(res).toMatchSnapshot(); }); it('computes contract leaf', () => { const cd = new NewContractData(makeAztecAddress(), makeEthAddress(), new Fr(3n)); - const res = computeContractLeaf(wasm, cd); + const res = computeContractLeaf(cd); expect(res).toMatchSnapshot(); }); - it('hashes empty function args', async () => { - const res = await computeVarArgsHash(wasm, []); + it('hashes empty function args', () => { + const res = computeVarArgsHash([]); expect(res).toMatchSnapshot(); }); - it('hashes function args', async () => { + it('hashes function args', () => { // const args = Array.from({ length: 8 }).map((_, i) => new Fr(i)); const args = times(8, i => new Fr(i)); - const res = await computeVarArgsHash(wasm, args); + const res = computeVarArgsHash(args); expect(res).toMatchSnapshot(); }); - it('hashes many function args', async () => { + it('hashes many function args', () => { const args = times(200, i => new Fr(i)); - const res = await computeVarArgsHash(wasm, args); + const res = computeVarArgsHash(args); expect(res).toMatchSnapshot(); }); }); diff --git a/yarn-project/circuits.js/src/abis/abis.ts b/yarn-project/circuits.js/src/abis/abis.ts index e6c1ce6aaaf4..5e0a369acc41 100644 --- a/yarn-project/circuits.js/src/abis/abis.ts +++ b/yarn-project/circuits.js/src/abis/abis.ts @@ -57,45 +57,14 @@ function wasmSyncCall( return buf; } -/** - * Writes input buffers to wasm memory, calls a wasm function, and returns the output buffer. - * @param wasm - A module providing low-level wasm access. - * @param fnName - The name of the function to call. - * @param inputBuffers - Buffers to write to wasm memory. - * @param expectedOutputLength - The expected length of the output buffer. - * @returns The output buffer. - */ -// function inputBuffersToOutputBuffer( -// wasm: IWasmModule, -// fnName: string, -// inputBuffers: Buffer[], -// expectedOutputLength: number, -// ) { -// const offsets: number[] = []; -// const totalLength = inputBuffers.reduce((total, cur) => { -// offsets.push(total); -// return total + cur.length; -// }, 0); - -// const outputBuf = wasm.call('bbmalloc', expectedOutputLength); -// const inputBuf = wasm.call('bbmalloc', totalLength); -// wasm.writeMemory(inputBuf, Buffer.concat(inputBuffers)); -// const args = offsets.map(offset => inputBuf + offset); -// wasm.call(fnName, ...args, outputBuf); -// const output = Buffer.from(wasm.getMemorySlice(outputBuf, outputBuf + expectedOutputLength)); -// wasm.call('bbfree', inputBuf); -// wasm.call('bbfree', outputBuf); -// return output; -// } - /** * Computes a hash of a transaction request. * @param wasm - A module providing low-level wasm access. * @param txRequest - The transaction request. * @returns The hash of the transaction request. */ -export function hashTxRequest(wasm: IWasmModule, txRequest: TxRequest): Buffer { - return computeTxHash(wasm, txRequest).toBuffer(); +export function hashTxRequest(txRequest: TxRequest): Buffer { + return computeTxHash(txRequest).toBuffer(); } /** @@ -104,7 +73,7 @@ export function hashTxRequest(wasm: IWasmModule, txRequest: TxRequest): Buffer { * @param funcSig - The function signature. * @returns The function selector. */ -export function computeFunctionSelector(wasm: IWasmModule, funcSig: string): Buffer { +export function computeFunctionSelector(funcSig: string): Buffer { return keccak(Buffer.from(funcSig)).subarray(0, FUNCTION_SELECTOR_NUM_BYTES); } @@ -124,7 +93,7 @@ export function hashVK(wasm: IWasmModule, vkBuf: Buffer) { * @param fnLeaf - The function leaf preimage. * @returns The function leaf. */ -export function computeFunctionLeaf(wasm: IWasmModule, fnLeaf: FunctionLeafPreimage): Fr { +export function computeFunctionLeaf(fnLeaf: FunctionLeafPreimage): Fr { return Fr.fromBuffer( pedersenHashWithHashIndex( [ @@ -159,12 +128,7 @@ export function computeFunctionTreeRoot(wasm: IWasmModule, fnLeaves: Fr[]) { * @param constructorVKHash - Hash of the constructor's verification key. * @returns The constructor hash. */ -export function hashConstructor( - wasm: IWasmModule, - functionData: FunctionData, - argsHash: Fr, - constructorVKHash: Buffer, -): Fr { +export function hashConstructor(functionData: FunctionData, argsHash: Fr, constructorVKHash: Buffer): Fr { return Fr.fromBuffer( pedersenHashWithHashIndex( [computeFunctionDataHash(functionData).toBuffer(), argsHash.toBuffer(), constructorVKHash], @@ -183,7 +147,6 @@ export function hashConstructor( * @returns The complete address. */ export function computeCompleteAddress( - wasm: IWasmModule, deployerPubKey: PublicKey, contractAddrSalt: Fr, fnTreeRoot: Fr, @@ -191,7 +154,7 @@ export function computeCompleteAddress( ): CompleteAddress { const partialAddress = computePartialAddress(contractAddrSalt, fnTreeRoot, constructorHash); return new CompleteAddress( - computeContractAddressFromPartial(wasm, deployerPubKey, partialAddress), + computeContractAddressFromPartial(deployerPubKey, partialAddress), deployerPubKey, partialAddress, ); @@ -223,11 +186,7 @@ function computePartialAddress(contractAddrSalt: Fr, fnTreeRoot: Fr, constructor * @param constructorHash - The hash of the constructor. * @returns The partially constructed contract address. */ -export function computeContractAddressFromPartial( - wasm: IWasmModule, - pubKey: PublicKey, - partialAddress: Fr, -): AztecAddress { +export function computeContractAddressFromPartial(pubKey: PublicKey, partialAddress: Fr): AztecAddress { const result = pedersenHashWithHashIndex( [pubKey.x.toBuffer(), pubKey.y.toBuffer(), partialAddress.toBuffer()], GeneratorIndex.CONTRACT_ADDRESS, @@ -242,7 +201,7 @@ export function computeContractAddressFromPartial( * @param commitmentIndex - The index of the commitment. * @returns A commitment nonce. */ -export function computeCommitmentNonce(wasm: IWasmModule, nullifierZero: Fr, commitmentIndex: number): Fr { +export function computeCommitmentNonce(nullifierZero: Fr, commitmentIndex: number): Fr { return Fr.fromBuffer( pedersenHashWithHashIndex( [nullifierZero.toBuffer(), numToUInt32BE(commitmentIndex, 32)], @@ -259,7 +218,7 @@ export function computeCommitmentNonce(wasm: IWasmModule, nullifierZero: Fr, com * @param innerCommitment - The commitment to silo. * @returns A siloed commitment. */ -export function siloCommitment(wasm: IWasmModule, contract: AztecAddress, innerCommitment: Fr): Fr { +export function siloCommitment(contract: AztecAddress, innerCommitment: Fr): Fr { return Fr.fromBuffer( pedersenHashWithHashIndex([contract.toBuffer(), innerCommitment.toBuffer()], GeneratorIndex.SILOED_COMMITMENT), ); @@ -272,7 +231,7 @@ export function siloCommitment(wasm: IWasmModule, contract: AztecAddress, innerC * @param siloedCommitment - An siloed commitment. * @returns A unique commitment. */ -export function computeUniqueCommitment(wasm: IWasmModule, nonce: Fr, siloedCommitment: Fr): Fr { +export function computeUniqueCommitment(nonce: Fr, siloedCommitment: Fr): Fr { return Fr.fromBuffer( pedersenHashWithHashIndex([nonce.toBuffer(), siloedCommitment.toBuffer()], GeneratorIndex.UNIQUE_COMMITMENT), ); @@ -286,7 +245,7 @@ export function computeUniqueCommitment(wasm: IWasmModule, nonce: Fr, siloedComm * @param innerNullifier - The nullifier to silo. * @returns A siloed nullifier. */ -export function siloNullifier(wasm: IWasmModule, contract: AztecAddress, innerNullifier: Fr): Fr { +export function siloNullifier(contract: AztecAddress, innerNullifier: Fr): Fr { return Fr.fromBuffer( pedersenHashWithHashIndex([contract.toBuffer(), innerNullifier.toBuffer()], GeneratorIndex.OUTER_NULLIFIER), ); @@ -304,7 +263,6 @@ export function siloNullifier(wasm: IWasmModule, contract: AztecAddress, innerNu * @returns The block hash. */ export function computeBlockHashWithGlobals( - wasm: IWasmModule, globals: GlobalVariables, noteHashTreeRoot: Fr, nullifierTreeRoot: Fr, @@ -313,7 +271,6 @@ export function computeBlockHashWithGlobals( publicDataTreeRoot: Fr, ): Fr { return computeBlockHash( - wasm, computeGlobalsHash(globals), noteHashTreeRoot, nullifierTreeRoot, @@ -335,7 +292,6 @@ export function computeBlockHashWithGlobals( * @returns The block hash. */ export function computeBlockHash( - wasm: IWasmModule, globalsHash: Fr, noteHashTreeRoot: Fr, nullifierTreeRoot: Fr, @@ -385,7 +341,7 @@ export function computeGlobalsHash(globals: GlobalVariables): Fr { * @returns Value hash into a tree-insertion-ready value. */ -export function computePublicDataTreeValue(wasm: IWasmModule, value: Fr): Fr { +export function computePublicDataTreeValue(value: Fr): Fr { return value; } @@ -397,7 +353,7 @@ export function computePublicDataTreeValue(wasm: IWasmModule, value: Fr): Fr { * @returns Public data tree index computed from contract address and storage slot. */ -export function computePublicDataTreeIndex(wasm: IWasmModule, contractAddress: AztecAddress, storageSlot: Fr): Fr { +export function computePublicDataTreeIndex(contractAddress: AztecAddress, storageSlot: Fr): Fr { return Fr.fromBuffer( pedersenHashWithHashIndex([contractAddress.toBuffer(), storageSlot.toBuffer()], GeneratorIndex.PUBLIC_LEAF_INDEX), ); @@ -412,8 +368,8 @@ const ARGS_HASH_CHUNK_COUNT = 16; * @param args - Arguments to hash. * @returns Pedersen hash of the arguments. */ -export function computeVarArgsHash(wasm: IWasmModule, args: Fr[]): Promise { - if (args.length === 0) return Promise.resolve(Fr.ZERO); +export function computeVarArgsHash(args: Fr[]) { + if (args.length === 0) return Fr.ZERO; if (args.length > ARGS_HASH_CHUNK_SIZE * ARGS_HASH_CHUNK_COUNT) throw new Error(`Cannot hash more than ${ARGS_HASH_CHUNK_SIZE * ARGS_HASH_CHUNK_COUNT} arguments`); @@ -436,7 +392,7 @@ export function computeVarArgsHash(wasm: IWasmModule, args: Fr[]): Promise { chunksHashes = padArrayEnd(chunksHashes, Fr.ZERO, ARGS_HASH_CHUNK_COUNT); } - return Promise.resolve(wasmComputeVarArgs(chunksHashes)); + return wasmComputeVarArgs(chunksHashes); } /** @@ -445,7 +401,7 @@ export function computeVarArgsHash(wasm: IWasmModule, args: Fr[]): Promise { * @param cd - The contract data of the deployed contract. * @returns The contract leaf. */ -export function computeContractLeaf(wasm: IWasmModule, cd: NewContractData): Fr { +export function computeContractLeaf(cd: NewContractData): Fr { return Fr.fromBuffer( pedersenHashWithHashIndex( [cd.contractAddress.toBuffer(), cd.portalContractAddress.toBuffer(), cd.functionTreeRoot.toBuffer()], @@ -460,7 +416,7 @@ export function computeContractLeaf(wasm: IWasmModule, cd: NewContractData): Fr * @param txRequest - The signed transaction request. * @returns The transaction hash. */ -export function computeTxHash(wasm: IWasmModule, txRequest: TxRequest): Fr { +export function computeTxHash(txRequest: TxRequest): Fr { return Fr.fromBuffer( pedersenHashWithHashIndex( [ @@ -595,6 +551,6 @@ export function computePublicCallStackItemHash(wasm: IWasmModule, callStackItem: * @param secretMessage - The secret message. * @returns */ -export function computeSecretMessageHash(wasm: IWasmModule, secretMessage: Fr) { +export function computeSecretMessageHash(secretMessage: Fr) { return Fr.fromBuffer(pedersenHashWithHashIndex([secretMessage.toBuffer()], GeneratorIndex.L1_TO_L2_MESSAGE_SECRET)); } diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.ts b/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.ts index 82c735563555..37247fe4c8bb 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.ts @@ -3,6 +3,8 @@ import { IWasmModule } from '@aztec/foundation/wasm'; import { CircuitsWasm, GrumpkinScalar } from '../../../index.js'; +// TODO!!!!!: Make this use grumpkin typescript currently in pedersen. + /** * Grumpkin elliptic curve operations. */ diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts new file mode 100644 index 000000000000..fb7a7d16cd34 --- /dev/null +++ b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts @@ -0,0 +1,40 @@ +import { toBufferBE } from '@aztec/foundation/bigint-buffer'; +import { pedersenCommit, pedersenCommitNoble } from '@aztec/foundation/crypto'; +import { Timer } from '@aztec/foundation/timer'; + +import { CircuitsWasm } from '../../../wasm/index.js'; +import { pedersenCommitWasm } from './index.js'; + +describe('pedersen', () => { + beforeAll(async () => {}); + + it('pedersen perf wasm', async () => { + const wasm = await CircuitsWasm.get(); + const loops = 10000; + const t = new Timer(); + for (let i = 0; i < loops; ++i) { + pedersenCommitWasm(wasm, [toBufferBE(1n, 32), toBufferBE(1n, 32)]); + } + console.log(t.us() / loops); + console.log(pedersenCommitWasm(wasm, [toBufferBE(1n, 32), toBufferBE(1n, 32)])); + }); + + it('pedersen perf elliptic', () => { + const loops = 10000; + const t = new Timer(); + for (let i = 0; i < loops; ++i) { + pedersenCommit([toBufferBE(1n, 32), toBufferBE(1n, 32)]); + } + console.log(t.us() / loops); + console.log(pedersenCommit([toBufferBE(1n, 32), toBufferBE(1n, 32)])); + }); + + // it('pedersen perf noble', () => { + // const loops = 10000; + // const t = new Timer(); + // for (let i = 0; i < loops; ++i) { + // pedersenCommitNoble([toBufferBE(1n, 32), toBufferBE(1n, 32)]); + // } + // console.log(t.us() / loops); + // }); +}); diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts index e003ad3577a4..a49b91422ee0 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts @@ -3,6 +3,10 @@ import { IWasmModule } from '@aztec/foundation/wasm'; import { Buffer } from 'buffer'; +import { serializeBufferArrayToVector } from '../../serialize.js'; + +// TODO: DELETE THIS FILE! + /** * Hashes two arrays. * @param wasm - The barretenberg module. @@ -12,8 +16,8 @@ import { Buffer } from 'buffer'; * @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific * purposes. */ -export function pedersenHash(wasm: IWasmModule, lhs: Uint8Array, rhs: Uint8Array): Buffer { - return pedersenHashWithHashIndex(wasm, [Buffer.from(lhs), Buffer.from(rhs)], 0); +export function pedersenHash(lhs: Uint8Array, rhs: Uint8Array): Buffer { + return pedersenHashWithHashIndex([Buffer.from(lhs), Buffer.from(rhs)], 0); } /** @@ -24,8 +28,8 @@ export function pedersenHash(wasm: IWasmModule, lhs: Uint8Array, rhs: Uint8Array * @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific * purposes. */ -export function pedersenHashInputs(wasm: IWasmModule, inputs: Buffer[]): Buffer { - return pedersenHashWithHashIndex(wasm, inputs, 0); +export function pedersenHashInputs(inputs: Buffer[]): Buffer { + return pedersenHashWithHashIndex(inputs, 0); } /** @@ -37,6 +41,44 @@ export function pedersenHashInputs(wasm: IWasmModule, inputs: Buffer[]): Buffer * @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific * purposes. */ -export function pedersenHashWithHashIndex(wasm: IWasmModule, inputs: Buffer[], hashIndex: number): Buffer { +export function pedersenHashWithHashIndex(inputs: Buffer[], hashIndex: number): Buffer { return cryptoPedersen(inputs, hashIndex); } + +/** + * + */ +export function pedersenCommitWasm(wasm: IWasmModule, inputs: Buffer[]) { + const data = serializeBufferArrayToVector(inputs); + + // WASM gives us 1024 bytes of scratch space which we can use without + // needing to allocate/free it ourselves. This can be useful for when we need to pass in several small variables + // when calling functions on the wasm, however it's important to not overrun this scratch space as otherwise + // the written data will begin to corrupt the stack. + // + // Using this scratch space isn't particularly safe if we have multiple threads interacting with the wasm however, + // each thread could write to the same pointer address simultaneously. + const SCRATCH_SPACE_SIZE = 1024; + + // For pedersen hashing, the case of hashing two inputs is the most common. + // so ideally we want to optimize for that. This will use 64 bytes of memory and + // can thus be optimized by checking if the input buffer is smaller than the scratch space. + let inputPtr = 0; + if (inputs.length >= SCRATCH_SPACE_SIZE) { + inputPtr = wasm.call('bbmalloc', data.length); + } + wasm.writeMemory(inputPtr, data); + + // Since the output is 32 bytes, instead of allocating memory + // we can reuse the scratch space to store the result. + const outputPtr = 0; + + wasm.call('pedersen__commit', inputPtr, outputPtr); + const hashOutput = wasm.getMemorySlice(0, 64); + + if (inputPtr !== 0) { + wasm.call('bbfree', inputPtr); + } + + return [Buffer.from(hashOutput.slice(0, 32)), Buffer.from(hashOutput.slice(32, 64))]; +} diff --git a/yarn-project/circuits.js/src/contract/contract_deployment_info.ts b/yarn-project/circuits.js/src/contract/contract_deployment_info.ts index df1d8efade57..4476ac852bea 100644 --- a/yarn-project/circuits.js/src/contract/contract_deployment_info.ts +++ b/yarn-project/circuits.js/src/contract/contract_deployment_info.ts @@ -42,16 +42,10 @@ export async function getContractDeploymentInfo( const functionTreeRoot = computeFunctionTreeRoot(wasm, leaves); const functionData = FunctionData.fromAbi(constructorArtifact); const flatArgs = encodeArguments(constructorArtifact, args); - const argsHash = await computeVarArgsHash(wasm, flatArgs); - const constructorHash = hashConstructor(wasm, functionData, argsHash, constructorVkHash.toBuffer()); + const argsHash = computeVarArgsHash(flatArgs); + const constructorHash = hashConstructor(functionData, argsHash, constructorVkHash.toBuffer()); - const completeAddress = computeCompleteAddress( - wasm, - publicKey, - contractAddressSalt, - functionTreeRoot, - constructorHash, - ); + const completeAddress = computeCompleteAddress(publicKey, contractAddressSalt, functionTreeRoot, constructorHash); return { completeAddress, diff --git a/yarn-project/circuits.js/src/contract/contract_tree/contract_tree.ts b/yarn-project/circuits.js/src/contract/contract_tree/contract_tree.ts index 13d88c315d00..d21f89058a4d 100644 --- a/yarn-project/circuits.js/src/contract/contract_tree/contract_tree.ts +++ b/yarn-project/circuits.js/src/contract/contract_tree/contract_tree.ts @@ -86,7 +86,7 @@ export function generateFunctionLeaves(functions: ContractFunctionDao[], wasm: C Fr.fromBuffer(vkHash), Fr.fromBuffer(acirHash), ); - const fnLeaf = computeFunctionLeaf(wasm, fnLeafPreimage); + const fnLeaf = computeFunctionLeaf(fnLeafPreimage); result.push(fnLeaf); } return result; diff --git a/yarn-project/circuits.js/src/structs/complete_address.ts b/yarn-project/circuits.js/src/structs/complete_address.ts index e35c98d252c2..e0f86e1419d1 100644 --- a/yarn-project/circuits.js/src/structs/complete_address.ts +++ b/yarn-project/circuits.js/src/structs/complete_address.ts @@ -30,13 +30,8 @@ export class CompleteAddress { /** Size in bytes of an instance */ static readonly SIZE_IN_BYTES = 32 * 4; - static async create( - address: AztecAddress, - publicKey: PublicKey, - partialAddress: PartialAddress, - ): Promise { - const wasm = await CircuitsWasm.get(); - const expectedAddress = computeContractAddressFromPartial(wasm, publicKey, partialAddress); + static create(address: AztecAddress, publicKey: PublicKey, partialAddress: PartialAddress) { + const expectedAddress = computeContractAddressFromPartial(publicKey, partialAddress); if (!expectedAddress.equals(address)) { throw new Error( `Address cannot be derived from pubkey and partial address (received ${address.toString()}, derived ${expectedAddress.toString()})`, @@ -45,11 +40,10 @@ export class CompleteAddress { return new CompleteAddress(address, publicKey, partialAddress); } - static async random(): Promise { + static random() { const partialAddress = Fr.random(); const pubKey = Point.random(); - const wasm = await CircuitsWasm.get(); - const address = computeContractAddressFromPartial(wasm, pubKey, partialAddress); + const address = computeContractAddressFromPartial(pubKey, partialAddress); return new CompleteAddress(address, pubKey, partialAddress); } @@ -60,7 +54,7 @@ export class CompleteAddress { const wasm = await CircuitsWasm.get(); const grumpkin = new Grumpkin(wasm); const pubKey = grumpkin.mul(Grumpkin.generator, privateKey); - const address = computeContractAddressFromPartial(wasm, pubKey, partialAddress); + const address = computeContractAddressFromPartial(pubKey, partialAddress); return new CompleteAddress(address, pubKey, partialAddress); } diff --git a/yarn-project/circuits.js/src/structs/public_call_request.ts b/yarn-project/circuits.js/src/structs/public_call_request.ts index e32e045fc9c7..6c62b190f4aa 100644 --- a/yarn-project/circuits.js/src/structs/public_call_request.ts +++ b/yarn-project/circuits.js/src/structs/public_call_request.ts @@ -1,7 +1,7 @@ import { BufferReader } from '@aztec/foundation/serialize'; import { computeVarArgsHash } from '../abis/abis.js'; -import { CircuitsWasm, FieldsOf } from '../index.js'; +import { FieldsOf } from '../index.js'; import { serializeToBuffer } from '../utils/serialize.js'; import { AztecAddress, @@ -92,10 +92,10 @@ export class PublicCallRequest { * Creates a new PublicCallStackItem by populating with zeroes all fields related to result in the public circuit output. * @returns A PublicCallStackItem instance with the same contract address, function data, call context, and args. */ - async toPublicCallStackItem(): Promise { + toPublicCallStackItem() { const publicInputs = PublicCircuitPublicInputs.empty(); publicInputs.callContext = this.callContext; - publicInputs.argsHash = await this.getArgsHash(); + publicInputs.argsHash = this.getArgsHash(); return new PublicCallStackItem(this.contractAddress, this.functionData, publicInputs, true); } @@ -103,7 +103,7 @@ export class PublicCallRequest { * Returns the hash of the arguments for this request. * @returns Hash of the arguments for this request. */ - async getArgsHash() { - return computeVarArgsHash(await CircuitsWasm.get(), this.args); + getArgsHash() { + return computeVarArgsHash(this.args); } } diff --git a/yarn-project/end-to-end/src/e2e_block_building.test.ts b/yarn-project/end-to-end/src/e2e_block_building.test.ts index 7c04c24b6b80..6451391f5a04 100644 --- a/yarn-project/end-to-end/src/e2e_block_building.test.ts +++ b/yarn-project/end-to-end/src/e2e_block_building.test.ts @@ -135,10 +135,7 @@ describe('e2e_block_building', () => { it('drops tx with private nullifier already emitted from public on the same block', async () => { const secret = Fr.random(); // See yarn-project/acir-simulator/src/public/index.test.ts 'Should be able to create a nullifier from the public context' - const emittedPublicNullifier = pedersenHashInputs( - await CircuitsWasm.get(), - [new Fr(140), secret].map(a => a.toBuffer()), - ); + const emittedPublicNullifier = pedersenHashInputs([new Fr(140), secret].map(a => a.toBuffer())); const calls = [ contract.methods.create_nullifier_public(140n, secret), diff --git a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts index a5b5fe1d0c05..9f55371193c9 100644 --- a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts +++ b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts @@ -39,7 +39,7 @@ describe('e2e_non_contract_account', () => { expect(receipt.status).toBe(TxStatus.MINED); const tx = await aztecNode!.getTx(receipt.txHash); - const expectedSiloedNullifier = siloNullifier(await CircuitsWasm.get(), contract.address, nullifier); + const expectedSiloedNullifier = siloNullifier(contract.address, nullifier); const siloedNullifier = tx!.newNullifiers[1]; expect(siloedNullifier.equals(expectedSiloedNullifier)).toBeTruthy(); diff --git a/yarn-project/end-to-end/src/e2e_ordering.test.ts b/yarn-project/end-to-end/src/e2e_ordering.test.ts index d0b9f902840f..49a95ea26940 100644 --- a/yarn-project/end-to-end/src/e2e_ordering.test.ts +++ b/yarn-project/end-to-end/src/e2e_ordering.test.ts @@ -70,7 +70,7 @@ describe('e2e_ordering', () => { expect(enqueuedPublicCalls.length).toEqual(2); // The call stack hashes in the output of the kernel proof match the tx enqueuedPublicFunctionCalls - const hashes = await Promise.all(enqueuedPublicCalls.map(c => c.toPublicCallStackItem().then(i => i.hash()))); + const hashes = enqueuedPublicCalls.map(c => c.toPublicCallStackItem().hash()); expect(tx.data.end.publicCallStack.slice(0, 2)).toEqual(hashes); // The enqueued public calls are in the expected order based on the argument they set (stack is reversed!) diff --git a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts index b4a5c583b85c..1104985f5f49 100644 --- a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts +++ b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts @@ -43,7 +43,7 @@ describe('guides/dapp/testing', () => { const mintAmount = 20n; const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const receipt = await token.methods.mint_private(mintAmount, secretHash).send().wait(); const storageSlot = new Fr(5); // The storage slot of `pending_shields` is 5. @@ -75,7 +75,7 @@ describe('guides/dapp/testing', () => { const recipientAddress = recipient.getAddress(); const mintAmount = 20n; const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const receipt = await token.methods.mint_private(mintAmount, secretHash).send().wait(); const storageSlot = new Fr(5); @@ -128,7 +128,7 @@ describe('guides/dapp/testing', () => { const ownerAddress = owner.getAddress(); const mintAmount = 100n; const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const receipt = await token.methods.mint_private(100n, secretHash).send().wait(); const storageSlot = new Fr(5); @@ -245,7 +245,7 @@ describe('guides/dapp/testing', () => { const mintAmount = 20n; const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const receipt = await token.methods.mint_private(mintAmount, secretHash).send().wait(); const storageSlot = new Fr(5); diff --git a/yarn-project/end-to-end/src/simulators/lending_simulator.ts b/yarn-project/end-to-end/src/simulators/lending_simulator.ts index 17cfa0ddc03e..62dcd17b700a 100644 --- a/yarn-project/end-to-end/src/simulators/lending_simulator.ts +++ b/yarn-project/end-to-end/src/simulators/lending_simulator.ts @@ -24,13 +24,8 @@ export class LendingAccount { * Computes the key for the private holdings of this account. * @returns Key in public space */ - public async key(): Promise { - return Fr.fromBuffer( - pedersenHashInputs( - await CircuitsWasm.get(), - [this.address, this.secret].map(f => f.toBuffer()), - ), - ); + public key() { + return Fr.fromBuffer(pedersenHashInputs([this.address, this.secret].map(f => f.toBuffer()))); } } @@ -175,7 +170,7 @@ export class LendingSimulator { expect(asset['interest_accumulator']).toEqual(this.accumulator); expect(asset['last_updated_ts']).toEqual(BigInt(this.time)); - for (const key of [this.account.address, await this.account.key()]) { + for (const key of [this.account.address, this.account.key()]) { const privatePos = await this.lendingContract.methods.get_position(key).view(); expect(new Fr(privatePos['collateral'])).toEqual(this.collateral[key.toString()] ?? Fr.ZERO); expect(new Fr(privatePos['static_debt'])).toEqual(this.staticDebt[key.toString()] ?? Fr.ZERO); diff --git a/yarn-project/foundation/package.json b/yarn-project/foundation/package.json index 9ac562c62f14..bbe710bdeee3 100644 --- a/yarn-project/foundation/package.json +++ b/yarn-project/foundation/package.json @@ -41,7 +41,8 @@ "clean": "rm -rf ./dest .tsbuildinfo", "formatting": "run -T prettier --check ./src && run -T eslint ./src", "formatting:fix": "run -T prettier -w ./src", - "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests" + "test:light": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests", + "test": "NODE_NO_WARNINGS=1 NODE_OPTIONS='--loader ts-node/esm' node --experimental-vm-modules $(yarn bin jest) --runner=jest-light-runner --passWithNoTests" }, "inherits": [ "../package.common.json" @@ -54,11 +55,25 @@ "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, + "mocha": { + "extension": [ + "ts" + ], + "node-option": [ + "experimental-specifier-resolution=node", + "loader=ts-node/esm" + ], + "spec": [ + "./src/crypto/pedersen/*.test.ts" + ] + }, "dependencies": { "@koa/cors": "^4.0.0", "@noble/curves": "^1.2.0", + "bn.js": "^5.2.1", "debug": "^4.3.4", "detect-node": "^2.1.0", + "elliptic": "^6.5.4", "hash.js": "^1.1.7", "koa": "^2.14.2", "koa-bodyparser": "^4.4.0", @@ -74,8 +89,10 @@ "devDependencies": { "@jest/globals": "^29.5.0", "@rushstack/eslint-patch": "^1.1.4", + "@types/bn.js": "^5.1.3", "@types/debug": "^4.1.7", "@types/detect-node": "^2.0.0", + "@types/elliptic": "^6.4.16", "@types/jest": "^29.5.0", "@types/koa": "^2.13.5", "@types/koa-bodyparser": "^4.3.10", @@ -99,6 +116,8 @@ "eslint-plugin-no-only-tests": "^3.1.0", "eslint-plugin-tsdoc": "^0.2.17", "jest": "^29.5.0", + "jest-light-runner": "^0.5.1", + "mocha": "^10.2.0", "prettier": "^2.7.1", "supertest": "^6.3.3", "ts-jest": "^29.1.0", diff --git a/yarn-project/foundation/src/async-map/async_map.test.ts b/yarn-project/foundation/src/async-map/async_map.test.ts index 2ec4c3701537..e64256c4ca67 100644 --- a/yarn-project/foundation/src/async-map/async_map.test.ts +++ b/yarn-project/foundation/src/async-map/async_map.test.ts @@ -1,7 +1,7 @@ import { asyncMap } from './index.js'; describe('asyncMap', () => { - test('execute list item sequentially', async () => { + it('execute list item sequentially', async () => { const sleepAndLog = (ms: number, idx: number) => new Promise(resolve => setTimeout(() => resolve(idx), ms)); const result = await asyncMap([100, 0, 30, 1], (ms, i) => sleepAndLog(ms, i)); expect(result).toEqual([0, 1, 2, 3]); diff --git a/yarn-project/foundation/src/crypto/pedersen/index.elliptic.ts b/yarn-project/foundation/src/crypto/pedersen/index.elliptic.ts new file mode 100644 index 000000000000..60ed202521d3 --- /dev/null +++ b/yarn-project/foundation/src/crypto/pedersen/index.elliptic.ts @@ -0,0 +1,567 @@ +import BN from 'bn.js'; +// eslint-disable-next-line +import EC from 'elliptic'; + +// eslint-disable-next-line +const grumpkin = new EC.curve.short({ + a: '0', + b: new BN('30644e72e131a029b85045b68181585d2833e84879b9709143e1f593effffff0', 16), + p: new BN('30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001', 16), + n: new BN('30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47', 16), + g: ['1', new BN('0000000000000002cf135e7506a45d632d270d45f1181294833fc48d823f272c', 16)], +} as any); + +const defaultGenerators = [ + [ + 0x083e7911d835097629f0067531fc15cafd79a89beecb39903f69572c636f4a5an, + 0x1a7f5efaad7f315c25a918f30cc8d7333fccab7ad7c90f14de81bcc528f9935dn, + ], + [ + 0x054aa86a73cb8a34525e5bbed6e43ba1198e860f5f3950268f71df4591bde402n, + 0x209dcfbf2cfb57f9f6046f44d71ac6faf87254afc7407c04eb621a6287cac126n, + ], + [ + 0x1c44f2a5207c81c28a8321a5815ce8b1311024bbed131819bbdaf5a2ada84748n, + 0x03aaee36e6422a1d0191632ac6599ae9eba5ac2c17a8c920aa3caf8b89c5f8a8n, + ], + [ + 0x26d8b1160c6821a30c65f6cb47124afe01c29f4338f44d4a12c9fccf22fb6fb2n, + 0x05c70c3b9c0d25a4c100e3a27bf3cc375f8af8cdd9498ec4089a823d7464caffn, + ], + [ + 0x20ed9c6a1d27271c4498bfce0578d59db1adbeaa8734f7facc097b9b994fcf6en, + 0x29cd7d370938b358c62c4a00f73a0d10aba7e5aaa04704a0713f891ebeb92371n, + ], + [ + 0x0224a8abc6c8b8d50373d64cd2a1ab1567bf372b3b1f7b861d7f01257052d383n, + 0x2358629b90eafb299d6650a311e79914b0215eb0a790810b26da5a826726d711n, + ], + [ + 0x0f106f6d46bc904a5290542490b2f238775ff3c445b2f8f704c466655f460a2an, + 0x29ab84d472f1d33f42fe09c47b8f7710f01920d6155250126731e486877bcf27n, + ], + [ + 0x0298f2e42249f0519c8a8abd91567ebe016e480f219b8c19461d6a595cc33696n, + 0x035bec4b8520a4ece27bd5aafabee3dfe1390d7439c419a8c55aceb207aac83bn, + ], + [ + 0x2c9628479de4181ea77e7b0913ccf41d2a74155b1d9c82eaa220c218781f6f3bn, + 0x278f86b8fd95520b5da23bee1a5e354dc5dcb0cb43d6b76e628ddbffb101d776n, + ], + [ + 0x0be1916f382e3532aa53a766fe74b1a983784caab90290aea7bf616bc371fb41n, + 0x0f65545005e896f14249956344faf9addd762b7573a487b58f805a361d920a20n, + ], + [ + 0x29ff8437ae5bec89981441b23036a22b7fd5bee9eff0e83c0dd5b87bfb5bd60en, + 0x1fd247352b77e2676b22db23cf7cd482474f543e3480b5a39c42f839a306be10n, + ], + [ + 0x2f3bd4e98f8c8458cd58888749f0f5e582a43565767398e08e50e94b9b19a4d9n, + 0x1f534906d1aa8b4ba74ad9e3f85ae3f8295e51eaafd15b5d116801b96360205bn, + ], + [ + 0x27759098f425b76447c2c52728576803a1ac5de37bba875ac47cdcff539ab931n, + 0x0aa47ee64d12d856cfb81b595c1d60ceecb693f0fdae644746ff333e39f61db7n, + ], + [ + 0x015ca8d68616fde86c9108e3db04f588e0f308e60d367e963b7d460fe9a65e6cn, + 0x2cf918009dda942ac9d59903cd2d0294d8738f938b1394170d892a027d0f347bn, + ], + [ + 0x0d1783d5b256765515f3c9988df9f1ba7e6f5fb0248c8971fbc503ffd5187714n, + 0x2ebb434ff4857fc3621f3bc3c6b8002b17d02d9c204e75f19b8f0b99ea68402cn, + ], + [ + 0x300f20942e37abb19520f931f7bf7c6bbac93e4461a7789677f986e344d1f5e5n, + 0x1172a6b674c66bb037109fbb4d93d4ca8054bb9dda08839a6189eb578511116dn, + ], + [ + 0x13a6b381a663aa8a757dd386a3a8947d456874a356f52f8af1a3d84ba1067eaan, + 0x224854000fa9c70e873fb14ad7c0d01dcf6df5f30261333d6b63c78a7da5a348n, + ], + [ + 0x2b37dc5eb4c3f8cba62f0085ec131053eae6181a3e73a82e7d79764a023394ccn, + 0x27c817c1376228a3a9f5ac6caed57857a3baa580a0c1b70a17f75a6ab7e2377cn, + ], + [ + 0x26ae1cc453dab3f2cf4810cc3fb8f71257383333aa4f3ace8eb69c8ba4fa5da1n, + 0x28bfbf80541bde37e9db113ae1eb049cf163ff4ea9654d61f42a95bc2e0b17bdn, + ], + [ + 0x0e29626ab6be74417d08b28c8f8ebf02fd701e28d1d47b1961e716e735e02d12n, + 0x119f55d6bffb6bba81779eaf98f310c5661d85397b094ffbddbb41fb264b0876n, + ], + [ + 0x055cda53e781f3eedd760ba2c48c6d36d2a061544c3d33e76100bd4c65e89748n, + 0x28391e899d6407e40294faa5e5561ab472e43ea5d54c15343b9a47cb7a80ed09n, + ], + [ + 0x203c402369e8b2bc2c3827bc82a278d32c51dc9ab95e55ce1566e8b625b7bce7n, + 0x2bf25525d4a62f1252355559dd496b68ba4d6ea65f4b669bb3da73c42455f0a3n, + ], + [ + 0x2468739cedeabea49dbc46c2356bd5cf341aa4574272ba53a40d8049e5ee949fn, + 0x0e8b73bcac6b2ccffaa2e50fce992db11a0b46dcdb8ad4b8325393f903a2543an, + ], + [ + 0x242d8ad05dc6e2a8a6fd636f48eec881e05ee8d2a58e2653173f4954ec867654n, + 0x0afe0d7aa588a3dcf791f11fcdf54c1d07cfc805c5ae0b02101faafab9cb55f0n, + ], + [ + 0x05c378d0596af9f9a2471be52b7ad0112d48ef355c372088eb0db86e42887e14n, + 0x1ba1f1adb66e67bc88c1b3eafe95b202812803a8b71ca62de9ed06c8b9f3cff3n, + ], + [ + 0x04e5c213eebfffcdb42b6c371e52f0d598646cf0ca2a353b4b99889074c5a2bcn, + 0x0ae6442bc73b0f2b2d45829fd8fa321ab6b5eecdd3988a39f0c5850544de5082n, + ], + [ + 0x2c96765650bd7c3bee01114b9097b036e20d5c774afe2ba7d5d6099f498f47fdn, + 0x0879c9cc5e7eea97f1f9193e1fd08b8d0390320197dee299af1eb67f92c506a3n, + ], + [ + 0x2113980404df880af7d25a27aec16e61c770619912435b618914da7fa1a88385n, + 0x106827183994d8da15037851748b05392620516277bf0000f8b38e97f5db602an, + ], + [ + 0x13b4c5f15cc69af871b91e862db8b0044834c5e8da5a287d0794342bb97ffca6n, + 0x17941f13343835b572e18d37ab3897f80e0461f9b72ab61da61927fc980a6bd2n, + ], + [ + 0x085c0f69b19e05986883dcc9d53334bb6799968688935d938cebd4b4455f9187n, + 0x242b8a5ab074d09e26427b1b6633a79a82ba41d64c4d658017f3186d6926721bn, + ], + [ + 0x1bb111daaf71e632a4c9244a362bdde16a5efc5e7c7dda42b20f3290c2776d2cn, + 0x2b4506bf741b2dc59f71f7036716cac04b6f808b4ca1469eb2fd7bccff5882c0n, + ], + [ + 0x1a76ba8ca6b8e2c65915521b175da98137dfcaf0b5faff1019f37afce77c99ean, + 0x1894c8c79e69e52a495bf6fe467aa4f5bdbe606490d6803df325a075c5b0079an, + ], + [ + 0x2fea40a9bfb252ba7e192be641a4051381982719b77d567caee2657f36b701abn, + 0x1e80d5ea79b50a722e65ce274b8ba2a133de94b757ef71b452183ee958c620e1n, + ], + [ + 0x217c100e6cd64b68e91fe26e90eda02eaa505859201253bd5e550e0bb8f0f29an, + 0x12a5c4fc942353f962bc5b97f36b9a326d5dbb6c505266d2a016415d8da0be65n, + ], + [ + 0x2f50fc293e4529108595329b6e7b0110c0db563927bd57a169e81884535660f9n, + 0x03547f619f9c30a761963381fe31f031ecd5b393d2281455a66e01aff0896338n, + ], + [ + 0x06e0f1aab04c530ed9e9584b7c06cb40d6dbd1752313b1bf8498accb8227e743n, + 0x2b47e83f03e635a9c20eb0d6412955dec1578a197c7d51f648550623ac5b3baen, + ], + [ + 0x1dee7c6f5d7527d26da506eec28cc3b71acf9a8e694567749dc5e6b073748632n, + 0x235955a911e3744859c1db3996aa1f0f64424f67c2ef1c8fcc8c767af5749068n, + ], + [ + 0x1e5aa70095a858d1c4153691e91c19f01a883f422efc19ec766c86bc416ceb2an, + 0x0f1e06c820067d8d0af14cf87633c1bd761d65bc5b3889a17bae7d70d2b19f5dn, + ], + [ + 0x2f4d8f60344443350f226f19c4b01e2198f6b475b0291dd2e0c3981e3797a5e0n, + 0x1aaab92caf692c5fb89e6eab983f26ebe009463c1ddece0a650508994cb84a82n, + ], + [ + 0x06e0aba4044a552343f7ba02f234dafe4ccca7fd552342a8493ce544758df012n, + 0x243269273e7c7ee7a50288f282cb6a7169ec2aac03d2ff7b40463638ad5722d5n, + ], + [ + 0x1aecf2ef53262227e12a9ca29ae7f14be031c03488a7604a03cdc77115f26136n, + 0x0753180b7d445c215d55dbfd6ebfb1c6aabd690ac92fd76cea5144ef3c9a8b3fn, + ], + [ + 0x207d50d783c727a979303bc8f50538ad75e5f856180d4f3dc2c7ee186916cef8n, + 0x20155253cd087a980aad326564240cca45a72c888e69395e4d8f5ca3d2b96e0an, + ], + [ + 0x21db09b3c2c299f1b0be7a8f3031fd283cd5f1efca0a468b7ea9a0f170e81fc7n, + 0x21b50f8107353afc7a1656040c9888ee393608420d88c2a07f34293fb609a26dn, + ], + [ + 0x02190016f4cc44935d100bc7b7dae46cea5922261e9889112cc815fafd5c45ccn, + 0x01dfaacfa00ddb9133042d9833d1201172f69a456f0c9483d0b58e5f01b571fdn, + ], + [ + 0x04e67573df0c1591ec51d2f60b74f1964abeef3e201084425a55cd71ffe0b4f8n, + 0x1f0285b2ede69aff961919827312afad0753c112cab001cb28ff6c2c27f277c6n, + ], + [ + 0x092450548d189dfe4e852370c17343aeef92ac3a8fbdeb8fdd244f87d3af03cdn, + 0x23e3c53d9265d6debfdb40988a908e64673b2f87b1fe2a08b56c6a3fcf84f5d1n, + ], + [ + 0x2935be388ee1365bf6a9cc6fd25d130607835dbf7926c5cafed690b9072cd316n, + 0x059edfbc50a9699e29b975a2fc3bfe7855997e708ce82fa30ed19cc91850f6ccn, + ], + [ + 0x21cc891713fb8570152149a9fbb23410d7c42dece266bc6093650e46111a465cn, + 0x248f486105ee09f447e7e0ff522b5ff1db5f64522f2bbbb28e7a07595cff3e79n, + ], + [ + 0x147f06fa12cbb8d1c98f9c06d57899e20d9651bb8da104ad5168c9be10d4419fn, + 0x2766f677196fb611814f5d7af22aa8555c3c65b572151576b116df5b9f05857dn, + ], + [ + 0x0143beefa7f0b8fb72262a3c3d1502a36d8b4cb35befbb37dba3a70ffe2571c7n, + 0x1808ba6988bbb8585b77765760fb2afccdfe4946702043a46b8d461c7d211b11n, + ], + [ + 0x1ac3c1edb1eddd9c5011f88769fac4050aa8820de1f84fcda7e400f87028ba3an, + 0x050cbb4da87ecd3f0c84d6252e76e19b3678b955c603f35abdcee3b988a57fa4n, + ], + [ + 0x05a7092c674d8f44add477edf7369dc7bcb9da4d1b903fd58dd8bd4d166de73en, + 0x182545ce8ba6fa781823673d50fc62c7d1bb5f3515da6e5c2bdfd7248f311e1bn, + ], + [ + 0x0154a12dbf3fd3ae8957fe154f378630c12306eb55425d9732e0ae2b56ca0306n, + 0x140688ffb0de33c9625e323a13e9df6fb37c841b34c4b18b7e19d51792d393ccn, + ], + [ + 0x2fcdf4e4b421286df484fdd08725ffe53728759508f74f0d87e65bd932af28d4n, + 0x25f57213413f9f0982573c4a6640efe32b612c6c8f0b027425260c4629d38b21n, + ], + [ + 0x203ed9a7ff1ef21910003e658dbff87a3e10da7782de00af71995c233587961dn, + 0x0c7ae4445018e5d451f197d7881b1b95fb66574c26ff6967a37c1eab5f907a08n, + ], + [ + 0x131abdc8d6c6319aeee7e8b186ace3c07d140eb4037b21285b2260cd7bf310f7n, + 0x2371e4c2b73ce0af013b30ee9f434584742cdd7e91f1d842c1a6a95bd12d915dn, + ], + [ + 0x124029864085263e79448fdeef91ee2ea5a4952637646b02f132c1ac917edbdan, + 0x29d11c62ccfca5d8328e5171466137e6cfd19d56bdc3bbc4633a0aed34a90e69n, + ], + [ + 0x1ded46fcf96cba70ac0cb4ca58348c90041b257232e476acd236b45271413fben, + 0x26d04c6660ab9693743bf5c5fcf13047860dfeed3dd903e6ff6fe917fddf73fbn, + ], + [ + 0x2b31b48b7313f6a5c3f1f59fe9ad3d4b8900d873056af1691d143208eb5c8790n, + 0x27cec87606fe5f9562a3d0b1fef90da3e8d17721c668c342b681468a501deff3n, + ], + [ + 0x22080b093f3b3c98f9afc52b80594dcf51a714e77c40c3a08513897d73a70806n, + 0x1cbcacedf498eaebd03b602c4908c165c50ba184230c7c52244c9a5d0e9759ebn, + ], + [ + 0x0560b3857af53bc7262482310593e316543551ee57417583161bfce9d12a4d40n, + 0x2c91b186a9740d4b9f49c8889878381833cc5b5fe29e6e83affa2916e2008988n, + ], + [ + 0x2cf006347b380b6e0eb766ebdd1d24dc1eed9a43c206ee58e9457303d509c308n, + 0x03d11688f54726466399ddce8523148453cd1b6cad3cd414ee6e2af66a6b6addn, + ], + [ + 0x2e5c7e4d9a6069892bac121490fee89df1c238c7738c9f3ab599d6b4cc2ff491n, + 0x0f3c26f5de9ad898d4a4b1a08d1e87fd5cf4362f9796fb8715c60d431902cd54n, + ], + [ + 0x15298a52895eb8c9399509dc1f0ef68a90afc29084d3a0cec6956c8420819b5cn, + 0x2dc0ccd80f1bbbdf364f5b912a961332d9f5db54763745b64e0d85e33faf87c7n, + ], + [ + 0x132026c02d21e2ccabf1338f0d93f4223ecca5f0f2a96208561c9d5a5ef79c88n, + 0x09224bf821c64b105233fb98964f9ee0d3365f59e054c4693492ac07956d5c87n, + ], + [ + 0x2d6c6f3d040ad0c71760e8139ed3aef03c01d86e03f4ff0919f97899649d4bden, + 0x1a186b79fdcea1c8bb184097418bc68279fc5f682c48f5f21809bd2087944935n, + ], + [ + 0x1d69440baeb72617846c275fd817a4dbf9a8d39ddd38ca87b6a9e54ec6cc2adcn, + 0x239c44e43c9a91c9d126e745b949bf87844de4f2775aad804f81b8dcd3c232c7n, + ], + [ + 0x1e80e18c68865cf7bfcc6964613ba1aa1ae749a2d6154288d9572f022b2a4dd5n, + 0x1fa00a74773c3214ed7dfd125c82192d4c24ce557f720c98827aeec194dc9a30n, + ], + [ + 0x01b1362ee72c3e3ef5d63f67b54a6c5f547db48126b640fc8356e4cc19382dd3n, + 0x13e340c7dea9488aa6f9fe7443d7d1aa4b937800dd213c8bb4b301ba4a1a583cn, + ], + [ + 0x21f121f9754a315b922f8464a6cbe5a9fe191f30cbd2218cc4997c3d028fa52dn, + 0x2b8e094f90ea155bd675e389c69c3b021095801905efcfbcfeced8d7e25d6e96n, + ], + [ + 0x0d03c9e026afecdaf0f1b68679faf85830f2e16edf65c80c04b032441935e7b1n, + 0x18a285be0228b819cdd475d2f08192c02a998c85802b10d0ab3256fe367d9cf3n, + ], + [ + 0x12db390e5305fd19780de901727bb248778b6077f75ee6f8ae9c2b8629a8c037n, + 0x16952c652e2719fd93571b55357e6533410e2cb115cb970676c5d08a39d1be87n, + ], + [ + 0x04598dbf51d48775d7acafd239192aa850b72785472238e79f65a89292ac238bn, + 0x06872dca2aac431fbcb2fc3196b516bb791afb6136cc457b3aeeb85d1b02e4ecn, + ], + [ + 0x015ae13d6981f433340a44f9d33ebfda3b7108fbed96fabbbdd96e95b9f2cf23n, + 0x269b90e34244790294b66b9699510444a01ef16661fa80a2a41d368c6371af4bn, + ], + [ + 0x0a3d1c57e4d12a2041a41cc6483b63d8616af9b11a272535e3c88a4bb0f293a7n, + 0x092cf2eec8c9c1cefcaac51028875fb2f9abc46d111c852466d479edb244d852n, + ], + [ + 0x054e837ebc7a6b5142d527fd0e0b052aca6b91dd6dc4827e0196acea8bd04af5n, + 0x294164cfdfc4ddde270ccef912a1ac370f1aced76d933f702937db9ae0f6ab13n, + ], + [ + 0x1d175a456220eaa15ac082acf8a910da24751810edad87b1d558e229064c8da4n, + 0x1c0db158fb28522527eeffec568c97f8b7bc7a3927d1ba93ffcdab8de75e7ecbn, + ], + [ + 0x254c3c07450ac82ed0479ce88ace7cc5223b7cdc07557c234620d006df28fb09n, + 0x09e22217e07537054ab2c6c3947690ec12620ab0f0e7d03b023f51160c1df68dn, + ], + [ + 0x1cf4eece13e6e8b9bfd4644614cb0df16b38f76e70b11b4e72c283bc47439ffcn, + 0x18fcd0501cc6d30faf81f21b62ab175d5b5fff6b16a80b23700c9094ee3f779an, + ], + [ + 0x2ca6acd35e2ff4527399a13876563461726f08e629bd5897dfbf9a576f4d6641n, + 0x303c6102e21ec7518cc4181436345be6af5916b8f604bb1054c02d5ee1362c6en, + ], + [ + 0x037612d11f47ede28098ea80adef547f4912031fd236c9a7e5d5cdf00ba4911fn, + 0x0d547e26bf94386d4ba5a69caa4baac73aaff2bf4abdfadaaa42b892cfa033d8n, + ], + [ + 0x2494d804f242aa8a8a7e5eaf09829b04b4c7690c810a5ab01d3fbe2dae54a1f3n, + 0x093b3e5ca5fdfdb2e58ba6649e9c13f97b79d8e7f4cf65e3255b98a14689c94an, + ], + [ + 0x020c10d95e90a551134c8ad77cfb5f11465c23efd81c7713efe22ad54c048403n, + 0x03eea8fd0ad7fc2ea2eae6a082bb199959a6a361f7e8865d251d6ff547c15207n, + ], + [ + 0x0e274ceca67b5c0ff0b8774e5c8adb780b62e3e4a1065b190c2c28da6c808f50n, + 0x21c6675fbe4ae752919ab3f92f412394c138807af9adc3a5dd81400a83db3bc5n, + ], + [ + 0x0158f7157c016635f6f878fb58e1b59f2741a2315939fea4536e056bb7f35ce7n, + 0x20b454ec327caab24f39f8eb5caf9eda33a9274a8f4bab8f03de09a3c176e7d4n, + ], + [ + 0x1fee261ad59b9bb95733b499820beb21ed40156dc89dea7f02739661eafd81a5n, + 0x003e98b3f725336c5a13aeddb2e2c1e894860365915d06733d847f3a01dced7fn, + ], + [ + 0x237e59a6bfc3ff0e1f5fada642d1d1a5c349502bed14f64a6c5b03caf3975008n, + 0x2362bf67d5eff33ec19af5ef915557363bd3aa313f3610bd6b1a93cf6bd8b045n, + ], + [ + 0x0204a6de6d1e5243dabb6485d5eb0231aa1487f417f7677fb56f398269b07fefn, + 0x01b9bbb78a97b65bd9854d56e5bd50be8ca60f18b73f012ef28775ef3fc0901bn, + ], + [ + 0x18ad002f659998c9bd8543361f97a2a454e5b87aa62893406298f3e37f2720ben, + 0x227bd053f0ba47f463cee2caa96c4d00516f579a1646ec4a2a70dc1700b06a50n, + ], + [ + 0x03a74f956daea99179061720902ed0f3206c92f215fe1dc2b1a10545803a99e9n, + 0x2a279b91188c2bd770f5b23f0cc724ec9eab26971db684d4d8a1623e150d0e4cn, + ], + [ + 0x26b3364b6285c48a552b5f1a977d9be8728a8493855bf5acc49d5815af84dd2cn, + 0x1898136f0513c863a49ba1b27f7de7452f004ebe7409dfae1f28966f918e6ba4n, + ], + [ + 0x2ead9bee2969459504a0fa26e953a7caafe76dee6da60ca921e9f78743378589n, + 0x0934d50a9d9007be2e47f077044775b50d33438443853dc1e81ba011816faccen, + ], + [ + 0x03b638cfae5057787fc620d2a8fa257b7126603402dade0789093853eca1b6a1n, + 0x1e57da2d7d7c7087e58b74ae04e3be194424a64e21ee94feb20859dc1f65438bn, + ], + [ + 0x1253e8cce9c54cc1f0c2f38eb583f48f7421b516ff629c9764bc187f768cb0d3n, + 0x1164460615286ea5972631b0e2d96f68cdbf17c327cd1a0399666e34950375a3n, + ], + [ + 0x0de7b3c645363ac23ff2c8af302e995251419b52ea1936cf58805b589485ed08n, + 0x29ac530d28441b612678ff86c9f48cbee512260e21aacb7ae1a6abc05d0df10fn, + ], + [ + 0x11ee0a33439f8e1da5fbaec6ad6368a2c1ecd2590ebe06bb0269a2c28bd389a5n, + 0x0d37b9e16c881409be41d42601fdaecfc7b67bca0f088eb0bef1c4e4c428a1f1n, + ], + [ + 0x00ef4d130e14eb610f533b395d18db4708b4154a689cd4acddac1f1b43ed6854n, + 0x2c485355a6a340b718e1a20206ec5c55da5dacc9045d3454b2947b759a1401ban, + ], + [ + 0x0b2500eddb982dc3ef2728e010260a5e33aa06e6960ac8d3926e3e4b441c978an, + 0x023919ab917efd33a4e07c3da64b5c0af384c7487e23333c43c4b62a315014cbn, + ], + [ + 0x2e9eb27d5d8f60d282cf0866e4f0fb92d045388f1d227852f85c1518dddc503an, + 0x1f0edc2cc1602d4f66b658f676446a7ebd3bab1a08cfe60184390600c2b0044dn, + ], + [ + 0x05c545ab45ef4d781e551674ce7027668b384667c7e3e04be02a921410223713n, + 0x0e8988769b7f561fd70e9a761c198ab9d5807fbe6ecd327241a8f10815ac4d76n, + ], + [ + 0x252896bd06ea09d5260c6053b96a3c9f0fe2bf520debabc1422b298e1b823ff0n, + 0x0beba0fe2d2ed0e028356ae129ba2a444a871a7aad25d5e90fc022b963e0c5e3n, + ], + [ + 0x17c2b8543fe3ba1042342557072eb30e941f8b93c879512e590a761454458694n, + 0x2de5011cc9b603ba43cfcc082671de63da3de9b9f0021879e7f482058f9fae0fn, + ], + [ + 0x0792855505a783cb49f954bccca6120e8990a7092b4ab0bd08168203932c7bacn, + 0x09e95a4c731b378b80991239ff87b90ba00b9439c287dbf01aaac56f05aa550dn, + ], + [ + 0x0d4beeb972497603c3a1d7d7ad79c45615f12844a530580ca2de18ef8fa1b1efn, + 0x004998039050599d55e744c51f8846dbc7db25a8318abcaf217ae68bff075d77n, + ], + [ + 0x12c6d0a3726a805bc04506282ce0218ce5de5386b1eb4aaa893722fe80983688n, + 0x2394def51425f2cee78f4ac1f0c04e25b60d1fdc9e84bacad67500f7ebcfca34n, + ], + [ + 0x1a19096c5c3522d45e2827449adef54d91287ede96b3d39818da08a0b93e9dc3n, + 0x27a0dde36f91156a87d746a58477553ec138d108fb471f157175e22a75a495dbn, + ], + [ + 0x0b7748b109ba5798a8d2803be7fd015f2ca5af9eaad8ddddde16d50a07a7bc10n, + 0x12214803947f2969d86455b1a47213f04a9309620d9692ec91114237acb84eebn, + ], + [ + 0x0c02dbea3ecb6bacc7390d53b6fe23feb49a58c571d95d01fabac5a42489a7can, + 0x0d73b846a5cf707f3e5abf9ba2b4f5602a55b5fbad7fbd7bd9b9ab48977c1005n, + ], + [ + 0x169623c619bc3ac95ec3315d5e01afecebafb1931826551b86c007070001fe90n, + 0x00cb91b18d7097d4fa2d7600ae1bf31a3b4df9479e39f1bf23f231773258ea3cn, + ], + [ + 0x0fd5b9f9d183b6da8ba0f99503e851450b3efb33c6a7807a6239e0707b5af271n, + 0x2a4153eb0395955d7d7ee71519d1d600bc32dd39b6283224fbc92d23b860eb54n, + ], + [ + 0x1209e1604a9b10afde568fcfe0ea9f1e09cdf13fe17747abeff0a1454dcf947bn, + 0x0e1d63b8ab7b9a4a7ef8d3d17207dcbbc22e9c21da661ddfdc1ac961e0032b57n, + ], + [ + 0x2982c7c825f0e86293b7a0c9eefea7f5383e222a054ffa4c5d4e5908c543c2a6n, + 0x151b990dec385eab48210cd7766d2de58eba95ff76faeee4eb64e6f3dbd3c139n, + ], + [ + 0x124faaed649b6df79325991151fb88952c9acfd57a6b3cb20b18f2fe63529818n, + 0x229dfd4712f46fe904c28adccd1165786e96baaa2c74a0a7744dbb4ab4300d41n, + ], + [ + 0x0963070c9042bbbbe66468d9e75a719123b52b76ee9797f4b039b5de1b5c9651n, + 0x06aa3729a947ec02394d82a46a0c2c2f8e2013e15f46cc97b96944937da731d0n, + ], + [ + 0x279040e3e8f1e0effaf0450099574e134c3eef819f04cadff27851de962da0d3n, + 0x1ee7f53a1b21c4fbd2ef56895bc274e520140858ba51eff6968eae9d0a03a2f8n, + ], + [ + 0x0502d68753a132e8b268e02362166d6c0e43494aef2a5173eff138aadfe05ad0n, + 0x21629dc5334c80a75f79a4b75169c40bb6eb665796a8c4d1024231cbc4604f1en, + ], + [ + 0x13edf560ae7a1c78296f4609233337cd8fbb009b22d89a27d2e5c94983095fe9n, + 0x039c043f9ac7c68faf473565cdcb51785597c90d8ba14dd8e577bf14d70c53e5n, + ], + [ + 0x075a3019dc700efd12e8b91be0029407d59c3dfeeeced4d8f8d35fed14900d79n, + 0x073d003f8998a46ba32780d2e50c2a287b6902ecb2b82672a817980666c406c1n, + ], + [ + 0x1e8509ab9d961e5dea389e1498be69790390a5f77c7dc68cc55858207ece11c5n, + 0x19979a1f1a22dc051a45427d70f66fc27c064fd451b64b6b609d74f0a6439b2cn, + ], + [ + 0x0dc528103070ee030c96bdfe9004693f52a22042abad186aba5616918c701f56n, + 0x05f194973a699889fecfedf291c50be0526c35c22faba00aec84b967e1a0f278n, + ], + [ + 0x1f795886933d543108a9cb86291f04ba487cd95fb6ff9a062d8e6ac9f267d3fan, + 0x127fe0e1209741e32c0a093bada5517cbab952de68241df774b6ddeabc2a6397n, + ], + [ + 0x156c18df6da11a7f9657751e43b50abea544017d347f27406cf4751e51a81e42n, + 0x28e38ee1433b9eefac4b22ba5d88f1d7979d1fce9920d20213b1c01fb204f725n, + ], + [ + 0x2341ce02c131e47cec7777567cc7996ac3b6fd6255ba880ba819ae4982465becn, + 0x0913340a3a212e4e0adb678d500a70e99e24f7a8370cab3b92df8cb6ec2766f3n, + ], + [ + 0x2ee690cd26ee66b12bfe6a7d4fe3077a8c2a41ce96216a964c1a94227b0cb8f9n, + 0x1e207e2e40816da78ca89b8d98f0ada6208f014beef4efec812f629d42e5e304n, + ], + [ + 0x086d9eebd9fbb9b6394cb155b8ee9e3558857f65053abb4a04c6d956d1fdfe95n, + 0x08deaf603a5fee68ccbf892f95f787dd437283b46362a9071ee1e73ec4e03edcn, + ], + [ + 0x0f63792ebcefa16d26dbfeb58db005dced755740bd047de3fde3013575b57022n, + 0x1cbd79e5b8ac132920b495e66d47f2969df49423452a34336796d152ac7de76bn, + ], + [ + 0x05f6732fe8526a3340e547d2a19a97a5c4538a94ce607eb0909db67c8880bdedn, + 0x1e0bbf2a4e501a83460c96e919bec020187f51ce94c328b3b38b07f34dea2cb2n, + ], + [ + 0x1f1df03870f616146c84545722f1e8064bc9db8180caf35061367af95445bb3fn, + 0x077004e054257d7389065f3f11be644084b357c1b9214a9869d5b6761ccee13cn, + ], +].map(([x, y]) => grumpkin.point(new BN(x.toString(16), 16), new BN(y.toString(16), 16))); + +const lengthGenerator = grumpkin.point( + new BN('2df8b940e5890e4e1377e05373fae69a1d754f6935e6a780b666947431f2cdcd', 16), + new BN('2ecd88d15967bc53b885912e0d16866154acb6aac2d3f85e27ca7eefb2c19083', 16), +); + +const pointAtInfinity = grumpkin.g.add(grumpkin.g.neg()); + +/** + * Create a pedersen commitment (point) from an array of input fields. + */ +function pedersenCommitInternal(input: Buffer[], generatorOffset = 0) { + if (generatorOffset + input.length > defaultGenerators.length) { + throw new Error('Pedersen commit overflowed default generators.'); + } + let result = pointAtInfinity; + for (let i = 0; i < input.length; ++i) { + // TODO: WARNING! Merkle tree tests fail if we don't reduce modulo p as they feed in 256 bits. + // Is it right that we accept 256 bit buffers here and reduce mod p? Is the right thing to only accept fields? + const ie = new BN(input[i]).mod(grumpkin.p); + result = ie ? result.add(defaultGenerators[generatorOffset + i].mul(ie)) : result; + } + return result; +} + +/** + * Create a pedersen commitment (point) from an array of input fields. + */ +export function pedersenCommit(input: Buffer[], generatorOffset = 0) { + const result = pedersenCommitInternal(input, generatorOffset); + return [result.getX().toBuffer(), result.getY().toBuffer()]; +} + +/** + * Create a pedersen hash (field) from an array of input fields. + */ +export function pedersenHashWithHashIndex(input: Buffer[], index = 0) { + const result = lengthGenerator.mul(new BN(input.length)); + return result.add(pedersenCommitInternal(input, index)).getX().toBuffer(); +} diff --git a/yarn-project/foundation/src/crypto/pedersen/index.noble.ts b/yarn-project/foundation/src/crypto/pedersen/index.noble.ts new file mode 100644 index 000000000000..d9ae4080114f --- /dev/null +++ b/yarn-project/foundation/src/crypto/pedersen/index.noble.ts @@ -0,0 +1,573 @@ +/* cSpell:disable */ +import { Field } from '@noble/curves/abstract/modular'; +import { weierstrassPoints } from '@noble/curves/abstract/weierstrass'; + +import { toBigIntBE, toBufferBE } from '../../bigint-buffer/index.js'; + +const grumpkin = weierstrassPoints({ + a: 0n, + b: 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593effffff0n, + Fp: Field(0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001n), + n: 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47n, + h: 1n, + Gx: 1n, + Gy: 0x0000000000000002cf135e7506a45d632d270d45f1181294833fc48d823f272cn, +}); + +const defaultGenerators = [ + [ + 0x083e7911d835097629f0067531fc15cafd79a89beecb39903f69572c636f4a5an, + 0x1a7f5efaad7f315c25a918f30cc8d7333fccab7ad7c90f14de81bcc528f9935dn, + ], + [ + 0x054aa86a73cb8a34525e5bbed6e43ba1198e860f5f3950268f71df4591bde402n, + 0x209dcfbf2cfb57f9f6046f44d71ac6faf87254afc7407c04eb621a6287cac126n, + ], + [ + 0x1c44f2a5207c81c28a8321a5815ce8b1311024bbed131819bbdaf5a2ada84748n, + 0x03aaee36e6422a1d0191632ac6599ae9eba5ac2c17a8c920aa3caf8b89c5f8a8n, + ], + [ + 0x26d8b1160c6821a30c65f6cb47124afe01c29f4338f44d4a12c9fccf22fb6fb2n, + 0x05c70c3b9c0d25a4c100e3a27bf3cc375f8af8cdd9498ec4089a823d7464caffn, + ], + [ + 0x20ed9c6a1d27271c4498bfce0578d59db1adbeaa8734f7facc097b9b994fcf6en, + 0x29cd7d370938b358c62c4a00f73a0d10aba7e5aaa04704a0713f891ebeb92371n, + ], + [ + 0x0224a8abc6c8b8d50373d64cd2a1ab1567bf372b3b1f7b861d7f01257052d383n, + 0x2358629b90eafb299d6650a311e79914b0215eb0a790810b26da5a826726d711n, + ], + [ + 0x0f106f6d46bc904a5290542490b2f238775ff3c445b2f8f704c466655f460a2an, + 0x29ab84d472f1d33f42fe09c47b8f7710f01920d6155250126731e486877bcf27n, + ], + [ + 0x0298f2e42249f0519c8a8abd91567ebe016e480f219b8c19461d6a595cc33696n, + 0x035bec4b8520a4ece27bd5aafabee3dfe1390d7439c419a8c55aceb207aac83bn, + ], + [ + 0x2c9628479de4181ea77e7b0913ccf41d2a74155b1d9c82eaa220c218781f6f3bn, + 0x278f86b8fd95520b5da23bee1a5e354dc5dcb0cb43d6b76e628ddbffb101d776n, + ], + [ + 0x0be1916f382e3532aa53a766fe74b1a983784caab90290aea7bf616bc371fb41n, + 0x0f65545005e896f14249956344faf9addd762b7573a487b58f805a361d920a20n, + ], + [ + 0x29ff8437ae5bec89981441b23036a22b7fd5bee9eff0e83c0dd5b87bfb5bd60en, + 0x1fd247352b77e2676b22db23cf7cd482474f543e3480b5a39c42f839a306be10n, + ], + [ + 0x2f3bd4e98f8c8458cd58888749f0f5e582a43565767398e08e50e94b9b19a4d9n, + 0x1f534906d1aa8b4ba74ad9e3f85ae3f8295e51eaafd15b5d116801b96360205bn, + ], + [ + 0x27759098f425b76447c2c52728576803a1ac5de37bba875ac47cdcff539ab931n, + 0x0aa47ee64d12d856cfb81b595c1d60ceecb693f0fdae644746ff333e39f61db7n, + ], + [ + 0x015ca8d68616fde86c9108e3db04f588e0f308e60d367e963b7d460fe9a65e6cn, + 0x2cf918009dda942ac9d59903cd2d0294d8738f938b1394170d892a027d0f347bn, + ], + [ + 0x0d1783d5b256765515f3c9988df9f1ba7e6f5fb0248c8971fbc503ffd5187714n, + 0x2ebb434ff4857fc3621f3bc3c6b8002b17d02d9c204e75f19b8f0b99ea68402cn, + ], + [ + 0x300f20942e37abb19520f931f7bf7c6bbac93e4461a7789677f986e344d1f5e5n, + 0x1172a6b674c66bb037109fbb4d93d4ca8054bb9dda08839a6189eb578511116dn, + ], + [ + 0x13a6b381a663aa8a757dd386a3a8947d456874a356f52f8af1a3d84ba1067eaan, + 0x224854000fa9c70e873fb14ad7c0d01dcf6df5f30261333d6b63c78a7da5a348n, + ], + [ + 0x2b37dc5eb4c3f8cba62f0085ec131053eae6181a3e73a82e7d79764a023394ccn, + 0x27c817c1376228a3a9f5ac6caed57857a3baa580a0c1b70a17f75a6ab7e2377cn, + ], + [ + 0x26ae1cc453dab3f2cf4810cc3fb8f71257383333aa4f3ace8eb69c8ba4fa5da1n, + 0x28bfbf80541bde37e9db113ae1eb049cf163ff4ea9654d61f42a95bc2e0b17bdn, + ], + [ + 0x0e29626ab6be74417d08b28c8f8ebf02fd701e28d1d47b1961e716e735e02d12n, + 0x119f55d6bffb6bba81779eaf98f310c5661d85397b094ffbddbb41fb264b0876n, + ], + [ + 0x055cda53e781f3eedd760ba2c48c6d36d2a061544c3d33e76100bd4c65e89748n, + 0x28391e899d6407e40294faa5e5561ab472e43ea5d54c15343b9a47cb7a80ed09n, + ], + [ + 0x203c402369e8b2bc2c3827bc82a278d32c51dc9ab95e55ce1566e8b625b7bce7n, + 0x2bf25525d4a62f1252355559dd496b68ba4d6ea65f4b669bb3da73c42455f0a3n, + ], + [ + 0x2468739cedeabea49dbc46c2356bd5cf341aa4574272ba53a40d8049e5ee949fn, + 0x0e8b73bcac6b2ccffaa2e50fce992db11a0b46dcdb8ad4b8325393f903a2543an, + ], + [ + 0x242d8ad05dc6e2a8a6fd636f48eec881e05ee8d2a58e2653173f4954ec867654n, + 0x0afe0d7aa588a3dcf791f11fcdf54c1d07cfc805c5ae0b02101faafab9cb55f0n, + ], + [ + 0x05c378d0596af9f9a2471be52b7ad0112d48ef355c372088eb0db86e42887e14n, + 0x1ba1f1adb66e67bc88c1b3eafe95b202812803a8b71ca62de9ed06c8b9f3cff3n, + ], + [ + 0x04e5c213eebfffcdb42b6c371e52f0d598646cf0ca2a353b4b99889074c5a2bcn, + 0x0ae6442bc73b0f2b2d45829fd8fa321ab6b5eecdd3988a39f0c5850544de5082n, + ], + [ + 0x2c96765650bd7c3bee01114b9097b036e20d5c774afe2ba7d5d6099f498f47fdn, + 0x0879c9cc5e7eea97f1f9193e1fd08b8d0390320197dee299af1eb67f92c506a3n, + ], + [ + 0x2113980404df880af7d25a27aec16e61c770619912435b618914da7fa1a88385n, + 0x106827183994d8da15037851748b05392620516277bf0000f8b38e97f5db602an, + ], + [ + 0x13b4c5f15cc69af871b91e862db8b0044834c5e8da5a287d0794342bb97ffca6n, + 0x17941f13343835b572e18d37ab3897f80e0461f9b72ab61da61927fc980a6bd2n, + ], + [ + 0x085c0f69b19e05986883dcc9d53334bb6799968688935d938cebd4b4455f9187n, + 0x242b8a5ab074d09e26427b1b6633a79a82ba41d64c4d658017f3186d6926721bn, + ], + [ + 0x1bb111daaf71e632a4c9244a362bdde16a5efc5e7c7dda42b20f3290c2776d2cn, + 0x2b4506bf741b2dc59f71f7036716cac04b6f808b4ca1469eb2fd7bccff5882c0n, + ], + [ + 0x1a76ba8ca6b8e2c65915521b175da98137dfcaf0b5faff1019f37afce77c99ean, + 0x1894c8c79e69e52a495bf6fe467aa4f5bdbe606490d6803df325a075c5b0079an, + ], + [ + 0x2fea40a9bfb252ba7e192be641a4051381982719b77d567caee2657f36b701abn, + 0x1e80d5ea79b50a722e65ce274b8ba2a133de94b757ef71b452183ee958c620e1n, + ], + [ + 0x217c100e6cd64b68e91fe26e90eda02eaa505859201253bd5e550e0bb8f0f29an, + 0x12a5c4fc942353f962bc5b97f36b9a326d5dbb6c505266d2a016415d8da0be65n, + ], + [ + 0x2f50fc293e4529108595329b6e7b0110c0db563927bd57a169e81884535660f9n, + 0x03547f619f9c30a761963381fe31f031ecd5b393d2281455a66e01aff0896338n, + ], + [ + 0x06e0f1aab04c530ed9e9584b7c06cb40d6dbd1752313b1bf8498accb8227e743n, + 0x2b47e83f03e635a9c20eb0d6412955dec1578a197c7d51f648550623ac5b3baen, + ], + [ + 0x1dee7c6f5d7527d26da506eec28cc3b71acf9a8e694567749dc5e6b073748632n, + 0x235955a911e3744859c1db3996aa1f0f64424f67c2ef1c8fcc8c767af5749068n, + ], + [ + 0x1e5aa70095a858d1c4153691e91c19f01a883f422efc19ec766c86bc416ceb2an, + 0x0f1e06c820067d8d0af14cf87633c1bd761d65bc5b3889a17bae7d70d2b19f5dn, + ], + [ + 0x2f4d8f60344443350f226f19c4b01e2198f6b475b0291dd2e0c3981e3797a5e0n, + 0x1aaab92caf692c5fb89e6eab983f26ebe009463c1ddece0a650508994cb84a82n, + ], + [ + 0x06e0aba4044a552343f7ba02f234dafe4ccca7fd552342a8493ce544758df012n, + 0x243269273e7c7ee7a50288f282cb6a7169ec2aac03d2ff7b40463638ad5722d5n, + ], + [ + 0x1aecf2ef53262227e12a9ca29ae7f14be031c03488a7604a03cdc77115f26136n, + 0x0753180b7d445c215d55dbfd6ebfb1c6aabd690ac92fd76cea5144ef3c9a8b3fn, + ], + [ + 0x207d50d783c727a979303bc8f50538ad75e5f856180d4f3dc2c7ee186916cef8n, + 0x20155253cd087a980aad326564240cca45a72c888e69395e4d8f5ca3d2b96e0an, + ], + [ + 0x21db09b3c2c299f1b0be7a8f3031fd283cd5f1efca0a468b7ea9a0f170e81fc7n, + 0x21b50f8107353afc7a1656040c9888ee393608420d88c2a07f34293fb609a26dn, + ], + [ + 0x02190016f4cc44935d100bc7b7dae46cea5922261e9889112cc815fafd5c45ccn, + 0x01dfaacfa00ddb9133042d9833d1201172f69a456f0c9483d0b58e5f01b571fdn, + ], + [ + 0x04e67573df0c1591ec51d2f60b74f1964abeef3e201084425a55cd71ffe0b4f8n, + 0x1f0285b2ede69aff961919827312afad0753c112cab001cb28ff6c2c27f277c6n, + ], + [ + 0x092450548d189dfe4e852370c17343aeef92ac3a8fbdeb8fdd244f87d3af03cdn, + 0x23e3c53d9265d6debfdb40988a908e64673b2f87b1fe2a08b56c6a3fcf84f5d1n, + ], + [ + 0x2935be388ee1365bf6a9cc6fd25d130607835dbf7926c5cafed690b9072cd316n, + 0x059edfbc50a9699e29b975a2fc3bfe7855997e708ce82fa30ed19cc91850f6ccn, + ], + [ + 0x21cc891713fb8570152149a9fbb23410d7c42dece266bc6093650e46111a465cn, + 0x248f486105ee09f447e7e0ff522b5ff1db5f64522f2bbbb28e7a07595cff3e79n, + ], + [ + 0x147f06fa12cbb8d1c98f9c06d57899e20d9651bb8da104ad5168c9be10d4419fn, + 0x2766f677196fb611814f5d7af22aa8555c3c65b572151576b116df5b9f05857dn, + ], + [ + 0x0143beefa7f0b8fb72262a3c3d1502a36d8b4cb35befbb37dba3a70ffe2571c7n, + 0x1808ba6988bbb8585b77765760fb2afccdfe4946702043a46b8d461c7d211b11n, + ], + [ + 0x1ac3c1edb1eddd9c5011f88769fac4050aa8820de1f84fcda7e400f87028ba3an, + 0x050cbb4da87ecd3f0c84d6252e76e19b3678b955c603f35abdcee3b988a57fa4n, + ], + [ + 0x05a7092c674d8f44add477edf7369dc7bcb9da4d1b903fd58dd8bd4d166de73en, + 0x182545ce8ba6fa781823673d50fc62c7d1bb5f3515da6e5c2bdfd7248f311e1bn, + ], + [ + 0x0154a12dbf3fd3ae8957fe154f378630c12306eb55425d9732e0ae2b56ca0306n, + 0x140688ffb0de33c9625e323a13e9df6fb37c841b34c4b18b7e19d51792d393ccn, + ], + [ + 0x2fcdf4e4b421286df484fdd08725ffe53728759508f74f0d87e65bd932af28d4n, + 0x25f57213413f9f0982573c4a6640efe32b612c6c8f0b027425260c4629d38b21n, + ], + [ + 0x203ed9a7ff1ef21910003e658dbff87a3e10da7782de00af71995c233587961dn, + 0x0c7ae4445018e5d451f197d7881b1b95fb66574c26ff6967a37c1eab5f907a08n, + ], + [ + 0x131abdc8d6c6319aeee7e8b186ace3c07d140eb4037b21285b2260cd7bf310f7n, + 0x2371e4c2b73ce0af013b30ee9f434584742cdd7e91f1d842c1a6a95bd12d915dn, + ], + [ + 0x124029864085263e79448fdeef91ee2ea5a4952637646b02f132c1ac917edbdan, + 0x29d11c62ccfca5d8328e5171466137e6cfd19d56bdc3bbc4633a0aed34a90e69n, + ], + [ + 0x1ded46fcf96cba70ac0cb4ca58348c90041b257232e476acd236b45271413fben, + 0x26d04c6660ab9693743bf5c5fcf13047860dfeed3dd903e6ff6fe917fddf73fbn, + ], + [ + 0x2b31b48b7313f6a5c3f1f59fe9ad3d4b8900d873056af1691d143208eb5c8790n, + 0x27cec87606fe5f9562a3d0b1fef90da3e8d17721c668c342b681468a501deff3n, + ], + [ + 0x22080b093f3b3c98f9afc52b80594dcf51a714e77c40c3a08513897d73a70806n, + 0x1cbcacedf498eaebd03b602c4908c165c50ba184230c7c52244c9a5d0e9759ebn, + ], + [ + 0x0560b3857af53bc7262482310593e316543551ee57417583161bfce9d12a4d40n, + 0x2c91b186a9740d4b9f49c8889878381833cc5b5fe29e6e83affa2916e2008988n, + ], + [ + 0x2cf006347b380b6e0eb766ebdd1d24dc1eed9a43c206ee58e9457303d509c308n, + 0x03d11688f54726466399ddce8523148453cd1b6cad3cd414ee6e2af66a6b6addn, + ], + [ + 0x2e5c7e4d9a6069892bac121490fee89df1c238c7738c9f3ab599d6b4cc2ff491n, + 0x0f3c26f5de9ad898d4a4b1a08d1e87fd5cf4362f9796fb8715c60d431902cd54n, + ], + [ + 0x15298a52895eb8c9399509dc1f0ef68a90afc29084d3a0cec6956c8420819b5cn, + 0x2dc0ccd80f1bbbdf364f5b912a961332d9f5db54763745b64e0d85e33faf87c7n, + ], + [ + 0x132026c02d21e2ccabf1338f0d93f4223ecca5f0f2a96208561c9d5a5ef79c88n, + 0x09224bf821c64b105233fb98964f9ee0d3365f59e054c4693492ac07956d5c87n, + ], + [ + 0x2d6c6f3d040ad0c71760e8139ed3aef03c01d86e03f4ff0919f97899649d4bden, + 0x1a186b79fdcea1c8bb184097418bc68279fc5f682c48f5f21809bd2087944935n, + ], + [ + 0x1d69440baeb72617846c275fd817a4dbf9a8d39ddd38ca87b6a9e54ec6cc2adcn, + 0x239c44e43c9a91c9d126e745b949bf87844de4f2775aad804f81b8dcd3c232c7n, + ], + [ + 0x1e80e18c68865cf7bfcc6964613ba1aa1ae749a2d6154288d9572f022b2a4dd5n, + 0x1fa00a74773c3214ed7dfd125c82192d4c24ce557f720c98827aeec194dc9a30n, + ], + [ + 0x01b1362ee72c3e3ef5d63f67b54a6c5f547db48126b640fc8356e4cc19382dd3n, + 0x13e340c7dea9488aa6f9fe7443d7d1aa4b937800dd213c8bb4b301ba4a1a583cn, + ], + [ + 0x21f121f9754a315b922f8464a6cbe5a9fe191f30cbd2218cc4997c3d028fa52dn, + 0x2b8e094f90ea155bd675e389c69c3b021095801905efcfbcfeced8d7e25d6e96n, + ], + [ + 0x0d03c9e026afecdaf0f1b68679faf85830f2e16edf65c80c04b032441935e7b1n, + 0x18a285be0228b819cdd475d2f08192c02a998c85802b10d0ab3256fe367d9cf3n, + ], + [ + 0x12db390e5305fd19780de901727bb248778b6077f75ee6f8ae9c2b8629a8c037n, + 0x16952c652e2719fd93571b55357e6533410e2cb115cb970676c5d08a39d1be87n, + ], + [ + 0x04598dbf51d48775d7acafd239192aa850b72785472238e79f65a89292ac238bn, + 0x06872dca2aac431fbcb2fc3196b516bb791afb6136cc457b3aeeb85d1b02e4ecn, + ], + [ + 0x015ae13d6981f433340a44f9d33ebfda3b7108fbed96fabbbdd96e95b9f2cf23n, + 0x269b90e34244790294b66b9699510444a01ef16661fa80a2a41d368c6371af4bn, + ], + [ + 0x0a3d1c57e4d12a2041a41cc6483b63d8616af9b11a272535e3c88a4bb0f293a7n, + 0x092cf2eec8c9c1cefcaac51028875fb2f9abc46d111c852466d479edb244d852n, + ], + [ + 0x054e837ebc7a6b5142d527fd0e0b052aca6b91dd6dc4827e0196acea8bd04af5n, + 0x294164cfdfc4ddde270ccef912a1ac370f1aced76d933f702937db9ae0f6ab13n, + ], + [ + 0x1d175a456220eaa15ac082acf8a910da24751810edad87b1d558e229064c8da4n, + 0x1c0db158fb28522527eeffec568c97f8b7bc7a3927d1ba93ffcdab8de75e7ecbn, + ], + [ + 0x254c3c07450ac82ed0479ce88ace7cc5223b7cdc07557c234620d006df28fb09n, + 0x09e22217e07537054ab2c6c3947690ec12620ab0f0e7d03b023f51160c1df68dn, + ], + [ + 0x1cf4eece13e6e8b9bfd4644614cb0df16b38f76e70b11b4e72c283bc47439ffcn, + 0x18fcd0501cc6d30faf81f21b62ab175d5b5fff6b16a80b23700c9094ee3f779an, + ], + [ + 0x2ca6acd35e2ff4527399a13876563461726f08e629bd5897dfbf9a576f4d6641n, + 0x303c6102e21ec7518cc4181436345be6af5916b8f604bb1054c02d5ee1362c6en, + ], + [ + 0x037612d11f47ede28098ea80adef547f4912031fd236c9a7e5d5cdf00ba4911fn, + 0x0d547e26bf94386d4ba5a69caa4baac73aaff2bf4abdfadaaa42b892cfa033d8n, + ], + [ + 0x2494d804f242aa8a8a7e5eaf09829b04b4c7690c810a5ab01d3fbe2dae54a1f3n, + 0x093b3e5ca5fdfdb2e58ba6649e9c13f97b79d8e7f4cf65e3255b98a14689c94an, + ], + [ + 0x020c10d95e90a551134c8ad77cfb5f11465c23efd81c7713efe22ad54c048403n, + 0x03eea8fd0ad7fc2ea2eae6a082bb199959a6a361f7e8865d251d6ff547c15207n, + ], + [ + 0x0e274ceca67b5c0ff0b8774e5c8adb780b62e3e4a1065b190c2c28da6c808f50n, + 0x21c6675fbe4ae752919ab3f92f412394c138807af9adc3a5dd81400a83db3bc5n, + ], + [ + 0x0158f7157c016635f6f878fb58e1b59f2741a2315939fea4536e056bb7f35ce7n, + 0x20b454ec327caab24f39f8eb5caf9eda33a9274a8f4bab8f03de09a3c176e7d4n, + ], + [ + 0x1fee261ad59b9bb95733b499820beb21ed40156dc89dea7f02739661eafd81a5n, + 0x003e98b3f725336c5a13aeddb2e2c1e894860365915d06733d847f3a01dced7fn, + ], + [ + 0x237e59a6bfc3ff0e1f5fada642d1d1a5c349502bed14f64a6c5b03caf3975008n, + 0x2362bf67d5eff33ec19af5ef915557363bd3aa313f3610bd6b1a93cf6bd8b045n, + ], + [ + 0x0204a6de6d1e5243dabb6485d5eb0231aa1487f417f7677fb56f398269b07fefn, + 0x01b9bbb78a97b65bd9854d56e5bd50be8ca60f18b73f012ef28775ef3fc0901bn, + ], + [ + 0x18ad002f659998c9bd8543361f97a2a454e5b87aa62893406298f3e37f2720ben, + 0x227bd053f0ba47f463cee2caa96c4d00516f579a1646ec4a2a70dc1700b06a50n, + ], + [ + 0x03a74f956daea99179061720902ed0f3206c92f215fe1dc2b1a10545803a99e9n, + 0x2a279b91188c2bd770f5b23f0cc724ec9eab26971db684d4d8a1623e150d0e4cn, + ], + [ + 0x26b3364b6285c48a552b5f1a977d9be8728a8493855bf5acc49d5815af84dd2cn, + 0x1898136f0513c863a49ba1b27f7de7452f004ebe7409dfae1f28966f918e6ba4n, + ], + [ + 0x2ead9bee2969459504a0fa26e953a7caafe76dee6da60ca921e9f78743378589n, + 0x0934d50a9d9007be2e47f077044775b50d33438443853dc1e81ba011816faccen, + ], + [ + 0x03b638cfae5057787fc620d2a8fa257b7126603402dade0789093853eca1b6a1n, + 0x1e57da2d7d7c7087e58b74ae04e3be194424a64e21ee94feb20859dc1f65438bn, + ], + [ + 0x1253e8cce9c54cc1f0c2f38eb583f48f7421b516ff629c9764bc187f768cb0d3n, + 0x1164460615286ea5972631b0e2d96f68cdbf17c327cd1a0399666e34950375a3n, + ], + [ + 0x0de7b3c645363ac23ff2c8af302e995251419b52ea1936cf58805b589485ed08n, + 0x29ac530d28441b612678ff86c9f48cbee512260e21aacb7ae1a6abc05d0df10fn, + ], + [ + 0x11ee0a33439f8e1da5fbaec6ad6368a2c1ecd2590ebe06bb0269a2c28bd389a5n, + 0x0d37b9e16c881409be41d42601fdaecfc7b67bca0f088eb0bef1c4e4c428a1f1n, + ], + [ + 0x00ef4d130e14eb610f533b395d18db4708b4154a689cd4acddac1f1b43ed6854n, + 0x2c485355a6a340b718e1a20206ec5c55da5dacc9045d3454b2947b759a1401ban, + ], + [ + 0x0b2500eddb982dc3ef2728e010260a5e33aa06e6960ac8d3926e3e4b441c978an, + 0x023919ab917efd33a4e07c3da64b5c0af384c7487e23333c43c4b62a315014cbn, + ], + [ + 0x2e9eb27d5d8f60d282cf0866e4f0fb92d045388f1d227852f85c1518dddc503an, + 0x1f0edc2cc1602d4f66b658f676446a7ebd3bab1a08cfe60184390600c2b0044dn, + ], + [ + 0x05c545ab45ef4d781e551674ce7027668b384667c7e3e04be02a921410223713n, + 0x0e8988769b7f561fd70e9a761c198ab9d5807fbe6ecd327241a8f10815ac4d76n, + ], + [ + 0x252896bd06ea09d5260c6053b96a3c9f0fe2bf520debabc1422b298e1b823ff0n, + 0x0beba0fe2d2ed0e028356ae129ba2a444a871a7aad25d5e90fc022b963e0c5e3n, + ], + [ + 0x17c2b8543fe3ba1042342557072eb30e941f8b93c879512e590a761454458694n, + 0x2de5011cc9b603ba43cfcc082671de63da3de9b9f0021879e7f482058f9fae0fn, + ], + [ + 0x0792855505a783cb49f954bccca6120e8990a7092b4ab0bd08168203932c7bacn, + 0x09e95a4c731b378b80991239ff87b90ba00b9439c287dbf01aaac56f05aa550dn, + ], + [ + 0x0d4beeb972497603c3a1d7d7ad79c45615f12844a530580ca2de18ef8fa1b1efn, + 0x004998039050599d55e744c51f8846dbc7db25a8318abcaf217ae68bff075d77n, + ], + [ + 0x12c6d0a3726a805bc04506282ce0218ce5de5386b1eb4aaa893722fe80983688n, + 0x2394def51425f2cee78f4ac1f0c04e25b60d1fdc9e84bacad67500f7ebcfca34n, + ], + [ + 0x1a19096c5c3522d45e2827449adef54d91287ede96b3d39818da08a0b93e9dc3n, + 0x27a0dde36f91156a87d746a58477553ec138d108fb471f157175e22a75a495dbn, + ], + [ + 0x0b7748b109ba5798a8d2803be7fd015f2ca5af9eaad8ddddde16d50a07a7bc10n, + 0x12214803947f2969d86455b1a47213f04a9309620d9692ec91114237acb84eebn, + ], + [ + 0x0c02dbea3ecb6bacc7390d53b6fe23feb49a58c571d95d01fabac5a42489a7can, + 0x0d73b846a5cf707f3e5abf9ba2b4f5602a55b5fbad7fbd7bd9b9ab48977c1005n, + ], + [ + 0x169623c619bc3ac95ec3315d5e01afecebafb1931826551b86c007070001fe90n, + 0x00cb91b18d7097d4fa2d7600ae1bf31a3b4df9479e39f1bf23f231773258ea3cn, + ], + [ + 0x0fd5b9f9d183b6da8ba0f99503e851450b3efb33c6a7807a6239e0707b5af271n, + 0x2a4153eb0395955d7d7ee71519d1d600bc32dd39b6283224fbc92d23b860eb54n, + ], + [ + 0x1209e1604a9b10afde568fcfe0ea9f1e09cdf13fe17747abeff0a1454dcf947bn, + 0x0e1d63b8ab7b9a4a7ef8d3d17207dcbbc22e9c21da661ddfdc1ac961e0032b57n, + ], + [ + 0x2982c7c825f0e86293b7a0c9eefea7f5383e222a054ffa4c5d4e5908c543c2a6n, + 0x151b990dec385eab48210cd7766d2de58eba95ff76faeee4eb64e6f3dbd3c139n, + ], + [ + 0x124faaed649b6df79325991151fb88952c9acfd57a6b3cb20b18f2fe63529818n, + 0x229dfd4712f46fe904c28adccd1165786e96baaa2c74a0a7744dbb4ab4300d41n, + ], + [ + 0x0963070c9042bbbbe66468d9e75a719123b52b76ee9797f4b039b5de1b5c9651n, + 0x06aa3729a947ec02394d82a46a0c2c2f8e2013e15f46cc97b96944937da731d0n, + ], + [ + 0x279040e3e8f1e0effaf0450099574e134c3eef819f04cadff27851de962da0d3n, + 0x1ee7f53a1b21c4fbd2ef56895bc274e520140858ba51eff6968eae9d0a03a2f8n, + ], + [ + 0x0502d68753a132e8b268e02362166d6c0e43494aef2a5173eff138aadfe05ad0n, + 0x21629dc5334c80a75f79a4b75169c40bb6eb665796a8c4d1024231cbc4604f1en, + ], + [ + 0x13edf560ae7a1c78296f4609233337cd8fbb009b22d89a27d2e5c94983095fe9n, + 0x039c043f9ac7c68faf473565cdcb51785597c90d8ba14dd8e577bf14d70c53e5n, + ], + [ + 0x075a3019dc700efd12e8b91be0029407d59c3dfeeeced4d8f8d35fed14900d79n, + 0x073d003f8998a46ba32780d2e50c2a287b6902ecb2b82672a817980666c406c1n, + ], + [ + 0x1e8509ab9d961e5dea389e1498be69790390a5f77c7dc68cc55858207ece11c5n, + 0x19979a1f1a22dc051a45427d70f66fc27c064fd451b64b6b609d74f0a6439b2cn, + ], + [ + 0x0dc528103070ee030c96bdfe9004693f52a22042abad186aba5616918c701f56n, + 0x05f194973a699889fecfedf291c50be0526c35c22faba00aec84b967e1a0f278n, + ], + [ + 0x1f795886933d543108a9cb86291f04ba487cd95fb6ff9a062d8e6ac9f267d3fan, + 0x127fe0e1209741e32c0a093bada5517cbab952de68241df774b6ddeabc2a6397n, + ], + [ + 0x156c18df6da11a7f9657751e43b50abea544017d347f27406cf4751e51a81e42n, + 0x28e38ee1433b9eefac4b22ba5d88f1d7979d1fce9920d20213b1c01fb204f725n, + ], + [ + 0x2341ce02c131e47cec7777567cc7996ac3b6fd6255ba880ba819ae4982465becn, + 0x0913340a3a212e4e0adb678d500a70e99e24f7a8370cab3b92df8cb6ec2766f3n, + ], + [ + 0x2ee690cd26ee66b12bfe6a7d4fe3077a8c2a41ce96216a964c1a94227b0cb8f9n, + 0x1e207e2e40816da78ca89b8d98f0ada6208f014beef4efec812f629d42e5e304n, + ], + [ + 0x086d9eebd9fbb9b6394cb155b8ee9e3558857f65053abb4a04c6d956d1fdfe95n, + 0x08deaf603a5fee68ccbf892f95f787dd437283b46362a9071ee1e73ec4e03edcn, + ], + [ + 0x0f63792ebcefa16d26dbfeb58db005dced755740bd047de3fde3013575b57022n, + 0x1cbd79e5b8ac132920b495e66d47f2969df49423452a34336796d152ac7de76bn, + ], + [ + 0x05f6732fe8526a3340e547d2a19a97a5c4538a94ce607eb0909db67c8880bdedn, + 0x1e0bbf2a4e501a83460c96e919bec020187f51ce94c328b3b38b07f34dea2cb2n, + ], + [ + 0x1f1df03870f616146c84545722f1e8064bc9db8180caf35061367af95445bb3fn, + 0x077004e054257d7389065f3f11be644084b357c1b9214a9869d5b6761ccee13cn, + ], +].map(([x, y]) => new grumpkin.ProjectivePoint(x, y, 1n)); + +const lengthGenerator = new grumpkin.ProjectivePoint( + 0x2df8b940e5890e4e1377e05373fae69a1d754f6935e6a780b666947431f2cdcdn, + 0x2ecd88d15967bc53b885912e0d16866154acb6aac2d3f85e27ca7eefb2c19083n, + 1n, +); + +const pointAtInfinity = new grumpkin.ProjectivePoint(0n, 1n, 0n); + +/** + * Create a pedersen commitment (point) from an array of input fields. + */ +function pedersenCommitInternal(input: Buffer[], generatorOffset = 0) { + if (generatorOffset + input.length > defaultGenerators.length) { + throw new Error( + `Pedersen commit overflowed default generators. offset: ${generatorOffset} length: ${input.length}`, + ); + } + let result = pointAtInfinity; + for (let i = 0; i < input.length; ++i) { + // TODO: WARNING! Merkle tree tests fail if we don't reduce modulo p as they feed in 256 bits. + // Is it right that we accept 256 bit buffers here and reduce mod p? Is the right thing to only accept fields? + const ie = toBigIntBE(input[i]) % grumpkin.CURVE.Fp.ORDER; + result = ie ? result.add(defaultGenerators[generatorOffset + i].multiply(ie)) : result; + } + return result; +} + +/** + * Create a pedersen commitment (point) from an array of input fields. + */ +export function pedersenCommitNoble(input: Buffer[], generatorOffset = 0) { + const result = pedersenCommitInternal(input, generatorOffset); + return [toBufferBE(result.x, 32), toBufferBE(result.y, 32)]; +} + +/** + * Create a pedersen hash (field) from an array of input fields. + */ +export function pedersenHashWithHashIndexNoble(input: Buffer[], index = 0) { + const result = lengthGenerator.multiply(BigInt(input.length)); + return toBufferBE(result.add(pedersenCommitInternal(input, index)).x, 32); +} diff --git a/yarn-project/foundation/src/crypto/pedersen/index.ts b/yarn-project/foundation/src/crypto/pedersen/index.ts index 3756b586e51e..ec098f69cedd 100644 --- a/yarn-project/foundation/src/crypto/pedersen/index.ts +++ b/yarn-project/foundation/src/crypto/pedersen/index.ts @@ -1,572 +1,2 @@ -/* cSpell:disable */ -import { Field } from '@noble/curves/abstract/modular'; -import { weierstrassPoints } from '@noble/curves/abstract/weierstrass'; - -import { toBigIntBE, toBufferBE } from '../../bigint-buffer/index.js'; - -const grumpkin = weierstrassPoints({ - a: 0n, - b: 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593effffff0n, - Fp: Field(0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001n), - n: 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47n, - h: 1n, - Gx: 1n, - Gy: 0x0000000000000002cf135e7506a45d632d270d45f1181294833fc48d823f272cn, -}); - -const defaultGenerators = [ - [ - 0x083e7911d835097629f0067531fc15cafd79a89beecb39903f69572c636f4a5an, - 0x1a7f5efaad7f315c25a918f30cc8d7333fccab7ad7c90f14de81bcc528f9935dn, - ], - [ - 0x054aa86a73cb8a34525e5bbed6e43ba1198e860f5f3950268f71df4591bde402n, - 0x209dcfbf2cfb57f9f6046f44d71ac6faf87254afc7407c04eb621a6287cac126n, - ], - [ - 0x1c44f2a5207c81c28a8321a5815ce8b1311024bbed131819bbdaf5a2ada84748n, - 0x03aaee36e6422a1d0191632ac6599ae9eba5ac2c17a8c920aa3caf8b89c5f8a8n, - ], - [ - 0x26d8b1160c6821a30c65f6cb47124afe01c29f4338f44d4a12c9fccf22fb6fb2n, - 0x05c70c3b9c0d25a4c100e3a27bf3cc375f8af8cdd9498ec4089a823d7464caffn, - ], - [ - 0x20ed9c6a1d27271c4498bfce0578d59db1adbeaa8734f7facc097b9b994fcf6en, - 0x29cd7d370938b358c62c4a00f73a0d10aba7e5aaa04704a0713f891ebeb92371n, - ], - [ - 0x0224a8abc6c8b8d50373d64cd2a1ab1567bf372b3b1f7b861d7f01257052d383n, - 0x2358629b90eafb299d6650a311e79914b0215eb0a790810b26da5a826726d711n, - ], - [ - 0x0f106f6d46bc904a5290542490b2f238775ff3c445b2f8f704c466655f460a2an, - 0x29ab84d472f1d33f42fe09c47b8f7710f01920d6155250126731e486877bcf27n, - ], - [ - 0x0298f2e42249f0519c8a8abd91567ebe016e480f219b8c19461d6a595cc33696n, - 0x035bec4b8520a4ece27bd5aafabee3dfe1390d7439c419a8c55aceb207aac83bn, - ], - [ - 0x2c9628479de4181ea77e7b0913ccf41d2a74155b1d9c82eaa220c218781f6f3bn, - 0x278f86b8fd95520b5da23bee1a5e354dc5dcb0cb43d6b76e628ddbffb101d776n, - ], - [ - 0x0be1916f382e3532aa53a766fe74b1a983784caab90290aea7bf616bc371fb41n, - 0x0f65545005e896f14249956344faf9addd762b7573a487b58f805a361d920a20n, - ], - [ - 0x29ff8437ae5bec89981441b23036a22b7fd5bee9eff0e83c0dd5b87bfb5bd60en, - 0x1fd247352b77e2676b22db23cf7cd482474f543e3480b5a39c42f839a306be10n, - ], - [ - 0x2f3bd4e98f8c8458cd58888749f0f5e582a43565767398e08e50e94b9b19a4d9n, - 0x1f534906d1aa8b4ba74ad9e3f85ae3f8295e51eaafd15b5d116801b96360205bn, - ], - [ - 0x27759098f425b76447c2c52728576803a1ac5de37bba875ac47cdcff539ab931n, - 0x0aa47ee64d12d856cfb81b595c1d60ceecb693f0fdae644746ff333e39f61db7n, - ], - [ - 0x015ca8d68616fde86c9108e3db04f588e0f308e60d367e963b7d460fe9a65e6cn, - 0x2cf918009dda942ac9d59903cd2d0294d8738f938b1394170d892a027d0f347bn, - ], - [ - 0x0d1783d5b256765515f3c9988df9f1ba7e6f5fb0248c8971fbc503ffd5187714n, - 0x2ebb434ff4857fc3621f3bc3c6b8002b17d02d9c204e75f19b8f0b99ea68402cn, - ], - [ - 0x300f20942e37abb19520f931f7bf7c6bbac93e4461a7789677f986e344d1f5e5n, - 0x1172a6b674c66bb037109fbb4d93d4ca8054bb9dda08839a6189eb578511116dn, - ], - [ - 0x13a6b381a663aa8a757dd386a3a8947d456874a356f52f8af1a3d84ba1067eaan, - 0x224854000fa9c70e873fb14ad7c0d01dcf6df5f30261333d6b63c78a7da5a348n, - ], - [ - 0x2b37dc5eb4c3f8cba62f0085ec131053eae6181a3e73a82e7d79764a023394ccn, - 0x27c817c1376228a3a9f5ac6caed57857a3baa580a0c1b70a17f75a6ab7e2377cn, - ], - [ - 0x26ae1cc453dab3f2cf4810cc3fb8f71257383333aa4f3ace8eb69c8ba4fa5da1n, - 0x28bfbf80541bde37e9db113ae1eb049cf163ff4ea9654d61f42a95bc2e0b17bdn, - ], - [ - 0x0e29626ab6be74417d08b28c8f8ebf02fd701e28d1d47b1961e716e735e02d12n, - 0x119f55d6bffb6bba81779eaf98f310c5661d85397b094ffbddbb41fb264b0876n, - ], - [ - 0x055cda53e781f3eedd760ba2c48c6d36d2a061544c3d33e76100bd4c65e89748n, - 0x28391e899d6407e40294faa5e5561ab472e43ea5d54c15343b9a47cb7a80ed09n, - ], - [ - 0x203c402369e8b2bc2c3827bc82a278d32c51dc9ab95e55ce1566e8b625b7bce7n, - 0x2bf25525d4a62f1252355559dd496b68ba4d6ea65f4b669bb3da73c42455f0a3n, - ], - [ - 0x2468739cedeabea49dbc46c2356bd5cf341aa4574272ba53a40d8049e5ee949fn, - 0x0e8b73bcac6b2ccffaa2e50fce992db11a0b46dcdb8ad4b8325393f903a2543an, - ], - [ - 0x242d8ad05dc6e2a8a6fd636f48eec881e05ee8d2a58e2653173f4954ec867654n, - 0x0afe0d7aa588a3dcf791f11fcdf54c1d07cfc805c5ae0b02101faafab9cb55f0n, - ], - [ - 0x05c378d0596af9f9a2471be52b7ad0112d48ef355c372088eb0db86e42887e14n, - 0x1ba1f1adb66e67bc88c1b3eafe95b202812803a8b71ca62de9ed06c8b9f3cff3n, - ], - [ - 0x04e5c213eebfffcdb42b6c371e52f0d598646cf0ca2a353b4b99889074c5a2bcn, - 0x0ae6442bc73b0f2b2d45829fd8fa321ab6b5eecdd3988a39f0c5850544de5082n, - ], - [ - 0x2c96765650bd7c3bee01114b9097b036e20d5c774afe2ba7d5d6099f498f47fdn, - 0x0879c9cc5e7eea97f1f9193e1fd08b8d0390320197dee299af1eb67f92c506a3n, - ], - [ - 0x2113980404df880af7d25a27aec16e61c770619912435b618914da7fa1a88385n, - 0x106827183994d8da15037851748b05392620516277bf0000f8b38e97f5db602an, - ], - [ - 0x13b4c5f15cc69af871b91e862db8b0044834c5e8da5a287d0794342bb97ffca6n, - 0x17941f13343835b572e18d37ab3897f80e0461f9b72ab61da61927fc980a6bd2n, - ], - [ - 0x085c0f69b19e05986883dcc9d53334bb6799968688935d938cebd4b4455f9187n, - 0x242b8a5ab074d09e26427b1b6633a79a82ba41d64c4d658017f3186d6926721bn, - ], - [ - 0x1bb111daaf71e632a4c9244a362bdde16a5efc5e7c7dda42b20f3290c2776d2cn, - 0x2b4506bf741b2dc59f71f7036716cac04b6f808b4ca1469eb2fd7bccff5882c0n, - ], - [ - 0x1a76ba8ca6b8e2c65915521b175da98137dfcaf0b5faff1019f37afce77c99ean, - 0x1894c8c79e69e52a495bf6fe467aa4f5bdbe606490d6803df325a075c5b0079an, - ], - [ - 0x2fea40a9bfb252ba7e192be641a4051381982719b77d567caee2657f36b701abn, - 0x1e80d5ea79b50a722e65ce274b8ba2a133de94b757ef71b452183ee958c620e1n, - ], - [ - 0x217c100e6cd64b68e91fe26e90eda02eaa505859201253bd5e550e0bb8f0f29an, - 0x12a5c4fc942353f962bc5b97f36b9a326d5dbb6c505266d2a016415d8da0be65n, - ], - [ - 0x2f50fc293e4529108595329b6e7b0110c0db563927bd57a169e81884535660f9n, - 0x03547f619f9c30a761963381fe31f031ecd5b393d2281455a66e01aff0896338n, - ], - [ - 0x06e0f1aab04c530ed9e9584b7c06cb40d6dbd1752313b1bf8498accb8227e743n, - 0x2b47e83f03e635a9c20eb0d6412955dec1578a197c7d51f648550623ac5b3baen, - ], - [ - 0x1dee7c6f5d7527d26da506eec28cc3b71acf9a8e694567749dc5e6b073748632n, - 0x235955a911e3744859c1db3996aa1f0f64424f67c2ef1c8fcc8c767af5749068n, - ], - [ - 0x1e5aa70095a858d1c4153691e91c19f01a883f422efc19ec766c86bc416ceb2an, - 0x0f1e06c820067d8d0af14cf87633c1bd761d65bc5b3889a17bae7d70d2b19f5dn, - ], - [ - 0x2f4d8f60344443350f226f19c4b01e2198f6b475b0291dd2e0c3981e3797a5e0n, - 0x1aaab92caf692c5fb89e6eab983f26ebe009463c1ddece0a650508994cb84a82n, - ], - [ - 0x06e0aba4044a552343f7ba02f234dafe4ccca7fd552342a8493ce544758df012n, - 0x243269273e7c7ee7a50288f282cb6a7169ec2aac03d2ff7b40463638ad5722d5n, - ], - [ - 0x1aecf2ef53262227e12a9ca29ae7f14be031c03488a7604a03cdc77115f26136n, - 0x0753180b7d445c215d55dbfd6ebfb1c6aabd690ac92fd76cea5144ef3c9a8b3fn, - ], - [ - 0x207d50d783c727a979303bc8f50538ad75e5f856180d4f3dc2c7ee186916cef8n, - 0x20155253cd087a980aad326564240cca45a72c888e69395e4d8f5ca3d2b96e0an, - ], - [ - 0x21db09b3c2c299f1b0be7a8f3031fd283cd5f1efca0a468b7ea9a0f170e81fc7n, - 0x21b50f8107353afc7a1656040c9888ee393608420d88c2a07f34293fb609a26dn, - ], - [ - 0x02190016f4cc44935d100bc7b7dae46cea5922261e9889112cc815fafd5c45ccn, - 0x01dfaacfa00ddb9133042d9833d1201172f69a456f0c9483d0b58e5f01b571fdn, - ], - [ - 0x04e67573df0c1591ec51d2f60b74f1964abeef3e201084425a55cd71ffe0b4f8n, - 0x1f0285b2ede69aff961919827312afad0753c112cab001cb28ff6c2c27f277c6n, - ], - [ - 0x092450548d189dfe4e852370c17343aeef92ac3a8fbdeb8fdd244f87d3af03cdn, - 0x23e3c53d9265d6debfdb40988a908e64673b2f87b1fe2a08b56c6a3fcf84f5d1n, - ], - [ - 0x2935be388ee1365bf6a9cc6fd25d130607835dbf7926c5cafed690b9072cd316n, - 0x059edfbc50a9699e29b975a2fc3bfe7855997e708ce82fa30ed19cc91850f6ccn, - ], - [ - 0x21cc891713fb8570152149a9fbb23410d7c42dece266bc6093650e46111a465cn, - 0x248f486105ee09f447e7e0ff522b5ff1db5f64522f2bbbb28e7a07595cff3e79n, - ], - [ - 0x147f06fa12cbb8d1c98f9c06d57899e20d9651bb8da104ad5168c9be10d4419fn, - 0x2766f677196fb611814f5d7af22aa8555c3c65b572151576b116df5b9f05857dn, - ], - [ - 0x0143beefa7f0b8fb72262a3c3d1502a36d8b4cb35befbb37dba3a70ffe2571c7n, - 0x1808ba6988bbb8585b77765760fb2afccdfe4946702043a46b8d461c7d211b11n, - ], - [ - 0x1ac3c1edb1eddd9c5011f88769fac4050aa8820de1f84fcda7e400f87028ba3an, - 0x050cbb4da87ecd3f0c84d6252e76e19b3678b955c603f35abdcee3b988a57fa4n, - ], - [ - 0x05a7092c674d8f44add477edf7369dc7bcb9da4d1b903fd58dd8bd4d166de73en, - 0x182545ce8ba6fa781823673d50fc62c7d1bb5f3515da6e5c2bdfd7248f311e1bn, - ], - [ - 0x0154a12dbf3fd3ae8957fe154f378630c12306eb55425d9732e0ae2b56ca0306n, - 0x140688ffb0de33c9625e323a13e9df6fb37c841b34c4b18b7e19d51792d393ccn, - ], - [ - 0x2fcdf4e4b421286df484fdd08725ffe53728759508f74f0d87e65bd932af28d4n, - 0x25f57213413f9f0982573c4a6640efe32b612c6c8f0b027425260c4629d38b21n, - ], - [ - 0x203ed9a7ff1ef21910003e658dbff87a3e10da7782de00af71995c233587961dn, - 0x0c7ae4445018e5d451f197d7881b1b95fb66574c26ff6967a37c1eab5f907a08n, - ], - [ - 0x131abdc8d6c6319aeee7e8b186ace3c07d140eb4037b21285b2260cd7bf310f7n, - 0x2371e4c2b73ce0af013b30ee9f434584742cdd7e91f1d842c1a6a95bd12d915dn, - ], - [ - 0x124029864085263e79448fdeef91ee2ea5a4952637646b02f132c1ac917edbdan, - 0x29d11c62ccfca5d8328e5171466137e6cfd19d56bdc3bbc4633a0aed34a90e69n, - ], - [ - 0x1ded46fcf96cba70ac0cb4ca58348c90041b257232e476acd236b45271413fben, - 0x26d04c6660ab9693743bf5c5fcf13047860dfeed3dd903e6ff6fe917fddf73fbn, - ], - [ - 0x2b31b48b7313f6a5c3f1f59fe9ad3d4b8900d873056af1691d143208eb5c8790n, - 0x27cec87606fe5f9562a3d0b1fef90da3e8d17721c668c342b681468a501deff3n, - ], - [ - 0x22080b093f3b3c98f9afc52b80594dcf51a714e77c40c3a08513897d73a70806n, - 0x1cbcacedf498eaebd03b602c4908c165c50ba184230c7c52244c9a5d0e9759ebn, - ], - [ - 0x0560b3857af53bc7262482310593e316543551ee57417583161bfce9d12a4d40n, - 0x2c91b186a9740d4b9f49c8889878381833cc5b5fe29e6e83affa2916e2008988n, - ], - [ - 0x2cf006347b380b6e0eb766ebdd1d24dc1eed9a43c206ee58e9457303d509c308n, - 0x03d11688f54726466399ddce8523148453cd1b6cad3cd414ee6e2af66a6b6addn, - ], - [ - 0x2e5c7e4d9a6069892bac121490fee89df1c238c7738c9f3ab599d6b4cc2ff491n, - 0x0f3c26f5de9ad898d4a4b1a08d1e87fd5cf4362f9796fb8715c60d431902cd54n, - ], - [ - 0x15298a52895eb8c9399509dc1f0ef68a90afc29084d3a0cec6956c8420819b5cn, - 0x2dc0ccd80f1bbbdf364f5b912a961332d9f5db54763745b64e0d85e33faf87c7n, - ], - [ - 0x132026c02d21e2ccabf1338f0d93f4223ecca5f0f2a96208561c9d5a5ef79c88n, - 0x09224bf821c64b105233fb98964f9ee0d3365f59e054c4693492ac07956d5c87n, - ], - [ - 0x2d6c6f3d040ad0c71760e8139ed3aef03c01d86e03f4ff0919f97899649d4bden, - 0x1a186b79fdcea1c8bb184097418bc68279fc5f682c48f5f21809bd2087944935n, - ], - [ - 0x1d69440baeb72617846c275fd817a4dbf9a8d39ddd38ca87b6a9e54ec6cc2adcn, - 0x239c44e43c9a91c9d126e745b949bf87844de4f2775aad804f81b8dcd3c232c7n, - ], - [ - 0x1e80e18c68865cf7bfcc6964613ba1aa1ae749a2d6154288d9572f022b2a4dd5n, - 0x1fa00a74773c3214ed7dfd125c82192d4c24ce557f720c98827aeec194dc9a30n, - ], - [ - 0x01b1362ee72c3e3ef5d63f67b54a6c5f547db48126b640fc8356e4cc19382dd3n, - 0x13e340c7dea9488aa6f9fe7443d7d1aa4b937800dd213c8bb4b301ba4a1a583cn, - ], - [ - 0x21f121f9754a315b922f8464a6cbe5a9fe191f30cbd2218cc4997c3d028fa52dn, - 0x2b8e094f90ea155bd675e389c69c3b021095801905efcfbcfeced8d7e25d6e96n, - ], - [ - 0x0d03c9e026afecdaf0f1b68679faf85830f2e16edf65c80c04b032441935e7b1n, - 0x18a285be0228b819cdd475d2f08192c02a998c85802b10d0ab3256fe367d9cf3n, - ], - [ - 0x12db390e5305fd19780de901727bb248778b6077f75ee6f8ae9c2b8629a8c037n, - 0x16952c652e2719fd93571b55357e6533410e2cb115cb970676c5d08a39d1be87n, - ], - [ - 0x04598dbf51d48775d7acafd239192aa850b72785472238e79f65a89292ac238bn, - 0x06872dca2aac431fbcb2fc3196b516bb791afb6136cc457b3aeeb85d1b02e4ecn, - ], - [ - 0x015ae13d6981f433340a44f9d33ebfda3b7108fbed96fabbbdd96e95b9f2cf23n, - 0x269b90e34244790294b66b9699510444a01ef16661fa80a2a41d368c6371af4bn, - ], - [ - 0x0a3d1c57e4d12a2041a41cc6483b63d8616af9b11a272535e3c88a4bb0f293a7n, - 0x092cf2eec8c9c1cefcaac51028875fb2f9abc46d111c852466d479edb244d852n, - ], - [ - 0x054e837ebc7a6b5142d527fd0e0b052aca6b91dd6dc4827e0196acea8bd04af5n, - 0x294164cfdfc4ddde270ccef912a1ac370f1aced76d933f702937db9ae0f6ab13n, - ], - [ - 0x1d175a456220eaa15ac082acf8a910da24751810edad87b1d558e229064c8da4n, - 0x1c0db158fb28522527eeffec568c97f8b7bc7a3927d1ba93ffcdab8de75e7ecbn, - ], - [ - 0x254c3c07450ac82ed0479ce88ace7cc5223b7cdc07557c234620d006df28fb09n, - 0x09e22217e07537054ab2c6c3947690ec12620ab0f0e7d03b023f51160c1df68dn, - ], - [ - 0x1cf4eece13e6e8b9bfd4644614cb0df16b38f76e70b11b4e72c283bc47439ffcn, - 0x18fcd0501cc6d30faf81f21b62ab175d5b5fff6b16a80b23700c9094ee3f779an, - ], - [ - 0x2ca6acd35e2ff4527399a13876563461726f08e629bd5897dfbf9a576f4d6641n, - 0x303c6102e21ec7518cc4181436345be6af5916b8f604bb1054c02d5ee1362c6en, - ], - [ - 0x037612d11f47ede28098ea80adef547f4912031fd236c9a7e5d5cdf00ba4911fn, - 0x0d547e26bf94386d4ba5a69caa4baac73aaff2bf4abdfadaaa42b892cfa033d8n, - ], - [ - 0x2494d804f242aa8a8a7e5eaf09829b04b4c7690c810a5ab01d3fbe2dae54a1f3n, - 0x093b3e5ca5fdfdb2e58ba6649e9c13f97b79d8e7f4cf65e3255b98a14689c94an, - ], - [ - 0x020c10d95e90a551134c8ad77cfb5f11465c23efd81c7713efe22ad54c048403n, - 0x03eea8fd0ad7fc2ea2eae6a082bb199959a6a361f7e8865d251d6ff547c15207n, - ], - [ - 0x0e274ceca67b5c0ff0b8774e5c8adb780b62e3e4a1065b190c2c28da6c808f50n, - 0x21c6675fbe4ae752919ab3f92f412394c138807af9adc3a5dd81400a83db3bc5n, - ], - [ - 0x0158f7157c016635f6f878fb58e1b59f2741a2315939fea4536e056bb7f35ce7n, - 0x20b454ec327caab24f39f8eb5caf9eda33a9274a8f4bab8f03de09a3c176e7d4n, - ], - [ - 0x1fee261ad59b9bb95733b499820beb21ed40156dc89dea7f02739661eafd81a5n, - 0x003e98b3f725336c5a13aeddb2e2c1e894860365915d06733d847f3a01dced7fn, - ], - [ - 0x237e59a6bfc3ff0e1f5fada642d1d1a5c349502bed14f64a6c5b03caf3975008n, - 0x2362bf67d5eff33ec19af5ef915557363bd3aa313f3610bd6b1a93cf6bd8b045n, - ], - [ - 0x0204a6de6d1e5243dabb6485d5eb0231aa1487f417f7677fb56f398269b07fefn, - 0x01b9bbb78a97b65bd9854d56e5bd50be8ca60f18b73f012ef28775ef3fc0901bn, - ], - [ - 0x18ad002f659998c9bd8543361f97a2a454e5b87aa62893406298f3e37f2720ben, - 0x227bd053f0ba47f463cee2caa96c4d00516f579a1646ec4a2a70dc1700b06a50n, - ], - [ - 0x03a74f956daea99179061720902ed0f3206c92f215fe1dc2b1a10545803a99e9n, - 0x2a279b91188c2bd770f5b23f0cc724ec9eab26971db684d4d8a1623e150d0e4cn, - ], - [ - 0x26b3364b6285c48a552b5f1a977d9be8728a8493855bf5acc49d5815af84dd2cn, - 0x1898136f0513c863a49ba1b27f7de7452f004ebe7409dfae1f28966f918e6ba4n, - ], - [ - 0x2ead9bee2969459504a0fa26e953a7caafe76dee6da60ca921e9f78743378589n, - 0x0934d50a9d9007be2e47f077044775b50d33438443853dc1e81ba011816faccen, - ], - [ - 0x03b638cfae5057787fc620d2a8fa257b7126603402dade0789093853eca1b6a1n, - 0x1e57da2d7d7c7087e58b74ae04e3be194424a64e21ee94feb20859dc1f65438bn, - ], - [ - 0x1253e8cce9c54cc1f0c2f38eb583f48f7421b516ff629c9764bc187f768cb0d3n, - 0x1164460615286ea5972631b0e2d96f68cdbf17c327cd1a0399666e34950375a3n, - ], - [ - 0x0de7b3c645363ac23ff2c8af302e995251419b52ea1936cf58805b589485ed08n, - 0x29ac530d28441b612678ff86c9f48cbee512260e21aacb7ae1a6abc05d0df10fn, - ], - [ - 0x11ee0a33439f8e1da5fbaec6ad6368a2c1ecd2590ebe06bb0269a2c28bd389a5n, - 0x0d37b9e16c881409be41d42601fdaecfc7b67bca0f088eb0bef1c4e4c428a1f1n, - ], - [ - 0x00ef4d130e14eb610f533b395d18db4708b4154a689cd4acddac1f1b43ed6854n, - 0x2c485355a6a340b718e1a20206ec5c55da5dacc9045d3454b2947b759a1401ban, - ], - [ - 0x0b2500eddb982dc3ef2728e010260a5e33aa06e6960ac8d3926e3e4b441c978an, - 0x023919ab917efd33a4e07c3da64b5c0af384c7487e23333c43c4b62a315014cbn, - ], - [ - 0x2e9eb27d5d8f60d282cf0866e4f0fb92d045388f1d227852f85c1518dddc503an, - 0x1f0edc2cc1602d4f66b658f676446a7ebd3bab1a08cfe60184390600c2b0044dn, - ], - [ - 0x05c545ab45ef4d781e551674ce7027668b384667c7e3e04be02a921410223713n, - 0x0e8988769b7f561fd70e9a761c198ab9d5807fbe6ecd327241a8f10815ac4d76n, - ], - [ - 0x252896bd06ea09d5260c6053b96a3c9f0fe2bf520debabc1422b298e1b823ff0n, - 0x0beba0fe2d2ed0e028356ae129ba2a444a871a7aad25d5e90fc022b963e0c5e3n, - ], - [ - 0x17c2b8543fe3ba1042342557072eb30e941f8b93c879512e590a761454458694n, - 0x2de5011cc9b603ba43cfcc082671de63da3de9b9f0021879e7f482058f9fae0fn, - ], - [ - 0x0792855505a783cb49f954bccca6120e8990a7092b4ab0bd08168203932c7bacn, - 0x09e95a4c731b378b80991239ff87b90ba00b9439c287dbf01aaac56f05aa550dn, - ], - [ - 0x0d4beeb972497603c3a1d7d7ad79c45615f12844a530580ca2de18ef8fa1b1efn, - 0x004998039050599d55e744c51f8846dbc7db25a8318abcaf217ae68bff075d77n, - ], - [ - 0x12c6d0a3726a805bc04506282ce0218ce5de5386b1eb4aaa893722fe80983688n, - 0x2394def51425f2cee78f4ac1f0c04e25b60d1fdc9e84bacad67500f7ebcfca34n, - ], - [ - 0x1a19096c5c3522d45e2827449adef54d91287ede96b3d39818da08a0b93e9dc3n, - 0x27a0dde36f91156a87d746a58477553ec138d108fb471f157175e22a75a495dbn, - ], - [ - 0x0b7748b109ba5798a8d2803be7fd015f2ca5af9eaad8ddddde16d50a07a7bc10n, - 0x12214803947f2969d86455b1a47213f04a9309620d9692ec91114237acb84eebn, - ], - [ - 0x0c02dbea3ecb6bacc7390d53b6fe23feb49a58c571d95d01fabac5a42489a7can, - 0x0d73b846a5cf707f3e5abf9ba2b4f5602a55b5fbad7fbd7bd9b9ab48977c1005n, - ], - [ - 0x169623c619bc3ac95ec3315d5e01afecebafb1931826551b86c007070001fe90n, - 0x00cb91b18d7097d4fa2d7600ae1bf31a3b4df9479e39f1bf23f231773258ea3cn, - ], - [ - 0x0fd5b9f9d183b6da8ba0f99503e851450b3efb33c6a7807a6239e0707b5af271n, - 0x2a4153eb0395955d7d7ee71519d1d600bc32dd39b6283224fbc92d23b860eb54n, - ], - [ - 0x1209e1604a9b10afde568fcfe0ea9f1e09cdf13fe17747abeff0a1454dcf947bn, - 0x0e1d63b8ab7b9a4a7ef8d3d17207dcbbc22e9c21da661ddfdc1ac961e0032b57n, - ], - [ - 0x2982c7c825f0e86293b7a0c9eefea7f5383e222a054ffa4c5d4e5908c543c2a6n, - 0x151b990dec385eab48210cd7766d2de58eba95ff76faeee4eb64e6f3dbd3c139n, - ], - [ - 0x124faaed649b6df79325991151fb88952c9acfd57a6b3cb20b18f2fe63529818n, - 0x229dfd4712f46fe904c28adccd1165786e96baaa2c74a0a7744dbb4ab4300d41n, - ], - [ - 0x0963070c9042bbbbe66468d9e75a719123b52b76ee9797f4b039b5de1b5c9651n, - 0x06aa3729a947ec02394d82a46a0c2c2f8e2013e15f46cc97b96944937da731d0n, - ], - [ - 0x279040e3e8f1e0effaf0450099574e134c3eef819f04cadff27851de962da0d3n, - 0x1ee7f53a1b21c4fbd2ef56895bc274e520140858ba51eff6968eae9d0a03a2f8n, - ], - [ - 0x0502d68753a132e8b268e02362166d6c0e43494aef2a5173eff138aadfe05ad0n, - 0x21629dc5334c80a75f79a4b75169c40bb6eb665796a8c4d1024231cbc4604f1en, - ], - [ - 0x13edf560ae7a1c78296f4609233337cd8fbb009b22d89a27d2e5c94983095fe9n, - 0x039c043f9ac7c68faf473565cdcb51785597c90d8ba14dd8e577bf14d70c53e5n, - ], - [ - 0x075a3019dc700efd12e8b91be0029407d59c3dfeeeced4d8f8d35fed14900d79n, - 0x073d003f8998a46ba32780d2e50c2a287b6902ecb2b82672a817980666c406c1n, - ], - [ - 0x1e8509ab9d961e5dea389e1498be69790390a5f77c7dc68cc55858207ece11c5n, - 0x19979a1f1a22dc051a45427d70f66fc27c064fd451b64b6b609d74f0a6439b2cn, - ], - [ - 0x0dc528103070ee030c96bdfe9004693f52a22042abad186aba5616918c701f56n, - 0x05f194973a699889fecfedf291c50be0526c35c22faba00aec84b967e1a0f278n, - ], - [ - 0x1f795886933d543108a9cb86291f04ba487cd95fb6ff9a062d8e6ac9f267d3fan, - 0x127fe0e1209741e32c0a093bada5517cbab952de68241df774b6ddeabc2a6397n, - ], - [ - 0x156c18df6da11a7f9657751e43b50abea544017d347f27406cf4751e51a81e42n, - 0x28e38ee1433b9eefac4b22ba5d88f1d7979d1fce9920d20213b1c01fb204f725n, - ], - [ - 0x2341ce02c131e47cec7777567cc7996ac3b6fd6255ba880ba819ae4982465becn, - 0x0913340a3a212e4e0adb678d500a70e99e24f7a8370cab3b92df8cb6ec2766f3n, - ], - [ - 0x2ee690cd26ee66b12bfe6a7d4fe3077a8c2a41ce96216a964c1a94227b0cb8f9n, - 0x1e207e2e40816da78ca89b8d98f0ada6208f014beef4efec812f629d42e5e304n, - ], - [ - 0x086d9eebd9fbb9b6394cb155b8ee9e3558857f65053abb4a04c6d956d1fdfe95n, - 0x08deaf603a5fee68ccbf892f95f787dd437283b46362a9071ee1e73ec4e03edcn, - ], - [ - 0x0f63792ebcefa16d26dbfeb58db005dced755740bd047de3fde3013575b57022n, - 0x1cbd79e5b8ac132920b495e66d47f2969df49423452a34336796d152ac7de76bn, - ], - [ - 0x05f6732fe8526a3340e547d2a19a97a5c4538a94ce607eb0909db67c8880bdedn, - 0x1e0bbf2a4e501a83460c96e919bec020187f51ce94c328b3b38b07f34dea2cb2n, - ], - [ - 0x1f1df03870f616146c84545722f1e8064bc9db8180caf35061367af95445bb3fn, - 0x077004e054257d7389065f3f11be644084b357c1b9214a9869d5b6761ccee13cn, - ], -].map(([x, y]) => new grumpkin.ProjectivePoint(x, y, 1n)); - -const lengthGenerator = new grumpkin.ProjectivePoint( - 0x2df8b940e5890e4e1377e05373fae69a1d754f6935e6a780b666947431f2cdcdn, - 0x2ecd88d15967bc53b885912e0d16866154acb6aac2d3f85e27ca7eefb2c19083n, - 1n, -); - -const pointAtInfinity = new grumpkin.ProjectivePoint(0n, 1n, 0n); - -/** - * Create a pedersen commitment (point) from an array of input fields. - */ -function pedersenCommitInternal(input: Buffer[], generatorOffset = 0) { - if (generatorOffset + input.length > defaultGenerators.length) { - throw new Error( - `Pedersen commit overflowed default generators. offset: ${generatorOffset} length: ${input.length}`, - ); - } - const generators = defaultGenerators.slice(generatorOffset, generatorOffset + input.length); - return generators.reduce((a, g, i) => { - // TODO: WARNING! Merkle tree tests fail if we don't reduce modulo p as they feed in 256 bits. - // Is it right that we accept 256 bit buffers here and reduce mod p? Is the right thing to only accept fields? - const ie = toBigIntBE(input[i]) % grumpkin.CURVE.Fp.ORDER; - return ie ? a.add(g.multiply(ie)) : a; - }, pointAtInfinity); -} - -/** - * Create a pedersen commitment (point) from an array of input fields. - */ -export function pedersenCommit(input: Buffer[], generatorOffset = 0) { - const result = pedersenCommitInternal(input, generatorOffset); - return [toBufferBE(result.x, 32), toBufferBE(result.y, 32)]; -} - -/** - * Create a pedersen hash (field) from an array of input fields. - */ -export function pedersenHashWithHashIndex(input: Buffer[], index = 0) { - const result = lengthGenerator.multiply(BigInt(input.length)); - return toBufferBE(result.add(pedersenCommitInternal(input, index)).x, 32); -} +export * from './index.elliptic.js'; +export * from './index.noble.js'; diff --git a/yarn-project/foundation/src/json-rpc/client/json_rpc_client.test.ts b/yarn-project/foundation/src/json-rpc/client/json_rpc_client.test.ts index b07c2f300ab4..7b720a6e1239 100644 --- a/yarn-project/foundation/src/json-rpc/client/json_rpc_client.test.ts +++ b/yarn-project/foundation/src/json-rpc/client/json_rpc_client.test.ts @@ -4,7 +4,7 @@ import { TestNote, TestState } from '../fixtures/test_state.js'; import { JsonRpcServer } from '../server/index.js'; import { createJsonRpcClient } from './json_rpc_client.js'; -test('test an RPC function over client', async () => { +it('test an RPC function over client', async () => { const mockFetch = async (host: string, method: string, body: any) => { const server = new JsonRpcServer(new TestState([new TestNote('a'), new TestNote('b')]), { TestNote }, {}, true); const result = await request(server.getApp().callback()).post(`/${method}`).send(body); diff --git a/yarn-project/foundation/src/json-rpc/convert.test.ts b/yarn-project/foundation/src/json-rpc/convert.test.ts index ddad7fa09bdb..ba5eeaa9f98b 100644 --- a/yarn-project/foundation/src/json-rpc/convert.test.ts +++ b/yarn-project/foundation/src/json-rpc/convert.test.ts @@ -7,7 +7,7 @@ import { ToStringClass as ToStringClassB } from './fixtures/class_b.js'; import { TestNote } from './fixtures/test_state.js'; const TEST_BASE64 = 'YmFzZTY0IGRlY29kZXI='; -test('test an RPC function over client', () => { +it('test an RPC function over client', () => { const cc = new ClassConverter({ TestNote }); const buffer = Buffer.from(TEST_BASE64, 'base64'); expect(convertFromJsonObj(cc, convertToJsonObj(cc, buffer)).toString('base64')).toBe(TEST_BASE64); @@ -16,18 +16,18 @@ test('test an RPC function over client', () => { expect(convertFromJsonObj(cc, convertToJsonObj(cc, note)).toString()).toBe('1'); }); -test('converts a bigint', () => { +it('converts a bigint', () => { expect(convertBigintsInObj(10n)).toEqual({ type: 'bigint', data: '10' }); expect(convertBigintsInObj({ value: 10n })).toEqual({ value: { type: 'bigint', data: '10' } }); expect(convertBigintsInObj([10n])).toEqual([{ type: 'bigint', data: '10' }]); }); -test('does not convert a string', () => { +it('does not convert a string', () => { expect(convertBigintsInObj('hello')).toEqual('hello'); expect(convertBigintsInObj({ msg: 'hello' })).toEqual({ msg: 'hello' }); }); -test('converts a registered class', () => { +it('converts a registered class', () => { const cc = new ClassConverter({ ToStringClass: ToStringClassA }); const obj = { content: new ToStringClassA('a', 'b') }; const serialized = convertToJsonObj(cc, obj); @@ -37,7 +37,7 @@ test('converts a registered class', () => { expect(deserialized.content.y).toEqual('b'); }); -test('converts a class by name in the event of duplicate modules being loaded', () => { +it('converts a class by name in the event of duplicate modules being loaded', () => { expect(ToStringClassA.prototype.constructor.name).toEqual('ToStringClass'); expect(ToStringClassB.prototype.constructor.name).toEqual('ToStringClass'); const cc = new ClassConverter({ ToStringClass: ToStringClassA }); @@ -49,7 +49,7 @@ test('converts a class by name in the event of duplicate modules being loaded', expect(deserialized.content.y).toEqual('b'); }); -test('converts a class by constructor instead of name in the event of minified bundle', () => { +it('converts a class by constructor instead of name in the event of minified bundle', () => { const cc = new ClassConverter({ NotMinifiedToStringClassName: ToStringClassA }); const obj = { content: new ToStringClassA('a', 'b') }; const serialized = convertToJsonObj(cc, obj); @@ -59,18 +59,18 @@ test('converts a class by constructor instead of name in the event of minified b expect(deserialized.content.y).toEqual('b'); }); -test('converts a plain object', () => { +it('converts a plain object', () => { const obj = { a: 10, b: [20, 30], c: 'foo' }; const cc = new ClassConverter(); expect(convertFromJsonObj(cc, convertToJsonObj(cc, obj))).toEqual(obj); }); -test('refuses to convert to json an unknown class', () => { +it('refuses to convert to json an unknown class', () => { const cc = new ClassConverter(); expect(() => convertToJsonObj(cc, { content: new ToStringClassA('a', 'b') })).toThrowError(/not registered/); }); -test('refuses to convert from json an unknown class', () => { +it('refuses to convert from json an unknown class', () => { const cc = new ClassConverter({ ToStringClass: ToStringClassA }); const serialized = convertToJsonObj(cc, { content: new ToStringClassA('a', 'b') }); expect(() => convertFromJsonObj(new ClassConverter(), serialized)).toThrowError(/not registered/); diff --git a/yarn-project/foundation/src/json-rpc/server/json_rpc_server.test.ts b/yarn-project/foundation/src/json-rpc/server/json_rpc_server.test.ts index 7c2d2c856cf2..c5272c2b74cb 100644 --- a/yarn-project/foundation/src/json-rpc/server/json_rpc_server.test.ts +++ b/yarn-project/foundation/src/json-rpc/server/json_rpc_server.test.ts @@ -3,7 +3,7 @@ import request from 'supertest'; import { TestNote, TestState } from '../fixtures/test_state.js'; import { JsonRpcServer } from './json_rpc_server.js'; -test('test an RPC function with a primitive parameter', async () => { +it('test an RPC function with a primitive parameter', async () => { const server = new JsonRpcServer(new TestState([new TestNote('a'), new TestNote('b')]), { TestNote }, {}, true); const response = await request(server.getApp().callback()) .post('/getNote') @@ -12,7 +12,7 @@ test('test an RPC function with a primitive parameter', async () => { expect(response.text).toBe(JSON.stringify({ result: { type: 'TestNote', data: 'a' } })); }); -test('test an RPC function with an array of classes', async () => { +it('test an RPC function with an array of classes', async () => { const server = new JsonRpcServer(new TestState([]), { TestNote }, {}, true); const response = await request(server.getApp().callback()) .post('/addNotes') @@ -23,7 +23,7 @@ test('test an RPC function with an array of classes', async () => { expect(response.text).toBe(JSON.stringify({ result: [{ data: 'a' }, { data: 'b' }, { data: 'c' }] })); }); -test('test invalid JSON', async () => { +it('test invalid JSON', async () => { const server = new JsonRpcServer(new TestState([]), { TestNote }, {}, false); const response = await request(server.getApp().callback()).post('/').send('{'); expect(response.status).toBe(400); @@ -34,7 +34,7 @@ test('test invalid JSON', async () => { }); }); -test('invalid method', async () => { +it('invalid method', async () => { const server = new JsonRpcServer(new TestState([]), { TestNote }, {}, false); const response = await request(server.getApp().callback()).post('/').send({ jsonrpc: '2.0', diff --git a/yarn-project/foundation/src/log/log_history.test.ts b/yarn-project/foundation/src/log/log_history.test.ts index 8049616d6c15..722c9a9fce9d 100644 --- a/yarn-project/foundation/src/log/log_history.test.ts +++ b/yarn-project/foundation/src/log/log_history.test.ts @@ -1,5 +1,3 @@ -import { jest } from '@jest/globals'; - import { createDebugOnlyLogger, enableLogs } from './debug.js'; import { LogHistory } from './log_history.js'; diff --git a/yarn-project/foundation/src/mutex/mutex.test.ts b/yarn-project/foundation/src/mutex/mutex.test.ts index 0c2eb485d895..8b4e9860f7cb 100644 --- a/yarn-project/foundation/src/mutex/mutex.test.ts +++ b/yarn-project/foundation/src/mutex/mutex.test.ts @@ -1,5 +1,3 @@ -import { jest } from '@jest/globals'; - import { Mutex } from './index.js'; import { MutexDatabase } from './mutex_database.js'; diff --git a/yarn-project/foundation/src/serialize/buffer_reader.test.ts b/yarn-project/foundation/src/serialize/buffer_reader.test.ts index 1bc92a95f662..8da7fec98112 100644 --- a/yarn-project/foundation/src/serialize/buffer_reader.test.ts +++ b/yarn-project/foundation/src/serialize/buffer_reader.test.ts @@ -1,5 +1,3 @@ -import { jest } from '@jest/globals'; - import { randomBytes } from '../crypto/index.js'; import { Fq, Fr } from '../fields/fields.js'; import { BufferReader } from './buffer_reader.js'; diff --git a/yarn-project/foundation/src/timer/timer.ts b/yarn-project/foundation/src/timer/timer.ts index b74be9819ea6..ee96cbc94a7b 100644 --- a/yarn-project/foundation/src/timer/timer.ts +++ b/yarn-project/foundation/src/timer/timer.ts @@ -14,7 +14,14 @@ export class Timer { private start: number; constructor() { - this.start = new Date().getTime(); + this.start = performance.now(); + } + + /** + * Return microseconds. + */ + public us() { + return this.ms() * 1000; } /** @@ -25,7 +32,7 @@ export class Timer { * @returns The elapsed time in milliseconds. */ public ms() { - return new Date().getTime() - this.start; + return performance.now() - this.start; } /** @@ -36,6 +43,6 @@ export class Timer { * @returns The elapsed time in seconds. */ public s() { - return (new Date().getTime() - this.start) / 1000; + return this.ms() / 1000; } } diff --git a/yarn-project/noir-private-kernel/src/index.test.ts b/yarn-project/noir-private-kernel/src/index.test.ts index 7fbc73c6ccb5..d06ec7af0a41 100644 --- a/yarn-project/noir-private-kernel/src/index.test.ts +++ b/yarn-project/noir-private-kernel/src/index.test.ts @@ -405,24 +405,21 @@ describe('Noir compatibility tests (interop_testing.nr)', () => { logger = createDebugLogger('noir-private-kernel-compatibility'); }); - it('Complete Address matches Noir', async () => { + it('Complete Address matches Noir', () => { logger('Initialized Noir instance with private kernel init circuit'); - const wasm = await CircuitsWasm.get(); const deployerPubKey = new Point(new Fr(1n), new Fr(2n)); const contractAddrSalt = new Fr(3n); const treeRoot = new Fr(4n); const constructorHash = new Fr(5n); - const res = computeCompleteAddress(wasm, deployerPubKey, contractAddrSalt, treeRoot, constructorHash); + const res = computeCompleteAddress(deployerPubKey, contractAddrSalt, treeRoot, constructorHash); expect(res.address.toString()).toMatchSnapshot(); expect(res.publicKey).toMatchSnapshot(); expect(res.partialAddress.toString()).toMatchSnapshot(); }); - it('TxRequest Hash matches Noir', async () => { - const wasm = await CircuitsWasm.get(); - + it('TxRequest Hash matches Noir', () => { const deploymentData = new ContractDeploymentData( new Point(new Fr(1), new Fr(2)), new Fr(1), @@ -436,14 +433,12 @@ describe('Noir compatibility tests (interop_testing.nr)', () => { argsHash: new Fr(3), txContext: new TxContext(false, false, true, deploymentData, Fr.ZERO, Fr.ZERO), }); - const hash = computeTxHash(wasm, txRequest); + const hash = computeTxHash(txRequest); expect(hash.toString()).toMatchSnapshot(); }); - it('ComputeContractAddressFromPartial matches Noir', async () => { - const wasm = await CircuitsWasm.get(); - + it('ComputeContractAddressFromPartial matches Noir', () => { const deploymentData = new ContractDeploymentData( new Point(new Fr(1), new Fr(2)), new Fr(1), @@ -457,16 +452,14 @@ describe('Noir compatibility tests (interop_testing.nr)', () => { argsHash: new Fr(3), txContext: new TxContext(false, false, true, deploymentData, Fr.ZERO, Fr.ZERO), }); - const hash = computeTxHash(wasm, txRequest); + const hash = computeTxHash(txRequest); expect(hash.toString()).toMatchSnapshot(); }); - it('Function leaf matches noir', async () => { - const wasm = await CircuitsWasm.get(); - + it('Function leaf matches noir', () => { const fnLeafPreimage = new FunctionLeafPreimage(new FunctionSelector(27), false, true, new Fr(1), new Fr(2)); - const fnLeaf = computeFunctionLeaf(wasm, fnLeafPreimage); + const fnLeaf = computeFunctionLeaf(fnLeafPreimage); expect(fnLeaf.toString()).toMatchSnapshot(); }); }); diff --git a/yarn-project/noir-private-kernel/src/noir_test_gen.test.ts b/yarn-project/noir-private-kernel/src/noir_test_gen.test.ts index 9183db2dde7f..602a8b32ad5e 100644 --- a/yarn-project/noir-private-kernel/src/noir_test_gen.test.ts +++ b/yarn-project/noir-private-kernel/src/noir_test_gen.test.ts @@ -37,7 +37,7 @@ describe('Data generation for noir tests', () => { it('Computes function leaf', () => { const functionLeafPreimage = new FunctionLeafPreimage(selector, false, true, vkHash, acirHash); - functionLeaf = computeFunctionLeaf(wasm, functionLeafPreimage); + functionLeaf = computeFunctionLeaf(functionLeafPreimage); expect(functionLeaf.toString()).toMatchSnapshot(); }); @@ -57,7 +57,6 @@ describe('Data generation for noir tests', () => { it('Computes the contract tree root', async () => { const contractLeaf = computeContractLeaf( - wasm, new NewContractData(contractAddress, portalContractAddress, functionTreeRoot), ); const db = levelup((memdown as any)()); diff --git a/yarn-project/package.common.json b/yarn-project/package.common.json index 7e200c5fb86d..1a673ecbe7b5 100644 --- a/yarn-project/package.common.json +++ b/yarn-project/package.common.json @@ -5,6 +5,7 @@ "clean": "rm -rf ./dest .tsbuildinfo", "formatting": "run -T prettier --check ./src && run -T eslint ./src", "formatting:fix": "run -T prettier -w ./src", + "test:light": "NODE_NO_WARNINGS=1 NODE_OPTIONS='--loader ts-node/esm' node --experimental-vm-modules $(yarn bin jest) --runner=jest-light-runner --passWithNoTests", "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests" }, "engines": { diff --git a/yarn-project/pxe/src/contract_tree/index.ts b/yarn-project/pxe/src/contract_tree/index.ts index 4fd6a61cd918..13a6255b4c84 100644 --- a/yarn-project/pxe/src/contract_tree/index.ts +++ b/yarn-project/pxe/src/contract_tree/index.ts @@ -91,10 +91,10 @@ export class ContractTree { const root = computeFunctionTreeRoot(wasm, leaves); const functionData = FunctionData.fromAbi(constructorArtifact); const vkHash = hashVKStr(constructorArtifact.verificationKey, wasm); - const argsHash = await computeVarArgsHash(wasm, args); - const constructorHash = hashConstructor(wasm, functionData, argsHash, vkHash); + const argsHash = computeVarArgsHash(args); + const constructorHash = hashConstructor(functionData, argsHash, vkHash); - const completeAddress = computeCompleteAddress(wasm, from, contractAddressSalt, root, constructorHash); + const completeAddress = computeCompleteAddress(from, contractAddressSalt, root, constructorHash); const contractDao: ContractDao = { ...artifact, @@ -228,7 +228,7 @@ export class ContractTree { const { completeAddress, portalContract } = this.contract; const root = await this.getFunctionTreeRoot(); const newContractData = new NewContractData(completeAddress.address, portalContract, root); - const commitment = computeContractLeaf(this.wasm, newContractData); + const commitment = computeContractLeaf(newContractData); this.contractIndex = await this.stateInfoProvider.findLeafIndex( MerkleTreeId.CONTRACT_TREE, commitment.toBuffer(), diff --git a/yarn-project/pxe/src/kernel_prover/proof_creator.ts b/yarn-project/pxe/src/kernel_prover/proof_creator.ts index 40d24e157593..d1bedafeeeed 100644 --- a/yarn-project/pxe/src/kernel_prover/proof_creator.ts +++ b/yarn-project/pxe/src/kernel_prover/proof_creator.ts @@ -101,11 +101,10 @@ export interface ProofCreator { export class KernelProofCreator implements ProofCreator { constructor(private log = createDebugLogger('aztec:kernel_proof_creator')) {} - public async getSiloedCommitments(publicInputs: PrivateCircuitPublicInputs) { - const wasm = await CircuitsWasm.get(); + public getSiloedCommitments(publicInputs: PrivateCircuitPublicInputs) { const contractAddress = publicInputs.callContext.storageContractAddress; - return publicInputs.newCommitments.map(commitment => siloCommitment(wasm, contractAddress, commitment)); + return Promise.resolve(publicInputs.newCommitments.map(commitment => siloCommitment(contractAddress, commitment))); } public async createProofInit(privateInputs: PrivateKernelInputsInit): Promise { diff --git a/yarn-project/pxe/src/note_processor/note_processor.test.ts b/yarn-project/pxe/src/note_processor/note_processor.test.ts index 00e1018b37c0..fded41ff9843 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.test.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.test.ts @@ -38,13 +38,7 @@ describe('Note Processor', () => { const numCommitmentsPerBlock = TXS_PER_BLOCK * MAX_NEW_COMMITMENTS_PER_TX; const firstBlockDataStartIndex = (firstBlockNum - 1) * numCommitmentsPerBlock; - const computeMockNoteHash = (preimage: Fr[]) => - Fr.fromBuffer( - pedersenHashInputs( - wasm, - preimage.map(p => p.toBuffer()), - ), - ); + const computeMockNoteHash = (preimage: Fr[]) => Fr.fromBuffer(pedersenHashInputs(preimage.map(p => p.toBuffer()))); // ownedData: [tx1, tx2, ...], the numbers in each tx represents the indices of the note hashes the account owns. const createEncryptedLogsAndOwnedNoteSpendingInfo = (ownedData: number[][], ownedNotes: NoteSpendingInfo[]) => { diff --git a/yarn-project/pxe/src/note_processor/note_processor.ts b/yarn-project/pxe/src/note_processor/note_processor.ts index 823be99e7d3c..1310ebf124c0 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.ts @@ -1,4 +1,4 @@ -import { CircuitsWasm, MAX_NEW_COMMITMENTS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX } from '@aztec/circuits.js'; +import { MAX_NEW_COMMITMENTS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX } from '@aztec/circuits.js'; import { computeCommitmentNonce, siloNullifier } from '@aztec/circuits.js/abis'; import { Grumpkin } from '@aztec/circuits.js/barretenberg'; import { Fr } from '@aztec/foundation/fields'; @@ -189,7 +189,6 @@ export class NoteProcessor { { contractAddress, storageSlot, notePreimage }: NoteSpendingInfo, excludedIndices: Set, ) { - const wasm = await CircuitsWasm.get(); let commitmentIndex = 0; let nonce: Fr | undefined; let innerNoteHash: Fr | undefined; @@ -202,7 +201,7 @@ export class NoteProcessor { const commitment = commitments[commitmentIndex]; if (commitment.equals(Fr.ZERO)) break; - const expectedNonce = computeCommitmentNonce(wasm, firstNullifier, commitmentIndex); + const expectedNonce = computeCommitmentNonce(firstNullifier, commitmentIndex); ({ innerNoteHash, siloedNoteHash, uniqueSiloedNoteHash, innerNullifier } = await this.simulator.computeNoteHashAndNullifier( contractAddress, @@ -242,7 +241,7 @@ https://github.com/AztecProtocol/aztec-packages/issues/1641`; commitmentIndex, nonce, innerNoteHash: innerNoteHash!, - siloedNullifier: siloNullifier(wasm, contractAddress, innerNullifier!), + siloedNullifier: siloNullifier(contractAddress, innerNullifier!), }; } diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 16a7349a9207..27bb9ff2567d 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -8,7 +8,6 @@ import { } from '@aztec/acir-simulator'; import { AztecAddress, - CircuitsWasm, CompleteAddress, FunctionData, GrumpkinPrivateKey, @@ -235,8 +234,7 @@ export class PXEService implements PXE { throw new Error('Note does not exist.'); } - const wasm = await CircuitsWasm.get(); - const siloedNullifier = siloNullifier(wasm, contractAddress, innerNullifier!); + const siloedNullifier = siloNullifier(contractAddress, innerNullifier!); const nullifierIndex = await this.node.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, siloedNullifier.toBuffer()); if (nullifierIndex !== undefined) { throw new Error('The note has been destroyed.'); @@ -265,8 +263,6 @@ export class PXEService implements PXE { throw new Error(`Unknown tx: ${txHash}`); } - const wasm = await CircuitsWasm.get(); - const nonces: Fr[] = []; const firstNullifier = tx.newNullifiers[0]; const commitments = tx.newCommitments; @@ -274,7 +270,7 @@ export class PXEService implements PXE { const commitment = commitments[i]; if (commitment.equals(Fr.ZERO)) break; - const nonce = computeCommitmentNonce(wasm, firstNullifier, i); + const nonce = computeCommitmentNonce(firstNullifier, i); const { siloedNoteHash, uniqueSiloedNoteHash } = await this.simulator.computeNoteHashAndNullifier( contractAddress, nonce, @@ -618,7 +614,7 @@ export class PXEService implements PXE { publicInputs: KernelCircuitPublicInputsFinal, enqueuedPublicCalls: PublicCallRequest[], ) { - const callToHash = (call: PublicCallRequest) => call.toPublicCallStackItem().then(item => item.hash()); + const callToHash = (call: PublicCallRequest) => call.toPublicCallStackItem().hash(); const enqueuedPublicCallsHashes = await Promise.all(enqueuedPublicCalls.map(callToHash)); const { publicCallStack } = publicInputs.end; diff --git a/yarn-project/sequencer-client/package.json b/yarn-project/sequencer-client/package.json index c6a4c6a50bdc..2a280c55665d 100644 --- a/yarn-project/sequencer-client/package.json +++ b/yarn-project/sequencer-client/package.json @@ -16,6 +16,7 @@ "clean": "rm -rf ./dest .tsbuildinfo", "formatting": "run -T prettier --check ./src && run -T eslint ./src", "formatting:fix": "run -T prettier -w ./src", + "test:light": "NODE_NO_WARNINGS=1 NODE_OPTIONS='--loader ts-node/esm' node --experimental-vm-modules $(yarn bin jest) --runner=jest-light-runner --passWithNoTests", "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests", "test:integration": "concurrently -k -s first -c reset,dim -n test,anvil \"yarn test:integration:run\" \"anvil\"", "test:integration:run": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --no-cache --config jest.integration.config.json" diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts index e5c828cb5c8a..f5ddccffe60e 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts @@ -1,7 +1,6 @@ import { AppendOnlyTreeSnapshot, BaseOrMergeRollupPublicInputs, - CircuitsWasm, Fr, GlobalVariables, KernelCircuitPublicInputs, @@ -80,8 +79,6 @@ describe('sequencer/solo_block_builder', () => { let rootRollupOutput: RootRollupPublicInputs; let mockL1ToL2Messages: Fr[]; - let wasm: CircuitsWasm; - let globalVariables: GlobalVariables; const emptyProof = new Proof(Buffer.alloc(32, 0)); @@ -89,10 +86,6 @@ describe('sequencer/solo_block_builder', () => { const chainId = Fr.ZERO; const version = Fr.ZERO; - beforeAll(async () => { - wasm = await CircuitsWasm.get(); - }); - beforeEach(async () => { blockNumber = 3; globalVariables = new GlobalVariables(chainId, version, new Fr(blockNumber), Fr.ZERO); @@ -128,7 +121,7 @@ describe('sequencer/solo_block_builder', () => { // Updates the expectedDb trees based on the new commitments, contracts, and nullifiers from these txs const updateExpectedTreesFromTxs = async (txs: ProcessedTx[]) => { - const newContracts = flatMap(txs, tx => tx.data.end.newContracts.map(n => computeContractLeaf(wasm, n))); + const newContracts = flatMap(txs, tx => tx.data.end.newContracts.map(n => computeContractLeaf(n))); for (const [tree, leaves] of [ [MerkleTreeId.NOTE_HASH_TREE, flatMap(txs, tx => tx.data.end.newCommitments.map(l => l.toBuffer()))], [MerkleTreeId.CONTRACT_TREE, newContracts.map(x => x.toBuffer())], @@ -152,7 +145,6 @@ describe('sequencer/solo_block_builder', () => { const updateHistoricBlocksTree = async () => { const blockHash = computeBlockHashWithGlobals( - wasm, globalVariables, rootRollupOutput.endNoteHashTreeSnapshot.root, rootRollupOutput.endNullifierTreeSnapshot.root, @@ -219,7 +211,7 @@ describe('sequencer/solo_block_builder', () => { const newNullifiers = flatMap(txs, tx => tx.data.end.newNullifiers); const newCommitments = flatMap(txs, tx => tx.data.end.newCommitments); - const newContracts = flatMap(txs, tx => tx.data.end.newContracts).map(cd => computeContractLeaf(wasm, cd)); + const newContracts = flatMap(txs, tx => tx.data.end.newContracts).map(cd => computeContractLeaf(cd)); const newContractData = flatMap(txs, tx => tx.data.end.newContracts).map( n => new ContractData(n.contractAddress, n.portalContractAddress), ); diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts index b7015942be54..b02c12ebb1c1 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts @@ -4,7 +4,6 @@ import { BaseRollupInputs, CONTRACT_SUBTREE_HEIGHT, CONTRACT_SUBTREE_SIBLING_PATH_LENGTH, - CircuitsWasm, ConstantRollupData, GlobalVariables, HISTORIC_BLOCKS_TREE_HEIGHT, @@ -132,10 +131,9 @@ export class SoloBlockBuilder implements BlockBuilder { } = circuitsOutput; // Collect all new nullifiers, commitments, and contracts from all txs in this block - const wasm = await CircuitsWasm.get(); const newNullifiers = flatMap(txs, tx => tx.data.end.newNullifiers); const newCommitments = flatMap(txs, tx => tx.data.end.newCommitments); - const newContracts = flatMap(txs, tx => tx.data.end.newContracts).map(cd => computeContractLeaf(wasm, cd)); + const newContracts = flatMap(txs, tx => tx.data.end.newContracts).map(cd => computeContractLeaf(cd)); const newContractData = flatMap(txs, tx => tx.data.end.newContracts).map( n => new ContractData(n.contractAddress, n.portalContractAddress), ); @@ -341,9 +339,7 @@ export class SoloBlockBuilder implements BlockBuilder { ) ).map(r => r.root); - const wasm = await CircuitsWasm.get(); const blockHash = computeBlockHashWithGlobals( - wasm, globals, noteHashTreeRoot, nullifierTreeRoot, @@ -541,14 +537,11 @@ export class SoloBlockBuilder implements BlockBuilder { return new MembershipWitness(height, index, assertLength(path.toFieldArray(), height)); } - protected async getHistoricTreesMembershipWitnessFor(tx: ProcessedTx) { - const wasm = await CircuitsWasm.get(); - + protected getHistoricTreesMembershipWitnessFor(tx: ProcessedTx) { const blockData = tx.data.constants.blockData; const { noteHashTreeRoot, nullifierTreeRoot, contractTreeRoot, l1ToL2MessagesTreeRoot, publicDataTreeRoot } = blockData; const blockHash = computeBlockHash( - wasm, blockData.globalVariablesHash, noteHashTreeRoot, nullifierTreeRoot, @@ -648,8 +641,6 @@ export class SoloBlockBuilder implements BlockBuilder { // Builds the base rollup inputs, updating the contract, nullifier, and data trees in the process protected async buildBaseRollupInput(left: ProcessedTx, right: ProcessedTx, globalVariables: GlobalVariables) { - const wasm = await CircuitsWasm.get(); - // Get trees info before any changes hit const constants = await this.getConstantRollupData(globalVariables); const startNullifierTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.NULLIFIER_TREE); @@ -679,9 +670,7 @@ export class SoloBlockBuilder implements BlockBuilder { // Update the contract and note hash trees with the new items being inserted to get the new roots // that will be used by the next iteration of the base rollup circuit, skipping the empty ones - const newContracts = flatMap([left, right], tx => - tx.data.end.newContracts.map(cd => computeContractLeaf(wasm, cd)), - ); + const newContracts = flatMap([left, right], tx => tx.data.end.newContracts.map(cd => computeContractLeaf(cd))); const newCommitments = flatMap([left, right], tx => tx.data.end.newCommitments.map(x => x.toBuffer())); await this.db.appendLeaves( MerkleTreeId.CONTRACT_TREE, diff --git a/yarn-project/sequencer-client/src/sequencer/public_processor.ts b/yarn-project/sequencer-client/src/sequencer/public_processor.ts index 1f63c6f4b82a..501cd78ca4bb 100644 --- a/yarn-project/sequencer-client/src/sequencer/public_processor.ts +++ b/yarn-project/sequencer-client/src/sequencer/public_processor.ts @@ -201,7 +201,7 @@ export class PublicProcessor { } // HACK(#1622): Manually patches the ordering of public state actions // TODO(#757): Enforce proper ordering of public state actions - await this.patchPublicStorageActionOrdering(kernelOutput, enqueuedExecutionResult!); + this.patchPublicStorageActionOrdering(kernelOutput, enqueuedExecutionResult!); } return [kernelOutput, kernelProof, newUnencryptedFunctionLogs]; @@ -262,7 +262,7 @@ export class PublicProcessor { return PublicCircuitPublicInputs.from({ callContext: result.execution.callContext, proverAddress: AztecAddress.ZERO, - argsHash: await computeVarArgsHash(wasm, result.execution.args), + argsHash: computeVarArgsHash(result.execution.args), newCommitments: padArrayEnd(result.newCommitments, Fr.ZERO, MAX_NEW_COMMITMENTS_PER_CALL), newNullifiers: padArrayEnd(result.newNullifiers, Fr.ZERO, MAX_NEW_NULLIFIERS_PER_CALL), newL2ToL1Msgs: padArrayEnd(result.newL2ToL1Messages, Fr.ZERO, MAX_NEW_L2_TO_L1_MSGS_PER_CALL), @@ -345,14 +345,10 @@ export class PublicProcessor { * @param publicInputs - to be patched here: public inputs to the kernel iteration up to this point * @param execResult - result of the top/first execution for this enqueued public call */ - private async patchPublicStorageActionOrdering( - publicInputs: KernelCircuitPublicInputs, - execResult: PublicExecutionResult, - ) { + private patchPublicStorageActionOrdering(publicInputs: KernelCircuitPublicInputs, execResult: PublicExecutionResult) { // Convert ContractStorage* objects to PublicData* objects and sort them in execution order - const wasm = await CircuitsWasm.get(); - const simPublicDataReads = collectPublicDataReads(wasm, execResult); - const simPublicDataUpdateRequests = collectPublicDataUpdateRequests(wasm, execResult); + const simPublicDataReads = collectPublicDataReads(execResult); + const simPublicDataUpdateRequests = collectPublicDataUpdateRequests(execResult); const { publicDataReads, publicDataUpdateRequests } = publicInputs.end; // from kernel diff --git a/yarn-project/sequencer-client/src/simulator/public_executor.ts b/yarn-project/sequencer-client/src/simulator/public_executor.ts index affb9e1ccb6d..d0e6b024f3f1 100644 --- a/yarn-project/sequencer-client/src/simulator/public_executor.ts +++ b/yarn-project/sequencer-client/src/simulator/public_executor.ts @@ -5,7 +5,7 @@ import { PublicExecutor, PublicStateDB, } from '@aztec/acir-simulator'; -import { AztecAddress, CircuitsWasm, EthAddress, Fr, FunctionSelector, HistoricBlockData } from '@aztec/circuits.js'; +import { AztecAddress, EthAddress, Fr, FunctionSelector, HistoricBlockData } from '@aztec/circuits.js'; import { computePublicDataTreeIndex } from '@aztec/circuits.js/abis'; import { ContractDataSource, ExtendedContractData, L1ToL2MessageSource, MerkleTreeId, Tx } from '@aztec/types'; import { MerkleTreeOperations } from '@aztec/world-state'; @@ -107,7 +107,7 @@ class WorldStatePublicDB implements PublicStateDB { * @returns The current value in the storage slot. */ public async storageRead(contract: AztecAddress, slot: Fr): Promise { - const index = computePublicDataTreeIndex(await CircuitsWasm.get(), contract, slot).value; + const index = computePublicDataTreeIndex(contract, slot).value; const cached = this.writeCache.get(index); if (cached !== undefined) return cached; const value = await this.db.getLeafValue(MerkleTreeId.PUBLIC_DATA_TREE, index); @@ -120,9 +120,10 @@ class WorldStatePublicDB implements PublicStateDB { * @param slot - Slot to read in the contract storage. * @param newValue - The new value to store. */ - public async storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise { - const index = computePublicDataTreeIndex(await CircuitsWasm.get(), contract, slot).value; + public storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise { + const index = computePublicDataTreeIndex(contract, slot).value; this.writeCache.set(index, newValue); + return Promise.resolve(); } } diff --git a/yarn-project/types/src/packed_arguments.ts b/yarn-project/types/src/packed_arguments.ts index 538afec05f6b..8b59ede60bad 100644 --- a/yarn-project/types/src/packed_arguments.ts +++ b/yarn-project/types/src/packed_arguments.ts @@ -1,4 +1,4 @@ -import { CircuitsWasm, FieldsOf, Fr, Vector } from '@aztec/circuits.js'; +import { FieldsOf, Fr, Vector } from '@aztec/circuits.js'; import { computeVarArgsHash } from '@aztec/circuits.js/abis'; import { BufferReader, serializeToBuffer } from '@aztec/circuits.js/utils'; @@ -25,8 +25,8 @@ export class PackedArguments { return new PackedArguments(...PackedArguments.getFields(fields)); } - static async fromArgs(args: Fr[], wasm?: CircuitsWasm) { - return new PackedArguments(args, await computeVarArgsHash(wasm ?? (await CircuitsWasm.get()), args)); + static fromArgs(args: Fr[]) { + return new PackedArguments(args, computeVarArgsHash(args)); } toBuffer() { diff --git a/yarn-project/world-state/src/world-state-db/merkle_trees.ts b/yarn-project/world-state/src/world-state-db/merkle_trees.ts index b48367539dba..2032f6400e3a 100644 --- a/yarn-project/world-state/src/world-state-db/merkle_trees.ts +++ b/yarn-project/world-state/src/world-state-db/merkle_trees.ts @@ -1,6 +1,5 @@ import { CONTRACT_TREE_HEIGHT, - CircuitsWasm, Fr, GlobalVariables, HISTORIC_BLOCKS_TREE_HEIGHT, @@ -14,7 +13,6 @@ import { computeBlockHash, computeGlobalsHash } from '@aztec/circuits.js/abis'; import { Committable } from '@aztec/foundation/committable'; import { SerialQueue } from '@aztec/foundation/fifo'; import { createDebugLogger } from '@aztec/foundation/log'; -import { IWasmModule } from '@aztec/foundation/wasm'; import { AppendOnlyTree, IndexedTree, @@ -71,7 +69,7 @@ export class MerkleTrees implements MerkleTreeDb { * @param optionalWasm - WASM instance to use for hashing (if not provided PrimitivesWasm will be used). * @param fromDbOptions - Options to initialize the trees from the database. */ - public async init(optionalWasm?: IWasmModule, fromDbOptions?: FromDbOptions) { + public async init(fromDbOptions?: FromDbOptions) { const fromDb = fromDbOptions !== undefined; const initializeTree = fromDb ? loadTree : newTree; @@ -140,9 +138,9 @@ export class MerkleTrees implements MerkleTreeDb { * @param wasm - WASM instance to use for hashing (if not provided PrimitivesWasm will be used). * @returns - A fully initialized MerkleTrees instance. */ - public static async new(db: levelup.LevelUp, wasm?: IWasmModule) { + public static async new(db: levelup.LevelUp) { const merkleTrees = new MerkleTrees(db); - await merkleTrees.init(wasm); + await merkleTrees.init(); return merkleTrees; } @@ -225,8 +223,7 @@ export class MerkleTrees implements MerkleTreeDb { private async _getCurrentBlockHash(globalsHash: Fr, includeUncommitted: boolean): Promise { const roots = (await this._getAllTreeRoots(includeUncommitted)).map(root => Fr.fromBuffer(root)); - const wasm = await CircuitsWasm.get(); - return computeBlockHash(wasm, globalsHash, roots[0], roots[1], roots[2], roots[3], roots[4]); + return computeBlockHash(globalsHash, roots[0], roots[1], roots[2], roots[3], roots[4]); } private _getAllTreeRoots(includeUncommitted: boolean): Promise { diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 09832b701b8c..189878eb9502 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -57,6 +57,13 @@ __metadata: languageName: node linkType: hard +"@assemblyscript/loader@npm:^0.10.1": + version: 0.10.1 + resolution: "@assemblyscript/loader@npm:0.10.1" + checksum: fd1f57bdf2c55252a48c2d93fbec3c5a9ef4ca40e581e8709dd8ee437613eb47af74c8cdba011a324077eda9605d6f24983f429c2ce18b0b582ddcc5acf75c26 + languageName: node + linkType: hard + "@aztec/acir-simulator@workspace:^, @aztec/acir-simulator@workspace:acir-simulator": version: 0.0.0-use.local resolution: "@aztec/acir-simulator@workspace:acir-simulator" @@ -339,6 +346,7 @@ __metadata: detect-node: ^2.1.0 eslint: ^8.35.0 jest: ^29.5.0 + jest-light-runner: ^0.5.1 lodash.capitalize: ^4.2.1 lodash.chunk: ^4.2.0 lodash.mapvalues: ^4.6.0 @@ -479,8 +487,10 @@ __metadata: "@koa/cors": ^4.0.0 "@noble/curves": ^1.2.0 "@rushstack/eslint-patch": ^1.1.4 + "@types/bn.js": ^5.1.3 "@types/debug": ^4.1.7 "@types/detect-node": ^2.0.0 + "@types/elliptic": ^6.4.16 "@types/jest": ^29.5.0 "@types/koa": ^2.13.5 "@types/koa-bodyparser": ^4.3.10 @@ -497,9 +507,11 @@ __metadata: "@types/supertest": ^2.0.12 "@typescript-eslint/eslint-plugin": ^6.2.1 "@typescript-eslint/parser": ^6.2.1 + bn.js: ^5.2.1 comlink: ^4.4.1 debug: ^4.3.4 detect-node: ^2.1.0 + elliptic: ^6.5.4 eslint: ^8.21.0 eslint-config-prettier: ^8.5.0 eslint-plugin-jsdoc: ^40.1.0 @@ -507,6 +519,7 @@ __metadata: eslint-plugin-tsdoc: ^0.2.17 hash.js: ^1.1.7 jest: ^29.5.0 + jest-light-runner: ^0.5.1 koa: ^2.14.2 koa-bodyparser: ^4.4.0 koa-compress: ^5.1.0 @@ -515,6 +528,7 @@ __metadata: levelup: ^5.1.1 lodash.clonedeepwith: ^4.5.0 memdown: ^6.1.1 + mocha: ^10.2.0 pako: ^2.1.0 prettier: ^2.7.1 sha3: ^2.1.4 @@ -2192,6 +2206,20 @@ __metadata: languageName: node linkType: hard +"@jest/console@npm:^29.7.0": + version: 29.7.0 + resolution: "@jest/console@npm:29.7.0" + dependencies: + "@jest/types": ^29.6.3 + "@types/node": "*" + chalk: ^4.0.0 + jest-message-util: ^29.7.0 + jest-util: ^29.7.0 + slash: ^3.0.0 + checksum: 0e3624e32c5a8e7361e889db70b170876401b7d70f509a2538c31d5cd50deb0c1ae4b92dc63fe18a0902e0a48c590c21d53787a0df41a52b34fa7cab96c384d6 + languageName: node + linkType: hard + "@jest/core@npm:^29.6.2": version: 29.6.2 resolution: "@jest/core@npm:29.6.2" @@ -2298,6 +2326,18 @@ __metadata: languageName: node linkType: hard +"@jest/environment@npm:^29.7.0": + version: 29.7.0 + resolution: "@jest/environment@npm:29.7.0" + dependencies: + "@jest/fake-timers": ^29.7.0 + "@jest/types": ^29.6.3 + "@types/node": "*" + jest-mock: ^29.7.0 + checksum: 6fb398143b2543d4b9b8d1c6dbce83fa5247f84f550330604be744e24c2bd2178bb893657d62d1b97cf2f24baf85c450223f8237cccb71192c36a38ea2272934 + languageName: node + linkType: hard + "@jest/expect-utils@npm:^29.6.2": version: 29.6.2 resolution: "@jest/expect-utils@npm:29.6.2" @@ -2316,6 +2356,25 @@ __metadata: languageName: node linkType: hard +"@jest/expect-utils@npm:^29.7.0": + version: 29.7.0 + resolution: "@jest/expect-utils@npm:29.7.0" + dependencies: + jest-get-type: ^29.6.3 + checksum: 75eb177f3d00b6331bcaa057e07c0ccb0733a1d0a1943e1d8db346779039cb7f103789f16e502f888a3096fb58c2300c38d1f3748b36a7fa762eb6f6d1b160ed + languageName: node + linkType: hard + +"@jest/expect@npm:^29.0.1, @jest/expect@npm:^29.7.0": + version: 29.7.0 + resolution: "@jest/expect@npm:29.7.0" + dependencies: + expect: ^29.7.0 + jest-snapshot: ^29.7.0 + checksum: a01cb85fd9401bab3370618f4b9013b90c93536562222d920e702a0b575d239d74cecfe98010aaec7ad464f67cf534a353d92d181646a4b792acaa7e912ae55e + languageName: node + linkType: hard + "@jest/expect@npm:^29.6.2": version: 29.6.2 resolution: "@jest/expect@npm:29.6.2" @@ -2336,6 +2395,20 @@ __metadata: languageName: node linkType: hard +"@jest/fake-timers@npm:^29.2.2, @jest/fake-timers@npm:^29.7.0": + version: 29.7.0 + resolution: "@jest/fake-timers@npm:29.7.0" + dependencies: + "@jest/types": ^29.6.3 + "@sinonjs/fake-timers": ^10.0.2 + "@types/node": "*" + jest-message-util: ^29.7.0 + jest-mock: ^29.7.0 + jest-util: ^29.7.0 + checksum: caf2bbd11f71c9241b458d1b5a66cbe95debc5a15d96442444b5d5c7ba774f523c76627c6931cca5e10e76f0d08761f6f1f01a608898f4751a0eee54fc3d8d00 + languageName: node + linkType: hard + "@jest/fake-timers@npm:^29.6.2": version: 29.6.2 resolution: "@jest/fake-timers@npm:29.6.2" @@ -2388,6 +2461,18 @@ __metadata: languageName: node linkType: hard +"@jest/globals@npm:^29.7.0": + version: 29.7.0 + resolution: "@jest/globals@npm:29.7.0" + dependencies: + "@jest/environment": ^29.7.0 + "@jest/expect": ^29.7.0 + "@jest/types": ^29.6.3 + jest-mock: ^29.7.0 + checksum: 97dbb9459135693ad3a422e65ca1c250f03d82b2a77f6207e7fa0edd2c9d2015fbe4346f3dc9ebff1678b9d8da74754d4d440b7837497f8927059c0642a22123 + languageName: node + linkType: hard + "@jest/reporters@npm:^29.6.2": version: 29.6.2 resolution: "@jest/reporters@npm:29.6.2" @@ -2526,6 +2611,18 @@ __metadata: languageName: node linkType: hard +"@jest/test-result@npm:^29.7.0": + version: 29.7.0 + resolution: "@jest/test-result@npm:29.7.0" + dependencies: + "@jest/console": ^29.7.0 + "@jest/types": ^29.6.3 + "@types/istanbul-lib-coverage": ^2.0.0 + collect-v8-coverage: ^1.0.0 + checksum: 67b6317d526e335212e5da0e768e3b8ab8a53df110361b80761353ad23b6aea4432b7c5665bdeb87658ea373b90fb1afe02ed3611ef6c858c7fba377505057fa + languageName: node + linkType: hard + "@jest/test-sequencer@npm:^29.6.2": version: 29.6.2 resolution: "@jest/test-sequencer@npm:29.6.2" @@ -2596,6 +2693,29 @@ __metadata: languageName: node linkType: hard +"@jest/transform@npm:^29.7.0": + version: 29.7.0 + resolution: "@jest/transform@npm:29.7.0" + dependencies: + "@babel/core": ^7.11.6 + "@jest/types": ^29.6.3 + "@jridgewell/trace-mapping": ^0.3.18 + babel-plugin-istanbul: ^6.1.1 + chalk: ^4.0.0 + convert-source-map: ^2.0.0 + fast-json-stable-stringify: ^2.1.0 + graceful-fs: ^4.2.9 + jest-haste-map: ^29.7.0 + jest-regex-util: ^29.6.3 + jest-util: ^29.7.0 + micromatch: ^4.0.4 + pirates: ^4.0.4 + slash: ^3.0.0 + write-file-atomic: ^4.0.2 + checksum: 0f8ac9f413903b3cb6d240102db848f2a354f63971ab885833799a9964999dd51c388162106a807f810071f864302cdd8e3f0c241c29ce02d85a36f18f3f40ab + languageName: node + linkType: hard + "@jest/types@npm:^29.6.1": version: 29.6.1 resolution: "@jest/types@npm:29.6.1" @@ -4268,6 +4388,15 @@ __metadata: languageName: node linkType: hard +"@types/bn.js@npm:*, @types/bn.js@npm:^5.1.3": + version: 5.1.3 + resolution: "@types/bn.js@npm:5.1.3" + dependencies: + "@types/node": "*" + checksum: 6cd144b8192b6655a009021a4f838a725ea3eb4c5e6425ffc5b144788f7612fb09018c2359954edef32ab7db15f7070b77d05499318b6d9824a55cb7e6776620 + languageName: node + linkType: hard + "@types/body-parser@npm:*": version: 1.19.2 resolution: "@types/body-parser@npm:1.19.2" @@ -4357,6 +4486,15 @@ __metadata: languageName: node linkType: hard +"@types/elliptic@npm:^6.4.16": + version: 6.4.16 + resolution: "@types/elliptic@npm:6.4.16" + dependencies: + "@types/bn.js": "*" + checksum: fedecadbab1a469a22bc9f8e44ce730bd945faed82230174c9df4748f29948d34d9d6f7c79122049cd37f048522e28019a470df7a55c86765a82fb0d05f3f415 + languageName: node + linkType: hard + "@types/eslint-scope@npm:^3.7.3": version: 3.7.4 resolution: "@types/eslint-scope@npm:3.7.4" @@ -7056,7 +7194,7 @@ __metadata: languageName: node linkType: hard -"base64-js@npm:^1.3.1, base64-js@npm:^1.5.1": +"base64-js@npm:^1.2.0, base64-js@npm:^1.3.1, base64-js@npm:^1.5.1": version: 1.5.1 resolution: "base64-js@npm:1.5.1" checksum: 669632eb3745404c2f822a18fc3a0122d2f9a7a13f7fb8b5823ee19d1d2ff9ee5b52c53367176ea4ad093c332fd5ab4bd0ebae5a8e27917a4105a4cfc86b1005 @@ -9042,7 +9180,7 @@ __metadata: languageName: node linkType: hard -"elliptic@npm:6.5.4, elliptic@npm:^6.5.3": +"elliptic@npm:6.5.4, elliptic@npm:^6.5.3, elliptic@npm:^6.5.4": version: 6.5.4 resolution: "elliptic@npm:6.5.4" dependencies: @@ -9808,6 +9946,13 @@ __metadata: languageName: node linkType: hard +"eventemitter-asyncresource@npm:^1.0.0": + version: 1.0.0 + resolution: "eventemitter-asyncresource@npm:1.0.0" + checksum: 3cfbbc3490bd429a165bff6336289ff810f7df214796f25000d2097a5a0883eae51542a78674916ff99bbd4c66811911b310df1cb4fc96dfc9546ba9dfc89f8f + languageName: node + linkType: hard + "eventemitter3@npm:4.0.7, eventemitter3@npm:^4.0.0, eventemitter3@npm:^4.0.7": version: 4.0.7 resolution: "eventemitter3@npm:4.0.7" @@ -9901,6 +10046,19 @@ __metadata: languageName: node linkType: hard +"expect@npm:^29.7.0": + version: 29.7.0 + resolution: "expect@npm:29.7.0" + dependencies: + "@jest/expect-utils": ^29.7.0 + jest-get-type: ^29.6.3 + jest-matcher-utils: ^29.7.0 + jest-message-util: ^29.7.0 + jest-util: ^29.7.0 + checksum: 9257f10288e149b81254a0fda8ffe8d54a7061cd61d7515779998b012579d2b8c22354b0eb901daf0145f347403da582f75f359f4810c007182ad3fb318b5c0c + languageName: node + linkType: hard + "exponential-backoff@npm:^3.1.1": version: 3.1.1 resolution: "exponential-backoff@npm:3.1.1" @@ -10900,6 +11058,24 @@ __metadata: languageName: node linkType: hard +"hdr-histogram-js@npm:^2.0.1": + version: 2.0.3 + resolution: "hdr-histogram-js@npm:2.0.3" + dependencies: + "@assemblyscript/loader": ^0.10.1 + base64-js: ^1.2.0 + pako: ^1.0.3 + checksum: 7bb252ba3596bed72b90427ffc6f6fa332a460c4810788faa9b9a743f7ac6f1cb42dccd7ae7555740f0a8c0602884944d00d1ccfb746af4976a816772361a6d6 + languageName: node + linkType: hard + +"hdr-histogram-percentiles-obj@npm:^3.0.0": + version: 3.0.0 + resolution: "hdr-histogram-percentiles-obj@npm:3.0.0" + checksum: ab238edcb38d9b60d23ca53da0ecd9a6b1c8ee9a49e30a6146bd3f8f70f26244652f28b79974157c00504e7ddf3129e0ddb217baf71d32330e3fae0105bf30ed + languageName: node + linkType: hard + "he@npm:1.2.0": version: 1.2.0 resolution: "he@npm:1.2.0" @@ -12189,6 +12365,34 @@ __metadata: languageName: node linkType: hard +"jest-circus@npm:^29.0.1": + version: 29.7.0 + resolution: "jest-circus@npm:29.7.0" + dependencies: + "@jest/environment": ^29.7.0 + "@jest/expect": ^29.7.0 + "@jest/test-result": ^29.7.0 + "@jest/types": ^29.6.3 + "@types/node": "*" + chalk: ^4.0.0 + co: ^4.6.0 + dedent: ^1.0.0 + is-generator-fn: ^2.0.0 + jest-each: ^29.7.0 + jest-matcher-utils: ^29.7.0 + jest-message-util: ^29.7.0 + jest-runtime: ^29.7.0 + jest-snapshot: ^29.7.0 + jest-util: ^29.7.0 + p-limit: ^3.1.0 + pretty-format: ^29.7.0 + pure-rand: ^6.0.0 + slash: ^3.0.0 + stack-utils: ^2.0.3 + checksum: 349437148924a5a109c9b8aad6d393a9591b4dac1918fc97d81b7fc515bc905af9918495055071404af1fab4e48e4b04ac3593477b1d5dcf48c4e71b527c70a7 + languageName: node + linkType: hard + "jest-circus@npm:^29.6.2": version: 29.6.2 resolution: "jest-circus@npm:29.6.2" @@ -12399,6 +12603,18 @@ __metadata: languageName: node linkType: hard +"jest-diff@npm:^29.7.0": + version: 29.7.0 + resolution: "jest-diff@npm:29.7.0" + dependencies: + chalk: ^4.0.0 + diff-sequences: ^29.6.3 + jest-get-type: ^29.6.3 + pretty-format: ^29.7.0 + checksum: 08e24a9dd43bfba1ef07a6374e5af138f53137b79ec3d5cc71a2303515335898888fa5409959172e1e05de966c9e714368d15e8994b0af7441f0721ee8e1bb77 + languageName: node + linkType: hard + "jest-docblock@npm:^29.4.3": version: 29.4.3 resolution: "jest-docblock@npm:29.4.3" @@ -12417,6 +12633,19 @@ __metadata: languageName: node linkType: hard +"jest-each@npm:^29.0.1, jest-each@npm:^29.7.0": + version: 29.7.0 + resolution: "jest-each@npm:29.7.0" + dependencies: + "@jest/types": ^29.6.3 + chalk: ^4.0.0 + jest-get-type: ^29.6.3 + jest-util: ^29.7.0 + pretty-format: ^29.7.0 + checksum: e88f99f0184000fc8813f2a0aa79e29deeb63700a3b9b7928b8a418d7d93cd24933608591dbbdea732b473eb2021c72991b5cc51a17966842841c6e28e6f691c + languageName: node + linkType: hard + "jest-each@npm:^29.6.2": version: 29.6.2 resolution: "jest-each@npm:29.6.2" @@ -12531,6 +12760,29 @@ __metadata: languageName: node linkType: hard +"jest-haste-map@npm:^29.7.0": + version: 29.7.0 + resolution: "jest-haste-map@npm:29.7.0" + dependencies: + "@jest/types": ^29.6.3 + "@types/graceful-fs": ^4.1.3 + "@types/node": "*" + anymatch: ^3.0.3 + fb-watchman: ^2.0.0 + fsevents: ^2.3.2 + graceful-fs: ^4.2.9 + jest-regex-util: ^29.6.3 + jest-util: ^29.7.0 + jest-worker: ^29.7.0 + micromatch: ^4.0.4 + walker: ^1.0.8 + dependenciesMeta: + fsevents: + optional: true + checksum: c2c8f2d3e792a963940fbdfa563ce14ef9e14d4d86da645b96d3cd346b8d35c5ce0b992ee08593939b5f718cf0a1f5a90011a056548a1dbf58397d4356786f01 + languageName: node + linkType: hard + "jest-leak-detector@npm:^29.6.2": version: 29.6.2 resolution: "jest-leak-detector@npm:29.6.2" @@ -12551,6 +12803,24 @@ __metadata: languageName: node linkType: hard +"jest-light-runner@npm:^0.5.1": + version: 0.5.1 + resolution: "jest-light-runner@npm:0.5.1" + dependencies: + "@jest/expect": ^29.0.1 + "@jest/fake-timers": ^29.2.2 + jest-circus: ^29.0.1 + jest-each: ^29.0.1 + jest-mock: ^29.0.1 + jest-snapshot: ^29.0.1 + piscina: ^3.1.0 + supports-color: ^9.2.1 + peerDependencies: + jest: ^27.5.0 || ^28.0.0 || ^29.0.0 + checksum: ef7ce093835f51396308ce488401fc0cce4fa2f278b0420bf4b2f6bedd469d97264db53f3a5fca3df28ff4f72714782406a0bc425b0fa473e8572bf83b738ed2 + languageName: node + linkType: hard + "jest-matcher-utils@npm:^29.6.2": version: 29.6.2 resolution: "jest-matcher-utils@npm:29.6.2" @@ -12575,6 +12845,18 @@ __metadata: languageName: node linkType: hard +"jest-matcher-utils@npm:^29.7.0": + version: 29.7.0 + resolution: "jest-matcher-utils@npm:29.7.0" + dependencies: + chalk: ^4.0.0 + jest-diff: ^29.7.0 + jest-get-type: ^29.6.3 + pretty-format: ^29.7.0 + checksum: d7259e5f995d915e8a37a8fd494cb7d6af24cd2a287b200f831717ba0d015190375f9f5dc35393b8ba2aae9b2ebd60984635269c7f8cff7d85b077543b7744cd + languageName: node + linkType: hard + "jest-message-util@npm:^29.6.2": version: 29.6.2 resolution: "jest-message-util@npm:29.6.2" @@ -12609,6 +12891,23 @@ __metadata: languageName: node linkType: hard +"jest-message-util@npm:^29.7.0": + version: 29.7.0 + resolution: "jest-message-util@npm:29.7.0" + dependencies: + "@babel/code-frame": ^7.12.13 + "@jest/types": ^29.6.3 + "@types/stack-utils": ^2.0.0 + chalk: ^4.0.0 + graceful-fs: ^4.2.9 + micromatch: ^4.0.4 + pretty-format: ^29.7.0 + slash: ^3.0.0 + stack-utils: ^2.0.3 + checksum: a9d025b1c6726a2ff17d54cc694de088b0489456c69106be6b615db7a51b7beb66788bea7a59991a019d924fbf20f67d085a445aedb9a4d6760363f4d7d09930 + languageName: node + linkType: hard + "jest-mock-extended@npm:^3.0.3, jest-mock-extended@npm:^3.0.4": version: 3.0.4 resolution: "jest-mock-extended@npm:3.0.4" @@ -12633,6 +12932,17 @@ __metadata: languageName: node linkType: hard +"jest-mock@npm:^29.0.1, jest-mock@npm:^29.7.0": + version: 29.7.0 + resolution: "jest-mock@npm:29.7.0" + dependencies: + "@jest/types": ^29.6.3 + "@types/node": "*" + jest-util: ^29.7.0 + checksum: 81ba9b68689a60be1482212878973700347cb72833c5e5af09895882b9eb5c4e02843a1bbdf23f94c52d42708bab53a30c45a3482952c9eec173d1eaac5b86c5 + languageName: node + linkType: hard + "jest-mock@npm:^29.6.2": version: 29.6.2 resolution: "jest-mock@npm:29.6.2" @@ -12735,6 +13045,23 @@ __metadata: languageName: node linkType: hard +"jest-resolve@npm:^29.7.0": + version: 29.7.0 + resolution: "jest-resolve@npm:29.7.0" + dependencies: + chalk: ^4.0.0 + graceful-fs: ^4.2.9 + jest-haste-map: ^29.7.0 + jest-pnp-resolver: ^1.2.2 + jest-util: ^29.7.0 + jest-validate: ^29.7.0 + resolve: ^1.20.0 + resolve.exports: ^2.0.0 + slash: ^3.0.0 + checksum: 0ca218e10731aa17920526ec39deaec59ab9b966237905ffc4545444481112cd422f01581230eceb7e82d86f44a543d520a71391ec66e1b4ef1a578bd5c73487 + languageName: node + linkType: hard + "jest-runner@npm:^29.6.2": version: 29.6.2 resolution: "jest-runner@npm:29.6.2" @@ -12853,6 +13180,64 @@ __metadata: languageName: node linkType: hard +"jest-runtime@npm:^29.7.0": + version: 29.7.0 + resolution: "jest-runtime@npm:29.7.0" + dependencies: + "@jest/environment": ^29.7.0 + "@jest/fake-timers": ^29.7.0 + "@jest/globals": ^29.7.0 + "@jest/source-map": ^29.6.3 + "@jest/test-result": ^29.7.0 + "@jest/transform": ^29.7.0 + "@jest/types": ^29.6.3 + "@types/node": "*" + chalk: ^4.0.0 + cjs-module-lexer: ^1.0.0 + collect-v8-coverage: ^1.0.0 + glob: ^7.1.3 + graceful-fs: ^4.2.9 + jest-haste-map: ^29.7.0 + jest-message-util: ^29.7.0 + jest-mock: ^29.7.0 + jest-regex-util: ^29.6.3 + jest-resolve: ^29.7.0 + jest-snapshot: ^29.7.0 + jest-util: ^29.7.0 + slash: ^3.0.0 + strip-bom: ^4.0.0 + checksum: d19f113d013e80691e07047f68e1e3448ef024ff2c6b586ce4f90cd7d4c62a2cd1d460110491019719f3c59bfebe16f0e201ed005ef9f80e2cf798c374eed54e + languageName: node + linkType: hard + +"jest-snapshot@npm:^29.0.1, jest-snapshot@npm:^29.7.0": + version: 29.7.0 + resolution: "jest-snapshot@npm:29.7.0" + dependencies: + "@babel/core": ^7.11.6 + "@babel/generator": ^7.7.2 + "@babel/plugin-syntax-jsx": ^7.7.2 + "@babel/plugin-syntax-typescript": ^7.7.2 + "@babel/types": ^7.3.3 + "@jest/expect-utils": ^29.7.0 + "@jest/transform": ^29.7.0 + "@jest/types": ^29.6.3 + babel-preset-current-node-syntax: ^1.0.0 + chalk: ^4.0.0 + expect: ^29.7.0 + graceful-fs: ^4.2.9 + jest-diff: ^29.7.0 + jest-get-type: ^29.6.3 + jest-matcher-utils: ^29.7.0 + jest-message-util: ^29.7.0 + jest-util: ^29.7.0 + natural-compare: ^1.4.0 + pretty-format: ^29.7.0 + semver: ^7.5.3 + checksum: 86821c3ad0b6899521ce75ee1ae7b01b17e6dfeff9166f2cf17f012e0c5d8c798f30f9e4f8f7f5bed01ea7b55a6bc159f5eda778311162cbfa48785447c237ad + languageName: node + linkType: hard + "jest-snapshot@npm:^29.6.2": version: 29.6.2 resolution: "jest-snapshot@npm:29.6.2" @@ -12937,6 +13322,20 @@ __metadata: languageName: node linkType: hard +"jest-util@npm:^29.7.0": + version: 29.7.0 + resolution: "jest-util@npm:29.7.0" + dependencies: + "@jest/types": ^29.6.3 + "@types/node": "*" + chalk: ^4.0.0 + ci-info: ^3.2.0 + graceful-fs: ^4.2.9 + picomatch: ^2.2.3 + checksum: 042ab4980f4ccd4d50226e01e5c7376a8556b472442ca6091a8f102488c0f22e6e8b89ea874111d2328a2080083bf3225c86f3788c52af0bd0345a00eb57a3ca + languageName: node + linkType: hard + "jest-validate@npm:^29.6.2": version: 29.6.2 resolution: "jest-validate@npm:29.6.2" @@ -12965,6 +13364,20 @@ __metadata: languageName: node linkType: hard +"jest-validate@npm:^29.7.0": + version: 29.7.0 + resolution: "jest-validate@npm:29.7.0" + dependencies: + "@jest/types": ^29.6.3 + camelcase: ^6.2.0 + chalk: ^4.0.0 + jest-get-type: ^29.6.3 + leven: ^3.1.0 + pretty-format: ^29.7.0 + checksum: 191fcdc980f8a0de4dbdd879fa276435d00eb157a48683af7b3b1b98b0f7d9de7ffe12689b617779097ff1ed77601b9f7126b0871bba4f776e222c40f62e9dae + languageName: node + linkType: hard + "jest-watcher@npm:^29.6.2": version: 29.6.2 resolution: "jest-watcher@npm:29.6.2" @@ -13032,6 +13445,18 @@ __metadata: languageName: node linkType: hard +"jest-worker@npm:^29.7.0": + version: 29.7.0 + resolution: "jest-worker@npm:29.7.0" + dependencies: + "@types/node": "*" + jest-util: ^29.7.0 + merge-stream: ^2.0.0 + supports-color: ^8.0.0 + checksum: 30fff60af49675273644d408b650fc2eb4b5dcafc5a0a455f238322a8f9d8a98d847baca9d51ff197b6747f54c7901daa2287799230b856a0f48287d131f8c13 + languageName: node + linkType: hard + "jest@npm:^29.5.0": version: 29.6.2 resolution: "jest@npm:29.6.2" @@ -14737,6 +15162,17 @@ __metadata: languageName: node linkType: hard +"nice-napi@npm:^1.0.2": + version: 1.0.2 + resolution: "nice-napi@npm:1.0.2" + dependencies: + node-addon-api: ^3.0.0 + node-gyp: latest + node-gyp-build: ^4.2.2 + conditions: "!os=win32" + languageName: node + linkType: hard + "node-addon-api@npm:^2.0.0": version: 2.0.2 resolution: "node-addon-api@npm:2.0.2" @@ -14746,6 +15182,15 @@ __metadata: languageName: node linkType: hard +"node-addon-api@npm:^3.0.0": + version: 3.2.1 + resolution: "node-addon-api@npm:3.2.1" + dependencies: + node-gyp: latest + checksum: 2369986bb0881ccd9ef6bacdf39550e07e089a9c8ede1cbc5fc7712d8e2faa4d50da0e487e333d4125f8c7a616c730131d1091676c9d499af1d74560756b4a18 + languageName: node + linkType: hard + "node-cleanup@npm:^2.1.2": version: 2.1.2 resolution: "node-cleanup@npm:2.1.2" @@ -14792,7 +15237,7 @@ __metadata: languageName: node linkType: hard -"node-gyp-build@npm:^4.2.0": +"node-gyp-build@npm:^4.2.0, node-gyp-build@npm:^4.2.2": version: 4.6.1 resolution: "node-gyp-build@npm:4.6.1" bin: @@ -15339,6 +15784,13 @@ __metadata: languageName: node linkType: hard +"pako@npm:^1.0.3, pako@npm:~1.0.2": + version: 1.0.11 + resolution: "pako@npm:1.0.11" + checksum: 1be2bfa1f807608c7538afa15d6f25baa523c30ec870a3228a89579e474a4d992f4293859524e46d5d87fd30fa17c5edf34dbef0671251d9749820b488660b16 + languageName: node + linkType: hard + "pako@npm:^2.1.0": version: 2.1.0 resolution: "pako@npm:2.1.0" @@ -15346,13 +15798,6 @@ __metadata: languageName: node linkType: hard -"pako@npm:~1.0.2": - version: 1.0.11 - resolution: "pako@npm:1.0.11" - checksum: 1be2bfa1f807608c7538afa15d6f25baa523c30ec870a3228a89579e474a4d992f4293859524e46d5d87fd30fa17c5edf34dbef0671251d9749820b488660b16 - languageName: node - linkType: hard - "parent-module@npm:^1.0.0": version: 1.0.1 resolution: "parent-module@npm:1.0.1" @@ -15590,6 +16035,21 @@ __metadata: languageName: node linkType: hard +"piscina@npm:^3.1.0": + version: 3.2.0 + resolution: "piscina@npm:3.2.0" + dependencies: + eventemitter-asyncresource: ^1.0.0 + hdr-histogram-js: ^2.0.1 + hdr-histogram-percentiles-obj: ^3.0.0 + nice-napi: ^1.0.2 + dependenciesMeta: + nice-napi: + optional: true + checksum: c1980c7d45d85f53265652dd2fc62a2b9e9d2321f5bbb9fc1796edb9c1324bb77c153e823a0d6454c3c35098820efedff584737cc282207480afe478a3b8a166 + languageName: node + linkType: hard + "pkg-dir@npm:^4.2.0": version: 4.2.0 resolution: "pkg-dir@npm:4.2.0" @@ -15769,6 +16229,17 @@ __metadata: languageName: node linkType: hard +"pretty-format@npm:^29.7.0": + version: 29.7.0 + resolution: "pretty-format@npm:29.7.0" + dependencies: + "@jest/schemas": ^29.6.3 + ansi-styles: ^5.0.0 + react-is: ^18.0.0 + checksum: 032c1602383e71e9c0c02a01bbd25d6759d60e9c7cf21937dde8357aa753da348fcec5def5d1002c9678a8524d5fe099ad98861286550ef44de8808cc61e43b6 + languageName: node + linkType: hard + "private-ip@npm:^3.0.0": version: 3.0.1 resolution: "private-ip@npm:3.0.1" @@ -17829,6 +18300,13 @@ __metadata: languageName: node linkType: hard +"supports-color@npm:^9.2.1": + version: 9.4.0 + resolution: "supports-color@npm:9.4.0" + checksum: cb8ff8daeaf1db642156f69a9aa545b6c01dd9c4def4f90a49f46cbf24be0c245d392fcf37acd119cd1819b99dad2cc9b7e3260813f64bcfd7f5b18b5a1eefb8 + languageName: node + linkType: hard + "supports-preserve-symlinks-flag@npm:^1.0.0": version: 1.0.0 resolution: "supports-preserve-symlinks-flag@npm:1.0.0" From 13569e6d4ba413b111b51676d6da33bc8be56184 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Sun, 29 Oct 2023 21:02:56 +0000 Subject: [PATCH 03/29] wip --- .../pedersen_commitment/pedersen.test.cpp | 13 ++++ barretenberg/ts/src/barretenberg/index.ts | 14 ++-- .../ts/src/barretenberg_api/pedersen.test.ts | 64 +++++++++++++++++++ .../ts/src/barretenberg_api/pedersen.ts | 0 .../barretenberg_wasm_base/index.ts | 4 ++ .../barretenberg_wasm_main/index.ts | 8 +++ yarn-project/circuits.js/package.json | 1 + .../crypto/pedersen/index.test.ts | 14 ++-- 8 files changed, 107 insertions(+), 11 deletions(-) create mode 100644 barretenberg/ts/src/barretenberg_api/pedersen.ts diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/pedersen.test.cpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/pedersen.test.cpp index 09015d346b91..821f42ac1b16 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/pedersen.test.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/pedersen.test.cpp @@ -1,4 +1,5 @@ #include "pedersen.hpp" +#include "barretenberg/common/timer.hpp" #include "barretenberg/crypto/generators/generator_data.hpp" #include @@ -27,6 +28,18 @@ TEST(Pedersen, CommitmentWithZero) EXPECT_EQ(r, expected); } +TEST(Pedersen, CommitmentProf) +{ + GTEST_SKIP() << "Skipping mini profiler."; + auto x = fr::random_element(); + auto y = fr::random_element(); + Timer t; + for (int i = 0; i < 10000; ++i) { + pedersen_commitment::commit_native({ x, y }); + } + info(t.nanoseconds() / 1000 / 10000); +} + // Useful for pasting into ts version of pedersen. TEST(Pedersen, GeneratorPrinter) { diff --git a/barretenberg/ts/src/barretenberg/index.ts b/barretenberg/ts/src/barretenberg/index.ts index 6ae070d4882c..7610b7e9b62c 100644 --- a/barretenberg/ts/src/barretenberg/index.ts +++ b/barretenberg/ts/src/barretenberg/index.ts @@ -2,7 +2,7 @@ import { proxy } from 'comlink'; import { BarretenbergApi } from '../barretenberg_api/index.js'; import { BarretenbergBinder } from '../barretenberg_binder/index.js'; import { createMainWorker } from '../barretenberg_wasm/barretenberg_wasm_main/factory/node/index.js'; -import { BarretenbergWasmMainWorker } from '../barretenberg_wasm/barretenberg_wasm_main/index.js'; +import { BarretenbergWasmMain, BarretenbergWasmMainWorker } from '../barretenberg_wasm/barretenberg_wasm_main/index.js'; import { getRemoteBarretenbergWasm } from '../barretenberg_wasm/helpers/index.js'; import { BarretenbergWasmWorker } from '../barretenberg_wasm/index.js'; import createDebug from 'debug'; @@ -14,7 +14,7 @@ const debug = createDebug('bb.js:wasm'); * It extends the generated api, and provides a static constructor "new" to compose components. */ export class Barretenberg extends BarretenbergApi { - private constructor(private worker: any, private wasm: BarretenbergWasmWorker) { + private constructor(private worker: any, private wasm: BarretenbergWasmWorker | BarretenbergWasmMain) { super(new BarretenbergBinder(wasm)); } @@ -31,12 +31,18 @@ export class Barretenberg extends BarretenbergApi { return new Barretenberg(worker, wasm); } + static async newSync() { + const wasm = new BarretenbergWasmMain(); + await wasm.init(1); + return new Barretenberg(undefined, wasm); + } + async getNumThreads() { return await this.wasm.getNumThreads(); } async destroy() { - await this.wasm.destroy(); - await this.worker.terminate(); + await this.wasm?.destroy(); + await this.worker?.terminate(); } } diff --git a/barretenberg/ts/src/barretenberg_api/pedersen.test.ts b/barretenberg/ts/src/barretenberg_api/pedersen.test.ts index 1a3c23799894..20188dc72e00 100644 --- a/barretenberg/ts/src/barretenberg_api/pedersen.test.ts +++ b/barretenberg/ts/src/barretenberg_api/pedersen.test.ts @@ -1,4 +1,8 @@ import { Barretenberg } from '../barretenberg/index.js'; +import { BarretenbergWasmMain } from '../barretenberg_wasm/barretenberg_wasm_main/index.js'; +import { BarretenbergWasm } from '../barretenberg_wasm/index.js'; +import { Timer } from '../benchmark/timer.js'; +import { serializeBufferArrayToVector } from '../serialize/serialize.js'; import { Fr, Point } from '../types/index.js'; describe('pedersen', () => { @@ -27,3 +31,63 @@ describe('pedersen', () => { ); }); }); + +describe('pedersen sync', () => { + function pedersenCommitWasm(wasm: BarretenbergWasmMain, inputs: Uint8Array[]) { + const data = serializeBufferArrayToVector(inputs); + + // WASM gives us 1024 bytes of scratch space which we can use without + // needing to allocate/free it ourselves. This can be useful for when we need to pass in several small variables + // when calling functions on the wasm, however it's important to not overrun this scratch space as otherwise + // the written data will begin to corrupt the stack. + // + // Using this scratch space isn't particularly safe if we have multiple threads interacting with the wasm however, + // each thread could write to the same pointer address simultaneously. + const SCRATCH_SPACE_SIZE = 1024; + + // For pedersen hashing, the case of hashing two inputs is the most common. + // so ideally we want to optimize for that. This will use 64 bytes of memory and + // can thus be optimized by checking if the input buffer is smaller than the scratch space. + let inputPtr = 0; + if (inputs.length >= SCRATCH_SPACE_SIZE) { + inputPtr = wasm.call('bbmalloc', data.length); + } + wasm.writeMemory(inputPtr, data); + + // Since the output is 32 bytes, instead of allocating memory + // we can reuse the scratch space to store the result. + const outputPtr = 0; + + wasm.call('pedersen__commit', inputPtr, outputPtr); + const hashOutput = wasm.getMemorySlice(0, 64); + + if (inputPtr !== 0) { + wasm.call('bbfree', inputPtr); + } + + return [Buffer.from(hashOutput.slice(0, 32)), Buffer.from(hashOutput.slice(32, 64))]; + } + + it('pedersenCommit pure sync', async () => { + const bb = new BarretenbergWasmMain(); + await bb.init(1); + const loops = 1000; + const fields = Array.from({ length: loops * 2 }).map(() => Fr.random().toBuffer()); + const t = new Timer(); + for (let i = 0; i < loops; ++i) { + pedersenCommitWasm(bb, [fields[i * 2], fields[i * 2 + 1]]); + } + console.log(t.us() / loops); + }); + + it('pedersenCommit sync', async () => { + const api = await Barretenberg.newSync(); + const loops = 1000; + const fields = Array.from({ length: loops * 2 }).map(() => Fr.random()); + const t = new Timer(); + for (let i = 0; i < loops; ++i) { + await api.pedersenCommit([fields[i * 2], fields[i * 2 + 1]]); + } + console.log(t.us() / loops); + }); +}); diff --git a/barretenberg/ts/src/barretenberg_api/pedersen.ts b/barretenberg/ts/src/barretenberg_api/pedersen.ts new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_base/index.ts b/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_base/index.ts index bbd27ea4f02a..76a5d3373533 100644 --- a/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_base/index.ts +++ b/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_base/index.ts @@ -4,6 +4,10 @@ import { killSelf } from '../helpers/index.js'; const debug = createDebug('bb.js:wasm'); +/** + * Base implementation of BarretenbergWasm. + * Contains code that is common to the "main thread" implementation and the "child thread" implementation. + */ export class BarretenbergWasmBase { protected memStore: { [key: string]: Uint8Array } = {}; protected memory!: WebAssembly.Memory; diff --git a/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_main/index.ts b/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_main/index.ts index 29365e311b53..9cc157552dab 100644 --- a/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_main/index.ts +++ b/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_main/index.ts @@ -9,6 +9,11 @@ import { BarretenbergWasmBase } from '../barretenberg_wasm_base/index.js'; const debug = createDebug('bb.js:wasm'); +/** + * This is the "main thread" implementation of BarretenbergWasm. + * It spawns a bunch of "child thread" implementations. + * In a browser context, this still runs on a worker, as it will block waiting on child threads. + */ export class BarretenbergWasmMain extends BarretenbergWasmBase { static MAX_THREADS = 32; private workers: Worker[] = []; @@ -102,4 +107,7 @@ export class BarretenbergWasmMain extends BarretenbergWasmBase { } } +/** + * The comlink type that asyncifies the BarretenbergWasmMain api. + */ export type BarretenbergWasmMainWorker = Remote; diff --git a/yarn-project/circuits.js/package.json b/yarn-project/circuits.js/package.json index 12ead497910f..b2712946f81a 100644 --- a/yarn-project/circuits.js/package.json +++ b/yarn-project/circuits.js/package.json @@ -26,6 +26,7 @@ "remake-bindings": "DEBUG=wasm ts-node-esm src/cbind/circuits.in.ts && prettier -w src/cbind/circuits.gen.ts", "remake-constants": "ts-node-esm src/cbind/constants.in.ts && prettier -w src/cbind/constants.gen.ts", "test:light": "NODE_NO_WARNINGS=1 NODE_OPTIONS='--loader ts-node/esm' node --experimental-vm-modules $(yarn bin jest) --runner=jest-light-runner --passWithNoTests", + "test:light:dbg": "NODE_NO_WARNINGS=1 NODE_OPTIONS='--loader ts-node/esm' node --inspect-brk=0.0.0.0 --experimental-vm-modules $(yarn bin jest) --runner=jest-light-runner --passWithNoTests", "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests" }, "inherits": [ diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts index fb7a7d16cd34..0ab770c7234b 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts @@ -1,32 +1,32 @@ import { toBufferBE } from '@aztec/foundation/bigint-buffer'; import { pedersenCommit, pedersenCommitNoble } from '@aztec/foundation/crypto'; +import { Fr } from '@aztec/foundation/fields'; import { Timer } from '@aztec/foundation/timer'; import { CircuitsWasm } from '../../../wasm/index.js'; import { pedersenCommitWasm } from './index.js'; describe('pedersen', () => { - beforeAll(async () => {}); + const loops = 1000; + const fields = Array.from({ length: loops * 2 }).map(() => Fr.random().toBuffer()); it('pedersen perf wasm', async () => { const wasm = await CircuitsWasm.get(); - const loops = 10000; const t = new Timer(); for (let i = 0; i < loops; ++i) { - pedersenCommitWasm(wasm, [toBufferBE(1n, 32), toBufferBE(1n, 32)]); + pedersenCommitWasm(wasm, [fields[i * 2], fields[i * 2 + 1]]); } console.log(t.us() / loops); - console.log(pedersenCommitWasm(wasm, [toBufferBE(1n, 32), toBufferBE(1n, 32)])); + // console.log(pedersenCommitWasm(wasm, [toBufferBE(1n, 32), toBufferBE(1n, 32)])); }); it('pedersen perf elliptic', () => { - const loops = 10000; const t = new Timer(); for (let i = 0; i < loops; ++i) { - pedersenCommit([toBufferBE(1n, 32), toBufferBE(1n, 32)]); + pedersenCommit([fields[i * 2], fields[i * 2 + 1]]); } console.log(t.us() / loops); - console.log(pedersenCommit([toBufferBE(1n, 32), toBufferBE(1n, 32)])); + // console.log(pedersenCommit([toBufferBE(1n, 32), toBufferBE(1n, 32)])); }); // it('pedersen perf noble', () => { From 78c393373a3a095ef0554ead67dcf6f10ef12732 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Mon, 30 Oct 2023 12:26:42 +0000 Subject: [PATCH 04/29] Add abis tests. --- .../src/abis/__snapshots__/abis.test.ts.snap | 90 ++++++++++++++ .../circuits.js/src/abis/abis.test.ts | 113 +++++++++++++++++- 2 files changed, 198 insertions(+), 5 deletions(-) diff --git a/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap b/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap index 4895aac0930e..e1091482759a 100644 --- a/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap +++ b/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap @@ -1,5 +1,35 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`abis wasm bindings compute globals hash 1`] = ` +Fr { + "value": 19996198784166720428914107076917074510032365849254400404611644441094528984289n, +} +`; + +exports[`abis wasm bindings compute private call stack item hash 1`] = ` +Fr { + "value": 3230879723118793997125108252427471059552102155544558929105689542823769599571n, +} +`; + +exports[`abis wasm bindings compute public call stack item hash 1`] = ` +Fr { + "value": 1369626479296628599511967895314683808250163038382688147156251959177959447826n, +} +`; + +exports[`abis wasm bindings compute secret message hash 1`] = ` +Fr { + "value": 6220068662483113241527007349428551778669520744131373768997518428761948042030n, +} +`; + +exports[`abis wasm bindings compute tx hash 1`] = ` +Fr { + "value": 11028384086470399424960241201065432836500251313078792361310973684322431200173n, +} +`; + exports[`abis wasm bindings computes a complete address 1`] = ` CompleteAddress { "address": AztecAddress { @@ -56,6 +86,48 @@ CompleteAddress { } `; +exports[`abis wasm bindings computes a contract address from partial 1`] = ` +AztecAddress { + "buffer": { + "data": [ + 34, + 41, + 121, + 74, + 138, + 50, + 100, + 6, + 122, + 50, + 114, + 42, + 84, + 48, + 151, + 243, + 88, + 162, + 160, + 249, + 55, + 16, + 237, + 195, + 114, + 27, + 106, + 66, + 228, + 123, + 33, + 231, + ], + "type": "Buffer", + }, +} +`; + exports[`abis wasm bindings computes a function leaf 1`] = ` Fr { "value": 8957681167943973616438847631514238173699549883609341685749385526208761312950n, @@ -74,6 +146,12 @@ exports[`abis wasm bindings computes a function selector 1`] = ` } `; +exports[`abis wasm bindings computes block hash with globals 1`] = ` +Fr { + "value": 7177915431153102916601456081755280584460785548870192083974540199919775120827n, +} +`; + exports[`abis wasm bindings computes commitment nonce 1`] = ` Fr { "value": 7653394882992289714855533169019502055399179742531912347686813547951736946253n, @@ -92,6 +170,18 @@ Fr { } `; +exports[`abis wasm bindings computes public data tree index 1`] = ` +Fr { + "value": 9076808949980998475110411569159266589807853958487763065147292518713994520820n, +} +`; + +exports[`abis wasm bindings computes public data tree value 1`] = ` +Fr { + "value": 3n, +} +`; + exports[`abis wasm bindings computes siloed commitment 1`] = ` Fr { "value": 7262347077404413274044670947879391583109741657896097604752287127491776887739n, diff --git a/yarn-project/circuits.js/src/abis/abis.test.ts b/yarn-project/circuits.js/src/abis/abis.test.ts index b630b7b50472..993ce0af3bd2 100644 --- a/yarn-project/circuits.js/src/abis/abis.test.ts +++ b/yarn-project/circuits.js/src/abis/abis.test.ts @@ -1,15 +1,39 @@ import times from 'lodash.times'; -import { AztecAddress, Fr, FunctionData, FunctionLeafPreimage, FunctionSelector, NewContractData } from '../index.js'; -import { makeAztecAddress, makeEthAddress, makePoint, makeTxRequest, makeVerificationKey } from '../tests/factories.js'; +import { + AztecAddress, + Fr, + FunctionData, + FunctionLeafPreimage, + FunctionSelector, + GlobalVariables, + NewContractData, +} from '../index.js'; +import { + makeAztecAddress, + makeEthAddress, + makePoint, + makePrivateCallStackItem, + makePublicCallStackItem, + makeTxRequest, + makeVerificationKey, +} from '../tests/factories.js'; import { CircuitsWasm } from '../wasm/circuits_wasm.js'; import { + computeBlockHashWithGlobals, + computeCallStackItemHash, computeCommitmentNonce, computeCompleteAddress, + computeContractAddressFromPartial, computeContractLeaf, computeFunctionLeaf, computeFunctionSelector, computeFunctionTreeRoot, + computeGlobalsHash, + computePublicDataTreeIndex, + computePublicDataTreeValue, + computeSecretMessageHash, + computeTxHash, computeUniqueCommitment, computeVarArgsHash, hashConstructor, @@ -71,6 +95,13 @@ describe('abis wasm bindings', () => { expect(res).toMatchSnapshot(); }); + it('computes a contract address from partial', () => { + const deployerPubKey = makePoint(); + const partialAddress = new Fr(2n); + const res = computeContractAddressFromPartial(wasm, deployerPubKey, partialAddress); + expect(res).toMatchSnapshot(); + }); + it('computes commitment nonce', () => { const nullifierZero = new Fr(123n); const commitmentIndex = 456; @@ -99,9 +130,51 @@ describe('abis wasm bindings', () => { expect(res).toMatchSnapshot(); }); - it('computes contract leaf', () => { - const cd = new NewContractData(makeAztecAddress(), makeEthAddress(), new Fr(3n)); - const res = computeContractLeaf(wasm, cd); + it('computes block hash with globals', () => { + const globals = GlobalVariables.from({ + chainId: new Fr(1n), + version: new Fr(2n), + blockNumber: new Fr(3n), + timestamp: new Fr(4n), + }); + const noteHashTreeRoot = new Fr(5n); + const nullifierTreeRoot = new Fr(6n); + const contractTreeRoot = new Fr(7n); + const l1ToL2DataTreeRoot = new Fr(8n); + const publicDataTreeRoot = new Fr(9n); + const res = computeBlockHashWithGlobals( + wasm, + globals, + noteHashTreeRoot, + nullifierTreeRoot, + contractTreeRoot, + l1ToL2DataTreeRoot, + publicDataTreeRoot, + ); + expect(res).toMatchSnapshot(); + }); + + it('compute globals hash', () => { + const globals = GlobalVariables.from({ + chainId: new Fr(1n), + version: new Fr(2n), + blockNumber: new Fr(3n), + timestamp: new Fr(4n), + }); + const res = computeGlobalsHash(wasm, globals); + expect(res).toMatchSnapshot(); + }); + + it('computes public data tree value', () => { + const value = new Fr(3n); + const res = computePublicDataTreeValue(wasm, value); + expect(res).toMatchSnapshot(); + }); + + it('computes public data tree index', () => { + const contractAddress = makeAztecAddress(); + const value = new Fr(3n); + const res = computePublicDataTreeIndex(wasm, contractAddress, value); expect(res).toMatchSnapshot(); }); @@ -121,4 +194,34 @@ describe('abis wasm bindings', () => { const res = await computeVarArgsHash(wasm, args); expect(res).toMatchSnapshot(); }); + + it('computes contract leaf', () => { + const cd = new NewContractData(makeAztecAddress(), makeEthAddress(), new Fr(3n)); + const res = computeContractLeaf(wasm, cd); + expect(res).toMatchSnapshot(); + }); + + it('compute tx hash', () => { + const txRequest = makeTxRequest(); + const hash = computeTxHash(wasm, txRequest); + expect(hash).toMatchSnapshot(); + }); + + it('compute private call stack item hash', () => { + const item = makePrivateCallStackItem(); + const hash = computeCallStackItemHash(wasm, item); + expect(hash).toMatchSnapshot(); + }); + + it('compute public call stack item hash', () => { + const item = makePublicCallStackItem(); + const hash = computeCallStackItemHash(wasm, item); + expect(hash).toMatchSnapshot(); + }); + + it('compute secret message hash', () => { + const value = new Fr(8n); + const hash = computeSecretMessageHash(wasm, value); + expect(hash).toMatchSnapshot(); + }); }); From 5e92b49ff9f70dbd5fb1e25fdadccefac3b2a773 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Wed, 1 Nov 2023 16:47:45 +0000 Subject: [PATCH 05/29] wip --- .../crypto/pedersen_commitment/c_bind.cpp | 9 +- .../crypto/pedersen_commitment/c_bind.hpp | 15 +- .../crypto/pedersen_commitment/c_bind_new.cpp | 18 - .../crypto/pedersen_commitment/c_bind_new.hpp | 12 - .../barretenberg/crypto/schnorr/c_bind.hpp | 6 +- barretenberg/exports.json | 577 ------------------ barretenberg/scripts/decls_json.py | 15 +- .../pedersen.ts => scripts/exports.json} | 0 .../ts/src/barretenberg_api/schnorr.test.ts | 4 +- barretenberg/ts/src/pedersen/index.ts | 1 + barretenberg/ts/src/pedersen/pedersen.test.ts | 33 + barretenberg/ts/src/pedersen/pedersen.ts | 58 ++ barretenberg/ts/src/types/fields.ts | 20 +- .../src/structs/complete_address.test.ts | 18 +- 14 files changed, 144 insertions(+), 642 deletions(-) delete mode 100644 barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.cpp delete mode 100644 barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.hpp rename barretenberg/{ts/src/barretenberg_api/pedersen.ts => scripts/exports.json} (100%) create mode 100644 barretenberg/ts/src/pedersen/index.ts create mode 100644 barretenberg/ts/src/pedersen/pedersen.test.ts create mode 100644 barretenberg/ts/src/pedersen/pedersen.ts diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp index 8dc747c3b894..bf1b4c731b8d 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp @@ -1,13 +1,18 @@ -#include "c_bind.hpp" #include "../pedersen_hash/pedersen.hpp" #include "barretenberg/common/serialize.hpp" +#include "c_bind_new.hpp" #include "pedersen.hpp" -WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output) +extern "C" { + +using namespace barretenberg; + +WASM_EXPORT void pedersen___commit(fr::vec_in_buf inputs_buffer, affine_element::out_buf output) { std::vector to_commit; read(inputs_buffer, to_commit); grumpkin::g1::affine_element pedersen_commitment = crypto::pedersen_commitment::commit_native(to_commit); serialize::write(output, pedersen_commitment); +} } \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp index 3c07abe2c9b6..84f56c20155d 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp @@ -1,7 +1,12 @@ #pragma once -#include "barretenberg/common/mem.hpp" -#include "barretenberg/common/serialize.hpp" -#include "barretenberg/common/streams.hpp" -#include "barretenberg/common/timer.hpp" +#include "barretenberg/common/wasm_export.hpp" +#include "barretenberg/ecc/curves/bn254/fr.hpp" +#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" -WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output); +extern "C" { + +using namespace barretenberg; +using affine_element = grumpkin::g1::affine_element; + +WASM_EXPORT void pedersen___commit(fr::vec_in_buf inputs_buffer, affine_element::out_buf output); +} \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.cpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.cpp deleted file mode 100644 index 9892f95c9d64..000000000000 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "c_bind_new.hpp" -#include "../pedersen_hash/pedersen.hpp" -#include "barretenberg/common/serialize.hpp" -#include "pedersen.hpp" - -extern "C" { - -using namespace barretenberg; - -WASM_EXPORT void pedersen___commit(fr::vec_in_buf inputs_buffer, affine_element::out_buf output) -{ - std::vector to_commit; - read(inputs_buffer, to_commit); - grumpkin::g1::affine_element pedersen_commitment = crypto::pedersen_commitment::commit_native(to_commit); - - serialize::write(output, pedersen_commitment); -} -} \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.hpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.hpp deleted file mode 100644 index 84f56c20155d..000000000000 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once -#include "barretenberg/common/wasm_export.hpp" -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" - -extern "C" { - -using namespace barretenberg; -using affine_element = grumpkin::g1::affine_element; - -WASM_EXPORT void pedersen___commit(fr::vec_in_buf inputs_buffer, affine_element::out_buf output); -} \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp index b6dc905876c7..efd5df66dbf7 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp @@ -17,7 +17,7 @@ WASM_EXPORT void schnorr_construct_signature(uint8_t const* message, fr::in_buf WASM_EXPORT void schnorr_verify_signature( uint8_t const* message, affine_element::in_buf pub_key, in_buf32 sig_s, in_buf32 sig_e, bool* result); -WASM_EXPORT void schnorr_multisig_create_multisig_public_key(fq::in_buf private_key, +WASM_EXPORT void schnorr_multisig_create_multisig_public_key(fr::in_buf private_key, multisig::MultiSigPublicKey::out_buf multisig_pubkey_buf); WASM_EXPORT void schnorr_multisig_validate_and_combine_signer_pubkeys( @@ -29,11 +29,11 @@ WASM_EXPORT void schnorr_multisig_construct_signature_round_1( WASM_EXPORT void schnorr_multisig_construct_signature_round_2( uint8_t const* message, - fq::in_buf private_key, + fr::in_buf private_key, multisig::RoundOnePrivateOutput::in_buf signer_round_one_private_buf, multisig::MultiSigPublicKey::vec_in_buf signer_pubkeys_buf, multisig::RoundOnePublicOutput::vec_in_buf round_one_public_buf, - fq::out_buf round_two_buf, + fr::out_buf round_two_buf, bool* success); WASM_EXPORT void schnorr_multisig_combine_signatures(uint8_t const* message, diff --git a/barretenberg/exports.json b/barretenberg/exports.json index ab37a26ec839..e69de29bb2d1 100644 --- a/barretenberg/exports.json +++ b/barretenberg/exports.json @@ -1,577 +0,0 @@ -[ - { - "functionName": "pedersen___commit", - "inArgs": [ - { - "name": "inputs_buffer", - "type": "fr::vec_in_buf" - } - ], - "outArgs": [ - { - "name": "output", - "type": "affine_element::out_buf" - } - ], - "isAsync": false - }, - { - "functionName": "pedersen_hash_with_hash_index", - "inArgs": [ - { - "name": "inputs_buffer", - "type": "fr::vec_in_buf" - }, - { - "name": "hash_index", - "type": "const uint32_t *" - } - ], - "outArgs": [ - { - "name": "output", - "type": "fr::out_buf" - } - ], - "isAsync": false - }, - { - "functionName": "blake2s", - "inArgs": [ - { - "name": "data", - "type": "const uint8_t *" - } - ], - "outArgs": [ - { - "name": "r", - "type": "out_buf32" - } - ], - "isAsync": false - }, - { - "functionName": "blake2s_to_field_", - "inArgs": [ - { - "name": "data", - "type": "const uint8_t *" - } - ], - "outArgs": [ - { - "name": "r", - "type": "fr::out_buf" - } - ], - "isAsync": false - }, - { - "functionName": "schnorr_compute_public_key", - "inArgs": [ - { - "name": "private_key", - "type": "fr::in_buf" - } - ], - "outArgs": [ - { - "name": "public_key_buf", - "type": "affine_element::out_buf" - } - ], - "isAsync": false - }, - { - "functionName": "schnorr_negate_public_key", - "inArgs": [ - { - "name": "public_key_buffer", - "type": "affine_element::in_buf" - } - ], - "outArgs": [ - { - "name": "output", - "type": "affine_element::out_buf" - } - ], - "isAsync": false - }, - { - "functionName": "schnorr_construct_signature", - "inArgs": [ - { - "name": "message", - "type": "const uint8_t *" - }, - { - "name": "private_key", - "type": "fr::in_buf" - } - ], - "outArgs": [ - { - "name": "s", - "type": "out_buf32" - }, - { - "name": "e", - "type": "out_buf32" - } - ], - "isAsync": false - }, - { - "functionName": "schnorr_verify_signature", - "inArgs": [ - { - "name": "message", - "type": "const uint8_t *" - }, - { - "name": "pub_key", - "type": "affine_element::in_buf" - }, - { - "name": "sig_s", - "type": "in_buf32" - }, - { - "name": "sig_e", - "type": "in_buf32" - } - ], - "outArgs": [ - { - "name": "result", - "type": "bool *" - } - ], - "isAsync": false - }, - { - "functionName": "schnorr_multisig_create_multisig_public_key", - "inArgs": [ - { - "name": "private_key", - "type": "fq::in_buf" - } - ], - "outArgs": [ - { - "name": "multisig_pubkey_buf", - "type": "multisig::MultiSigPublicKey::out_buf" - } - ], - "isAsync": false - }, - { - "functionName": "schnorr_multisig_validate_and_combine_signer_pubkeys", - "inArgs": [ - { - "name": "signer_pubkey_buf", - "type": "multisig::MultiSigPublicKey::vec_in_buf" - } - ], - "outArgs": [ - { - "name": "combined_key_buf", - "type": "affine_element::out_buf" - }, - { - "name": "success", - "type": "bool *" - } - ], - "isAsync": false - }, - { - "functionName": "schnorr_multisig_construct_signature_round_1", - "inArgs": [], - "outArgs": [ - { - "name": "round_one_public_output_buf", - "type": "multisig::RoundOnePublicOutput::out_buf" - }, - { - "name": "round_one_private_output_buf", - "type": "multisig::RoundOnePrivateOutput::out_buf" - } - ], - "isAsync": false - }, - { - "functionName": "schnorr_multisig_construct_signature_round_2", - "inArgs": [ - { - "name": "message", - "type": "const uint8_t *" - }, - { - "name": "private_key", - "type": "fq::in_buf" - }, - { - "name": "signer_round_one_private_buf", - "type": "multisig::RoundOnePrivateOutput::in_buf" - }, - { - "name": "signer_pubkeys_buf", - "type": "multisig::MultiSigPublicKey::vec_in_buf" - }, - { - "name": "round_one_public_buf", - "type": "multisig::RoundOnePublicOutput::vec_in_buf" - } - ], - "outArgs": [ - { - "name": "round_two_buf", - "type": "fq::out_buf" - }, - { - "name": "success", - "type": "bool *" - } - ], - "isAsync": false - }, - { - "functionName": "schnorr_multisig_combine_signatures", - "inArgs": [ - { - "name": "message", - "type": "const uint8_t *" - }, - { - "name": "signer_pubkeys_buf", - "type": "multisig::MultiSigPublicKey::vec_in_buf" - }, - { - "name": "round_one_buf", - "type": "multisig::RoundOnePublicOutput::vec_in_buf" - }, - { - "name": "round_two_buf", - "type": "fr::vec_in_buf" - } - ], - "outArgs": [ - { - "name": "s", - "type": "out_buf32" - }, - { - "name": "e", - "type": "out_buf32" - }, - { - "name": "success", - "type": "bool *" - } - ], - "isAsync": false - }, - { - "functionName": "srs_init_srs", - "inArgs": [ - { - "name": "points_buf", - "type": "const uint8_t *" - }, - { - "name": "num_points", - "type": "const uint32_t *" - }, - { - "name": "g2_point_buf", - "type": "const uint8_t *" - } - ], - "outArgs": [], - "isAsync": false - }, - { - "functionName": "examples_simple_create_and_verify_proof", - "inArgs": [], - "outArgs": [ - { - "name": "valid", - "type": "bool *" - } - ], - "isAsync": false - }, - { - "functionName": "test_threads", - "inArgs": [ - { - "name": "threads", - "type": "const uint32_t *" - }, - { - "name": "iterations", - "type": "const uint32_t *" - } - ], - "outArgs": [ - { - "name": "out", - "type": "uint32_t *" - } - ], - "isAsync": false - }, - { - "functionName": "common_init_slab_allocator", - "inArgs": [ - { - "name": "circuit_size", - "type": "const uint32_t *" - } - ], - "outArgs": [], - "isAsync": false - }, - { - "functionName": "acir_get_circuit_sizes", - "inArgs": [ - { - "name": "constraint_system_buf", - "type": "const uint8_t *" - } - ], - "outArgs": [ - { - "name": "exact", - "type": "uint32_t *" - }, - { - "name": "total", - "type": "uint32_t *" - }, - { - "name": "subgroup", - "type": "uint32_t *" - } - ], - "isAsync": false - }, - { - "functionName": "acir_new_acir_composer", - "inArgs": [ - { - "name": "size_hint", - "type": "const uint32_t *" - } - ], - "outArgs": [ - { - "name": "out", - "type": "out_ptr" - } - ], - "isAsync": false - }, - { - "functionName": "acir_delete_acir_composer", - "inArgs": [ - { - "name": "acir_composer_ptr", - "type": "in_ptr" - } - ], - "outArgs": [], - "isAsync": false - }, - { - "functionName": "acir_create_circuit", - "inArgs": [ - { - "name": "acir_composer_ptr", - "type": "in_ptr" - }, - { - "name": "constraint_system_buf", - "type": "const uint8_t *" - }, - { - "name": "size_hint", - "type": "const uint32_t *" - } - ], - "outArgs": [], - "isAsync": false - }, - { - "functionName": "acir_init_proving_key", - "inArgs": [ - { - "name": "acir_composer_ptr", - "type": "in_ptr" - }, - { - "name": "constraint_system_buf", - "type": "const uint8_t *" - } - ], - "outArgs": [], - "isAsync": false - }, - { - "functionName": "acir_create_proof", - "inArgs": [ - { - "name": "acir_composer_ptr", - "type": "in_ptr" - }, - { - "name": "constraint_system_buf", - "type": "const uint8_t *" - }, - { - "name": "witness_buf", - "type": "const uint8_t *" - }, - { - "name": "is_recursive", - "type": "const bool *" - } - ], - "outArgs": [ - { - "name": "out", - "type": "uint8_t **" - } - ], - "isAsync": false - }, - { - "functionName": "acir_load_verification_key", - "inArgs": [ - { - "name": "acir_composer_ptr", - "type": "in_ptr" - }, - { - "name": "vk_buf", - "type": "const uint8_t *" - } - ], - "outArgs": [], - "isAsync": false - }, - { - "functionName": "acir_init_verification_key", - "inArgs": [ - { - "name": "acir_composer_ptr", - "type": "in_ptr" - } - ], - "outArgs": [], - "isAsync": false - }, - { - "functionName": "acir_get_verification_key", - "inArgs": [ - { - "name": "acir_composer_ptr", - "type": "in_ptr" - } - ], - "outArgs": [ - { - "name": "out", - "type": "uint8_t **" - } - ], - "isAsync": false - }, - { - "functionName": "acir_verify_proof", - "inArgs": [ - { - "name": "acir_composer_ptr", - "type": "in_ptr" - }, - { - "name": "proof_buf", - "type": "const uint8_t *" - }, - { - "name": "is_recursive", - "type": "const bool *" - } - ], - "outArgs": [ - { - "name": "result", - "type": "bool *" - } - ], - "isAsync": false - }, - { - "functionName": "acir_get_solidity_verifier", - "inArgs": [ - { - "name": "acir_composer_ptr", - "type": "in_ptr" - } - ], - "outArgs": [ - { - "name": "out", - "type": "out_str_buf" - } - ], - "isAsync": false - }, - { - "functionName": "acir_serialize_proof_into_fields", - "inArgs": [ - { - "name": "acir_composer_ptr", - "type": "in_ptr" - }, - { - "name": "proof_buf", - "type": "const uint8_t *" - }, - { - "name": "num_inner_public_inputs", - "type": "const uint32_t *" - } - ], - "outArgs": [ - { - "name": "out", - "type": "fr::vec_out_buf" - } - ], - "isAsync": false - }, - { - "functionName": "acir_serialize_verification_key_into_fields", - "inArgs": [ - { - "name": "acir_composer_ptr", - "type": "in_ptr" - } - ], - "outArgs": [ - { - "name": "out_vkey", - "type": "fr::vec_out_buf" - }, - { - "name": "out_key_hash", - "type": "fr::out_buf" - } - ], - "isAsync": false - } -] diff --git a/barretenberg/scripts/decls_json.py b/barretenberg/scripts/decls_json.py index d01fba39dd28..93cb152bd8be 100755 --- a/barretenberg/scripts/decls_json.py +++ b/barretenberg/scripts/decls_json.py @@ -33,14 +33,15 @@ def process_files(files: List[str]) -> List[dict]: idx = clang.cindex.Index.create() for path in files: tu = idx.parse(path, args=[ - '-isystem', '/usr/include/c++/10', - '-isystem', '/usr/include/x86_64-linux-gnu/c++/10', - '-isystem', '/usr/include/c++/10/backward', - '-isystem', '/usr/lib/llvm-15/lib/clang/15.0.7/include', - '-isystem', '/usr/local/include', - '-isystem', '/usr/include/x86_64-linux-gnu', - '-isystem', '/usr/include', + # '-isystem', '/usr/include/c++/10', + # '-isystem', '/usr/include/x86_64-linux-gnu/c++/10', + # '-isystem', '/usr/include/c++/10/backward', + # '-isystem', '/usr/lib/llvm-16/lib/clang/16/include', + # '-isystem', '/usr/local/include', + # '-isystem', '/usr/include/x86_64-linux-gnu', + # '-isystem', '/usr/include', "-I./cpp/src", + '-stdlib=libc++', '-std=gnu++20', '-Wall', '-Wextra']) for diag in tu.diagnostics: print_diagnostic(diag, file=sys.stderr) diff --git a/barretenberg/ts/src/barretenberg_api/pedersen.ts b/barretenberg/scripts/exports.json similarity index 100% rename from barretenberg/ts/src/barretenberg_api/pedersen.ts rename to barretenberg/scripts/exports.json diff --git a/barretenberg/ts/src/barretenberg_api/schnorr.test.ts b/barretenberg/ts/src/barretenberg_api/schnorr.test.ts index 6b161cfb1c98..1656da56395e 100644 --- a/barretenberg/ts/src/barretenberg_api/schnorr.test.ts +++ b/barretenberg/ts/src/barretenberg_api/schnorr.test.ts @@ -1,5 +1,5 @@ import { TextEncoder } from 'util'; -import { Buffer128, Buffer32, Fr, Point } from '../types/index.js'; +import { Buffer128, Buffer32, Fq, Fr, Point } from '../types/index.js'; import { Barretenberg } from '../barretenberg/index.js'; import { asyncMap } from '../async_map/index.js'; @@ -48,7 +48,7 @@ describe('schnorr', () => { it('should create + verify multi signature', async () => { // set up multisig accounts const numSigners = 7; - const pks = [...Array(numSigners)].map(() => Fr.random()); + const pks = [...Array(numSigners)].map(() => Fq.random()); const pubKeys = await asyncMap(pks, pk => api.schnorrMultisigCreateMultisigPublicKey(pk)); // round one diff --git a/barretenberg/ts/src/pedersen/index.ts b/barretenberg/ts/src/pedersen/index.ts new file mode 100644 index 000000000000..41d557571b3e --- /dev/null +++ b/barretenberg/ts/src/pedersen/index.ts @@ -0,0 +1 @@ +export * from './pedersen.js'; diff --git a/barretenberg/ts/src/pedersen/pedersen.test.ts b/barretenberg/ts/src/pedersen/pedersen.test.ts new file mode 100644 index 000000000000..0295a6018d47 --- /dev/null +++ b/barretenberg/ts/src/pedersen/pedersen.test.ts @@ -0,0 +1,33 @@ +import { Pedersen } from './pedersen.js'; +import { Timer } from '../benchmark/timer.js'; +import { Fr, Point } from '../types/index.js'; + +describe('pedersen sync', () => { + it('pedersenHashWithHashIndex', async () => { + const pedersen = await Pedersen.new(); + const result = pedersen.pedersenHashWithHashIndex([new Fr(4n), new Fr(8n)], 7); + expect(result).toEqual(new Fr(2152386650411553803409271316104075950536496387580531018130718456431861859990n)); + }); + + it('pedersenCommit', async () => { + const pedersen = await Pedersen.new(); + const result = pedersen.pedersenCommit([new Fr(4n), new Fr(8n), new Fr(12n)]); + expect(result).toEqual( + new Point( + new Fr(18374309251862457296563484909553154519357910650678202211610516068880120638872n), + new Fr(2572141322478528249692953821523229170092797347760799983831061874108357705739n), + ), + ); + }); + + it.skip('pedersenCommit perf test', async () => { + const pedersen = await Pedersen.new(); + const loops = 1000; + const fields = Array.from({ length: loops * 2 }).map(() => Fr.random()); + const t = new Timer(); + for (let i = 0; i < loops; ++i) { + pedersen.pedersenCommit([fields[i * 2], fields[i * 2 + 1]]); + } + console.log(t.us() / loops); + }); +}); diff --git a/barretenberg/ts/src/pedersen/pedersen.ts b/barretenberg/ts/src/pedersen/pedersen.ts new file mode 100644 index 000000000000..6b713c879b84 --- /dev/null +++ b/barretenberg/ts/src/pedersen/pedersen.ts @@ -0,0 +1,58 @@ +import { BarretenbergWasmMain } from '../barretenberg_wasm/barretenberg_wasm_main/index.js'; +import { numToUInt32BE, serializeBufferArrayToVector } from '../serialize/serialize.js'; +import { Point, Fr } from '../types/index.js'; + +export class Pedersen { + constructor(public wasm: BarretenbergWasmMain) {} + + static async new() { + const wasm = new BarretenbergWasmMain(); + await wasm.init(1); + return new Pedersen(wasm); + } + + pedersenHashWithHashIndex(inputs: Fr[], hashIndex: number) { + const SCRATCH_SPACE_SIZE = 1024; + + const data = serializeBufferArrayToVector(inputs.map(fr => fr.toBuffer())); + + let inputPtr = 0; + if (inputs.length >= SCRATCH_SPACE_SIZE - 4) { + inputPtr = this.wasm.call('bbmalloc', data.length); + } + this.wasm.writeMemory(inputPtr, data); + this.wasm.writeMemory(SCRATCH_SPACE_SIZE - 4, numToUInt32BE(hashIndex)); + + const outputPtr = 0; + this.wasm.call('pedersen_hash_with_hash_index', inputPtr, SCRATCH_SPACE_SIZE - 4, outputPtr); + const hashOutput = this.wasm.getMemorySlice(0, 32); + + if (inputPtr !== 0) { + this.wasm.call('bbfree', inputPtr); + } + + return Fr.fromBuffer(hashOutput); + } + + pedersenCommit(inputs: Fr[]) { + const SCRATCH_SPACE_SIZE = 1024; + + const data = serializeBufferArrayToVector(inputs.map(fr => fr.toBuffer())); + + let inputPtr = 0; + if (inputs.length >= SCRATCH_SPACE_SIZE) { + inputPtr = this.wasm.call('bbmalloc', data.length); + } + this.wasm.writeMemory(inputPtr, data); + + const outputPtr = 0; + this.wasm.call('pedersen__commit', inputPtr, outputPtr); + const hashOutput = this.wasm.getMemorySlice(0, 64); + + if (inputPtr !== 0) { + this.wasm.call('bbfree', inputPtr); + } + + return new Point(Fr.fromBuffer(hashOutput.slice(0, 32)), Fr.fromBuffer(hashOutput.slice(32, 64))); + } +} diff --git a/barretenberg/ts/src/types/fields.ts b/barretenberg/ts/src/types/fields.ts index a0b095813d33..97502dafae3c 100644 --- a/barretenberg/ts/src/types/fields.ts +++ b/barretenberg/ts/src/types/fields.ts @@ -7,10 +7,16 @@ export class Fr { static MODULUS = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001n; static MAX_VALUE = this.MODULUS - 1n; static SIZE_IN_BYTES = 32; - - constructor(public readonly value: bigint) { - if (value > Fr.MAX_VALUE) { - throw new Error(`Fr out of range ${value}.`); + value: Uint8Array; + + constructor(value: Uint8Array | bigint) { + if (typeof value === 'bigint') { + if (value > Fr.MAX_VALUE) { + throw new Error(`Fr out of range ${value}.`); + } + this.value = toBufferBE(value); + } else { + this.value = value; } } @@ -21,7 +27,7 @@ export class Fr { static fromBuffer(buffer: Uint8Array | BufferReader) { const reader = BufferReader.asReader(buffer); - return new this(toBigIntBE(reader.readBytes(this.SIZE_IN_BYTES))); + return new this(reader.readBytes(this.SIZE_IN_BYTES)); } static fromBufferReduce(buffer: Uint8Array | BufferReader) { @@ -34,7 +40,7 @@ export class Fr { } toBuffer() { - return toBufferBE(this.value, Fr.SIZE_IN_BYTES); + return this.value; } toString() { @@ -46,7 +52,7 @@ export class Fr { } isZero() { - return this.value === 0n; + return this.value.every(v => v === 0); } } diff --git a/yarn-project/circuits.js/src/structs/complete_address.test.ts b/yarn-project/circuits.js/src/structs/complete_address.test.ts index 52953661b549..2809fdbed506 100644 --- a/yarn-project/circuits.js/src/structs/complete_address.test.ts +++ b/yarn-project/circuits.js/src/structs/complete_address.test.ts @@ -5,25 +5,25 @@ import { CompleteAddress } from './complete_address.js'; describe('CompleteAddress', () => { it('refuses to add an account with incorrect address for given partial address and pubkey', async () => { - await expect(CompleteAddress.create(AztecAddress.random(), Point.random(), Fr.random())).rejects.toThrowError( + expect(() => CompleteAddress.create(AztecAddress.random(), Point.random(), Fr.random())).toThrowError( /cannot be derived/, ); }); - it('equals returns true when 2 instances are equal', async () => { - const address1 = await CompleteAddress.random(); - const address2 = await CompleteAddress.create(address1.address, address1.publicKey, address1.partialAddress); + it('equals returns true when 2 instances are equal', () => { + const address1 = CompleteAddress.random(); + const address2 = CompleteAddress.create(address1.address, address1.publicKey, address1.partialAddress); expect(address1.equals(address2)).toBe(true); }); - it('equals returns true when 2 instances are not equal', async () => { - const address1 = await CompleteAddress.random(); - const address2 = await CompleteAddress.random(); + it('equals returns true when 2 instances are not equal', () => { + const address1 = CompleteAddress.random(); + const address2 = CompleteAddress.random(); expect(address1.equals(address2)).toBe(false); }); - it('serializes / deserializes correctly', async () => { - const expectedAddress = await CompleteAddress.random(); + it('serializes / deserializes correctly', () => { + const expectedAddress = CompleteAddress.random(); const address = CompleteAddress.fromBuffer(expectedAddress.toBuffer()); expect(address.equals(expectedAddress)).toBe(true); }); From 7a5b7dc430ede3eda0a02be99626830554327d9c Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Wed, 1 Nov 2023 17:10:54 +0000 Subject: [PATCH 06/29] Wip --- .../cpp/src/barretenberg/common/mem.hpp | 5 +- .../crypto/pedersen_commitment/c_bind.cpp | 2 +- .../commitment/pedersen/pedersen.test.cpp | 2 +- barretenberg/exports.json | 577 ++++++++++++++++++ barretenberg/scripts/c_bind_files.txt | 2 +- barretenberg/scripts/decls_json.py | 1 - barretenberg/ts/src/barretenberg_api/index.ts | 8 +- .../ts/src/barretenberg_api/pedersen.test.ts | 93 --- .../ts/src/barretenberg_api/schnorr.test.ts | 4 +- 9 files changed, 587 insertions(+), 107 deletions(-) delete mode 100644 barretenberg/ts/src/barretenberg_api/pedersen.test.ts diff --git a/barretenberg/cpp/src/barretenberg/common/mem.hpp b/barretenberg/cpp/src/barretenberg/common/mem.hpp index d97ccd495ea7..fe4a6351e9e0 100644 --- a/barretenberg/cpp/src/barretenberg/common/mem.hpp +++ b/barretenberg/cpp/src/barretenberg/common/mem.hpp @@ -75,7 +75,4 @@ inline void aligned_free(void* mem) // info("Total allocated space (uordblks): ", minfo.uordblks); // info("Total free space (fordblks): ", minfo.fordblks); // info("Top-most, releasable space (keepcost): ", minfo.keepcost); -// } - -WASM_EXPORT void* bbmalloc(size_t size); -WASM_EXPORT void bbfree(void* ptr); +// } \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp index bf1b4c731b8d..e4bed81865f8 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp @@ -1,6 +1,6 @@ +#include "c_bind.hpp" #include "../pedersen_hash/pedersen.hpp" #include "barretenberg/common/serialize.hpp" -#include "c_bind_new.hpp" #include "pedersen.hpp" extern "C" { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.test.cpp index a1b3e58cf4a7..e60c8c4731f7 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.test.cpp @@ -1,6 +1,6 @@ #include "barretenberg/crypto/pedersen_commitment/pedersen.hpp" #include "barretenberg/common/test.hpp" -#include "barretenberg/crypto/pedersen_commitment/c_bind_new.hpp" +#include "barretenberg/crypto/pedersen_commitment/c_bind.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" #include "barretenberg/numeric/random/engine.hpp" #include "barretenberg/stdlib/primitives/curves/bn254.hpp" diff --git a/barretenberg/exports.json b/barretenberg/exports.json index e69de29bb2d1..1bf3126c10f3 100644 --- a/barretenberg/exports.json +++ b/barretenberg/exports.json @@ -0,0 +1,577 @@ +[ + { + "functionName": "pedersen___commit", + "inArgs": [ + { + "name": "inputs_buffer", + "type": "fr::vec_in_buf" + } + ], + "outArgs": [ + { + "name": "output", + "type": "affine_element::out_buf" + } + ], + "isAsync": false + }, + { + "functionName": "pedersen_hash_with_hash_index", + "inArgs": [ + { + "name": "inputs_buffer", + "type": "fr::vec_in_buf" + }, + { + "name": "hash_index", + "type": "const uint32_t *" + } + ], + "outArgs": [ + { + "name": "output", + "type": "fr::out_buf" + } + ], + "isAsync": false + }, + { + "functionName": "blake2s", + "inArgs": [ + { + "name": "data", + "type": "const uint8_t *" + } + ], + "outArgs": [ + { + "name": "r", + "type": "out_buf32" + } + ], + "isAsync": false + }, + { + "functionName": "blake2s_to_field_", + "inArgs": [ + { + "name": "data", + "type": "const uint8_t *" + } + ], + "outArgs": [ + { + "name": "r", + "type": "fr::out_buf" + } + ], + "isAsync": false + }, + { + "functionName": "schnorr_compute_public_key", + "inArgs": [ + { + "name": "private_key", + "type": "fr::in_buf" + } + ], + "outArgs": [ + { + "name": "public_key_buf", + "type": "affine_element::out_buf" + } + ], + "isAsync": false + }, + { + "functionName": "schnorr_negate_public_key", + "inArgs": [ + { + "name": "public_key_buffer", + "type": "affine_element::in_buf" + } + ], + "outArgs": [ + { + "name": "output", + "type": "affine_element::out_buf" + } + ], + "isAsync": false + }, + { + "functionName": "schnorr_construct_signature", + "inArgs": [ + { + "name": "message", + "type": "const uint8_t *" + }, + { + "name": "private_key", + "type": "fr::in_buf" + } + ], + "outArgs": [ + { + "name": "s", + "type": "out_buf32" + }, + { + "name": "e", + "type": "out_buf32" + } + ], + "isAsync": false + }, + { + "functionName": "schnorr_verify_signature", + "inArgs": [ + { + "name": "message", + "type": "const uint8_t *" + }, + { + "name": "pub_key", + "type": "affine_element::in_buf" + }, + { + "name": "sig_s", + "type": "in_buf32" + }, + { + "name": "sig_e", + "type": "in_buf32" + } + ], + "outArgs": [ + { + "name": "result", + "type": "bool *" + } + ], + "isAsync": false + }, + { + "functionName": "schnorr_multisig_create_multisig_public_key", + "inArgs": [ + { + "name": "private_key", + "type": "fr::in_buf" + } + ], + "outArgs": [ + { + "name": "multisig_pubkey_buf", + "type": "multisig::MultiSigPublicKey::out_buf" + } + ], + "isAsync": false + }, + { + "functionName": "schnorr_multisig_validate_and_combine_signer_pubkeys", + "inArgs": [ + { + "name": "signer_pubkey_buf", + "type": "multisig::MultiSigPublicKey::vec_in_buf" + } + ], + "outArgs": [ + { + "name": "combined_key_buf", + "type": "affine_element::out_buf" + }, + { + "name": "success", + "type": "bool *" + } + ], + "isAsync": false + }, + { + "functionName": "schnorr_multisig_construct_signature_round_1", + "inArgs": [], + "outArgs": [ + { + "name": "round_one_public_output_buf", + "type": "multisig::RoundOnePublicOutput::out_buf" + }, + { + "name": "round_one_private_output_buf", + "type": "multisig::RoundOnePrivateOutput::out_buf" + } + ], + "isAsync": false + }, + { + "functionName": "schnorr_multisig_construct_signature_round_2", + "inArgs": [ + { + "name": "message", + "type": "const uint8_t *" + }, + { + "name": "private_key", + "type": "fr::in_buf" + }, + { + "name": "signer_round_one_private_buf", + "type": "multisig::RoundOnePrivateOutput::in_buf" + }, + { + "name": "signer_pubkeys_buf", + "type": "multisig::MultiSigPublicKey::vec_in_buf" + }, + { + "name": "round_one_public_buf", + "type": "multisig::RoundOnePublicOutput::vec_in_buf" + } + ], + "outArgs": [ + { + "name": "round_two_buf", + "type": "fr::out_buf" + }, + { + "name": "success", + "type": "bool *" + } + ], + "isAsync": false + }, + { + "functionName": "schnorr_multisig_combine_signatures", + "inArgs": [ + { + "name": "message", + "type": "const uint8_t *" + }, + { + "name": "signer_pubkeys_buf", + "type": "multisig::MultiSigPublicKey::vec_in_buf" + }, + { + "name": "round_one_buf", + "type": "multisig::RoundOnePublicOutput::vec_in_buf" + }, + { + "name": "round_two_buf", + "type": "fr::vec_in_buf" + } + ], + "outArgs": [ + { + "name": "s", + "type": "out_buf32" + }, + { + "name": "e", + "type": "out_buf32" + }, + { + "name": "success", + "type": "bool *" + } + ], + "isAsync": false + }, + { + "functionName": "srs_init_srs", + "inArgs": [ + { + "name": "points_buf", + "type": "const uint8_t *" + }, + { + "name": "num_points", + "type": "const uint32_t *" + }, + { + "name": "g2_point_buf", + "type": "const uint8_t *" + } + ], + "outArgs": [], + "isAsync": false + }, + { + "functionName": "examples_simple_create_and_verify_proof", + "inArgs": [], + "outArgs": [ + { + "name": "valid", + "type": "bool *" + } + ], + "isAsync": false + }, + { + "functionName": "test_threads", + "inArgs": [ + { + "name": "threads", + "type": "const uint32_t *" + }, + { + "name": "iterations", + "type": "const uint32_t *" + } + ], + "outArgs": [ + { + "name": "out", + "type": "uint32_t *" + } + ], + "isAsync": false + }, + { + "functionName": "common_init_slab_allocator", + "inArgs": [ + { + "name": "circuit_size", + "type": "const uint32_t *" + } + ], + "outArgs": [], + "isAsync": false + }, + { + "functionName": "acir_get_circuit_sizes", + "inArgs": [ + { + "name": "constraint_system_buf", + "type": "const uint8_t *" + } + ], + "outArgs": [ + { + "name": "exact", + "type": "uint32_t *" + }, + { + "name": "total", + "type": "uint32_t *" + }, + { + "name": "subgroup", + "type": "uint32_t *" + } + ], + "isAsync": false + }, + { + "functionName": "acir_new_acir_composer", + "inArgs": [ + { + "name": "size_hint", + "type": "const uint32_t *" + } + ], + "outArgs": [ + { + "name": "out", + "type": "out_ptr" + } + ], + "isAsync": false + }, + { + "functionName": "acir_delete_acir_composer", + "inArgs": [ + { + "name": "acir_composer_ptr", + "type": "in_ptr" + } + ], + "outArgs": [], + "isAsync": false + }, + { + "functionName": "acir_create_circuit", + "inArgs": [ + { + "name": "acir_composer_ptr", + "type": "in_ptr" + }, + { + "name": "constraint_system_buf", + "type": "const uint8_t *" + }, + { + "name": "size_hint", + "type": "const uint32_t *" + } + ], + "outArgs": [], + "isAsync": false + }, + { + "functionName": "acir_init_proving_key", + "inArgs": [ + { + "name": "acir_composer_ptr", + "type": "in_ptr" + }, + { + "name": "constraint_system_buf", + "type": "const uint8_t *" + } + ], + "outArgs": [], + "isAsync": false + }, + { + "functionName": "acir_create_proof", + "inArgs": [ + { + "name": "acir_composer_ptr", + "type": "in_ptr" + }, + { + "name": "constraint_system_buf", + "type": "const uint8_t *" + }, + { + "name": "witness_buf", + "type": "const uint8_t *" + }, + { + "name": "is_recursive", + "type": "const bool *" + } + ], + "outArgs": [ + { + "name": "out", + "type": "uint8_t **" + } + ], + "isAsync": false + }, + { + "functionName": "acir_load_verification_key", + "inArgs": [ + { + "name": "acir_composer_ptr", + "type": "in_ptr" + }, + { + "name": "vk_buf", + "type": "const uint8_t *" + } + ], + "outArgs": [], + "isAsync": false + }, + { + "functionName": "acir_init_verification_key", + "inArgs": [ + { + "name": "acir_composer_ptr", + "type": "in_ptr" + } + ], + "outArgs": [], + "isAsync": false + }, + { + "functionName": "acir_get_verification_key", + "inArgs": [ + { + "name": "acir_composer_ptr", + "type": "in_ptr" + } + ], + "outArgs": [ + { + "name": "out", + "type": "uint8_t **" + } + ], + "isAsync": false + }, + { + "functionName": "acir_verify_proof", + "inArgs": [ + { + "name": "acir_composer_ptr", + "type": "in_ptr" + }, + { + "name": "proof_buf", + "type": "const uint8_t *" + }, + { + "name": "is_recursive", + "type": "const bool *" + } + ], + "outArgs": [ + { + "name": "result", + "type": "bool *" + } + ], + "isAsync": false + }, + { + "functionName": "acir_get_solidity_verifier", + "inArgs": [ + { + "name": "acir_composer_ptr", + "type": "in_ptr" + } + ], + "outArgs": [ + { + "name": "out", + "type": "out_str_buf" + } + ], + "isAsync": false + }, + { + "functionName": "acir_serialize_proof_into_fields", + "inArgs": [ + { + "name": "acir_composer_ptr", + "type": "in_ptr" + }, + { + "name": "proof_buf", + "type": "const uint8_t *" + }, + { + "name": "num_inner_public_inputs", + "type": "const uint32_t *" + } + ], + "outArgs": [ + { + "name": "out", + "type": "fr::vec_out_buf" + } + ], + "isAsync": false + }, + { + "functionName": "acir_serialize_verification_key_into_fields", + "inArgs": [ + { + "name": "acir_composer_ptr", + "type": "in_ptr" + } + ], + "outArgs": [ + { + "name": "out_vkey", + "type": "fr::vec_out_buf" + }, + { + "name": "out_key_hash", + "type": "fr::out_buf" + } + ], + "isAsync": false + } +] diff --git a/barretenberg/scripts/c_bind_files.txt b/barretenberg/scripts/c_bind_files.txt index c0fe8b60f46d..a84057549ba3 100644 --- a/barretenberg/scripts/c_bind_files.txt +++ b/barretenberg/scripts/c_bind_files.txt @@ -1,4 +1,4 @@ -./cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.hpp +./cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp ./cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp ./cpp/src/barretenberg/crypto/blake2s/c_bind.hpp ./cpp/src/barretenberg/crypto/schnorr/c_bind.hpp diff --git a/barretenberg/scripts/decls_json.py b/barretenberg/scripts/decls_json.py index 93cb152bd8be..5b8473b46928 100755 --- a/barretenberg/scripts/decls_json.py +++ b/barretenberg/scripts/decls_json.py @@ -41,7 +41,6 @@ def process_files(files: List[str]) -> List[dict]: # '-isystem', '/usr/include/x86_64-linux-gnu', # '-isystem', '/usr/include', "-I./cpp/src", - '-stdlib=libc++', '-std=gnu++20', '-Wall', '-Wextra']) for diag in tu.diagnostics: print_diagnostic(diag, file=sys.stderr) diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index d7e5af84411e..20c4702db0d6 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -65,7 +65,7 @@ export class BarretenbergApi { return result[0]; } - async schnorrMultisigCreateMultisigPublicKey(privateKey: Fq): Promise { + async schnorrMultisigCreateMultisigPublicKey(privateKey: Fr): Promise { const result = await this.binder.callWasmExport( 'schnorr_multisig_create_multisig_public_key', [privateKey], @@ -94,15 +94,15 @@ export class BarretenbergApi { async schnorrMultisigConstructSignatureRound2( message: Uint8Array, - privateKey: Fq, + privateKey: Fr, signerRoundOnePrivateBuf: Buffer128, signerPubkeysBuf: Buffer128[], roundOnePublicBuf: Buffer128[], - ): Promise<[Fq, boolean]> { + ): Promise<[Fr, boolean]> { const result = await this.binder.callWasmExport( 'schnorr_multisig_construct_signature_round_2', [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf], - [Fq, BoolDeserializer()], + [Fr, BoolDeserializer()], ); return result as any; } diff --git a/barretenberg/ts/src/barretenberg_api/pedersen.test.ts b/barretenberg/ts/src/barretenberg_api/pedersen.test.ts deleted file mode 100644 index 20188dc72e00..000000000000 --- a/barretenberg/ts/src/barretenberg_api/pedersen.test.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { Barretenberg } from '../barretenberg/index.js'; -import { BarretenbergWasmMain } from '../barretenberg_wasm/barretenberg_wasm_main/index.js'; -import { BarretenbergWasm } from '../barretenberg_wasm/index.js'; -import { Timer } from '../benchmark/timer.js'; -import { serializeBufferArrayToVector } from '../serialize/serialize.js'; -import { Fr, Point } from '../types/index.js'; - -describe('pedersen', () => { - let api: Barretenberg; - - beforeAll(async () => { - api = await Barretenberg.new(1); - }, 30000); - - afterAll(async () => { - await api.destroy(); - }); - - it('pedersenHashWithHashIndex', async () => { - const result = await api.pedersenHashWithHashIndex([new Fr(4n), new Fr(8n)], 7); - expect(result).toEqual(new Fr(2152386650411553803409271316104075950536496387580531018130718456431861859990n)); - }); - - it('pedersenCommit', async () => { - const result = await api.pedersenCommit([new Fr(4n), new Fr(8n), new Fr(12n)]); - expect(result).toEqual( - new Point( - new Fr(18374309251862457296563484909553154519357910650678202211610516068880120638872n), - new Fr(2572141322478528249692953821523229170092797347760799983831061874108357705739n), - ), - ); - }); -}); - -describe('pedersen sync', () => { - function pedersenCommitWasm(wasm: BarretenbergWasmMain, inputs: Uint8Array[]) { - const data = serializeBufferArrayToVector(inputs); - - // WASM gives us 1024 bytes of scratch space which we can use without - // needing to allocate/free it ourselves. This can be useful for when we need to pass in several small variables - // when calling functions on the wasm, however it's important to not overrun this scratch space as otherwise - // the written data will begin to corrupt the stack. - // - // Using this scratch space isn't particularly safe if we have multiple threads interacting with the wasm however, - // each thread could write to the same pointer address simultaneously. - const SCRATCH_SPACE_SIZE = 1024; - - // For pedersen hashing, the case of hashing two inputs is the most common. - // so ideally we want to optimize for that. This will use 64 bytes of memory and - // can thus be optimized by checking if the input buffer is smaller than the scratch space. - let inputPtr = 0; - if (inputs.length >= SCRATCH_SPACE_SIZE) { - inputPtr = wasm.call('bbmalloc', data.length); - } - wasm.writeMemory(inputPtr, data); - - // Since the output is 32 bytes, instead of allocating memory - // we can reuse the scratch space to store the result. - const outputPtr = 0; - - wasm.call('pedersen__commit', inputPtr, outputPtr); - const hashOutput = wasm.getMemorySlice(0, 64); - - if (inputPtr !== 0) { - wasm.call('bbfree', inputPtr); - } - - return [Buffer.from(hashOutput.slice(0, 32)), Buffer.from(hashOutput.slice(32, 64))]; - } - - it('pedersenCommit pure sync', async () => { - const bb = new BarretenbergWasmMain(); - await bb.init(1); - const loops = 1000; - const fields = Array.from({ length: loops * 2 }).map(() => Fr.random().toBuffer()); - const t = new Timer(); - for (let i = 0; i < loops; ++i) { - pedersenCommitWasm(bb, [fields[i * 2], fields[i * 2 + 1]]); - } - console.log(t.us() / loops); - }); - - it('pedersenCommit sync', async () => { - const api = await Barretenberg.newSync(); - const loops = 1000; - const fields = Array.from({ length: loops * 2 }).map(() => Fr.random()); - const t = new Timer(); - for (let i = 0; i < loops; ++i) { - await api.pedersenCommit([fields[i * 2], fields[i * 2 + 1]]); - } - console.log(t.us() / loops); - }); -}); diff --git a/barretenberg/ts/src/barretenberg_api/schnorr.test.ts b/barretenberg/ts/src/barretenberg_api/schnorr.test.ts index 1656da56395e..6b161cfb1c98 100644 --- a/barretenberg/ts/src/barretenberg_api/schnorr.test.ts +++ b/barretenberg/ts/src/barretenberg_api/schnorr.test.ts @@ -1,5 +1,5 @@ import { TextEncoder } from 'util'; -import { Buffer128, Buffer32, Fq, Fr, Point } from '../types/index.js'; +import { Buffer128, Buffer32, Fr, Point } from '../types/index.js'; import { Barretenberg } from '../barretenberg/index.js'; import { asyncMap } from '../async_map/index.js'; @@ -48,7 +48,7 @@ describe('schnorr', () => { it('should create + verify multi signature', async () => { // set up multisig accounts const numSigners = 7; - const pks = [...Array(numSigners)].map(() => Fq.random()); + const pks = [...Array(numSigners)].map(() => Fr.random()); const pubKeys = await asyncMap(pks, pk => api.schnorrMultisigCreateMultisigPublicKey(pk)); // round one From 3357fb8632d723e8e8635435e2957d102bf909e8 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Wed, 1 Nov 2023 18:23:46 +0000 Subject: [PATCH 07/29] wip --- .../crypto/pedersen_commitment/c_bind.cpp | 6 +- .../crypto/pedersen_commitment/c_bind.hpp | 4 +- .../crypto/pedersen_hash/c_bind.cpp | 4 +- .../crypto/pedersen_hash/c_bind.hpp | 4 +- .../crypto/pedersen_hash/c_bind_new.cpp | 17 -- barretenberg/exports.json | 8 +- barretenberg/ts/src/barretenberg_api/index.ts | 146 ++++-------------- barretenberg/ts/src/index.ts | 1 + barretenberg/ts/src/pedersen/pedersen.test.ts | 20 ++- barretenberg/ts/src/pedersen/pedersen.ts | 17 +- .../src/client/simulator.test.ts | 17 +- yarn-project/circuits.js/src/abis/abis.ts | 45 +++--- .../crypto/pedersen/index.test.ts | 27 ++-- .../barretenberg/crypto/pedersen/pedersen.ts | 43 +----- yarn-project/foundation/package.json | 1 + .../src/crypto/pedersen/index.test.ts | 6 +- .../foundation/src/crypto/pedersen/index.ts | 3 +- ...index.elliptic.ts => pedersen.elliptic.ts} | 2 +- .../{index.noble.ts => pedersen.noble.ts} | 0 .../src/crypto/pedersen/pedersen.wasm.ts | 24 +++ yarn-project/merkle-tree/src/pedersen.ts | 6 +- yarn-project/yarn.lock | 14 ++ 22 files changed, 143 insertions(+), 272 deletions(-) delete mode 100644 barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind_new.cpp rename yarn-project/foundation/src/crypto/pedersen/{index.elliptic.ts => pedersen.elliptic.ts} (99%) rename yarn-project/foundation/src/crypto/pedersen/{index.noble.ts => pedersen.noble.ts} (100%) create mode 100644 yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp index e4bed81865f8..a3fef2032b55 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp @@ -7,10 +7,14 @@ extern "C" { using namespace barretenberg; -WASM_EXPORT void pedersen___commit(fr::vec_in_buf inputs_buffer, affine_element::out_buf output) +WASM_EXPORT void pedersen_commit(fr::vec_in_buf inputs_buffer, + uint32_t const* hash_index, + affine_element::out_buf output) { std::vector to_commit; read(inputs_buffer, to_commit); + crypto::GeneratorContext ctx; + ctx.offset = static_cast(ntohl(*hash_index)); grumpkin::g1::affine_element pedersen_commitment = crypto::pedersen_commitment::commit_native(to_commit); serialize::write(output, pedersen_commitment); diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp index 84f56c20155d..e8c6db5eeb1d 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp @@ -8,5 +8,7 @@ extern "C" { using namespace barretenberg; using affine_element = grumpkin::g1::affine_element; -WASM_EXPORT void pedersen___commit(fr::vec_in_buf inputs_buffer, affine_element::out_buf output); +WASM_EXPORT void pedersen_commit(fr::vec_in_buf inputs_buffer, + uint32_t const* hash_index, + affine_element::out_buf output); } \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.cpp index 3dd91cb31714..6f51283ed9bd 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.cpp @@ -5,12 +5,12 @@ extern "C" { -WASM_EXPORT void pedersen__hash_with_hash_index(uint8_t const* inputs_buffer, uint32_t hash_index, uint8_t* output) +WASM_EXPORT void pedersen_hash(uint8_t const* inputs_buffer, uint32_t const* hash_index, uint8_t* output) { std::vector to_hash; read(inputs_buffer, to_hash); crypto::GeneratorContext ctx; - ctx.offset = static_cast(hash_index); + ctx.offset = static_cast(ntohl(*hash_index)); auto r = crypto::pedersen_hash::hash(to_hash, ctx); barretenberg::fr::serialize_to_buffer(r, output); } diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp index fdd7d51797a9..869418762d2d 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp @@ -7,7 +7,5 @@ extern "C" { using namespace barretenberg; -WASM_EXPORT void pedersen_hash_with_hash_index(fr::vec_in_buf inputs_buffer, - uint32_t const* hash_index, - fr::out_buf output); +WASM_EXPORT void pedersen_hash(fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, fr::out_buf output); } \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind_new.cpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind_new.cpp deleted file mode 100644 index 6a157492d34d..000000000000 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind_new.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "barretenberg/common/mem.hpp" -#include "barretenberg/common/serialize.hpp" -#include "c_bind.hpp" -#include "pedersen.hpp" - -extern "C" { - -WASM_EXPORT void pedersen_hash_with_hash_index(uint8_t const* inputs_buffer, - uint32_t const* hash_index, - uint8_t* output) -{ - std::vector to_hash; - read(inputs_buffer, to_hash); - auto r = crypto::pedersen_hash::hash(to_hash, ntohl(*hash_index)); - barretenberg::fr::serialize_to_buffer(r, output); -} -} \ No newline at end of file diff --git a/barretenberg/exports.json b/barretenberg/exports.json index 1bf3126c10f3..78152fb3c30c 100644 --- a/barretenberg/exports.json +++ b/barretenberg/exports.json @@ -1,10 +1,14 @@ [ { - "functionName": "pedersen___commit", + "functionName": "pedersen_commit", "inArgs": [ { "name": "inputs_buffer", "type": "fr::vec_in_buf" + }, + { + "name": "hash_index", + "type": "const uint32_t *" } ], "outArgs": [ @@ -16,7 +20,7 @@ "isAsync": false }, { - "functionName": "pedersen_hash_with_hash_index", + "functionName": "pedersen_hash", "inArgs": [ { "name": "inputs_buffer", diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index 20c4702db0d6..fb4669c8159a 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -1,13 +1,7 @@ // WARNING: FILE CODE GENERATED BY BINDGEN UTILITY. DO NOT EDIT! /* eslint-disable @typescript-eslint/no-unused-vars */ import { BarretenbergBinder } from '../barretenberg_binder/index.js'; -import { - BufferDeserializer, - NumberDeserializer, - VectorDeserializer, - BoolDeserializer, - StringDeserializer, -} from '../serialize/index.js'; +import { BufferDeserializer, NumberDeserializer, VectorDeserializer, BoolDeserializer, StringDeserializer } from '../serialize/index.js'; import { Fr, Fq, Point, Buffer32, Buffer128, Ptr } from '../types/index.js'; export class BarretenbergApi { @@ -17,13 +11,13 @@ export class BarretenbergApi { await this.binder.wasm.destroy(); } - async pedersenCommit(inputsBuffer: Fr[]): Promise { - const result = await this.binder.callWasmExport('pedersen___commit', [inputsBuffer], [Point]); + async pedersenCommit(inputsBuffer: Fr[], hashIndex: number): Promise { + const result = await this.binder.callWasmExport('pedersen_commit', [inputsBuffer, hashIndex], [Point]); return result[0]; } - async pedersenHashWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Promise { - const result = await this.binder.callWasmExport('pedersen_hash_with_hash_index', [inputsBuffer, hashIndex], [Fr]); + async pedersenHash(inputsBuffer: Fr[], hashIndex: number): Promise { + const result = await this.binder.callWasmExport('pedersen_hash', [inputsBuffer, hashIndex], [Fr]); return result[0]; } @@ -48,76 +42,37 @@ export class BarretenbergApi { } async schnorrConstructSignature(message: Uint8Array, privateKey: Fr): Promise<[Buffer32, Buffer32]> { - const result = await this.binder.callWasmExport( - 'schnorr_construct_signature', - [message, privateKey], - [Buffer32, Buffer32], - ); + const result = await this.binder.callWasmExport('schnorr_construct_signature', [message, privateKey], [Buffer32, Buffer32]); return result as any; } async schnorrVerifySignature(message: Uint8Array, pubKey: Point, sigS: Buffer32, sigE: Buffer32): Promise { - const result = await this.binder.callWasmExport( - 'schnorr_verify_signature', - [message, pubKey, sigS, sigE], - [BoolDeserializer()], - ); + const result = await this.binder.callWasmExport('schnorr_verify_signature', [message, pubKey, sigS, sigE], [BoolDeserializer()]); return result[0]; } async schnorrMultisigCreateMultisigPublicKey(privateKey: Fr): Promise { - const result = await this.binder.callWasmExport( - 'schnorr_multisig_create_multisig_public_key', - [privateKey], - [Buffer128], - ); + const result = await this.binder.callWasmExport('schnorr_multisig_create_multisig_public_key', [privateKey], [Buffer128]); return result[0]; } async schnorrMultisigValidateAndCombineSignerPubkeys(signerPubkeyBuf: Buffer128[]): Promise<[Point, boolean]> { - const result = await this.binder.callWasmExport( - 'schnorr_multisig_validate_and_combine_signer_pubkeys', - [signerPubkeyBuf], - [Point, BoolDeserializer()], - ); + const result = await this.binder.callWasmExport('schnorr_multisig_validate_and_combine_signer_pubkeys', [signerPubkeyBuf], [Point, BoolDeserializer()]); return result as any; } async schnorrMultisigConstructSignatureRound1(): Promise<[Buffer128, Buffer128]> { - const result = await this.binder.callWasmExport( - 'schnorr_multisig_construct_signature_round_1', - [], - [Buffer128, Buffer128], - ); + const result = await this.binder.callWasmExport('schnorr_multisig_construct_signature_round_1', [], [Buffer128, Buffer128]); return result as any; } - async schnorrMultisigConstructSignatureRound2( - message: Uint8Array, - privateKey: Fr, - signerRoundOnePrivateBuf: Buffer128, - signerPubkeysBuf: Buffer128[], - roundOnePublicBuf: Buffer128[], - ): Promise<[Fr, boolean]> { - const result = await this.binder.callWasmExport( - 'schnorr_multisig_construct_signature_round_2', - [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf], - [Fr, BoolDeserializer()], - ); + async schnorrMultisigConstructSignatureRound2(message: Uint8Array, privateKey: Fr, signerRoundOnePrivateBuf: Buffer128, signerPubkeysBuf: Buffer128[], roundOnePublicBuf: Buffer128[]): Promise<[Fr, boolean]> { + const result = await this.binder.callWasmExport('schnorr_multisig_construct_signature_round_2', [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf], [Fr, BoolDeserializer()]); return result as any; } - async schnorrMultisigCombineSignatures( - message: Uint8Array, - signerPubkeysBuf: Buffer128[], - roundOneBuf: Buffer128[], - roundTwoBuf: Fr[], - ): Promise<[Buffer32, Buffer32, boolean]> { - const result = await this.binder.callWasmExport( - 'schnorr_multisig_combine_signatures', - [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf], - [Buffer32, Buffer32, BoolDeserializer()], - ); + async schnorrMultisigCombineSignatures(message: Uint8Array, signerPubkeysBuf: Buffer128[], roundOneBuf: Buffer128[], roundTwoBuf: Fr[]): Promise<[Buffer32, Buffer32, boolean]> { + const result = await this.binder.callWasmExport('schnorr_multisig_combine_signatures', [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf], [Buffer32, Buffer32, BoolDeserializer()]); return result as any; } @@ -127,11 +82,7 @@ export class BarretenbergApi { } async examplesSimpleCreateAndVerifyProof(): Promise { - const result = await this.binder.callWasmExport( - 'examples_simple_create_and_verify_proof', - [], - [BoolDeserializer()], - ); + const result = await this.binder.callWasmExport('examples_simple_create_and_verify_proof', [], [BoolDeserializer()]); return result[0]; } @@ -146,11 +97,7 @@ export class BarretenbergApi { } async acirGetCircuitSizes(constraintSystemBuf: Uint8Array): Promise<[number, number, number]> { - const result = await this.binder.callWasmExport( - 'acir_get_circuit_sizes', - [constraintSystemBuf], - [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()], - ); + const result = await this.binder.callWasmExport('acir_get_circuit_sizes', [constraintSystemBuf], [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()]); return result as any; } @@ -165,34 +112,17 @@ export class BarretenbergApi { } async acirCreateCircuit(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, sizeHint: number): Promise { - const result = await this.binder.callWasmExport( - 'acir_create_circuit', - [acirComposerPtr, constraintSystemBuf, sizeHint], - [], - ); + const result = await this.binder.callWasmExport('acir_create_circuit', [acirComposerPtr, constraintSystemBuf, sizeHint], []); return; } async acirInitProvingKey(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array): Promise { - const result = await this.binder.callWasmExport( - 'acir_init_proving_key', - [acirComposerPtr, constraintSystemBuf], - [], - ); + const result = await this.binder.callWasmExport('acir_init_proving_key', [acirComposerPtr, constraintSystemBuf], []); return; } - async acirCreateProof( - acirComposerPtr: Ptr, - constraintSystemBuf: Uint8Array, - witnessBuf: Uint8Array, - isRecursive: boolean, - ): Promise { - const result = await this.binder.callWasmExport( - 'acir_create_proof', - [acirComposerPtr, constraintSystemBuf, witnessBuf, isRecursive], - [BufferDeserializer()], - ); + async acirCreateProof(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array, isRecursive: boolean): Promise { + const result = await this.binder.callWasmExport('acir_create_proof', [acirComposerPtr, constraintSystemBuf, witnessBuf, isRecursive], [BufferDeserializer()]); return result[0]; } @@ -207,51 +137,27 @@ export class BarretenbergApi { } async acirGetVerificationKey(acirComposerPtr: Ptr): Promise { - const result = await this.binder.callWasmExport( - 'acir_get_verification_key', - [acirComposerPtr], - [BufferDeserializer()], - ); + const result = await this.binder.callWasmExport('acir_get_verification_key', [acirComposerPtr], [BufferDeserializer()]); return result[0]; } async acirVerifyProof(acirComposerPtr: Ptr, proofBuf: Uint8Array, isRecursive: boolean): Promise { - const result = await this.binder.callWasmExport( - 'acir_verify_proof', - [acirComposerPtr, proofBuf, isRecursive], - [BoolDeserializer()], - ); + const result = await this.binder.callWasmExport('acir_verify_proof', [acirComposerPtr, proofBuf, isRecursive], [BoolDeserializer()]); return result[0]; } async acirGetSolidityVerifier(acirComposerPtr: Ptr): Promise { - const result = await this.binder.callWasmExport( - 'acir_get_solidity_verifier', - [acirComposerPtr], - [StringDeserializer()], - ); + const result = await this.binder.callWasmExport('acir_get_solidity_verifier', [acirComposerPtr], [StringDeserializer()]); return result[0]; } - async acirSerializeProofIntoFields( - acirComposerPtr: Ptr, - proofBuf: Uint8Array, - numInnerPublicInputs: number, - ): Promise { - const result = await this.binder.callWasmExport( - 'acir_serialize_proof_into_fields', - [acirComposerPtr, proofBuf, numInnerPublicInputs], - [VectorDeserializer(Fr)], - ); + async acirSerializeProofIntoFields(acirComposerPtr: Ptr, proofBuf: Uint8Array, numInnerPublicInputs: number): Promise { + const result = await this.binder.callWasmExport('acir_serialize_proof_into_fields', [acirComposerPtr, proofBuf, numInnerPublicInputs], [VectorDeserializer(Fr)]); return result[0]; } async acirSerializeVerificationKeyIntoFields(acirComposerPtr: Ptr): Promise<[Fr[], Fr]> { - const result = await this.binder.callWasmExport( - 'acir_serialize_verification_key_into_fields', - [acirComposerPtr], - [VectorDeserializer(Fr), Fr], - ); + const result = await this.binder.callWasmExport('acir_serialize_verification_key_into_fields', [acirComposerPtr], [VectorDeserializer(Fr), Fr]); return result as any; } } diff --git a/barretenberg/ts/src/index.ts b/barretenberg/ts/src/index.ts index 0998072f1de6..b088e2a2ce52 100644 --- a/barretenberg/ts/src/index.ts +++ b/barretenberg/ts/src/index.ts @@ -1,3 +1,4 @@ export { Crs } from './crs/index.js'; export { Barretenberg } from './barretenberg/index.js'; export { RawBuffer, Fr } from './types/index.js'; +export { Pedersen } from './pedersen/index.js'; diff --git a/barretenberg/ts/src/pedersen/pedersen.test.ts b/barretenberg/ts/src/pedersen/pedersen.test.ts index 0295a6018d47..74c339830458 100644 --- a/barretenberg/ts/src/pedersen/pedersen.test.ts +++ b/barretenberg/ts/src/pedersen/pedersen.test.ts @@ -1,23 +1,21 @@ import { Pedersen } from './pedersen.js'; import { Timer } from '../benchmark/timer.js'; -import { Fr, Point } from '../types/index.js'; +import { Fr } from '../types/index.js'; describe('pedersen sync', () => { - it('pedersenHashWithHashIndex', async () => { + it('pedersenHash', async () => { const pedersen = await Pedersen.new(); - const result = pedersen.pedersenHashWithHashIndex([new Fr(4n), new Fr(8n)], 7); + const result = pedersen.pedersenHash([new Fr(4n).toBuffer(), new Fr(8n).toBuffer()], 7); expect(result).toEqual(new Fr(2152386650411553803409271316104075950536496387580531018130718456431861859990n)); }); it('pedersenCommit', async () => { const pedersen = await Pedersen.new(); - const result = pedersen.pedersenCommit([new Fr(4n), new Fr(8n), new Fr(12n)]); - expect(result).toEqual( - new Point( - new Fr(18374309251862457296563484909553154519357910650678202211610516068880120638872n), - new Fr(2572141322478528249692953821523229170092797347760799983831061874108357705739n), - ), - ); + const result = pedersen.pedersenCommit([new Fr(4n).toBuffer(), new Fr(8n).toBuffer(), new Fr(12n).toBuffer()]); + expect(result).toEqual([ + new Fr(18374309251862457296563484909553154519357910650678202211610516068880120638872n).toBuffer(), + new Fr(2572141322478528249692953821523229170092797347760799983831061874108357705739n).toBuffer(), + ]); }); it.skip('pedersenCommit perf test', async () => { @@ -26,7 +24,7 @@ describe('pedersen sync', () => { const fields = Array.from({ length: loops * 2 }).map(() => Fr.random()); const t = new Timer(); for (let i = 0; i < loops; ++i) { - pedersen.pedersenCommit([fields[i * 2], fields[i * 2 + 1]]); + pedersen.pedersenCommit([fields[i * 2].toBuffer(), fields[i * 2 + 1].toBuffer()]); } console.log(t.us() / loops); }); diff --git a/barretenberg/ts/src/pedersen/pedersen.ts b/barretenberg/ts/src/pedersen/pedersen.ts index 6b713c879b84..6e3a154d771a 100644 --- a/barretenberg/ts/src/pedersen/pedersen.ts +++ b/barretenberg/ts/src/pedersen/pedersen.ts @@ -1,6 +1,5 @@ import { BarretenbergWasmMain } from '../barretenberg_wasm/barretenberg_wasm_main/index.js'; import { numToUInt32BE, serializeBufferArrayToVector } from '../serialize/serialize.js'; -import { Point, Fr } from '../types/index.js'; export class Pedersen { constructor(public wasm: BarretenbergWasmMain) {} @@ -11,10 +10,10 @@ export class Pedersen { return new Pedersen(wasm); } - pedersenHashWithHashIndex(inputs: Fr[], hashIndex: number) { + pedersenHash(inputs: Uint8Array[], hashIndex = 0) { const SCRATCH_SPACE_SIZE = 1024; - const data = serializeBufferArrayToVector(inputs.map(fr => fr.toBuffer())); + const data = serializeBufferArrayToVector(inputs); let inputPtr = 0; if (inputs.length >= SCRATCH_SPACE_SIZE - 4) { @@ -24,20 +23,20 @@ export class Pedersen { this.wasm.writeMemory(SCRATCH_SPACE_SIZE - 4, numToUInt32BE(hashIndex)); const outputPtr = 0; - this.wasm.call('pedersen_hash_with_hash_index', inputPtr, SCRATCH_SPACE_SIZE - 4, outputPtr); + this.wasm.call('pedersen_hash', inputPtr, SCRATCH_SPACE_SIZE - 4, outputPtr); const hashOutput = this.wasm.getMemorySlice(0, 32); if (inputPtr !== 0) { this.wasm.call('bbfree', inputPtr); } - return Fr.fromBuffer(hashOutput); + return hashOutput; } - pedersenCommit(inputs: Fr[]) { + pedersenCommit(inputs: Uint8Array[], hashIndex = 0) { const SCRATCH_SPACE_SIZE = 1024; - const data = serializeBufferArrayToVector(inputs.map(fr => fr.toBuffer())); + const data = serializeBufferArrayToVector(inputs); let inputPtr = 0; if (inputs.length >= SCRATCH_SPACE_SIZE) { @@ -46,13 +45,13 @@ export class Pedersen { this.wasm.writeMemory(inputPtr, data); const outputPtr = 0; - this.wasm.call('pedersen__commit', inputPtr, outputPtr); + this.wasm.call('pedersen_commit', inputPtr, hashIndex, outputPtr); const hashOutput = this.wasm.getMemorySlice(0, 64); if (inputPtr !== 0) { this.wasm.call('bbfree', inputPtr); } - return new Point(Fr.fromBuffer(hashOutput.slice(0, 32)), Fr.fromBuffer(hashOutput.slice(32, 64))); + return [hashOutput.slice(0, 32), hashOutput.slice(32, 64)]; } } diff --git a/yarn-project/acir-simulator/src/client/simulator.test.ts b/yarn-project/acir-simulator/src/client/simulator.test.ts index d1b5cade92ff..4dcf6fca9099 100644 --- a/yarn-project/acir-simulator/src/client/simulator.test.ts +++ b/yarn-project/acir-simulator/src/client/simulator.test.ts @@ -1,4 +1,4 @@ -import { CircuitsWasm, CompleteAddress } from '@aztec/circuits.js'; +import { CompleteAddress } from '@aztec/circuits.js'; import { computeUniqueCommitment, siloCommitment } from '@aztec/circuits.js/abis'; import { pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; import { ABIParameterVisibility } from '@aztec/foundation/abi'; @@ -16,22 +16,13 @@ import { AcirSimulator } from './simulator.js'; describe('Simulator', () => { let oracle: MockProxy; let simulator: AcirSimulator; - let circuitsWasm: CircuitsWasm; let ownerCompleteAddress: CompleteAddress; let owner: AztecAddress; const ownerPk = GrumpkinScalar.fromString('2dcc5485a58316776299be08c78fa3788a1a7961ae30dc747fb1be17692a8d32'); - const hashFields = (data: Fr[]) => - Fr.fromBuffer( - pedersenHashInputs( - circuitsWasm, - data.map(f => f.toBuffer()), - ), - ); + const hashFields = (data: Fr[]) => Fr.fromBuffer(pedersenHashInputs(data.map(f => f.toBuffer()))); beforeAll(async () => { - circuitsWasm = await CircuitsWasm.get(); - ownerCompleteAddress = await CompleteAddress.fromPrivateKeyAndPartialAddress(ownerPk, Fr.random()); owner = ownerCompleteAddress.address; }); @@ -58,8 +49,8 @@ describe('Simulator', () => { const note = createNote(); const valueNoteHash = hashFields(note.items); const innerNoteHash = hashFields([storageSlot, valueNoteHash]); - const siloedNoteHash = siloCommitment(circuitsWasm, contractAddress, innerNoteHash); - const uniqueSiloedNoteHash = computeUniqueCommitment(circuitsWasm, nonce, siloedNoteHash); + const siloedNoteHash = siloCommitment(contractAddress, innerNoteHash); + const uniqueSiloedNoteHash = computeUniqueCommitment(nonce, siloedNoteHash); const innerNullifier = hashFields([uniqueSiloedNoteHash, ownerPk.low, ownerPk.high]); const result = await simulator.computeNoteHashAndNullifier(contractAddress, nonce, storageSlot, note); diff --git a/yarn-project/circuits.js/src/abis/abis.ts b/yarn-project/circuits.js/src/abis/abis.ts index 5e0a369acc41..d79df2e957d1 100644 --- a/yarn-project/circuits.js/src/abis/abis.ts +++ b/yarn-project/circuits.js/src/abis/abis.ts @@ -1,5 +1,5 @@ import { padArrayEnd } from '@aztec/foundation/collection'; -import { keccak, pedersenHashWithHashIndex } from '@aztec/foundation/crypto'; +import { keccak, pedersenHash } from '@aztec/foundation/crypto'; import { numToUInt32BE } from '@aztec/foundation/serialize'; import { IWasmModule } from '@aztec/foundation/wasm'; @@ -95,7 +95,7 @@ export function hashVK(wasm: IWasmModule, vkBuf: Buffer) { */ export function computeFunctionLeaf(fnLeaf: FunctionLeafPreimage): Fr { return Fr.fromBuffer( - pedersenHashWithHashIndex( + pedersenHash( [ fnLeaf.functionSelector.toBuffer(), boolToBuffer(fnLeaf.isInternal), @@ -130,7 +130,7 @@ export function computeFunctionTreeRoot(wasm: IWasmModule, fnLeaves: Fr[]) { */ export function hashConstructor(functionData: FunctionData, argsHash: Fr, constructorVKHash: Buffer): Fr { return Fr.fromBuffer( - pedersenHashWithHashIndex( + pedersenHash( [computeFunctionDataHash(functionData).toBuffer(), argsHash.toBuffer(), constructorVKHash], GeneratorIndex.CONSTRUCTOR, ), @@ -165,7 +165,7 @@ export function computeCompleteAddress( */ function computePartialAddress(contractAddrSalt: Fr, fnTreeRoot: Fr, constructorHash: Fr) { return Fr.fromBuffer( - pedersenHashWithHashIndex( + pedersenHash( [ Fr.ZERO.toBuffer(), Fr.ZERO.toBuffer(), @@ -187,7 +187,7 @@ function computePartialAddress(contractAddrSalt: Fr, fnTreeRoot: Fr, constructor * @returns The partially constructed contract address. */ export function computeContractAddressFromPartial(pubKey: PublicKey, partialAddress: Fr): AztecAddress { - const result = pedersenHashWithHashIndex( + const result = pedersenHash( [pubKey.x.toBuffer(), pubKey.y.toBuffer(), partialAddress.toBuffer()], GeneratorIndex.CONTRACT_ADDRESS, ); @@ -203,10 +203,7 @@ export function computeContractAddressFromPartial(pubKey: PublicKey, partialAddr */ export function computeCommitmentNonce(nullifierZero: Fr, commitmentIndex: number): Fr { return Fr.fromBuffer( - pedersenHashWithHashIndex( - [nullifierZero.toBuffer(), numToUInt32BE(commitmentIndex, 32)], - GeneratorIndex.COMMITMENT_NONCE, - ), + pedersenHash([nullifierZero.toBuffer(), numToUInt32BE(commitmentIndex, 32)], GeneratorIndex.COMMITMENT_NONCE), ); } @@ -220,7 +217,7 @@ export function computeCommitmentNonce(nullifierZero: Fr, commitmentIndex: numbe */ export function siloCommitment(contract: AztecAddress, innerCommitment: Fr): Fr { return Fr.fromBuffer( - pedersenHashWithHashIndex([contract.toBuffer(), innerCommitment.toBuffer()], GeneratorIndex.SILOED_COMMITMENT), + pedersenHash([contract.toBuffer(), innerCommitment.toBuffer()], GeneratorIndex.SILOED_COMMITMENT), ); } @@ -232,9 +229,7 @@ export function siloCommitment(contract: AztecAddress, innerCommitment: Fr): Fr * @returns A unique commitment. */ export function computeUniqueCommitment(nonce: Fr, siloedCommitment: Fr): Fr { - return Fr.fromBuffer( - pedersenHashWithHashIndex([nonce.toBuffer(), siloedCommitment.toBuffer()], GeneratorIndex.UNIQUE_COMMITMENT), - ); + return Fr.fromBuffer(pedersenHash([nonce.toBuffer(), siloedCommitment.toBuffer()], GeneratorIndex.UNIQUE_COMMITMENT)); } /** @@ -246,9 +241,7 @@ export function computeUniqueCommitment(nonce: Fr, siloedCommitment: Fr): Fr { * @returns A siloed nullifier. */ export function siloNullifier(contract: AztecAddress, innerNullifier: Fr): Fr { - return Fr.fromBuffer( - pedersenHashWithHashIndex([contract.toBuffer(), innerNullifier.toBuffer()], GeneratorIndex.OUTER_NULLIFIER), - ); + return Fr.fromBuffer(pedersenHash([contract.toBuffer(), innerNullifier.toBuffer()], GeneratorIndex.OUTER_NULLIFIER)); } /** @@ -300,7 +293,7 @@ export function computeBlockHash( publicDataTreeRoot: Fr, ): Fr { return Fr.fromBuffer( - pedersenHashWithHashIndex( + pedersenHash( [ globalsHash.toBuffer(), noteHashTreeRoot.toBuffer(), @@ -322,7 +315,7 @@ export function computeBlockHash( */ export function computeGlobalsHash(globals: GlobalVariables): Fr { return Fr.fromBuffer( - pedersenHashWithHashIndex( + pedersenHash( [ globals.chainId.toBuffer(), globals.version.toBuffer(), @@ -355,7 +348,7 @@ export function computePublicDataTreeValue(value: Fr): Fr { */ export function computePublicDataTreeIndex(contractAddress: AztecAddress, storageSlot: Fr): Fr { return Fr.fromBuffer( - pedersenHashWithHashIndex([contractAddress.toBuffer(), storageSlot.toBuffer()], GeneratorIndex.PUBLIC_LEAF_INDEX), + pedersenHash([contractAddress.toBuffer(), storageSlot.toBuffer()], GeneratorIndex.PUBLIC_LEAF_INDEX), ); } @@ -375,7 +368,7 @@ export function computeVarArgsHash(args: Fr[]) { const wasmComputeVarArgs = (args: Fr[]) => Fr.fromBuffer( - pedersenHashWithHashIndex( + pedersenHash( args.map(a => a.toBuffer()), GeneratorIndex.FUNCTION_ARGS, ), @@ -403,7 +396,7 @@ export function computeVarArgsHash(args: Fr[]) { */ export function computeContractLeaf(cd: NewContractData): Fr { return Fr.fromBuffer( - pedersenHashWithHashIndex( + pedersenHash( [cd.contractAddress.toBuffer(), cd.portalContractAddress.toBuffer(), cd.functionTreeRoot.toBuffer()], GeneratorIndex.CONTRACT_LEAF, ), @@ -418,7 +411,7 @@ export function computeContractLeaf(cd: NewContractData): Fr { */ export function computeTxHash(txRequest: TxRequest): Fr { return Fr.fromBuffer( - pedersenHashWithHashIndex( + pedersenHash( [ txRequest.origin.toBuffer(), computeFunctionDataHash(txRequest.functionData).toBuffer(), @@ -435,7 +428,7 @@ export function computeTxHash(txRequest: TxRequest): Fr { */ function computeFunctionDataHash(functionData: FunctionData): Fr { return Fr.fromBuffer( - pedersenHashWithHashIndex( + pedersenHash( [ functionData.selector.toBuffer(), new Fr(functionData.isInternal).toBuffer(), @@ -452,7 +445,7 @@ function computeFunctionDataHash(functionData: FunctionData): Fr { */ function computeTxContextHash(txContext: TxContext): Fr { return Fr.fromBuffer( - pedersenHashWithHashIndex( + pedersenHash( [ new Fr(txContext.isFeePaymentTx).toBuffer(), new Fr(txContext.isRebatePaymentTx).toBuffer(), @@ -471,7 +464,7 @@ function computeTxContextHash(txContext: TxContext): Fr { */ function computeContractDeploymentDataHash(data: ContractDeploymentData): Fr { return Fr.fromBuffer( - pedersenHashWithHashIndex( + pedersenHash( [ data.deployerPublicKey.x.toBuffer(), data.deployerPublicKey.y.toBuffer(), @@ -552,5 +545,5 @@ export function computePublicCallStackItemHash(wasm: IWasmModule, callStackItem: * @returns */ export function computeSecretMessageHash(secretMessage: Fr) { - return Fr.fromBuffer(pedersenHashWithHashIndex([secretMessage.toBuffer()], GeneratorIndex.L1_TO_L2_MESSAGE_SECRET)); + return Fr.fromBuffer(pedersenHash([secretMessage.toBuffer()], GeneratorIndex.L1_TO_L2_MESSAGE_SECRET)); } diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts index 0ab770c7234b..c9966dcde4eb 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts @@ -1,33 +1,28 @@ -import { toBufferBE } from '@aztec/foundation/bigint-buffer'; -import { pedersenCommit, pedersenCommitNoble } from '@aztec/foundation/crypto'; +import { pedersenCommit } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import { Timer } from '@aztec/foundation/timer'; -import { CircuitsWasm } from '../../../wasm/index.js'; -import { pedersenCommitWasm } from './index.js'; - describe('pedersen', () => { const loops = 1000; const fields = Array.from({ length: loops * 2 }).map(() => Fr.random().toBuffer()); - it('pedersen perf wasm', async () => { - const wasm = await CircuitsWasm.get(); + it('pedersen perf', () => { const t = new Timer(); for (let i = 0; i < loops; ++i) { - pedersenCommitWasm(wasm, [fields[i * 2], fields[i * 2 + 1]]); + pedersenCommit([fields[i * 2], fields[i * 2 + 1]]); } console.log(t.us() / loops); // console.log(pedersenCommitWasm(wasm, [toBufferBE(1n, 32), toBufferBE(1n, 32)])); }); - it('pedersen perf elliptic', () => { - const t = new Timer(); - for (let i = 0; i < loops; ++i) { - pedersenCommit([fields[i * 2], fields[i * 2 + 1]]); - } - console.log(t.us() / loops); - // console.log(pedersenCommit([toBufferBE(1n, 32), toBufferBE(1n, 32)])); - }); + // it('pedersen perf elliptic', () => { + // const t = new Timer(); + // for (let i = 0; i < loops; ++i) { + // pedersenCommit([fields[i * 2], fields[i * 2 + 1]]); + // } + // console.log(t.us() / loops); + // // console.log(pedersenCommit([toBufferBE(1n, 32), toBufferBE(1n, 32)])); + // }); // it('pedersen perf noble', () => { // const loops = 10000; diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts index a49b91422ee0..12dc1b91a7a0 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts @@ -1,10 +1,7 @@ -import { pedersenHashWithHashIndex as cryptoPedersen } from '@aztec/foundation/crypto'; -import { IWasmModule } from '@aztec/foundation/wasm'; +import { pedersenHash as cryptoPedersen } from '@aztec/foundation/crypto'; import { Buffer } from 'buffer'; -import { serializeBufferArrayToVector } from '../../serialize.js'; - // TODO: DELETE THIS FILE! /** @@ -44,41 +41,3 @@ export function pedersenHashInputs(inputs: Buffer[]): Buffer { export function pedersenHashWithHashIndex(inputs: Buffer[], hashIndex: number): Buffer { return cryptoPedersen(inputs, hashIndex); } - -/** - * - */ -export function pedersenCommitWasm(wasm: IWasmModule, inputs: Buffer[]) { - const data = serializeBufferArrayToVector(inputs); - - // WASM gives us 1024 bytes of scratch space which we can use without - // needing to allocate/free it ourselves. This can be useful for when we need to pass in several small variables - // when calling functions on the wasm, however it's important to not overrun this scratch space as otherwise - // the written data will begin to corrupt the stack. - // - // Using this scratch space isn't particularly safe if we have multiple threads interacting with the wasm however, - // each thread could write to the same pointer address simultaneously. - const SCRATCH_SPACE_SIZE = 1024; - - // For pedersen hashing, the case of hashing two inputs is the most common. - // so ideally we want to optimize for that. This will use 64 bytes of memory and - // can thus be optimized by checking if the input buffer is smaller than the scratch space. - let inputPtr = 0; - if (inputs.length >= SCRATCH_SPACE_SIZE) { - inputPtr = wasm.call('bbmalloc', data.length); - } - wasm.writeMemory(inputPtr, data); - - // Since the output is 32 bytes, instead of allocating memory - // we can reuse the scratch space to store the result. - const outputPtr = 0; - - wasm.call('pedersen__commit', inputPtr, outputPtr); - const hashOutput = wasm.getMemorySlice(0, 64); - - if (inputPtr !== 0) { - wasm.call('bbfree', inputPtr); - } - - return [Buffer.from(hashOutput.slice(0, 32)), Buffer.from(hashOutput.slice(32, 64))]; -} diff --git a/yarn-project/foundation/package.json b/yarn-project/foundation/package.json index bbe710bdeee3..715db3fe353e 100644 --- a/yarn-project/foundation/package.json +++ b/yarn-project/foundation/package.json @@ -68,6 +68,7 @@ ] }, "dependencies": { + "@aztec/bb.js": "portal:../../barretenberg/ts", "@koa/cors": "^4.0.0", "@noble/curves": "^1.2.0", "bn.js": "^5.2.1", diff --git a/yarn-project/foundation/src/crypto/pedersen/index.test.ts b/yarn-project/foundation/src/crypto/pedersen/index.test.ts index 2aa763e8a5d8..0640c13d0b17 100644 --- a/yarn-project/foundation/src/crypto/pedersen/index.test.ts +++ b/yarn-project/foundation/src/crypto/pedersen/index.test.ts @@ -1,5 +1,5 @@ import { toBufferBE } from '../../bigint-buffer/index.js'; -import { pedersenCommit, pedersenHashWithHashIndex } from './index.js'; +import { pedersenCommit, pedersenHash } from './index.js'; describe('pedersen', () => { it('pedersen commit', () => { @@ -19,12 +19,12 @@ describe('pedersen', () => { }); it('pedersen hash', () => { - const r = pedersenHashWithHashIndex([toBufferBE(1n, 32), toBufferBE(1n, 32)]); + const r = pedersenHash([toBufferBE(1n, 32), toBufferBE(1n, 32)]); expect(r).toEqual(Buffer.from('07ebfbf4df29888c6cd6dca13d4bb9d1a923013ddbbcbdc3378ab8845463297b', 'hex')); }); it('pedersen hash with index', () => { - const r = pedersenHashWithHashIndex([toBufferBE(1n, 32), toBufferBE(1n, 32)], 5); + const r = pedersenHash([toBufferBE(1n, 32), toBufferBE(1n, 32)], 5); expect(r).toEqual(Buffer.from('1c446df60816b897cda124524e6b03f36df0cec333fad87617aab70d7861daa6', 'hex')); }); }); diff --git a/yarn-project/foundation/src/crypto/pedersen/index.ts b/yarn-project/foundation/src/crypto/pedersen/index.ts index ec098f69cedd..c85dafd4ca47 100644 --- a/yarn-project/foundation/src/crypto/pedersen/index.ts +++ b/yarn-project/foundation/src/crypto/pedersen/index.ts @@ -1,2 +1 @@ -export * from './index.elliptic.js'; -export * from './index.noble.js'; +export * from './pedersen.wasm.js'; diff --git a/yarn-project/foundation/src/crypto/pedersen/index.elliptic.ts b/yarn-project/foundation/src/crypto/pedersen/pedersen.elliptic.ts similarity index 99% rename from yarn-project/foundation/src/crypto/pedersen/index.elliptic.ts rename to yarn-project/foundation/src/crypto/pedersen/pedersen.elliptic.ts index 60ed202521d3..8f36453bbad5 100644 --- a/yarn-project/foundation/src/crypto/pedersen/index.elliptic.ts +++ b/yarn-project/foundation/src/crypto/pedersen/pedersen.elliptic.ts @@ -561,7 +561,7 @@ export function pedersenCommit(input: Buffer[], generatorOffset = 0) { /** * Create a pedersen hash (field) from an array of input fields. */ -export function pedersenHashWithHashIndex(input: Buffer[], index = 0) { +export function pedersenHash(input: Buffer[], index = 0) { const result = lengthGenerator.mul(new BN(input.length)); return result.add(pedersenCommitInternal(input, index)).getX().toBuffer(); } diff --git a/yarn-project/foundation/src/crypto/pedersen/index.noble.ts b/yarn-project/foundation/src/crypto/pedersen/pedersen.noble.ts similarity index 100% rename from yarn-project/foundation/src/crypto/pedersen/index.noble.ts rename to yarn-project/foundation/src/crypto/pedersen/pedersen.noble.ts diff --git a/yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts b/yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts new file mode 100644 index 000000000000..de880b7f0e75 --- /dev/null +++ b/yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts @@ -0,0 +1,24 @@ +import { Pedersen } from '@aztec/bb.js'; + +const pedersen = await Pedersen.new(); + +/** + * Create a pedersen commitment (point) from an array of input fields. + */ +export function pedersenCommit(input: Buffer[], generatorOffset = 0) { + if (!pedersen) { + throw new Error('Need to call await pedersenInit() first.'); + } + const [x, y] = pedersen.pedersenCommit(input, generatorOffset); + return [Buffer.from(x), Buffer.from(y)]; +} + +/** + * Create a pedersen hash (field) from an array of input fields. + */ +export function pedersenHash(input: Buffer[], index = 0) { + if (!pedersen) { + throw new Error('Need to call await pedersenInit() first.'); + } + return Buffer.from(pedersen.pedersenHash(input, index)); +} diff --git a/yarn-project/merkle-tree/src/pedersen.ts b/yarn-project/merkle-tree/src/pedersen.ts index 18212da85722..0d1681c50773 100644 --- a/yarn-project/merkle-tree/src/pedersen.ts +++ b/yarn-project/merkle-tree/src/pedersen.ts @@ -1,4 +1,4 @@ -import { pedersenHashWithHashIndex } from '@aztec/foundation/crypto'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { Hasher } from '@aztec/types'; /** @@ -12,7 +12,7 @@ export class Pedersen implements Hasher { * purposes. */ public hash(lhs: Uint8Array, rhs: Uint8Array): Buffer { - return pedersenHashWithHashIndex([Buffer.from(lhs), Buffer.from(rhs)]); + return pedersenHash([Buffer.from(lhs), Buffer.from(rhs)]); } /* @@ -20,6 +20,6 @@ export class Pedersen implements Hasher { * purposes. */ public hashInputs(inputs: Buffer[]): Buffer { - return pedersenHashWithHashIndex(inputs); + return pedersenHash(inputs); } } diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index e02147e26fe5..7d17f717bbbe 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -300,6 +300,19 @@ __metadata: languageName: node linkType: hard +"@aztec/bb.js@portal:../../barretenberg/ts::locator=%40aztec%2Ffoundation%40workspace%3Afoundation": + version: 0.0.0-use.local + resolution: "@aztec/bb.js@portal:../../barretenberg/ts::locator=%40aztec%2Ffoundation%40workspace%3Afoundation" + dependencies: + comlink: ^4.4.1 + commander: ^10.0.1 + debug: ^4.3.4 + tslib: ^2.4.0 + bin: + bb.js: ./dest/node/main.js + languageName: node + linkType: soft + "@aztec/canary@workspace:canary": version: 0.0.0-use.local resolution: "@aztec/canary@workspace:canary" @@ -483,6 +496,7 @@ __metadata: version: 0.0.0-use.local resolution: "@aztec/foundation@workspace:foundation" dependencies: + "@aztec/bb.js": "portal:../../barretenberg/ts" "@jest/globals": ^29.5.0 "@koa/cors": ^4.0.0 "@noble/curves": ^1.2.0 From db10fbd432faa86bf000e319778cf06b776f8dc4 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Wed, 1 Nov 2023 20:22:34 +0000 Subject: [PATCH 08/29] wip --- barretenberg/ts/src/pedersen/pedersen.ts | 7 ++++--- yarn-project/circuits.js/src/abis/abis.ts | 9 +++++---- yarn-project/circuits.js/src/utils/serialize.ts | 6 ++++-- yarn-project/foundation/src/abi/function_selector.ts | 5 +++-- yarn-project/foundation/src/crypto/pedersen/index.ts | 2 +- .../src/crypto/pedersen/pedersen.elliptic.ts | 10 ++++++++++ .../foundation/src/crypto/pedersen/pedersen.wasm.ts | 12 ++++++++---- 7 files changed, 35 insertions(+), 16 deletions(-) diff --git a/barretenberg/ts/src/pedersen/pedersen.ts b/barretenberg/ts/src/pedersen/pedersen.ts index 6e3a154d771a..ebf7d9645b9b 100644 --- a/barretenberg/ts/src/pedersen/pedersen.ts +++ b/barretenberg/ts/src/pedersen/pedersen.ts @@ -16,7 +16,7 @@ export class Pedersen { const data = serializeBufferArrayToVector(inputs); let inputPtr = 0; - if (inputs.length >= SCRATCH_SPACE_SIZE - 4) { + if (data.length > SCRATCH_SPACE_SIZE - 4) { inputPtr = this.wasm.call('bbmalloc', data.length); } this.wasm.writeMemory(inputPtr, data); @@ -39,13 +39,14 @@ export class Pedersen { const data = serializeBufferArrayToVector(inputs); let inputPtr = 0; - if (inputs.length >= SCRATCH_SPACE_SIZE) { + if (data.length > SCRATCH_SPACE_SIZE - 4) { inputPtr = this.wasm.call('bbmalloc', data.length); } this.wasm.writeMemory(inputPtr, data); + this.wasm.writeMemory(SCRATCH_SPACE_SIZE - 4, numToUInt32BE(hashIndex)); const outputPtr = 0; - this.wasm.call('pedersen_commit', inputPtr, hashIndex, outputPtr); + this.wasm.call('pedersen_commit', inputPtr, SCRATCH_SPACE_SIZE - 4, outputPtr); const hashOutput = this.wasm.getMemorySlice(0, 64); if (inputPtr !== 0) { diff --git a/yarn-project/circuits.js/src/abis/abis.ts b/yarn-project/circuits.js/src/abis/abis.ts index d79df2e957d1..b0da747f0981 100644 --- a/yarn-project/circuits.js/src/abis/abis.ts +++ b/yarn-project/circuits.js/src/abis/abis.ts @@ -94,12 +94,13 @@ export function hashVK(wasm: IWasmModule, vkBuf: Buffer) { * @returns The function leaf. */ export function computeFunctionLeaf(fnLeaf: FunctionLeafPreimage): Fr { + // return Fr.fromBuffer(wasmSyncCall(wasm, 'abis__compute_function_leaf', fnLeaf, 32)); return Fr.fromBuffer( pedersenHash( [ - fnLeaf.functionSelector.toBuffer(), - boolToBuffer(fnLeaf.isInternal), - boolToBuffer(fnLeaf.isPrivate), + numToUInt32BE(fnLeaf.functionSelector.value, 32), + boolToBuffer(fnLeaf.isInternal, 32), + boolToBuffer(fnLeaf.isPrivate, 32), fnLeaf.vkHash.toBuffer(), fnLeaf.acirHash.toBuffer(), ], @@ -430,7 +431,7 @@ function computeFunctionDataHash(functionData: FunctionData): Fr { return Fr.fromBuffer( pedersenHash( [ - functionData.selector.toBuffer(), + functionData.selector.toBuffer(32), new Fr(functionData.isInternal).toBuffer(), new Fr(functionData.isPrivate).toBuffer(), new Fr(functionData.isConstructor).toBuffer(), diff --git a/yarn-project/circuits.js/src/utils/serialize.ts b/yarn-project/circuits.js/src/utils/serialize.ts index c1c79ba0d304..fd75c700d379 100644 --- a/yarn-project/circuits.js/src/utils/serialize.ts +++ b/yarn-project/circuits.js/src/utils/serialize.ts @@ -101,8 +101,10 @@ export function uint8ArrayToNum(array: Uint8Array): number { * @param value - Value to serialize. * @returns The serialized boolean. */ -export function boolToBuffer(value: boolean): Buffer { - return Buffer.from([value ? 1 : 0]); +export function boolToBuffer(value: boolean, bufferSize = 1): Buffer { + const buf = Buffer.alloc(bufferSize); + buf.writeUInt8(value ? 1 : 0, bufferSize - 1); + return buf; } /** diff --git a/yarn-project/foundation/src/abi/function_selector.ts b/yarn-project/foundation/src/abi/function_selector.ts index fbfc56f79b6b..ac20bcb3620a 100644 --- a/yarn-project/foundation/src/abi/function_selector.ts +++ b/yarn-project/foundation/src/abi/function_selector.ts @@ -29,10 +29,11 @@ export class FunctionSelector { /** * Serialize as a buffer. + * @param bufferSize - The buffer size. * @returns The buffer. */ - toBuffer(): Buffer { - return toBufferBE(BigInt(this.value), FunctionSelector.SIZE); + toBuffer(bufferSize = FunctionSelector.SIZE): Buffer { + return toBufferBE(BigInt(this.value), bufferSize); } /** diff --git a/yarn-project/foundation/src/crypto/pedersen/index.ts b/yarn-project/foundation/src/crypto/pedersen/index.ts index c85dafd4ca47..033c8f43d192 100644 --- a/yarn-project/foundation/src/crypto/pedersen/index.ts +++ b/yarn-project/foundation/src/crypto/pedersen/index.ts @@ -1 +1 @@ -export * from './pedersen.wasm.js'; +export * from './pedersen.elliptic.js'; diff --git a/yarn-project/foundation/src/crypto/pedersen/pedersen.elliptic.ts b/yarn-project/foundation/src/crypto/pedersen/pedersen.elliptic.ts index 8f36453bbad5..7aad5c7c7bdb 100644 --- a/yarn-project/foundation/src/crypto/pedersen/pedersen.elliptic.ts +++ b/yarn-project/foundation/src/crypto/pedersen/pedersen.elliptic.ts @@ -1,3 +1,10 @@ +/** + * This is about 10x slower than WASM pedersen. + * But note that if run within jest it's like, 100x slower. + * I banged my head against a wall for a weekend trying to understand why, profiling and everything. + * Ultimately I discovered that using jest-runner-light resolved that, and still it's a mystery to me. + * Given it's 10x slower anyway, this might be fine for small hash calculations, but not for merkle trees. + */ import BN from 'bn.js'; // eslint-disable-next-line import EC from 'elliptic'; @@ -562,6 +569,9 @@ export function pedersenCommit(input: Buffer[], generatorOffset = 0) { * Create a pedersen hash (field) from an array of input fields. */ export function pedersenHash(input: Buffer[], index = 0) { + if (!input.every(i => i.length === 32)) { + throw new Error('All input buffers must be <= 32 bytes.'); + } const result = lengthGenerator.mul(new BN(input.length)); return result.add(pedersenCommitInternal(input, index)).getX().toBuffer(); } diff --git a/yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts b/yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts index de880b7f0e75..aacf2b81eae1 100644 --- a/yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts +++ b/yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts @@ -4,21 +4,25 @@ const pedersen = await Pedersen.new(); /** * Create a pedersen commitment (point) from an array of input fields. + * Left pads any inputs less than 32 bytes. */ export function pedersenCommit(input: Buffer[], generatorOffset = 0) { - if (!pedersen) { - throw new Error('Need to call await pedersenInit() first.'); + if (!input.every(i => i.length <= 32)) { + throw new Error('All input buffers must be <= 32 bytes.'); } + input = input.map(i => (i.length < 32 ? Buffer.concat([Buffer.alloc(32 - i.length, 0), i]) : i)); const [x, y] = pedersen.pedersenCommit(input, generatorOffset); return [Buffer.from(x), Buffer.from(y)]; } /** * Create a pedersen hash (field) from an array of input fields. + * Left pads any inputs less than 32 bytes. */ export function pedersenHash(input: Buffer[], index = 0) { - if (!pedersen) { - throw new Error('Need to call await pedersenInit() first.'); + if (!input.every(i => i.length === 32)) { + throw new Error('All input buffers must be <= 32 bytes.'); } + input = input.map(i => (i.length < 32 ? Buffer.concat([Buffer.alloc(32 - i.length, 0), i]) : i)); return Buffer.from(pedersen.pedersenHash(input, index)); } From a35beffe15394a796d516e4271d92ee52a3d4a50 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Wed, 1 Nov 2023 20:42:11 +0000 Subject: [PATCH 09/29] Fix --- .../cpp/src/barretenberg/barretenberg.hpp | 1 + .../common/{mem.cpp => bbmalloc.cpp} | 3 +- .../cpp/src/barretenberg/common/bbmalloc.hpp | 7 + barretenberg/ts/src/barretenberg_api/index.ts | 138 +++++++++++++++--- 4 files changed, 125 insertions(+), 24 deletions(-) rename barretenberg/cpp/src/barretenberg/common/{mem.cpp => bbmalloc.cpp} (80%) create mode 100644 barretenberg/cpp/src/barretenberg/common/bbmalloc.hpp diff --git a/barretenberg/cpp/src/barretenberg/barretenberg.hpp b/barretenberg/cpp/src/barretenberg/barretenberg.hpp index 24c79da90c01..9e13d09e2a7b 100644 --- a/barretenberg/cpp/src/barretenberg/barretenberg.hpp +++ b/barretenberg/cpp/src/barretenberg/barretenberg.hpp @@ -1,6 +1,7 @@ #pragma once // External Barretenberg C++ API +#include "common/bbmalloc.hpp" #include "common/container.hpp" #include "common/map.hpp" #include "common/mem.hpp" diff --git a/barretenberg/cpp/src/barretenberg/common/mem.cpp b/barretenberg/cpp/src/barretenberg/common/bbmalloc.cpp similarity index 80% rename from barretenberg/cpp/src/barretenberg/common/mem.cpp rename to barretenberg/cpp/src/barretenberg/common/bbmalloc.cpp index d119eaf24a43..d9c061acb12b 100644 --- a/barretenberg/cpp/src/barretenberg/common/mem.cpp +++ b/barretenberg/cpp/src/barretenberg/common/bbmalloc.cpp @@ -1,6 +1,5 @@ -#include "./mem.hpp" +#include "./bbmalloc.hpp" #include "./slab_allocator.hpp" -#include "./wasm_export.hpp" WASM_EXPORT void* bbmalloc(size_t size) { diff --git a/barretenberg/cpp/src/barretenberg/common/bbmalloc.hpp b/barretenberg/cpp/src/barretenberg/common/bbmalloc.hpp new file mode 100644 index 000000000000..6a53df3756ee --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/common/bbmalloc.hpp @@ -0,0 +1,7 @@ +#pragma once +#include "./wasm_export.hpp" +#include + +WASM_EXPORT void* bbmalloc(size_t size); + +WASM_EXPORT void bbfree(void* ptr); diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index fb4669c8159a..eab96a1f9742 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -1,7 +1,13 @@ // WARNING: FILE CODE GENERATED BY BINDGEN UTILITY. DO NOT EDIT! /* eslint-disable @typescript-eslint/no-unused-vars */ import { BarretenbergBinder } from '../barretenberg_binder/index.js'; -import { BufferDeserializer, NumberDeserializer, VectorDeserializer, BoolDeserializer, StringDeserializer } from '../serialize/index.js'; +import { + BufferDeserializer, + NumberDeserializer, + VectorDeserializer, + BoolDeserializer, + StringDeserializer, +} from '../serialize/index.js'; import { Fr, Fq, Point, Buffer32, Buffer128, Ptr } from '../types/index.js'; export class BarretenbergApi { @@ -42,37 +48,76 @@ export class BarretenbergApi { } async schnorrConstructSignature(message: Uint8Array, privateKey: Fr): Promise<[Buffer32, Buffer32]> { - const result = await this.binder.callWasmExport('schnorr_construct_signature', [message, privateKey], [Buffer32, Buffer32]); + const result = await this.binder.callWasmExport( + 'schnorr_construct_signature', + [message, privateKey], + [Buffer32, Buffer32], + ); return result as any; } async schnorrVerifySignature(message: Uint8Array, pubKey: Point, sigS: Buffer32, sigE: Buffer32): Promise { - const result = await this.binder.callWasmExport('schnorr_verify_signature', [message, pubKey, sigS, sigE], [BoolDeserializer()]); + const result = await this.binder.callWasmExport( + 'schnorr_verify_signature', + [message, pubKey, sigS, sigE], + [BoolDeserializer()], + ); return result[0]; } async schnorrMultisigCreateMultisigPublicKey(privateKey: Fr): Promise { - const result = await this.binder.callWasmExport('schnorr_multisig_create_multisig_public_key', [privateKey], [Buffer128]); + const result = await this.binder.callWasmExport( + 'schnorr_multisig_create_multisig_public_key', + [privateKey], + [Buffer128], + ); return result[0]; } async schnorrMultisigValidateAndCombineSignerPubkeys(signerPubkeyBuf: Buffer128[]): Promise<[Point, boolean]> { - const result = await this.binder.callWasmExport('schnorr_multisig_validate_and_combine_signer_pubkeys', [signerPubkeyBuf], [Point, BoolDeserializer()]); + const result = await this.binder.callWasmExport( + 'schnorr_multisig_validate_and_combine_signer_pubkeys', + [signerPubkeyBuf], + [Point, BoolDeserializer()], + ); return result as any; } async schnorrMultisigConstructSignatureRound1(): Promise<[Buffer128, Buffer128]> { - const result = await this.binder.callWasmExport('schnorr_multisig_construct_signature_round_1', [], [Buffer128, Buffer128]); + const result = await this.binder.callWasmExport( + 'schnorr_multisig_construct_signature_round_1', + [], + [Buffer128, Buffer128], + ); return result as any; } - async schnorrMultisigConstructSignatureRound2(message: Uint8Array, privateKey: Fr, signerRoundOnePrivateBuf: Buffer128, signerPubkeysBuf: Buffer128[], roundOnePublicBuf: Buffer128[]): Promise<[Fr, boolean]> { - const result = await this.binder.callWasmExport('schnorr_multisig_construct_signature_round_2', [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf], [Fr, BoolDeserializer()]); + async schnorrMultisigConstructSignatureRound2( + message: Uint8Array, + privateKey: Fr, + signerRoundOnePrivateBuf: Buffer128, + signerPubkeysBuf: Buffer128[], + roundOnePublicBuf: Buffer128[], + ): Promise<[Fr, boolean]> { + const result = await this.binder.callWasmExport( + 'schnorr_multisig_construct_signature_round_2', + [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf], + [Fr, BoolDeserializer()], + ); return result as any; } - async schnorrMultisigCombineSignatures(message: Uint8Array, signerPubkeysBuf: Buffer128[], roundOneBuf: Buffer128[], roundTwoBuf: Fr[]): Promise<[Buffer32, Buffer32, boolean]> { - const result = await this.binder.callWasmExport('schnorr_multisig_combine_signatures', [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf], [Buffer32, Buffer32, BoolDeserializer()]); + async schnorrMultisigCombineSignatures( + message: Uint8Array, + signerPubkeysBuf: Buffer128[], + roundOneBuf: Buffer128[], + roundTwoBuf: Fr[], + ): Promise<[Buffer32, Buffer32, boolean]> { + const result = await this.binder.callWasmExport( + 'schnorr_multisig_combine_signatures', + [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf], + [Buffer32, Buffer32, BoolDeserializer()], + ); return result as any; } @@ -82,7 +127,11 @@ export class BarretenbergApi { } async examplesSimpleCreateAndVerifyProof(): Promise { - const result = await this.binder.callWasmExport('examples_simple_create_and_verify_proof', [], [BoolDeserializer()]); + const result = await this.binder.callWasmExport( + 'examples_simple_create_and_verify_proof', + [], + [BoolDeserializer()], + ); return result[0]; } @@ -97,7 +146,11 @@ export class BarretenbergApi { } async acirGetCircuitSizes(constraintSystemBuf: Uint8Array): Promise<[number, number, number]> { - const result = await this.binder.callWasmExport('acir_get_circuit_sizes', [constraintSystemBuf], [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()]); + const result = await this.binder.callWasmExport( + 'acir_get_circuit_sizes', + [constraintSystemBuf], + [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()], + ); return result as any; } @@ -112,17 +165,34 @@ export class BarretenbergApi { } async acirCreateCircuit(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, sizeHint: number): Promise { - const result = await this.binder.callWasmExport('acir_create_circuit', [acirComposerPtr, constraintSystemBuf, sizeHint], []); + const result = await this.binder.callWasmExport( + 'acir_create_circuit', + [acirComposerPtr, constraintSystemBuf, sizeHint], + [], + ); return; } async acirInitProvingKey(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array): Promise { - const result = await this.binder.callWasmExport('acir_init_proving_key', [acirComposerPtr, constraintSystemBuf], []); + const result = await this.binder.callWasmExport( + 'acir_init_proving_key', + [acirComposerPtr, constraintSystemBuf], + [], + ); return; } - async acirCreateProof(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array, isRecursive: boolean): Promise { - const result = await this.binder.callWasmExport('acir_create_proof', [acirComposerPtr, constraintSystemBuf, witnessBuf, isRecursive], [BufferDeserializer()]); + async acirCreateProof( + acirComposerPtr: Ptr, + constraintSystemBuf: Uint8Array, + witnessBuf: Uint8Array, + isRecursive: boolean, + ): Promise { + const result = await this.binder.callWasmExport( + 'acir_create_proof', + [acirComposerPtr, constraintSystemBuf, witnessBuf, isRecursive], + [BufferDeserializer()], + ); return result[0]; } @@ -137,27 +207,51 @@ export class BarretenbergApi { } async acirGetVerificationKey(acirComposerPtr: Ptr): Promise { - const result = await this.binder.callWasmExport('acir_get_verification_key', [acirComposerPtr], [BufferDeserializer()]); + const result = await this.binder.callWasmExport( + 'acir_get_verification_key', + [acirComposerPtr], + [BufferDeserializer()], + ); return result[0]; } async acirVerifyProof(acirComposerPtr: Ptr, proofBuf: Uint8Array, isRecursive: boolean): Promise { - const result = await this.binder.callWasmExport('acir_verify_proof', [acirComposerPtr, proofBuf, isRecursive], [BoolDeserializer()]); + const result = await this.binder.callWasmExport( + 'acir_verify_proof', + [acirComposerPtr, proofBuf, isRecursive], + [BoolDeserializer()], + ); return result[0]; } async acirGetSolidityVerifier(acirComposerPtr: Ptr): Promise { - const result = await this.binder.callWasmExport('acir_get_solidity_verifier', [acirComposerPtr], [StringDeserializer()]); + const result = await this.binder.callWasmExport( + 'acir_get_solidity_verifier', + [acirComposerPtr], + [StringDeserializer()], + ); return result[0]; } - async acirSerializeProofIntoFields(acirComposerPtr: Ptr, proofBuf: Uint8Array, numInnerPublicInputs: number): Promise { - const result = await this.binder.callWasmExport('acir_serialize_proof_into_fields', [acirComposerPtr, proofBuf, numInnerPublicInputs], [VectorDeserializer(Fr)]); + async acirSerializeProofIntoFields( + acirComposerPtr: Ptr, + proofBuf: Uint8Array, + numInnerPublicInputs: number, + ): Promise { + const result = await this.binder.callWasmExport( + 'acir_serialize_proof_into_fields', + [acirComposerPtr, proofBuf, numInnerPublicInputs], + [VectorDeserializer(Fr)], + ); return result[0]; } async acirSerializeVerificationKeyIntoFields(acirComposerPtr: Ptr): Promise<[Fr[], Fr]> { - const result = await this.binder.callWasmExport('acir_serialize_verification_key_into_fields', [acirComposerPtr], [VectorDeserializer(Fr), Fr]); + const result = await this.binder.callWasmExport( + 'acir_serialize_verification_key_into_fields', + [acirComposerPtr], + [VectorDeserializer(Fr), Fr], + ); return result as any; } } From 6861c584ae008231574e2a3285b5084145124df3 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Thu, 2 Nov 2023 00:00:25 +0000 Subject: [PATCH 10/29] We have a serious circular dependency problem. --- .circleci/config.yml | 1 + barretenberg/ts/src/pedersen/pedersen.test.ts | 4 +- barretenberg/ts/src/types/fields.ts | 2 +- build_manifest.yml | 1 + .../src/client/client_execution_context.ts | 5 +- .../account/manager/deploy_account_sent_tx.ts | 3 +- .../aztec.js/src/contract/batch_call.ts | 4 +- .../aztec.js/src/contract/contract.ts | 3 +- .../src/contract_deployer/deploy_method.ts | 2 +- .../src/contract_deployer/deploy_sent_tx.ts | 9 +- yarn-project/aztec.js/src/wallet/index.ts | 4 +- yarn-project/foundation/package.json | 2 +- .../foundation/src/crypto/pedersen/index.ts | 2 +- .../src/crypto/pedersen/pedersen.elliptic.ts | 9 +- .../src/crypto/pedersen/pedersen.wasm.ts | 2 +- .../foundation/src/log/log_history.test.ts | 2 + .../foundation/src/mutex/mutex.test.ts | 2 + .../src/serialize/buffer_reader.test.ts | 2 + yarn-project/package.common.json | 1 - yarn-project/package.json | 1 + yarn-project/yarn-project-base/Dockerfile | 21 +- yarn-project/yarn.lock | 973 +++++++++++++++++- 22 files changed, 1011 insertions(+), 44 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 49097fff0e3b..7205038b7163 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1250,6 +1250,7 @@ workflows: requires: - circuits-wasm-linux-clang - l1-contracts + - bb-js <<: *defaults - yarn-project: requires: diff --git a/barretenberg/ts/src/pedersen/pedersen.test.ts b/barretenberg/ts/src/pedersen/pedersen.test.ts index 74c339830458..12721e3d630e 100644 --- a/barretenberg/ts/src/pedersen/pedersen.test.ts +++ b/barretenberg/ts/src/pedersen/pedersen.test.ts @@ -6,7 +6,9 @@ describe('pedersen sync', () => { it('pedersenHash', async () => { const pedersen = await Pedersen.new(); const result = pedersen.pedersenHash([new Fr(4n).toBuffer(), new Fr(8n).toBuffer()], 7); - expect(result).toEqual(new Fr(2152386650411553803409271316104075950536496387580531018130718456431861859990n)); + expect(result).toEqual( + new Fr(2152386650411553803409271316104075950536496387580531018130718456431861859990n).toBuffer(), + ); }); it('pedersenCommit', async () => { diff --git a/barretenberg/ts/src/types/fields.ts b/barretenberg/ts/src/types/fields.ts index 97502dafae3c..a54cbe5a3289 100644 --- a/barretenberg/ts/src/types/fields.ts +++ b/barretenberg/ts/src/types/fields.ts @@ -48,7 +48,7 @@ export class Fr { } equals(rhs: Fr) { - return this.value === rhs.value; + return this.value.every((v, i) => v === rhs.value[i]); } isZero() { diff --git a/build_manifest.yml b/build_manifest.yml index 8adee0e270ea..31b310e835e4 100644 --- a/build_manifest.yml +++ b/build_manifest.yml @@ -102,6 +102,7 @@ yarn-project-base: dependencies: - circuits-wasm-linux-clang - l1-contracts + - bb.js yarn-project: buildDir: yarn-project diff --git a/yarn-project/acir-simulator/src/client/client_execution_context.ts b/yarn-project/acir-simulator/src/client/client_execution_context.ts index d9588ef919d3..579771f109da 100644 --- a/yarn-project/acir-simulator/src/client/client_execution_context.ts +++ b/yarn-project/acir-simulator/src/client/client_execution_context.ts @@ -267,8 +267,9 @@ export class ClientExecutionContext extends ViewDataOracle { * @param innerNullifier - The pending nullifier to add in the list (not yet siloed by contract address). * @param innerNoteHash - The inner note hash of the new note. */ - public async notifyNullifiedNote(innerNullifier: Fr, innerNoteHash: Fr) { - await this.noteCache.nullifyNote(this.contractAddress, innerNullifier, innerNoteHash); + public notifyNullifiedNote(innerNullifier: Fr, innerNoteHash: Fr) { + this.noteCache.nullifyNote(this.contractAddress, innerNullifier, innerNoteHash); + return Promise.resolve(); } /** diff --git a/yarn-project/aztec.js/src/account/manager/deploy_account_sent_tx.ts b/yarn-project/aztec.js/src/account/manager/deploy_account_sent_tx.ts index c34051e894a3..3d2dab3ab20f 100644 --- a/yarn-project/aztec.js/src/account/manager/deploy_account_sent_tx.ts +++ b/yarn-project/aztec.js/src/account/manager/deploy_account_sent_tx.ts @@ -1,7 +1,8 @@ import { FieldsOf } from '@aztec/circuits.js'; import { TxHash, TxReceipt } from '@aztec/types'; -import { SentTx, WaitOpts, Wallet } from '../../index.js'; +import { SentTx, WaitOpts } from '../../contract/index.js'; +import { Wallet } from '../../wallet/index.js'; /** Extends a transaction receipt with a wallet instance for the newly deployed contract. */ export type DeployAccountTxReceipt = FieldsOf & { diff --git a/yarn-project/aztec.js/src/contract/batch_call.ts b/yarn-project/aztec.js/src/contract/batch_call.ts index 9b801ddec83a..0a848312cbfc 100644 --- a/yarn-project/aztec.js/src/contract/batch_call.ts +++ b/yarn-project/aztec.js/src/contract/batch_call.ts @@ -1,4 +1,6 @@ -import { FunctionCall, TxExecutionRequest, Wallet } from '../index.js'; +import { FunctionCall, TxExecutionRequest } from '@aztec/types'; + +import { Wallet } from '../wallet/index.js'; import { BaseContractInteraction } from './base_contract_interaction.js'; /** A batch of function calls to be sent as a single transaction through a wallet. */ diff --git a/yarn-project/aztec.js/src/contract/contract.ts b/yarn-project/aztec.js/src/contract/contract.ts index 47dc389c7eb2..5de21db3d777 100644 --- a/yarn-project/aztec.js/src/contract/contract.ts +++ b/yarn-project/aztec.js/src/contract/contract.ts @@ -1,8 +1,9 @@ import { ContractArtifact } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; +import { Point } from '@aztec/foundation/fields'; import { PublicKey } from '@aztec/types'; -import { DeployMethod, Point } from '../index.js'; +import { DeployMethod } from '../contract_deployer/deploy_method.js'; import { Wallet } from '../wallet/index.js'; import { ContractBase } from './contract_base.js'; diff --git a/yarn-project/aztec.js/src/contract_deployer/deploy_method.ts b/yarn-project/aztec.js/src/contract_deployer/deploy_method.ts index a97ae9fc6cb7..d2ad1a95416a 100644 --- a/yarn-project/aztec.js/src/contract_deployer/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract_deployer/deploy_method.ts @@ -93,7 +93,7 @@ export class DeployMethod extends Bas const args = encodeArguments(this.constructorArtifact, this.args); const functionData = FunctionData.fromAbi(this.constructorArtifact); const execution = { args, functionData, to: completeAddress.address }; - const packedArguments = await PackedArguments.fromArgs(execution.args); + const packedArguments = PackedArguments.fromArgs(execution.args); const txRequest = TxExecutionRequest.from({ origin: execution.to, diff --git a/yarn-project/aztec.js/src/contract_deployer/deploy_sent_tx.ts b/yarn-project/aztec.js/src/contract_deployer/deploy_sent_tx.ts index 93c16ad56a99..23a2e0bfb06c 100644 --- a/yarn-project/aztec.js/src/contract_deployer/deploy_sent_tx.ts +++ b/yarn-project/aztec.js/src/contract_deployer/deploy_sent_tx.ts @@ -1,8 +1,11 @@ -import { CompleteAddress, FieldsOf } from '@aztec/circuits.js'; +import { AztecAddress, CompleteAddress, FieldsOf } from '@aztec/circuits.js'; import { ContractArtifact } from '@aztec/foundation/abi'; -import { TxHash, TxReceipt } from '@aztec/types'; +import { PXE, TxHash, TxReceipt } from '@aztec/types'; -import { AztecAddress, Contract, ContractBase, PXE, SentTx, WaitOpts, Wallet } from '../index.js'; +import { Contract } from '../contract/contract.js'; +import { ContractBase } from '../contract/contract_base.js'; +import { SentTx, WaitOpts } from '../contract/sent_tx.js'; +import { Wallet } from '../wallet/index.js'; /** Options related to waiting for a deployment tx. */ export type DeployedWaitOpts = WaitOpts & { diff --git a/yarn-project/aztec.js/src/wallet/index.ts b/yarn-project/aztec.js/src/wallet/index.ts index fa43fcb1a97d..b0c01e656cdb 100644 --- a/yarn-project/aztec.js/src/wallet/index.ts +++ b/yarn-project/aztec.js/src/wallet/index.ts @@ -1,4 +1,6 @@ -import { AccountInterface, PXE } from '../index.js'; +import { PXE } from '@aztec/types'; + +import { AccountInterface } from '../account/index.js'; export * from './base_wallet.js'; export * from './account_wallet.js'; diff --git a/yarn-project/foundation/package.json b/yarn-project/foundation/package.json index 715db3fe353e..93b40e2247c8 100644 --- a/yarn-project/foundation/package.json +++ b/yarn-project/foundation/package.json @@ -42,7 +42,7 @@ "formatting": "run -T prettier --check ./src && run -T eslint ./src", "formatting:fix": "run -T prettier -w ./src", "test:light": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests", - "test": "NODE_NO_WARNINGS=1 NODE_OPTIONS='--loader ts-node/esm' node --experimental-vm-modules $(yarn bin jest) --runner=jest-light-runner --passWithNoTests" + "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests" }, "inherits": [ "../package.common.json" diff --git a/yarn-project/foundation/src/crypto/pedersen/index.ts b/yarn-project/foundation/src/crypto/pedersen/index.ts index 033c8f43d192..c85dafd4ca47 100644 --- a/yarn-project/foundation/src/crypto/pedersen/index.ts +++ b/yarn-project/foundation/src/crypto/pedersen/index.ts @@ -1 +1 @@ -export * from './pedersen.elliptic.js'; +export * from './pedersen.wasm.js'; diff --git a/yarn-project/foundation/src/crypto/pedersen/pedersen.elliptic.ts b/yarn-project/foundation/src/crypto/pedersen/pedersen.elliptic.ts index 7aad5c7c7bdb..0ff91b5abe62 100644 --- a/yarn-project/foundation/src/crypto/pedersen/pedersen.elliptic.ts +++ b/yarn-project/foundation/src/crypto/pedersen/pedersen.elliptic.ts @@ -559,19 +559,26 @@ function pedersenCommitInternal(input: Buffer[], generatorOffset = 0) { /** * Create a pedersen commitment (point) from an array of input fields. + * Left pads any inputs less than 32 bytes. */ export function pedersenCommit(input: Buffer[], generatorOffset = 0) { + if (!input.every(i => i.length <= 32)) { + throw new Error('All input buffers must be <= 32 bytes.'); + } + input = input.map(i => (i.length < 32 ? Buffer.concat([Buffer.alloc(32 - i.length, 0), i]) : i)); const result = pedersenCommitInternal(input, generatorOffset); return [result.getX().toBuffer(), result.getY().toBuffer()]; } /** * Create a pedersen hash (field) from an array of input fields. + * Left pads any inputs less than 32 bytes. */ export function pedersenHash(input: Buffer[], index = 0) { - if (!input.every(i => i.length === 32)) { + if (!input.every(i => i.length <= 32)) { throw new Error('All input buffers must be <= 32 bytes.'); } + input = input.map(i => (i.length < 32 ? Buffer.concat([Buffer.alloc(32 - i.length, 0), i]) : i)); const result = lengthGenerator.mul(new BN(input.length)); return result.add(pedersenCommitInternal(input, index)).getX().toBuffer(); } diff --git a/yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts b/yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts index aacf2b81eae1..f4688b8fcfe4 100644 --- a/yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts +++ b/yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts @@ -20,7 +20,7 @@ export function pedersenCommit(input: Buffer[], generatorOffset = 0) { * Left pads any inputs less than 32 bytes. */ export function pedersenHash(input: Buffer[], index = 0) { - if (!input.every(i => i.length === 32)) { + if (!input.every(i => i.length <= 32)) { throw new Error('All input buffers must be <= 32 bytes.'); } input = input.map(i => (i.length < 32 ? Buffer.concat([Buffer.alloc(32 - i.length, 0), i]) : i)); diff --git a/yarn-project/foundation/src/log/log_history.test.ts b/yarn-project/foundation/src/log/log_history.test.ts index 722c9a9fce9d..8049616d6c15 100644 --- a/yarn-project/foundation/src/log/log_history.test.ts +++ b/yarn-project/foundation/src/log/log_history.test.ts @@ -1,3 +1,5 @@ +import { jest } from '@jest/globals'; + import { createDebugOnlyLogger, enableLogs } from './debug.js'; import { LogHistory } from './log_history.js'; diff --git a/yarn-project/foundation/src/mutex/mutex.test.ts b/yarn-project/foundation/src/mutex/mutex.test.ts index 8b4e9860f7cb..0c2eb485d895 100644 --- a/yarn-project/foundation/src/mutex/mutex.test.ts +++ b/yarn-project/foundation/src/mutex/mutex.test.ts @@ -1,3 +1,5 @@ +import { jest } from '@jest/globals'; + import { Mutex } from './index.js'; import { MutexDatabase } from './mutex_database.js'; diff --git a/yarn-project/foundation/src/serialize/buffer_reader.test.ts b/yarn-project/foundation/src/serialize/buffer_reader.test.ts index 8da7fec98112..1bc92a95f662 100644 --- a/yarn-project/foundation/src/serialize/buffer_reader.test.ts +++ b/yarn-project/foundation/src/serialize/buffer_reader.test.ts @@ -1,3 +1,5 @@ +import { jest } from '@jest/globals'; + import { randomBytes } from '../crypto/index.js'; import { Fq, Fr } from '../fields/fields.js'; import { BufferReader } from './buffer_reader.js'; diff --git a/yarn-project/package.common.json b/yarn-project/package.common.json index 1a673ecbe7b5..7e200c5fb86d 100644 --- a/yarn-project/package.common.json +++ b/yarn-project/package.common.json @@ -5,7 +5,6 @@ "clean": "rm -rf ./dest .tsbuildinfo", "formatting": "run -T prettier --check ./src && run -T eslint ./src", "formatting:fix": "run -T prettier -w ./src", - "test:light": "NODE_NO_WARNINGS=1 NODE_OPTIONS='--loader ts-node/esm' node --experimental-vm-modules $(yarn bin jest) --runner=jest-light-runner --passWithNoTests", "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests" }, "engines": { diff --git a/yarn-project/package.json b/yarn-project/package.json index 33c83a466c57..3e85099f7184 100644 --- a/yarn-project/package.json +++ b/yarn-project/package.json @@ -56,6 +56,7 @@ "eslint": "^8.21.0", "eslint-import-resolver-typescript": "^3.5.5", "eslint-plugin-import": "^2.27.5", + "madge": "^6.1.0", "prettier": "^2.8.8", "typedoc": "^0.24.8", "typescript": "^5.0.4" diff --git a/yarn-project/yarn-project-base/Dockerfile b/yarn-project/yarn-project-base/Dockerfile index 4d92493bd06f..0ce208ab3d30 100644 --- a/yarn-project/yarn-project-base/Dockerfile +++ b/yarn-project/yarn-project-base/Dockerfile @@ -42,12 +42,21 @@ # FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/circuits-wasm-linux-clang as circuits FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/l1-contracts as contracts +FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/bb.js as bb.js FROM node:18-alpine RUN apk update && apk add --no-cache bash jq curl -WORKDIR /usr/src/yarn-project +# Bring in circuits wasms. +COPY --from=circuits /usr/src/circuits/cpp/build-wasm/bin /usr/src/circuits/cpp/build-wasm/bin +# Copy ignition download script. +COPY --from=circuits /usr/src/barretenberg/cpp/srs_db/download_ignition.sh /usr/src/barretenberg/cpp/srs_db/download_ignition.sh +# Copy L1 contracts. +COPY --from=contracts /usr/src/l1-contracts /usr/src/l1-contracts +# Copy in bb.js +COPY --from=bb.js /usr/src/barretenberg/ts /usr/src/barretenberg/ts +WORKDIR /usr/src/yarn-project # The dockerignore file ensures the context only contains package.json and tsconfig.json files. COPY . . @@ -67,13 +76,5 @@ RUN echo "enableNetwork: false" >> .yarnrc.yml # Check package.json inheritance and tsconfig project references. RUN yarn prepare:check -# Bring in circuits wasms. -COPY --from=circuits /usr/src/circuits/cpp/build-wasm/bin /usr/src/circuits/cpp/build-wasm/bin - -# Copy ignition download script. -COPY --from=circuits /usr/src/barretenberg/cpp/srs_db/download_ignition.sh /usr/src/barretenberg/cpp/srs_db/download_ignition.sh - -# Copy L1 contracts. -COPY --from=contracts /usr/src/l1-contracts /usr/src/l1-contracts # Generate L1 contract TypeScript artifacts. -RUN cd l1-artifacts && ./scripts/generate-artifacts.sh +RUN cd l1-artifacts && ./scripts/generate-artifacts.sh \ No newline at end of file diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 7d17f717bbbe..85977810f10c 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -280,6 +280,7 @@ __metadata: eslint: ^8.21.0 eslint-import-resolver-typescript: ^3.5.5 eslint-plugin-import: ^2.27.5 + madge: ^6.1.0 prettier: ^2.8.8 typedoc: ^0.24.8 typescript: ^5.0.4 @@ -1133,6 +1134,15 @@ __metadata: languageName: node linkType: hard +"@babel/parser@npm:^7.0.0, @babel/parser@npm:^7.21.4": + version: 7.23.0 + resolution: "@babel/parser@npm:7.23.0" + bin: + parser: ./bin/babel-parser.js + checksum: 453fdf8b9e2c2b7d7b02139e0ce003d1af21947bbc03eb350fb248ee335c9b85e4ab41697ddbdd97079698de825a265e45a0846bb2ed47a2c7c1df833f42a354 + languageName: node + linkType: hard + "@babel/parser@npm:^7.1.0, @babel/parser@npm:^7.14.7, @babel/parser@npm:^7.17.3, @babel/parser@npm:^7.20.5, @babel/parser@npm:^7.20.7, @babel/parser@npm:^7.22.5, @babel/parser@npm:^7.22.7": version: 7.22.7 resolution: "@babel/parser@npm:7.22.7" @@ -1503,6 +1513,16 @@ __metadata: languageName: node linkType: hard +"@dependents/detective-less@npm:^3.0.1": + version: 3.0.2 + resolution: "@dependents/detective-less@npm:3.0.2" + dependencies: + gonzales-pe: ^4.3.0 + node-source-walk: ^5.0.1 + checksum: 2c263ab64fcd1f76117bc35f2b29a150c64bd2b105c96a909a63ce2f2baf07efd93d9ae80e612161d003fb71fbe46598292375f5cc3f447a1b83cfb545dc8f8f + languageName: node + linkType: hard + "@discoveryjs/json-ext@npm:^0.5.0": version: 0.5.7 resolution: "@discoveryjs/json-ext@npm:0.5.7" @@ -5490,6 +5510,20 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/types@npm:4.33.0": + version: 4.33.0 + resolution: "@typescript-eslint/types@npm:4.33.0" + checksum: 3baae1ca35872421b4eb60f5d3f3f32dc1d513f2ae0a67dee28c7d159fd7a43ed0d11a8a5a0f0c2d38507ffa036fc7c511cb0f18a5e8ac524b3ebde77390ec53 + languageName: node + linkType: hard + +"@typescript-eslint/types@npm:5.62.0": + version: 5.62.0 + resolution: "@typescript-eslint/types@npm:5.62.0" + checksum: 48c87117383d1864766486f24de34086155532b070f6264e09d0e6139449270f8a9559cfef3c56d16e3bcfb52d83d42105d61b36743626399c7c2b5e0ac3b670 + languageName: node + linkType: hard + "@typescript-eslint/types@npm:6.2.1": version: 6.2.1 resolution: "@typescript-eslint/types@npm:6.2.1" @@ -5540,6 +5574,42 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/typescript-estree@npm:^4.33.0": + version: 4.33.0 + resolution: "@typescript-eslint/typescript-estree@npm:4.33.0" + dependencies: + "@typescript-eslint/types": 4.33.0 + "@typescript-eslint/visitor-keys": 4.33.0 + debug: ^4.3.1 + globby: ^11.0.3 + is-glob: ^4.0.1 + semver: ^7.3.5 + tsutils: ^3.21.0 + peerDependenciesMeta: + typescript: + optional: true + checksum: 2566984390c76bd95f43240057215c068c69769e406e27aba41e9f21fd300074d6772e4983fa58fe61e80eb5550af1548d2e31e80550d92ba1d051bb00fe6f5c + languageName: node + linkType: hard + +"@typescript-eslint/typescript-estree@npm:^5.55.0": + version: 5.62.0 + resolution: "@typescript-eslint/typescript-estree@npm:5.62.0" + dependencies: + "@typescript-eslint/types": 5.62.0 + "@typescript-eslint/visitor-keys": 5.62.0 + debug: ^4.3.4 + globby: ^11.1.0 + is-glob: ^4.0.3 + semver: ^7.3.7 + tsutils: ^3.21.0 + peerDependenciesMeta: + typescript: + optional: true + checksum: 3624520abb5807ed8f57b1197e61c7b1ed770c56dfcaca66372d584ff50175225798bccb701f7ef129d62c5989070e1ee3a0aa2d84e56d9524dcf011a2bb1a52 + languageName: node + linkType: hard + "@typescript-eslint/utils@npm:6.2.1": version: 6.2.1 resolution: "@typescript-eslint/utils@npm:6.2.1" @@ -5574,6 +5644,26 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/visitor-keys@npm:4.33.0": + version: 4.33.0 + resolution: "@typescript-eslint/visitor-keys@npm:4.33.0" + dependencies: + "@typescript-eslint/types": 4.33.0 + eslint-visitor-keys: ^2.0.0 + checksum: 59953e474ad4610c1aa23b2b1a964445e2c6201521da6367752f37939d854352bbfced5c04ea539274065e012b1337ba3ffa49c2647a240a4e87155378ba9873 + languageName: node + linkType: hard + +"@typescript-eslint/visitor-keys@npm:5.62.0": + version: 5.62.0 + resolution: "@typescript-eslint/visitor-keys@npm:5.62.0" + dependencies: + "@typescript-eslint/types": 5.62.0 + eslint-visitor-keys: ^3.3.0 + checksum: 976b05d103fe8335bef5c93ad3f76d781e3ce50329c0243ee0f00c0fcfb186c81df50e64bfdd34970148113f8ade90887f53e3c4938183afba830b4ba8e30a35 + languageName: node + linkType: hard + "@typescript-eslint/visitor-keys@npm:6.2.1": version: 6.2.1 resolution: "@typescript-eslint/visitor-keys@npm:6.2.1" @@ -6789,6 +6879,13 @@ __metadata: languageName: node linkType: hard +"any-promise@npm:^1.1.0": + version: 1.3.0 + resolution: "any-promise@npm:1.3.0" + checksum: 0ee8a9bdbe882c90464d75d1f55cf027f5458650c4bd1f0467e65aec38ccccda07ca5844969ee77ed46d04e7dded3eaceb027e8d32f385688523fe305fa7e1de + languageName: node + linkType: hard + "any-signal@npm:^4.1.1": version: 4.1.1 resolution: "any-signal@npm:4.1.1" @@ -6806,6 +6903,13 @@ __metadata: languageName: node linkType: hard +"app-module-path@npm:^2.2.0": + version: 2.2.0 + resolution: "app-module-path@npm:2.2.0" + checksum: b52aa49cfa809efbad41b514222e8ef3f8ee9e147f5eccf79280b45eddcc61f7aeb302b0049474e3f42072dd53a28348c57dd96f36cd461d2e31cc8ab1ef56b5 + languageName: node + linkType: hard + "aproba@npm:^1.0.3 || ^2.0.0": version: 2.0.0 resolution: "aproba@npm:2.0.0" @@ -6988,6 +7092,27 @@ __metadata: languageName: node linkType: hard +"ast-module-types@npm:^2.7.1": + version: 2.7.1 + resolution: "ast-module-types@npm:2.7.1" + checksum: 6238647bcf34eeff2a1390cb60388da8a5064dd598acf48d68f8d972d9a332dc8d0382a5a7c511b16470e314b313bcbb95de4b0b669515393e043282c0489538 + languageName: node + linkType: hard + +"ast-module-types@npm:^3.0.0": + version: 3.0.0 + resolution: "ast-module-types@npm:3.0.0" + checksum: c6ef35d9b286f84c7942aeb0e2b50e389e0b6f44ee3b6d2c46aeed4852dbca0681dde8c3c0ec1d456dad5dbc84fced2e1c607b10b4b4c3b065b901b40f45bbe7 + languageName: node + linkType: hard + +"ast-module-types@npm:^4.0.0": + version: 4.0.0 + resolution: "ast-module-types@npm:4.0.0" + checksum: 12705ff906e57d1440a2ff82f30cf5b3c93e1734076ea5868936477d5812a6fc257eb1e44fb2b7f8c22f7483987251d72251d2a295542f64df8768434f3f06db + languageName: node + linkType: hard + "ast-types@npm:^0.13.4": version: 0.13.4 resolution: "ast-types@npm:0.13.4" @@ -7286,6 +7411,17 @@ __metadata: languageName: node linkType: hard +"bl@npm:^4.1.0": + version: 4.1.0 + resolution: "bl@npm:4.1.0" + dependencies: + buffer: ^5.5.0 + inherits: ^2.0.4 + readable-stream: ^3.4.0 + checksum: 9e8521fa7e83aa9427c6f8ccdcba6e8167ef30cc9a22df26effcc5ab682ef91d2cbc23a239f945d099289e4bbcfae7a192e9c28c84c6202e710a0dfec3722662 + languageName: node + linkType: hard + "blank-contract-react@workspace:boxes/blank-react": version: 0.0.0-use.local resolution: "blank-contract-react@workspace:boxes/blank-react" @@ -7660,7 +7796,7 @@ __metadata: languageName: node linkType: hard -"buffer@npm:^5.2.1, buffer@npm:^5.4.3": +"buffer@npm:^5.2.1, buffer@npm:^5.4.3, buffer@npm:^5.5.0": version: 5.7.1 resolution: "buffer@npm:5.7.1" dependencies: @@ -8036,6 +8172,22 @@ __metadata: languageName: node linkType: hard +"cli-cursor@npm:^3.1.0": + version: 3.1.0 + resolution: "cli-cursor@npm:3.1.0" + dependencies: + restore-cursor: ^3.1.0 + checksum: 2692784c6cd2fd85cfdbd11f53aea73a463a6d64a77c3e098b2b4697a20443f430c220629e1ca3b195ea5ac4a97a74c2ee411f3807abf6df2b66211fec0c0a29 + languageName: node + linkType: hard + +"cli-spinners@npm:^2.5.0": + version: 2.9.1 + resolution: "cli-spinners@npm:2.9.1" + checksum: 1780618be58309c469205bc315db697934bac68bce78cd5dfd46248e507a533172d623c7348ecfd904734f597ce0a4e5538684843d2cfb7af485d4466699940c + languageName: node + linkType: hard + "clipboardy@npm:3.0.0": version: 3.0.0 resolution: "clipboardy@npm:3.0.0" @@ -8102,6 +8254,13 @@ __metadata: languageName: node linkType: hard +"clone@npm:^1.0.2": + version: 1.0.4 + resolution: "clone@npm:1.0.4" + checksum: d06418b7335897209e77bdd430d04f882189582e67bd1f75a04565f3f07f5b3f119a9d670c943b6697d0afb100f03b866b3b8a1f91d4d02d72c4ecf2bb64b5dd + languageName: node + linkType: hard + "clsx@npm:1.1.1": version: 1.1.1 resolution: "clsx@npm:1.1.1" @@ -8167,7 +8326,7 @@ __metadata: languageName: node linkType: hard -"color-name@npm:^1.0.0, color-name@npm:~1.1.4": +"color-name@npm:^1.0.0, color-name@npm:^1.1.4, color-name@npm:~1.1.4": version: 1.1.4 resolution: "color-name@npm:1.1.4" checksum: b0445859521eb4021cd0fb0cc1a75cecf67fceecae89b63f62b201cca8d345baf8b952c966862a9d9a2632987d4f6581f0ec8d957dfacece86f0a7919316f610 @@ -8243,14 +8402,21 @@ __metadata: languageName: node linkType: hard -"commander@npm:^2.20.0, commander@npm:^2.20.3": +"commander@npm:^2.16.0, commander@npm:^2.20.0, commander@npm:^2.20.3, commander@npm:^2.8.1": version: 2.20.3 resolution: "commander@npm:2.20.3" checksum: ab8c07884e42c3a8dbc5dd9592c606176c7eb5c1ca5ff274bcf907039b2c41de3626f684ea75ccf4d361ba004bbaff1f577d5384c155f3871e456bdf27becf9e languageName: node linkType: hard -"commander@npm:^9.0.0": +"commander@npm:^7.2.0": + version: 7.2.0 + resolution: "commander@npm:7.2.0" + checksum: 53501cbeee61d5157546c0bef0fedb6cdfc763a882136284bed9a07225f09a14b82d2a84e7637edfd1a679fb35ed9502fd58ef1d091e6287f60d790147f68ddc + languageName: node + linkType: hard + +"commander@npm:^9.0.0, commander@npm:^9.5.0": version: 9.5.0 resolution: "commander@npm:9.5.0" checksum: c7a3e27aa59e913b54a1bafd366b88650bc41d6651f0cbe258d4ff09d43d6a7394232a4dadd0bf518b3e696fdf595db1028a0d82c785b88bd61f8a440cecfade @@ -8276,6 +8442,13 @@ __metadata: languageName: node linkType: hard +"commondir@npm:^1.0.1": + version: 1.0.1 + resolution: "commondir@npm:1.0.1" + checksum: 59715f2fc456a73f68826285718503340b9f0dd89bfffc42749906c5cf3d4277ef11ef1cca0350d0e79204f00f1f6d83851ececc9095dc88512a697ac0b9bdcb + languageName: node + linkType: hard + "component-emitter@npm:^1.3.0": version: 1.3.0 resolution: "component-emitter@npm:1.3.0" @@ -8709,7 +8882,7 @@ __metadata: languageName: node linkType: hard -"debug@npm:4, debug@npm:4.3.4, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.3.1, debug@npm:^4.3.2, debug@npm:^4.3.3, debug@npm:^4.3.4": +"debug@npm:4, debug@npm:4.3.4, debug@npm:^4.0.0, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.3.1, debug@npm:^4.3.2, debug@npm:^4.3.3, debug@npm:^4.3.4": version: 4.3.4 resolution: "debug@npm:4.3.4" dependencies: @@ -8881,6 +9054,15 @@ __metadata: languageName: node linkType: hard +"defaults@npm:^1.0.3": + version: 1.0.4 + resolution: "defaults@npm:1.0.4" + dependencies: + clone: ^1.0.2 + checksum: 3a88b7a587fc076b84e60affad8b85245c01f60f38fc1d259e7ac1d89eb9ce6abb19e27215de46b98568dd5bc48471730b327637e6f20b0f1bc85cf00440c80a + languageName: node + linkType: hard + "deferred-leveldown@npm:^7.0.0": version: 7.0.0 resolution: "deferred-leveldown@npm:7.0.0" @@ -8968,6 +9150,21 @@ __metadata: languageName: node linkType: hard +"dependency-tree@npm:^9.0.0": + version: 9.0.0 + resolution: "dependency-tree@npm:9.0.0" + dependencies: + commander: ^2.20.3 + debug: ^4.3.1 + filing-cabinet: ^3.0.1 + precinct: ^9.0.0 + typescript: ^4.0.0 + bin: + dependency-tree: bin/cli.js + checksum: 38f95ec248f350f3ed443e0aac520c8ad979b3801262a1e67f6a5972c14f972887150d88972fb9e2630cef8c75efcd82719f93a55f9fc3207e64174ab9d3b0f3 + languageName: node + linkType: hard + "des.js@npm:^1.0.0": version: 1.1.0 resolution: "des.js@npm:1.1.0" @@ -9020,6 +9217,191 @@ __metadata: languageName: node linkType: hard +"detective-amd@npm:^3.1.0": + version: 3.1.2 + resolution: "detective-amd@npm:3.1.2" + dependencies: + ast-module-types: ^3.0.0 + escodegen: ^2.0.0 + get-amd-module-type: ^3.0.0 + node-source-walk: ^4.2.0 + bin: + detective-amd: bin/cli.js + checksum: 0b71555edad8e85c9a2ae85e2799d5faf2bdfe0de969587c9288ca76e717494678e34f444dffe32ffdd432e85ce50ca7017a5d0441a4855677a45a40c4590c74 + languageName: node + linkType: hard + +"detective-amd@npm:^4.0.1, detective-amd@npm:^4.1.0": + version: 4.2.0 + resolution: "detective-amd@npm:4.2.0" + dependencies: + ast-module-types: ^4.0.0 + escodegen: ^2.0.0 + get-amd-module-type: ^4.1.0 + node-source-walk: ^5.0.1 + bin: + detective-amd: bin/cli.js + checksum: c1e829a3202045796105680c9fe90ac61f63b0ccecc12cc30c7204c9e7ec22a4e2c3e2357719b9346a4e3579eba778cdce9a050e642938e2a4c8b57b091278e4 + languageName: node + linkType: hard + +"detective-cjs@npm:^3.1.1": + version: 3.1.3 + resolution: "detective-cjs@npm:3.1.3" + dependencies: + ast-module-types: ^3.0.0 + node-source-walk: ^4.0.0 + checksum: a691cb4afbbfea59d9aae0ee00752ec1a825a7ef18fc9178b53664975f162f3b537268590def009d9ce1cccfc5bc4f38cf775df08d0872aaacc05d96c72de85a + languageName: node + linkType: hard + +"detective-cjs@npm:^4.0.0, detective-cjs@npm:^4.1.0": + version: 4.1.0 + resolution: "detective-cjs@npm:4.1.0" + dependencies: + ast-module-types: ^4.0.0 + node-source-walk: ^5.0.1 + checksum: 17e40183959e9f377333a9fd03dcf4cbabf1b7a9f588882311066ecaaad68ad16765a7b63ffc096fc91d2a3c14ac044ed1823257c76105c9cb96dfc141a806e2 + languageName: node + linkType: hard + +"detective-es6@npm:^2.2.1": + version: 2.2.2 + resolution: "detective-es6@npm:2.2.2" + dependencies: + node-source-walk: ^4.0.0 + checksum: 9ee9909c089f5dcd1f89eccd347d509197996280ba24e2e08742bbc5ca3eef655ff07b4edfd76b52d6b4376ba03b8ec17d621c9f9c4382a6ba233dc1b1d00d33 + languageName: node + linkType: hard + +"detective-es6@npm:^3.0.0, detective-es6@npm:^3.0.1": + version: 3.0.1 + resolution: "detective-es6@npm:3.0.1" + dependencies: + node-source-walk: ^5.0.0 + checksum: 881a0c16b49504c212e61a521231ebbb4299a6102b178230959c74d2ca22d5f7538dfaf9518d01fb568ff93eadcf61d865d4428c9fed893dd4c91a7f29d515c5 + languageName: node + linkType: hard + +"detective-less@npm:^1.0.2": + version: 1.0.2 + resolution: "detective-less@npm:1.0.2" + dependencies: + debug: ^4.0.0 + gonzales-pe: ^4.2.3 + node-source-walk: ^4.0.0 + checksum: 858936fbad87423bd5d7502ff5fafca023e7c99e4006ed01b31c12c4b5ff8697edce91419798479d857efec68ee8f022fcac64de5530db6a64012be600a2249e + languageName: node + linkType: hard + +"detective-postcss@npm:^4.0.0": + version: 4.0.0 + resolution: "detective-postcss@npm:4.0.0" + dependencies: + debug: ^4.1.1 + is-url: ^1.2.4 + postcss: ^8.1.7 + postcss-values-parser: ^2.0.1 + checksum: e4c9fed31613df43466357fb104c4c5cdaf45a12909f7c1174161a45ebb2ebe77bb0843b3c0c117b68f55c9acb4e0578668298594c7f0108dfb73e54aaec8513 + languageName: node + linkType: hard + +"detective-postcss@npm:^6.1.0, detective-postcss@npm:^6.1.1": + version: 6.1.3 + resolution: "detective-postcss@npm:6.1.3" + dependencies: + is-url: ^1.2.4 + postcss: ^8.4.23 + postcss-values-parser: ^6.0.2 + checksum: 54c58227d5a1ec27e1b2b23bd992d823d0161d80e3d8ff6b202094e9841d53e88ac96a4d4cc9762ba4f09a9e038832b5d7c7a45b5e373c1c995c424a8289857b + languageName: node + linkType: hard + +"detective-sass@npm:^3.0.1": + version: 3.0.2 + resolution: "detective-sass@npm:3.0.2" + dependencies: + gonzales-pe: ^4.3.0 + node-source-walk: ^4.0.0 + checksum: 7489e5ae7dbed2eba89855cea21ad32321e8e92bd9f2d3b925e7feec0dd9aa8b4b865296525275938e573a3be9759715490038103cbc970570a1c48c4f2fd23d + languageName: node + linkType: hard + +"detective-sass@npm:^4.0.1, detective-sass@npm:^4.1.1": + version: 4.1.3 + resolution: "detective-sass@npm:4.1.3" + dependencies: + gonzales-pe: ^4.3.0 + node-source-walk: ^5.0.1 + checksum: 91681e90037cc935f38b2867fab2aa5585848491b3a269dfb44b37721146ff83f57a540d964b15db22dc1f232623568bedfd13470ec7363e6111991d4d3fe573 + languageName: node + linkType: hard + +"detective-scss@npm:^2.0.1": + version: 2.0.2 + resolution: "detective-scss@npm:2.0.2" + dependencies: + gonzales-pe: ^4.3.0 + node-source-walk: ^4.0.0 + checksum: 515ff1b8946ec92baead48ef435efe1ea0f33ee1d98a7537dd700f1d06dd192f9ea0971c10343adcb08b561ab296d01c18a1f62d0b63163a8f4c09885a956e1a + languageName: node + linkType: hard + +"detective-scss@npm:^3.0.0, detective-scss@npm:^3.0.1": + version: 3.1.1 + resolution: "detective-scss@npm:3.1.1" + dependencies: + gonzales-pe: ^4.3.0 + node-source-walk: ^5.0.1 + checksum: 3d9c0468216c822c25572e700b9aba1e2e2797d336b6b84fd455d83ce849263324855008d1e58d6ccdf9c7a4f099e31277b99e885407cd19674e0bb10fc458cd + languageName: node + linkType: hard + +"detective-stylus@npm:^1.0.0": + version: 1.0.3 + resolution: "detective-stylus@npm:1.0.3" + checksum: 2723da93545f3a55a2a7eaa76b50712457af3c93c2b003e95d02f4c240d5e5206a5df99209a4f5b54128c11fc4270c2de1d7316b4f7d02b359483ae74f5a6637 + languageName: node + linkType: hard + +"detective-stylus@npm:^2.0.1": + version: 2.0.1 + resolution: "detective-stylus@npm:2.0.1" + checksum: c701ba6df3e6b5346aa5dd37b8329a9069a20fd7d075933e2e3b819a75922a2adab809143591151e7337183d59c980e6bc64ad6e51ce96de864575221c1b9506 + languageName: node + linkType: hard + +"detective-stylus@npm:^3.0.0": + version: 3.0.0 + resolution: "detective-stylus@npm:3.0.0" + checksum: e82eda490406d289f7b22050423ad69eb1c0f0d88414adaa292de4ab533be3c50d4cf512a9fefba426f3ad20789f0c0db3b0d32f70162112ca89034bbc5ca9d3 + languageName: node + linkType: hard + +"detective-typescript@npm:^7.0.0": + version: 7.0.2 + resolution: "detective-typescript@npm:7.0.2" + dependencies: + "@typescript-eslint/typescript-estree": ^4.33.0 + ast-module-types: ^2.7.1 + node-source-walk: ^4.2.0 + typescript: ^3.9.10 + checksum: 77703410baa242029dc5e7d02cca7a26278dea498ec1c3320f92efa08a85263affc3b102fc2b09952ece1d2c851a3808733d7bfa9ed11944a7c0f39920e33ec9 + languageName: node + linkType: hard + +"detective-typescript@npm:^9.0.0, detective-typescript@npm:^9.1.1": + version: 9.1.1 + resolution: "detective-typescript@npm:9.1.1" + dependencies: + "@typescript-eslint/typescript-estree": ^5.55.0 + ast-module-types: ^4.0.0 + node-source-walk: ^5.0.1 + typescript: ^4.9.5 + checksum: 5f50801f622740d4e9d724ce04518ceb81591215bf18c18c5d22f6f3948df49dfb0a8bbe3596dac47220a37028bc2879ccd7a968f265217c9855817bda4622f5 + languageName: node + linkType: hard + "devtools-protocol@npm:0.0.1179426": version: 0.0.1179426 resolution: "devtools-protocol@npm:0.0.1179426" @@ -9276,7 +9658,7 @@ __metadata: languageName: node linkType: hard -"enhanced-resolve@npm:^5.0.0, enhanced-resolve@npm:^5.12.0, enhanced-resolve@npm:^5.15.0": +"enhanced-resolve@npm:^5.0.0, enhanced-resolve@npm:^5.12.0, enhanced-resolve@npm:^5.15.0, enhanced-resolve@npm:^5.8.3": version: 5.15.0 resolution: "enhanced-resolve@npm:5.15.0" dependencies: @@ -9555,7 +9937,7 @@ __metadata: languageName: node linkType: hard -"escodegen@npm:^2.1.0": +"escodegen@npm:^2.0.0, escodegen@npm:^2.1.0": version: 2.1.0 resolution: "escodegen@npm:2.1.0" dependencies: @@ -9726,6 +10108,13 @@ __metadata: languageName: node linkType: hard +"eslint-visitor-keys@npm:^2.0.0": + version: 2.1.0 + resolution: "eslint-visitor-keys@npm:2.1.0" + checksum: e3081d7dd2611a35f0388bbdc2f5da60b3a3c5b8b6e928daffff7391146b434d691577aa95064c8b7faad0b8a680266bcda0a42439c18c717b80e6718d7e267d + languageName: node + linkType: hard + "eslint-visitor-keys@npm:^3.3.0, eslint-visitor-keys@npm:^3.4.1, eslint-visitor-keys@npm:^3.4.2": version: 3.4.2 resolution: "eslint-visitor-keys@npm:3.4.2" @@ -10306,6 +10695,29 @@ __metadata: languageName: node linkType: hard +"filing-cabinet@npm:^3.0.1": + version: 3.3.1 + resolution: "filing-cabinet@npm:3.3.1" + dependencies: + app-module-path: ^2.2.0 + commander: ^2.20.3 + debug: ^4.3.3 + enhanced-resolve: ^5.8.3 + is-relative-path: ^1.0.2 + module-definition: ^3.3.1 + module-lookup-amd: ^7.0.1 + resolve: ^1.21.0 + resolve-dependency-path: ^2.0.0 + sass-lookup: ^3.0.0 + stylus-lookup: ^3.0.1 + tsconfig-paths: ^3.10.1 + typescript: ^3.9.7 + bin: + filing-cabinet: bin/cli.js + checksum: f6511c2e93e236c0d882244b49936a2c8cb2fde47e0d1a0a93345ce171995c2734670c38ed1c0aceaee9ed4958fcce48bfbbb687efe4dedf04b6ea46b0a8c1c0 + languageName: node + linkType: hard + "fill-range@npm:^7.0.1": version: 7.0.1 resolution: "fill-range@npm:7.0.1" @@ -10392,6 +10804,13 @@ __metadata: languageName: node linkType: hard +"flatten@npm:^1.0.2": + version: 1.0.3 + resolution: "flatten@npm:1.0.3" + checksum: 5c57379816f1692aaa79fbc6390e0a0644e5e8442c5783ed57c6d315468eddbc53a659eaa03c9bb1e771b0f4a9bd8dd8a2620286bf21fd6538a7857321fdfb20 + languageName: node + linkType: hard + "fn.name@npm:1.x.x": version: 1.1.0 resolution: "fn.name@npm:1.1.0" @@ -10592,6 +11011,13 @@ __metadata: languageName: node linkType: hard +"function-bind@npm:^1.1.2": + version: 1.1.2 + resolution: "function-bind@npm:1.1.2" + checksum: 2b0ff4ce708d99715ad14a6d1f894e2a83242e4a52ccfcefaee5e40050562e5f6dafc1adbb4ce2d4ab47279a45dc736ab91ea5042d843c3c092820dfe032efb1 + languageName: node + linkType: hard + "function.prototype.name@npm:^1.1.5": version: 1.1.5 resolution: "function.prototype.name@npm:1.1.5" @@ -10650,6 +11076,26 @@ __metadata: languageName: node linkType: hard +"get-amd-module-type@npm:^3.0.0": + version: 3.0.2 + resolution: "get-amd-module-type@npm:3.0.2" + dependencies: + ast-module-types: ^3.0.0 + node-source-walk: ^4.2.2 + checksum: d16fac5037f63027992e6ebd2d642e6d4feef2f8fa71ff3da6aa76006e05b3dcd4aa6044b4c5966f13ba5d412fd7c1367d910df86b58f9c13f53cbb35d2e4b72 + languageName: node + linkType: hard + +"get-amd-module-type@npm:^4.1.0": + version: 4.1.0 + resolution: "get-amd-module-type@npm:4.1.0" + dependencies: + ast-module-types: ^4.0.0 + node-source-walk: ^5.0.1 + checksum: dd3f58e88efb6a2224bb38325fe21b1ab417ba105b7f90d49089141b0eb3c24aab1866a2e2bf370430bbfc7ef226fc0a2a5c657e161d1d42d8a243f44ebd4fbe + languageName: node + linkType: hard + "get-caller-file@npm:^2.0.1, get-caller-file@npm:^2.0.5": version: 2.0.5 resolution: "get-caller-file@npm:2.0.5" @@ -10697,6 +11143,13 @@ __metadata: languageName: node linkType: hard +"get-own-enumerable-property-symbols@npm:^3.0.0": + version: 3.0.2 + resolution: "get-own-enumerable-property-symbols@npm:3.0.2" + checksum: 8f0331f14159f939830884799f937343c8c0a2c330506094bc12cbee3665d88337fe97a4ea35c002cc2bdba0f5d9975ad7ec3abb925015cdf2a93e76d4759ede + languageName: node + linkType: hard + "get-package-type@npm:^0.1.0": version: 0.1.0 resolution: "get-package-type@npm:0.1.0" @@ -10827,7 +11280,7 @@ __metadata: languageName: node linkType: hard -"glob@npm:^7.0.0, glob@npm:^7.0.3, glob@npm:^7.1.3, glob@npm:^7.1.4": +"glob@npm:^7.0.0, glob@npm:^7.0.3, glob@npm:^7.1.3, glob@npm:^7.1.4, glob@npm:^7.1.6": version: 7.2.3 resolution: "glob@npm:7.2.3" dependencies: @@ -10893,7 +11346,7 @@ __metadata: languageName: node linkType: hard -"globby@npm:^11.0.1, globby@npm:^11.1.0": +"globby@npm:^11.0.1, globby@npm:^11.0.3, globby@npm:^11.1.0": version: 11.1.0 resolution: "globby@npm:11.1.0" dependencies: @@ -10931,6 +11384,17 @@ __metadata: languageName: node linkType: hard +"gonzales-pe@npm:^4.2.3, gonzales-pe@npm:^4.3.0": + version: 4.3.0 + resolution: "gonzales-pe@npm:4.3.0" + dependencies: + minimist: ^1.2.5 + bin: + gonzales: bin/gonzales.js + checksum: 49d60fc49ad35639e5d55923c1516d3ec2e4de5e6e5913ec3458a479b66623e54a060d568295349b0bb9f96ee970c473ff984d4b82a5cfeaf736c55f0d6dc3b7 + languageName: node + linkType: hard + "gopd@npm:^1.0.1": version: 1.0.1 resolution: "gopd@npm:1.0.1" @@ -11072,6 +11536,15 @@ __metadata: languageName: node linkType: hard +"hasown@npm:^2.0.0": + version: 2.0.0 + resolution: "hasown@npm:2.0.0" + dependencies: + function-bind: ^1.1.2 + checksum: 6151c75ca12554565098641c98a40f4cc86b85b0fd5b6fe92360967e4605a4f9610f7757260b4e8098dd1c2ce7f4b095f2006fe72a570e3b6d2d28de0298c176 + languageName: node + linkType: hard + "hdr-histogram-js@npm:^2.0.1": version: 2.0.3 resolution: "hdr-histogram-js@npm:2.0.3" @@ -11446,6 +11919,13 @@ __metadata: languageName: node linkType: hard +"indexes-of@npm:^1.0.1": + version: 1.0.1 + resolution: "indexes-of@npm:1.0.1" + checksum: 4f9799b1739a62f3e02d09f6f4162cf9673025282af7fa36e790146e7f4e216dad3e776a25b08536c093209c9fcb5ea7bd04b082d42686a45f58ff401d6da32e + languageName: node + linkType: hard + "infer-owner@npm:^1.0.4": version: 1.0.4 resolution: "infer-owner@npm:1.0.4" @@ -11657,6 +12137,15 @@ __metadata: languageName: node linkType: hard +"is-core-module@npm:^2.13.0": + version: 2.13.1 + resolution: "is-core-module@npm:2.13.1" + dependencies: + hasown: ^2.0.0 + checksum: 256559ee8a9488af90e4bad16f5583c6d59e92f0742e9e8bb4331e758521ee86b810b93bae44f390766ffbc518a0488b18d9dab7da9a5ff997d499efc9403f7c + languageName: node + linkType: hard + "is-core-module@npm:^2.5.0": version: 2.13.0 resolution: "is-core-module@npm:2.13.0" @@ -11757,6 +12246,13 @@ __metadata: languageName: node linkType: hard +"is-interactive@npm:^1.0.0": + version: 1.0.0 + resolution: "is-interactive@npm:1.0.0" + checksum: 824808776e2d468b2916cdd6c16acacebce060d844c35ca6d82267da692e92c3a16fdba624c50b54a63f38bdc4016055b6f443ce57d7147240de4f8cdabaf6f9 + languageName: node + linkType: hard + "is-lambda@npm:^1.0.1": version: 1.0.1 resolution: "is-lambda@npm:1.0.1" @@ -11801,6 +12297,13 @@ __metadata: languageName: node linkType: hard +"is-obj@npm:^1.0.1": + version: 1.0.1 + resolution: "is-obj@npm:1.0.1" + checksum: 3ccf0efdea12951e0b9c784e2b00e77e87b2f8bd30b42a498548a8afcc11b3287342a2030c308e473e93a7a19c9ea7854c99a8832a476591c727df2a9c79796c + languageName: node + linkType: hard + "is-path-inside@npm:^3.0.3": version: 3.0.3 resolution: "is-path-inside@npm:3.0.3" @@ -11855,6 +12358,20 @@ __metadata: languageName: node linkType: hard +"is-regexp@npm:^1.0.0": + version: 1.0.0 + resolution: "is-regexp@npm:1.0.0" + checksum: be692828e24cba479ec33644326fa98959ec68ba77965e0291088c1a741feaea4919d79f8031708f85fd25e39de002b4520622b55460660b9c369e6f7187faef + languageName: node + linkType: hard + +"is-relative-path@npm:^1.0.2": + version: 1.0.2 + resolution: "is-relative-path@npm:1.0.2" + checksum: 6c2ccffd3c0a3e3990535d0571370883d558b825b51940085f3446ec338857f4552f44521dfec3e83b7e067de08c0b0369de290208a91200bcae2c569533e340 + languageName: node + linkType: hard + "is-set@npm:^2.0.1, is-set@npm:^2.0.2": version: 2.0.2 resolution: "is-set@npm:2.0.2" @@ -11926,6 +12443,20 @@ __metadata: languageName: node linkType: hard +"is-url-superb@npm:^4.0.0": + version: 4.0.0 + resolution: "is-url-superb@npm:4.0.0" + checksum: fd55e91c96349acb0d688f95fcb1ac67450e5db934976e3a8ff13ef446841e779a6f4d18b15f02331f05a3429c8fdaba2382ac1ab444059e86e9ffcde1ec8db0 + languageName: node + linkType: hard + +"is-url@npm:^1.2.4": + version: 1.2.4 + resolution: "is-url@npm:1.2.4" + checksum: 100e74b3b1feab87a43ef7653736e88d997eb7bd32e71fd3ebc413e58c1cbe56269699c776aaea84244b0567f2a7d68dfaa512a062293ed2f9fdecb394148432 + languageName: node + linkType: hard + "is-weakmap@npm:^2.0.1": version: 2.0.1 resolution: "is-weakmap@npm:2.0.1" @@ -14293,7 +14824,7 @@ __metadata: languageName: node linkType: hard -"log-symbols@npm:4.1.0": +"log-symbols@npm:4.1.0, log-symbols@npm:^4.1.0": version: 4.1.0 resolution: "log-symbols@npm:4.1.0" dependencies: @@ -14400,6 +14931,43 @@ __metadata: languageName: node linkType: hard +"madge@npm:^6.1.0": + version: 6.1.0 + resolution: "madge@npm:6.1.0" + dependencies: + chalk: ^4.1.1 + commander: ^7.2.0 + commondir: ^1.0.1 + debug: ^4.3.1 + dependency-tree: ^9.0.0 + detective-amd: ^4.0.1 + detective-cjs: ^4.0.0 + detective-es6: ^3.0.0 + detective-less: ^1.0.2 + detective-postcss: ^6.1.0 + detective-sass: ^4.0.1 + detective-scss: ^3.0.0 + detective-stylus: ^2.0.1 + detective-typescript: ^9.0.0 + ora: ^5.4.1 + pluralize: ^8.0.0 + precinct: ^8.1.0 + pretty-ms: ^7.0.1 + rc: ^1.2.7 + stream-to-array: ^2.3.0 + ts-graphviz: ^1.5.0 + walkdir: ^0.4.1 + peerDependencies: + typescript: ^3.9.5 || ^4.9.5 || ^5 + peerDependenciesMeta: + typescript: + optional: true + bin: + madge: bin/cli.js + checksum: cb8a629c1eb837640ca2416dbd2236f1ea8657eb188725ff42294718dd1769ece5ec635ef02c344c72e3b4faab3cd8f084b043ce8ecccf4018915738b3329096 + languageName: node + linkType: hard + "make-dir@npm:^4.0.0": version: 4.0.0 resolution: "make-dir@npm:4.0.0" @@ -14826,7 +15394,7 @@ __metadata: languageName: node linkType: hard -"minimist@npm:^1.2.0, minimist@npm:^1.2.6": +"minimist@npm:^1.2.0, minimist@npm:^1.2.5, minimist@npm:^1.2.6": version: 1.2.8 resolution: "minimist@npm:1.2.8" checksum: 75a6d645fb122dad29c06a7597bddea977258957ed88d7a6df59b5cd3fe4a527e253e9bbf2e783e4b73657f9098b96a5fe96ab8a113655d4109108577ecf85b0 @@ -15002,6 +15570,45 @@ __metadata: languageName: node linkType: hard +"module-definition@npm:^3.3.1": + version: 3.4.0 + resolution: "module-definition@npm:3.4.0" + dependencies: + ast-module-types: ^3.0.0 + node-source-walk: ^4.0.0 + bin: + module-definition: bin/cli.js + checksum: 5cbfd38aab1a9169b5c31924e208e430a87a1b1512ab9736a9a368d950e3cc8e2f5cf642e37fe74123e25402cae50bfb8fdf1f5f0fd3d4d9270df705a2360bfa + languageName: node + linkType: hard + +"module-definition@npm:^4.1.0": + version: 4.1.0 + resolution: "module-definition@npm:4.1.0" + dependencies: + ast-module-types: ^4.0.0 + node-source-walk: ^5.0.1 + bin: + module-definition: bin/cli.js + checksum: d9b6397c9ba04b08bc035fd87a3652900530b9a5d6e5263f8a1e05c927dfc103fdffcecd7071a9fd6cd7813fc9feafbbe828f5277e5b706e5de82831153ef0fb + languageName: node + linkType: hard + +"module-lookup-amd@npm:^7.0.1": + version: 7.0.1 + resolution: "module-lookup-amd@npm:7.0.1" + dependencies: + commander: ^2.8.1 + debug: ^4.1.0 + glob: ^7.1.6 + requirejs: ^2.3.5 + requirejs-config-file: ^4.0.0 + bin: + lookup-amd: bin/cli.js + checksum: 911abd6b8fb1d82cfae4ef38050981d4eb7e710bfeba898903c5c49a4d3a44b3cacb6201ddf9930a39fae3473faf9b96d39930cfa8766dbf0da86689108895b1 + languageName: node + linkType: hard + "moment@npm:^2.29.1": version: 2.29.4 resolution: "moment@npm:2.29.4" @@ -15352,6 +15959,24 @@ __metadata: languageName: node linkType: hard +"node-source-walk@npm:^4.0.0, node-source-walk@npm:^4.2.0, node-source-walk@npm:^4.2.2": + version: 4.3.0 + resolution: "node-source-walk@npm:4.3.0" + dependencies: + "@babel/parser": ^7.0.0 + checksum: 124bcec61f73141a5f13e63f773beb00c9a9620e9eec6d7505b9de8fa884797f3eb0b9e9d225bb324930234ae03b28a4a7a231e2c2f23d71405d4a562b404e34 + languageName: node + linkType: hard + +"node-source-walk@npm:^5.0.0, node-source-walk@npm:^5.0.1": + version: 5.0.2 + resolution: "node-source-walk@npm:5.0.2" + dependencies: + "@babel/parser": ^7.21.4 + checksum: 1031bc0871bb77ace33bd09fb1e9ef7589b03e6a2fa441b8e684023102362da6dba77d6b9b086dc1f995c7e69e3517666d5316c3831b9d9ff077cb36d57179e8 + languageName: node + linkType: hard + "nopt@npm:^5.0.0": version: 5.0.0 resolution: "nopt@npm:5.0.0" @@ -15581,7 +16206,7 @@ __metadata: languageName: node linkType: hard -"onetime@npm:^5.1.2": +"onetime@npm:^5.1.0, onetime@npm:^5.1.2": version: 5.1.2 resolution: "onetime@npm:5.1.2" dependencies: @@ -15643,6 +16268,23 @@ __metadata: languageName: node linkType: hard +"ora@npm:^5.4.1": + version: 5.4.1 + resolution: "ora@npm:5.4.1" + dependencies: + bl: ^4.1.0 + chalk: ^4.1.0 + cli-cursor: ^3.1.0 + cli-spinners: ^2.5.0 + is-interactive: ^1.0.0 + is-unicode-supported: ^0.1.0 + log-symbols: ^4.1.0 + strip-ansi: ^6.0.0 + wcwidth: ^1.0.1 + checksum: 28d476ee6c1049d68368c0dc922e7225e3b5600c3ede88fade8052837f9ed342625fdaa84a6209302587c8ddd9b664f71f0759833cbdb3a4cf81344057e63c63 + languageName: node + linkType: hard + "outdent@npm:^0.8.0": version: 0.8.0 resolution: "outdent@npm:0.8.0" @@ -15846,6 +16488,13 @@ __metadata: languageName: node linkType: hard +"parse-ms@npm:^2.1.0": + version: 2.1.0 + resolution: "parse-ms@npm:2.1.0" + checksum: d5c66c76cca8df5bd0574e2d11b9c3752893b59b466e74308d4a2f09760dc5436a1633f549cad300fc8c3c19154d14959a3b8333d3b2f7bd75898fe18149d564 + languageName: node + linkType: hard + "parseurl@npm:^1.3.2, parseurl@npm:~1.3.2, parseurl@npm:~1.3.3": version: 1.3.3 resolution: "parseurl@npm:1.3.3" @@ -16080,6 +16729,13 @@ __metadata: languageName: node linkType: hard +"pluralize@npm:^8.0.0": + version: 8.0.0 + resolution: "pluralize@npm:8.0.0" + checksum: 08931d4a6a4a5561a7f94f67a31c17e6632cb21e459ab3ff4f6f629d9a822984cf8afef2311d2005fbea5d7ef26016ebb090db008e2d8bce39d0a9a9d218736e + languageName: node + linkType: hard + "pngjs@npm:^3.3.0": version: 3.4.0 resolution: "pngjs@npm:3.4.0" @@ -16169,6 +16825,41 @@ __metadata: languageName: node linkType: hard +"postcss-values-parser@npm:^2.0.1": + version: 2.0.1 + resolution: "postcss-values-parser@npm:2.0.1" + dependencies: + flatten: ^1.0.2 + indexes-of: ^1.0.1 + uniq: ^1.0.1 + checksum: 050877880937e15af8d18bf48902e547e2123d7cc32c1f215b392642bc5e2598a87a341995d62f38e450aab4186b8afeb2c9541934806d458ad8b117020b2ebf + languageName: node + linkType: hard + +"postcss-values-parser@npm:^6.0.2": + version: 6.0.2 + resolution: "postcss-values-parser@npm:6.0.2" + dependencies: + color-name: ^1.1.4 + is-url-superb: ^4.0.0 + quote-unquote: ^1.0.0 + peerDependencies: + postcss: ^8.2.9 + checksum: 615fea3d7996b3fae84a8674fb0e7c6bd0bc006beddb126692c2e43112b772625329c5f10121b00d69fe7a24f7f18dd25e24745574556735c4e9671774df0eb1 + languageName: node + linkType: hard + +"postcss@npm:^8.1.7, postcss@npm:^8.4.23": + version: 8.4.31 + resolution: "postcss@npm:8.4.31" + dependencies: + nanoid: ^3.3.6 + picocolors: ^1.0.0 + source-map-js: ^1.0.2 + checksum: 1d8611341b073143ad90486fcdfeab49edd243377b1f51834dc4f6d028e82ce5190e4f11bb2633276864503654fb7cab28e67abdc0fbf9d1f88cad4a0ff0beea + languageName: node + linkType: hard + "postcss@npm:^8.4.21, postcss@npm:^8.4.29": version: 8.4.29 resolution: "postcss@npm:8.4.29" @@ -16205,6 +16896,51 @@ __metadata: languageName: node linkType: hard +"precinct@npm:^8.1.0": + version: 8.3.1 + resolution: "precinct@npm:8.3.1" + dependencies: + commander: ^2.20.3 + debug: ^4.3.3 + detective-amd: ^3.1.0 + detective-cjs: ^3.1.1 + detective-es6: ^2.2.1 + detective-less: ^1.0.2 + detective-postcss: ^4.0.0 + detective-sass: ^3.0.1 + detective-scss: ^2.0.1 + detective-stylus: ^1.0.0 + detective-typescript: ^7.0.0 + module-definition: ^3.3.1 + node-source-walk: ^4.2.0 + bin: + precinct: bin/cli.js + checksum: 16ba57e545fc53481b3a194f9d7843cefd562ce5e847280355eed360ca4c55def4d03d501776fb49fdf79bfe84a03ec6138003d8387c0426f6a68e1931688399 + languageName: node + linkType: hard + +"precinct@npm:^9.0.0": + version: 9.2.1 + resolution: "precinct@npm:9.2.1" + dependencies: + "@dependents/detective-less": ^3.0.1 + commander: ^9.5.0 + detective-amd: ^4.1.0 + detective-cjs: ^4.1.0 + detective-es6: ^3.0.1 + detective-postcss: ^6.1.1 + detective-sass: ^4.1.1 + detective-scss: ^3.0.1 + detective-stylus: ^3.0.0 + detective-typescript: ^9.1.1 + module-definition: ^4.1.0 + node-source-walk: ^5.0.1 + bin: + precinct: bin/cli.js + checksum: 0352553cca8aff0baa04412429bbe3fab278e9e574fd9bcb2b1bb87dc3ed608f3e08b66c86aee90eed6bac5c4091fe78753ae094d54b01a803189d3259817fe7 + languageName: node + linkType: hard + "prelude-ls@npm:^1.2.1": version: 1.2.1 resolution: "prelude-ls@npm:1.2.1" @@ -16254,6 +16990,15 @@ __metadata: languageName: node linkType: hard +"pretty-ms@npm:^7.0.1": + version: 7.0.1 + resolution: "pretty-ms@npm:7.0.1" + dependencies: + parse-ms: ^2.1.0 + checksum: d76c4920283b48be91f1d3797a2ce4bd51187d58d2a609ae993c028f73c92d16439449d857af57ccad91ae3a38b30c87307f5589749a056102ebb494c686957e + languageName: node + linkType: hard + "private-ip@npm:^3.0.0": version: 3.0.1 resolution: "private-ip@npm:3.0.1" @@ -16602,6 +17347,13 @@ __metadata: languageName: node linkType: hard +"quote-unquote@npm:^1.0.0": + version: 1.0.0 + resolution: "quote-unquote@npm:1.0.0" + checksum: 955a2ead534f5b6a3f8d4dc5a4b95ac6468213d3fb11f8c1592a0a56345c45a3d14d5ca04d3de2bc9891493fcac38c03dfa91c48a6159aef50124e9c5afcea49 + languageName: node + linkType: hard + "randombytes@npm:^2.0.0, randombytes@npm:^2.0.1, randombytes@npm:^2.0.5, randombytes@npm:^2.1.0": version: 2.1.0 resolution: "randombytes@npm:2.1.0" @@ -16666,7 +17418,7 @@ __metadata: languageName: node linkType: hard -"rc@npm:^1.0.1, rc@npm:^1.1.6": +"rc@npm:^1.0.1, rc@npm:^1.1.6, rc@npm:^1.2.7": version: 1.2.8 resolution: "rc@npm:1.2.8" dependencies: @@ -16986,6 +17738,26 @@ __metadata: languageName: node linkType: hard +"requirejs-config-file@npm:^4.0.0": + version: 4.0.0 + resolution: "requirejs-config-file@npm:4.0.0" + dependencies: + esprima: ^4.0.0 + stringify-object: ^3.2.1 + checksum: 61ac1c419a8978df9484211827047f0a43d48a97e242ebca9628a2e52da8c739ee068bd67dc4d5dc5fd7be6d1c9a863006bb02df691c86914921fe12713fbebb + languageName: node + linkType: hard + +"requirejs@npm:^2.3.5": + version: 2.3.6 + resolution: "requirejs@npm:2.3.6" + bin: + r.js: ./bin/r.js + r_js: ./bin/r.js + checksum: 7c3c006bf5e1887d93ac7adb7f600328918d23cf3d28282a505a2873d4ddde499c7ec560e55cee3440d17fe1205cb4dcb72b07f35b39e8940372eca850e49b62 + languageName: node + linkType: hard + "requires-port@npm:^1.0.0": version: 1.0.0 resolution: "requires-port@npm:1.0.0" @@ -17002,6 +17774,13 @@ __metadata: languageName: node linkType: hard +"resolve-dependency-path@npm:^2.0.0": + version: 2.0.0 + resolution: "resolve-dependency-path@npm:2.0.0" + checksum: 161296969a0a7853ebb7710847154ffb5bd11a51c370b67a0d0c89cacfcb57063d204587617fd030ea227bfd19a3c4af79d39e9d20ae0fbe354c27598d1ea8a8 + languageName: node + linkType: hard + "resolve-from@npm:^4.0.0": version: 4.0.0 resolution: "resolve-from@npm:4.0.0" @@ -17064,6 +17843,19 @@ __metadata: languageName: node linkType: hard +"resolve@npm:^1.21.0": + version: 1.22.8 + resolution: "resolve@npm:1.22.8" + dependencies: + is-core-module: ^2.13.0 + path-parse: ^1.0.7 + supports-preserve-symlinks-flag: ^1.0.0 + bin: + resolve: bin/resolve + checksum: f8a26958aa572c9b064562750b52131a37c29d072478ea32e129063e2da7f83e31f7f11e7087a18225a8561cfe8d2f0df9dbea7c9d331a897571c0a2527dbb4c + languageName: node + linkType: hard + "resolve@npm:~1.19.0": version: 1.19.0 resolution: "resolve@npm:1.19.0" @@ -17087,6 +17879,19 @@ __metadata: languageName: node linkType: hard +"resolve@patch:resolve@^1.21.0#~builtin": + version: 1.22.8 + resolution: "resolve@patch:resolve@npm%3A1.22.8#~builtin::version=1.22.8&hash=c3c19d" + dependencies: + is-core-module: ^2.13.0 + path-parse: ^1.0.7 + supports-preserve-symlinks-flag: ^1.0.0 + bin: + resolve: bin/resolve + checksum: 5479b7d431cacd5185f8db64bfcb7286ae5e31eb299f4c4f404ad8aa6098b77599563ac4257cb2c37a42f59dfc06a1bec2bcf283bb448f319e37f0feb9a09847 + languageName: node + linkType: hard + "resolve@patch:resolve@~1.19.0#~builtin": version: 1.19.0 resolution: "resolve@patch:resolve@npm%3A1.19.0#~builtin::version=1.19.0&hash=c3c19d" @@ -17097,6 +17902,16 @@ __metadata: languageName: node linkType: hard +"restore-cursor@npm:^3.1.0": + version: 3.1.0 + resolution: "restore-cursor@npm:3.1.0" + dependencies: + onetime: ^5.1.0 + signal-exit: ^3.0.2 + checksum: f877dd8741796b909f2a82454ec111afb84eb45890eb49ac947d87991379406b3b83ff9673a46012fca0d7844bb989f45cc5b788254cf1a39b6b5a9659de0630 + languageName: node + linkType: hard + "retry@npm:^0.12.0": version: 0.12.0 resolution: "retry@npm:0.12.0" @@ -17313,6 +18128,17 @@ __metadata: languageName: node linkType: hard +"sass-lookup@npm:^3.0.0": + version: 3.0.0 + resolution: "sass-lookup@npm:3.0.0" + dependencies: + commander: ^2.16.0 + bin: + sass-lookup: bin/cli.js + checksum: fd4bf1ad9c54111617dec30dd90aff083e87c96aef50aff6cec443ad2fbbfa65da09f6e67a7e5ef99fa39dff65c937dc7358f18d319e083c6031f21def85ce6d + languageName: node + linkType: hard + "sass@npm:^1.58.0": version: 1.67.0 resolution: "sass@npm:1.67.0" @@ -17435,7 +18261,7 @@ __metadata: languageName: node linkType: hard -"semver@npm:^7.3.4, semver@npm:^7.3.5, semver@npm:^7.3.8, semver@npm:^7.5.3, semver@npm:^7.5.4": +"semver@npm:^7.3.4, semver@npm:^7.3.5, semver@npm:^7.3.7, semver@npm:^7.3.8, semver@npm:^7.5.3, semver@npm:^7.5.4": version: 7.5.4 resolution: "semver@npm:7.5.4" dependencies: @@ -17663,7 +18489,7 @@ __metadata: languageName: node linkType: hard -"signal-exit@npm:^3.0.3, signal-exit@npm:^3.0.7": +"signal-exit@npm:^3.0.2, signal-exit@npm:^3.0.3, signal-exit@npm:^3.0.7": version: 3.0.7 resolution: "signal-exit@npm:3.0.7" checksum: a2f098f247adc367dffc27845853e9959b9e88b01cb301658cfe4194352d8d2bb32e18467c786a7fe15f1d44b233ea35633d076d5e737870b7139949d1ab6318 @@ -18024,6 +18850,15 @@ __metadata: languageName: node linkType: hard +"stream-to-array@npm:^2.3.0": + version: 2.3.0 + resolution: "stream-to-array@npm:2.3.0" + dependencies: + any-promise: ^1.1.0 + checksum: 7feaf63b38399b850615e6ffcaa951e96e4c8f46745dbce4b553a94c5dc43966933813747014935a3ff97793e7f30a65270bde19f82b2932871a1879229a77cf + languageName: node + linkType: hard + "stream-to-it@npm:^0.2.2": version: 0.2.4 resolution: "stream-to-it@npm:0.2.4" @@ -18158,6 +18993,17 @@ __metadata: languageName: node linkType: hard +"stringify-object@npm:^3.2.1": + version: 3.3.0 + resolution: "stringify-object@npm:3.3.0" + dependencies: + get-own-enumerable-property-symbols: ^3.0.0 + is-obj: ^1.0.1 + is-regexp: ^1.0.0 + checksum: 6827a3f35975cfa8572e8cd3ed4f7b262def260af18655c6fde549334acdac49ddba69f3c861ea5a6e9c5a4990fe4ae870b9c0e6c31019430504c94a83b7a154 + languageName: node + linkType: hard + "strip-ansi-cjs@npm:strip-ansi@^6.0.1, strip-ansi@npm:^6.0.0, strip-ansi@npm:^6.0.1": version: 6.0.1 resolution: "strip-ansi@npm:6.0.1" @@ -18245,6 +19091,18 @@ __metadata: languageName: node linkType: hard +"stylus-lookup@npm:^3.0.1": + version: 3.0.2 + resolution: "stylus-lookup@npm:3.0.2" + dependencies: + commander: ^2.8.1 + debug: ^4.1.0 + bin: + stylus-lookup: bin/cli.js + checksum: 460e9b6e7e662e2cf98d41ee670cb5da9ec8b8dbc1d4574de29ac422c632d5c7933772822fc12792f2ee9f9c2f62b3f60ed5850690e7c780ab7b6f07010199e4 + languageName: node + linkType: hard + "superagent@npm:^8.0.5": version: 8.0.9 resolution: "superagent@npm:8.0.9" @@ -18690,6 +19548,13 @@ __metadata: languageName: node linkType: hard +"ts-graphviz@npm:^1.5.0": + version: 1.8.1 + resolution: "ts-graphviz@npm:1.8.1" + checksum: c560fc3a70fc7743bb1cacd21fdeb68661e78132cad4c0cb53c071d2485b1e5975350f0a754c2a797912e9d9022dc375b47e6b023a2eafe4b824c0bb9b7d58ed + languageName: node + linkType: hard + "ts-jest@npm:29.1.1": version: 29.1.1 resolution: "ts-jest@npm:29.1.1" @@ -18825,7 +19690,7 @@ __metadata: languageName: node linkType: hard -"tsconfig-paths@npm:^3.14.2": +"tsconfig-paths@npm:^3.10.1, tsconfig-paths@npm:^3.14.2": version: 3.14.2 resolution: "tsconfig-paths@npm:3.14.2" dependencies: @@ -18837,7 +19702,7 @@ __metadata: languageName: node linkType: hard -"tslib@npm:1.14.1, tslib@npm:^1.9.0": +"tslib@npm:1.14.1, tslib@npm:^1.8.1, tslib@npm:^1.9.0": version: 1.14.1 resolution: "tslib@npm:1.14.1" checksum: dbe628ef87f66691d5d2959b3e41b9ca0045c3ee3c7c7b906cc1e328b39f199bb1ad9e671c39025bd56122ac57dfbf7385a94843b1cc07c60a4db74795829acd @@ -18872,6 +19737,17 @@ __metadata: languageName: node linkType: hard +"tsutils@npm:^3.21.0": + version: 3.21.0 + resolution: "tsutils@npm:3.21.0" + dependencies: + tslib: ^1.8.1 + peerDependencies: + typescript: ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" + checksum: 1843f4c1b2e0f975e08c4c21caa4af4f7f65a12ac1b81b3b8489366826259323feb3fc7a243123453d2d1a02314205a7634e048d4a8009921da19f99755cdc48 + languageName: node + linkType: hard + "tty-browserify@npm:^0.0.1": version: 0.0.1 resolution: "tty-browserify@npm:0.0.1" @@ -19026,6 +19902,26 @@ __metadata: languageName: node linkType: hard +"typescript@npm:^3.9.10, typescript@npm:^3.9.7": + version: 3.9.10 + resolution: "typescript@npm:3.9.10" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: 46c842e2cd4797b88b66ef06c9c41dd21da48b95787072ccf39d5f2aa3124361bc4c966aa1c7f709fae0509614d76751455b5231b12dbb72eb97a31369e1ff92 + languageName: node + linkType: hard + +"typescript@npm:^4.0.0, typescript@npm:^4.9.5": + version: 4.9.5 + resolution: "typescript@npm:4.9.5" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: ee000bc26848147ad423b581bd250075662a354d84f0e06eb76d3b892328d8d4440b7487b5a83e851b12b255f55d71835b008a66cbf8f255a11e4400159237db + languageName: node + linkType: hard + "typescript@npm:^5.0.4": version: 5.1.6 resolution: "typescript@npm:5.1.6" @@ -19036,6 +19932,26 @@ __metadata: languageName: node linkType: hard +"typescript@patch:typescript@^3.9.10#~builtin, typescript@patch:typescript@^3.9.7#~builtin": + version: 3.9.10 + resolution: "typescript@patch:typescript@npm%3A3.9.10#~builtin::version=3.9.10&hash=3bd3d3" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: dc7141ab555b23a8650a6787f98845fc11692063d02b75ff49433091b3af2fe3d773650dea18389d7c21f47d620fb3b110ea363dab4ab039417a6ccbbaf96fc2 + languageName: node + linkType: hard + +"typescript@patch:typescript@^4.0.0#~builtin, typescript@patch:typescript@^4.9.5#~builtin": + version: 4.9.5 + resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin::version=4.9.5&hash=289587" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: 1f8f3b6aaea19f0f67cba79057674ba580438a7db55057eb89cc06950483c5d632115c14077f6663ea76fd09fce3c190e6414bb98582ec80aa5a4eaf345d5b68 + languageName: node + linkType: hard + "typescript@patch:typescript@^5.0.4#~builtin": version: 5.1.6 resolution: "typescript@patch:typescript@npm%3A5.1.6#~builtin::version=5.1.6&hash=5da071" @@ -19144,6 +20060,13 @@ __metadata: languageName: node linkType: hard +"uniq@npm:^1.0.1": + version: 1.0.1 + resolution: "uniq@npm:1.0.1" + checksum: 8206535f83745ea83f9da7035f3b983fd6ed5e35b8ed7745441944e4065b616bc67cf0d0a23a86b40ee0074426f0607f0a138f9b78e124eb6a7a6a6966055709 + languageName: node + linkType: hard + "unique-filename@npm:^1.1.1": version: 1.1.1 resolution: "unique-filename@npm:1.1.1" @@ -19558,6 +20481,13 @@ __metadata: languageName: node linkType: hard +"walkdir@npm:^0.4.1": + version: 0.4.1 + resolution: "walkdir@npm:0.4.1" + checksum: 71045c21dc19aae3321f897b6e9e507cf8039202665c35a0b908eecccaf25636aab769b31cbd61ef8267237fe22fc316923a691ecc2d9d38840a15c59c0f2594 + languageName: node + linkType: hard + "walker@npm:^1.0.8": version: 1.0.8 resolution: "walker@npm:1.0.8" @@ -19586,6 +20516,15 @@ __metadata: languageName: node linkType: hard +"wcwidth@npm:^1.0.1": + version: 1.0.1 + resolution: "wcwidth@npm:1.0.1" + dependencies: + defaults: ^1.0.3 + checksum: 814e9d1ddcc9798f7377ffa448a5a3892232b9275ebb30a41b529607691c0491de47cba426e917a4d08ded3ee7e9ba2f3fe32e62ee3cd9c7d3bafb7754bd553c + languageName: node + linkType: hard + "web-streams-polyfill@npm:^3.0.3": version: 3.2.1 resolution: "web-streams-polyfill@npm:3.2.1" From 39c1c67a186e9a9f53c7802b85357ad7976bde58 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Thu, 2 Nov 2023 00:10:42 +0000 Subject: [PATCH 11/29] one less circular. --- .../world-state/src/world-state-db/index.ts | 244 +----------------- .../src/world-state-db/merkle_trees.ts | 2 +- 2 files changed, 2 insertions(+), 244 deletions(-) diff --git a/yarn-project/world-state/src/world-state-db/index.ts b/yarn-project/world-state/src/world-state-db/index.ts index 053e5db849cb..8c0a92a77dd6 100644 --- a/yarn-project/world-state/src/world-state-db/index.ts +++ b/yarn-project/world-state/src/world-state-db/index.ts @@ -1,245 +1,3 @@ -import { MAX_NEW_NULLIFIERS_PER_TX } from '@aztec/circuits.js'; -import { Fr } from '@aztec/foundation/fields'; -import { createDebugLogger } from '@aztec/foundation/log'; -import { LeafData, LowLeafWitnessData } from '@aztec/merkle-tree'; -import { L2Block, MerkleTreeId, SiblingPath } from '@aztec/types'; - export * from './merkle_trees.js'; +export * from './merkle_tree_db.js'; export { LeafData } from '@aztec/merkle-tree'; - -/** - * Type alias for the nullifier tree ID. - */ -export type IndexedTreeId = MerkleTreeId.NULLIFIER_TREE; - -/** - * Type alias for the public data tree ID. - */ -export type PublicTreeId = MerkleTreeId.PUBLIC_DATA_TREE; - -/** - * - * @remarks Short explanation: - * The nullifier tree must be initially padded as the pre-populated 0 index prevents efficient subtree insertion. - * Padding with some values solves this issue. - * - * @remarks Thorough explanation: - * There needs to be an initial (0,0,0) leaf in the tree, so that when we insert the first 'proper' leaf, we can - * prove that any value greater than 0 doesn't exist in the tree yet. We prefill/pad the tree with "the number of - * leaves that are added by one block" so that the first 'proper' block can insert a full subtree. - * - * Without this padding, there would be a leaf (0,0,0) at leaf index 0, making it really difficult to insert e.g. - * 1024 leaves for the first block, because there's only neat space for 1023 leaves after 0. By padding with 1023 - * more leaves, we can then insert the first block of 1024 leaves into indices 1024:2047. - */ -export const INITIAL_NULLIFIER_TREE_SIZE = 2 * MAX_NEW_NULLIFIERS_PER_TX; - -/** - * Defines tree information. - */ -export interface TreeInfo { - /** - * The tree ID. - */ - treeId: MerkleTreeId; - /** - * The tree root. - */ - root: Buffer; - /** - * The number of leaves in the tree. - */ - size: bigint; - - /** - * The depth of the tree. - */ - depth: number; -} - -/** - * Adds a last boolean flag in each function on the type. - */ -type WithIncludeUncommitted = F extends (...args: [...infer Rest]) => infer Return - ? (...args: [...Rest, boolean]) => Return - : F; - -/** - * The current roots of the commitment trees - */ -export type CurrentTreeRoots = { - /** Note Hash Tree root. */ - noteHashTreeRoot: Buffer; - /** Contract data tree root. */ - contractDataTreeRoot: Buffer; - /** L1 to L2 Messages data tree root. */ - l1Tol2MessagesTreeRoot: Buffer; - /** Nullifier data tree root. */ - nullifierTreeRoot: Buffer; - /** Blocks tree root. */ - blocksTreeRoot: Buffer; - /** Public data tree root */ - publicDataTreeRoot: Buffer; -}; - -/** - * Defines the names of the setters on Merkle Trees. - */ -type MerkleTreeSetters = 'appendLeaves' | 'updateLeaf' | 'commit' | 'rollback' | 'handleL2Block' | 'batchInsert'; - -/** - * Defines the interface for operations on a set of Merkle Trees configuring whether to return committed or uncommitted data. - */ -export type MerkleTreeDb = { - [Property in keyof MerkleTreeOperations as Exclude]: WithIncludeUncommitted< - MerkleTreeOperations[Property] - >; -} & Pick; - -/** - * Defines the interface for operations on a set of Merkle Trees. - */ -export interface MerkleTreeOperations { - /** - * Appends leaves to a given tree. - * @param treeId - The tree to be updated. - * @param leaves - The set of leaves to be appended. - */ - appendLeaves(treeId: MerkleTreeId, leaves: Buffer[]): Promise; - - /** - * Returns information about the given tree. - * @param treeId - The tree to be queried. - */ - getTreeInfo(treeId: MerkleTreeId): Promise; - - /** - * Gets the current roots of the commitment trees. - */ - getTreeRoots(): Promise; - - /** - * Gets sibling path for a leaf. - * @param treeId - The tree to be queried for a sibling path. - * @param index - The index of the leaf for which a sibling path should be returned. - */ - getSiblingPath(treeId: MerkleTreeId, index: bigint): Promise>; - - /** - * Returns the previous index for a given value in an indexed tree. - * @param treeId - The tree for which the previous value index is required. - * @param value - The value to be queried. - */ - getPreviousValueIndex( - treeId: IndexedTreeId, - value: bigint, - ): Promise<{ - /** - * The index of the found leaf. - */ - index: number; - /** - * A flag indicating if the corresponding leaf's value is equal to `newValue`. - */ - alreadyPresent: boolean; - }>; - - /** - * Returns the data at a specific leaf. - * @param treeId - The tree for which leaf data should be returned. - * @param index - The index of the leaf required. - */ - getLeafData(treeId: IndexedTreeId, index: number): Promise; - - /** - * Update the leaf data at the given index. - * @param treeId - The tree for which leaf data should be edited. - * @param leaf - The updated leaf value. - * @param index - The index of the leaf to be updated. - */ - updateLeaf(treeId: IndexedTreeId | PublicTreeId, leaf: LeafData | Buffer, index: bigint): Promise; - - /** - * Returns the index containing a leaf value. - * @param treeId - The tree for which the index should be returned. - * @param value - The value to search for in the tree. - */ - findLeafIndex(treeId: MerkleTreeId, value: Buffer): Promise; - - /** - * Gets the value for a leaf in the tree. - * @param treeId - The tree for which the index should be returned. - * @param index - The index of the leaf. - */ - getLeafValue(treeId: MerkleTreeId, index: bigint): Promise; - - /** - * Inserts the new block hash into the new block hashes tree. - * This includes all of the current roots of all of the data trees and the current blocks global vars. - * @param globalVariablesHash - The global variables hash to insert into the block hash. - */ - updateHistoricBlocksTree(globalVariablesHash: Fr): Promise; - - /** - * Updates the latest global variables hash - * @param globalVariablesHash - The latest global variables hash - */ - updateLatestGlobalVariablesHash(globalVariablesHash: Fr): Promise; - - /** - * Gets the global variables hash from the previous block - */ - getLatestGlobalVariablesHash(): Promise; - - /** - * Batch insert multiple leaves into the tree. - * @param leaves - Leaves to insert into the tree. - * @param treeId - The tree on which to insert. - * @param subtreeHeight - Height of the subtree. - * @returns The witness data for the leaves to be updated when inserting the new ones. - */ - batchInsert( - treeId: MerkleTreeId, - leaves: Buffer[], - subtreeHeight: number, - ): Promise<[LowLeafWitnessData[], SiblingPath] | [undefined, SiblingPath]>; - - /** - * Handles a single L2 block (i.e. Inserts the new commitments into the merkle tree). - * @param block - The L2 block to handle. - */ - handleL2Block(block: L2Block): Promise; - - /** - * Commits pending changes to the underlying store. - */ - commit(): Promise; - - /** - * Rolls back pending changes. - */ - rollback(): Promise; -} - -/** Return type for handleL2Block */ -export type HandleL2BlockResult = { - /** Whether the block processed was emitted by our sequencer */ isBlockOurs: boolean; -}; - -/** - * Outputs a tree leaves using for debugging purposes. - */ -export async function inspectTree( - db: MerkleTreeOperations, - treeId: MerkleTreeId, - log = createDebugLogger('aztec:inspect-tree'), -) { - const info = await db.getTreeInfo(treeId); - const output = [`Tree id=${treeId} size=${info.size} root=0x${info.root.toString('hex')}`]; - for (let i = 0; i < info.size; i++) { - output.push( - ` Leaf ${i}: ${await db.getLeafValue(treeId, BigInt(i)).then(x => x?.toString('hex') ?? '[undefined]')}`, - ); - } - log(output.join('\n')); -} diff --git a/yarn-project/world-state/src/world-state-db/merkle_trees.ts b/yarn-project/world-state/src/world-state-db/merkle_trees.ts index 2032f6400e3a..4ae2e41b8581 100644 --- a/yarn-project/world-state/src/world-state-db/merkle_trees.ts +++ b/yarn-project/world-state/src/world-state-db/merkle_trees.ts @@ -40,7 +40,7 @@ import { MerkleTreeOperations, PublicTreeId, TreeInfo, -} from './index.js'; +} from './merkle_tree_db.js'; /** * Data necessary to reinitialize the merkle trees from Db. From 960765619530b6a6ed9ea13e8fb5dc3769b02b84 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Thu, 2 Nov 2023 12:32:54 +0000 Subject: [PATCH 12/29] fix --- .../src/world-state-db/merkle_tree_db.ts | 242 ++++++++++++++++++ 1 file changed, 242 insertions(+) create mode 100644 yarn-project/world-state/src/world-state-db/merkle_tree_db.ts diff --git a/yarn-project/world-state/src/world-state-db/merkle_tree_db.ts b/yarn-project/world-state/src/world-state-db/merkle_tree_db.ts new file mode 100644 index 000000000000..0f23abaa2574 --- /dev/null +++ b/yarn-project/world-state/src/world-state-db/merkle_tree_db.ts @@ -0,0 +1,242 @@ +import { MAX_NEW_NULLIFIERS_PER_TX } from '@aztec/circuits.js'; +import { Fr } from '@aztec/foundation/fields'; +import { createDebugLogger } from '@aztec/foundation/log'; +import { LeafData, LowLeafWitnessData } from '@aztec/merkle-tree'; +import { L2Block, MerkleTreeId, SiblingPath } from '@aztec/types'; + +/** + * Type alias for the nullifier tree ID. + */ +export type IndexedTreeId = MerkleTreeId.NULLIFIER_TREE; + +/** + * Type alias for the public data tree ID. + */ +export type PublicTreeId = MerkleTreeId.PUBLIC_DATA_TREE; + +/** + * + * @remarks Short explanation: + * The nullifier tree must be initially padded as the pre-populated 0 index prevents efficient subtree insertion. + * Padding with some values solves this issue. + * + * @remarks Thorough explanation: + * There needs to be an initial (0,0,0) leaf in the tree, so that when we insert the first 'proper' leaf, we can + * prove that any value greater than 0 doesn't exist in the tree yet. We prefill/pad the tree with "the number of + * leaves that are added by one block" so that the first 'proper' block can insert a full subtree. + * + * Without this padding, there would be a leaf (0,0,0) at leaf index 0, making it really difficult to insert e.g. + * 1024 leaves for the first block, because there's only neat space for 1023 leaves after 0. By padding with 1023 + * more leaves, we can then insert the first block of 1024 leaves into indices 1024:2047. + */ +export const INITIAL_NULLIFIER_TREE_SIZE = 2 * MAX_NEW_NULLIFIERS_PER_TX; + +/** + * Defines tree information. + */ +export interface TreeInfo { + /** + * The tree ID. + */ + treeId: MerkleTreeId; + /** + * The tree root. + */ + root: Buffer; + /** + * The number of leaves in the tree. + */ + size: bigint; + + /** + * The depth of the tree. + */ + depth: number; +} + +/** + * Adds a last boolean flag in each function on the type. + */ +type WithIncludeUncommitted = F extends (...args: [...infer Rest]) => infer Return + ? (...args: [...Rest, boolean]) => Return + : F; + +/** + * The current roots of the commitment trees + */ +export type CurrentTreeRoots = { + /** Note Hash Tree root. */ + noteHashTreeRoot: Buffer; + /** Contract data tree root. */ + contractDataTreeRoot: Buffer; + /** L1 to L2 Messages data tree root. */ + l1Tol2MessagesTreeRoot: Buffer; + /** Nullifier data tree root. */ + nullifierTreeRoot: Buffer; + /** Blocks tree root. */ + blocksTreeRoot: Buffer; + /** Public data tree root */ + publicDataTreeRoot: Buffer; +}; + +/** + * Defines the names of the setters on Merkle Trees. + */ +type MerkleTreeSetters = 'appendLeaves' | 'updateLeaf' | 'commit' | 'rollback' | 'handleL2Block' | 'batchInsert'; + +/** + * Defines the interface for operations on a set of Merkle Trees configuring whether to return committed or uncommitted data. + */ +export type MerkleTreeDb = { + [Property in keyof MerkleTreeOperations as Exclude]: WithIncludeUncommitted< + MerkleTreeOperations[Property] + >; +} & Pick; + +/** + * Defines the interface for operations on a set of Merkle Trees. + */ +export interface MerkleTreeOperations { + /** + * Appends leaves to a given tree. + * @param treeId - The tree to be updated. + * @param leaves - The set of leaves to be appended. + */ + appendLeaves(treeId: MerkleTreeId, leaves: Buffer[]): Promise; + + /** + * Returns information about the given tree. + * @param treeId - The tree to be queried. + */ + getTreeInfo(treeId: MerkleTreeId): Promise; + + /** + * Gets the current roots of the commitment trees. + */ + getTreeRoots(): Promise; + + /** + * Gets sibling path for a leaf. + * @param treeId - The tree to be queried for a sibling path. + * @param index - The index of the leaf for which a sibling path should be returned. + */ + getSiblingPath(treeId: MerkleTreeId, index: bigint): Promise>; + + /** + * Returns the previous index for a given value in an indexed tree. + * @param treeId - The tree for which the previous value index is required. + * @param value - The value to be queried. + */ + getPreviousValueIndex( + treeId: IndexedTreeId, + value: bigint, + ): Promise<{ + /** + * The index of the found leaf. + */ + index: number; + /** + * A flag indicating if the corresponding leaf's value is equal to `newValue`. + */ + alreadyPresent: boolean; + }>; + + /** + * Returns the data at a specific leaf. + * @param treeId - The tree for which leaf data should be returned. + * @param index - The index of the leaf required. + */ + getLeafData(treeId: IndexedTreeId, index: number): Promise; + + /** + * Update the leaf data at the given index. + * @param treeId - The tree for which leaf data should be edited. + * @param leaf - The updated leaf value. + * @param index - The index of the leaf to be updated. + */ + updateLeaf(treeId: IndexedTreeId | PublicTreeId, leaf: LeafData | Buffer, index: bigint): Promise; + + /** + * Returns the index containing a leaf value. + * @param treeId - The tree for which the index should be returned. + * @param value - The value to search for in the tree. + */ + findLeafIndex(treeId: MerkleTreeId, value: Buffer): Promise; + + /** + * Gets the value for a leaf in the tree. + * @param treeId - The tree for which the index should be returned. + * @param index - The index of the leaf. + */ + getLeafValue(treeId: MerkleTreeId, index: bigint): Promise; + + /** + * Inserts the new block hash into the new block hashes tree. + * This includes all of the current roots of all of the data trees and the current blocks global vars. + * @param globalVariablesHash - The global variables hash to insert into the block hash. + */ + updateHistoricBlocksTree(globalVariablesHash: Fr): Promise; + + /** + * Updates the latest global variables hash + * @param globalVariablesHash - The latest global variables hash + */ + updateLatestGlobalVariablesHash(globalVariablesHash: Fr): Promise; + + /** + * Gets the global variables hash from the previous block + */ + getLatestGlobalVariablesHash(): Promise; + + /** + * Batch insert multiple leaves into the tree. + * @param leaves - Leaves to insert into the tree. + * @param treeId - The tree on which to insert. + * @param subtreeHeight - Height of the subtree. + * @returns The witness data for the leaves to be updated when inserting the new ones. + */ + batchInsert( + treeId: MerkleTreeId, + leaves: Buffer[], + subtreeHeight: number, + ): Promise<[LowLeafWitnessData[], SiblingPath] | [undefined, SiblingPath]>; + + /** + * Handles a single L2 block (i.e. Inserts the new commitments into the merkle tree). + * @param block - The L2 block to handle. + */ + handleL2Block(block: L2Block): Promise; + + /** + * Commits pending changes to the underlying store. + */ + commit(): Promise; + + /** + * Rolls back pending changes. + */ + rollback(): Promise; +} + +/** Return type for handleL2Block */ +export type HandleL2BlockResult = { + /** Whether the block processed was emitted by our sequencer */ isBlockOurs: boolean; +}; + +/** + * Outputs a tree leaves using for debugging purposes. + */ +export async function inspectTree( + db: MerkleTreeOperations, + treeId: MerkleTreeId, + log = createDebugLogger('aztec:inspect-tree'), +) { + const info = await db.getTreeInfo(treeId); + const output = [`Tree id=${treeId} size=${info.size} root=0x${info.root.toString('hex')}`]; + for (let i = 0; i < info.size; i++) { + output.push( + ` Leaf ${i}: ${await db.getLeafValue(treeId, BigInt(i)).then(x => x?.toString('hex') ?? '[undefined]')}`, + ); + } + log(output.join('\n')); +} From fdc11456ff4ab0fb43881dfe6276fd83ffa21cf7 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Thu, 2 Nov 2023 13:11:35 +0000 Subject: [PATCH 13/29] Remove awaits. --- .../acir-simulator/src/acvm/serialize.ts | 4 +- .../acir-simulator/src/public/index.test.ts | 2 +- yarn-project/acir-simulator/src/utils.ts | 6 +- .../aztec-node/src/aztec-node/server.ts | 1 - .../aztec-sandbox/src/examples/token.ts | 2 +- .../account/defaults/default_entrypoint.ts | 6 +- yarn-project/aztec.js/src/account/utils.ts | 2 +- .../aztec.js/src/contract/contract.test.ts | 4 +- .../token/src/tests/token.contract.test.ts | 56 +++++++++---------- .../crypto/pedersen/index.test.ts | 22 +------- .../src/structs/complete_address.test.ts | 2 +- yarn-project/cli/src/index.ts | 2 +- yarn-project/cli/src/test/utils.test.ts | 2 +- .../end-to-end/src/e2e_2_pxes.test.ts | 2 +- .../end-to-end/src/e2e_block_building.test.ts | 1 - .../src/e2e_cross_chain_messaging.test.ts | 14 ++--- .../src/e2e_escrow_contract.test.ts | 4 +- .../src/e2e_lending_contract.test.ts | 22 ++++---- .../e2e_multiple_accounts_1_enc_key.test.ts | 2 +- .../src/e2e_non_contract_account.test.ts | 2 +- .../e2e_public_cross_chain_messaging.test.ts | 8 +-- .../e2e_public_to_private_messaging.test.ts | 2 +- .../src/e2e_sandbox_example.test.ts | 4 +- .../end-to-end/src/e2e_token_contract.test.ts | 56 +++++++++---------- .../writing_an_account_contract.test.ts | 2 +- .../src/integration_archiver_l1_to_l2.test.ts | 2 +- yarn-project/end-to-end/src/shared/browser.ts | 2 +- yarn-project/end-to-end/src/shared/cli.ts | 2 +- .../src/shared/cross_chain_test_harness.ts | 4 +- .../end-to-end/src/shared/uniswap_l1_l2.ts | 38 ++++++------- .../src/simulators/lending_simulator.ts | 2 +- .../noir-protocol-circuits/src/index.test.ts | 1 - .../src/pxe_service/test/pxe_test_suite.ts | 8 +-- .../src/sequencer/public_processor.test.ts | 2 +- yarn-project/types/src/mocks.ts | 4 +- 35 files changed, 135 insertions(+), 160 deletions(-) diff --git a/yarn-project/acir-simulator/src/acvm/serialize.ts b/yarn-project/acir-simulator/src/acvm/serialize.ts index 18776741e400..213061be319f 100644 --- a/yarn-project/acir-simulator/src/acvm/serialize.ts +++ b/yarn-project/acir-simulator/src/acvm/serialize.ts @@ -187,12 +187,12 @@ export function toAcvmCallPrivateStackItem(item: PrivateCallStackItem): ACVMFiel * @param item - The public call stack item to serialize to be passed onto Noir. * @returns The fields expected by the enqueue_public_function_call_oracle Aztec.nr function. */ -export async function toAcvmEnqueuePublicFunctionResult(item: PublicCallRequest): Promise { +export function toAcvmEnqueuePublicFunctionResult(item: PublicCallRequest): Promise { return [ toACVMField(item.contractAddress), ...toACVMFunctionData(item.functionData), ...toACVMCallContext(item.callContext), - toACVMField(await item.getArgsHash()), + toACVMField(item.getArgsHash()), ]; } diff --git a/yarn-project/acir-simulator/src/public/index.test.ts b/yarn-project/acir-simulator/src/public/index.test.ts index bfc5a131a41a..549f242075d6 100644 --- a/yarn-project/acir-simulator/src/public/index.test.ts +++ b/yarn-project/acir-simulator/src/public/index.test.ts @@ -370,7 +370,7 @@ describe('ACIR public execution simulator', () => { const secret = new Fr(1n); const recipient = AztecAddress.random(); - const preimage = await buildL1ToL2Message( + const preimage = buildL1ToL2Message( getFunctionSelector('mint_public(bytes32,uint256,address)').substring(2), [recipient.toField(), new Fr(bridgedAmount), canceller.toField()], contractAddress, diff --git a/yarn-project/acir-simulator/src/utils.ts b/yarn-project/acir-simulator/src/utils.ts index 1398bcdecc5d..02ad7e0d6dff 100644 --- a/yarn-project/acir-simulator/src/utils.ts +++ b/yarn-project/acir-simulator/src/utils.ts @@ -23,11 +23,7 @@ export function computeSlotForMapping(mappingSlot: Fr, owner: NoirPoint | Fr) { const isFr = (owner: NoirPoint | Fr): owner is Fr => typeof (owner as Fr).value === 'bigint'; const ownerField = isFr(owner) ? owner : new Fr(owner.x); - return Fr.fromBuffer( - pedersenHashInputs( - [mappingSlot, ownerField].map(f => f.toBuffer()), - ), - ); + return Fr.fromBuffer(pedersenHashInputs([mappingSlot, ownerField].map(f => f.toBuffer()))); } /** diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 9ae2dac6f814..bcab5f2c68be 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -1,7 +1,6 @@ import { Archiver } from '@aztec/archiver'; import { CONTRACT_TREE_HEIGHT, - CircuitsWasm, Fr, GlobalVariables, HistoricBlockData, diff --git a/yarn-project/aztec-sandbox/src/examples/token.ts b/yarn-project/aztec-sandbox/src/examples/token.ts index 2d35a5011b7c..14dbcef82e77 100644 --- a/yarn-project/aztec-sandbox/src/examples/token.ts +++ b/yarn-project/aztec-sandbox/src/examples/token.ts @@ -52,7 +52,7 @@ async function main() { // Create a secret and a corresponding hash that will be used to mint funds privately const aliceSecret = Fr.random(); - const aliceSecretHash = await computeMessageSecretHash(aliceSecret); + const aliceSecretHash = computeMessageSecretHash(aliceSecret); const receipt = await tokenAlice.methods.mint_private(ALICE_MINT_BALANCE, aliceSecretHash).send().wait(); // Add the newly created "pending shield" note to PXE diff --git a/yarn-project/aztec.js/src/account/defaults/default_entrypoint.ts b/yarn-project/aztec.js/src/account/defaults/default_entrypoint.ts index 974d0fa6bdee..edff78a592f2 100644 --- a/yarn-project/aztec.js/src/account/defaults/default_entrypoint.ts +++ b/yarn-project/aztec.js/src/account/defaults/default_entrypoint.ts @@ -19,10 +19,10 @@ export class DefaultAccountEntrypoint implements EntrypointInterface { ) {} async createTxExecutionRequest(executions: FunctionCall[]): Promise { - const { payload, packedArguments: callsPackedArguments } = await buildPayload(executions); + const { payload, packedArguments: callsPackedArguments } = buildPayload(executions); const abi = this.getEntrypointAbi(); - const packedArgs = await PackedArguments.fromArgs(encodeArguments(abi, [payload])); - const message = Fr.fromBuffer(await hashPayload(payload)); + const packedArgs = PackedArguments.fromArgs(encodeArguments(abi, [payload])); + const message = Fr.fromBuffer(hashPayload(payload)); const authWitness = await this.auth.createAuthWitness(message); const txRequest = TxExecutionRequest.from({ argsHash: packedArgs.hash, diff --git a/yarn-project/aztec.js/src/account/utils.ts b/yarn-project/aztec.js/src/account/utils.ts index 0890a3eff461..f6309b90ee73 100644 --- a/yarn-project/aztec.js/src/account/utils.ts +++ b/yarn-project/aztec.js/src/account/utils.ts @@ -19,7 +19,7 @@ export function createAccount(pxe: PXE): Promise { * @returns Complete address of the registered recipient. */ export async function createRecipient(pxe: PXE): Promise { - const completeAddress = await CompleteAddress.random(); + const completeAddress = CompleteAddress.random(); await pxe.registerRecipient(completeAddress); return completeAddress; } diff --git a/yarn-project/aztec.js/src/contract/contract.test.ts b/yarn-project/aztec.js/src/contract/contract.test.ts index 4852169b3a52..41e3cc5b9b19 100644 --- a/yarn-project/aztec.js/src/contract/contract.test.ts +++ b/yarn-project/aztec.js/src/contract/contract.test.ts @@ -95,10 +95,10 @@ describe('Contract Class', () => { events: [], }; - beforeEach(async () => { + beforeEach(() => { resolvedExtendedContractData = ExtendedContractData.random(); contractAddress = resolvedExtendedContractData.contractData.contractAddress; - account = await CompleteAddress.random(); + account = CompleteAddress.random(); wallet = mock(); wallet.createTxExecutionRequest.mockResolvedValue(mockTxRequest); diff --git a/yarn-project/boxes/token/src/tests/token.contract.test.ts b/yarn-project/boxes/token/src/tests/token.contract.test.ts index 27d8bb5fef89..0ec4dee07cc2 100644 --- a/yarn-project/boxes/token/src/tests/token.contract.test.ts +++ b/yarn-project/boxes/token/src/tests/token.contract.test.ts @@ -161,8 +161,8 @@ describe('e2e_token_contract', () => { let secretHash: Fr; let txHash: TxHash; - beforeAll(async () => { - secretHash = await computeMessageSecretHash(secret); + beforeAll(() => { + secretHash = computeMessageSecretHash(secret); }); describe('Mint flow', () => { @@ -258,7 +258,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); // docs:end:authwit_public_transfer_example @@ -319,7 +319,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // We need to compute the message we want to sign and add it to the wallet as approved await wallets[0].setPublicAuth(messageHash, true).send().wait(); @@ -342,7 +342,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[0].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[0].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); @@ -364,7 +364,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[0].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[0].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); // Perform the transfer @@ -409,7 +409,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // docs:end:authwit_computeAuthWitMessageHash const witness = await wallets[0].createAuthWitness(messageHash); @@ -460,7 +460,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -484,7 +484,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await expect(action.simulate()).rejects.toThrowError( `Unknown auth witness for message hash 0x${messageHash.toString('hex')}`, @@ -501,8 +501,8 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[2]) .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); - const expectedMessageHash = await computeAuthWitMessageHash(accounts[2].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); + const expectedMessageHash = computeAuthWitMessageHash(accounts[2].address, action.request()); const witness = await wallets[0].createAuthWitness(messageHash); await wallets[2].addAuthWitness(witness); @@ -520,8 +520,8 @@ describe('e2e_token_contract', () => { const secret = Fr.random(); let secretHash: Fr; - beforeAll(async () => { - secretHash = await computeMessageSecretHash(secret); + beforeAll(() => { + secretHash = computeMessageSecretHash(secret); }); it('on behalf of self', async () => { @@ -553,7 +553,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.shield(accounts[0].address, amount, secretHash, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); const tx = action.send(); @@ -608,7 +608,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.shield(accounts[0].address, amount, secretHash, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); await expect(action.simulate()).rejects.toThrowError('Assertion failed: Underflow'); @@ -622,7 +622,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[2]).methods.shield(accounts[0].address, amount, secretHash, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); await expect(action.simulate()).rejects.toThrowError('Assertion failed: Message not authorized by account'); @@ -664,7 +664,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -716,7 +716,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -737,8 +737,8 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[2]) .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); - const expectedMessageHash = await computeAuthWitMessageHash(accounts[2].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); + const expectedMessageHash = computeAuthWitMessageHash(accounts[2].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -774,7 +774,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); const tx = action.send(); @@ -825,7 +825,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); await expect(action.simulate()).rejects.toThrowError('Assertion failed: Underflow'); @@ -839,7 +839,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[0].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[0].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); await expect( @@ -868,7 +868,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -913,7 +913,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -932,7 +932,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await expect(action.simulate()).rejects.toThrowError( `Unknown auth witness for message hash 0x${messageHash.toString('hex')}`, @@ -947,8 +947,8 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[2]).methods.burn(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); - const expectedMessageHash = await computeAuthWitMessageHash(accounts[2].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); + const expectedMessageHash = computeAuthWitMessageHash(accounts[2].address, action.request()); const witness = await wallets[0].createAuthWitness(messageHash); await wallets[2].addAuthWitness(witness); diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts index c9966dcde4eb..27b823762adf 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts @@ -11,25 +11,7 @@ describe('pedersen', () => { for (let i = 0; i < loops; ++i) { pedersenCommit([fields[i * 2], fields[i * 2 + 1]]); } - console.log(t.us() / loops); - // console.log(pedersenCommitWasm(wasm, [toBufferBE(1n, 32), toBufferBE(1n, 32)])); + // console.log(t.us() / loops); + expect(t.us() / loops).toBeLessThan(500); }); - - // it('pedersen perf elliptic', () => { - // const t = new Timer(); - // for (let i = 0; i < loops; ++i) { - // pedersenCommit([fields[i * 2], fields[i * 2 + 1]]); - // } - // console.log(t.us() / loops); - // // console.log(pedersenCommit([toBufferBE(1n, 32), toBufferBE(1n, 32)])); - // }); - - // it('pedersen perf noble', () => { - // const loops = 10000; - // const t = new Timer(); - // for (let i = 0; i < loops; ++i) { - // pedersenCommitNoble([toBufferBE(1n, 32), toBufferBE(1n, 32)]); - // } - // console.log(t.us() / loops); - // }); }); diff --git a/yarn-project/circuits.js/src/structs/complete_address.test.ts b/yarn-project/circuits.js/src/structs/complete_address.test.ts index 2809fdbed506..c3047a267cb7 100644 --- a/yarn-project/circuits.js/src/structs/complete_address.test.ts +++ b/yarn-project/circuits.js/src/structs/complete_address.test.ts @@ -4,7 +4,7 @@ import { Fr, Point } from '@aztec/foundation/fields'; import { CompleteAddress } from './complete_address.js'; describe('CompleteAddress', () => { - it('refuses to add an account with incorrect address for given partial address and pubkey', async () => { + it('refuses to add an account with incorrect address for given partial address and pubkey', () => { expect(() => CompleteAddress.create(AztecAddress.random(), Point.random(), Fr.random())).toThrowError( /cannot be derived/, ); diff --git a/yarn-project/cli/src/index.ts b/yarn-project/cli/src/index.ts index 2dd5ae417391..a6e421fa2ab2 100644 --- a/yarn-project/cli/src/index.ts +++ b/yarn-project/cli/src/index.ts @@ -433,7 +433,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { .addOption(pxeOption) .action(async ({ address, publicKey, partialAddress, rpcUrl }) => { const client = await createCompatibleClient(rpcUrl, debugLogger); - await client.registerRecipient(await CompleteAddress.create(address, publicKey, partialAddress)); + await client.registerRecipient(CompleteAddress.create(address, publicKey, partialAddress)); log(`\nRegistered details for account with address: ${address}\n`); }); diff --git a/yarn-project/cli/src/test/utils.test.ts b/yarn-project/cli/src/test/utils.test.ts index aea7a8bbfc66..28dac48c874d 100644 --- a/yarn-project/cli/src/test/utils.test.ts +++ b/yarn-project/cli/src/test/utils.test.ts @@ -33,7 +33,7 @@ describe('CLI Utils', () => { expect(result).toEqual(aztecAddress); // returns an address found in the aztec client - const completeAddress = await CompleteAddress.random(); + const completeAddress = CompleteAddress.random(); client.getRegisteredAccounts.mockResolvedValueOnce([completeAddress]); const resultWithoutString = await getTxSender(client); expect(client.getRegisteredAccounts).toHaveBeenCalled(); diff --git a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts index a429175bb9fd..21a750ab5f54 100644 --- a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts +++ b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts @@ -90,7 +90,7 @@ describe('e2e_2_pxes', () => { const mintTokens = async (contract: TokenContract, recipient: AztecAddress, balance: bigint, pxe: PXE) => { const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const receipt = await contract.methods.mint_private(balance, secretHash).send().wait(); expect(receipt.status).toEqual(TxStatus.MINED); diff --git a/yarn-project/end-to-end/src/e2e_block_building.test.ts b/yarn-project/end-to-end/src/e2e_block_building.test.ts index 6451391f5a04..1a29e9a0c38a 100644 --- a/yarn-project/end-to-end/src/e2e_block_building.test.ts +++ b/yarn-project/end-to-end/src/e2e_block_building.test.ts @@ -6,7 +6,6 @@ import { Wallet, isContractDeployed, } from '@aztec/aztec.js'; -import { CircuitsWasm } from '@aztec/circuits.js'; import { pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; import { DebugLogger } from '@aztec/foundation/log'; import { TestContractArtifact } from '@aztec/noir-contracts/artifacts'; diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts index 457ff3a7431f..d32698927763 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts @@ -59,9 +59,9 @@ describe('e2e_cross_chain_messaging', () => { const bridgeAmount = 100n; const [secretForL2MessageConsumption, secretHashForL2MessageConsumption] = - await crossChainTestHarness.generateClaimSecret(); + crossChainTestHarness.generateClaimSecret(); const [secretForRedeemingMintedNotes, secretHashForRedeemingMintedNotes] = - await crossChainTestHarness.generateClaimSecret(); + crossChainTestHarness.generateClaimSecret(); // 1. Mint tokens on L1 await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); @@ -99,7 +99,7 @@ describe('e2e_cross_chain_messaging', () => { // 4. Give approval to bridge to burn owner's funds: const withdrawAmount = 9n; const nonce = Fr.random(); - const burnMessageHash = await computeAuthWitMessageHash( + const burnMessageHash = computeAuthWitMessageHash( l2Bridge.address, l2Token.methods.burn(ownerAddress, withdrawAmount, nonce).request(), ); @@ -124,9 +124,9 @@ describe('e2e_cross_chain_messaging', () => { const l1TokenBalance = 1000000n; const bridgeAmount = 100n; const [secretForL2MessageConsumption, secretHashForL2MessageConsumption] = - await crossChainTestHarness.generateClaimSecret(); + crossChainTestHarness.generateClaimSecret(); const [secretForRedeemingMintedNotes, secretHashForRedeemingMintedNotes] = - await crossChainTestHarness.generateClaimSecret(); + crossChainTestHarness.generateClaimSecret(); await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); const messageKey = await crossChainTestHarness.sendTokensToPortalPrivate( @@ -190,7 +190,7 @@ describe('e2e_cross_chain_messaging', () => { const withdrawAmount = 9n; const nonce = Fr.random(); - const expectedBurnMessageHash = await computeAuthWitMessageHash( + const expectedBurnMessageHash = computeAuthWitMessageHash( l2Bridge.address, l2Token.methods.burn(user1Wallet.getAddress(), withdrawAmount, nonce).request(), ); @@ -210,7 +210,7 @@ describe('e2e_cross_chain_messaging', () => { // 2. Deposit tokens to the TokenPortal privately const [secretForL2MessageConsumption, secretHashForL2MessageConsumption] = - await crossChainTestHarness.generateClaimSecret(); + crossChainTestHarness.generateClaimSecret(); const messageKey = await crossChainTestHarness.sendTokensToPortalPrivate( Fr.random(), diff --git a/yarn-project/end-to-end/src/e2e_escrow_contract.test.ts b/yarn-project/end-to-end/src/e2e_escrow_contract.test.ts index 968a8a4b7757..9409e953b6cb 100644 --- a/yarn-project/end-to-end/src/e2e_escrow_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_escrow_contract.test.ts @@ -61,7 +61,7 @@ describe('e2e_escrow_contract', () => { const mintAmount = 100n; const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const receipt = await token.methods.mint_private(mintAmount, secretHash).send().wait(); expect(receipt.status).toEqual(TxStatus.MINED); @@ -108,7 +108,7 @@ describe('e2e_escrow_contract', () => { logger(`Minting funds in token contract to ${owner}`); const mintAmount = 50n; const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const receipt = await token.methods.mint_private(mintAmount, secretHash).send().wait(); expect(receipt.status).toEqual(TxStatus.MINED); diff --git a/yarn-project/end-to-end/src/e2e_lending_contract.test.ts b/yarn-project/end-to-end/src/e2e_lending_contract.test.ts index 9fe151d549a7..06f198a0440d 100644 --- a/yarn-project/end-to-end/src/e2e_lending_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_lending_contract.test.ts @@ -113,7 +113,7 @@ describe('e2e_lending_contract', () => { const mintAmount = 10000n; for (const asset of assets) { const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const a = asset.methods.mint_public(lendingAccount.address, mintAmount).send(); const b = asset.methods.mint_private(mintAmount, secretHash).send(); @@ -150,7 +150,7 @@ describe('e2e_lending_contract', () => { it('Depositing 🥸 : 💰 -> 🏦', async () => { const depositAmount = 420n; const nonce = Fr.random(); - const messageHash = await computeAuthWitMessageHash( + const messageHash = computeAuthWitMessageHash( lendingContract.address, collateralAsset.methods .unshield(lendingAccount.address, lendingContract.address, depositAmount, nonce) @@ -159,7 +159,7 @@ describe('e2e_lending_contract', () => { await wallet.createAuthWitness(Fr.fromBuffer(messageHash)); await lendingSim.progressTime(TIME_JUMP); - lendingSim.depositPrivate(lendingAccount.address, await lendingAccount.key(), depositAmount); + lendingSim.depositPrivate(lendingAccount.address, lendingAccount.key(), depositAmount); // Make a private deposit of funds into own account. // This should: @@ -184,7 +184,7 @@ describe('e2e_lending_contract', () => { it('Depositing 🥸 on behalf of recipient: 💰 -> 🏦', async () => { const depositAmount = 421n; const nonce = Fr.random(); - const messageHash = await computeAuthWitMessageHash( + const messageHash = computeAuthWitMessageHash( lendingContract.address, collateralAsset.methods .unshield(lendingAccount.address, lendingContract.address, depositAmount, nonce) @@ -218,7 +218,7 @@ describe('e2e_lending_contract', () => { const depositAmount = 211n; const nonce = Fr.random(); - const messageHash = await computeAuthWitMessageHash( + const messageHash = computeAuthWitMessageHash( lendingContract.address, collateralAsset.methods .transfer_public(lendingAccount.address, lendingContract.address, depositAmount, nonce) @@ -262,7 +262,7 @@ describe('e2e_lending_contract', () => { it('Borrow 🥸 : 🏦 -> 🍌', async () => { const borrowAmount = 69n; await lendingSim.progressTime(TIME_JUMP); - lendingSim.borrow(await lendingAccount.key(), lendingAccount.address, borrowAmount); + lendingSim.borrow(lendingAccount.key(), lendingAccount.address, borrowAmount); // Make a private borrow using the private account // This should: @@ -296,14 +296,14 @@ describe('e2e_lending_contract', () => { it('Repay 🥸 : 🍌 -> 🏦', async () => { const repayAmount = 20n; const nonce = Fr.random(); - const messageHash = await computeAuthWitMessageHash( + const messageHash = computeAuthWitMessageHash( lendingContract.address, stableCoin.methods.burn(lendingAccount.address, repayAmount, nonce).request(), ); await wallet.createAuthWitness(Fr.fromBuffer(messageHash)); await lendingSim.progressTime(TIME_JUMP); - lendingSim.repayPrivate(lendingAccount.address, await lendingAccount.key(), repayAmount); + lendingSim.repayPrivate(lendingAccount.address, lendingAccount.key(), repayAmount); // Make a private repay of the debt in the private account // This should: @@ -322,7 +322,7 @@ describe('e2e_lending_contract', () => { it('Repay 🥸 on behalf of public: 🍌 -> 🏦', async () => { const repayAmount = 21n; const nonce = Fr.random(); - const messageHash = await computeAuthWitMessageHash( + const messageHash = computeAuthWitMessageHash( lendingContract.address, stableCoin.methods.burn(lendingAccount.address, repayAmount, nonce).request(), ); @@ -349,7 +349,7 @@ describe('e2e_lending_contract', () => { const repayAmount = 20n; const nonce = Fr.random(); - const messageHash = await computeAuthWitMessageHash( + const messageHash = computeAuthWitMessageHash( lendingContract.address, stableCoin.methods.burn_public(lendingAccount.address, repayAmount, nonce).request(), ); @@ -392,7 +392,7 @@ describe('e2e_lending_contract', () => { it('Withdraw 🥸 : 🏦 -> 💰', async () => { const withdrawAmount = 42n; await lendingSim.progressTime(TIME_JUMP); - lendingSim.withdraw(await lendingAccount.key(), lendingAccount.address, withdrawAmount); + lendingSim.withdraw(lendingAccount.key(), lendingAccount.address, withdrawAmount); // Withdraw funds from the private account // This should: diff --git a/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts b/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts index 1222245d6ea4..8a6abdcaf727 100644 --- a/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts +++ b/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts @@ -69,7 +69,7 @@ describe('e2e_multiple_accounts_1_enc_key', () => { logger(`Token deployed at ${tokenAddress}`); const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const receipt = await token.methods.mint_private(initialBalance, secretHash).send().wait(); expect(receipt.status).toEqual(TxStatus.MINED); diff --git a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts index 3cd89b236a8e..5c3c23d05984 100644 --- a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts +++ b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts @@ -1,5 +1,5 @@ import { SignerlessWallet, Wallet } from '@aztec/aztec.js'; -import { CircuitsWasm, Fr } from '@aztec/circuits.js'; +import { Fr } from '@aztec/circuits.js'; import { siloNullifier } from '@aztec/circuits.js/abis'; import { DebugLogger } from '@aztec/foundation/log'; import { toBigInt } from '@aztec/foundation/serialize'; diff --git a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts index d42b21af784f..960aed46e147 100644 --- a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts @@ -54,7 +54,7 @@ describe('e2e_public_cross_chain_messaging', () => { const l1TokenBalance = 1000000n; const bridgeAmount = 100n; - const [secret, secretHash] = await crossChainTestHarness.generateClaimSecret(); + const [secret, secretHash] = crossChainTestHarness.generateClaimSecret(); // 1. Mint tokens on L1 await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); @@ -83,7 +83,7 @@ describe('e2e_public_cross_chain_messaging', () => { // 4. Give approval to bridge to burn owner's funds: const withdrawAmount = 9n; const nonce = Fr.random(); - const burnMessageHash = await computeAuthWitMessageHash( + const burnMessageHash = computeAuthWitMessageHash( l2Bridge.address, l2Token.methods.burn_public(ownerAddress, withdrawAmount, nonce).request(), ); @@ -110,7 +110,7 @@ describe('e2e_public_cross_chain_messaging', () => { const l1TokenBalance = 1000000n; const bridgeAmount = 100n; - const [secret, secretHash] = await crossChainTestHarness.generateClaimSecret(); + const [secret, secretHash] = crossChainTestHarness.generateClaimSecret(); await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); const messageKey = await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount, secretHash); @@ -162,7 +162,7 @@ describe('e2e_public_cross_chain_messaging', () => { it("can't claim funds privately which were intended for public deposit from the token portal", async () => { const bridgeAmount = 100n; - const [secret, secretHash] = await crossChainTestHarness.generateClaimSecret(); + const [secret, secretHash] = crossChainTestHarness.generateClaimSecret(); await crossChainTestHarness.mintTokensOnL1(bridgeAmount); const messageKey = await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount, secretHash); diff --git a/yarn-project/end-to-end/src/e2e_public_to_private_messaging.test.ts b/yarn-project/end-to-end/src/e2e_public_to_private_messaging.test.ts index 87bfafa399fe..1134b67c8d28 100644 --- a/yarn-project/end-to-end/src/e2e_public_to_private_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_public_to_private_messaging.test.ts @@ -46,7 +46,7 @@ describe('e2e_public_to_private_messaging', () => { const bridgeAmount = 100n; const shieldAmount = 50n; - const [secret, secretHash] = await crossChainTestHarness.generateClaimSecret(); + const [secret, secretHash] = crossChainTestHarness.generateClaimSecret(); await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); const messageKey = await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount, secretHash); diff --git a/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts b/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts index 0d1cb02d933a..abcfeacd34c7 100644 --- a/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts +++ b/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts @@ -69,7 +69,7 @@ describe('e2e_sandbox_example', () => { // Create a secret and a corresponding hash that will be used to mint funds privately const aliceSecret = Fr.random(); - const aliceSecretHash = await computeMessageSecretHash(aliceSecret); + const aliceSecretHash = computeMessageSecretHash(aliceSecret); logger(`Minting tokens to Alice...`); // Mint the initial supply privately "to secret hash" @@ -136,7 +136,7 @@ describe('e2e_sandbox_example', () => { await tokenContractAlice.methods.set_minter(bob, true).send().wait(); const bobSecret = Fr.random(); - const bobSecretHash = await computeMessageSecretHash(bobSecret); + const bobSecretHash = computeMessageSecretHash(bobSecret); // Bob now has a secret 🥷 const mintQuantity = 10_000n; diff --git a/yarn-project/end-to-end/src/e2e_token_contract.test.ts b/yarn-project/end-to-end/src/e2e_token_contract.test.ts index 34c9a3d7bfc4..bbb174b94572 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract.test.ts @@ -154,8 +154,8 @@ describe('e2e_token_contract', () => { let secretHash: Fr; let txHash: TxHash; - beforeAll(async () => { - secretHash = await computeMessageSecretHash(secret); + beforeAll(() => { + secretHash = computeMessageSecretHash(secret); }); describe('Mint flow', () => { @@ -255,7 +255,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); // docs:end:authwit_public_transfer_example @@ -316,7 +316,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // We need to compute the message we want to sign and add it to the wallet as approved await wallets[0].setPublicAuth(messageHash, true).send().wait(); @@ -339,7 +339,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[0].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[0].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); @@ -361,7 +361,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[0].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[0].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); // Perform the transfer @@ -413,7 +413,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // docs:end:authwit_computeAuthWitMessageHash const witness = await wallets[0].createAuthWitness(messageHash); @@ -464,7 +464,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -495,7 +495,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await expect(action.simulate()).rejects.toThrowError( `Unknown auth witness for message hash 0x${messageHash.toString('hex')}`, @@ -512,8 +512,8 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[2]) .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); - const expectedMessageHash = await computeAuthWitMessageHash(accounts[2].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); + const expectedMessageHash = computeAuthWitMessageHash(accounts[2].address, action.request()); const witness = await wallets[0].createAuthWitness(messageHash); await wallets[2].addAuthWitness(witness); @@ -531,8 +531,8 @@ describe('e2e_token_contract', () => { const secret = Fr.random(); let secretHash: Fr; - beforeAll(async () => { - secretHash = await computeMessageSecretHash(secret); + beforeAll(() => { + secretHash = computeMessageSecretHash(secret); }); it('on behalf of self', async () => { @@ -564,7 +564,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.shield(accounts[0].address, amount, secretHash, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); const tx = action.send(); @@ -619,7 +619,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.shield(accounts[0].address, amount, secretHash, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); await expect(action.simulate()).rejects.toThrowError('Assertion failed: Underflow'); @@ -633,7 +633,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[2]).methods.shield(accounts[0].address, amount, secretHash, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); await expect(action.simulate()).rejects.toThrowError('Assertion failed: Message not authorized by account'); @@ -675,7 +675,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -727,7 +727,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -748,8 +748,8 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[2]) .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); - const expectedMessageHash = await computeAuthWitMessageHash(accounts[2].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); + const expectedMessageHash = computeAuthWitMessageHash(accounts[2].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -785,7 +785,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); const tx = action.send(); @@ -836,7 +836,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); await expect(action.simulate()).rejects.toThrowError('Assertion failed: Underflow'); @@ -850,7 +850,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[0].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[0].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); await expect( @@ -879,7 +879,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -924,7 +924,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -943,7 +943,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await expect(action.simulate()).rejects.toThrowError( `Unknown auth witness for message hash 0x${messageHash.toString('hex')}`, @@ -958,8 +958,8 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[2]).methods.burn(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); - const expectedMessageHash = await computeAuthWitMessageHash(accounts[2].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); + const expectedMessageHash = computeAuthWitMessageHash(accounts[2].address, action.request()); const witness = await wallets[0].createAuthWitness(messageHash); await wallets[2].addAuthWitness(witness); diff --git a/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts b/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts index e87c7af4970e..78ff082d93c9 100644 --- a/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts +++ b/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts @@ -65,7 +65,7 @@ describe('guides/writing_an_account_contract', () => { logger(`Deployed token contract at ${token.address}`); const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const mintAmount = 50n; const receipt = await token.methods.mint_private(mintAmount, secretHash).send().wait(); diff --git a/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts b/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts index eb1fe393d185..18b668aca7cb 100644 --- a/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts +++ b/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts @@ -73,7 +73,7 @@ describe('archiver integration with l1 to l2 messages', () => { // Generate a claim secret using pedersen logger("Generating a claim secret using pedersen's hash function"); const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const secretString = `0x${secretHash.toBuffer().toString('hex')}` as `0x${string}`; logger('Generated claim secret: ' + secretString); diff --git a/yarn-project/end-to-end/src/shared/browser.ts b/yarn-project/end-to-end/src/shared/browser.ts index 95ded0f40c56..f28f847e2e86 100644 --- a/yarn-project/end-to-end/src/shared/browser.ts +++ b/yarn-project/end-to-end/src/shared/browser.ts @@ -199,7 +199,7 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL const token = await Contract.at(receipt.contractAddress!, TokenContractArtifact, owner); const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const mintPrivateReceipt = await token.methods.mint_private(initialBalance, secretHash).send().wait(); const storageSlot = new Fr(5); diff --git a/yarn-project/end-to-end/src/shared/cli.ts b/yarn-project/end-to-end/src/shared/cli.ts index bcc500edc9ff..59de7abe3b50 100644 --- a/yarn-project/end-to-end/src/shared/cli.ts +++ b/yarn-project/end-to-end/src/shared/cli.ts @@ -131,7 +131,7 @@ export const cliTestSuite = ( expect(checkResult).toEqual(deployedContract?.contractAddress.toString()); const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); debug('Mint initial tokens.'); await run( diff --git a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts index e24619285114..c0d3bf0e2a58 100644 --- a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts +++ b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts @@ -202,10 +202,10 @@ export class CrossChainTestHarness { public ownerAddress: AztecAddress, ) {} - async generateClaimSecret(): Promise<[Fr, Fr]> { + generateClaimSecret(): [Fr, Fr] { this.logger("Generating a claim secret using pedersen's hash function"); const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); this.logger('Generated claim secret: ' + secretHash.toString(true)); return [secret, secretHash]; } diff --git a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts index 44a7584523f3..3825ed735a72 100644 --- a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts +++ b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts @@ -156,8 +156,8 @@ export const uniswapL1L2TestSuite = ( const wethL1BeforeBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress); // 1. Approve and deposit weth to the portal and move to L2 - const [secretForMintingWeth, secretHashForMintingWeth] = await wethCrossChainHarness.generateClaimSecret(); - const [secretForRedeemingWeth, secretHashForRedeemingWeth] = await wethCrossChainHarness.generateClaimSecret(); + const [secretForMintingWeth, secretHashForMintingWeth] = wethCrossChainHarness.generateClaimSecret(); + const [secretForRedeemingWeth, secretHashForRedeemingWeth] = wethCrossChainHarness.generateClaimSecret(); const messageKey = await wethCrossChainHarness.sendTokensToPortalPrivate( secretHashForRedeemingWeth, @@ -200,7 +200,7 @@ export const uniswapL1L2TestSuite = ( // 3. Owner gives uniswap approval to unshield funds to self on its behalf logger('Approving uniswap to unshield funds to self on my behalf'); const nonceForWETHUnshieldApproval = new Fr(1n); - const unshieldToUniswapMessageHash = await computeAuthWitMessageHash( + const unshieldToUniswapMessageHash = computeAuthWitMessageHash( uniswapL2Contract.address, wethCrossChainHarness.l2Token.methods .unshield(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHUnshieldApproval) @@ -211,8 +211,8 @@ export const uniswapL1L2TestSuite = ( // 4. Swap on L1 - sends L2 to L1 message to withdraw WETH to L1 and another message to swap assets. logger('Withdrawing weth to L1 and sending message to swap to dai'); const [secretForDepositingSwappedDai, secretHashForDepositingSwappedDai] = - await daiCrossChainHarness.generateClaimSecret(); - const [secretForRedeemingDai, secretHashForRedeemingDai] = await daiCrossChainHarness.generateClaimSecret(); + daiCrossChainHarness.generateClaimSecret(); + const [secretForRedeemingDai, secretHashForRedeemingDai] = daiCrossChainHarness.generateClaimSecret(); const withdrawReceipt = await uniswapL2Contract.methods .swap_private( @@ -304,7 +304,7 @@ export const uniswapL1L2TestSuite = ( const wethL1BeforeBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress); // 1. Approve and deposit weth to the portal and move to L2 - const [secretForMintingWeth, secretHashForMintingWeth] = await wethCrossChainHarness.generateClaimSecret(); + const [secretForMintingWeth, secretHashForMintingWeth] = wethCrossChainHarness.generateClaimSecret(); const messageKey = await wethCrossChainHarness.sendTokensToPortalPublic( wethAmountToBridge, @@ -339,7 +339,7 @@ export const uniswapL1L2TestSuite = ( // 3. Owner gives uniswap approval to transfer funds on its behalf const nonceForWETHTransferApproval = new Fr(1n); - const transferMessageHash = await computeAuthWitMessageHash( + const transferMessageHash = computeAuthWitMessageHash( uniswapL2Contract.address, wethCrossChainHarness.l2Token.methods .transfer_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval) @@ -353,7 +353,7 @@ export const uniswapL1L2TestSuite = ( // 4. Swap on L1 - sends L2 to L1 message to withdraw WETH to L1 and another message to swap assets. const [secretForDepositingSwappedDai, secretHashForDepositingSwappedDai] = - await daiCrossChainHarness.generateClaimSecret(); + daiCrossChainHarness.generateClaimSecret(); // 4.1 Owner approves user to swap on their behalf: const nonceForSwap = new Fr(3n); @@ -374,7 +374,7 @@ export const uniswapL1L2TestSuite = ( ownerEthAddress, nonceForSwap, ); - const swapMessageHash = await computeAuthWitMessageHash(sponsorAddress, action.request()); + const swapMessageHash = computeAuthWitMessageHash(sponsorAddress, action.request()); await ownerWallet.setPublicAuth(swapMessageHash, true).send().wait(); // 4.2 Call swap_public from user2 on behalf of owner @@ -451,7 +451,7 @@ export const uniswapL1L2TestSuite = ( // swap should fail since no withdraw approval to uniswap: const nonceForWETHUnshieldApproval = new Fr(2n); - const expectedMessageHash = await computeAuthWitMessageHash( + const expectedMessageHash = computeAuthWitMessageHash( uniswapL2Contract.address, wethCrossChainHarness.l2Token.methods .unshield(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHUnshieldApproval) @@ -480,7 +480,7 @@ export const uniswapL1L2TestSuite = ( it("can't swap if user passes a token different to what the bridge tracks", async () => { // 1. give user private funds on L2: - const [secretForRedeemingWeth, secretHashForRedeemingWeth] = await wethCrossChainHarness.generateClaimSecret(); + const [secretForRedeemingWeth, secretHashForRedeemingWeth] = wethCrossChainHarness.generateClaimSecret(); await wethCrossChainHarness.mintTokensPrivateOnL2(wethAmountToBridge, secretHashForRedeemingWeth); await wethCrossChainHarness.redeemShieldPrivatelyOnL2(wethAmountToBridge, secretForRedeemingWeth); await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethAmountToBridge); @@ -488,7 +488,7 @@ export const uniswapL1L2TestSuite = ( // 2. owner gives uniswap approval to unshield funds: logger('Approving uniswap to unshield funds to self on my behalf'); const nonceForWETHUnshieldApproval = new Fr(3n); - const unshieldToUniswapMessageHash = await computeAuthWitMessageHash( + const unshieldToUniswapMessageHash = computeAuthWitMessageHash( uniswapL2Contract.address, wethCrossChainHarness.l2Token.methods .unshield(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHUnshieldApproval) @@ -526,7 +526,7 @@ export const uniswapL1L2TestSuite = ( // 2. Give approval to uniswap to transfer funds to itself const nonceForWETHTransferApproval = new Fr(2n); - const transferMessageHash = await computeAuthWitMessageHash( + const transferMessageHash = computeAuthWitMessageHash( uniswapL2Contract.address, wethCrossChainHarness.l2Token.methods .transfer_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval) @@ -535,7 +535,7 @@ export const uniswapL1L2TestSuite = ( await ownerWallet.setPublicAuth(transferMessageHash, true).send().wait(); // No approval to call `swap` but should work even without it: - const [_, secretHashForDepositingSwappedDai] = await daiCrossChainHarness.generateClaimSecret(); + const [_, secretHashForDepositingSwappedDai] = daiCrossChainHarness.generateClaimSecret(); const withdrawReceipt = await uniswapL2Contract.methods .swap_public( @@ -584,7 +584,7 @@ export const uniswapL1L2TestSuite = ( ownerEthAddress, nonceForSwap, ); - const swapMessageHash = await computeAuthWitMessageHash(approvedUser, action.request()); + const swapMessageHash = computeAuthWitMessageHash(approvedUser, action.request()); await ownerWallet.setPublicAuth(swapMessageHash, true).send().wait(); // Swap! @@ -597,7 +597,7 @@ export const uniswapL1L2TestSuite = ( // swap should fail since no transfer approval to uniswap: const nonceForWETHTransferApproval = new Fr(4n); - const transferMessageHash = await computeAuthWitMessageHash( + const transferMessageHash = computeAuthWitMessageHash( uniswapL2Contract.address, wethCrossChainHarness.l2Token.methods .transfer_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval) @@ -629,7 +629,7 @@ export const uniswapL1L2TestSuite = ( // tests when trying to mix private and public flows: it("can't call swap_public on L1 if called swap_private on L2", async () => { // get tokens on L2: - const [secretForRedeemingWeth, secretHashForRedeemingWeth] = await wethCrossChainHarness.generateClaimSecret(); + const [secretForRedeemingWeth, secretHashForRedeemingWeth] = wethCrossChainHarness.generateClaimSecret(); logger('minting weth on L2'); await wethCrossChainHarness.mintTokensPrivateOnL2(wethAmountToBridge, secretHashForRedeemingWeth); await wethCrossChainHarness.redeemShieldPrivatelyOnL2(wethAmountToBridge, secretForRedeemingWeth); @@ -638,7 +638,7 @@ export const uniswapL1L2TestSuite = ( logger('Approving uniswap to unshield funds to self on my behalf'); const nonceForWETHUnshieldApproval = new Fr(4n); - const unshieldToUniswapMessageHash = await computeAuthWitMessageHash( + const unshieldToUniswapMessageHash = computeAuthWitMessageHash( uniswapL2Contract.address, wethCrossChainHarness.l2Token.methods .unshield(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHUnshieldApproval) @@ -699,7 +699,7 @@ export const uniswapL1L2TestSuite = ( // Owner gives uniswap approval to transfer funds on its behalf const nonceForWETHTransferApproval = new Fr(5n); - const transferMessageHash = await computeAuthWitMessageHash( + const transferMessageHash = computeAuthWitMessageHash( uniswapL2Contract.address, wethCrossChainHarness.l2Token.methods .transfer_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval) diff --git a/yarn-project/end-to-end/src/simulators/lending_simulator.ts b/yarn-project/end-to-end/src/simulators/lending_simulator.ts index 62dcd17b700a..a0c87b1ffc64 100644 --- a/yarn-project/end-to-end/src/simulators/lending_simulator.ts +++ b/yarn-project/end-to-end/src/simulators/lending_simulator.ts @@ -1,6 +1,6 @@ // Convenience struct to hold an account's address and secret that can easily be passed around. import { CheatCodes } from '@aztec/aztec.js'; -import { AztecAddress, CircuitsWasm, Fr } from '@aztec/circuits.js'; +import { AztecAddress, Fr } from '@aztec/circuits.js'; import { pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; import { LendingContract } from '@aztec/noir-contracts/types'; diff --git a/yarn-project/noir-protocol-circuits/src/index.test.ts b/yarn-project/noir-protocol-circuits/src/index.test.ts index d06ec7af0a41..893dcafc3381 100644 --- a/yarn-project/noir-protocol-circuits/src/index.test.ts +++ b/yarn-project/noir-protocol-circuits/src/index.test.ts @@ -3,7 +3,6 @@ import { AztecAddress, CONTRACT_TREE_HEIGHT, CallContext, - CircuitsWasm, CombinedAccumulatedData, CombinedConstantData, ContractDeploymentData, diff --git a/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts b/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts index cbb772b36faa..fdc21c699418 100644 --- a/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts +++ b/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts @@ -34,7 +34,7 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise) => }); it('registers a recipient and returns it as a recipient only and not as an account', async () => { - const completeAddress = await CompleteAddress.random(); + const completeAddress = CompleteAddress.random(); await pxe.registerRecipient(completeAddress); @@ -63,7 +63,7 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise) => }); it('cannot register a recipient with the same aztec address but different pub key or partial address', async () => { - const recipient1 = await CompleteAddress.random(); + const recipient1 = CompleteAddress.random(); const recipient2 = new CompleteAddress(recipient1.address, Point.random(), Fr.random()); await pxe.registerRecipient(recipient1); @@ -73,14 +73,14 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise) => }); it('does not throw when registering the same recipient twice (just ignores the second attempt)', async () => { - const completeAddress = await CompleteAddress.random(); + const completeAddress = CompleteAddress.random(); await pxe.registerRecipient(completeAddress); await pxe.registerRecipient(completeAddress); }); it('successfully adds a contract', async () => { - const contracts: DeployedContract[] = [await randomDeployedContract(), await randomDeployedContract()]; + const contracts: DeployedContract[] = [randomDeployedContract(), randomDeployedContract()]; await pxe.addContracts(contracts); const expectedContractAddresses = contracts.map(contract => contract.completeAddress.address); diff --git a/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts b/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts index e0761465d09f..64a36de4d098 100644 --- a/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts @@ -175,7 +175,7 @@ describe('public_processor', () => { it('runs a tx with an enqueued public call with nested execution', async function () { const callRequest: PublicCallRequest = makePublicCallRequest(0x100); - const callStackItem = await callRequest.toPublicCallStackItem(); + const callStackItem = callRequest.toPublicCallStackItem(); const callStackHash = computeCallStackItemHash(wasm, callStackItem); const kernelOutput = makePrivateKernelPublicInputsFinal(0x10); diff --git a/yarn-project/types/src/mocks.ts b/yarn-project/types/src/mocks.ts index 459c436afff2..5752c8789f8d 100644 --- a/yarn-project/types/src/mocks.ts +++ b/yarn-project/types/src/mocks.ts @@ -47,9 +47,9 @@ export const randomContractArtifact = (): ContractArtifact => ({ events: [], }); -export const randomDeployedContract = async (): Promise => ({ +export const randomDeployedContract = (): DeployedContract => ({ artifact: randomContractArtifact(), - completeAddress: await CompleteAddress.random(), + completeAddress: CompleteAddress.random(), portalContract: EthAddress.random(), }); From 8b3289aec11d403b0f5ce6d20cc64e96579a51ad Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Thu, 2 Nov 2023 13:17:52 +0000 Subject: [PATCH 14/29] Try to colorise output. --- yarn-project/end-to-end/scripts/docker-compose.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yarn-project/end-to-end/scripts/docker-compose.yml b/yarn-project/end-to-end/scripts/docker-compose.yml index 81b15fcbd52b..866c4b3f0450 100644 --- a/yarn-project/end-to-end/scripts/docker-compose.yml +++ b/yarn-project/end-to-end/scripts/docker-compose.yml @@ -31,8 +31,9 @@ services: image: aztecprotocol/end-to-end:latest environment: BENCHMARK: 'true' - LOG_LEVL: 'debug' + LOG_LEVEL: 'debug' DEBUG: ${DEBUG:-aztec:*} + DEBUG_COLORS: 1 ETHEREUM_HOST: http://fork:8545 CHAIN_ID: 31337 PXE_URL: http://sandbox:8080 From 92d3260cdd2819bd922dd59a8ca914d333706613 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Thu, 2 Nov 2023 13:19:52 +0000 Subject: [PATCH 15/29] fix --- yarn-project/acir-simulator/src/acvm/serialize.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/acir-simulator/src/acvm/serialize.ts b/yarn-project/acir-simulator/src/acvm/serialize.ts index 213061be319f..bfb63d3ffbdc 100644 --- a/yarn-project/acir-simulator/src/acvm/serialize.ts +++ b/yarn-project/acir-simulator/src/acvm/serialize.ts @@ -187,7 +187,7 @@ export function toAcvmCallPrivateStackItem(item: PrivateCallStackItem): ACVMFiel * @param item - The public call stack item to serialize to be passed onto Noir. * @returns The fields expected by the enqueue_public_function_call_oracle Aztec.nr function. */ -export function toAcvmEnqueuePublicFunctionResult(item: PublicCallRequest): Promise { +export function toAcvmEnqueuePublicFunctionResult(item: PublicCallRequest): ACVMField[] { return [ toACVMField(item.contractAddress), ...toACVMFunctionData(item.functionData), From 55be313490cab6e713e5d944e307d358b0959381 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Thu, 2 Nov 2023 14:47:59 +0000 Subject: [PATCH 16/29] remove test. --- .../barretenberg/crypto/pedersen/index.test.ts | 17 ----------------- .../block_builder/solo_block_builder.test.ts | 1 + 2 files changed, 1 insertion(+), 17 deletions(-) delete mode 100644 yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts deleted file mode 100644 index 27b823762adf..000000000000 --- a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { pedersenCommit } from '@aztec/foundation/crypto'; -import { Fr } from '@aztec/foundation/fields'; -import { Timer } from '@aztec/foundation/timer'; - -describe('pedersen', () => { - const loops = 1000; - const fields = Array.from({ length: loops * 2 }).map(() => Fr.random().toBuffer()); - - it('pedersen perf', () => { - const t = new Timer(); - for (let i = 0; i < loops; ++i) { - pedersenCommit([fields[i * 2], fields[i * 2 + 1]]); - } - // console.log(t.us() / loops); - expect(t.us() / loops).toBeLessThan(500); - }); -}); diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts index f5ddccffe60e..9bca05b2f0fe 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts @@ -358,6 +358,7 @@ describe('sequencer/solo_block_builder', () => { makeEmptyProcessedTx(), makeEmptyProcessedTx(), ]); + console.log(txs); const [l2Block] = await builder.buildL2Block(globalVariables, txs, mockL1ToL2Messages); expect(l2Block.number).toEqual(blockNumber); From 0f1e439c7f4187c1394ae57e91560285ae4be973 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Thu, 2 Nov 2023 16:22:54 +0000 Subject: [PATCH 17/29] fix --- yarn-project/circuits.js/src/abis/abis.ts | 3 +++ .../src/block_builder/solo_block_builder.test.ts | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/yarn-project/circuits.js/src/abis/abis.ts b/yarn-project/circuits.js/src/abis/abis.ts index b0da747f0981..88911dd1c670 100644 --- a/yarn-project/circuits.js/src/abis/abis.ts +++ b/yarn-project/circuits.js/src/abis/abis.ts @@ -396,6 +396,9 @@ export function computeVarArgsHash(args: Fr[]) { * @returns The contract leaf. */ export function computeContractLeaf(cd: NewContractData): Fr { + if (cd.contractAddress.isZero() && cd.portalContractAddress.isZero() && cd.functionTreeRoot.isZero()) { + return new Fr(0); + } return Fr.fromBuffer( pedersenHash( [cd.contractAddress.toBuffer(), cd.portalContractAddress.toBuffer(), cd.functionTreeRoot.toBuffer()], diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts index 9bca05b2f0fe..f5ddccffe60e 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts @@ -358,7 +358,6 @@ describe('sequencer/solo_block_builder', () => { makeEmptyProcessedTx(), makeEmptyProcessedTx(), ]); - console.log(txs); const [l2Block] = await builder.buildL2Block(globalVariables, txs, mockL1ToL2Messages); expect(l2Block.number).toEqual(blockNumber); From 42c1d84b598eacae8f0e53ee2342174bdae55dc4 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Thu, 2 Nov 2023 17:18:46 +0000 Subject: [PATCH 18/29] Cleanup --- barretenberg/scripts/decls_json.py | 7 - barretenberg/ts/src/barretenberg/index.ts | 14 +- .../src/client/private_execution.test.ts | 4 +- .../src/client/simulator.test.ts | 4 +- .../acir-simulator/src/public/index.test.ts | 10 +- yarn-project/acir-simulator/src/utils.ts | 5 +- .../account/defaults/entrypoint_payload.ts | 4 +- yarn-project/aztec.js/src/utils/authwit.ts | 4 +- .../aztec.js/src/utils/cheat_codes.ts | 5 +- yarn-project/circuits.js/package.json | 3 - .../src/abis/__snapshots__/abis.test.ts.snap | 6 + .../circuits.js/src/abis/abis.test.ts | 6 + .../src/barretenberg/crypto/grumpkin/index.ts | 2 +- .../src/barretenberg/crypto/index.ts | 1 - .../src/barretenberg/crypto/pedersen/index.ts | 1 - .../barretenberg/crypto/pedersen/pedersen.ts | 43 -- .../scripts/docker-compose-browser.yml | 2 + .../scripts/docker-compose-no-sandbox.yml | 1 + .../end-to-end/scripts/docker-compose-p2p.yml | 2 + .../end-to-end/scripts/docker-compose.yml | 1 - .../end-to-end/src/e2e_block_building.test.ts | 5 +- .../src/simulators/lending_simulator.ts | 4 +- yarn-project/foundation/package.json | 14 - .../src/note_processor/note_processor.test.ts | 5 +- yarn-project/sequencer-client/package.json | 1 - yarn-project/yarn.lock | 474 +----------------- 26 files changed, 56 insertions(+), 572 deletions(-) delete mode 100644 yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.ts delete mode 100644 yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts diff --git a/barretenberg/scripts/decls_json.py b/barretenberg/scripts/decls_json.py index 5b8473b46928..2b1753220baa 100755 --- a/barretenberg/scripts/decls_json.py +++ b/barretenberg/scripts/decls_json.py @@ -33,13 +33,6 @@ def process_files(files: List[str]) -> List[dict]: idx = clang.cindex.Index.create() for path in files: tu = idx.parse(path, args=[ - # '-isystem', '/usr/include/c++/10', - # '-isystem', '/usr/include/x86_64-linux-gnu/c++/10', - # '-isystem', '/usr/include/c++/10/backward', - # '-isystem', '/usr/lib/llvm-16/lib/clang/16/include', - # '-isystem', '/usr/local/include', - # '-isystem', '/usr/include/x86_64-linux-gnu', - # '-isystem', '/usr/include', "-I./cpp/src", '-std=gnu++20', '-Wall', '-Wextra']) for diag in tu.diagnostics: diff --git a/barretenberg/ts/src/barretenberg/index.ts b/barretenberg/ts/src/barretenberg/index.ts index 7610b7e9b62c..6ae070d4882c 100644 --- a/barretenberg/ts/src/barretenberg/index.ts +++ b/barretenberg/ts/src/barretenberg/index.ts @@ -2,7 +2,7 @@ import { proxy } from 'comlink'; import { BarretenbergApi } from '../barretenberg_api/index.js'; import { BarretenbergBinder } from '../barretenberg_binder/index.js'; import { createMainWorker } from '../barretenberg_wasm/barretenberg_wasm_main/factory/node/index.js'; -import { BarretenbergWasmMain, BarretenbergWasmMainWorker } from '../barretenberg_wasm/barretenberg_wasm_main/index.js'; +import { BarretenbergWasmMainWorker } from '../barretenberg_wasm/barretenberg_wasm_main/index.js'; import { getRemoteBarretenbergWasm } from '../barretenberg_wasm/helpers/index.js'; import { BarretenbergWasmWorker } from '../barretenberg_wasm/index.js'; import createDebug from 'debug'; @@ -14,7 +14,7 @@ const debug = createDebug('bb.js:wasm'); * It extends the generated api, and provides a static constructor "new" to compose components. */ export class Barretenberg extends BarretenbergApi { - private constructor(private worker: any, private wasm: BarretenbergWasmWorker | BarretenbergWasmMain) { + private constructor(private worker: any, private wasm: BarretenbergWasmWorker) { super(new BarretenbergBinder(wasm)); } @@ -31,18 +31,12 @@ export class Barretenberg extends BarretenbergApi { return new Barretenberg(worker, wasm); } - static async newSync() { - const wasm = new BarretenbergWasmMain(); - await wasm.init(1); - return new Barretenberg(undefined, wasm); - } - async getNumThreads() { return await this.wasm.getNumThreads(); } async destroy() { - await this.wasm?.destroy(); - await this.worker?.terminate(); + await this.wasm.destroy(); + await this.worker.terminate(); } } diff --git a/yarn-project/acir-simulator/src/client/private_execution.test.ts b/yarn-project/acir-simulator/src/client/private_execution.test.ts index bb44d30866ce..61ac920141e0 100644 --- a/yarn-project/acir-simulator/src/client/private_execution.test.ts +++ b/yarn-project/acir-simulator/src/client/private_execution.test.ts @@ -21,11 +21,11 @@ import { computeVarArgsHash, siloCommitment, } from '@aztec/circuits.js/abis'; -import { pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; import { makeContractDeploymentData } from '@aztec/circuits.js/factories'; import { FunctionArtifact, FunctionSelector, encodeArguments } from '@aztec/foundation/abi'; import { asyncMap } from '@aztec/foundation/async-map'; import { AztecAddress } from '@aztec/foundation/aztec-address'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr, GrumpkinScalar } from '@aztec/foundation/fields'; import { DebugLogger, createDebugLogger } from '@aztec/foundation/log'; @@ -142,7 +142,7 @@ describe('Private Execution test suite', () => { return trees[name]; }; - const hashFields = (data: Fr[]) => Fr.fromBuffer(pedersenHashInputs(data.map(f => f.toBuffer()))); + const hashFields = (data: Fr[]) => Fr.fromBuffer(pedersenHash(data.map(f => f.toBuffer()))); beforeAll(async () => { logger = createDebugLogger('aztec:test:private_execution'); diff --git a/yarn-project/acir-simulator/src/client/simulator.test.ts b/yarn-project/acir-simulator/src/client/simulator.test.ts index 4dcf6fca9099..e24d2de37a29 100644 --- a/yarn-project/acir-simulator/src/client/simulator.test.ts +++ b/yarn-project/acir-simulator/src/client/simulator.test.ts @@ -1,8 +1,8 @@ import { CompleteAddress } from '@aztec/circuits.js'; import { computeUniqueCommitment, siloCommitment } from '@aztec/circuits.js/abis'; -import { pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; import { ABIParameterVisibility } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { Fr, GrumpkinScalar } from '@aztec/foundation/fields'; import { TokenContractArtifact } from '@aztec/noir-contracts/artifacts'; import { Note } from '@aztec/types'; @@ -20,7 +20,7 @@ describe('Simulator', () => { let owner: AztecAddress; const ownerPk = GrumpkinScalar.fromString('2dcc5485a58316776299be08c78fa3788a1a7961ae30dc747fb1be17692a8d32'); - const hashFields = (data: Fr[]) => Fr.fromBuffer(pedersenHashInputs(data.map(f => f.toBuffer()))); + const hashFields = (data: Fr[]) => Fr.fromBuffer(pedersenHash(data.map(f => f.toBuffer()))); beforeAll(async () => { ownerCompleteAddress = await CompleteAddress.fromPrivateKeyAndPartialAddress(ownerPk, Fr.random()); diff --git a/yarn-project/acir-simulator/src/public/index.test.ts b/yarn-project/acir-simulator/src/public/index.test.ts index 549f242075d6..38ef76b81904 100644 --- a/yarn-project/acir-simulator/src/public/index.test.ts +++ b/yarn-project/acir-simulator/src/public/index.test.ts @@ -5,9 +5,9 @@ import { HistoricBlockData, L1_TO_L2_MSG_TREE_HEIGHT, } from '@aztec/circuits.js'; -import { pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; import { FunctionArtifact, FunctionSelector, encodeArguments } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; import { @@ -326,9 +326,9 @@ describe('ACIR public execution simulator', () => { // Assert the commitment was created expect(result.newCommitments.length).toEqual(1); - const expectedNoteHash = pedersenHashInputs([amount.toBuffer(), secretHash.toBuffer()]); + const expectedNoteHash = pedersenHash([amount.toBuffer(), secretHash.toBuffer()]); const storageSlot = new Fr(5); // for pending_shields - const expectedInnerNoteHash = pedersenHashInputs([storageSlot.toBuffer(), expectedNoteHash]); + const expectedInnerNoteHash = pedersenHash([storageSlot.toBuffer(), expectedNoteHash]); expect(result.newCommitments[0].toBuffer()).toEqual(expectedInnerNoteHash); }); @@ -356,7 +356,7 @@ describe('ACIR public execution simulator', () => { // Assert the l2 to l1 message was created expect(result.newL2ToL1Messages.length).toEqual(1); - const expectedNewMessageValue = pedersenHashInputs(params.map(a => a.toBuffer())); + const expectedNewMessageValue = pedersenHash(params.map(a => a.toBuffer())); expect(result.newL2ToL1Messages[0].toBuffer()).toEqual(expectedNewMessageValue); }); @@ -440,7 +440,7 @@ describe('ACIR public execution simulator', () => { // Assert the l2 to l1 message was created expect(result.newNullifiers.length).toEqual(1); - const expectedNewMessageValue = pedersenHashInputs(params.map(a => a.toBuffer())); + const expectedNewMessageValue = pedersenHash(params.map(a => a.toBuffer())); expect(result.newNullifiers[0].toBuffer()).toEqual(expectedNewMessageValue); }); }); diff --git a/yarn-project/acir-simulator/src/utils.ts b/yarn-project/acir-simulator/src/utils.ts index 02ad7e0d6dff..bc1ff8717377 100644 --- a/yarn-project/acir-simulator/src/utils.ts +++ b/yarn-project/acir-simulator/src/utils.ts @@ -1,5 +1,6 @@ import { GrumpkinPrivateKey } from '@aztec/circuits.js'; -import { Grumpkin, pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; +import { Grumpkin } from '@aztec/circuits.js/barretenberg'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; /** @@ -23,7 +24,7 @@ export function computeSlotForMapping(mappingSlot: Fr, owner: NoirPoint | Fr) { const isFr = (owner: NoirPoint | Fr): owner is Fr => typeof (owner as Fr).value === 'bigint'; const ownerField = isFr(owner) ? owner : new Fr(owner.x); - return Fr.fromBuffer(pedersenHashInputs([mappingSlot, ownerField].map(f => f.toBuffer()))); + return Fr.fromBuffer(pedersenHash([mappingSlot, ownerField].map(f => f.toBuffer()))); } /** diff --git a/yarn-project/aztec.js/src/account/defaults/entrypoint_payload.ts b/yarn-project/aztec.js/src/account/defaults/entrypoint_payload.ts index 99fc8377cb4d..4e2afca40402 100644 --- a/yarn-project/aztec.js/src/account/defaults/entrypoint_payload.ts +++ b/yarn-project/aztec.js/src/account/defaults/entrypoint_payload.ts @@ -1,6 +1,6 @@ import { Fr, GeneratorIndex } from '@aztec/circuits.js'; -import { pedersenHashWithHashIndex } from '@aztec/circuits.js/barretenberg'; import { padArrayEnd } from '@aztec/foundation/collection'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { FunctionCall, PackedArguments, emptyFunctionCall } from '@aztec/types'; // These must match the values defined in yarn-project/aztec-nr/aztec/src/entrypoint.nr @@ -69,7 +69,7 @@ export function buildPayload(calls: FunctionCall[]): { /** Hashes an entrypoint payload to a 32-byte buffer (useful for signing) */ export function hashPayload(payload: EntrypointPayload) { - return pedersenHashWithHashIndex( + return pedersenHash( flattenPayload(payload).map(fr => fr.toBuffer()), GeneratorIndex.SIGNATURE_PAYLOAD, ); diff --git a/yarn-project/aztec.js/src/utils/authwit.ts b/yarn-project/aztec.js/src/utils/authwit.ts index f31f3e26b732..2d4aec8e3a73 100644 --- a/yarn-project/aztec.js/src/utils/authwit.ts +++ b/yarn-project/aztec.js/src/utils/authwit.ts @@ -1,5 +1,5 @@ import { AztecAddress, GeneratorIndex } from '@aztec/circuits.js'; -import { pedersenHashWithHashIndex } from '@aztec/circuits.js/barretenberg'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { FunctionCall, PackedArguments } from '@aztec/types'; // docs:start:authwit_computeAuthWitMessageHash @@ -11,7 +11,7 @@ import { FunctionCall, PackedArguments } from '@aztec/types'; * @returns The message hash for the witness */ export const computeAuthWitMessageHash = (caller: AztecAddress, request: FunctionCall) => { - return pedersenHashWithHashIndex( + return pedersenHash( [ caller.toField(), request.to.toField(), diff --git a/yarn-project/aztec.js/src/utils/cheat_codes.ts b/yarn-project/aztec.js/src/utils/cheat_codes.ts index ce0beb7bf8ba..9833ef02398c 100644 --- a/yarn-project/aztec.js/src/utils/cheat_codes.ts +++ b/yarn-project/aztec.js/src/utils/cheat_codes.ts @@ -1,7 +1,6 @@ import { AztecAddress, CircuitsWasm, EthAddress, Fr } from '@aztec/circuits.js'; -import { pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; import { toBigIntBE, toHex } from '@aztec/foundation/bigint-buffer'; -import { keccak } from '@aztec/foundation/crypto'; +import { keccak, pedersenHash } from '@aztec/foundation/crypto'; import { createDebugLogger } from '@aztec/foundation/log'; import { Note, PXE } from '@aztec/types'; @@ -235,7 +234,7 @@ export class AztecCheatCodes { public computeSlotInMap(baseSlot: Fr | bigint, key: Fr | bigint | AztecAddress): Fr { // Based on `at` function in // aztec3-packages/yarn-project/aztec-nr/aztec/src/state_vars/map.nr - return Fr.fromBuffer(pedersenHashInputs([new Fr(baseSlot), new Fr(key)].map(f => f.toBuffer()))); + return Fr.fromBuffer(pedersenHash([new Fr(baseSlot), new Fr(key)].map(f => f.toBuffer()))); } /** diff --git a/yarn-project/circuits.js/package.json b/yarn-project/circuits.js/package.json index b2712946f81a..120d66964e54 100644 --- a/yarn-project/circuits.js/package.json +++ b/yarn-project/circuits.js/package.json @@ -25,8 +25,6 @@ "formatting:fix": "run -T prettier -w ./src", "remake-bindings": "DEBUG=wasm ts-node-esm src/cbind/circuits.in.ts && prettier -w src/cbind/circuits.gen.ts", "remake-constants": "ts-node-esm src/cbind/constants.in.ts && prettier -w src/cbind/constants.gen.ts", - "test:light": "NODE_NO_WARNINGS=1 NODE_OPTIONS='--loader ts-node/esm' node --experimental-vm-modules $(yarn bin jest) --runner=jest-light-runner --passWithNoTests", - "test:light:dbg": "NODE_NO_WARNINGS=1 NODE_OPTIONS='--loader ts-node/esm' node --inspect-brk=0.0.0.0 --experimental-vm-modules $(yarn bin jest) --runner=jest-light-runner --passWithNoTests", "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests" }, "inherits": [ @@ -64,7 +62,6 @@ "@types/lodash.mapvalues": "^4.6.7", "@types/node": "^18.7.23", "jest": "^29.5.0", - "jest-light-runner": "^0.5.1", "prettier": "^2.8.4", "ts-dedent": "^2.2.0", "ts-jest": "^29.1.0", diff --git a/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap b/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap index e1091482759a..52da5e516217 100644 --- a/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap +++ b/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap @@ -200,6 +200,12 @@ Fr { } `; +exports[`abis wasm bindings computes zero contract leaf 1`] = ` +Fr { + "value": 0n, +} +`; + exports[`abis wasm bindings hashes VK 1`] = ` { "data": [ diff --git a/yarn-project/circuits.js/src/abis/abis.test.ts b/yarn-project/circuits.js/src/abis/abis.test.ts index f6f7050666d6..79413a36c104 100644 --- a/yarn-project/circuits.js/src/abis/abis.test.ts +++ b/yarn-project/circuits.js/src/abis/abis.test.ts @@ -201,6 +201,12 @@ describe('abis wasm bindings', () => { expect(res).toMatchSnapshot(); }); + it('computes zero contract leaf', () => { + const cd = new NewContractData(AztecAddress.ZERO, AztecAddress.ZERO, new Fr(0n)); + const res = computeContractLeaf(cd); + expect(res).toMatchSnapshot(); + }); + it('compute tx hash', () => { const txRequest = makeTxRequest(); const hash = computeTxHash(txRequest); diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.ts b/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.ts index 37247fe4c8bb..35a0cb068e5a 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.ts @@ -3,7 +3,7 @@ import { IWasmModule } from '@aztec/foundation/wasm'; import { CircuitsWasm, GrumpkinScalar } from '../../../index.js'; -// TODO!!!!!: Make this use grumpkin typescript currently in pedersen. +// TODO: Establish if these needs high performance and consider refactoring and using the grumpkin curve in pedersen ts. /** * Grumpkin elliptic curve operations. diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/index.ts b/yarn-project/circuits.js/src/barretenberg/crypto/index.ts index 4157db3d632c..e9c594c032d0 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/index.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/index.ts @@ -1,6 +1,5 @@ export * from './aes128/index.js'; export * from './grumpkin/index.js'; -export * from './pedersen/index.js'; export * from './ecdsa/index.js'; export * from './secp256k1/index.js'; export * from './schnorr/index.js'; diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.ts b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.ts deleted file mode 100644 index 41d557571b3e..000000000000 --- a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './pedersen.js'; diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts deleted file mode 100644 index 12dc1b91a7a0..000000000000 --- a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { pedersenHash as cryptoPedersen } from '@aztec/foundation/crypto'; - -import { Buffer } from 'buffer'; - -// TODO: DELETE THIS FILE! - -/** - * Hashes two arrays. - * @param wasm - The barretenberg module. - * @param lhs - The first array. - * @param rhs - The second array. - * @returns The new 32-byte hash. - * @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific - * purposes. - */ -export function pedersenHash(lhs: Uint8Array, rhs: Uint8Array): Buffer { - return pedersenHashWithHashIndex([Buffer.from(lhs), Buffer.from(rhs)], 0); -} - -/** - * Computes the hash of an array of buffers. - * @param wasm - The barretenberg module. - * @param inputs - The array of buffers to hash. - * @returns The new 32-byte hash. - * @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific - * purposes. - */ -export function pedersenHashInputs(inputs: Buffer[]): Buffer { - return pedersenHashWithHashIndex(inputs, 0); -} - -/** - * Hashes an array of buffers. - * @param wasm - The barretenberg module. - * @param inputs - The array of buffers to hash. - * @param hashIndex - Hash index of the generator to use (See GeneratorIndex enum). - * @returns The resulting 32-byte hash. - * @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific - * purposes. - */ -export function pedersenHashWithHashIndex(inputs: Buffer[], hashIndex: number): Buffer { - return cryptoPedersen(inputs, hashIndex); -} diff --git a/yarn-project/end-to-end/scripts/docker-compose-browser.yml b/yarn-project/end-to-end/scripts/docker-compose-browser.yml index ddb5838000b6..d3abd8fb74dc 100644 --- a/yarn-project/end-to-end/scripts/docker-compose-browser.yml +++ b/yarn-project/end-to-end/scripts/docker-compose-browser.yml @@ -16,6 +16,7 @@ services: image: aztecprotocol/aztec-sandbox:latest environment: DEBUG: 'aztec:*' + DEBUG_COLORS: 1 ETHEREUM_HOST: http://fork:8545 CHAIN_ID: 31337 ARCHIVER_POLLING_INTERVAL_MS: 50 @@ -32,6 +33,7 @@ services: environment: BENCHMARK: 'true' DEBUG: ${DEBUG:-'aztec:*'} + DEBUG_COLORS: 1 ETHEREUM_HOST: http://fork:8545 CHAIN_ID: 31337 PXE_URL: http://sandbox:8080 diff --git a/yarn-project/end-to-end/scripts/docker-compose-no-sandbox.yml b/yarn-project/end-to-end/scripts/docker-compose-no-sandbox.yml index 76d045ebc4bd..e810a57db3d0 100644 --- a/yarn-project/end-to-end/scripts/docker-compose-no-sandbox.yml +++ b/yarn-project/end-to-end/scripts/docker-compose-no-sandbox.yml @@ -17,6 +17,7 @@ services: environment: BENCHMARK: 'true' DEBUG: ${DEBUG:-'aztec:*'} + DEBUG_COLORS: 1 ETHEREUM_HOST: http://fork:8545 CHAIN_ID: 31337 ARCHIVER_POLLING_INTERVAL_MS: 50 diff --git a/yarn-project/end-to-end/scripts/docker-compose-p2p.yml b/yarn-project/end-to-end/scripts/docker-compose-p2p.yml index 9fa069b1ca95..c030caaef203 100644 --- a/yarn-project/end-to-end/scripts/docker-compose-p2p.yml +++ b/yarn-project/end-to-end/scripts/docker-compose-p2p.yml @@ -13,6 +13,7 @@ services: command: 'start' environment: DEBUG: 'aztec:*' + DEBUG_COLORS: 1 P2P_TCP_LISTEN_PORT: 40400 P2P_TCP_LISTEN_IP: '0.0.0.0' P2P_ANNOUNCE_HOSTNAME: 'p2p-bootstrap' @@ -23,6 +24,7 @@ services: environment: BENCHMARK: true DEBUG: ${DEBUG:-'aztec:*'} + DEBUG_COLORS: 1 ETHEREUM_HOST: http://fork:8545 CHAIN_ID: 31337 ARCHIVER_POLLING_INTERVAL: 500 diff --git a/yarn-project/end-to-end/scripts/docker-compose.yml b/yarn-project/end-to-end/scripts/docker-compose.yml index 866c4b3f0450..59364f2bc789 100644 --- a/yarn-project/end-to-end/scripts/docker-compose.yml +++ b/yarn-project/end-to-end/scripts/docker-compose.yml @@ -31,7 +31,6 @@ services: image: aztecprotocol/end-to-end:latest environment: BENCHMARK: 'true' - LOG_LEVEL: 'debug' DEBUG: ${DEBUG:-aztec:*} DEBUG_COLORS: 1 ETHEREUM_HOST: http://fork:8545 diff --git a/yarn-project/end-to-end/src/e2e_block_building.test.ts b/yarn-project/end-to-end/src/e2e_block_building.test.ts index 329f891e96c9..d6eccd469361 100644 --- a/yarn-project/end-to-end/src/e2e_block_building.test.ts +++ b/yarn-project/end-to-end/src/e2e_block_building.test.ts @@ -1,6 +1,5 @@ import { BatchCall, - CircuitsWasm, ContractDeployer, ContractFunctionInteraction, DebugLogger, @@ -10,7 +9,7 @@ import { Wallet, isContractDeployed, } from '@aztec/aztec.js'; -import { pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { TestContractArtifact } from '@aztec/noir-contracts/artifacts'; import { TestContract, TokenContract } from '@aztec/noir-contracts/types'; @@ -136,7 +135,7 @@ describe('e2e_block_building', () => { it('drops tx with private nullifier already emitted from public on the same block', async () => { const secret = Fr.random(); // See yarn-project/acir-simulator/src/public/index.test.ts 'Should be able to create a nullifier from the public context' - const emittedPublicNullifier = pedersenHashInputs([new Fr(140), secret].map(a => a.toBuffer())); + const emittedPublicNullifier = pedersenHash([new Fr(140), secret].map(a => a.toBuffer())); const calls = [ contract.methods.create_nullifier_public(140n, secret), diff --git a/yarn-project/end-to-end/src/simulators/lending_simulator.ts b/yarn-project/end-to-end/src/simulators/lending_simulator.ts index 8fd3e3c1ab34..c5d6bdcf7062 100644 --- a/yarn-project/end-to-end/src/simulators/lending_simulator.ts +++ b/yarn-project/end-to-end/src/simulators/lending_simulator.ts @@ -1,6 +1,6 @@ // Convenience struct to hold an account's address and secret that can easily be passed around. import { AztecAddress, CheatCodes, Fr } from '@aztec/aztec.js'; -import { pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { LendingContract } from '@aztec/noir-contracts/types'; import { TokenSimulator } from './token_simulator.js'; @@ -24,7 +24,7 @@ export class LendingAccount { * @returns Key in public space */ public key() { - return Fr.fromBuffer(pedersenHashInputs([this.address, this.secret].map(f => f.toBuffer()))); + return Fr.fromBuffer(pedersenHash([this.address, this.secret].map(f => f.toBuffer()))); } } diff --git a/yarn-project/foundation/package.json b/yarn-project/foundation/package.json index d8bb10757e03..d71d41889d53 100644 --- a/yarn-project/foundation/package.json +++ b/yarn-project/foundation/package.json @@ -56,18 +56,6 @@ "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, - "mocha": { - "extension": [ - "ts" - ], - "node-option": [ - "experimental-specifier-resolution=node", - "loader=ts-node/esm" - ], - "spec": [ - "./src/crypto/pedersen/*.test.ts" - ] - }, "dependencies": { "@aztec/bb.js": "portal:../../barretenberg/ts", "@koa/cors": "^4.0.0", @@ -119,8 +107,6 @@ "eslint-plugin-no-only-tests": "^3.1.0", "eslint-plugin-tsdoc": "^0.2.17", "jest": "^29.5.0", - "jest-light-runner": "^0.5.1", - "mocha": "^10.2.0", "prettier": "^2.7.1", "supertest": "^6.3.3", "ts-jest": "^29.1.0", diff --git a/yarn-project/pxe/src/note_processor/note_processor.test.ts b/yarn-project/pxe/src/note_processor/note_processor.test.ts index 471ddd2079bd..207850ee7574 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.test.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.test.ts @@ -1,6 +1,7 @@ import { AcirSimulator } from '@aztec/acir-simulator'; import { CircuitsWasm, Fr, MAX_NEW_COMMITMENTS_PER_TX } from '@aztec/circuits.js'; -import { Grumpkin, pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; +import { Grumpkin } from '@aztec/circuits.js/barretenberg'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { Point } from '@aztec/foundation/fields'; import { ConstantKeyPair } from '@aztec/key-store'; import { @@ -40,7 +41,7 @@ describe('Note Processor', () => { const numCommitmentsPerBlock = TXS_PER_BLOCK * MAX_NEW_COMMITMENTS_PER_TX; const firstBlockDataStartIndex = (firstBlockNum - 1) * numCommitmentsPerBlock; - const computeMockNoteHash = (note: Note) => Fr.fromBuffer(pedersenHashInputs(note.items.map(i => i.toBuffer()))); + const computeMockNoteHash = (note: Note) => Fr.fromBuffer(pedersenHash(note.items.map(i => i.toBuffer()))); // ownedData: [tx1, tx2, ...], the numbers in each tx represents the indices of the note hashes the account owns. const createEncryptedLogsAndOwnedL1NotePayloads = (ownedData: number[][], ownedNotes: L1NotePayload[]) => { diff --git a/yarn-project/sequencer-client/package.json b/yarn-project/sequencer-client/package.json index 2a280c55665d..c6a4c6a50bdc 100644 --- a/yarn-project/sequencer-client/package.json +++ b/yarn-project/sequencer-client/package.json @@ -16,7 +16,6 @@ "clean": "rm -rf ./dest .tsbuildinfo", "formatting": "run -T prettier --check ./src && run -T eslint ./src", "formatting:fix": "run -T prettier -w ./src", - "test:light": "NODE_NO_WARNINGS=1 NODE_OPTIONS='--loader ts-node/esm' node --experimental-vm-modules $(yarn bin jest) --runner=jest-light-runner --passWithNoTests", "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests", "test:integration": "concurrently -k -s first -c reset,dim -n test,anvil \"yarn test:integration:run\" \"anvil\"", "test:integration:run": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --no-cache --config jest.integration.config.json" diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 54f591b2cc60..8ff4395124bc 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -57,13 +57,6 @@ __metadata: languageName: node linkType: hard -"@assemblyscript/loader@npm:^0.10.1": - version: 0.10.1 - resolution: "@assemblyscript/loader@npm:0.10.1" - checksum: fd1f57bdf2c55252a48c2d93fbec3c5a9ef4ca40e581e8709dd8ee437613eb47af74c8cdba011a324077eda9605d6f24983f429c2ce18b0b582ddcc5acf75c26 - languageName: node - linkType: hard - "@aztec/acir-simulator@workspace:^, @aztec/acir-simulator@workspace:acir-simulator": version: 0.0.0-use.local resolution: "@aztec/acir-simulator@workspace:acir-simulator" @@ -359,7 +352,6 @@ __metadata: detect-node: ^2.1.0 eslint: ^8.35.0 jest: ^29.5.0 - jest-light-runner: ^0.5.1 lodash.capitalize: ^4.2.1 lodash.chunk: ^4.2.0 lodash.mapvalues: ^4.6.0 @@ -534,7 +526,6 @@ __metadata: eslint-plugin-tsdoc: ^0.2.17 hash.js: ^1.1.7 jest: ^29.5.0 - jest-light-runner: ^0.5.1 koa: ^2.14.2 koa-bodyparser: ^4.4.0 koa-compress: ^5.1.0 @@ -543,7 +534,6 @@ __metadata: levelup: ^5.1.1 lodash.clonedeepwith: ^4.5.0 memdown: ^6.1.1 - mocha: ^10.2.0 pako: ^2.1.0 prettier: ^2.7.1 sha3: ^2.1.4 @@ -2241,20 +2231,6 @@ __metadata: languageName: node linkType: hard -"@jest/console@npm:^29.7.0": - version: 29.7.0 - resolution: "@jest/console@npm:29.7.0" - dependencies: - "@jest/types": ^29.6.3 - "@types/node": "*" - chalk: ^4.0.0 - jest-message-util: ^29.7.0 - jest-util: ^29.7.0 - slash: ^3.0.0 - checksum: 0e3624e32c5a8e7361e889db70b170876401b7d70f509a2538c31d5cd50deb0c1ae4b92dc63fe18a0902e0a48c590c21d53787a0df41a52b34fa7cab96c384d6 - languageName: node - linkType: hard - "@jest/core@npm:^29.6.2": version: 29.6.2 resolution: "@jest/core@npm:29.6.2" @@ -2361,18 +2337,6 @@ __metadata: languageName: node linkType: hard -"@jest/environment@npm:^29.7.0": - version: 29.7.0 - resolution: "@jest/environment@npm:29.7.0" - dependencies: - "@jest/fake-timers": ^29.7.0 - "@jest/types": ^29.6.3 - "@types/node": "*" - jest-mock: ^29.7.0 - checksum: 6fb398143b2543d4b9b8d1c6dbce83fa5247f84f550330604be744e24c2bd2178bb893657d62d1b97cf2f24baf85c450223f8237cccb71192c36a38ea2272934 - languageName: node - linkType: hard - "@jest/expect-utils@npm:^29.6.2": version: 29.6.2 resolution: "@jest/expect-utils@npm:29.6.2" @@ -2391,25 +2355,6 @@ __metadata: languageName: node linkType: hard -"@jest/expect-utils@npm:^29.7.0": - version: 29.7.0 - resolution: "@jest/expect-utils@npm:29.7.0" - dependencies: - jest-get-type: ^29.6.3 - checksum: 75eb177f3d00b6331bcaa057e07c0ccb0733a1d0a1943e1d8db346779039cb7f103789f16e502f888a3096fb58c2300c38d1f3748b36a7fa762eb6f6d1b160ed - languageName: node - linkType: hard - -"@jest/expect@npm:^29.0.1, @jest/expect@npm:^29.7.0": - version: 29.7.0 - resolution: "@jest/expect@npm:29.7.0" - dependencies: - expect: ^29.7.0 - jest-snapshot: ^29.7.0 - checksum: a01cb85fd9401bab3370618f4b9013b90c93536562222d920e702a0b575d239d74cecfe98010aaec7ad464f67cf534a353d92d181646a4b792acaa7e912ae55e - languageName: node - linkType: hard - "@jest/expect@npm:^29.6.2": version: 29.6.2 resolution: "@jest/expect@npm:29.6.2" @@ -2430,20 +2375,6 @@ __metadata: languageName: node linkType: hard -"@jest/fake-timers@npm:^29.2.2, @jest/fake-timers@npm:^29.7.0": - version: 29.7.0 - resolution: "@jest/fake-timers@npm:29.7.0" - dependencies: - "@jest/types": ^29.6.3 - "@sinonjs/fake-timers": ^10.0.2 - "@types/node": "*" - jest-message-util: ^29.7.0 - jest-mock: ^29.7.0 - jest-util: ^29.7.0 - checksum: caf2bbd11f71c9241b458d1b5a66cbe95debc5a15d96442444b5d5c7ba774f523c76627c6931cca5e10e76f0d08761f6f1f01a608898f4751a0eee54fc3d8d00 - languageName: node - linkType: hard - "@jest/fake-timers@npm:^29.6.2": version: 29.6.2 resolution: "@jest/fake-timers@npm:29.6.2" @@ -2496,18 +2427,6 @@ __metadata: languageName: node linkType: hard -"@jest/globals@npm:^29.7.0": - version: 29.7.0 - resolution: "@jest/globals@npm:29.7.0" - dependencies: - "@jest/environment": ^29.7.0 - "@jest/expect": ^29.7.0 - "@jest/types": ^29.6.3 - jest-mock: ^29.7.0 - checksum: 97dbb9459135693ad3a422e65ca1c250f03d82b2a77f6207e7fa0edd2c9d2015fbe4346f3dc9ebff1678b9d8da74754d4d440b7837497f8927059c0642a22123 - languageName: node - linkType: hard - "@jest/reporters@npm:^29.6.2": version: 29.6.2 resolution: "@jest/reporters@npm:29.6.2" @@ -2646,18 +2565,6 @@ __metadata: languageName: node linkType: hard -"@jest/test-result@npm:^29.7.0": - version: 29.7.0 - resolution: "@jest/test-result@npm:29.7.0" - dependencies: - "@jest/console": ^29.7.0 - "@jest/types": ^29.6.3 - "@types/istanbul-lib-coverage": ^2.0.0 - collect-v8-coverage: ^1.0.0 - checksum: 67b6317d526e335212e5da0e768e3b8ab8a53df110361b80761353ad23b6aea4432b7c5665bdeb87658ea373b90fb1afe02ed3611ef6c858c7fba377505057fa - languageName: node - linkType: hard - "@jest/test-sequencer@npm:^29.6.2": version: 29.6.2 resolution: "@jest/test-sequencer@npm:29.6.2" @@ -2728,29 +2635,6 @@ __metadata: languageName: node linkType: hard -"@jest/transform@npm:^29.7.0": - version: 29.7.0 - resolution: "@jest/transform@npm:29.7.0" - dependencies: - "@babel/core": ^7.11.6 - "@jest/types": ^29.6.3 - "@jridgewell/trace-mapping": ^0.3.18 - babel-plugin-istanbul: ^6.1.1 - chalk: ^4.0.0 - convert-source-map: ^2.0.0 - fast-json-stable-stringify: ^2.1.0 - graceful-fs: ^4.2.9 - jest-haste-map: ^29.7.0 - jest-regex-util: ^29.6.3 - jest-util: ^29.7.0 - micromatch: ^4.0.4 - pirates: ^4.0.4 - slash: ^3.0.0 - write-file-atomic: ^4.0.2 - checksum: 0f8ac9f413903b3cb6d240102db848f2a354f63971ab885833799a9964999dd51c388162106a807f810071f864302cdd8e3f0c241c29ce02d85a36f18f3f40ab - languageName: node - linkType: hard - "@jest/types@npm:^29.6.1": version: 29.6.1 resolution: "@jest/types@npm:29.6.1" @@ -7341,7 +7225,7 @@ __metadata: languageName: node linkType: hard -"base64-js@npm:^1.2.0, base64-js@npm:^1.3.1, base64-js@npm:^1.5.1": +"base64-js@npm:^1.3.1, base64-js@npm:^1.5.1": version: 1.5.1 resolution: "base64-js@npm:1.5.1" checksum: 669632eb3745404c2f822a18fc3a0122d2f9a7a13f7fb8b5823ee19d1d2ff9ee5b52c53367176ea4ad093c332fd5ab4bd0ebae5a8e27917a4105a4cfc86b1005 @@ -10357,13 +10241,6 @@ __metadata: languageName: node linkType: hard -"eventemitter-asyncresource@npm:^1.0.0": - version: 1.0.0 - resolution: "eventemitter-asyncresource@npm:1.0.0" - checksum: 3cfbbc3490bd429a165bff6336289ff810f7df214796f25000d2097a5a0883eae51542a78674916ff99bbd4c66811911b310df1cb4fc96dfc9546ba9dfc89f8f - languageName: node - linkType: hard - "eventemitter3@npm:4.0.7, eventemitter3@npm:^4.0.0, eventemitter3@npm:^4.0.7": version: 4.0.7 resolution: "eventemitter3@npm:4.0.7" @@ -10457,19 +10334,6 @@ __metadata: languageName: node linkType: hard -"expect@npm:^29.7.0": - version: 29.7.0 - resolution: "expect@npm:29.7.0" - dependencies: - "@jest/expect-utils": ^29.7.0 - jest-get-type: ^29.6.3 - jest-matcher-utils: ^29.7.0 - jest-message-util: ^29.7.0 - jest-util: ^29.7.0 - checksum: 9257f10288e149b81254a0fda8ffe8d54a7061cd61d7515779998b012579d2b8c22354b0eb901daf0145f347403da582f75f359f4810c007182ad3fb318b5c0c - languageName: node - linkType: hard - "exponential-backoff@npm:^3.1.1": version: 3.1.1 resolution: "exponential-backoff@npm:3.1.1" @@ -11553,24 +11417,6 @@ __metadata: languageName: node linkType: hard -"hdr-histogram-js@npm:^2.0.1": - version: 2.0.3 - resolution: "hdr-histogram-js@npm:2.0.3" - dependencies: - "@assemblyscript/loader": ^0.10.1 - base64-js: ^1.2.0 - pako: ^1.0.3 - checksum: 7bb252ba3596bed72b90427ffc6f6fa332a460c4810788faa9b9a743f7ac6f1cb42dccd7ae7555740f0a8c0602884944d00d1ccfb746af4976a816772361a6d6 - languageName: node - linkType: hard - -"hdr-histogram-percentiles-obj@npm:^3.0.0": - version: 3.0.0 - resolution: "hdr-histogram-percentiles-obj@npm:3.0.0" - checksum: ab238edcb38d9b60d23ca53da0ecd9a6b1c8ee9a49e30a6146bd3f8f70f26244652f28b79974157c00504e7ddf3129e0ddb217baf71d32330e3fae0105bf30ed - languageName: node - linkType: hard - "he@npm:1.2.0": version: 1.2.0 resolution: "he@npm:1.2.0" @@ -12918,34 +12764,6 @@ __metadata: languageName: node linkType: hard -"jest-circus@npm:^29.0.1": - version: 29.7.0 - resolution: "jest-circus@npm:29.7.0" - dependencies: - "@jest/environment": ^29.7.0 - "@jest/expect": ^29.7.0 - "@jest/test-result": ^29.7.0 - "@jest/types": ^29.6.3 - "@types/node": "*" - chalk: ^4.0.0 - co: ^4.6.0 - dedent: ^1.0.0 - is-generator-fn: ^2.0.0 - jest-each: ^29.7.0 - jest-matcher-utils: ^29.7.0 - jest-message-util: ^29.7.0 - jest-runtime: ^29.7.0 - jest-snapshot: ^29.7.0 - jest-util: ^29.7.0 - p-limit: ^3.1.0 - pretty-format: ^29.7.0 - pure-rand: ^6.0.0 - slash: ^3.0.0 - stack-utils: ^2.0.3 - checksum: 349437148924a5a109c9b8aad6d393a9591b4dac1918fc97d81b7fc515bc905af9918495055071404af1fab4e48e4b04ac3593477b1d5dcf48c4e71b527c70a7 - languageName: node - linkType: hard - "jest-circus@npm:^29.6.2": version: 29.6.2 resolution: "jest-circus@npm:29.6.2" @@ -13156,18 +12974,6 @@ __metadata: languageName: node linkType: hard -"jest-diff@npm:^29.7.0": - version: 29.7.0 - resolution: "jest-diff@npm:29.7.0" - dependencies: - chalk: ^4.0.0 - diff-sequences: ^29.6.3 - jest-get-type: ^29.6.3 - pretty-format: ^29.7.0 - checksum: 08e24a9dd43bfba1ef07a6374e5af138f53137b79ec3d5cc71a2303515335898888fa5409959172e1e05de966c9e714368d15e8994b0af7441f0721ee8e1bb77 - languageName: node - linkType: hard - "jest-docblock@npm:^29.4.3": version: 29.4.3 resolution: "jest-docblock@npm:29.4.3" @@ -13186,19 +12992,6 @@ __metadata: languageName: node linkType: hard -"jest-each@npm:^29.0.1, jest-each@npm:^29.7.0": - version: 29.7.0 - resolution: "jest-each@npm:29.7.0" - dependencies: - "@jest/types": ^29.6.3 - chalk: ^4.0.0 - jest-get-type: ^29.6.3 - jest-util: ^29.7.0 - pretty-format: ^29.7.0 - checksum: e88f99f0184000fc8813f2a0aa79e29deeb63700a3b9b7928b8a418d7d93cd24933608591dbbdea732b473eb2021c72991b5cc51a17966842841c6e28e6f691c - languageName: node - linkType: hard - "jest-each@npm:^29.6.2": version: 29.6.2 resolution: "jest-each@npm:29.6.2" @@ -13313,29 +13106,6 @@ __metadata: languageName: node linkType: hard -"jest-haste-map@npm:^29.7.0": - version: 29.7.0 - resolution: "jest-haste-map@npm:29.7.0" - dependencies: - "@jest/types": ^29.6.3 - "@types/graceful-fs": ^4.1.3 - "@types/node": "*" - anymatch: ^3.0.3 - fb-watchman: ^2.0.0 - fsevents: ^2.3.2 - graceful-fs: ^4.2.9 - jest-regex-util: ^29.6.3 - jest-util: ^29.7.0 - jest-worker: ^29.7.0 - micromatch: ^4.0.4 - walker: ^1.0.8 - dependenciesMeta: - fsevents: - optional: true - checksum: c2c8f2d3e792a963940fbdfa563ce14ef9e14d4d86da645b96d3cd346b8d35c5ce0b992ee08593939b5f718cf0a1f5a90011a056548a1dbf58397d4356786f01 - languageName: node - linkType: hard - "jest-leak-detector@npm:^29.6.2": version: 29.6.2 resolution: "jest-leak-detector@npm:29.6.2" @@ -13356,24 +13126,6 @@ __metadata: languageName: node linkType: hard -"jest-light-runner@npm:^0.5.1": - version: 0.5.1 - resolution: "jest-light-runner@npm:0.5.1" - dependencies: - "@jest/expect": ^29.0.1 - "@jest/fake-timers": ^29.2.2 - jest-circus: ^29.0.1 - jest-each: ^29.0.1 - jest-mock: ^29.0.1 - jest-snapshot: ^29.0.1 - piscina: ^3.1.0 - supports-color: ^9.2.1 - peerDependencies: - jest: ^27.5.0 || ^28.0.0 || ^29.0.0 - checksum: ef7ce093835f51396308ce488401fc0cce4fa2f278b0420bf4b2f6bedd469d97264db53f3a5fca3df28ff4f72714782406a0bc425b0fa473e8572bf83b738ed2 - languageName: node - linkType: hard - "jest-matcher-utils@npm:^29.6.2": version: 29.6.2 resolution: "jest-matcher-utils@npm:29.6.2" @@ -13398,18 +13150,6 @@ __metadata: languageName: node linkType: hard -"jest-matcher-utils@npm:^29.7.0": - version: 29.7.0 - resolution: "jest-matcher-utils@npm:29.7.0" - dependencies: - chalk: ^4.0.0 - jest-diff: ^29.7.0 - jest-get-type: ^29.6.3 - pretty-format: ^29.7.0 - checksum: d7259e5f995d915e8a37a8fd494cb7d6af24cd2a287b200f831717ba0d015190375f9f5dc35393b8ba2aae9b2ebd60984635269c7f8cff7d85b077543b7744cd - languageName: node - linkType: hard - "jest-message-util@npm:^29.6.2": version: 29.6.2 resolution: "jest-message-util@npm:29.6.2" @@ -13444,23 +13184,6 @@ __metadata: languageName: node linkType: hard -"jest-message-util@npm:^29.7.0": - version: 29.7.0 - resolution: "jest-message-util@npm:29.7.0" - dependencies: - "@babel/code-frame": ^7.12.13 - "@jest/types": ^29.6.3 - "@types/stack-utils": ^2.0.0 - chalk: ^4.0.0 - graceful-fs: ^4.2.9 - micromatch: ^4.0.4 - pretty-format: ^29.7.0 - slash: ^3.0.0 - stack-utils: ^2.0.3 - checksum: a9d025b1c6726a2ff17d54cc694de088b0489456c69106be6b615db7a51b7beb66788bea7a59991a019d924fbf20f67d085a445aedb9a4d6760363f4d7d09930 - languageName: node - linkType: hard - "jest-mock-extended@npm:^3.0.3, jest-mock-extended@npm:^3.0.4": version: 3.0.4 resolution: "jest-mock-extended@npm:3.0.4" @@ -13485,17 +13208,6 @@ __metadata: languageName: node linkType: hard -"jest-mock@npm:^29.0.1, jest-mock@npm:^29.7.0": - version: 29.7.0 - resolution: "jest-mock@npm:29.7.0" - dependencies: - "@jest/types": ^29.6.3 - "@types/node": "*" - jest-util: ^29.7.0 - checksum: 81ba9b68689a60be1482212878973700347cb72833c5e5af09895882b9eb5c4e02843a1bbdf23f94c52d42708bab53a30c45a3482952c9eec173d1eaac5b86c5 - languageName: node - linkType: hard - "jest-mock@npm:^29.6.2": version: 29.6.2 resolution: "jest-mock@npm:29.6.2" @@ -13598,23 +13310,6 @@ __metadata: languageName: node linkType: hard -"jest-resolve@npm:^29.7.0": - version: 29.7.0 - resolution: "jest-resolve@npm:29.7.0" - dependencies: - chalk: ^4.0.0 - graceful-fs: ^4.2.9 - jest-haste-map: ^29.7.0 - jest-pnp-resolver: ^1.2.2 - jest-util: ^29.7.0 - jest-validate: ^29.7.0 - resolve: ^1.20.0 - resolve.exports: ^2.0.0 - slash: ^3.0.0 - checksum: 0ca218e10731aa17920526ec39deaec59ab9b966237905ffc4545444481112cd422f01581230eceb7e82d86f44a543d520a71391ec66e1b4ef1a578bd5c73487 - languageName: node - linkType: hard - "jest-runner@npm:^29.6.2": version: 29.6.2 resolution: "jest-runner@npm:29.6.2" @@ -13733,64 +13428,6 @@ __metadata: languageName: node linkType: hard -"jest-runtime@npm:^29.7.0": - version: 29.7.0 - resolution: "jest-runtime@npm:29.7.0" - dependencies: - "@jest/environment": ^29.7.0 - "@jest/fake-timers": ^29.7.0 - "@jest/globals": ^29.7.0 - "@jest/source-map": ^29.6.3 - "@jest/test-result": ^29.7.0 - "@jest/transform": ^29.7.0 - "@jest/types": ^29.6.3 - "@types/node": "*" - chalk: ^4.0.0 - cjs-module-lexer: ^1.0.0 - collect-v8-coverage: ^1.0.0 - glob: ^7.1.3 - graceful-fs: ^4.2.9 - jest-haste-map: ^29.7.0 - jest-message-util: ^29.7.0 - jest-mock: ^29.7.0 - jest-regex-util: ^29.6.3 - jest-resolve: ^29.7.0 - jest-snapshot: ^29.7.0 - jest-util: ^29.7.0 - slash: ^3.0.0 - strip-bom: ^4.0.0 - checksum: d19f113d013e80691e07047f68e1e3448ef024ff2c6b586ce4f90cd7d4c62a2cd1d460110491019719f3c59bfebe16f0e201ed005ef9f80e2cf798c374eed54e - languageName: node - linkType: hard - -"jest-snapshot@npm:^29.0.1, jest-snapshot@npm:^29.7.0": - version: 29.7.0 - resolution: "jest-snapshot@npm:29.7.0" - dependencies: - "@babel/core": ^7.11.6 - "@babel/generator": ^7.7.2 - "@babel/plugin-syntax-jsx": ^7.7.2 - "@babel/plugin-syntax-typescript": ^7.7.2 - "@babel/types": ^7.3.3 - "@jest/expect-utils": ^29.7.0 - "@jest/transform": ^29.7.0 - "@jest/types": ^29.6.3 - babel-preset-current-node-syntax: ^1.0.0 - chalk: ^4.0.0 - expect: ^29.7.0 - graceful-fs: ^4.2.9 - jest-diff: ^29.7.0 - jest-get-type: ^29.6.3 - jest-matcher-utils: ^29.7.0 - jest-message-util: ^29.7.0 - jest-util: ^29.7.0 - natural-compare: ^1.4.0 - pretty-format: ^29.7.0 - semver: ^7.5.3 - checksum: 86821c3ad0b6899521ce75ee1ae7b01b17e6dfeff9166f2cf17f012e0c5d8c798f30f9e4f8f7f5bed01ea7b55a6bc159f5eda778311162cbfa48785447c237ad - languageName: node - linkType: hard - "jest-snapshot@npm:^29.6.2": version: 29.6.2 resolution: "jest-snapshot@npm:29.6.2" @@ -13875,20 +13512,6 @@ __metadata: languageName: node linkType: hard -"jest-util@npm:^29.7.0": - version: 29.7.0 - resolution: "jest-util@npm:29.7.0" - dependencies: - "@jest/types": ^29.6.3 - "@types/node": "*" - chalk: ^4.0.0 - ci-info: ^3.2.0 - graceful-fs: ^4.2.9 - picomatch: ^2.2.3 - checksum: 042ab4980f4ccd4d50226e01e5c7376a8556b472442ca6091a8f102488c0f22e6e8b89ea874111d2328a2080083bf3225c86f3788c52af0bd0345a00eb57a3ca - languageName: node - linkType: hard - "jest-validate@npm:^29.6.2": version: 29.6.2 resolution: "jest-validate@npm:29.6.2" @@ -13917,20 +13540,6 @@ __metadata: languageName: node linkType: hard -"jest-validate@npm:^29.7.0": - version: 29.7.0 - resolution: "jest-validate@npm:29.7.0" - dependencies: - "@jest/types": ^29.6.3 - camelcase: ^6.2.0 - chalk: ^4.0.0 - jest-get-type: ^29.6.3 - leven: ^3.1.0 - pretty-format: ^29.7.0 - checksum: 191fcdc980f8a0de4dbdd879fa276435d00eb157a48683af7b3b1b98b0f7d9de7ffe12689b617779097ff1ed77601b9f7126b0871bba4f776e222c40f62e9dae - languageName: node - linkType: hard - "jest-watcher@npm:^29.6.2": version: 29.6.2 resolution: "jest-watcher@npm:29.6.2" @@ -13998,18 +13607,6 @@ __metadata: languageName: node linkType: hard -"jest-worker@npm:^29.7.0": - version: 29.7.0 - resolution: "jest-worker@npm:29.7.0" - dependencies: - "@types/node": "*" - jest-util: ^29.7.0 - merge-stream: ^2.0.0 - supports-color: ^8.0.0 - checksum: 30fff60af49675273644d408b650fc2eb4b5dcafc5a0a455f238322a8f9d8a98d847baca9d51ff197b6747f54c7901daa2287799230b856a0f48287d131f8c13 - languageName: node - linkType: hard - "jest@npm:^29.5.0": version: 29.6.2 resolution: "jest@npm:29.6.2" @@ -15791,17 +15388,6 @@ __metadata: languageName: node linkType: hard -"nice-napi@npm:^1.0.2": - version: 1.0.2 - resolution: "nice-napi@npm:1.0.2" - dependencies: - node-addon-api: ^3.0.0 - node-gyp: latest - node-gyp-build: ^4.2.2 - conditions: "!os=win32" - languageName: node - linkType: hard - "node-addon-api@npm:^2.0.0": version: 2.0.2 resolution: "node-addon-api@npm:2.0.2" @@ -15811,15 +15397,6 @@ __metadata: languageName: node linkType: hard -"node-addon-api@npm:^3.0.0": - version: 3.2.1 - resolution: "node-addon-api@npm:3.2.1" - dependencies: - node-gyp: latest - checksum: 2369986bb0881ccd9ef6bacdf39550e07e089a9c8ede1cbc5fc7712d8e2faa4d50da0e487e333d4125f8c7a616c730131d1091676c9d499af1d74560756b4a18 - languageName: node - linkType: hard - "node-cleanup@npm:^2.1.2": version: 2.1.2 resolution: "node-cleanup@npm:2.1.2" @@ -15866,7 +15443,7 @@ __metadata: languageName: node linkType: hard -"node-gyp-build@npm:^4.2.0, node-gyp-build@npm:^4.2.2": +"node-gyp-build@npm:^4.2.0": version: 4.6.1 resolution: "node-gyp-build@npm:4.6.1" bin: @@ -16448,13 +16025,6 @@ __metadata: languageName: node linkType: hard -"pako@npm:^1.0.3, pako@npm:~1.0.2": - version: 1.0.11 - resolution: "pako@npm:1.0.11" - checksum: 1be2bfa1f807608c7538afa15d6f25baa523c30ec870a3228a89579e474a4d992f4293859524e46d5d87fd30fa17c5edf34dbef0671251d9749820b488660b16 - languageName: node - linkType: hard - "pako@npm:^2.1.0": version: 2.1.0 resolution: "pako@npm:2.1.0" @@ -16462,6 +16032,13 @@ __metadata: languageName: node linkType: hard +"pako@npm:~1.0.2": + version: 1.0.11 + resolution: "pako@npm:1.0.11" + checksum: 1be2bfa1f807608c7538afa15d6f25baa523c30ec870a3228a89579e474a4d992f4293859524e46d5d87fd30fa17c5edf34dbef0671251d9749820b488660b16 + languageName: node + linkType: hard + "parent-module@npm:^1.0.0": version: 1.0.1 resolution: "parent-module@npm:1.0.1" @@ -16706,21 +16283,6 @@ __metadata: languageName: node linkType: hard -"piscina@npm:^3.1.0": - version: 3.2.0 - resolution: "piscina@npm:3.2.0" - dependencies: - eventemitter-asyncresource: ^1.0.0 - hdr-histogram-js: ^2.0.1 - hdr-histogram-percentiles-obj: ^3.0.0 - nice-napi: ^1.0.2 - dependenciesMeta: - nice-napi: - optional: true - checksum: c1980c7d45d85f53265652dd2fc62a2b9e9d2321f5bbb9fc1796edb9c1324bb77c153e823a0d6454c3c35098820efedff584737cc282207480afe478a3b8a166 - languageName: node - linkType: hard - "pkg-dir@npm:^4.2.0": version: 4.2.0 resolution: "pkg-dir@npm:4.2.0" @@ -16987,17 +16549,6 @@ __metadata: languageName: node linkType: hard -"pretty-format@npm:^29.7.0": - version: 29.7.0 - resolution: "pretty-format@npm:29.7.0" - dependencies: - "@jest/schemas": ^29.6.3 - ansi-styles: ^5.0.0 - react-is: ^18.0.0 - checksum: 032c1602383e71e9c0c02a01bbd25d6759d60e9c7cf21937dde8357aa753da348fcec5def5d1002c9678a8524d5fe099ad98861286550ef44de8808cc61e43b6 - languageName: node - linkType: hard - "pretty-ms@npm:^7.0.1": version: 7.0.1 resolution: "pretty-ms@npm:7.0.1" @@ -19180,13 +18731,6 @@ __metadata: languageName: node linkType: hard -"supports-color@npm:^9.2.1": - version: 9.4.0 - resolution: "supports-color@npm:9.4.0" - checksum: cb8ff8daeaf1db642156f69a9aa545b6c01dd9c4def4f90a49f46cbf24be0c245d392fcf37acd119cd1819b99dad2cc9b7e3260813f64bcfd7f5b18b5a1eefb8 - languageName: node - linkType: hard - "supports-preserve-symlinks-flag@npm:^1.0.0": version: 1.0.0 resolution: "supports-preserve-symlinks-flag@npm:1.0.0" From 36d226e7d67f80e995f9bed237437c2e1fb0d9e9 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Thu, 2 Nov 2023 19:16:07 +0000 Subject: [PATCH 19/29] Fixes. --- yarn-project/end-to-end/package.json | 2 +- yarn-project/end-to-end/scripts/docker-compose.yml | 1 + yarn-project/end-to-end/src/e2e_ordering.test.ts | 2 +- yarn-project/pxe/src/kernel_prover/proof_creator.ts | 1 - 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn-project/end-to-end/package.json b/yarn-project/end-to-end/package.json index 58960a8f48df..3c6adc367f09 100644 --- a/yarn-project/end-to-end/package.json +++ b/yarn-project/end-to-end/package.json @@ -9,7 +9,7 @@ "clean": "rm -rf ./dest .tsbuildinfo", "formatting": "run -T prettier --check ./src \"!src/web/main.js\" && run -T eslint ./src", "formatting:fix": "run -T prettier -w ./src", - "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --runInBand --passWithNoTests --testTimeout=15000 --forceExit", + "test": "DEBUG='aztec:*' NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --runInBand --passWithNoTests --testTimeout=15000 --forceExit", "test:integration": "concurrently -k -s first -c reset,dim -n test,anvil \"yarn test:integration:run\" \"anvil\"", "test:integration:run": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --config jest.integration.config.json" }, diff --git a/yarn-project/end-to-end/scripts/docker-compose.yml b/yarn-project/end-to-end/scripts/docker-compose.yml index 59364f2bc789..9b675470f35c 100644 --- a/yarn-project/end-to-end/scripts/docker-compose.yml +++ b/yarn-project/end-to-end/scripts/docker-compose.yml @@ -16,6 +16,7 @@ services: image: aztecprotocol/aztec-sandbox:latest environment: DEBUG: 'aztec:*' + DEBUG_COLORS: 1 ETHEREUM_HOST: http://fork:8545 CHAIN_ID: 31337 ARCHIVER_POLLING_INTERVAL_MS: 50 diff --git a/yarn-project/end-to-end/src/e2e_ordering.test.ts b/yarn-project/end-to-end/src/e2e_ordering.test.ts index a9938b17f6b7..b8f704a9a064 100644 --- a/yarn-project/end-to-end/src/e2e_ordering.test.ts +++ b/yarn-project/end-to-end/src/e2e_ordering.test.ts @@ -65,7 +65,7 @@ describe('e2e_ordering', () => { expect(enqueuedPublicCalls.length).toEqual(2); // The call stack hashes in the output of the kernel proof match the tx enqueuedPublicFunctionCalls - const hashes = enqueuedPublicCalls.map(c => c.toPublicCallStackItem().hash()); + const hashes = await Promise.all(enqueuedPublicCalls.map(c => c.toPublicCallStackItem().hash())); expect(tx.data.end.publicCallStack.slice(0, 2)).toEqual(hashes); // The enqueued public calls are in the expected order based on the argument they set (stack is reversed!) diff --git a/yarn-project/pxe/src/kernel_prover/proof_creator.ts b/yarn-project/pxe/src/kernel_prover/proof_creator.ts index 12a8aa8ba4dc..afd1e5862242 100644 --- a/yarn-project/pxe/src/kernel_prover/proof_creator.ts +++ b/yarn-project/pxe/src/kernel_prover/proof_creator.ts @@ -1,5 +1,4 @@ import { - CircuitsWasm, KernelCircuitPublicInputs, KernelCircuitPublicInputsFinal, PrivateCircuitPublicInputs, From 880acb7f0d1a3431c00fc8da436cb59967346237 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Thu, 2 Nov 2023 22:19:44 +0000 Subject: [PATCH 20/29] Fixes. --- build-system/scripts/spot_run_script | 3 ++- .../circuits.js/src/contract/contract_deployment_info.ts | 2 +- .../circuits.js/src/contract/contract_tree/contract_tree.ts | 2 +- yarn-project/end-to-end/src/shared/browser.ts | 4 ++++ yarn-project/pxe/src/contract_tree/index.ts | 4 ++-- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/build-system/scripts/spot_run_script b/build-system/scripts/spot_run_script index 69707de660f4..33a0fc3dfb0a 100755 --- a/build-system/scripts/spot_run_script +++ b/build-system/scripts/spot_run_script @@ -11,6 +11,7 @@ set -eu CONTENT_HASH=$1 CPUS=$2 shift 2 +IP= # On any sort of exit (error or not). function on_exit { @@ -38,5 +39,5 @@ if [ -z "$IP" ]; then exit 1 fi -# Run script remotely on spot instance, capturing success or failure. +# Run script remotely on spot instance, returning success or failure. remote_run_script $IP $@ \ No newline at end of file diff --git a/yarn-project/circuits.js/src/contract/contract_deployment_info.ts b/yarn-project/circuits.js/src/contract/contract_deployment_info.ts index 4476ac852bea..5914d6c840bf 100644 --- a/yarn-project/circuits.js/src/contract/contract_deployment_info.ts +++ b/yarn-project/circuits.js/src/contract/contract_deployment_info.ts @@ -38,7 +38,7 @@ export async function getContractDeploymentInfo( ...f, selector: FunctionSelector.fromNameAndParameters(f.name, f.parameters), })); - const leaves = generateFunctionLeaves(functions, wasm); + const leaves = generateFunctionLeaves(functions); const functionTreeRoot = computeFunctionTreeRoot(wasm, leaves); const functionData = FunctionData.fromAbi(constructorArtifact); const flatArgs = encodeArguments(constructorArtifact, args); diff --git a/yarn-project/circuits.js/src/contract/contract_tree/contract_tree.ts b/yarn-project/circuits.js/src/contract/contract_tree/contract_tree.ts index 2264299dcb3d..b74a372849b7 100644 --- a/yarn-project/circuits.js/src/contract/contract_tree/contract_tree.ts +++ b/yarn-project/circuits.js/src/contract/contract_tree/contract_tree.ts @@ -64,7 +64,7 @@ export function isConstrained({ * @param wasm - CircuitsWasm instance used for hashing and computations. * @returns An array of Fr instances representing the generated function leaves. */ -export function generateFunctionLeaves(functions: ContractFunctionDao[], wasm: CircuitsWasm) { +export function generateFunctionLeaves(functions: ContractFunctionDao[]) { const targetFunctions = functions.filter(isConstrained); const result: Fr[] = []; for (let i = 0; i < targetFunctions.length; i++) { diff --git a/yarn-project/end-to-end/src/shared/browser.ts b/yarn-project/end-to-end/src/shared/browser.ts index f28f847e2e86..050c5f4f8144 100644 --- a/yarn-project/end-to-end/src/shared/browser.ts +++ b/yarn-project/end-to-end/src/shared/browser.ts @@ -72,6 +72,10 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL pageLogger.error(err.toString()); }); await page.goto(`http://localhost:${PORT}/index.html`); + while (!(await page.evaluate(() => !!window.AztecJs))) { + pageLogger('Waiting for window.AztecJs...'); + await AztecJs.sleep(1000); + } }, 120_000); afterAll(async () => { diff --git a/yarn-project/pxe/src/contract_tree/index.ts b/yarn-project/pxe/src/contract_tree/index.ts index 1ac235c6336a..81546f39bafe 100644 --- a/yarn-project/pxe/src/contract_tree/index.ts +++ b/yarn-project/pxe/src/contract_tree/index.ts @@ -87,7 +87,7 @@ export class ContractTree { ...f, selector: FunctionSelector.fromNameAndParameters(f.name, f.parameters), })); - const leaves = generateFunctionLeaves(functions, wasm); + const leaves = generateFunctionLeaves(functions); const root = computeFunctionTreeRoot(wasm, leaves); const functionData = FunctionData.fromAbi(constructorArtifact); const vkHash = hashVKStr(constructorArtifact.verificationKey, wasm); @@ -218,7 +218,7 @@ export class ContractTree { */ private getFunctionLeaves() { if (!this.functionLeaves) { - this.functionLeaves = generateFunctionLeaves(this.contract.functions, this.wasm); + this.functionLeaves = generateFunctionLeaves(this.contract.functions); } return this.functionLeaves; } From e83961ae3d0bc71e4242f9ddf6cf488a7e672aa4 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Fri, 3 Nov 2023 09:41:01 +0000 Subject: [PATCH 21/29] timestamps on compose runs [ci rebuild end-to-end] --- build-system/scripts/cond_spot_run_compose | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-system/scripts/cond_spot_run_compose b/build-system/scripts/cond_spot_run_compose index b10cc9decf59..0c49b7fe1729 100755 --- a/build-system/scripts/cond_spot_run_compose +++ b/build-system/scripts/cond_spot_run_compose @@ -7,4 +7,4 @@ CPUS=$2 shift 2 export TAG_POSTFIX=$JOB_NAME -cond_spot_run_script $REPOSITORY $CPUS cond_run_compose $REPOSITORY $@ +cond_spot_run_script $REPOSITORY $CPUS cond_run_compose $REPOSITORY $@ | add_timestamps From 34b82fbfad84cc7f20ed3ff17bb349450259c7da Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Fri, 3 Nov 2023 10:32:16 +0000 Subject: [PATCH 22/29] Update cond_spot_run_compose [ci rebuild end-to-end] --- build-system/scripts/cond_spot_run_compose | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-system/scripts/cond_spot_run_compose b/build-system/scripts/cond_spot_run_compose index 0c49b7fe1729..c41cc9ad4396 100755 --- a/build-system/scripts/cond_spot_run_compose +++ b/build-system/scripts/cond_spot_run_compose @@ -7,4 +7,4 @@ CPUS=$2 shift 2 export TAG_POSTFIX=$JOB_NAME -cond_spot_run_script $REPOSITORY $CPUS cond_run_compose $REPOSITORY $@ | add_timestamps +cond_spot_run_script $REPOSITORY $CPUS cond_run_compose $REPOSITORY $@ | add_timestamps 2>&1 From 96fb2095971954d6e1e6c4ec7e857e522592a21e Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Fri, 3 Nov 2023 10:32:56 +0000 Subject: [PATCH 23/29] Update cond_spot_run_compose [ci rebuild end-to-end] --- build-system/scripts/cond_spot_run_compose | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-system/scripts/cond_spot_run_compose b/build-system/scripts/cond_spot_run_compose index c41cc9ad4396..1d8b5c667881 100755 --- a/build-system/scripts/cond_spot_run_compose +++ b/build-system/scripts/cond_spot_run_compose @@ -7,4 +7,4 @@ CPUS=$2 shift 2 export TAG_POSTFIX=$JOB_NAME -cond_spot_run_script $REPOSITORY $CPUS cond_run_compose $REPOSITORY $@ | add_timestamps 2>&1 +cond_spot_run_script $REPOSITORY $CPUS cond_run_compose $REPOSITORY $@ 2>&1 | add_timestamps From ccdd2be7bef99084e621ab89de22c5c87590a031 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Fri, 3 Nov 2023 11:02:08 +0000 Subject: [PATCH 24/29] use printf in add_timestamps as I got paranoid about performance. [ci rebuild end-to-end] --- build-system/scripts/add_timestamps | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-system/scripts/add_timestamps b/build-system/scripts/add_timestamps index 4eeab6f56db8..8b658925ba50 100755 --- a/build-system/scripts/add_timestamps +++ b/build-system/scripts/add_timestamps @@ -1,4 +1,4 @@ #!/bin/bash while IFS= read -r line; do - echo "$(date '+%Y-%m-%d %H:%M:%S') $line" + printf '%(%Y-%m-%d %H:%M:%S)T %s\n' -1 "$line" done From 4bad573ce4dbe12dad1cefb0d2d91fc6ec82c8da Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Fri, 3 Nov 2023 11:03:30 +0000 Subject: [PATCH 25/29] [ci rebuild end-to-end] From d5ee8cceebaf5f8d90ef1d3b48ca77febb45c166 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Fri, 3 Nov 2023 22:10:07 +0000 Subject: [PATCH 26/29] pedersenCommit shouldn't have hashIndex. --- .../src/barretenberg/crypto/pedersen_commitment/c_bind.cpp | 6 +----- .../src/barretenberg/crypto/pedersen_commitment/c_bind.hpp | 4 +--- barretenberg/exports.json | 4 ---- barretenberg/ts/src/barretenberg_api/index.ts | 4 ++-- barretenberg/ts/src/pedersen/pedersen.ts | 7 +++---- 5 files changed, 7 insertions(+), 18 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp index a3fef2032b55..67188995545d 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp @@ -7,14 +7,10 @@ extern "C" { using namespace barretenberg; -WASM_EXPORT void pedersen_commit(fr::vec_in_buf inputs_buffer, - uint32_t const* hash_index, - affine_element::out_buf output) +WASM_EXPORT void pedersen_commit(fr::vec_in_buf inputs_buffer, affine_element::out_buf output) { std::vector to_commit; read(inputs_buffer, to_commit); - crypto::GeneratorContext ctx; - ctx.offset = static_cast(ntohl(*hash_index)); grumpkin::g1::affine_element pedersen_commitment = crypto::pedersen_commitment::commit_native(to_commit); serialize::write(output, pedersen_commitment); diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp index e8c6db5eeb1d..3de155cae2bd 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp @@ -8,7 +8,5 @@ extern "C" { using namespace barretenberg; using affine_element = grumpkin::g1::affine_element; -WASM_EXPORT void pedersen_commit(fr::vec_in_buf inputs_buffer, - uint32_t const* hash_index, - affine_element::out_buf output); +WASM_EXPORT void pedersen_commit(fr::vec_in_buf inputs_buffer, affine_element::out_buf output); } \ No newline at end of file diff --git a/barretenberg/exports.json b/barretenberg/exports.json index 78152fb3c30c..18dfb174475f 100644 --- a/barretenberg/exports.json +++ b/barretenberg/exports.json @@ -5,10 +5,6 @@ { "name": "inputs_buffer", "type": "fr::vec_in_buf" - }, - { - "name": "hash_index", - "type": "const uint32_t *" } ], "outArgs": [ diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index eab96a1f9742..aaa718f5b582 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -17,8 +17,8 @@ export class BarretenbergApi { await this.binder.wasm.destroy(); } - async pedersenCommit(inputsBuffer: Fr[], hashIndex: number): Promise { - const result = await this.binder.callWasmExport('pedersen_commit', [inputsBuffer, hashIndex], [Point]); + async pedersenCommit(inputsBuffer: Fr[]): Promise { + const result = await this.binder.callWasmExport('pedersen_commit', [inputsBuffer], [Point]); return result[0]; } diff --git a/barretenberg/ts/src/pedersen/pedersen.ts b/barretenberg/ts/src/pedersen/pedersen.ts index ebf7d9645b9b..be9028cbd863 100644 --- a/barretenberg/ts/src/pedersen/pedersen.ts +++ b/barretenberg/ts/src/pedersen/pedersen.ts @@ -33,20 +33,19 @@ export class Pedersen { return hashOutput; } - pedersenCommit(inputs: Uint8Array[], hashIndex = 0) { + pedersenCommit(inputs: Uint8Array[]) { const SCRATCH_SPACE_SIZE = 1024; const data = serializeBufferArrayToVector(inputs); let inputPtr = 0; - if (data.length > SCRATCH_SPACE_SIZE - 4) { + if (data.length > SCRATCH_SPACE_SIZE) { inputPtr = this.wasm.call('bbmalloc', data.length); } this.wasm.writeMemory(inputPtr, data); - this.wasm.writeMemory(SCRATCH_SPACE_SIZE - 4, numToUInt32BE(hashIndex)); const outputPtr = 0; - this.wasm.call('pedersen_commit', inputPtr, SCRATCH_SPACE_SIZE - 4, outputPtr); + this.wasm.call('pedersen_commit', inputPtr, outputPtr); const hashOutput = this.wasm.getMemorySlice(0, 64); if (inputPtr !== 0) { From 6bbb4c01098e4443aee8021b49aadc4a0687aa26 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Sat, 4 Nov 2023 19:08:14 +0000 Subject: [PATCH 27/29] fix --- yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts b/yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts index f4688b8fcfe4..86fd96e882d9 100644 --- a/yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts +++ b/yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts @@ -6,12 +6,12 @@ const pedersen = await Pedersen.new(); * Create a pedersen commitment (point) from an array of input fields. * Left pads any inputs less than 32 bytes. */ -export function pedersenCommit(input: Buffer[], generatorOffset = 0) { +export function pedersenCommit(input: Buffer[]) { if (!input.every(i => i.length <= 32)) { throw new Error('All input buffers must be <= 32 bytes.'); } input = input.map(i => (i.length < 32 ? Buffer.concat([Buffer.alloc(32 - i.length, 0), i]) : i)); - const [x, y] = pedersen.pedersenCommit(input, generatorOffset); + const [x, y] = pedersen.pedersenCommit(input); return [Buffer.from(x), Buffer.from(y)]; } From 1714d46c97dbd7ce9ffe8c4b9d88dd5fdedf41c9 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Tue, 7 Nov 2023 15:18:28 +0000 Subject: [PATCH 28/29] Fix field change oops. Remove c_bind_new for schnorr. --- .../barretenberg/crypto/schnorr/c_bind.cpp | 103 +++++++----- .../barretenberg/crypto/schnorr/c_bind.hpp | 8 +- .../crypto/schnorr/c_bind_new.cpp | 150 ------------------ barretenberg/exports.json | 8 +- barretenberg/ts/src/barretenberg_api/index.ts | 10 +- .../ts/src/barretenberg_api/schnorr.test.ts | 10 +- 6 files changed, 77 insertions(+), 212 deletions(-) delete mode 100644 barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind_new.cpp diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp index ce31a6928a0d..b1ceb606a330 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp @@ -1,16 +1,22 @@ +#include "c_bind.hpp" #include "multisig.hpp" #include "schnorr.hpp" -#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" +extern "C" { -WASM_EXPORT void compute_public_key(uint8_t const* private_key, uint8_t* public_key_buf) +using namespace barretenberg; +using affine_element = grumpkin::g1::affine_element; +using multisig = crypto::schnorr::multisig; +using multisig_public_key = typename multisig::MultiSigPublicKey; + +WASM_EXPORT void schnorr_compute_public_key(uint8_t const* private_key, uint8_t* public_key_buf) { auto priv_key = from_buffer(private_key); grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; serialize::write(public_key_buf, pub_key); } -WASM_EXPORT void negate_public_key(uint8_t const* public_key_buffer, uint8_t* output) +WASM_EXPORT void schnorr_negate_public_key(uint8_t const* public_key_buffer, uint8_t* output) { // Negate the public key (effectively negating the y-coordinate of the public key) and return the resulting public // key. @@ -18,31 +24,35 @@ WASM_EXPORT void negate_public_key(uint8_t const* public_key_buffer, uint8_t* ou serialize::write(output, -account_public_key); } -WASM_EXPORT void construct_signature( - uint8_t const* message, size_t msg_len, uint8_t const* private_key, uint8_t* s, uint8_t* e) +WASM_EXPORT void schnorr_construct_signature(uint8_t const* message_buf, + uint8_t const* private_key, + uint8_t* s, + uint8_t* e) { + auto message = from_buffer(message_buf); auto priv_key = from_buffer(private_key); grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; crypto::schnorr::key_pair key_pair = { priv_key, pub_key }; - auto sig = crypto::schnorr::construct_signature(std::string((char*)message, msg_len), - key_pair); + auto sig = crypto::schnorr::construct_signature(message, key_pair); write(s, sig.s); write(e, sig.e); } -WASM_EXPORT bool verify_signature( - uint8_t const* message, size_t msg_len, uint8_t const* pub_key, uint8_t const* sig_s, uint8_t const* sig_e) +WASM_EXPORT void schnorr_verify_signature( + uint8_t const* message_buf, uint8_t const* pub_key, uint8_t const* sig_s, uint8_t const* sig_e, bool* result) { auto pubk = from_buffer(pub_key); - std::array s, e; + auto message = from_buffer(message_buf); + std::array s; + std::array e; std::copy(sig_s, sig_s + 32, s.begin()); std::copy(sig_e, sig_e + 32, e.begin()); crypto::schnorr::signature sig = { s, e }; - return crypto::schnorr::verify_signature( - std::string((char*)message, msg_len), pubk, sig); + *result = + crypto::schnorr::verify_signature(message, pubk, sig); } -WASM_EXPORT void multisig_create_multisig_public_key(uint8_t const* private_key, uint8_t* multisig_pubkey_buf) +WASM_EXPORT void schnorr_multisig_create_multisig_public_key(uint8_t const* private_key, uint8_t* multisig_pubkey_buf) { using multisig = crypto::schnorr::multisig; using multisig_public_key = typename multisig::MultiSigPublicKey; @@ -55,23 +65,26 @@ WASM_EXPORT void multisig_create_multisig_public_key(uint8_t const* private_key, serialize::write(multisig_pubkey_buf, agg_pubkey); } -WASM_EXPORT bool multisig_validate_and_combine_signer_pubkeys(uint8_t const* signer_pubkey_buf, - uint8_t* combined_key_buf) +WASM_EXPORT void schnorr_multisig_validate_and_combine_signer_pubkeys(uint8_t const* signer_pubkey_buf, + affine_element::out_buf combined_key_buf, + bool* success) { using multisig = crypto::schnorr::multisig; - std::vector pubkeys = - from_buffer>(signer_pubkey_buf); + auto pubkeys = from_buffer>(signer_pubkey_buf); + + auto combined_key = multisig::validate_and_combine_signer_pubkeys(pubkeys); - if (auto combined_key = multisig::validate_and_combine_signer_pubkeys(pubkeys); combined_key) { + if (combined_key) { serialize::write(combined_key_buf, *combined_key); - return true; + *success = true; } else { - return false; + serialize::write(combined_key_buf, affine_element::one()); + *success = false; } } -WASM_EXPORT void multisig_construct_signature_round_1(uint8_t* round_one_public_output_buf, - uint8_t* round_one_private_output_buf) +WASM_EXPORT void schnorr_multisig_construct_signature_round_1(uint8_t* round_one_public_output_buf, + uint8_t* round_one_private_output_buf) { using multisig = crypto::schnorr::multisig; @@ -80,15 +93,16 @@ WASM_EXPORT void multisig_construct_signature_round_1(uint8_t* round_one_public_ serialize::write(round_one_private_output_buf, private_output); } -WASM_EXPORT bool multisig_construct_signature_round_2(uint8_t const* message, - size_t msg_len, - uint8_t* const private_key, - uint8_t* const signer_round_one_private_buf, - uint8_t* const signer_pubkeys_buf, - uint8_t* const round_one_public_buf, - uint8_t* round_two_buf) +WASM_EXPORT void schnorr_multisig_construct_signature_round_2(uint8_t const* message_buf, + uint8_t const* private_key, + uint8_t const* signer_round_one_private_buf, + uint8_t const* signer_pubkeys_buf, + uint8_t const* round_one_public_buf, + uint8_t* round_two_buf, + bool* success) { using multisig = crypto::schnorr::multisig; + auto message = from_buffer(message_buf); auto priv_key = from_buffer(private_key); grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; crypto::schnorr::key_pair key_pair = { priv_key, pub_key }; @@ -97,39 +111,40 @@ WASM_EXPORT bool multisig_construct_signature_round_2(uint8_t const* message, auto round_one_outputs = from_buffer>(round_one_public_buf); auto round_one_private = from_buffer(signer_round_one_private_buf); - auto round_two_output = multisig::construct_signature_round_2( - std::string((char*)message, msg_len), key_pair, round_one_private, signer_pubkeys, round_one_outputs); + auto round_two_output = + multisig::construct_signature_round_2(message, key_pair, round_one_private, signer_pubkeys, round_one_outputs); if (round_two_output.has_value()) { write(round_two_buf, *round_two_output); - return true; + *success = true; } else { - return false; + *success = false; } } -WASM_EXPORT bool multisig_combine_signatures(uint8_t const* message, - size_t msg_len, - uint8_t* const signer_pubkeys_buf, - uint8_t* const round_one_buf, - uint8_t* const round_two_buf, - uint8_t* s, - uint8_t* e) +WASM_EXPORT void schnorr_multisig_combine_signatures(uint8_t const* message_buf, + uint8_t const* signer_pubkeys_buf, + uint8_t const* round_one_buf, + uint8_t const* round_two_buf, + uint8_t* s, + uint8_t* e, + bool* success) { using multisig = crypto::schnorr::multisig; + auto message = from_buffer(message_buf); auto signer_pubkeys = from_buffer>(signer_pubkeys_buf); auto round_one_outputs = from_buffer>(round_one_buf); auto round_two_outputs = from_buffer>(round_two_buf); - auto sig = multisig::combine_signatures( - std::string((char*)message, msg_len), signer_pubkeys, round_one_outputs, round_two_outputs); + auto sig = multisig::combine_signatures(message, signer_pubkeys, round_one_outputs, round_two_outputs); if (sig.has_value()) { write(s, (*sig).s); write(e, (*sig).e); - return true; + *success = true; } else { - return false; + *success = false; } } +} diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp index efd5df66dbf7..cb65671fafc3 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp @@ -17,7 +17,7 @@ WASM_EXPORT void schnorr_construct_signature(uint8_t const* message, fr::in_buf WASM_EXPORT void schnorr_verify_signature( uint8_t const* message, affine_element::in_buf pub_key, in_buf32 sig_s, in_buf32 sig_e, bool* result); -WASM_EXPORT void schnorr_multisig_create_multisig_public_key(fr::in_buf private_key, +WASM_EXPORT void schnorr_multisig_create_multisig_public_key(fq::in_buf private_key, multisig::MultiSigPublicKey::out_buf multisig_pubkey_buf); WASM_EXPORT void schnorr_multisig_validate_and_combine_signer_pubkeys( @@ -29,17 +29,17 @@ WASM_EXPORT void schnorr_multisig_construct_signature_round_1( WASM_EXPORT void schnorr_multisig_construct_signature_round_2( uint8_t const* message, - fr::in_buf private_key, + fq::in_buf private_key, multisig::RoundOnePrivateOutput::in_buf signer_round_one_private_buf, multisig::MultiSigPublicKey::vec_in_buf signer_pubkeys_buf, multisig::RoundOnePublicOutput::vec_in_buf round_one_public_buf, - fr::out_buf round_two_buf, + fq::out_buf round_two_buf, bool* success); WASM_EXPORT void schnorr_multisig_combine_signatures(uint8_t const* message, multisig::MultiSigPublicKey::vec_in_buf signer_pubkeys_buf, multisig::RoundOnePublicOutput::vec_in_buf round_one_buf, - fr::vec_in_buf round_two_buf, + fq::vec_in_buf round_two_buf, out_buf32 s, out_buf32 e, bool* success); diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind_new.cpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind_new.cpp deleted file mode 100644 index b1ceb606a330..000000000000 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind_new.cpp +++ /dev/null @@ -1,150 +0,0 @@ -#include "c_bind.hpp" -#include "multisig.hpp" -#include "schnorr.hpp" - -extern "C" { - -using namespace barretenberg; -using affine_element = grumpkin::g1::affine_element; -using multisig = crypto::schnorr::multisig; -using multisig_public_key = typename multisig::MultiSigPublicKey; - -WASM_EXPORT void schnorr_compute_public_key(uint8_t const* private_key, uint8_t* public_key_buf) -{ - auto priv_key = from_buffer(private_key); - grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; - serialize::write(public_key_buf, pub_key); -} - -WASM_EXPORT void schnorr_negate_public_key(uint8_t const* public_key_buffer, uint8_t* output) -{ - // Negate the public key (effectively negating the y-coordinate of the public key) and return the resulting public - // key. - auto account_public_key = from_buffer(public_key_buffer); - serialize::write(output, -account_public_key); -} - -WASM_EXPORT void schnorr_construct_signature(uint8_t const* message_buf, - uint8_t const* private_key, - uint8_t* s, - uint8_t* e) -{ - auto message = from_buffer(message_buf); - auto priv_key = from_buffer(private_key); - grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; - crypto::schnorr::key_pair key_pair = { priv_key, pub_key }; - auto sig = crypto::schnorr::construct_signature(message, key_pair); - write(s, sig.s); - write(e, sig.e); -} - -WASM_EXPORT void schnorr_verify_signature( - uint8_t const* message_buf, uint8_t const* pub_key, uint8_t const* sig_s, uint8_t const* sig_e, bool* result) -{ - auto pubk = from_buffer(pub_key); - auto message = from_buffer(message_buf); - std::array s; - std::array e; - std::copy(sig_s, sig_s + 32, s.begin()); - std::copy(sig_e, sig_e + 32, e.begin()); - crypto::schnorr::signature sig = { s, e }; - *result = - crypto::schnorr::verify_signature(message, pubk, sig); -} - -WASM_EXPORT void schnorr_multisig_create_multisig_public_key(uint8_t const* private_key, uint8_t* multisig_pubkey_buf) -{ - using multisig = crypto::schnorr::multisig; - using multisig_public_key = typename multisig::MultiSigPublicKey; - auto priv_key = from_buffer(private_key); - grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; - crypto::schnorr::key_pair key_pair = { priv_key, pub_key }; - - auto agg_pubkey = multisig_public_key(key_pair); - - serialize::write(multisig_pubkey_buf, agg_pubkey); -} - -WASM_EXPORT void schnorr_multisig_validate_and_combine_signer_pubkeys(uint8_t const* signer_pubkey_buf, - affine_element::out_buf combined_key_buf, - bool* success) -{ - using multisig = crypto::schnorr::multisig; - auto pubkeys = from_buffer>(signer_pubkey_buf); - - auto combined_key = multisig::validate_and_combine_signer_pubkeys(pubkeys); - - if (combined_key) { - serialize::write(combined_key_buf, *combined_key); - *success = true; - } else { - serialize::write(combined_key_buf, affine_element::one()); - *success = false; - } -} - -WASM_EXPORT void schnorr_multisig_construct_signature_round_1(uint8_t* round_one_public_output_buf, - uint8_t* round_one_private_output_buf) -{ - using multisig = crypto::schnorr::multisig; - - auto [public_output, private_output] = multisig::construct_signature_round_1(); - serialize::write(round_one_public_output_buf, public_output); - serialize::write(round_one_private_output_buf, private_output); -} - -WASM_EXPORT void schnorr_multisig_construct_signature_round_2(uint8_t const* message_buf, - uint8_t const* private_key, - uint8_t const* signer_round_one_private_buf, - uint8_t const* signer_pubkeys_buf, - uint8_t const* round_one_public_buf, - uint8_t* round_two_buf, - bool* success) -{ - using multisig = crypto::schnorr::multisig; - auto message = from_buffer(message_buf); - auto priv_key = from_buffer(private_key); - grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; - crypto::schnorr::key_pair key_pair = { priv_key, pub_key }; - - auto signer_pubkeys = from_buffer>(signer_pubkeys_buf); - auto round_one_outputs = from_buffer>(round_one_public_buf); - - auto round_one_private = from_buffer(signer_round_one_private_buf); - auto round_two_output = - multisig::construct_signature_round_2(message, key_pair, round_one_private, signer_pubkeys, round_one_outputs); - - if (round_two_output.has_value()) { - write(round_two_buf, *round_two_output); - *success = true; - } else { - *success = false; - } -} - -WASM_EXPORT void schnorr_multisig_combine_signatures(uint8_t const* message_buf, - uint8_t const* signer_pubkeys_buf, - uint8_t const* round_one_buf, - uint8_t const* round_two_buf, - uint8_t* s, - uint8_t* e, - bool* success) -{ - using multisig = crypto::schnorr::multisig; - - auto message = from_buffer(message_buf); - auto signer_pubkeys = from_buffer>(signer_pubkeys_buf); - auto round_one_outputs = from_buffer>(round_one_buf); - auto round_two_outputs = from_buffer>(round_two_buf); - - auto sig = multisig::combine_signatures(message, signer_pubkeys, round_one_outputs, round_two_outputs); - - if (sig.has_value()) { - write(s, (*sig).s); - write(e, (*sig).e); - *success = true; - } else { - *success = false; - } -} -} diff --git a/barretenberg/exports.json b/barretenberg/exports.json index 18dfb174475f..0c6856e3c877 100644 --- a/barretenberg/exports.json +++ b/barretenberg/exports.json @@ -156,7 +156,7 @@ "inArgs": [ { "name": "private_key", - "type": "fr::in_buf" + "type": "fq::in_buf" } ], "outArgs": [ @@ -211,7 +211,7 @@ }, { "name": "private_key", - "type": "fr::in_buf" + "type": "fq::in_buf" }, { "name": "signer_round_one_private_buf", @@ -229,7 +229,7 @@ "outArgs": [ { "name": "round_two_buf", - "type": "fr::out_buf" + "type": "fq::out_buf" }, { "name": "success", @@ -255,7 +255,7 @@ }, { "name": "round_two_buf", - "type": "fr::vec_in_buf" + "type": "fq::vec_in_buf" } ], "outArgs": [ diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index aaa718f5b582..5612d7406543 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -65,7 +65,7 @@ export class BarretenbergApi { return result[0]; } - async schnorrMultisigCreateMultisigPublicKey(privateKey: Fr): Promise { + async schnorrMultisigCreateMultisigPublicKey(privateKey: Fq): Promise { const result = await this.binder.callWasmExport( 'schnorr_multisig_create_multisig_public_key', [privateKey], @@ -94,15 +94,15 @@ export class BarretenbergApi { async schnorrMultisigConstructSignatureRound2( message: Uint8Array, - privateKey: Fr, + privateKey: Fq, signerRoundOnePrivateBuf: Buffer128, signerPubkeysBuf: Buffer128[], roundOnePublicBuf: Buffer128[], - ): Promise<[Fr, boolean]> { + ): Promise<[Fq, boolean]> { const result = await this.binder.callWasmExport( 'schnorr_multisig_construct_signature_round_2', [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf], - [Fr, BoolDeserializer()], + [Fq, BoolDeserializer()], ); return result as any; } @@ -111,7 +111,7 @@ export class BarretenbergApi { message: Uint8Array, signerPubkeysBuf: Buffer128[], roundOneBuf: Buffer128[], - roundTwoBuf: Fr[], + roundTwoBuf: Fq[], ): Promise<[Buffer32, Buffer32, boolean]> { const result = await this.binder.callWasmExport( 'schnorr_multisig_combine_signatures', diff --git a/barretenberg/ts/src/barretenberg_api/schnorr.test.ts b/barretenberg/ts/src/barretenberg_api/schnorr.test.ts index 6b161cfb1c98..e98e5583afa1 100644 --- a/barretenberg/ts/src/barretenberg_api/schnorr.test.ts +++ b/barretenberg/ts/src/barretenberg_api/schnorr.test.ts @@ -1,5 +1,5 @@ import { TextEncoder } from 'util'; -import { Buffer128, Buffer32, Fr, Point } from '../types/index.js'; +import { Buffer128, Buffer32, Fq, Fr, Point } from '../types/index.js'; import { Barretenberg } from '../barretenberg/index.js'; import { asyncMap } from '../async_map/index.js'; @@ -48,7 +48,7 @@ describe('schnorr', () => { it('should create + verify multi signature', async () => { // set up multisig accounts const numSigners = 7; - const pks = [...Array(numSigners)].map(() => Fr.random()); + const pks = [...Array(numSigners)].map(() => Fq.random()); const pubKeys = await asyncMap(pks, pk => api.schnorrMultisigCreateMultisigPublicKey(pk)); // round one @@ -84,7 +84,7 @@ describe('schnorr', () => { }); it('should identify invalid multi signature', async () => { - const pks = [...Array(3)].map(() => Fr.random()); + const pks = [...Array(3)].map(() => Fq.random()); const pubKeys = await asyncMap(pks, pk => api.schnorrMultisigCreateMultisigPublicKey(pk)); const [combinedKey] = await api.schnorrMultisigValidateAndCombineSignerPubkeys(pubKeys); @@ -95,7 +95,7 @@ describe('schnorr', () => { it('should not construct invalid multi signature', async () => { // set up multisig accounts const numSigners = 7; - const pks = [...Array(numSigners)].map(() => Fr.random()); + const pks = [...Array(numSigners)].map(() => Fq.random()); const pubKeys = await asyncMap(pks, pk => api.schnorrMultisigCreateMultisigPublicKey(pk)); // round one @@ -164,7 +164,7 @@ describe('schnorr', () => { }); it('should not create combined key from public keys containing invalid key', async () => { - const pks = [...Array(5)].map(() => Fr.random()); + const pks = [...Array(5)].map(() => Fq.random()); const pubKeys = await asyncMap(pks, pk => api.schnorrMultisigCreateMultisigPublicKey(pk)); // not a valid point From d3d42bfb20b0c14b696bef53b2d451577cd3ab45 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Tue, 7 Nov 2023 16:48:46 +0000 Subject: [PATCH 29/29] Formatting. --- yarn-project/end-to-end/src/e2e_cheat_codes.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts index 39dcc9477d1e..d14102622f4b 100644 --- a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts +++ b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts @@ -207,7 +207,7 @@ describe('e2e_cheat_codes', () => { // docs:start:load_private_cheatcode const mintAmount = 100n; const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const receipt = await token.methods.mint_private(mintAmount, secretHash).send().wait(); const note = new Note([new Fr(mintAmount), secretHash]);