Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanks12 committed Dec 10, 2024
1 parent 7db5441 commit 65e8c47
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion yarn-project/ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@
"engines": {
"node": ">=18"
}
}
}
2 changes: 1 addition & 1 deletion yarn-project/foundation/src/abi/event_selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class EventSelector extends Selector {
static fromString(selector: string) {
const buf = fromHex(selector);
if (buf.length !== Selector.SIZE) {
throw new Error(`Invalid Selector length ${buf.length} (expected ${Selector.SIZE}).`);
throw new Error(`Invalid EventSelector length ${buf.length} (expected ${Selector.SIZE}).`);
}
return EventSelector.fromBuffer(buf);
}
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/foundation/src/abi/function_selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class FunctionSelector extends Selector {
static fromString(selector: string) {
const buf = fromHex(selector);
if (buf.length !== Selector.SIZE) {
throw new Error(`Invalid Selector length ${buf.length} (expected ${Selector.SIZE}).`);
throw new Error(`Invalid FunctionSelector length ${buf.length} (expected ${Selector.SIZE}).`);
}
return FunctionSelector.fromBuffer(buf);
}
Expand Down
28 changes: 22 additions & 6 deletions yarn-project/pxe/src/pxe_service/error_enriching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,36 @@ export async function enrichSimulationError(err: SimulationError, db: PxeDatabas
// representation to get e.g. different contract address objects with the same address value to match.
const mentionedFunctions: Map<string, Set<string>> = new Map();

err.getCallStack().forEach(({ contractAddress, functionSelector }) => {
err.getCallStack().forEach(({ contractAddress, functionName }) => {
if (!mentionedFunctions.has(contractAddress.toString())) {
mentionedFunctions.set(contractAddress.toString(), new Set());
}
mentionedFunctions.get(contractAddress.toString())!.add(functionSelector?.toString() ?? '');
console.log(`Contract address: ${contractAddress.toString()}`);
console.log(`functionName: ${functionName}`);
//console.log(`functionSelector: ${functionSelector}`);
//console.log(`functionSelector? ?? '': ${functionSelector?.toString() ?? ''}`);
//mentionedFunctions.get(contractAddress.toString())!.add(functionSelector?.toString() ?? '');
mentionedFunctions.get(contractAddress.toString())!.add(functionName?.toString() ?? '');
});

await Promise.all(
[...mentionedFunctions.entries()].map(async ([contractAddress, selectors]) => {
[...mentionedFunctions.entries()].map(async ([contractAddress, fnNames]) => {
const parsedContractAddress = AztecAddress.fromString(contractAddress);
const contract = await db.getContract(parsedContractAddress);
if (contract) {
err.enrichWithContractName(parsedContractAddress, contract.name);
selectors.forEach(selector => {
const functionArtifact = contract.functions.find(f => FunctionSelector.fromString(selector).equals(f));
console.log(`Selectors: ${JSON.stringify(fnNames)}`);
fnNames.forEach(fnName => {
//console.log(`Finding selector: ${fnName}`);
console.log(`Finding fnName: ${fnName}`);
//for (const f of contract.functions) {
// console.log(`f.name: ${f.name}`);
// console.log(`f: ${f}`);
//}
//const functionArtifact = contract.functions.find(f => FunctionSelector.fromString(fnName).equals(f));
const functionArtifact = contract.functions.find(f => fnName === f.name);
console.log(`functionArtifact.name: ${functionArtifact?.name}`);

if (functionArtifact) {
err.enrichWithFunctionName(
parsedContractAddress,
Expand All @@ -39,7 +54,7 @@ export async function enrichSimulationError(err: SimulationError, db: PxeDatabas
);
} else {
logger.warn(
`Could not function artifact in contract ${contract.name} for selector ${selector} when enriching error callstack`,
`Could not function artifact in contract ${contract.name} for selector ${fnName} when enriching error callstack`,
);
}
});
Expand All @@ -50,6 +65,7 @@ export async function enrichSimulationError(err: SimulationError, db: PxeDatabas
}
}),
);
console.log(`after promises`);
}

export async function enrichPublicSimulationError(
Expand Down
1 change: 1 addition & 0 deletions yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ export class PXEService implements PXE {
this.log.error(`Failed to enrich public simulation error: ${enrichErr}`);
}
}
console.log(`after enrich`);
throw err;
}
}
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/simulator/src/common/debug_fn_name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export async function getPublicFunctionDebugName(
calldata[0] !== undefined
? await db.getDebugFunctionName(contractAddress, FunctionSelector.fromField(calldata[0]))
: `<calldata[0] undefined> (Contract Address: ${contractAddress})`;
return `${targetFunction} (via dispatch)`;
return `${targetFunction}`;
}

0 comments on commit 65e8c47

Please sign in to comment.