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
6 changes: 3 additions & 3 deletions yarn-project/acir-simulator/src/acvm/oracle/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class Oracle {
`Low nullifier witness not found for nullifier ${parsedNullifier} at block ${parsedBlockNumber}.`,
);
}
return witness.toFieldArray().map(toACVMField);
return witness.toFields().map(toACVMField);
}

async getLowNullifierMembershipWitness(
Expand All @@ -105,7 +105,7 @@ export class Oracle {
`Low nullifier witness not found for nullifier ${parsedNullifier} at block ${parsedBlockNumber}.`,
);
}
return witness.toFieldArray().map(toACVMField);
return witness.toFields().map(toACVMField);
}

async getPublicDataTreeWitness([blockNumber]: ACVMField[], [leafSlot]: ACVMField[]): Promise<ACVMField[]> {
Expand All @@ -116,7 +116,7 @@ export class Oracle {
if (!witness) {
throw new Error(`Public data witness not found for slot ${parsedLeafSlot} at block ${parsedBlockNumber}.`);
}
return witness.toFieldArray().map(toACVMField);
return witness.toFields().map(toACVMField);
}

async getHeader([blockNumber]: ACVMField[]): Promise<ACVMField[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class MessageLoadOracleInputs<N extends number> {
) {}

toFields(): Fr[] {
return [...this.message.toFieldArray(), new Fr(this.index), ...this.siblingPath.toFieldArray()];
return [...this.message.toFields(), new Fr(this.index), ...this.siblingPath.toFields()];
}
}

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/circuit-types/src/interfaces/nullifier_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class NullifierMembershipWitness {
* Returns a field array representation of a nullifier witness.
* @returns A field array representation of a nullifier witness.
*/
public toFieldArray(): Fr[] {
return [new Fr(this.index), ...this.leafPreimage.toFieldArray(), ...this.siblingPath.toFieldArray()];
public toFields(): Fr[] {
return [new Fr(this.index), ...this.leafPreimage.toFields(), ...this.siblingPath.toFields()];
}
}
4 changes: 2 additions & 2 deletions yarn-project/circuit-types/src/interfaces/public_data_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ export class PublicDataWitness {
* Returns a field array representation of a public data witness.
* @returns A field array representation of a public data witness.
*/
public toFieldArray(): Fr[] {
public toFields(): Fr[] {
return [
new Fr(this.index),
new Fr(this.leafPreimage.slot),
new Fr(this.leafPreimage.value),
new Fr(this.leafPreimage.nextIndex),
new Fr(this.leafPreimage.nextSlot),
...this.siblingPath.toFieldArray(),
...this.siblingPath.toFields(),
];
}
}
12 changes: 6 additions & 6 deletions yarn-project/circuit-types/src/l1_to_l2_message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ export class L1ToL2Message {
* Returns each element within its own field so that it can be consumed by an acvm oracle call.
* @returns The message as an array of fields (in order).
*/
toFieldArray(): Fr[] {
toFields(): Fr[] {
return [
...this.sender.toFieldArray(),
...this.recipient.toFieldArray(),
...this.sender.toFields(),
...this.recipient.toFields(),
this.content,
this.secretHash,
new Fr(BigInt(this.deadline)),
Expand All @@ -118,7 +118,7 @@ export class L1ToL2Message {
}

hash(): Fr {
return Fr.fromBufferReduce(sha256(serializeToBuffer(...this.toFieldArray())));
return Fr.fromBufferReduce(sha256(serializeToBuffer(...this.toFields())));
}

static fromBuffer(buffer: Buffer | BufferReader): L1ToL2Message {
Expand Down Expand Up @@ -177,7 +177,7 @@ export class L1Actor {
return new L1Actor(EthAddress.ZERO, 0);
}

toFieldArray(): Fr[] {
toFields(): Fr[] {
return [this.sender.toField(), new Fr(BigInt(this.chainId))];
}

Expand Down Expand Up @@ -216,7 +216,7 @@ export class L2Actor {
return new L2Actor(AztecAddress.ZERO, 0);
}

toFieldArray(): Fr[] {
toFields(): Fr[] {
return [this.recipient.toField(), new Fr(BigInt(this.version))];
}

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/circuit-types/src/sibling_path/sibling-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class SiblingPath<N extends number> {
* Convert the Sibling Path object into an array of field elements.
* @returns The field array representation of this object.
*/
public toFieldArray(): Fr[] {
public toFields(): Fr[] {
return this.data.map(buf => Fr.fromBuffer(buf));
}

Expand All @@ -85,7 +85,7 @@ export class SiblingPath<N extends number> {
* @returns A tuple representation of the sibling path.
*/
public toTuple<N extends number>(): Tuple<Fr, N> {
const array = this.toFieldArray();
const array = this.toFields();
return makeTuple(array.length as N, i => array[i], 0);
}

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/circuits.js/src/structs/call_context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { EthAddress } from '@aztec/foundation/eth-address';
import { BufferReader, FieldReader, serializeToBuffer, serializeToFieldArray } from '@aztec/foundation/serialize';
import { BufferReader, FieldReader, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize';
import { FieldsOf } from '@aztec/foundation/types';

import { Fr, FunctionSelector } from './index.js';
Expand Down Expand Up @@ -108,7 +108,7 @@ export class CallContext {
}

toFields(): Fr[] {
return serializeToFieldArray(...CallContext.getFields(this));
return serializeToFields(...CallContext.getFields(this));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/circuits.js/src/structs/global_variables.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fr } from '@aztec/foundation/fields';
import { BufferReader, FieldReader, serializeToBuffer, serializeToFieldArray } from '@aztec/foundation/serialize';
import { BufferReader, FieldReader, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize';
import { FieldsOf } from '@aztec/foundation/types';

/**
Expand Down Expand Up @@ -68,7 +68,7 @@ export class GlobalVariables {
}

toFields() {
return serializeToFieldArray(...GlobalVariables.getFields(this));
return serializeToFields(...GlobalVariables.getFields(this));
}

toJSON() {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/structs/membership_witness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ export class MembershipWitness<N extends number> {

// import { SiblingPath } from '@aztec/merkle-tree';
// static fromSiblingPath<N extends number>(leafIndex: bigint, siblingPath: SiblingPath<N>): MembershipWitness<N> {
// return new MembershipWitness<N>(siblingPath.pathSize, leafIndex, siblingPath.toFieldArray() as Tuple<Fr, N>);
// return new MembershipWitness<N>(siblingPath.pathSize, leafIndex, siblingPath.toFields() as Tuple<Fr, N>);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ import { makeTuple } from '@aztec/foundation/array';
import { isArrayEmpty } from '@aztec/foundation/collection';
import { pedersenHash } from '@aztec/foundation/crypto';
import { Fr } from '@aztec/foundation/fields';
import {
BufferReader,
FieldReader,
Tuple,
serializeToBuffer,
serializeToFieldArray,
} from '@aztec/foundation/serialize';
import { BufferReader, FieldReader, Tuple, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize';
import { FieldsOf } from '@aztec/foundation/types';

import {
Expand Down Expand Up @@ -282,7 +276,7 @@ export class PrivateCircuitPublicInputs {
* Serialize this as a field array.
*/
toFields(): Fr[] {
return serializeToFieldArray(...PrivateCircuitPublicInputs.getFields(this));
return serializeToFields(...PrivateCircuitPublicInputs.getFields(this));
}

hash(): Fr {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AztecAddress } from '@aztec/foundation/aztec-address';
import { isArrayEmpty } from '@aztec/foundation/collection';
import { pedersenHash } from '@aztec/foundation/crypto';
import { Fr } from '@aztec/foundation/fields';
import { FieldReader, Tuple, serializeToBuffer, serializeToFieldArray } from '@aztec/foundation/serialize';
import { FieldReader, Tuple, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize';
import { FieldsOf } from '@aztec/foundation/types';

import {
Expand Down Expand Up @@ -175,7 +175,7 @@ export class PublicCircuitPublicInputs {
}

toFields(): Fr[] {
return serializeToFieldArray(...PublicCircuitPublicInputs.getFields(this));
return serializeToFields(...PublicCircuitPublicInputs.getFields(this));
}

static fromFields(fields: Fr[] | FieldReader): PublicCircuitPublicInputs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class NullifierLeafPreimage implements IndexedTreeLeafPreimage {
];
}

toFieldArray(): Fr[] {
toFields(): Fr[] {
return this.toHashInputs().map(buf => Fr.fromBuffer(buf));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('e2e_blacklist_token_contract', () => {
index,
value: Fr.fromBuffer(slowUpdateTreeSimulator.getLeafValue(index, includeUncommitted)!),
// eslint-disable-next-line camelcase
sibling_path: (await slowUpdateTreeSimulator.getSiblingPath(index, includeUncommitted)).toFieldArray(),
sibling_path: (await slowUpdateTreeSimulator.getSiblingPath(index, includeUncommitted)).toFields(),
};
};

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_slow_tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('e2e_slow_tree', () => {
index,
value: Fr.fromBuffer(slowUpdateTreeSimulator.getLeafValue(index, includeUncommitted)!),
// eslint-disable-next-line camelcase
sibling_path: (await slowUpdateTreeSimulator.getSiblingPath(index, includeUncommitted)).toFieldArray(),
sibling_path: (await slowUpdateTreeSimulator.getSiblingPath(index, includeUncommitted)).toFields(),
};
};

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/foundation/src/serialize/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ export function serializeToBufferArray(...objs: Bufferable[]): Buffer[] {
* @param objs - Objects to serialize.
* @returns An array of fields with the concatenation of all fields.
*/
export function serializeToFieldArray(...objs: Fieldeable[]): Fr[] {
export function serializeToFields(...objs: Fieldeable[]): Fr[] {
let ret: Fr[] = [];
for (const obj of objs) {
if (Array.isArray(obj)) {
ret = [...ret, ...serializeToFieldArray(...obj)];
ret = [...ret, ...serializeToFields(...obj)];
} else if (obj instanceof Fr) {
ret.push(obj);
} else if (typeof obj === 'boolean' || typeof obj === 'number' || typeof obj === 'bigint') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('Data generation for noir tests', () => {

const root = noteHashTree.getRoot(true);
const siblingPaths = await Promise.all(
indexes.map(async index => (await noteHashTree.getSiblingPath(index, true)).toFieldArray()),
indexes.map(async index => (await noteHashTree.getSiblingPath(index, true)).toFields()),
);

expect({
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/kernel_oracle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class KernelOracle implements ProvingDataOracle {
return new MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT>(
path.pathSize,
leafIndex,
path.toFieldArray() as Tuple<Fr, typeof NOTE_HASH_TREE_HEIGHT>,
path.toFields() as Tuple<Fr, typeof NOTE_HASH_TREE_HEIGHT>,
);
}

Expand Down
10 changes: 5 additions & 5 deletions yarn-project/pxe/src/simulator_oracle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ export class SimulatorOracle implements DBOracle {
// @todo Doing a nasty workaround here because of https://github.com/AztecProtocol/aztec-packages/issues/3414
switch (treeId) {
case MerkleTreeId.CONTRACT_TREE:
return (await this.stateInfoProvider.getContractSiblingPath(blockNumber, leafIndex)).toFieldArray();
return (await this.stateInfoProvider.getContractSiblingPath(blockNumber, leafIndex)).toFields();
case MerkleTreeId.NULLIFIER_TREE:
return (await this.stateInfoProvider.getNullifierSiblingPath(blockNumber, leafIndex)).toFieldArray();
return (await this.stateInfoProvider.getNullifierSiblingPath(blockNumber, leafIndex)).toFields();
case MerkleTreeId.NOTE_HASH_TREE:
return (await this.stateInfoProvider.getNoteHashSiblingPath(blockNumber, leafIndex)).toFieldArray();
return (await this.stateInfoProvider.getNoteHashSiblingPath(blockNumber, leafIndex)).toFields();
case MerkleTreeId.PUBLIC_DATA_TREE:
return (await this.stateInfoProvider.getPublicDataSiblingPath(blockNumber, leafIndex)).toFieldArray();
return (await this.stateInfoProvider.getPublicDataSiblingPath(blockNumber, leafIndex)).toFields();
case MerkleTreeId.ARCHIVE:
return (await this.stateInfoProvider.getArchiveSiblingPath(blockNumber, leafIndex)).toFieldArray();
return (await this.stateInfoProvider.getArchiveSiblingPath(blockNumber, leafIndex)).toFields();
default:
throw new Error('Not implemented');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ export class SoloBlockBuilder implements BlockBuilder {
const { size } = await this.db.getTreeInfo(treeId);
// TODO: Check for off-by-one errors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know who created this todo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git blame points to @spalladino

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I wrote this during the London offsite in my 2nd week on the job, heh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I wrote this during the London offsite in my 2nd week on the job, heh

@spalladino Ok ok, will nuke it in my PR up the stack

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that the comment 2 lines above is also stale. Will nuke that as well.

const path = await this.db.getSiblingPath(treeId, size);
return path.toFieldArray();
return path.toFields();
};

const newL1ToL2MessageTreeRootSiblingPathArray = await this.getSubtreeSiblingPath(
Expand Down Expand Up @@ -450,7 +450,7 @@ export class SoloBlockBuilder implements BlockBuilder {
throw new Error(`Leaf with value ${value} not found in tree ${MerkleTreeId[treeId]}`);
}
const path = await this.db.getSiblingPath(treeId, index);
return new MembershipWitness(height, index, assertLength(path.toFieldArray(), height));
return new MembershipWitness(height, index, assertLength(path.toFields(), height));
}

protected async getConstantRollupData(globalVariables: GlobalVariables): Promise<ConstantRollupData> {
Expand Down Expand Up @@ -489,7 +489,7 @@ export class SoloBlockBuilder implements BlockBuilder {
witness: new MembershipWitness(
NULLIFIER_TREE_HEIGHT,
BigInt(prevValueIndex.index),
assertLength(prevValueSiblingPath.toFieldArray(), NULLIFIER_TREE_HEIGHT),
assertLength(prevValueSiblingPath.toFields(), NULLIFIER_TREE_HEIGHT),
),
};
}
Expand All @@ -499,7 +499,7 @@ export class SoloBlockBuilder implements BlockBuilder {
const fullSiblingPath = await this.db.getSiblingPath(treeId, nextAvailableLeafIndex);

// Drop the first subtreeHeight items since we only care about the path to the subtree root
return fullSiblingPath.getSubtreeSiblingPath(subtreeHeight).toFieldArray();
return fullSiblingPath.getSubtreeSiblingPath(subtreeHeight).toFields();
}

protected async processPublicDataUpdateRequests(tx: ProcessedTx) {
Expand All @@ -525,7 +525,7 @@ export class SoloBlockBuilder implements BlockBuilder {
return sortedNewLeavesIndexes[i];
});

const subtreeSiblingPathAsFields = newSubtreeSiblingPath.toFieldArray();
const subtreeSiblingPathAsFields = newSubtreeSiblingPath.toFields();
const newPublicDataSubtreeSiblingPath = makeTuple(PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH, i => {
return subtreeSiblingPathAsFields[i];
});
Expand Down Expand Up @@ -655,7 +655,7 @@ export class SoloBlockBuilder implements BlockBuilder {
MembershipWitness.fromBufferArray(l.index, assertLength(l.siblingPath.toBufferArray(), NULLIFIER_TREE_HEIGHT)),
);

const nullifierSubtreeSiblingPathArray = newNullifiersSubtreeSiblingPath.toFieldArray();
const nullifierSubtreeSiblingPathArray = newNullifiersSubtreeSiblingPath.toFields();

const nullifierSubtreeSiblingPath = makeTuple(NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH, i =>
i < nullifierSubtreeSiblingPathArray.length ? nullifierSubtreeSiblingPathArray[i] : Fr.ZERO,
Expand Down