diff --git a/yarn-project/acir-simulator/src/client/function_selectors.ts b/yarn-project/acir-simulator/src/client/function_selectors.ts deleted file mode 100644 index 900969623cb8..000000000000 --- a/yarn-project/acir-simulator/src/client/function_selectors.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { FunctionSelector } from '@aztec/circuits.js'; - -export const computeNoteHashAndNullifierSignature = 'compute_note_hash_and_nullifier(Field,Field,Field,[Field;3])'; - -export const computeNoteHashAndNullifierSelector = FunctionSelector.fromSignature(computeNoteHashAndNullifierSignature); 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 0a4202791b15..b00efb9dfeaf 100644 --- a/yarn-project/acir-simulator/src/client/private_execution.test.ts +++ b/yarn-project/acir-simulator/src/client/private_execution.test.ts @@ -621,7 +621,9 @@ describe('Private Execution test suite', () => { const result = await runSimulator({ args, abi: parentAbi }); expect(result.callStackItem.publicInputs.returnValues[0]).toEqual(new Fr(privateIncrement)); - expect(oracle.getFunctionABI.mock.calls[0]).toEqual([childAddress, childSelector]); + expect(oracle.getFunctionABI.mock.calls[0].map(a => a.toBuffer())).toEqual( + [childAddress, childSelector].map(a => a.toBuffer()), + ); expect(oracle.getPortalContractAddress.mock.calls[0]).toEqual([childAddress]); expect(result.nestedExecutions).toHaveLength(1); expect(result.nestedExecutions[0].callStackItem.publicInputs.returnValues[0]).toEqual(new Fr(privateIncrement)); @@ -671,7 +673,9 @@ describe('Private Execution test suite', () => { const result = await runSimulator({ args, abi: parentAbi }); expect(result.callStackItem.publicInputs.returnValues[0]).toEqual(argsHash); - expect(oracle.getFunctionABI.mock.calls[0]).toEqual([testAddress, testCodeGenSelector]); + expect(oracle.getFunctionABI.mock.calls[0].map(a => a.toBuffer())).toEqual( + [testAddress, testCodeGenSelector].map(a => a.toBuffer()), + ); expect(oracle.getPortalContractAddress.mock.calls[0]).toEqual([testAddress]); expect(result.nestedExecutions).toHaveLength(1); expect(result.nestedExecutions[0].callStackItem.publicInputs.returnValues[0]).toEqual(argsHash); @@ -815,7 +819,7 @@ describe('Private Execution test suite', () => { ); expect(result.enqueuedPublicFunctionCalls).toHaveLength(1); - expect(result.enqueuedPublicFunctionCalls[0]).toEqual(publicCallRequest); + expect(result.enqueuedPublicFunctionCalls[0].toBuffer()).toEqual(publicCallRequest.toBuffer()); expect(result.callStackItem.publicInputs.publicCallStack[0]).toEqual(publicCallRequestHash); }); }); diff --git a/yarn-project/acir-simulator/src/client/simulator.ts b/yarn-project/acir-simulator/src/client/simulator.ts index 80e0a7eeb5b8..856b194d96c7 100644 --- a/yarn-project/acir-simulator/src/client/simulator.ts +++ b/yarn-project/acir-simulator/src/client/simulator.ts @@ -1,4 +1,4 @@ -import { CallContext, CircuitsWasm, FunctionData, TxContext } from '@aztec/circuits.js'; +import { CallContext, CircuitsWasm, FunctionData, MAX_NOTE_FIELDS_LENGTH, TxContext } from '@aztec/circuits.js'; import { computeTxHash } from '@aztec/circuits.js/abis'; import { Grumpkin } from '@aztec/circuits.js/barretenberg'; import { ArrayType, FunctionSelector, FunctionType, encodeArguments } from '@aztec/foundation/abi'; @@ -14,7 +14,6 @@ import { PackedArgsCache } from '../packed_args_cache.js'; import { ClientTxExecutionContext } from './client_execution_context.js'; import { DBOracle, FunctionAbiWithDebugMetadata } from './db_oracle.js'; import { ExecutionResult } from './execution_result.js'; -import { computeNoteHashAndNullifierSelector, computeNoteHashAndNullifierSignature } from './function_selectors.js'; import { PrivateFunctionExecution } from './private_execution.js'; import { UnconstrainedFunctionExecution } from './unconstrained_execution.js'; @@ -171,12 +170,12 @@ export class AcirSimulator { let abi: FunctionAbiWithDebugMetadata | undefined = undefined; // Brute force - for (let i = 1; i < 5; i++) { + for (let i = 0; i < MAX_NOTE_FIELDS_LENGTH; i++) { const signature = `compute_note_hash_and_nullifier(Field,Field,Field,[Field;${i}])`; const selector = FunctionSelector.fromSignature(signature); try { abi = await this.db.getFunctionABI(contractAddress, selector); - break; + if (abi !== undefined) break; } catch (e) { // ignore } 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 41d789b8a912..27a303e5d9fc 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 @@ -1,6 +1,6 @@ import { AztecNodeService } from '@aztec/aztec-node'; import { AztecRPCServer } from '@aztec/aztec-rpc'; -import { AztecAddress, CheatCodes, Fr, Wallet, computeMessageSecretHash, sleep } from '@aztec/aztec.js'; +import { AztecAddress, CheatCodes, Fr, Wallet, computeMessageSecretHash } from '@aztec/aztec.js'; import { CircuitsWasm, CompleteAddress } from '@aztec/circuits.js'; import { pedersenPlookupCommitInputs } from '@aztec/circuits.js/barretenberg'; import { DebugLogger } from '@aztec/foundation/log'; @@ -88,7 +88,6 @@ describe('e2e_lending_contract', () => { stableCoin: NativeTokenContract, account: Account, ) => { - await sleep(5000); logger('Fetching storage snapshot 📸 '); const accountKey = await account.key(); @@ -294,7 +293,6 @@ describe('e2e_lending_contract', () => { const receipt3 = await tx3.wait(); expect(receipt3.status).toBe(TxStatus.MINED); - // At this point we should have some values!???? const tx4 = stableCoin.methods.redeemShield(shieldAmount, secret, recipient).send({ origin: recipient }); const receipt4 = await tx4.wait(); expect(receipt4.status).toBe(TxStatus.MINED); @@ -413,7 +411,6 @@ describe('e2e_lending_contract', () => { // - increase the private debt. logger('Borrow 🥸 : 🏦 -> 🍌'); - logger(`Addresses: ${stableCoin.address}, ${lendingContract.address}, ${collateralAsset.address}, ${recipient}`); const tx = lendingContract.methods .borrow_private(account.secret, account.address, borrowAmount) .send({ origin: recipient }); diff --git a/yarn-project/foundation/src/abi/decoder.ts b/yarn-project/foundation/src/abi/decoder.ts index 4153be9f94c3..5ca889f9d63b 100644 --- a/yarn-project/foundation/src/abi/decoder.ts +++ b/yarn-project/foundation/src/abi/decoder.ts @@ -123,7 +123,16 @@ export class FunctionSignatureDecoder { * @returns The function signature. */ public decode(): string { - const hmm = this.parameters.map(param => this.decodeParameter(param.type)); - return `${this.name}(${hmm.join(',')})`; + return `${this.name}(${this.parameters.map(param => this.decodeParameter(param.type)).join(',')})`; } } + +/** + * Decodes a function signature from the name and parameters. + * @param name - The name of the function- + * @param parameters - The parameters of the function. + * @returns - The function signature. + */ +export function decodeFunctionSignature(name: string, parameters: ABIParameter[]) { + return new FunctionSignatureDecoder(name, parameters).decode(); +} diff --git a/yarn-project/foundation/src/abi/function_selector.ts b/yarn-project/foundation/src/abi/function_selector.ts index 75d14872f7d8..da10c7d0d28d 100644 --- a/yarn-project/foundation/src/abi/function_selector.ts +++ b/yarn-project/foundation/src/abi/function_selector.ts @@ -1,9 +1,11 @@ -import { ABIParameter, FunctionSignatureDecoder } from '@aztec/foundation/abi'; +import { ABIParameter, decodeFunctionSignature } from '@aztec/foundation/abi'; import { toBigIntBE, toBufferBE } from '@aztec/foundation/bigint-buffer'; import { keccak } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import { BufferReader } from '@aztec/foundation/serialize'; +import { createDebugLogger } from '../log/logger.js'; + /** * A function selector is the first 4 bytes of the hash of a function signature. */ @@ -12,6 +14,7 @@ export class FunctionSelector { * The size of the function selector in bytes. */ public static SIZE = 4; + protected logger = createDebugLogger('aztec:foundation:function-selector'); constructor(/** number representing the function selector */ public value: number) { if (value > 2 ** (FunctionSelector.SIZE * 8) - 1) { @@ -97,10 +100,9 @@ export class FunctionSelector { * @returns A Buffer containing the 4-byte function selector. */ static fromNameAndParameters(name: string, parameters: ABIParameter[]) { - const signature = new FunctionSignatureDecoder(name, parameters).decode(); + const signature = decodeFunctionSignature(name, parameters); const selector = FunctionSelector.fromSignature(signature); - // If you are debugging, can be useful to uncomment the following line. - // console.log(`Function selector for ${signature} is ${selector}`); + selector.logger(`Function selector for ${signature} is ${selector}`); return selector; } diff --git a/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.ts b/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.ts index f96c432c05e3..eb135466b0bb 100644 --- a/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.ts +++ b/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.ts @@ -1,5 +1,5 @@ import { SerialQueue } from '@aztec/foundation/fifo'; -import { createDebugLogger } from '@aztec/foundation/log'; +import { DebugLogger, createDebugLogger } from '@aztec/foundation/log'; import { L2Block, L2BlockDownloader, L2BlockSource } from '@aztec/types'; import { MerkleTreeOperations, MerkleTrees } from '../index.js'; @@ -28,7 +28,7 @@ export class ServerWorldStateSynchroniser implements WorldStateSynchroniser { private merkleTreeDb: MerkleTrees, private l2BlockSource: L2BlockSource, config: WorldStateConfig, - private log = createDebugLogger('aztec:world_state'), + private log: DebugLogger = createDebugLogger('aztec:world_state'), ) { this.l2BlockDownloader = new L2BlockDownloader( l2BlockSource,