Skip to content

Commit

Permalink
feat!: remove SharedImmutable (#10183)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nventuro authored and AztecBot committed Nov 26, 2024
1 parent 616389e commit f56f7aa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 84 deletions.
2 changes: 1 addition & 1 deletion aztec/src/prelude.nr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub use crate::{
state_vars::{
map::Map, private_immutable::PrivateImmutable, private_mutable::PrivateMutable,
private_set::PrivateSet, public_immutable::PublicImmutable, public_mutable::PublicMutable,
shared_immutable::SharedImmutable, shared_mutable::SharedMutable, storage::Storable,
shared_mutable::SharedMutable, storage::Storable,
},
};
pub use dep::protocol_types::{
Expand Down
2 changes: 0 additions & 2 deletions aztec/src/state_vars/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub mod private_mutable;
pub mod public_immutable;
pub mod public_mutable;
pub mod private_set;
pub mod shared_immutable;
pub mod shared_mutable;
pub mod storage;

Expand All @@ -14,6 +13,5 @@ pub use crate::state_vars::private_mutable::PrivateMutable;
pub use crate::state_vars::private_set::PrivateSet;
pub use crate::state_vars::public_immutable::PublicImmutable;
pub use crate::state_vars::public_mutable::PublicMutable;
pub use crate::state_vars::shared_immutable::SharedImmutable;
pub use crate::state_vars::shared_mutable::SharedMutable;
pub use crate::state_vars::storage::Storage;
28 changes: 25 additions & 3 deletions aztec/src/state_vars/public_immutable.nr
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use crate::{context::{PublicContext, UnconstrainedContext}, state_vars::storage::Storage};
use crate::{
context::{PrivateContext, PublicContext, UnconstrainedContext},
state_vars::storage::Storage,
};
use dep::protocol_types::{
constants::INITIALIZATION_SLOT_SEPARATOR,
traits::{Deserialize, Serialize},
};

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

impl<T, let T_SERIALIZED_LEN: u32> PublicImmutable<T, UnconstrainedContext>
where
T: Deserialize<T_SERIALIZED_LEN>,
T: Serialize<T_SERIALIZED_LEN> + Deserialize<T_SERIALIZED_LEN>,
{
pub unconstrained fn read(self) -> T {
self.context.storage_read(self.storage_slot)
}
}

impl<T, let T_SERIALIZED_LEN: u32> PublicImmutable<T, &mut PrivateContext>
where
T: Serialize<T_SERIALIZED_LEN> + Deserialize<T_SERIALIZED_LEN>,
{
pub fn read(self) -> T {
let header = self.context.get_header();
let mut fields = [0; T_SERIALIZED_LEN];

for i in 0..fields.len() {
fields[i] = header.public_storage_historical_read(
self.storage_slot + i as Field,
(*self.context).this_address(),
);
}
T::deserialize(fields)
}
}
78 changes: 0 additions & 78 deletions aztec/src/state_vars/shared_immutable.nr

This file was deleted.

0 comments on commit f56f7aa

Please sign in to comment.