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: Set side effect counter on contract reads #1870

Merged
merged 1 commit into from
Aug 30, 2023
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
18 changes: 8 additions & 10 deletions yarn-project/acir-simulator/src/public/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
CallContext,
CircuitsWasm,
ContractStorageRead,
FunctionData,
GlobalVariables,
HistoricBlockData,
Expand Down Expand Up @@ -174,23 +175,20 @@ describe('ACIR public execution simulator', () => {
expect(result.contractStorageReads).toEqual([]);
});

// Contract storage reads and update requests are implemented as built-ins, which at the moment Noir does not
// now whether they have side-effects or not, so they get run even when their code path
// is not picked by a conditional. Once that's fixed, we should re-enable this test.
// Task to repair this test: https://github.com/AztecProtocol/aztec-packages/issues/1588
it.skip('should run the transfer function without enough sender balance', async () => {
it('should fail the transfer function without enough sender balance', async () => {
const senderBalance = new Fr(10n);
const recipientBalance = new Fr(20n);
mockStore(senderBalance, recipientBalance);

const result = await executor.execute(execution, GlobalVariables.empty());

expect(result.returnValues[0]).toEqual(recipientBalance);

expect(result.contractStorageReads).toEqual([
{ storageSlot: recipientStorageSlot, value: recipientBalance },
{ storageSlot: senderStorageSlot, value: senderBalance },
]);
expect(result.contractStorageReads).toEqual(
[
{ storageSlot: senderStorageSlot, currentValue: senderBalance, sideEffectCounter: 0 },
{ storageSlot: recipientStorageSlot, currentValue: recipientBalance, sideEffectCounter: 1 },
].map(ContractStorageRead.from),
);

expect(result.contractStorageUpdateRequests).toEqual([]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ export class ContractStorageRead {
* Value read from the storage slot.
*/
currentValue: Fr;
/**
* Optional side effect counter tracking position of this event in tx execution.
*/
sideEffectCounter?: number;
}) {
return new ContractStorageRead(args.storageSlot, args.currentValue);
return new ContractStorageRead(args.storageSlot, args.currentValue, args.sideEffectCounter);
}

toBuffer() {
Expand Down