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
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/history/note/test.nr
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ unconstrained fn succeeds_on_blocks_after_creation_and_before_nullification() {
});
}

#[test(should_fail_with = "Proving nullifier non-inclusion failed")]
#[test(should_fail_with = "Cannot prove nullifier non-inclusion")]
unconstrained fn fails_on_blocks_after_note_nullification() {
let (env, hinted_note) = test::create_note_and_nullify_it();

Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/history/nullifier/test.nr
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ unconstrained fn note_not_nullified_succeeds_in_blocks_before_note_nullification
);
}

#[test(should_fail_with = "Proving nullifier non-inclusion failed")]
#[test(should_fail_with = "Cannot prove nullifier non-inclusion")]
unconstrained fn note_not_nullified_fails_in_blocks_after_note_nullification_fails() {
let (env, hinted_note) = test::create_note_and_nullify_it();

Expand All @@ -100,7 +100,7 @@ unconstrained fn nullifier_non_inclusion_succeeds_in_blocks_before_nullifier_cre
});
}

#[test(should_fail_with = "Proving nullifier non-inclusion failed")]
#[test(should_fail_with = "Cannot prove nullifier non-inclusion")]
unconstrained fn nullifier_non_inclusion_fails_in_blocks_after_nullifier_creation() {
let env = TestEnvironment::new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ unconstrained fn assert_contract_was_initialized_by_before_initialization_fails(
);
}

#[test(should_fail_with = "Proving nullifier non-inclusion failed")]
#[test(should_fail_with = "Cannot prove nullifier non-inclusion")]
unconstrained fn assert_contract_bytecode_was_not_published_by_of_deployed_fails() {
let (env, contract_address, _owner) = setup();

Expand All @@ -119,7 +119,7 @@ unconstrained fn assert_contract_bytecode_was_not_published_by_of_deployed_fails
);
}

