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
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 `count` 32-bit unsigned integers from the buffer at the current index position.
* @param count - The number of 32-bit unsigned integers to read.
* @returns An array of 32-bit unsigned integers.
*/
public readNumbers<N extends number>(count: N): Tuple<number, N> {
const result = Array.from({ length: count }, () => 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