Skip to content

Commit 87f3d7e

Browse files
author
AztecBot
committed
Merge branch 'next' into merge-train/barretenberg
2 parents d401c05 + d7ec707 commit 87f3d7e

File tree

18 files changed

+218
-158
lines changed

18 files changed

+218
-158
lines changed

docs/docs-developers/docs/resources/migration_notes.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ These methods were not used by PXE and returned a subset of the information alre
2424
|----------------|-------------|
2525
| `getNullifierSiblingPath` | `getNullifierMembershipWitness` |
2626
| `getNoteHashSiblingPath` | `getNoteHashMembershipWitness` |
27-
| `getArchiveSiblingPath` | `getArchiveMembershipWitness` |
27+
| `getArchiveSiblingPath` | `getBlockHashMembershipWitness` |
2828
| `getPublicDataSiblingPath` | `getPublicDataWitness` |
2929

3030
The membership witness methods return both the sibling path and additional context (leaf index, preimage data) needed for proofs.
@@ -56,6 +56,29 @@ The nullifier secret key (`nsk_m` / `nsk_app`) has been renamed to nullifier hid
5656

5757
The `GeneratorIndex.NSK_M` enum member is now `GeneratorIndex.NHK_M`.
5858

59+
### [AztecNode/Aztec.nr] `getArchiveMembershipWitness` renamed to `getBlockHashMembershipWitness`
60+
61+
The `getArchiveMembershipWitness` method has been renamed to `getBlockHashMembershipWitness` to better reflect its purpose. Block hashes are the leaves of the archive tree - each time a new block is added to the chain, its block hash is appended as a new leaf. This rename clarifies that the method finds a membership witness for a block hash in the archive tree.
62+
63+
**TypeScript (AztecNode interface):**
64+
65+
```diff
66+
- const witness = await aztecNode.getArchiveMembershipWitness(blockNumber, archiveLeaf);
67+
+ const witness = await aztecNode.getBlockHashMembershipWitness(blockNumber, blockHash);
68+
```
69+
70+
The second parameter type has also changed from `Fr` to `BlockHash`.
71+
72+
**Noir (aztec-nr):**
73+
74+
```diff
75+
- use dep::aztec::oracle::get_membership_witness::get_archive_membership_witness;
76+
+ use dep::aztec::oracle::get_membership_witness::get_block_hash_membership_witness;
77+
78+
- let witness = get_archive_membership_witness(block_header, leaf_value);
79+
+ let witness = get_block_hash_membership_witness(anchor_block_header, block_hash);
80+
```
81+
5982
### [Aztec.nr] `protocol_types` renamed to `protocol`
6083

6184
The `protocol_types` re-export from the `aztec` crate has been renamed to `protocol`. Update all imports accordingly:

