Skip to content

Commit

Permalink
chore: refactor AVM simulator's side-effect tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanks12 committed Jun 21, 2024
1 parent dec622f commit fcc5bf6
Show file tree
Hide file tree
Showing 24 changed files with 1,234 additions and 1,383 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,19 +363,19 @@ contract AvmTest {
// Use the standard context interface to check for a nullifier
#[aztec(public)]
fn nullifier_exists(nullifier: Field) -> bool {
context.nullifier_exists(nullifier, context.this_address())
context.nullifier_exists(nullifier, context.storage_address())
}

#[aztec(public)]
fn assert_nullifier_exists(nullifier: Field) {
assert(context.nullifier_exists(nullifier, context.this_address()), "Nullifier doesn't exist!");
assert(context.nullifier_exists(nullifier, context.storage_address()), "Nullifier doesn't exist!");
}

// Use the standard context interface to emit a new nullifier
#[aztec(public)]
fn emit_nullifier_and_check(nullifier: Field) {
context.push_new_nullifier(nullifier, 0);
let exists = context.nullifier_exists(nullifier, context.this_address());
let exists = context.nullifier_exists(nullifier, context.storage_address());
assert(exists, "Nullifier was just created, but its existence wasn't detected!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ export class ContractStorageUpdateRequest {
/**
* Optional side effect counter tracking position of this event in tx execution.
*/
public readonly sideEffectCounter: number,
public readonly counter: number,
/**
* Contract address whose storage is being read.
*/
public contractAddress?: AztecAddress, // TODO: Should not be optional. This is a temporary hack to silo the storage slot with the correct address for nested executions.
) {}

toBuffer() {
return serializeToBuffer(this.storageSlot, this.newValue, this.sideEffectCounter);
return serializeToBuffer(this.storageSlot, this.newValue, this.counter);
}

static fromBuffer(buffer: Buffer | BufferReader) {
Expand All @@ -52,7 +55,7 @@ export class ContractStorageUpdateRequest {
* @returns The array.
*/
static getFields(fields: FieldsOf<ContractStorageUpdateRequest>) {
return [fields.storageSlot, fields.newValue, fields.sideEffectCounter, fields.contractAddress] as const;
return [fields.storageSlot, fields.newValue, fields.counter, fields.contractAddress] as const;
}

static empty() {
Expand All @@ -65,12 +68,12 @@ export class ContractStorageUpdateRequest {

toFriendlyJSON() {
return `Slot=${this.storageSlot.toFriendlyJSON()}: ${this.newValue.toFriendlyJSON()}, sideEffectCounter=${
this.sideEffectCounter
this.counter
}`;
}

toFields(): Fr[] {
const fields = [this.storageSlot, this.newValue, new Fr(this.sideEffectCounter)];
const fields = [this.storageSlot, this.newValue, new Fr(this.counter)];
if (fields.length !== CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH) {
throw new Error(
`Invalid number of fields for ContractStorageUpdateRequest. Expected ${CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH}, got ${fields.length}`,
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/end-to-end/src/e2e_block_building.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import { StatefulTestContractArtifact } from '@aztec/noir-contracts.js';
import { TestContract } from '@aztec/noir-contracts.js/Test';
import { TokenContract } from '@aztec/noir-contracts.js/Token';

import 'jest-extended';

import { TaggedLog } from '../../circuit-types/src/logs/l1_payload/tagged_log.js';
import { DUPLICATE_NULLIFIER_ERROR } from './fixtures/fixtures.js';
import { setup } from './fixtures/utils.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class AvmExecutionEnvironment {
/*sender=*/ this.address,
this.feePerL2Gas,
this.feePerDaGas,
this.contractCallDepth,
this.contractCallDepth.add(Fr.ONE),
this.header,
this.globals,
isStaticCall,
Expand Down
Loading

0 comments on commit fcc5bf6

Please sign in to comment.