Skip to content
Closed
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
12 changes: 6 additions & 6 deletions yarn-project/aztec.js/src/contract/sent_tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ export class SentTx {
const tx = (await this.pxe.getTxEffect(txHash))!;
const visibleNotes = await this.pxe.getNotes({ txHash });
receipt.debugInfo = {
newNoteHashes: tx.newNoteHashes.filter(n => !n.isZero()),
newNullifiers: tx.newNullifiers.filter(n => !n.isZero()),
newPublicDataWrites: tx.newPublicDataWrites.filter(p => !p.isEmpty()),
newL2ToL1Msgs: tx.newL2ToL1Msgs.filter(l => !l.isZero()),
newContracts: tx.contractLeaves.filter(c => !c.isZero()),
newContractData: tx.contractData.filter(c => !c.isEmpty()),
noteHashes: tx.noteHashes.filter(n => !n.isZero()),
nullifiers: tx.nullifiers.filter(n => !n.isZero()),
publicDataWrites: tx.publicDataWrites.filter(p => !p.isEmpty()),
l2ToL1Msgs: tx.l2ToL1Msgs.filter(l => !l.isZero()),
contractsLeaves: tx.contractLeaves.filter(c => !c.isZero()),
contractData: tx.contractData.filter(c => !c.isEmpty()),
visibleNotes,
};
}
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuit-types/src/body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class Body {

get numberOfTxs() {
// We gather all the txEffects that are not empty (the ones that have been padded by checking the first newNullifier of the txEffect);
return this.txEffects.reduce((acc, txEffect) => (!txEffect.newNullifiers[0].equals(Fr.ZERO) ? acc + 1 : acc), 0);
return this.txEffects.reduce((acc, txEffect) => (!txEffect.nullifiers[0].equals(Fr.ZERO) ? acc + 1 : acc), 0);
}

static random(
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuit-types/src/l2_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export class L2Block {
this.assertIndexInRange(txIndex);

// Gets the first nullifier of the tx specified by txIndex
const firstNullifier = this.body.txEffects[txIndex].newNullifiers[0];
const firstNullifier = this.body.txEffects[txIndex].nullifiers[0];

return new TxHash(firstNullifier.toBuffer());
}
Expand Down
14 changes: 7 additions & 7 deletions yarn-project/circuit-types/src/tx/tx_receipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,27 @@ interface DebugInfo {
/**
* New note hashes created by the transaction.
*/
newNoteHashes: Fr[];
noteHashes: Fr[];
/**
* New nullifiers created by the transaction.
*/
newNullifiers: Fr[];
nullifiers: Fr[];
/**
* New public data writes created by the transaction.
*/
newPublicDataWrites: PublicDataWrite[];
publicDataWrites: PublicDataWrite[];
/**
* New L2 to L1 messages created by the transaction.
*/
newL2ToL1Msgs: Fr[];
l2ToL1Msgs: Fr[];
/**
* New contracts leafs created by the transaction to be inserted into the contract tree.
* New contracts leaves created by the transaction to be inserted into the contract tree.
*/
newContracts: Fr[];
contractsLeaves: Fr[];
/**
* New contract data created by the transaction.
*/
newContractData: ContractData[];
contractData: ContractData[];
/**
* Notes created in this tx which belong to accounts which are registered in the PXE which was used to submit the
* tx. You will not receive notes of accounts which are not registered in the PXE here even though they were
Expand Down
26 changes: 13 additions & 13 deletions yarn-project/circuit-types/src/tx_effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ export class TxEffect {
/**
* The note hashes to be inserted into the note hash tree.
*/
public newNoteHashes: Tuple<Fr, typeof MAX_NEW_NOTE_HASHES_PER_TX>,
public noteHashes: Tuple<Fr, typeof MAX_NEW_NOTE_HASHES_PER_TX>,
/**
* The nullifiers to be inserted into the nullifier tree.
*/
public newNullifiers: Tuple<Fr, typeof MAX_NEW_NULLIFIERS_PER_TX>,
public nullifiers: Tuple<Fr, typeof MAX_NEW_NULLIFIERS_PER_TX>,
/**
* The L2 to L1 messages to be inserted into the messagebox on L1.
*/
public newL2ToL1Msgs: Tuple<Fr, typeof MAX_NEW_L2_TO_L1_MSGS_PER_TX>,
public l2ToL1Msgs: Tuple<Fr, typeof MAX_NEW_L2_TO_L1_MSGS_PER_TX>,
/**
* The public data writes to be inserted into the public data tree.
*/
public newPublicDataWrites: Tuple<PublicDataWrite, typeof MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX>,
public publicDataWrites: Tuple<PublicDataWrite, typeof MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX>,
/**
* The leaves of the new contract data that will be inserted into the contracts tree.
*/
Expand All @@ -46,10 +46,10 @@ export class TxEffect {
) {}

toBuffer(): Buffer {
const nonZeroNoteHashes = this.newNoteHashes.filter(h => !h.isZero());
const nonZeroNullifiers = this.newNullifiers.filter(h => !h.isZero());
const nonZeroL2ToL1Msgs = this.newL2ToL1Msgs.filter(h => !h.isZero());
const nonZeroPublicDataWrites = this.newPublicDataWrites.filter(h => !h.isEmpty());
const nonZeroNoteHashes = this.noteHashes.filter(h => !h.isZero());
const nonZeroNullifiers = this.nullifiers.filter(h => !h.isZero());
const nonZeroL2ToL1Msgs = this.l2ToL1Msgs.filter(h => !h.isZero());
const nonZeroPublicDataWrites = this.publicDataWrites.filter(h => !h.isEmpty());
const nonZeroContractLeaves = this.contractLeaves.filter(h => !h.isZero());
const nonZeroContractData = this.contractData.filter(h => !h.isEmpty());

Expand Down Expand Up @@ -97,10 +97,10 @@ export class TxEffect {
}

hash() {
const noteHashesBuffer = Buffer.concat(this.newNoteHashes.map(x => x.toBuffer()));
const nullifiersBuffer = Buffer.concat(this.newNullifiers.map(x => x.toBuffer()));
const newL2ToL1MsgsBuffer = Buffer.concat(this.newL2ToL1Msgs.map(x => x.toBuffer()));
const publicDataUpdateRequestsBuffer = Buffer.concat(this.newPublicDataWrites.map(x => x.toBuffer()));
const noteHashesBuffer = Buffer.concat(this.noteHashes.map(x => x.toBuffer()));
const nullifiersBuffer = Buffer.concat(this.nullifiers.map(x => x.toBuffer()));
const newL2ToL1MsgsBuffer = Buffer.concat(this.l2ToL1Msgs.map(x => x.toBuffer()));
const publicDataUpdateRequestsBuffer = Buffer.concat(this.publicDataWrites.map(x => x.toBuffer()));
const encryptedLogsHashKernel0 = this.encryptedLogs.hash();
const unencryptedLogsHashKernel0 = this.unencryptedLogs.hash();

Expand Down Expand Up @@ -159,6 +159,6 @@ export class TxEffect {
}

get txHash(): TxHash {
return new TxHash(this.newNullifiers[0].toBuffer());
return new TxHash(this.nullifiers[0].toBuffer());
}
}
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_deploy_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ describe('e2e_deploy_contract', () => {
const contract = await registerContract(testWallet, TestContract);
const receipt = await contract.methods.emit_nullifier(10).send().wait({ debug: true });
const expected = siloNullifier(contract.address, new Fr(10));
expect(receipt.debugInfo?.newNullifiers[1]).toEqual(expected);
expect(receipt.debugInfo?.nullifiers[1]).toEqual(expected);
},
30_000,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('e2e_inclusion_proofs_contract', () => {
describe('proves note existence and its nullifier non-existence and nullifier non-existence failure case', () => {
// Owner of a note
let noteCreationBlockNumber: number;
let newNoteHashes, visibleNotes: any;
let noteHashes, visibleNotes: any;
const value = 100n;
let validNoteBlockNumber: any;

Expand All @@ -63,11 +63,11 @@ describe('e2e_inclusion_proofs_contract', () => {
const receipt = await contract.methods.create_note(owner, value).send().wait({ debug: true });

noteCreationBlockNumber = receipt.blockNumber!;
({ newNoteHashes, visibleNotes } = receipt.debugInfo!);
({ noteHashes, visibleNotes } = receipt.debugInfo!);
});

it('should return the correct values for creating a note', () => {
expect(newNoteHashes.length).toBe(1);
expect(noteHashes.length).toBe(1);
expect(visibleNotes.length).toBe(1);
const [receivedValue, receivedOwner, _randomness] = visibleNotes[0].note.items;
expect(receivedValue.toBigInt()).toBe(value);
Expand Down Expand Up @@ -158,7 +158,7 @@ describe('e2e_inclusion_proofs_contract', () => {
const receipt = await contract.methods.create_note(owner, value).send().wait({ debug: true });

noteCreationBlockNumber = receipt.blockNumber!;
const { newNoteHashes, visibleNotes } = receipt.debugInfo!;
const { noteHashes: newNoteHashes, visibleNotes } = receipt.debugInfo!;

expect(newNoteHashes.length).toBe(1);
expect(visibleNotes.length).toBe(1);
Expand Down Expand Up @@ -224,7 +224,7 @@ describe('e2e_inclusion_proofs_contract', () => {
// Choose random block number between deployment and current block number to test archival node
const blockNumber = await getRandomBlockNumberSinceDeployment();
const block = await pxe.getBlock(blockNumber);
const nullifier = block?.body.txEffects[0].newNullifiers[0];
const nullifier = block?.body.txEffects[0].nullifiers[0];

await contract.methods.test_nullifier_inclusion(nullifier!, true, blockNumber).send().wait();
await contract.methods.test_nullifier_inclusion(nullifier!, false, 0n).send().wait();
Expand Down
39 changes: 14 additions & 25 deletions yarn-project/end-to-end/src/e2e_non_contract_account.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
import {
AztecNode,
DebugLogger,
ExtendedNote,
Fr,
Note,
PXE,
SignerlessWallet,
TxStatus,
Wallet,
toBigInt,
} from '@aztec/aztec.js';
import { DebugLogger, ExtendedNote, Fr, Note, PXE, SignerlessWallet, Wallet, toBigInt } from '@aztec/aztec.js';
import { siloNullifier } from '@aztec/circuits.js/hash';
import { TestContract } from '@aztec/noir-contracts.js/Test';

import { setup } from './fixtures/utils.js';

describe('e2e_non_contract_account', () => {
let aztecNode: AztecNode | undefined;
let pxe: PXE;
let nonContractAccountWallet: Wallet;
let teardown: () => Promise<void>;
Expand All @@ -27,7 +15,7 @@ describe('e2e_non_contract_account', () => {
let wallet: Wallet;

beforeEach(async () => {
({ teardown, aztecNode, pxe, wallet, logger } = await setup(1));
({ teardown, pxe, wallet, logger } = await setup(1));
nonContractAccountWallet = new SignerlessWallet(pxe);

logger(`Deploying L2 contract...`);
Expand All @@ -42,12 +30,13 @@ describe('e2e_non_contract_account', () => {

// Send transaction as arbitrary non-contract account
const nullifier = new Fr(940);
const receipt = await contractWithNoContractWallet.methods.emit_nullifier(nullifier).send().wait({ interval: 0.1 });
expect(receipt.status).toBe(TxStatus.MINED);
const { debugInfo } = await contractWithNoContractWallet.methods
.emit_nullifier(nullifier)
.send()
.wait({ interval: 0.1, debug: true });

const tx = await aztecNode!.getTxEffect(receipt.txHash);
const expectedSiloedNullifier = siloNullifier(contract.address, nullifier);
const siloedNullifier = tx!.newNullifiers[1];
const siloedNullifier = debugInfo!.nullifiers[1];

expect(siloedNullifier.equals(expectedSiloedNullifier)).toBeTruthy();
}, 120_000);
Expand All @@ -57,8 +46,7 @@ describe('e2e_non_contract_account', () => {

// Send transaction as arbitrary non-contract account
const tx = contractWithNoContractWallet.methods.emit_msg_sender().send();
const receipt = await tx.wait({ interval: 0.1 });
expect(receipt.status).toBe(TxStatus.MINED);
await tx.wait({ interval: 0.1 });

const logs = (await tx.getUnencryptedLogs()).logs;
expect(logs.length).toBe(1);
Expand All @@ -73,12 +61,13 @@ describe('e2e_non_contract_account', () => {
it('can set and get a constant', async () => {
const value = 123n;

const receipt = await contract.methods.set_constant(value).send().wait({ interval: 0.1 });
const { txHash, debugInfo } = await contract.methods
.set_constant(value)
.send()
.wait({ interval: 0.1, debug: true });

// check that 1 note hash was created
const tx = await pxe.getTxEffect(receipt.txHash);
const nonZeroNoteHashes = tx?.newNoteHashes.filter(c => c.value > 0);
expect(nonZeroNoteHashes?.length).toBe(1);
expect(debugInfo!.noteHashes.length).toBe(1);

// Add the note
const note = new Note([new Fr(value)]);
Expand All @@ -91,7 +80,7 @@ describe('e2e_non_contract_account', () => {
contract.address,
storageSlot,
noteTypeId,
receipt.txHash,
txHash,
);
await wallet.addNote(extendedNote);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('e2e_pending_commitments_contract', () => {
const blockNum = await aztecNode!.getBlockNumber();
const block = (await aztecNode!.getBlocks(blockNum, 1))[0];

const commitmentsArray = block.body.txEffects.flatMap(txEffect => txEffect.newNoteHashes);
const commitmentsArray = block.body.txEffects.flatMap(txEffect => txEffect.noteHashes);

// all new commitments should be zero (should be squashed)
for (let c = 0; c < exceptFirstFew; c++) {
Expand All @@ -39,7 +39,7 @@ describe('e2e_pending_commitments_contract', () => {
const blockNum = await aztecNode!.getBlockNumber();
const block = (await aztecNode!.getBlocks(blockNum, 1))[0];

const nullifierArray = block.body.txEffects.flatMap(txEffect => txEffect.newNullifiers);
const nullifierArray = block.body.txEffects.flatMap(txEffect => txEffect.nullifiers);

// 0th nullifier should be nonzero (txHash), all others should be zero (should be squashed)
for (let n = 0; n < exceptFirstFew + 1; n++) {
Expand Down
44 changes: 23 additions & 21 deletions yarn-project/end-to-end/src/e2e_state_vars.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,10 @@ describe('e2e_state_vars', () => {
it('initialize PrivateMutable', async () => {
expect(await contract.methods.is_legendary_initialized().view()).toEqual(false);
// Send the transaction and wait for it to be mined (wait function throws if the tx is not mined)
const receipt = await contract.methods.initialize_private(RANDOMNESS, POINTS).send().wait();
const { debugInfo } = await contract.methods.initialize_private(RANDOMNESS, POINTS).send().wait({ debug: true });

const tx = await wallet.getTxEffect(receipt.txHash);
expect(tx?.newNoteHashes.length).toEqual(1);
// 1 for the tx, another for the initializer
expect(tx?.newNullifiers.length).toEqual(2);
expect(debugInfo!.nullifiers.length).toEqual(2);
expect(await contract.methods.is_legendary_initialized().view()).toEqual(true);
});

Expand All @@ -97,12 +95,14 @@ describe('e2e_state_vars', () => {
it('replace with same value', async () => {
expect(await contract.methods.is_legendary_initialized().view()).toEqual(true);
const noteBefore = await contract.methods.get_legendary_card().view();
const receipt = await contract.methods.update_legendary_card(RANDOMNESS, POINTS).send().wait();
const { debugInfo } = await contract.methods
.update_legendary_card(RANDOMNESS, POINTS)
.send()
.wait({ debug: true });

const tx = await wallet.getTxEffect(receipt.txHash);
expect(tx?.newNoteHashes.length).toEqual(1);
expect(debugInfo!.noteHashes.length).toEqual(1);
// 1 for the tx, another for the nullifier of the previous note
expect(tx?.newNullifiers.length).toEqual(2);
expect(debugInfo!.nullifiers.length).toEqual(2);

const noteAfter = await contract.methods.get_legendary_card().view();

Expand All @@ -118,14 +118,14 @@ describe('e2e_state_vars', () => {

it('replace PrivateMutable with other values', async () => {
expect(await contract.methods.is_legendary_initialized().view()).toEqual(true);
const receipt = await contract.methods
const { debugInfo } = await contract.methods
.update_legendary_card(RANDOMNESS + 2n, POINTS + 1n)
.send()
.wait();
const tx = await wallet.getTxEffect(receipt.txHash);
expect(tx?.newNoteHashes.length).toEqual(1);
.wait({ debug: true });

expect(debugInfo!.noteHashes.length).toEqual(1);
// 1 for the tx, another for the nullifier of the previous note
expect(tx?.newNullifiers.length).toEqual(2);
expect(debugInfo!.nullifiers.length).toEqual(2);

const { points, randomness } = await contract.methods.get_legendary_card().view();
expect(points).toEqual(POINTS + 1n);
Expand All @@ -135,11 +135,11 @@ describe('e2e_state_vars', () => {
it('replace PrivateMutable dependent on prior value', async () => {
expect(await contract.methods.is_legendary_initialized().view()).toEqual(true);
const noteBefore = await contract.methods.get_legendary_card().view();
const receipt = await contract.methods.increase_legendary_points().send().wait();
const tx = await wallet.getTxEffect(receipt.txHash);
expect(tx?.newNoteHashes.length).toEqual(1);
const { debugInfo } = await contract.methods.increase_legendary_points().send().wait({ debug: true });

expect(debugInfo!.noteHashes.length).toEqual(1);
// 1 for the tx, another for the nullifier of the previous note
expect(tx?.newNullifiers.length).toEqual(2);
expect(debugInfo!.nullifiers.length).toEqual(2);

const { points, randomness } = await contract.methods.get_legendary_card().view();
expect(points).toEqual(noteBefore.points + 1n);
Expand All @@ -155,12 +155,14 @@ describe('e2e_state_vars', () => {

it('initialize PrivateImmutable', async () => {
expect(await contract.methods.is_priv_imm_initialized().view()).toEqual(false);
const receipt = await contract.methods.initialize_private_immutable(RANDOMNESS, POINTS).send().wait();
const { debugInfo } = await contract.methods
.initialize_private_immutable(RANDOMNESS, POINTS)
.send()
.wait({ debug: true });

const tx = await wallet.getTxEffect(receipt.txHash);
expect(tx?.newNoteHashes.length).toEqual(1);
expect(debugInfo!.noteHashes.length).toEqual(1);
// 1 for the tx, another for the initializer
expect(tx?.newNullifiers.length).toEqual(2);
expect(debugInfo!.nullifiers.length).toEqual(2);
expect(await contract.methods.is_priv_imm_initialized().view()).toEqual(true);
});

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/integration_l1_publisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ describe('L1Publisher integration', () => {
messages: {
l1ToL2Messages: l1ToL2Messages.map(m => `0x${m.toBuffer().toString('hex').padStart(64, '0')}`),
l2ToL1Messages: block.body.txEffects
.flatMap(txEffect => txEffect.newL2ToL1Msgs)
.flatMap(txEffect => txEffect.l2ToL1Msgs)
.map(m => `0x${m.toBuffer().toString('hex').padStart(64, '0')}`),
},
block: {
Expand Down Expand Up @@ -415,7 +415,7 @@ describe('L1Publisher integration', () => {
expect(await inbox.read.contains([l1ToL2Messages[j].toString()])).toBeTruthy();
}

const newL2ToL1MsgsArray = block.body.txEffects.flatMap(txEffect => txEffect.newL2ToL1Msgs);
const newL2ToL1MsgsArray = block.body.txEffects.flatMap(txEffect => txEffect.l2ToL1Msgs);

// check that values are not in the outbox
for (let j = 0; j < newL2ToL1MsgsArray.length; j++) {
Expand Down
Loading