Skip to content

Commit d45a673

Browse files
nchamoaztec-bot
authored andcommitted
fix(pxe): throw error on origin/contract address mismatch in simulation (#22637)
1 parent 9e878ae commit d45a673

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

yarn-project/pxe/src/contract_function_simulator/contract_function_simulator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export class ContractFunctionSimulator {
208208
}
209209

210210
if (request.origin !== contractAddress) {
211-
this.log.warn(
211+
throw new Error(
212212
`Request origin does not match contract address in simulation. Request origin: ${request.origin}, contract address: ${contractAddress}`,
213213
);
214214
}

yarn-project/pxe/src/contract_function_simulator/oracle/private_execution.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,40 @@ describe('Private Execution test suite', () => {
520520
});
521521
});
522522

523+
it('throws when request origin does not match contract address', async () => {
524+
const contractAddress = await mockContractInstance(TestContractArtifact);
525+
const differentAddress = await AztecAddress.random();
526+
contracts[differentAddress.toString()] = TestContractArtifact;
527+
528+
const functionArtifact = getFunctionArtifactByName(TestContractArtifact, 'emit_array_as_encrypted_log');
529+
const selector = await FunctionSelector.fromNameAndParameters(functionArtifact.name, functionArtifact.parameters);
530+
const hashedArguments = await HashedValues.fromArgs(
531+
encodeArguments(functionArtifact, [Fr.ZERO, times(5, () => Fr.random()), owner, false]),
532+
);
533+
534+
const txRequest = TxExecutionRequest.from({
535+
origin: differentAddress,
536+
firstCallArgsHash: hashedArguments.hash,
537+
functionSelector: selector,
538+
txContext: TxContext.from(txContextFields),
539+
argsOfCalls: [hashedArguments],
540+
authWitnesses: [],
541+
capsules: [],
542+
salt: Fr.random(),
543+
});
544+
545+
await expect(
546+
acirSimulator.run(txRequest, {
547+
contractAddress,
548+
selector,
549+
anchorBlockHeader,
550+
senderForTags,
551+
jobId: TEST_JOB_ID,
552+
scopes: [owner],
553+
}),
554+
).rejects.toThrow('Request origin does not match contract address');
555+
});
556+
523557
describe('stateful test contract', () => {
524558
let contractAddress: AztecAddress;
525559
const mockFirstNullifier = new Fr(1111);

0 commit comments

Comments
 (0)