Skip to content

Commit f56f7aa

Browse files
nventuroAztecBot
authored and
AztecBot
committed
feat!: remove SharedImmutable (#10183)
Working on AztecProtocol/aztec-packages#10164 made me realize that this state variable is now useless: it is the exact same as `PublicImmutable` except it also has getters for private execution contexts. I deleted it entirely in favor of `PublicImmutable`, which should be less surprising for a library user. After all, reading publicly known immutable values during private execution is fine. I updated the docs and tests accordingly, mostly keeping the shared immut versions as those were more complete.
1 parent 616389e commit f56f7aa

File tree

4 files changed

+26
-84
lines changed

4 files changed

+26
-84
lines changed

aztec/src/prelude.nr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub use crate::{
1111
state_vars::{
1212
map::Map, private_immutable::PrivateImmutable, private_mutable::PrivateMutable,
1313
private_set::PrivateSet, public_immutable::PublicImmutable, public_mutable::PublicMutable,
14-
shared_immutable::SharedImmutable, shared_mutable::SharedMutable, storage::Storable,
14+
shared_mutable::SharedMutable, storage::Storable,
1515
},
1616
};
1717
pub use dep::protocol_types::{

aztec/src/state_vars/mod.nr

-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub mod private_mutable;
44
pub mod public_immutable;
55
pub mod public_mutable;
66
pub mod private_set;
7-
pub mod shared_immutable;
87
pub mod shared_mutable;
98
pub mod storage;
109

@@ -14,6 +13,5 @@ pub use crate::state_vars::private_mutable::PrivateMutable;
1413
pub use crate::state_vars::private_set::PrivateSet;
1514
pub use crate::state_vars::public_immutable::PublicImmutable;
1615
pub use crate::state_vars::public_mutable::PublicMutable;
17-
pub use crate::state_vars::shared_immutable::SharedImmutable;
1816
pub use crate::state_vars::shared_mutable::SharedMutable;
1917
pub use crate::state_vars::storage::Storage;

aztec/src/state_vars/public_immutable.nr

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
use crate::{context::{PublicContext, UnconstrainedContext}, state_vars::storage::Storage};
1+
use crate::{
2+
context::{PrivateContext, PublicContext, UnconstrainedContext},
3+
state_vars::storage::Storage,
4+
};
25
use dep::protocol_types::{
36
constants::INITIALIZATION_SLOT_SEPARATOR,
47
traits::{Deserialize, Serialize},
58
};
69

7-
// Just like SharedImmutable but without the ability to read from private functions.
10+
/// Stores an immutable value in public state which can be read from public, private and unconstrained execution
11+
/// contexts.
812
// docs:start:public_immutable_struct
913
pub struct PublicImmutable<T, Context> {
1014
context: Context,
@@ -57,9 +61,27 @@ where
5761

5862
impl<T, let T_SERIALIZED_LEN: u32> PublicImmutable<T, UnconstrainedContext>
5963
where
60-
T: Deserialize<T_SERIALIZED_LEN>,
64+
T: Serialize<T_SERIALIZED_LEN> + Deserialize<T_SERIALIZED_LEN>,
6165
{
6266
pub unconstrained fn read(self) -> T {
6367
self.context.storage_read(self.storage_slot)
6468
}
6569
}
70+
71+
impl<T, let T_SERIALIZED_LEN: u32> PublicImmutable<T, &mut PrivateContext>
72+
where
73+
T: Serialize<T_SERIALIZED_LEN> + Deserialize<T_SERIALIZED_LEN>,
74+
{
75+
pub fn read(self) -> T {
76+
let header = self.context.get_header();
77+
let mut fields = [0; T_SERIALIZED_LEN];
78+
79+
for i in 0..fields.len() {
80+
fields[i] = header.public_storage_historical_read(
81+
self.storage_slot + i as Field,
82+
(*self.context).this_address(),
83+
);
84+
}
85+
T::deserialize(fields)
86+
}
87+
}

aztec/src/state_vars/shared_immutable.nr

-78
This file was deleted.

0 commit comments

Comments
 (0)