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

test: cleaning up circuits test setup #4235

Merged
merged 6 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
31 changes: 30 additions & 1 deletion yarn-project/circuits.js/src/structs/kernel/private_kernel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fr } from '@aztec/foundation/fields';
import { Fr, GrumpkinScalar } from '@aztec/foundation/fields';
import { BufferReader, Tuple, serializeToBuffer } from '@aztec/foundation/serialize';
import { FieldsOf } from '@aztec/foundation/types';

Expand Down Expand Up @@ -148,6 +148,16 @@ export class PrivateKernelInputsInit {
toBuffer() {
return serializeToBuffer(this.txRequest, this.privateCall);
}

/**
* Deserializes from a buffer or reader.
* @param buffer - Buffer or reader to read from.
* @returns The deserialized instance.
*/
static fromBuffer(buffer: Buffer | BufferReader): PrivateKernelInputsInit {
const reader = BufferReader.asReader(buffer);
return new PrivateKernelInputsInit(reader.readObject(TxRequest), reader.readObject(PrivateCallData));
}
}

/**
Expand Down Expand Up @@ -239,4 +249,23 @@ export class PrivateKernelInputsOrdering {
this.masterNullifierSecretKeys,
);
}

/**
* Deserializes from a buffer or reader.
* @param buffer - Buffer or reader to read from.
* @returns The deserialized instance.
*/
static fromBuffer(buffer: Buffer | BufferReader): PrivateKernelInputsOrdering {
const reader = BufferReader.asReader(buffer);
return new PrivateKernelInputsOrdering(
reader.readObject(PreviousKernelData),
reader.readArray(MAX_NEW_COMMITMENTS_PER_TX, SideEffect),
reader.readNumbers(MAX_NEW_COMMITMENTS_PER_TX),
reader.readArray(MAX_READ_REQUESTS_PER_TX, Fr),
reader.readArray(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash),
reader.readNumbers(MAX_NEW_NULLIFIERS_PER_TX),
reader.readArray(MAX_NEW_NULLIFIERS_PER_TX, Fr),
reader.readArray(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, GrumpkinScalar),
);
}
}
32 changes: 26 additions & 6 deletions yarn-project/end-to-end/src/e2e_nested_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,32 @@ describe('e2e_nested_contract', () => {
.wait();

if (isGenerateTestDataEnabled()) {
const privateKernelInputs = getTestData('private-kernel-inputs-inner');
const nestedCallPrivateKernelInput = privateKernelInputs[privateKernelInputs.length - 1];
writeFileSync(
'../noir-protocol-circuits/src/fixtures/nested-call-private-kernel-inner.hex',
nestedCallPrivateKernelInput.toBuffer().toString('hex'),
);
{
const privateKernelInputsInit = getTestData('private-kernel-inputs-init');
const nestedCallPrivateKernelInput = privateKernelInputsInit[0];
writeFileSync(
'../noir-protocol-circuits/src/fixtures/nested-call-private-kernel-init.hex',
nestedCallPrivateKernelInput.toBuffer().toString('hex'),
);
}

{
const privateKernelInputsInner = getTestData('private-kernel-inputs-inner');
const nestedCallPrivateKernelInput = privateKernelInputsInner[privateKernelInputsInner.length - 1];
writeFileSync(
'../noir-protocol-circuits/src/fixtures/nested-call-private-kernel-inner.hex',
nestedCallPrivateKernelInput.toBuffer().toString('hex'),
);
}

{
const privateKernelInputsOrdering = getTestData('private-kernel-inputs-ordering');
const nestedCallPrivateKernelInput = privateKernelInputsOrdering[0];
writeFileSync(
'../noir-protocol-circuits/src/fixtures/nested-call-private-kernel-ordering.hex',
nestedCallPrivateKernelInput.toBuffer().toString('hex'),
);
}
}
}, 100_000);

Expand Down
10 changes: 10 additions & 0 deletions yarn-project/foundation/src/serialize/buffer_reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ export class BufferReader {
return this.buffer.readUint32BE(this.index - 4);
}

/**
* Reads `size` 32-bit unsigned integers from the buffer at the current index position.
* @param size - The number of 32-bit unsigned integers to read.
* @returns An array of 32-bit unsigned integers.
*/
public readNumbers<N extends number>(size: N): Tuple<number, N> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: I'd rename size to count. I initially thought that the param was the size of each number, but then reading the comment I understood it's the amount of numbers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Addressed in 185c773

const result = Array.from({ length: size }, () => this.readNumber());
return result as Tuple<number, N>;
}

/**
* Reads a 16-bit unsigned integer from the buffer at the current index position.
* Updates the index position by 2 bytes after reading the number.
Expand Down
Loading
Loading