Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion circuits/cpp/barretenberg
Submodule barretenberg updated 193 files
5 changes: 4 additions & 1 deletion yarn-project/archiver/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import { createPublicClient, http } from 'viem';
import { localhost } from 'viem/chains';
import { Archiver, getConfigEnvVars } from './archiver/index.js';
import { MemoryArchiverStore } from './archiver/archiver_store.js';
import { createLogger } from '@aztec/foundation/log';

export * from './archiver/index.js';

const log = createLogger('aztec:archiver_init');

/**
* A function which instantiates and starts Archiver.
*/
Expand Down Expand Up @@ -35,7 +38,7 @@ async function main() {
if (process.argv[1] === fileURLToPath(import.meta.url).replace(/\/index\.js$/, '')) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
main().catch(err => {
console.log(err);
log(err);
process.exit(1);
});
}
6 changes: 4 additions & 2 deletions yarn-project/aztec-cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env node
import { createLogger } from '@aztec/foundation/log';
import { Command } from 'commander';

const program = new Command();
const log = createLogger('aztec:aztec-cli');

/**
* A placeholder for the Aztec-cli.
Expand All @@ -11,13 +13,13 @@ async function main() {
.command('run')
.argument('<cmd>', 'command')
.action((cmd: string) => {
console.log(`Running '${cmd}'...`);
log(`Running '${cmd}'...`);
});

await program.parseAsync(process.argv);
}

main().catch(err => {
console.log(`Error thrown: ${err}`);
log(`Error thrown: ${err}`);
process.exit(1);
});
2 changes: 1 addition & 1 deletion yarn-project/aztec-rpc/src/synchroniser/synchroniser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class Synchroniser {
from += unverifiedData.length;
return from;
} catch (err) {
console.log(err);
this.log(err);
await this.interruptableSleep.sleep(retryInterval);
return from;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ describe('pedersen', () => {
});

it('hasher_consistency_and_benchmark', () => {
const start1 = new Date().getTime();
// const start1 = new Date().getTime();
const result = pedersenGetHashTree(barretenbergWasm, values);
const end1 = new Date().getTime() - start1;
// const end1 = new Date().getTime() - start1;

console.log(`Single hasher: ~${end1 / values.length}ms / value`);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left comments

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, I think here it's ok to leave the console.log statements commented out because it's just for when people run it locally + the whole test is a messy WIP.

// console.log(`Single hasher: ~${end1 / values.length}ms / value`);
// TODO more than smoke-test this
expect(result.length).toBe(values.length * 2 - 1);
// TODO
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/kernel/public_kernel.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fr, simulatePublicKernelCircuit, simulatePublicKernelCircuitNoPreviousKernel } from '../index.js';
import { simulatePublicKernelCircuit, simulatePublicKernelCircuitNoPreviousKernel } from '../index.js';
import { makePublicKernelInputsNoKernelInput, makePublicKernelInputsWithEmptyOutput } from '../tests/factories.js';

describe('kernel/public_kernel', () => {
Expand Down
6 changes: 6 additions & 0 deletions yarn-project/circuits.js/src/structs/call_stack_item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { PublicCircuitPublicInputs } from './public_circuit_public_inputs.js';
* @see cpp/src/aztec3/circuits/abis/call_stack_item.hpp.
*/
export class PrivateCallStackItem {
/**
* Whether the current callstack item should be considered a public fn execution request.
*/
public readonly isExecutionRequest = false;

constructor(
Expand Down Expand Up @@ -61,6 +64,9 @@ export class PublicCallStackItem {
* Public inputs to the public kernel circuit.
*/
public publicInputs: PublicCircuitPublicInputs,
/**
* Whether the current callstack item should be considered a public fn execution request.
*/
public isExecutionRequest: boolean,
) {}

Expand Down
12 changes: 12 additions & 0 deletions yarn-project/circuits.js/src/structs/public_call_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,21 @@ import {
*/
export class PublicCallRequest {
constructor(
/**
*Address of the contract on which the function is invoked.
*/
public contractAddress: AztecAddress,
/**
* Data identifying the function being called.
*/
public functionData: FunctionData,
/**
* Context of the public call.
*/
public callContext: CallContext,
/**
* Function arguments.
*/
public args: Fr[],
) {}

Expand Down
28 changes: 14 additions & 14 deletions yarn-project/foundation/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ module.exports = {
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/no-floating-promises': 2,
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'require-await': 2,
'no-console': 'error',
'no-constant-condition': 'off',
camelcase: 2,
'no-restricted-imports': [
'warn',
'error',
{
patterns: [
{
Expand All @@ -86,27 +87,26 @@ module.exports = {
],
},
],
'tsdoc/syntax': 'warn',
'tsdoc/syntax': 'error',
'jsdoc/require-jsdoc': [
'warn',
'error',
{
contexts,
checkConstructors: false,
checkGetters: true,
checkSetters: true,
},
],
'jsdoc/require-description': ['warn', { contexts }],
'jsdoc/require-description-complete-sentence': ['warn'],
'jsdoc/require-hyphen-before-param-description': ['warn'],
'jsdoc/require-description': ['error', { contexts }],
'jsdoc/require-hyphen-before-param-description': ['error'],
'jsdoc/require-param': ['error', { contexts, checkDestructured: false }],
'jsdoc/require-param-description': ['warn', { contexts }],
'jsdoc/require-param-name': ['warn', { contexts }],
'jsdoc/require-property': ['warn', { contexts }],
'jsdoc/require-property-description': ['warn', { contexts }],
'jsdoc/require-property-name': ['warn', { contexts }],
'jsdoc/require-returns': ['warn', { contexts }],
'jsdoc/require-returns-description': ['warn', { contexts }],
'jsdoc/require-param-description': ['error', { contexts }],
'jsdoc/require-param-name': ['error', { contexts }],
'jsdoc/require-property': ['error', { contexts }],
'jsdoc/require-property-description': ['error', { contexts }],
'jsdoc/require-property-name': ['error', { contexts }],
'jsdoc/require-returns': ['error', { contexts }],
'jsdoc/require-returns-description': ['error', { contexts }],
},
ignorePatterns: ['node_modules', 'dest*', 'dist', '*.js', '.eslintrc.cjs'],
};
11 changes: 10 additions & 1 deletion yarn-project/foundation/src/abi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export interface ABIVariable {
type: ABIType;
}

/**
* Indicates whether a parameter is public or secret/private.
*/
export enum ABIParameterVisibility {
PUBLIC = 'public',
SECRET = 'secret',
Expand All @@ -21,6 +24,9 @@ export enum ABIParameterVisibility {
* A function parameter.
*/
export interface ABIParameter extends ABIVariable {
/**
* Indicates whether a parameter is public or secret/private.
*/
visibility: ABIParameterVisibility;
}

Expand Down Expand Up @@ -88,7 +94,7 @@ export interface StructType extends BasicType<'struct'> {
}

/**
* Noir function types
* Noir function types.
*/
export enum FunctionType {
SECRET = 'secret',
Expand Down Expand Up @@ -126,6 +132,9 @@ export interface FunctionAbi {
verificationKey?: string;
}

/**
* Defines ABI of a contract.
*/
export interface ContractAbi {
/**
* The name of the contract.
Expand Down
5 changes: 3 additions & 2 deletions yarn-project/foundation/src/fifo/bounded_serial_queue.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createLogger } from '../log/console.js';
import { Semaphore } from './semaphore.js';
import { SerialQueue } from './serial_queue.js';

Expand All @@ -9,7 +10,7 @@ export class BoundedSerialQueue {
private readonly queue = new SerialQueue();
private semaphore: Semaphore;

constructor(maxQueueSize: number) {
constructor(maxQueueSize: number, private log = createLogger('aztec:foundation:bounded_serial_queue')) {
this.semaphore = new Semaphore(maxQueueSize);
}

Expand Down Expand Up @@ -70,7 +71,7 @@ export class BoundedSerialQueue {
}
})
.catch(err => {
console.error('BoundedSerialQueue handler exception:', err);
this.log('BoundedSerialQueue handler exception:', err);
});
}

Expand Down
6 changes: 5 additions & 1 deletion yarn-project/foundation/src/fifo/memory_fifo.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createLogger } from '../log/console.js';

/**
* A simple fifo queue. It can grow unbounded. It can have multiple producers and consumers.
* Putting an item onto the queue always succeeds, unless either end() or cancel() has been called in which case
Expand All @@ -8,6 +10,8 @@ export class MemoryFifo<T> {
private items: T[] = [];
private flushing = false;

constructor(private log = createLogger('aztec:foundation:memory_fifo')) {}

/**
* Returns the current number of items in the queue.
* The length represents the size of the queue at the time of invocation and may change as new items are added or consumed.
Expand Down Expand Up @@ -104,7 +108,7 @@ export class MemoryFifo<T> {
await handler(item);
}
} catch (err) {
console.error('Queue handler exception:', err);
this.log('Queue handler exception:', err);
}
}
}
15 changes: 8 additions & 7 deletions yarn-project/foundation/src/json-rpc/server/json_rpc_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import { ClassConverterInput } from '../class_converter.js';
import Koa from 'koa';
import bodyParser from 'koa-bodyparser';
import { JsonProxy } from './json_proxy.js';
import { createDebugLogger } from '../../log/index.js';

const debug = createDebugLogger('json-rpc:json_rpc_server');
import { createLogger } from '../../log/index.js';

/**
* JsonRpcServer.
* Minimal, dev-friendly mechanism to create a server from an object.
*/
export class JsonRpcServer {
proxy: JsonProxy;
constructor(private handler: object, input: ClassConverterInput) {
constructor(
private handler: object,
input: ClassConverterInput,
private log = createLogger('aztec:foundation:json-rpc:server'),
) {
this.proxy = new JsonProxy(handler, input);
}

Expand All @@ -31,14 +33,14 @@ export class JsonRpcServer {
try {
await next();
} catch (err: any) {
console.log(err);
this.log(err);
ctx.status = 400;
ctx.body = { error: err.message };
}
};
const app = new Koa();
app.on('error', error => {
console.log(`KOA app-level error. ${JSON.stringify({ error })}`);
this.log(`KOA app-level error. ${JSON.stringify({ error })}`);
});
app.use(compress({ br: false } as any));
app.use(bodyParser());
Expand Down Expand Up @@ -66,7 +68,6 @@ export class JsonRpcServer {
}
router.post(`/${method}`, async (ctx: Koa.Context) => {
const { params = [], jsonrpc, id } = ctx.request.body as any;
debug('JsonRpcServer:getRouter', method, '<-', params);
const result = await this.proxy.call(method, params);
ctx.body = { jsonrpc, id, result };
ctx.status = 200;
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/foundation/src/log/console.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-console */

/**
* Logger is a utility type that represents a logging function that accepts any number of arguments.
* It is used to provide customizable logging functionality, allowing developers to easily log messages
Expand Down
13 changes: 10 additions & 3 deletions yarn-project/foundation/src/retry/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createLogger } from '../log/index.js';
import { sleep } from '../sleep/index.js';
import { Timer } from '../timer/index.js';

Expand All @@ -24,9 +25,15 @@ export function* backoffGenerator() {
* @param fn - The asynchronous function to be retried.
* @param name - The optional name of the operation, used for logging purposes.
* @param backoff - The optional backoff generator providing the intervals in seconds between retries. Defaults to a predefined series.
* @param log - Logger to use for logging.
* @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
*/
export async function retry<Result>(fn: () => Promise<Result>, name = 'Operation', backoff = backoffGenerator()) {
export async function retry<Result>(
fn: () => Promise<Result>,
name = 'Operation',
backoff = backoffGenerator(),
log = createLogger('aztec:foundation:retry'),
) {
while (true) {
try {
return await fn();
Expand All @@ -35,8 +42,8 @@ export async function retry<Result>(fn: () => Promise<Result>, name = 'Operation
if (s === undefined) {
throw err;
}
console.log(`${name} failed. Will retry in ${s}s...`);
console.log(err);
log(`${name} failed. Will retry in ${s}s...`);
log(err);
await sleep(s * 1000);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createDebugLogger } from '../../log/debug.js';

/**
* Represents a message object for dispatching function calls.
* Contains the function name ('fn') and an array of arguments ('args') required to call the target method.
Expand All @@ -17,13 +19,12 @@ export interface DispatchMsg {
* Creates a dispatch function that calls the target's specified method with provided arguments.
* The created dispatch function takes a DispatchMsg object as input, which contains the name of
* the method to be called ('fn') and an array of arguments to be passed to the method ('args').
* An optional 'debug' parameter can be passed, which defaults to console.error, to log dispatched messages.
*
* @param targetFn - A function that returns the target object containing the methods to be dispatched.
* @param debug - Optional logging function for debugging purposes (defaults to console.error).
* @param debug - Optional logging function for debugging purposes.
* @returns A dispatch function that accepts a DispatchMsg object and calls the target's method with provided arguments.
*/
export function createDispatchFn(targetFn: () => any, debug = console.error) {
export function createDispatchFn(targetFn: () => any, debug = createDebugLogger('aztec:foundation:dispatch')) {
return async ({ fn, args }: DispatchMsg) => {
const target = targetFn();
debug(`dispatching to ${target}: ${fn}`, args);
Expand Down
Loading