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
23 changes: 21 additions & 2 deletions noir-projects/aztec-nr/aztec/src/ephemeral/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ impl<T> EphemeralArray<T> {
Self { slot }
}

/// Returns an empty ephemeral array at the given slot, clearing any pre-existing data.
pub unconstrained fn empty_at(slot: Field) -> Self {
Self::at(slot).clear()
}

/// Returns the number of elements stored in the array.
pub unconstrained fn len(self) -> u32 {
ephemeral::len_oracle(self.slot)
Expand Down Expand Up @@ -76,8 +81,9 @@ impl<T> EphemeralArray<T> {
ephemeral::remove_oracle(self.slot, index);
}

/// Removes all elements from the array and returns self for chaining (e.g. `EphemeralArray::at(slot).clear()`
/// to get a guaranteed-empty array at a given slot).
/// Removes all elements from the array and returns self for chaining.
///
/// Prefer [`EphemeralArray::empty_at`] when the intent is to start with a fresh array.
pub unconstrained fn clear(self) -> Self {
ephemeral::clear_oracle(self.slot);
self
Expand Down Expand Up @@ -362,6 +368,19 @@ mod test {
});
}

#[test]
unconstrained fn empty_at_wipes_previous_data() {
let env = TestEnvironment::new();
env.utility_context(|_| {
let array: EphemeralArray<Field> = EphemeralArray::at(SLOT);
array.push(1);
assert_eq(array.len(), 1);

let fresh: EphemeralArray<Field> = EphemeralArray::empty_at(SLOT);
assert_eq(fresh.len(), 0);
});
}

#[test]
unconstrained fn clear_returns_self() {
let env = TestEnvironment::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub unconstrained fn do_sync_state(
// First we process all private logs, which can contain different kinds of messages e.g. private notes, partial
// notes, private events, etc.
// TODO(F-588): populate with tagging secrets for constrained delivery
let provided_secrets = EphemeralArray::<ProvidedSecret>::at(PROVIDED_SECRETS_ARRAY_BASE_SLOT).clear();
let provided_secrets = EphemeralArray::<ProvidedSecret>::empty_at(PROVIDED_SECRETS_ARRAY_BASE_SLOT);
let logs = message_processing::get_pending_tagged_logs(scope, provided_secrets);
logs.for_each(|_i, pending_tagged_log: PendingTaggedLog| {
if pending_tagged_log.log.len() == 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ pub unconstrained fn sync_inbox(
scope: AztecAddress,
) -> EphemeralArray<OffchainMessageWithContext> {
let inbox: CapsuleArray<PendingOffchainMsg> = CapsuleArray::at(contract_address, OFFCHAIN_INBOX_SLOT, scope);
let context_resolution_requests: EphemeralArray<Field> = EphemeralArray::at(OFFCHAIN_CONTEXT_REQUESTS_SLOT).clear();
let context_resolution_requests: EphemeralArray<Field> = EphemeralArray::empty_at(OFFCHAIN_CONTEXT_REQUESTS_SLOT);
let ready_to_process: EphemeralArray<OffchainMessageWithContext> =
EphemeralArray::at(OFFCHAIN_READY_MESSAGES_SLOT).clear();
EphemeralArray::empty_at(OFFCHAIN_READY_MESSAGES_SLOT);

// Build a request list aligned with the inbox indices.
let mut i = 0;
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/shared_secret.nr
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub unconstrained fn get_shared_secrets<let N: u32>(
eph_pks: BoundedVec<EmbeddedCurvePoint, N>,
contract_address: AztecAddress,
) -> BoundedVec<Field, N> {
let request_array: EphemeralArray<EmbeddedCurvePoint> = EphemeralArray::at(GET_SHARED_SECRETS_REQUEST_SLOT).clear();
let request_array: EphemeralArray<EmbeddedCurvePoint> = EphemeralArray::empty_at(GET_SHARED_SECRETS_REQUEST_SLOT);
eph_pks.for_each(|pk| request_array.push(pk));

let response_array = get_shared_secrets_oracle(address, request_array, contract_address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ unconstrained fn get_handshake_logs_in_range(
from_block: Option<u32>,
to_block: Option<u32>,
) -> EphemeralArray<LogRetrievalResponse> {
let requests = EphemeralArray::at(LOG_RETRIEVAL_REQUEST_ARRAY_SLOT).clear();
let requests = EphemeralArray::empty_at(LOG_RETRIEVAL_REQUEST_ARRAY_SLOT);
requests.push(
LogRetrievalRequest {
contract_address,
Expand Down
Loading