Skip to content
Open
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
101 changes: 0 additions & 101 deletions noir-projects/aztec-nr/aztec/src/oracle/tx_resolution.nr
Original file line number Diff line number Diff line change
Expand Up @@ -18,104 +18,3 @@ pub(crate) unconstrained fn get_resolved_txs(requests: EphemeralArray<Field>) ->

#[oracle(aztec_utl_getResolvedTxs)]
unconstrained fn get_resolved_txs_oracle(requests: EphemeralArray<Field>) -> EphemeralArray<Option<ResolvedTx>> {}

mod test {
use crate::oracle::tx_resolution::ResolvedTx;
use crate::protocol::traits::Deserialize;

#[test]
unconstrained fn resolved_tx_serialization_matches_typescript() {
// Setup test data
let tx_hash = 123;
let unique_note_hashes = BoundedVec::from_array([4, 5]);
let first_nullifier = 6;
let block_number: u32 = 7;
let block_hash = 8;

// Create a ResolvedTx instance
let resolved_tx = ResolvedTx {
tx_hash,
unique_note_hashes_in_tx: unique_note_hashes,
first_nullifier_in_tx: first_nullifier,
block_number,
block_hash,
};

// Expected output generated from TypeScript's `ResolvedTx.toFields()`
let serialized_resolved_tx_from_typescript = [
0x000000000000000000000000000000000000000000000000000000000000007b,
0x0000000000000000000000000000000000000000000000000000000000000004,
0x0000000000000000000000000000000000000000000000000000000000000005,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000002,
0x0000000000000000000000000000000000000000000000000000000000000006,
0x0000000000000000000000000000000000000000000000000000000000000007,
0x0000000000000000000000000000000000000000000000000000000000000008,
];

let deserialized = ResolvedTx::deserialize(serialized_resolved_tx_from_typescript);

assert_eq(deserialized, resolved_tx);
}
}
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/contract_function_simulator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ export { NoteValidationRequest } from './noir-structs/note_validation_request.js
export type { PendingTaggedLog } from './noir-structs/pending_tagged_log.js';
export type { TxEffectData } from './noir-structs/tx_effect_data.js';
export type { ProvidedSecret } from './noir-structs/provided_secret.js';
export { ResolvedTx } from './noir-structs/resolved_tx.js';
export type { ResolvedTx } from './noir-structs/resolved_tx.js';
export { TransientArrayService } from './transient_array_service.js';

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,53 +1,19 @@
import { MAX_NOTE_HASHES_PER_TX } from '@aztec/constants';
import { padArrayEnd } from '@aztec/foundation/collection';
import { Fr } from '@aztec/foundation/curves/bn254';
import { TxHash } from '@aztec/stdlib/tx';
import type { Fr } from '@aztec/foundation/curves/bn254';
import type { TxHash } from '@aztec/stdlib/tx';

/**
* The resolved on-chain context of a transaction.
*
* Carries the note hashes and first nullifier needed to discover notes that originated from the transaction, plus the
* number and hash of the block in which it was mined.
*
* A TS version of the `ResolvedTx` struct in `oracle/tx_resolution.nr`.
* A TS version of the `ResolvedTx` struct in `oracle/tx_resolution.nr`; its wire layout lives in the `RESOLVED_TX`
* type mapping.
*/
export class ResolvedTx {
constructor(
public txHash: TxHash,
public uniqueNoteHashesInTx: Fr[],
public firstNullifierInTx: Fr,
public blockNumber: number,
public blockHash: Fr,
) {}

toFields(): Fr[] {
return [
this.txHash.hash,
...serializeBoundedVec(this.uniqueNoteHashesInTx, MAX_NOTE_HASHES_PER_TX),
this.firstNullifierInTx,
new Fr(this.blockNumber),
this.blockHash,
];
}

static empty(): ResolvedTx {
return new ResolvedTx(TxHash.zero(), [], Fr.ZERO, 0, Fr.ZERO);
}
}

/**
* Helper function to serialize a bounded vector according to Noir's BoundedVec format: the storage array padded to
* `maxLength`, followed by the actual length.
* @param values - The values to serialize
* @param maxLength - The maximum length of the bounded vector
* @returns The serialized bounded vector as Fr[]
*/
function serializeBoundedVec(values: Fr[], maxLength: number): Fr[] {
const storage = padArrayEnd(
values,
Fr.ZERO,
maxLength,
`Attempted to serialize ${values} values into a BoundedVec with max length ${maxLength}`,
);
return [...storage, new Fr(values.length)];
}
export type ResolvedTx = {
txHash: TxHash;
uniqueNoteHashesInTx: Fr[];
firstNullifierInTx: Fr;
blockNumber: number;
blockHash: Fr;
};
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,14 @@ describe('oracle type mappings', () => {
expect(EPHEMERAL_ARRAY(FIELD).label).toBe('ephemeral-array(field)');
});

it('renders struct fields in Noir snake_case', () => {
it('renders a struct namelessly, splicing nested structs into the parent', () => {
const inner = STRUCT([{ name: 'blockNumber', type: U32 }]);
const struct = STRUCT([
{ name: 'txHash', type: TX_HASH },
{ name: 'blockNumber', type: U32 },
{ name: 'origin', type: inner },
{ name: 'wrapped', type: OPTION(inner) },
]);
expect(struct.label).toBe('{tx_hash:field,block_number:u32}');
expect(struct.label).toBe('{field,u32,option({u32})}');
});
});
});
Expand Down
Loading
Loading