#[test(should_fail_with = "Proving nullifier non-inclusion failed")]
#[test(should_fail_with = "Cannot prove nullifier non-inclusion")]
unconstrained fn assert_contract_was_not_initialized_by_of_initialized_fails() {
let (env, contract_address, _owner) = setup();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ unconstrained fn packed_delayed_public_mutable_values_match_typescript() {
let pre_value = MockStruct { a: 1, b: 2 };
let post_value = MockStruct { a: 3, b: 4 };

let sdc = ScheduledDelayChange::<0u64>::new(Option::some(1), Option::some(50), 2);
let sdc = ScheduledDelayChange::<0_u64>::new(Option::some(1), Option::some(50), 2);
let svc = ScheduledValueChange::new(pre_value, post_value, 50);
let dpmv = DelayedPublicMutableValues::new(svc, sdc);

Expand Down
24 changes: 21 additions & 3 deletions yarn-project/archiver/src/store/kv_archiver_store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2997,6 +2997,24 @@ describe('KVArchiverDataStore', () => {
}
});

it('"tag" filter param is respected', async () => {
// Get a random tag from the logs
const targetBlockIndex = randomInt(numBlocksForPublicLogs);
const targetBlock = publishedCheckpoints[targetBlockIndex].checkpoint.blocks[0];
const targetTxIndex = randomInt(getTxsPerBlock(targetBlock));
const targetLogIndex = randomInt(getPublicLogsPerTx(targetBlock, targetTxIndex));
const targetTag = targetBlock.body.txEffects[targetTxIndex].publicLogs[targetLogIndex].fields[0];

const response = await store.getPublicLogs({ tag: targetTag });

expect(response.maxLogsHit).toBeFalsy();
expect(response.logs.length).toBeGreaterThan(0);

for (const extendedLog of response.logs) {
expect(extendedLog.log.fields[0].equals(targetTag)).toBeTruthy();
}
});

it('"afterLog" filter param is respected', async () => {
// Get a random log as reference
const targetBlockIndex = randomInt(numBlocksForPublicLogs);
Expand Down Expand Up @@ -3032,13 +3050,13 @@ describe('KVArchiverDataStore', () => {
}
});

it('"txHash" filter param is ignored when "afterLog" is set', async () => {
// Get random txHash
it('"txHash" filter param is respected when "afterLog" is set', async () => {
// A random txHash should match nothing, even with afterLog set
const txHash = TxHash.random();
const afterLog = new LogId(BlockNumber(1), BlockHash.random(), TxHash.random(), 0, 0);

const response = await store.getPublicLogs({ txHash, afterLog });
expect(response.logs.length).toBeGreaterThan(1);
expect(response.logs.length).toBe(0);
});

it('intersecting works', async () => {
Expand Down
25 changes: 24 additions & 1 deletion yarn-project/archiver/src/store/log_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,24 @@ export class LogStore {
txLogs: PublicLog[],
filter: LogFilter = {},
): boolean {
if (filter.fromBlock && blockNumber < filter.fromBlock) {
return false;
}
if (filter.toBlock && blockNumber >= filter.toBlock) {
return false;
}
if (filter.txHash && !txHash.equals(filter.txHash)) {
return false;
}

let maxLogsHit = false;
let logIndex = typeof filter.afterLog?.logIndex === 'number' ? filter.afterLog.logIndex + 1 : 0;
for (; logIndex < txLogs.length; logIndex++) {
const log = txLogs[logIndex];
if (!filter.contractAddress || log.contractAddress.equals(filter.contractAddress)) {
if (
(!filter.contractAddress || log.contractAddress.equals(filter.contractAddress)) &&
(!filter.tag || log.fields[0]?.equals(filter.tag))
) {
results.push(
new ExtendedPublicLog(new LogId(BlockNumber(blockNumber), blockHash, txHash, txIndex, logIndex), log),
);
Expand All @@ -661,6 +674,16 @@ export class LogStore {
txLogs: ContractClassLog[],
filter: LogFilter = {},
): boolean {
if (filter.fromBlock && blockNumber < filter.fromBlock) {
return false;
}
if (filter.toBlock && blockNumber >= filter.toBlock) {
return false;
}
if (filter.txHash && !txHash.equals(filter.txHash)) {
return false;
}

let maxLogsHit = false;
let logIndex = typeof filter.afterLog?.logIndex === 'number' ? filter.afterLog.logIndex + 1 : 0;
for (; logIndex < txLogs.length; logIndex++) {
Expand Down
27 changes: 27 additions & 0 deletions yarn-project/aztec-node/src/aztec-node/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,33 @@ describe('aztec node', () => {
});
});

describe('getLowNullifierMembershipWitness', () => {
beforeEach(() => {
lastBlockNumber = BlockNumber(1);
});

it('throws when nullifier already exists in the tree', async () => {
const nullifier = Fr.random();
merkleTreeOps.getPreviousValueIndex.mockImplementation((treeId: MerkleTreeId, value: bigint) => {
if (treeId === MerkleTreeId.NULLIFIER_TREE && value === nullifier.toBigInt()) {
return Promise.resolve({ index: 42n, alreadyPresent: true });
}
return Promise.resolve(undefined);
});

await expect(node.getLowNullifierMembershipWitness('latest', nullifier)).rejects.toThrow(
/Cannot prove nullifier non-inclusion/,
);
});

it('returns undefined when nullifier not found', async () => {
merkleTreeOps.getPreviousValueIndex.mockResolvedValue(undefined);

const result = await node.getLowNullifierMembershipWitness('latest', Fr.random());
expect(result).toBeUndefined();
});
});

describe('findLeavesIndexes', () => {
const blockHash1 = Fr.random();
const blockHash2 = Fr.random();
Expand Down
19 changes: 3 additions & 16 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1131,21 +1131,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
}

/**
* Returns a low nullifier membership witness for a given nullifier at a given block.
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
* @param nullifier - Nullifier we try to find the low nullifier witness for.
* @returns The low nullifier membership witness (if found).
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
* we are trying to prove non-inclusion for.
*
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
* index of the nullifier itself when it already exists in the tree.
* TODO: This is a confusing behavior and we should eventually address that.
*/
public async getLowNullifierMembershipWitness(
referenceBlock: BlockParameter,
nullifier: Fr,
Expand All @@ -1157,7 +1142,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
}
const { index, alreadyPresent } = findResult;
if (alreadyPresent) {
this.log.warn(`Nullifier ${nullifier.toBigInt()} already exists in the tree`);
throw new Error(
`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
);
}
const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
MAX_NULLIFIERS_PER_TX,
MAX_NULLIFIER_READ_REQUESTS_PER_TX,
MAX_PRIVATE_LOGS_PER_TX,
MAX_TX_LIFETIME,
PRIVATE_TX_L2_GAS_OVERHEAD,
PUBLIC_TX_L2_GAS_OVERHEAD,
TX_DA_GAS_OVERHEAD,
Expand Down Expand Up @@ -442,12 +443,23 @@ export async function generateSimulatedProvingResult(

let publicTeardownCallRequest;

// We set expiration timestamp to anchor_block_timestamp + MAX_TX_LIFETIME (24h) just like kernels do
let expirationTimestamp =
privateExecutionResult.entrypoint.publicInputs.anchorBlockHeader.globalVariables.timestamp +
BigInt(MAX_TX_LIFETIME);

const executions = [privateExecutionResult.entrypoint];

while (executions.length !== 0) {
const execution = executions.shift()!;
executions.unshift(...execution!.nestedExecutionResults);

// Just like kernels we overwrite the default value if the call sets it.
const callExpirationTimestamp = execution.publicInputs.expirationTimestamp;
if (callExpirationTimestamp !== 0n && callExpirationTimestamp < expirationTimestamp) {
expirationTimestamp = callExpirationTimestamp;
}

const { contractAddress } = execution.publicInputs.callContext;

scopedNoteHashes.push(
Expand Down Expand Up @@ -671,7 +683,7 @@ export async function generateSimulatedProvingResult(
}),
),
/*feePayer=*/ AztecAddress.zero(),
/*expirationTimestamp=*/ 0n,
/*expirationTimestamp=*/ expirationTimestamp,
hasPublicCalls ? inputsForPublic : undefined,
!hasPublicCalls ? inputsForRollup : undefined,
);
Expand Down
Loading
Loading