Skip to content

Commit

Permalink
fix: Set side effect counter on contract reads (#1870)
Browse files Browse the repository at this point in the history
The side effect counter was not being collected in
`ContractStorageRead`s due to an error in the `from` static method. This
PR fixes it and reenables a test on public execution.

Fixes #1588
  • Loading branch information
spalladino authored Aug 30, 2023
1 parent a065fd5 commit 1d8881e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
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

0 comments on commit 1d8881e

Please sign in to comment.