@@ -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 ();
0 commit comments