Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: rename kernel circuits and disambiguate inputs #4535

Merged
merged 3 commits into from
Feb 12, 2024
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
6 changes: 3 additions & 3 deletions yarn-project/aztec-nr/aztec/src/context/private_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct PrivateContext {
inputs: PrivateContextInputs,
side_effect_counter: u32,

meta_hwm: u32,
max_non_revertible_side_effect_counter: u32,

args_hash : Field,
return_values : BoundedVec<Field, RETURN_VALUES_LENGTH>,
Expand Down Expand Up @@ -91,7 +91,7 @@ impl PrivateContext {
PrivateContext {
inputs: inputs,
side_effect_counter: inputs.call_context.start_side_effect_counter,
meta_hwm: 0,
max_non_revertible_side_effect_counter: 0,

args_hash: args_hash,
return_values: BoundedVec::new(0),
Expand Down Expand Up @@ -163,7 +163,7 @@ impl PrivateContext {
call_context: self.inputs.call_context,
args_hash: self.args_hash,
return_values: self.return_values.storage,
meta_hwm: self.meta_hwm,
max_non_revertible_side_effect_counter: self.max_non_revertible_side_effect_counter,
read_requests: self.read_requests.storage,
nullifier_key_validation_requests: self.nullifier_key_validation_requests.storage,
new_commitments: self.new_commitments.storage,
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/circuit-types/src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
Proof,
} from '@aztec/circuits.js';
import { makePrivateKernelPublicInputsFinal, makePublicCallRequest } from '@aztec/circuits.js/factories';
import { makePrivateKernelTailCircuitPublicInputs, makePublicCallRequest } from '@aztec/circuits.js/factories';
import { ContractArtifact } from '@aztec/foundation/abi';
import { times } from '@aztec/foundation/collection';
import { randomBytes } from '@aztec/foundation/crypto';
Expand All @@ -30,7 +30,7 @@ export const randomTxHash = (): TxHash => new TxHash(randomBytes(32));

export const mockTx = (seed = 1) => {
return new Tx(
makePrivateKernelPublicInputsFinal(seed),
makePrivateKernelTailCircuitPublicInputs(seed),
new Proof(Buffer.alloc(0)),
TxL2Logs.random(8, 3), // 8 priv function invocations creating 3 encrypted logs each
TxL2Logs.random(11, 2), // 8 priv + 3 pub function invocations creating 2 unencrypted logs each
Expand Down
15 changes: 10 additions & 5 deletions yarn-project/circuit-types/src/tx/tx.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { MAX_NEW_CONTRACTS_PER_TX, PrivateKernelPublicInputsFinal, Proof, PublicCallRequest } from '@aztec/circuits.js';
import {
MAX_NEW_CONTRACTS_PER_TX,
PrivateKernelTailCircuitPublicInputs,
Proof,
PublicCallRequest,
} from '@aztec/circuits.js';
import { arrayNonEmptyLength } from '@aztec/foundation/collection';
import { BufferReader, Tuple, serializeToBuffer } from '@aztec/foundation/serialize';

Expand All @@ -17,7 +22,7 @@ export class Tx {
/**
* Output of the private kernel circuit for this tx.
*/
public readonly data: PrivateKernelPublicInputsFinal,
public readonly data: PrivateKernelTailCircuitPublicInputs,
/**
* Proof from the private kernel circuit.
*/
Expand Down Expand Up @@ -70,7 +75,7 @@ export class Tx {
static fromBuffer(buffer: Buffer | BufferReader): Tx {
const reader = BufferReader.asReader(buffer);
return new Tx(
reader.readObject(PrivateKernelPublicInputsFinal),
reader.readObject(PrivateKernelTailCircuitPublicInputs),
reader.readObject(Proof),
reader.readObject(TxL2Logs),
reader.readObject(TxL2Logs),
Expand Down Expand Up @@ -126,7 +131,7 @@ export class Tx {
* @returns A Tx class object.
*/
public static fromJSON(obj: any) {
const publicInputs = PrivateKernelPublicInputsFinal.fromBuffer(Buffer.from(obj.data, 'hex'));
const publicInputs = PrivateKernelTailCircuitPublicInputs.fromBuffer(Buffer.from(obj.data, 'hex'));
const encryptedLogs = TxL2Logs.fromBuffer(Buffer.from(obj.encryptedLogs, 'hex'));
const unencryptedLogs = TxL2Logs.fromBuffer(Buffer.from(obj.unencryptedLogs, 'hex'));
const proof = Buffer.from(obj.proof, 'hex');
Expand Down Expand Up @@ -199,7 +204,7 @@ export class Tx {
* @returns The cloned transaction.
*/
static clone(tx: Tx): Tx {
const publicInputs = PrivateKernelPublicInputsFinal.fromBuffer(tx.data.toBuffer());
const publicInputs = PrivateKernelTailCircuitPublicInputs.fromBuffer(tx.data.toBuffer());
const proof = Proof.fromBuffer(tx.proof.toBuffer());
const encryptedLogs = TxL2Logs.fromBuffer(tx.encryptedLogs.toBuffer());
const unencryptedLogs = TxL2Logs.fromBuffer(tx.unencryptedLogs.toBuffer());
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/circuits.js/src/contract/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export * from './contract_instance.js';
export * from './contract_tree/index.js';
export * from './contract_class_id.js';
export * from './contract_class.js';
export * from './artifact_hash.js';
export * from './contract_address.js';
export * from './private_function.js';
export * from './public_bytecode.js';
export * from './contract_class.js';
export * from './contract_class_id.js';
export * from './contract_class_registered_event.js';
export * from './contract_instance.js';
export * from './contract_instance_deployed_event.js';
export * from './contract_tree/index.js';
export * from './private_function.js';
export * from './public_bytecode.js';
4 changes: 2 additions & 2 deletions yarn-project/circuits.js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './structs/index.js';
export * from './constants.gen.js';
export * from './contract/index.js';
export * from './keys/index.js';
export * from './structs/index.js';
export * from './types/index.js';
export * from './constants.gen.js';
23 changes: 15 additions & 8 deletions yarn-project/circuits.js/src/structs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ export * from './global_variables.js';
export * from './header.js';
export * from './kernel/combined_accumulated_data.js';
export * from './kernel/combined_constant_data.js';
export * from './kernel/previous_kernel_data.js';
export * from './kernel/private_kernel.js';
export * from './kernel/public_inputs.js';
export * from './kernel/public_inputs_final.js';
export * from './kernel/public_kernel.js';
export * from './kernel/private_call_data.js';
export * from './kernel/private_kernel_init_circuit_private_inputs.js';
export * from './kernel/private_kernel_inner_circuit_private_inputs.js';
export * from './kernel/private_kernel_inner_circuit_public_inputs.js';
export * from './kernel/private_kernel_inner_data.js';
export * from './kernel/private_kernel_tail_circuit_private_inputs.js';
export * from './kernel/private_kernel_tail_circuit_public_inputs.js';
export * from './kernel/private_kernel_tail_data.js';
export * from './kernel/public_call_data.js';
export * from './kernel/public_kernel_circuit_private_inputs.js';
export * from './kernel/public_kernel_circuit_public_inputs.js';
export * from './kernel/public_kernel_data.js';
export * from './membership_witness.js';
export * from './nullifier_key_validation_request.js';
export * from './partial_state_reference.js';
export * from './private_call_stack_item.js';
export * from './private_circuit_public_inputs.js';
export * from './proof.js';
Expand All @@ -32,14 +40,13 @@ export * from './rollup/base_rollup.js';
export * from './rollup/merge_rollup.js';
export * from './rollup/previous_rollup_data.js';
export * from './rollup/root_rollup.js';
export * from './rollup/state_diff_hints.js';
export * from './shared.js';
export * from './side_effects.js';
export * from './rollup/state_diff_hints.js';
export * from './state_reference.js';
export * from './tx_context.js';
export * from './tx_request.js';
export * from './verification_key.js';
export * from './state_reference.js';
export * from './partial_state_reference.js';

export { FunctionSelector } from '@aztec/foundation/abi';
export * from '@aztec/foundation/aztec-address';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,18 +453,18 @@ export class FinalAccumulatedData {
}
}

export class AccumulatedMetaData {
export class AccumulatedNonRevertibleData {
constructor(
/**
* The new commitments made in this transaction.
* The new non-revertible commitments made in this transaction.
*/
public newCommitments: Tuple<SideEffect, typeof MAX_NEW_COMMITMENTS_PER_TX_META>,
/**
* The new nullifiers made in this transaction.
* The new non-revertible nullifiers made in this transaction.
*/
public newNullifiers: Tuple<SideEffectLinkedToNoteHash, typeof MAX_NEW_NULLIFIERS_PER_TX_META>,
/**
* Current public call stack.
* Current public call stack that will produce non-revertible side effects.
*/
public publicCallStack: Tuple<CallRequest, typeof MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX_META>,
) {}
Expand All @@ -473,9 +473,9 @@ export class AccumulatedMetaData {
return serializeToBuffer(this.newCommitments, this.newNullifiers, this.publicCallStack);
}

static fromBuffer(buffer: Buffer | BufferReader): AccumulatedMetaData {
static fromBuffer(buffer: Buffer | BufferReader): AccumulatedNonRevertibleData {
const reader = BufferReader.asReader(buffer);
return new AccumulatedMetaData(
return new AccumulatedNonRevertibleData(
reader.readArray(MAX_NEW_COMMITMENTS_PER_TX_META, SideEffect),
reader.readArray(MAX_NEW_NULLIFIERS_PER_TX_META, SideEffectLinkedToNoteHash),
reader.readArray(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX_META, CallRequest),
Expand All @@ -487,11 +487,11 @@ export class AccumulatedMetaData {
}

static fromString(str: string) {
return AccumulatedMetaData.fromBuffer(Buffer.from(str, 'hex'));
return AccumulatedNonRevertibleData.fromBuffer(Buffer.from(str, 'hex'));
}

static empty() {
return new AccumulatedMetaData(
return new AccumulatedNonRevertibleData(
makeTuple(MAX_NEW_COMMITMENTS_PER_TX_META, SideEffect.empty),
makeTuple(MAX_NEW_NULLIFIERS_PER_TX_META, SideEffectLinkedToNoteHash.empty),
makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX_META, CallRequest.empty),
Expand Down

This file was deleted.

135 changes: 135 additions & 0 deletions yarn-project/circuits.js/src/structs/kernel/private_call_data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { Fr } from '@aztec/foundation/fields';
import { BufferReader, Tuple, serializeToBuffer } from '@aztec/foundation/serialize';
import { FieldsOf } from '@aztec/foundation/types';

import {
FUNCTION_TREE_HEIGHT,
MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL,
MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,
MAX_READ_REQUESTS_PER_CALL,
} from '../../constants.gen.js';
import { CallRequest } from '../call_request.js';
import { MembershipWitness } from '../membership_witness.js';
import { PrivateCallStackItem } from '../private_call_stack_item.js';
import { Proof } from '../proof.js';
import { ReadRequestMembershipWitness } from '../read_request_membership_witness.js';
import { VerificationKey } from '../verification_key.js';

/**
* Private call data.
*/
export class PrivateCallData {
constructor(
/**
* The call stack item currently being processed.
*/
public callStackItem: PrivateCallStackItem,
/**
* Other private call stack items to be processed.
*/
public privateCallStack: Tuple<CallRequest, typeof MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL>,
/**
* Other public call stack items to be processed.
*/
public publicCallStack: Tuple<CallRequest, typeof MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL>,
/**
* The proof of the execution of this private call.
*/
public proof: Proof,
/**
* The verification key for the function being invoked.
*/
public vk: VerificationKey,
/**
* Artifact hash of the contract class for this private call.
*/
public contractClassArtifactHash: Fr,
/**
* Public bytecode commitment for the contract class for this private call.
*/
public contractClassPublicBytecodeCommitment: Fr,
/**
* Public keys hash of the contract instance.
*/
public publicKeysHash: Fr,
/**
* Salted initialization hash of the contract instance.
*/
public saltedInitializationHash: Fr,
/**
* The membership witness for the function leaf corresponding to the function being invoked.
*/
public functionLeafMembershipWitness: MembershipWitness<typeof FUNCTION_TREE_HEIGHT>,
/**
* The membership witnesses for read requests created by the function being invoked.
*/
public readRequestMembershipWitnesses: Tuple<ReadRequestMembershipWitness, typeof MAX_READ_REQUESTS_PER_CALL>,
/**
* The address of the portal contract corresponding to the contract on which the function is being invoked.
*/
public portalContractAddress: Fr,
/**
* The hash of the ACIR of the function being invoked.
*/
public acirHash: Fr,
) {}

/**
* Serialize into a field array. Low-level utility.
* @param fields - Object with fields.
* @returns The array.
*/
static getFields(fields: FieldsOf<PrivateCallData>) {
return [
fields.callStackItem,
fields.privateCallStack,
fields.publicCallStack,
fields.proof,
fields.vk,
fields.contractClassArtifactHash,
fields.contractClassPublicBytecodeCommitment,
fields.publicKeysHash,
fields.saltedInitializationHash,
fields.functionLeafMembershipWitness,
fields.readRequestMembershipWitnesses,
fields.portalContractAddress,
fields.acirHash,
] as const;
}

static from(fields: FieldsOf<PrivateCallData>): PrivateCallData {
return new PrivateCallData(...PrivateCallData.getFields(fields));
}

/**
* Serialize this as a buffer.
* @returns The buffer.
*/
toBuffer(): Buffer {
return serializeToBuffer(...PrivateCallData.getFields(this));
}

/**
* Deserializes from a buffer or reader.
* @param buffer - Buffer or reader to read from.
* @returns The deserialized instance.
*/
static fromBuffer(buffer: Buffer | BufferReader): PrivateCallData {
const reader = BufferReader.asReader(buffer);
return new PrivateCallData(
reader.readObject(PrivateCallStackItem),
reader.readArray(MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, CallRequest),
reader.readArray(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, CallRequest),
reader.readObject(Proof),
reader.readObject(VerificationKey),
reader.readObject(Fr),
reader.readObject(Fr),
reader.readObject(Fr),
reader.readObject(Fr),
reader.readObject(MembershipWitness.deserializer(FUNCTION_TREE_HEIGHT)),
reader.readArray(MAX_READ_REQUESTS_PER_CALL, ReadRequestMembershipWitness),
reader.readObject(Fr),
reader.readObject(Fr),
);
}
}
Loading
Loading