docs/docs-network/operators/reference/node-api-reference.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,14 @@ curl -X POST http://localhost:8080 \
475475
-d '{"jsonrpc":"2.0","method":"node_getPublicDataWitness","params":[12345,"0x0000..."],"id":1}'
476476
```
477477

478-
### node_getArchiveMembershipWitness
478+
### node_getBlockHashMembershipWitness
479479

480-
Gets archive tree membership witness.
480+
Gets a membership witness for a block hash in the archive tree. Block hashes are the leaves of the archive tree - each time a new block is added to the chain, its block hash is appended as a new leaf.
481481

482482
**Parameters**:
483483

484-
1. `blockNumber` - `number | "latest"` - Block number
485-
2. `archive` - `string` - Archive leaf value (32-byte hex)
484+
1. `block` - `number | "latest"` - Block number at which to query the archive tree
485+
2. `blockHash` - `string` - Block hash to find in the archive tree (32-byte hex)
486486

487487
**Returns**: `MembershipWitness | null`
488488

@@ -491,7 +491,7 @@ Gets archive tree membership witness.
491491
```bash
492492
curl -X POST http://localhost:8080 \
493493
-H 'Content-Type: application/json' \
494-
-d '{"jsonrpc":"2.0","method":"node_getArchiveMembershipWitness","params":[12345,"0x1234..."],"id":1}'
494+
-d '{"jsonrpc":"2.0","method":"node_getBlockHashMembershipWitness","params":[12345,"0x1234..."],"id":1}'
495495
```
496496

497497
### node_getNoteHashMembershipWitness

noir-projects/aztec-nr/aztec/src/oracle/block_header.nr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::protocol::{abis::block_header::BlockHeader, merkle_tree::root::root_from_sibling_path, traits::Hash};
22

3-
use crate::{context::PrivateContext, oracle::get_membership_witness::get_archive_membership_witness};
3+
use crate::{context::PrivateContext, oracle::get_membership_witness::get_block_hash_membership_witness};
44

55
#[oracle(utilityGetBlockHeader)]
66
unconstrained fn get_block_header_at_oracle(_block_number: u32) -> BlockHeader {}
@@ -56,7 +56,7 @@ fn constrain_get_block_header_at_internal(
5656

5757
// 2) Get the membership witness of the block in the archive tree.
5858
// Safety: The witness is only used as a "magical value" that makes the merkle proof below pass. Hence it's safe.
59-
let witness = unsafe { get_archive_membership_witness(anchor_block_header, block_hash) };
59+
let witness = unsafe { get_block_hash_membership_witness(anchor_block_header, block_hash) };
6060

6161
// 3) Check that the block is in the archive (i.e. the witness is valid)
6262
assert_eq(

noir-projects/aztec-nr/aztec/src/oracle/get_membership_witness.nr

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,36 @@ pub struct MembershipWitness<let N: u32, let M: u32> {
1919

2020
#[oracle(utilityGetNoteHashMembershipWitness)]
2121
unconstrained fn get_note_hash_membership_witness_oracle(
22-
block_hash: Field,
23-
leaf_value: Field,
22+
anchor_block_hash: Field,
23+
note_hash: Field,
2424
) -> MembershipWitness<NOTE_HASH_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT + 1> {}
2525

26-
#[oracle(utilityGetArchiveMembershipWitness)]
27-
unconstrained fn get_archive_membership_witness_oracle(
26+
#[oracle(utilityGetBlockHashMembershipWitness)]
27+
unconstrained fn get_block_hash_membership_witness_oracle(
28+
anchor_block_hash: Field,
2829
block_hash: Field,
29-
leaf_value: Field,
3030
) -> MembershipWitness<ARCHIVE_HEIGHT, ARCHIVE_HEIGHT + 1> {}
3131

3232
// Note: get_nullifier_membership_witness function is implemented in get_nullifier_membership_witness.nr
3333

34+
/// Returns a membership witness for a `note_hash` in the note hash tree whose root is defined in
35+
// `anchor_block_header`.
3436
pub unconstrained fn get_note_hash_membership_witness(
35-
block_header: BlockHeader,
36-
leaf_value: Field,
37+
anchor_block_header: BlockHeader,
38+
note_hash: Field,
3739
) -> MembershipWitness<NOTE_HASH_TREE_HEIGHT, NOTE_HASH_TREE_HEIGHT + 1> {
38-
let block_hash = block_header.hash();
39-
get_note_hash_membership_witness_oracle(block_hash, leaf_value)
40+
let anchor_block_hash = anchor_block_header.hash();
41+
get_note_hash_membership_witness_oracle(anchor_block_hash, note_hash)
4042
}
4143

4244
// There is no `get_public_data_membership_witness` function because it doesn't make sense to be getting a membership
4345
// witness for a value in the public data tree.
4446

45-
pub unconstrained fn get_archive_membership_witness(
46-
block_header: BlockHeader,
47-
leaf_value: Field,
47+
/// Returns a membership witness for a `block_hash` in the archive tree whose root is defined in `anchor_block_header`.
48+
pub unconstrained fn get_block_hash_membership_witness(
49+
anchor_block_header: BlockHeader,
50+
block_hash: Field,
4851
) -> MembershipWitness<ARCHIVE_HEIGHT, ARCHIVE_HEIGHT + 1> {
49-
let block_hash = block_header.hash();
50-
get_archive_membership_witness_oracle(block_hash, leaf_value)
52+
let anchor_block_hash = anchor_block_header.hash();
53+
get_block_hash_membership_witness_oracle(anchor_block_hash, block_hash)
5154
}

noir-projects/aztec-nr/aztec/src/oracle/version.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
///
55
/// @dev Whenever a contract function or Noir test is run, the `utilityAssertCompatibleOracleVersion` oracle is called
66
/// and if the oracle version is incompatible an error is thrown.
7-
pub global ORACLE_VERSION: Field = 9;
7+
pub global ORACLE_VERSION: Field = 10;
88

99
/// Asserts that the version of the oracle is compatible with the version expected by the contract.
1010
pub fn assert_compatible_oracle_version() {

noir-projects/noir-contracts/bootstrap.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ function get_contract_hash {
126126
../../barretenberg/cpp/.rebuild_patterns \
127127
../../barretenberg/ts/.rebuild_patterns \
128128
"^noir-projects/noir-contracts/contracts/$contract_path/" \
129+
"^noir-projects/noir-contracts/contracts/protocol/aztec_sublib/" \
129130
"^noir-projects/aztec-nr/" \
130131
"^noir-projects/noir-protocol-circuits/crates/types/")
131132
fi

noir-projects/noir-contracts/contracts/protocol/aztec_sublib/Nargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ name = "aztec_sublib"
33
type = "lib"
44

55
[dependencies]
6+
aztec = { path = "../../../../aztec-nr/aztec" }
67
protocol_types = { path = "../../../../noir-protocol-circuits/crates/types" }

noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/oracle/mod.nr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Oracle modules for protocol contracts.
22

33
pub mod avm;
4-
pub mod version;
54
pub mod execution_cache;
65
pub mod capsules;
76
pub mod storage;
@@ -15,3 +14,6 @@ pub mod logs;
1514
// debug_log oracle is used by both noir-protocol-circuits and this crate and for this reason we just re-export it
1615
// here from protocol_types.
1716
pub use protocol_types::debug_log;
17+
18+
// version oracle is defined in aztec-nr and re-exported here as re-defining versions is not practical.
19+
pub use aztec::oracle::version;

noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/oracle/version.nr

Lines changed: 0 additions & 23 deletions
This file was deleted.

yarn-project/aztec-node/src/aztec-node/server.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -851,11 +851,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
851851
}
852852

853853
public async findLeavesIndexes(
854-
block: BlockParameter,
854+
referenceBlock: BlockParameter,
855855
treeId: MerkleTreeId,
856856
leafValues: Fr[],
857857
): Promise<(DataInBlock<bigint> | undefined)[]> {
858-
const committedDb = await this.#getWorldState(block);
858+
const committedDb = await this.#getWorldState(referenceBlock);
859859
const maybeIndices = await committedDb.findLeafIndices(
860860
treeId,
861861
leafValues.map(x => x.toBuffer()),
@@ -913,22 +913,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
913913
});
914914
}
915915

916-
public async getArchiveMembershipWitness(
917-
block: BlockParameter,
918-
archive: Fr,
916+
public async getBlockHashMembershipWitness(
917+
referenceBlock: BlockParameter,
918+
blockHash: BlockHash,
919919
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
920-
const committedDb = await this.#getWorldState(block);
921-
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [archive]);
920+
const committedDb = await this.#getWorldState(referenceBlock);
921+
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
922922
return pathAndIndex === undefined
923923
? undefined
924924
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
925925
}
926926

927927
public async getNoteHashMembershipWitness(
928-
block: BlockParameter,
928+
referenceBlock: BlockParameter,
929929
noteHash: Fr,
930930
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
931-
const committedDb = await this.#getWorldState(block);
931+
const committedDb = await this.#getWorldState(referenceBlock);
932932
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
933933
MerkleTreeId.NOTE_HASH_TREE,
934934
[noteHash],
@@ -939,10 +939,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
939939
}
940940

941941
public async getL1ToL2MessageMembershipWitness(
942-
block: BlockParameter,
942+
referenceBlock: BlockParameter,
943943
l1ToL2Message: Fr,
944944
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
945-
const db = await this.#getWorldState(block);
945+
const db = await this.#getWorldState(referenceBlock);
946946
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
947947
if (!witness) {
948948
return undefined;
@@ -996,10 +996,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
996996
}
997997

998998
public async getNullifierMembershipWitness(
999-
block: BlockParameter,
999+
referenceBlock: BlockParameter,
10001000
nullifier: Fr,
10011001
): Promise<NullifierMembershipWitness | undefined> {
1002-
const db = await this.#getWorldState(block);
1002+
const db = await this.#getWorldState(referenceBlock);
10031003
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
10041004
if (!witness) {
10051005
return undefined;
@@ -1016,7 +1016,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
10161016

10171017
/**
10181018
* Returns a low nullifier membership witness for a given nullifier at a given block.
1019-
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
1019+
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
1020+
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
10201021
* @param nullifier - Nullifier we try to find the low nullifier witness for.
10211022
* @returns The low nullifier membership witness (if found).
10221023
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
@@ -1029,10 +1030,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
10291030
* TODO: This is a confusing behavior and we should eventually address that.
10301031
*/
10311032
public async getLowNullifierMembershipWitness(
1032-
block: BlockParameter,
1033+
referenceBlock: BlockParameter,
10331034
nullifier: Fr,
10341035
): Promise<NullifierMembershipWitness | undefined> {
1035-
const committedDb = await this.#getWorldState(block);
1036+
const committedDb = await this.#getWorldState(referenceBlock);
10361037
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
10371038
if (!findResult) {
10381039
return undefined;
@@ -1047,8 +1048,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
10471048
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
10481049
}
10491050

1050-
async getPublicDataWitness(block: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1051-
const committedDb = await this.#getWorldState(block);
1051+
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1052+
const committedDb = await this.#getWorldState(referenceBlock);
10521053
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
10531054
if (!lowLeafResult) {
10541055
return undefined;
@@ -1062,8 +1063,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
10621063
}
10631064
}
10641065

1065-
public async getPublicStorageAt(block: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1066-
const committedDb = await this.#getWorldState(block);
1066+
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1067+
const committedDb = await this.#getWorldState(referenceBlock);
10671068
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
10681069

10691070
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());

0 commit comments

Comments
 (0)