Skip to content

Commit 4adc0f8

Browse files
authored
feat: merge-train/fairies (#23844)
See [merge-train-readme.md](https://github.com/AztecProtocol/aztec-packages/blob/next/.github/workflows/merge-train-readme.md). This is a merge-train.
2 parents 8500d6a + 44b8827 commit 4adc0f8

5 files changed

Lines changed: 26 additions & 7 deletions

File tree

noir-projects/aztec-nr/aztec/src/ephemeral/mod.nr

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ impl<T> EphemeralArray<T> {
3030
Self { slot }
3131
}
3232

33+
/// Returns an empty ephemeral array at the given slot, clearing any pre-existing data.
34+
pub unconstrained fn empty_at(slot: Field) -> Self {
35+
Self::at(slot).clear()
36+
}
37+
3338
/// Returns the number of elements stored in the array.
3439
pub unconstrained fn len(self) -> u32 {
3540
ephemeral::len_oracle(self.slot)
@@ -76,8 +81,9 @@ impl<T> EphemeralArray<T> {
7681
ephemeral::remove_oracle(self.slot, index);
7782
}
7883

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

371+
#[test]
372+
unconstrained fn empty_at_wipes_previous_data() {
373+
let env = TestEnvironment::new();
374+
env.utility_context(|_| {
375+
let array: EphemeralArray<Field> = EphemeralArray::at(SLOT);
376+
array.push(1);
377+
assert_eq(array.len(), 1);
378+
379+
let fresh: EphemeralArray<Field> = EphemeralArray::empty_at(SLOT);
380+
assert_eq(fresh.len(), 0);
381+
});
382+
}
383+
365384
#[test]
366385
unconstrained fn clear_returns_self() {
367386
let env = TestEnvironment::new();

noir-projects/aztec-nr/aztec/src/messages/discovery/mod.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub unconstrained fn do_sync_state(
146146
// First we process all private logs, which can contain different kinds of messages e.g. private notes, partial
147147
// notes, private events, etc.
148148
// TODO(F-588): populate with tagging secrets for constrained delivery
149-
let provided_secrets = EphemeralArray::<ProvidedSecret>::at(PROVIDED_SECRETS_ARRAY_BASE_SLOT).clear();
149+
let provided_secrets = EphemeralArray::<ProvidedSecret>::empty_at(PROVIDED_SECRETS_ARRAY_BASE_SLOT);
150150
let logs = message_processing::get_pending_tagged_logs(scope, provided_secrets);
151151
logs.for_each(|_i, pending_tagged_log: PendingTaggedLog| {
152152
if pending_tagged_log.log.len() == 0 {

noir-projects/aztec-nr/aztec/src/messages/processing/offchain.nr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ pub unconstrained fn sync_inbox(
141141
scope: AztecAddress,
142142
) -> EphemeralArray<OffchainMessageWithContext> {
143143
let inbox: CapsuleArray<PendingOffchainMsg> = CapsuleArray::at(contract_address, OFFCHAIN_INBOX_SLOT, scope);
144-
let context_resolution_requests: EphemeralArray<Field> = EphemeralArray::at(OFFCHAIN_CONTEXT_REQUESTS_SLOT).clear();
144+
let context_resolution_requests: EphemeralArray<Field> = EphemeralArray::empty_at(OFFCHAIN_CONTEXT_REQUESTS_SLOT);
145145
let ready_to_process: EphemeralArray<OffchainMessageWithContext> =
146-
EphemeralArray::at(OFFCHAIN_READY_MESSAGES_SLOT).clear();
146+
EphemeralArray::empty_at(OFFCHAIN_READY_MESSAGES_SLOT);
147147

148148
// Build a request list aligned with the inbox indices.
149149
let mut i = 0;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub unconstrained fn get_shared_secrets<let N: u32>(
4343
eph_pks: BoundedVec<EmbeddedCurvePoint, N>,
4444
contract_address: AztecAddress,
4545
) -> BoundedVec<Field, N> {
46-
let request_array: EphemeralArray<EmbeddedCurvePoint> = EphemeralArray::at(GET_SHARED_SECRETS_REQUEST_SLOT).clear();
46+
let request_array: EphemeralArray<EmbeddedCurvePoint> = EphemeralArray::empty_at(GET_SHARED_SECRETS_REQUEST_SLOT);
4747
eph_pks.for_each(|pk| request_array.push(pk));
4848

4949
let response_array = get_shared_secrets_oracle(address, request_array, contract_address);

noir-projects/noir-contracts/contracts/standard/handshake_registry_contract/src/sync.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ unconstrained fn get_handshake_logs_in_range(
109109
from_block: Option<u32>,
110110
to_block: Option<u32>,
111111
) -> EphemeralArray<LogRetrievalResponse> {
112-
let requests = EphemeralArray::at(LOG_RETRIEVAL_REQUEST_ARRAY_SLOT).clear();
112+
let requests = EphemeralArray::empty_at(LOG_RETRIEVAL_REQUEST_ARRAY_SLOT);
113113
requests.push(
114114
LogRetrievalRequest {
115115
contract_address,

0 commit comments

Comments
 (0)