Skip to content
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
4 changes: 3 additions & 1 deletion barretenberg/cpp/src/barretenberg/vm2/common/avm_inputs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ struct AccumulatedData {
// We are currently using this structure as the input to TX simulation.
// That's why I'm not calling it TxHint. We can reconsider if the inner types seem to dirty.
struct Tx {
std::string hash;
AccumulatedData nonRevertibleAccumulatedData;
AccumulatedData revertibleAccumulatedData;
std::vector<EnqueuedCallHint> setupEnqueuedCalls;
Expand All @@ -261,7 +262,8 @@ struct Tx {

bool operator==(const Tx& other) const = default;

MSGPACK_FIELDS(nonRevertibleAccumulatedData,
MSGPACK_FIELDS(hash,
nonRevertibleAccumulatedData,
revertibleAccumulatedData,
setupEnqueuedCalls,
appLogicEnqueuedCalls,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace bb::avm2::simulation {

void TxExecution::simulate(const Tx& tx)
{
info("Simulating tx with ",
info("Simulating tx ",
tx.hash,
" with ",
tx.setupEnqueuedCalls.size(),
" setup enqueued calls, ",
tx.appLogicEnqueuedCalls.size(),
Expand Down
10 changes: 5 additions & 5 deletions yarn-project/bb-prover/src/prover/bb_prover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
* @returns The proof.
*/
@trackSpan('BBNativeRollupProver.getAvmProof', inputs => ({
[Attributes.APP_CIRCUIT_NAME]: inputs.functionName,
[Attributes.APP_CIRCUIT_NAME]: inputs.hints.tx.hash,
}))
public async getAvmProof(
inputs: AvmCircuitInputs,
Expand Down Expand Up @@ -503,12 +503,12 @@ export class BBNativeRollupProver implements ServerCircuitProver {
}

private async generateAvmProofWithBB(input: AvmCircuitInputs, workingDirectory: string): Promise<BBSuccess> {
logger.info(`Proving avm-circuit for ${input.functionName}...`);
logger.info(`Proving avm-circuit for TX ${input.hints.tx.hash}...`);

const provingResult = await generateAvmProof(this.config.bbBinaryPath, workingDirectory, input, logger);

if (provingResult.status === BB_RESULT.FAILURE) {
logger.error(`Failed to generate AVM proof for ${input.functionName}: ${provingResult.reason}`);
logger.error(`Failed to generate AVM proof for TX ${input.hints.tx.hash}: ${provingResult.reason}`);
throw new ProvingError(provingResult.reason, provingResult, provingResult.retry);
}

Expand Down Expand Up @@ -556,10 +556,10 @@ export class BBNativeRollupProver implements ServerCircuitProver {
this.instrumentation.recordAvmSize('circuitSize', appCircuitName, verificationKey.circuitSize);

logger.info(
`Generated proof for ${circuitType}(${input.functionName}) in ${Math.ceil(provingResult.durationMs)} ms`,
`Generated proof for ${circuitType}(${input.hints.tx.hash}) in ${Math.ceil(provingResult.durationMs)} ms`,
{
circuitName: circuitType,
appCircuitName: input.functionName,
appCircuitName: input.hints.tx.hash,
// does not include reading the proof from disk
duration: provingResult.durationMs,
proofSize: avmProof.binaryProof.buffer.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class PublicTxContext {
const firstNullifier = nonRevertibleAccumulatedDataFromPrivate.nullifiers[0];

// We wrap the DB to collect AVM hints.
const hints = new AvmExecutionHints(AvmTxHint.fromTx(tx));
const hints = new AvmExecutionHints(await AvmTxHint.fromTx(tx));
const hintingContractsDB = new HintingPublicContractsDB(contractsDB, hints);
const hintingTreesDB = new HintingPublicTreesDB(treesDB, hints);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export class PublicTxSimulator {
public async simulate(tx: Tx): Promise<PublicTxResult> {
try {
const txHash = await this.computeTxHash(tx);

this.log.debug(`Simulating ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, { txHash });

const context = await PublicTxContext.create(
Expand Down Expand Up @@ -437,7 +436,7 @@ export class PublicTxSimulator {
): AvmProvingRequest {
return {
type: ProvingRequestType.PUBLIC_VM,
inputs: new AvmCircuitInputs('public_dispatch', [], hints, publicInputs),
inputs: new AvmCircuitInputs(hints, publicInputs),
};
}
}
71 changes: 43 additions & 28 deletions yarn-project/stdlib/src/avm/avm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ export class AvmEnqueuedCallHint {

export class AvmTxHint {
constructor(
public readonly hash: string,
public readonly nonRevertibleAccumulatedData: {
noteHashes: Fr[];
nullifiers: Fr[];
Expand All @@ -393,12 +394,16 @@ export class AvmTxHint {
public readonly teardownEnqueuedCall: AvmEnqueuedCallHint | null,
) {}

static fromTx(tx: Tx): AvmTxHint {
static async fromTx(tx: Tx): Promise<AvmTxHint> {
const setupCallRequests = tx.getNonRevertiblePublicCallRequestsWithCalldata();
const appLogicCallRequests = tx.getRevertiblePublicCallRequestsWithCalldata();
const teardownCallRequest = tx.getTeardownPublicCallRequestWithCalldata();

// For informational purposes. Assumed quick because it should be cached.
const txHash = await tx.getTxHash();

return new AvmTxHint(
txHash.hash.toString(),
{
noteHashes: tx.data.forPublic!.nonRevertibleAccumulatedData.noteHashes.filter(x => !x.isZero()),
nullifiers: tx.data.forPublic!.nonRevertibleAccumulatedData.nullifiers.filter(x => !x.isZero()),
Expand Down Expand Up @@ -437,23 +442,43 @@ export class AvmTxHint {
}

static empty() {
return new AvmTxHint({ noteHashes: [], nullifiers: [] }, { noteHashes: [], nullifiers: [] }, [], [], null);
return new AvmTxHint('', { noteHashes: [], nullifiers: [] }, { noteHashes: [], nullifiers: [] }, [], [], null);
}

static get schema() {
return z.object({
nonRevertibleAccumulatedData: z.object({
noteHashes: schemas.Fr.array(),
nullifiers: schemas.Fr.array(),
}),
revertibleAccumulatedData: z.object({
noteHashes: schemas.Fr.array(),
nullifiers: schemas.Fr.array(),
}),
setupEnqueuedCalls: AvmEnqueuedCallHint.schema.array(),
appLogicEnqueuedCalls: AvmEnqueuedCallHint.schema.array(),
teardownEnqueuedCall: AvmEnqueuedCallHint.schema.nullable(),
});
return z
.object({
hash: z.string(),
nonRevertibleAccumulatedData: z.object({
noteHashes: schemas.Fr.array(),
nullifiers: schemas.Fr.array(),
}),
revertibleAccumulatedData: z.object({
noteHashes: schemas.Fr.array(),
nullifiers: schemas.Fr.array(),
}),
setupEnqueuedCalls: AvmEnqueuedCallHint.schema.array(),
appLogicEnqueuedCalls: AvmEnqueuedCallHint.schema.array(),
teardownEnqueuedCall: AvmEnqueuedCallHint.schema.nullable(),
})
.transform(
({
hash,
nonRevertibleAccumulatedData,
revertibleAccumulatedData,
setupEnqueuedCalls,
appLogicEnqueuedCalls,
teardownEnqueuedCall,
}) =>
new AvmTxHint(
hash,
nonRevertibleAccumulatedData,
revertibleAccumulatedData,
setupEnqueuedCalls,
appLogicEnqueuedCalls,
teardownEnqueuedCall,
),
);
}
}

Expand Down Expand Up @@ -537,29 +562,19 @@ export class AvmExecutionHints {
}

export class AvmCircuitInputs {
constructor(
public readonly functionName: string, // only informational
public readonly calldata: Fr[],
public readonly hints: AvmExecutionHints,
public publicInputs: AvmCircuitPublicInputs,
) {}
constructor(public readonly hints: AvmExecutionHints, public publicInputs: AvmCircuitPublicInputs) {}

static empty() {
return new AvmCircuitInputs('', [], AvmExecutionHints.empty(), AvmCircuitPublicInputs.empty());
return new AvmCircuitInputs(AvmExecutionHints.empty(), AvmCircuitPublicInputs.empty());
}

static get schema() {
return z
.object({
functionName: z.string(),
calldata: schemas.Fr.array(),
hints: AvmExecutionHints.schema,
publicInputs: AvmCircuitPublicInputs.schema,
})
.transform(
({ functionName, calldata, hints, publicInputs }) =>
new AvmCircuitInputs(functionName, calldata, hints, publicInputs),
);
.transform(({ hints, publicInputs }) => new AvmCircuitInputs(hints, publicInputs));
}

public serializeWithMessagePack(): Buffer {
Expand Down
7 changes: 3 additions & 4 deletions yarn-project/stdlib/src/tests/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,7 @@ export function makeAvmEnqueuedCallHint(seed = 0): AvmEnqueuedCallHint {

export function makeAvmTxHint(seed = 0): AvmTxHint {
return new AvmTxHint(
`txhash-${seed}`,
{
noteHashes: makeArray((seed % 20) + 4, i => new Fr(i), seed + 0x1000),
nullifiers: makeArray((seed % 20) + 4, i => new Fr(i), seed + 0x2000),
Expand Down Expand Up @@ -1544,14 +1545,12 @@ export async function makeAvmCircuitInputs(
overrides: Partial<FieldsOf<AvmCircuitInputs>> = {},
): Promise<AvmCircuitInputs> {
const fields = {
functionName: `function${seed}`,
calldata: makeArray((seed % 100) + 10, i => new Fr(i), seed + 0x1000),
avmHints: await makeAvmExecutionHints(seed + 0x3000),
hints: await makeAvmExecutionHints(seed + 0x3000),
publicInputs: makeAvmCircuitPublicInputs(seed + 0x4000),
...overrides,
};

return new AvmCircuitInputs(fields.functionName, fields.calldata, fields.avmHints, fields.publicInputs);
return new AvmCircuitInputs(fields.hints, fields.publicInputs);
}

/**
Expand Down
Loading