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
Original file line number Diff line number Diff line change
Expand Up @@ -867,17 +867,17 @@ void ContentAddressedCachedTreeStore<LeafValueType>::advance_finalized_block(con
ReadTransactionPtr readTx = create_read_transaction();
get_meta(uncommittedMeta);
get_meta(committedMeta, *readTx, false);
// do nothing if the block is already finalized
if (committedMeta.finalizedBlockHeight >= blockNumber) {
return;
}
if (!dataStore_->read_block_data(blockNumber, blockPayload, *readTx)) {
throw std::runtime_error(format("Unable to advance finalized block: ",
blockNumber,
". Failed to read block data. Tree name: ",
forkConstantData_.name_));
}
}
// do nothing if the block is already finalized
if (committedMeta.finalizedBlockHeight >= blockNumber) {
return;
}

// can currently only finalize up to the unfinalized block height
if (committedMeta.finalizedBlockHeight > committedMeta.unfinalizedBlockHeight) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ impl PrivateContext {
/// network as a whole. For example, if a contract interaction sets include-by to some publicly-known value (e.g.
/// the time when a contract upgrades), then the wallet might wish to set an even lower one to avoid revealing that
/// this tx is interacting with said contract. Ideally, all wallets should standardize on an approach in order to
/// provide users with a large anonymity set -- although the exact approach
/// provide users with a large privacy set -- although the exact approach
/// will need to be discussed. Wallets that deviate from a standard might accidentally reveal which wallet each
/// transaction originates from.
///
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/history/nullifier.nr
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod test;
///
/// ## Cost
///
/// This function performs a full merkle tree inclusion proof, which is in the order of 4k gates.
/// This function performs a single merkle tree inclusion proof, which is in the order of 4k gates.
///
/// If you don't need to assert existence at a _specific_ past block, consider using
/// [`PrivateContext::assert_nullifier_exists`](crate::context::PrivateContext::assert_nullifier_exists) instead, which
Expand Down Expand Up @@ -82,7 +82,7 @@ pub fn assert_nullifier_existed_by(block_header: BlockHeader, siloed_nullifier:
///
/// ## Cost
///
/// This function performs a full merkle tree inclusion proof, which is in the order of 4k gates.
/// This function performs a single merkle tree inclusion proof, which is in the order of 4k gates.
pub fn assert_nullifier_did_not_exist_by(block_header: BlockHeader, siloed_nullifier: Field) {
// 1) Get the membership witness of a low nullifier of the nullifier.
// Safety: The witness is only used as a "magical value" that makes the proof below pass. Hence it's safe.
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/macros/notes.nr
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ pub comptime fn custom_note(s: TypeDefinition) -> Quoted {
}
}

/// Asserts that the given note implements the `Packable` trait.
/// Asserts that the given note implements the [`Packable`](crate::protocol::traits::Packable) trait.
///
/// We require that notes have the `Packable` trait implemented because it is used when emitting a note in a log or as
/// an offchain message.
Expand Down
102 changes: 99 additions & 3 deletions noir-projects/aztec-nr/aztec/src/oracle/block_header.nr
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,107 @@ fn constrain_get_block_header_at_internal(
}

mod test {
use crate::protocol::traits::Hash;
use crate::test::helpers::test_environment::TestEnvironment;
use super::{constrain_get_block_header_at_internal, get_block_header_at_internal};
use super::{constrain_get_block_header_at_internal, get_block_header_at, get_block_header_at_internal};

#[test(should_fail_with = "Proving membership of a block in archive failed")]
unconstrained fn fetching_header_with_mismatched_block_number_should_fail() {
#[test]
unconstrained fn fetching_earliest_block_header_succeeds() {
let env = TestEnvironment::new();

env.mine_block();
env.mine_block();
env.mine_block();
env.mine_block();

env.private_context(|context| {
let anchor_block_header = context.anchor_block_header;

let header = get_block_header_at_internal(1);
constrain_get_block_header_at_internal(header, 1, anchor_block_header);

assert_eq(header.block_number(), 1);
});
}

#[test]
unconstrained fn fetching_past_block_header_succeeds() {
let env = TestEnvironment::new();

env.mine_block();
env.mine_block();
env.mine_block();
env.mine_block();

env.private_context(|context| {
let anchor_block_header = context.anchor_block_header;
let target_block_number = anchor_block_header.block_number() - 2;

let header = get_block_header_at_internal(target_block_number);
constrain_get_block_header_at_internal(header, target_block_number, anchor_block_header);

assert_eq(header.block_number(), target_block_number);
});
}

#[test]
unconstrained fn fetching_header_immediately_before_anchor_succeeds() {
let env = TestEnvironment::new();

env.mine_block();
env.mine_block();
env.mine_block();
env.mine_block();

// Block N-1 is the boundary case: last_archive covers exactly up to block N-1.
env.private_context(|context| {
let anchor_block_header = context.anchor_block_header;
let target_block_number = anchor_block_header.block_number() - 1;

let header = get_block_header_at_internal(target_block_number);
constrain_get_block_header_at_internal(header, target_block_number, anchor_block_header);

assert_eq(header.block_number(), target_block_number);
});
}

#[test]
unconstrained fn fetching_anchor_block_header_works() {
let env = TestEnvironment::new();

env.mine_block();
env.mine_block();
env.mine_block();
env.mine_block();

env.private_context(|context| {
let anchor_block_number = context.anchor_block_header.block_number();

let header = get_block_header_at(anchor_block_number, *context);

assert_eq(header.block_number(), anchor_block_number);
assert_eq(header.hash(), context.anchor_block_header.hash());
});
}

#[test(should_fail_with = "Last archive block number is smaller than the block number")]
unconstrained fn fetching_future_block_header_fails() {
let env = TestEnvironment::new();

env.mine_block();
env.mine_block();
env.mine_block();
env.mine_block();

env.private_context(|context| {
let anchor_block_number = context.anchor_block_header.block_number();

let _header = get_block_header_at(anchor_block_number + 1, *context);
});
}

#[test(should_fail_with = "Block number provided is not the same as the block number from the header hint")]
unconstrained fn fetching_header_with_mismatched_block_number_fails() {
let env = TestEnvironment::new();

env.mine_block();
Expand Down
Loading
Loading