Skip to content

Commit 3657efd

Browse files
author
dbanks12
committed
chore: remove transitional adapter file from old public circuit public inputs
1 parent bd6ae99 commit 3657efd

File tree

2 files changed

+72
-123
lines changed

2 files changed

+72
-123
lines changed

yarn-project/simulator/src/public/public_tx_context.ts

+72-10
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,32 @@ import {
1818
type GasSettings,
1919
type GlobalVariables,
2020
MAX_L2_GAS_PER_TX_PUBLIC_PORTION,
21+
MAX_L2_TO_L1_MSGS_PER_TX,
2122
MAX_NOTE_HASHES_PER_TX,
2223
MAX_NULLIFIERS_PER_TX,
24+
MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
25+
PrivateToAvmAccumulatedData,
26+
PrivateToAvmAccumulatedDataArrayLengths,
2327
type PrivateToPublicAccumulatedData,
24-
type PublicCallRequest,
28+
PublicCallRequest,
29+
PublicDataWrite,
2530
RevertCode,
2631
type StateReference,
2732
TreeSnapshots,
2833
computeTransactionFee,
2934
countAccumulatedItems,
35+
mergeAccumulatedData,
3036
} from '@aztec/circuits.js';
37+
import { padArrayEnd } from '@aztec/foundation/collection';
3138
import { type Logger, createLogger } from '@aztec/foundation/log';
39+
import { assertLength } from '@aztec/foundation/serialize';
3240

3341
import { strict as assert } from 'assert';
3442
import { inspect } from 'util';
3543

3644
import { AvmPersistableStateManager } from '../avm/index.js';
3745
import { type WorldStateDB } from './public_db_sources.js';
3846
import { SideEffectArrayLengths, SideEffectTrace } from './side_effect_trace.js';
39-
import { generateAvmCircuitPublicInputs } from './transitional_adapters.js';
4047
import { getCallRequestsByPhase, getExecutionRequestsByPhase } from './utils.js';
4148

4249
/**
@@ -350,23 +357,78 @@ export class PublicTxContext {
350357
publicDataTree,
351358
);
352359

353-
return generateAvmCircuitPublicInputs(
354-
this.trace,
360+
const startTreeSnapshots = new TreeSnapshots(
361+
this.startStateReference.l1ToL2MessageTree,
362+
this.startStateReference.partial.noteHashTree,
363+
this.startStateReference.partial.nullifierTree,
364+
this.startStateReference.partial.publicDataTree,
365+
);
366+
367+
const avmCircuitPublicInputs = this.trace.toAvmCircuitPublicInputs(
355368
this.globalVariables,
356-
this.startStateReference,
369+
startTreeSnapshots,
357370
/*startGasUsed=*/ this.gasUsedByPrivate,
358371
this.gasSettings,
359372
this.feePayer,
360373
this.setupCallRequests,
361374
this.appLogicCallRequests,
362-
this.teardownCallRequests,
363-
this.nonRevertibleAccumulatedDataFromPrivate,
364-
this.revertibleAccumulatedDataFromPrivate,
375+
/*teardownCallRequest=*/ this.teardownCallRequests.length
376+
? this.teardownCallRequests[0]
377+
: PublicCallRequest.empty(),
365378
endTreeSnapshots,
366379
/*endGasUsed=*/ this.getTotalGasUsed(),
367-
this.getTransactionFeeUnsafe(),
368-
this.revertCode,
380+
/*transactionFee=*/ this.getTransactionFeeUnsafe(),
381+
/*reverted=*/ !this.revertCode.isOK(),
369382
);
383+
384+
const getArrayLengths = (from: PrivateToPublicAccumulatedData) =>
385+
new PrivateToAvmAccumulatedDataArrayLengths(
386+
countAccumulatedItems(from.noteHashes),
387+
countAccumulatedItems(from.nullifiers),
388+
countAccumulatedItems(from.l2ToL1Msgs),
389+
);
390+
const convertAccumulatedData = (from: PrivateToPublicAccumulatedData) =>
391+
new PrivateToAvmAccumulatedData(from.noteHashes, from.nullifiers, from.l2ToL1Msgs);
392+
// Temporary overrides as these entries aren't yet populated in trace
393+
avmCircuitPublicInputs.previousNonRevertibleAccumulatedDataArrayLengths = getArrayLengths(
394+
this.nonRevertibleAccumulatedDataFromPrivate,
395+
);
396+
avmCircuitPublicInputs.previousRevertibleAccumulatedDataArrayLengths = getArrayLengths(
397+
this.revertibleAccumulatedDataFromPrivate,
398+
);
399+
avmCircuitPublicInputs.previousNonRevertibleAccumulatedData = convertAccumulatedData(
400+
this.nonRevertibleAccumulatedDataFromPrivate,
401+
);
402+
avmCircuitPublicInputs.previousRevertibleAccumulatedData = convertAccumulatedData(
403+
this.revertibleAccumulatedDataFromPrivate,
404+
);
405+
406+
const msgsFromPrivate = this.revertCode.isOK()
407+
? mergeAccumulatedData(
408+
avmCircuitPublicInputs.previousNonRevertibleAccumulatedData.l2ToL1Msgs,
409+
avmCircuitPublicInputs.previousRevertibleAccumulatedData.l2ToL1Msgs,
410+
)
411+
: avmCircuitPublicInputs.previousNonRevertibleAccumulatedData.l2ToL1Msgs;
412+
avmCircuitPublicInputs.accumulatedData.l2ToL1Msgs = assertLength(
413+
mergeAccumulatedData(msgsFromPrivate, avmCircuitPublicInputs.accumulatedData.l2ToL1Msgs),
414+
MAX_L2_TO_L1_MSGS_PER_TX,
415+
);
416+
417+
// Maps slot to value. Maps in TS are iterable in insertion order, which is exactly what we want for
418+
// squashing "to the left", where the first occurrence of a slot uses the value of the last write to it,
419+
// and the rest occurrences are omitted
420+
const squashedPublicDataWrites: Map<bigint, Fr> = new Map();
421+
for (const publicDataWrite of avmCircuitPublicInputs.accumulatedData.publicDataWrites) {
422+
squashedPublicDataWrites.set(publicDataWrite.leafSlot.toBigInt(), publicDataWrite.value);
423+
}
424+
425+
avmCircuitPublicInputs.accumulatedData.publicDataWrites = padArrayEnd(
426+
Array.from(squashedPublicDataWrites.entries()).map(([slot, value]) => new PublicDataWrite(new Fr(slot), value)),
427+
PublicDataWrite.empty(),
428+
MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
429+
);
430+
431+
return avmCircuitPublicInputs;
370432
}
371433

372434
/**

yarn-project/simulator/src/public/transitional_adapters.ts

-113
This file was deleted.

0 commit comments

Comments
 (0)