Skip to content
Closed
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
60 changes: 16 additions & 44 deletions yarn-project/circuit-types/src/simulation_error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,79 +4,51 @@ import { schemas } from '@aztec/foundation/schemas';

import { z } from 'zod';

/**
* Address and selector of a function that failed during simulation.
*/
/** Address and selector of a function that failed during simulation. */
export interface FailingFunction {
/**
* The address of the contract that failed.
*/
/** The address of the contract that failed. */
contractAddress: AztecAddress;
/**
* The name of the contract that failed.
*/
/** The name of the contract that failed. */
contractName?: string;
/**
* The selector of the function that failed.
*/
/** The selector of the function that failed. */
functionSelector?: FunctionSelector;
/**
* The name of the function that failed.
*/
/** The name of the function that failed. */
functionName?: string;
}

/**
* A pointer to a failing section of the noir source code.
*/
/** A pointer to a failing section of the noir source code. */
export interface SourceCodeLocation {
/**
* The path to the source file.
*/
/** The path to the source file. */
filePath: string;
/**
* The line number of the call.
*/
/** The line number of the call. */
line: number;
/**
* The column number of the call.
*/
/** The column number of the call. */
column: number;
/**
* The source code of the file.
*/
fileSource: string;
/**
* The source code text of the failed constraint.
*/
/** The source code of the file. */
fileSource?: string;
/** The source code text of the failed constraint. */
locationText: string;
}

const SourceCodeLocationSchema = z.object({
filePath: z.string(),
line: z.number(),
column: z.number(),
fileSource: z.string(),
fileSource: z.string().optional(),
locationText: z.string(),
});

/**
* A stack of noir source code locations.
*/
/** A stack of noir source code locations. */
export type NoirCallStack = SourceCodeLocation[] | OpcodeLocation[];

const NoirCallStackSchema: z.ZodType<NoirCallStack> = z.union([z.array(SourceCodeLocationSchema), z.array(z.string())]);

/**
* Checks if a call stack is unresolved.
*/
/** Checks if a call stack is unresolved. */
export function isNoirCallStackUnresolved(callStack: NoirCallStack): callStack is OpcodeLocation[] {
return typeof callStack[0] === 'string';
}

/**
* An error during the simulation of a function call.
*/
/** An error during the simulation of a function call. */
export class SimulationError extends Error {
constructor(
private originalMessage: string,
Expand Down
10 changes: 2 additions & 8 deletions yarn-project/simulator/src/common/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function getSourceCodeLocationsFromOpcodeLocation(
return callStack.map(call => {
const { file: fileId, span } = call;

const { path, source } = files[fileId];
const { path: filePath, source } = files[fileId];

const locationText = source.substring(span.start, span.end);
const precedingText = source.substring(0, span.start);
Expand All @@ -119,13 +119,7 @@ function getSourceCodeLocationsFromOpcodeLocation(
const line = previousLines.length;
const column = previousLines[previousLines.length - 1].length + 1;

return {
filePath: path,
line,
column,
fileSource: source,
locationText,
};
return { filePath, line, column, locationText };
});
}

Expand Down