Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: TXE fixes #9930

Merged
merged 1 commit into from
Nov 13, 2024
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 yarn-project/txe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests",
"dev": "DEBUG='aztec:*' LOG_LEVEL=debug node ./dest/bin/index.js",
"dev": "DEBUG='aztec:*,-aztec:avm_simulator:*' LOG_LEVEL=debug node ./dest/bin/index.js",
"start": "node ./dest/bin/index.js"
},
"inherits": [
Expand Down
106 changes: 54 additions & 52 deletions yarn-project/txe/src/oracle/txe_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
NULLIFIER_SUBTREE_HEIGHT,
type NULLIFIER_TREE_HEIGHT,
type NullifierLeafPreimage,
PRIVATE_CONTEXT_INPUTS_LENGTH,
PUBLIC_DATA_SUBTREE_HEIGHT,
type PUBLIC_DATA_TREE_HEIGHT,
PUBLIC_DISPATCH_SELECTOR,
Expand Down Expand Up @@ -348,16 +349,16 @@ export class TXE implements TypedOracle {
}

async getPublicDataTreeWitness(blockNumber: number, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
const committedDb = new MerkleTreeSnapshotOperationsFacade(this.trees, blockNumber);
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
const db = await this.#getTreesAt(blockNumber);
const lowLeafResult = await db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
if (!lowLeafResult) {
return undefined;
} else {
const preimage = (await committedDb.getLeafPreimage(
const preimage = (await db.getLeafPreimage(
MerkleTreeId.PUBLIC_DATA_TREE,
lowLeafResult.index,
)) as PublicDataTreeLeafPreimage;
const path = await committedDb.getSiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>(
const path = await db.getSiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>(
MerkleTreeId.PUBLIC_DATA_TREE,
lowLeafResult.index,
);
Expand Down Expand Up @@ -563,55 +564,53 @@ export class TXE implements TypedOracle {
const initialWitness = await this.getInitialWitness(artifact, argsHash, sideEffectCounter, isStaticCall);
const acvmCallback = new Oracle(this);
const timer = new Timer();
try {
const acirExecutionResult = await acvm(acir, initialWitness, acvmCallback).catch((err: Error) => {
err.message = resolveAssertionMessageFromError(err, artifact);

const execError = new ExecutionError(
err.message,
{
contractAddress: targetContractAddress,
functionSelector,
},
extractCallStack(err, artifact.debug),
{ cause: err },
);
this.logger.debug(`Error executing private function ${targetContractAddress}:${functionSelector}`);
throw createSimulationError(execError);
});
const duration = timer.ms();
const publicInputs = extractPrivateCircuitPublicInputs(artifact, acirExecutionResult.partialWitness);

const initialWitnessSize = witnessMapToFields(initialWitness).length * Fr.SIZE_IN_BYTES;
this.logger.debug(`Ran external function ${targetContractAddress.toString()}:${functionSelector}`, {
circuitName: 'app-circuit',
duration,
eventName: 'circuit-witness-generation',
inputSize: initialWitnessSize,
outputSize: publicInputs.toBuffer().length,
appCircuitName: 'noname',
} satisfies CircuitWitnessGenerationStats);

// Apply side effects
const endSideEffectCounter = publicInputs.endSideEffectCounter;
this.sideEffectCounter = endSideEffectCounter.toNumber() + 1;

await this.addNullifiers(
targetContractAddress,
publicInputs.nullifiers.filter(nullifier => !nullifier.isEmpty()).map(nullifier => nullifier.value),
const acirExecutionResult = await acvm(acir, initialWitness, acvmCallback).catch((err: Error) => {
err.message = resolveAssertionMessageFromError(err, artifact);

const execError = new ExecutionError(
err.message,
{
contractAddress: targetContractAddress,
functionSelector,
},
extractCallStack(err, artifact.debug),
{ cause: err },
);
this.logger.debug(`Error executing private function ${targetContractAddress}:${functionSelector}`);
throw createSimulationError(execError);
});
const duration = timer.ms();
const publicInputs = extractPrivateCircuitPublicInputs(artifact, acirExecutionResult.partialWitness);

const initialWitnessSize = witnessMapToFields(initialWitness).length * Fr.SIZE_IN_BYTES;
this.logger.debug(`Ran external function ${targetContractAddress.toString()}:${functionSelector}`, {
circuitName: 'app-circuit',
duration,
eventName: 'circuit-witness-generation',
inputSize: initialWitnessSize,
outputSize: publicInputs.toBuffer().length,
appCircuitName: 'noname',
} satisfies CircuitWitnessGenerationStats);

await this.addNoteHashes(
targetContractAddress,
publicInputs.noteHashes.filter(noteHash => !noteHash.isEmpty()).map(noteHash => noteHash.value),
);
// Apply side effects
const endSideEffectCounter = publicInputs.endSideEffectCounter;
this.sideEffectCounter = endSideEffectCounter.toNumber() + 1;

return { endSideEffectCounter, returnsHash: publicInputs.returnsHash };
} finally {
this.setContractAddress(currentContractAddress);
this.setMsgSender(currentMessageSender);
this.setFunctionSelector(currentFunctionSelector);
}
await this.addNullifiers(
targetContractAddress,
publicInputs.nullifiers.filter(nullifier => !nullifier.isEmpty()).map(nullifier => nullifier.value),
);

await this.addNoteHashes(
targetContractAddress,
publicInputs.noteHashes.filter(noteHash => !noteHash.isEmpty()).map(noteHash => noteHash.value),
);

this.setContractAddress(currentContractAddress);
this.setMsgSender(currentMessageSender);
this.setFunctionSelector(currentFunctionSelector);

return { endSideEffectCounter, returnsHash: publicInputs.returnsHash };
}

async getInitialWitness(abi: FunctionAbi, argsHash: Fr, sideEffectCounter: number, isStaticCall: boolean) {
Expand All @@ -628,9 +627,12 @@ export class TXE implements TypedOracle {
sideEffectCounter,
isStaticCall,
);
const privateContextInputsAsFields = privateContextInputs.toFields();
if (privateContextInputsAsFields.length !== PRIVATE_CONTEXT_INPUTS_LENGTH) {
throw new Error('Invalid private context inputs size');
}

const fields = [...privateContextInputs.toFields(), ...args];

const fields = [...privateContextInputsAsFields, ...args];
return toACVMWitness(0, fields);
}

Expand Down
Loading