Skip to content

Commit

Permalink
enable merkles
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanks12 committed Dec 7, 2024
1 parent a516e3a commit 6a739a6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
40 changes: 27 additions & 13 deletions yarn-project/simulator/src/avm/journal/journal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class AvmPersistableStateManager {
const leafSlot = computePublicDataTreeLeafSlot(contractAddress, slot);
if (this.doMerkleOperations) {
const result = await this.merkleTrees.writePublicStorage(leafSlot, value);
assert(result !== undefined, 'Public data tree insertion error. You might want to disable skipMerkleOperations.');
assert(result !== undefined, 'Public data tree insertion error. You might want to disable doMerkleOperations.');
this.log.debug(`Inserted public data tree leaf at leafSlot ${leafSlot}, value: ${value}`);

const lowLeafInfo = result.lowWitness;
Expand Down Expand Up @@ -525,15 +525,22 @@ export class AvmPersistableStateManager {
public async getContractInstance(contractAddress: AztecAddress): Promise<SerializableContractInstance | undefined> {
this.log.debug(`Getting contract instance for address ${contractAddress}`);
const instanceWithAddress = await this.worldStateDB.getContractInstance(contractAddress);
const contractAddressNullifier = siloNullifier(
AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS),
contractAddress.toField(),
);
const exists = instanceWithAddress !== undefined;
const [existsInTree, leafOrLowLeafPreimage, leafOrLowLeafIndex, leafOrLowLeafPath] =
await this.getNullifierMembership(/*siloedNullifier=*/ contractAddressNullifier);

let [existsInTree, leafOrLowLeafPreimage, leafOrLowLeafIndex, leafOrLowLeafPath] = [
exists,
NullifierLeafPreimage.empty(),
Fr.ZERO,
new Array<Fr>(),
];
if (!contractAddressIsCanonical(contractAddress)) {
const contractAddressNullifier = siloNullifier(
AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS),
contractAddress.toField(),
);
[existsInTree, leafOrLowLeafPreimage, leafOrLowLeafIndex, leafOrLowLeafPath] = await this.getNullifierMembership(
/*siloedNullifier=*/ contractAddressNullifier,
);
assert(
exists == existsInTree,
'WorldStateDB contains contract instance, but nullifier tree does not contain contract address (or vice versa).... This is a bug!',
Expand Down Expand Up @@ -584,14 +591,21 @@ export class AvmPersistableStateManager {
this.log.debug(`Getting bytecode for contract address ${contractAddress}`);
const instanceWithAddress = await this.worldStateDB.getContractInstance(contractAddress);
const exists = instanceWithAddress !== undefined;
const contractAddressNullifier = siloNullifier(
AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS),
contractAddress.toField(),
);
const [existsInTree, leafOrLowLeafPreimage, leafOrLowLeafIndex, leafOrLowLeafPath] =
await this.getNullifierMembership(/*siloedNullifier=*/ contractAddressNullifier);

let [existsInTree, leafOrLowLeafPreimage, leafOrLowLeafIndex, leafOrLowLeafPath] = [
exists,
NullifierLeafPreimage.empty(),
Fr.ZERO,
new Array<Fr>(),
];
if (!contractAddressIsCanonical(contractAddress)) {
const contractAddressNullifier = siloNullifier(
AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS),
contractAddress.toField(),
);
[existsInTree, leafOrLowLeafPreimage, leafOrLowLeafIndex, leafOrLowLeafPath] = await this.getNullifierMembership(
/*siloedNullifier=*/ contractAddressNullifier,
);
assert(
exists == existsInTree,
'WorldStateDB contains contract instance, but nullifier tree does not contain contract address (or vice versa).... This is a bug!',
Expand Down
1 change: 0 additions & 1 deletion yarn-project/simulator/src/public/fixtures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export async function simulateAvmTestContractGenerateCircuitInputs(
worldStateDB,
new NoopTelemetryClient(),
globalVariables,
/*realAvmProving=*/ true,
/*doMerkleOperations=*/ true,
);

Expand Down
8 changes: 7 additions & 1 deletion yarn-project/simulator/src/public/public_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ export class PublicProcessorFactory {
const historicalHeader = maybeHistoricalHeader ?? merkleTree.getInitialHeader();

const worldStateDB = new WorldStateDB(merkleTree, this.contractDataSource);
const publicTxSimulator = new PublicTxSimulator(merkleTree, worldStateDB, this.telemetryClient, globalVariables);
const publicTxSimulator = new PublicTxSimulator(
merkleTree,
worldStateDB,
this.telemetryClient,
globalVariables,
/*doMerkleOperations=*/ true,
);

return new PublicProcessor(
merkleTree,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ describe('public_tx_simulator', () => {
worldStateDB,
new NoopTelemetryClient(),
GlobalVariables.from({ ...GlobalVariables.empty(), gasFees }),
/*realAvmProvingRequest=*/ false,
/*doMerkleOperations=*/ true,
);

Expand Down
1 change: 0 additions & 1 deletion yarn-project/simulator/src/public/public_tx_simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export class PublicTxSimulator {
private worldStateDB: WorldStateDB,
telemetryClient: TelemetryClient,
private globalVariables: GlobalVariables,
private realAvmProvingRequests: boolean = true,
private doMerkleOperations: boolean = false,
) {
this.log = createDebugLogger(`aztec:public_tx_simulator`);
Expand Down
1 change: 0 additions & 1 deletion yarn-project/txe/src/oracle/txe_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@ export class TXE implements TypedOracle {
new TXEWorldStateDB(db, new TXEPublicContractDataSource(this)),
new NoopTelemetryClient(),
globalVariables,
/*realAvmProvingRequests=*/ false,
);

// When setting up a teardown call, we tell it that
Expand Down

0 comments on commit 6a739a6

Please sign in to comment.