> Aztec.nr API reference, v6.0.0 (mainnet and testnet). Index: https://docs.aztec.network/aztec-nr-api/mainnet/llms.txt

# Struct WithHash

Module: `noir_aztec::utils`

```rust
pub struct WithHash<T, let M: u32>
{ /* private fields */ }
```

A struct that allows for efficient reading of value `T` from public storage in private.

The efficient reads are achieved by verifying large values through a single hash check and then proving inclusion only of the hash in public storage. This reduces the number of required tree inclusion proofs from `M` to 1.

## Type Parameters

- `T`: The underlying type being wrapped, must implement `Packable<N>`
- `M`: The number of field elements required to pack values of type `T`

## Implementations

```rust
impl<T, let M: u32> WithHash<T, M>
where
    T: Packable<N = M>
```

```rust
pub fn new(value: T) -> Self
```

```rust
pub fn get_value(self) -> T
```

```rust
pub fn get_hash(self) -> Field
```

```rust
pub fn public_storage_read(context: PublicContext, storage_slot: Field) -> T
```

Reads the value stored in this [`WithHash`](/aztec-nr-api/mainnet/noir_aztec/utils/struct.WithHash.md) from public storage.

Note that unlike a full public storage read, this will *not* read (not return) the stored hash of the value, resulting in reduced gas costs.

This is the public counterpart to [`WithHash::utility_public_storage_read`](/aztec-nr-api/mainnet/noir_aztec/utils/struct.WithHash.md#utility_public_storage_read) and [`WithHash::historical_public_storage_read`](/aztec-nr-api/mainnet/noir_aztec/utils/struct.WithHash.md#historical_public_storage_read).

```rust
pub unconstrained fn utility_public_storage_read(
    context: UtilityContext,
    storage_slot: Field,
) -> T
```

```rust
pub fn historical_public_storage_read(
    header_to_read_from: BlockHeader,
    address: AztecAddress,
    storage_slot: Field,
) -> T
```

## Trait implementations

```rust
impl<let M: u32, T> Packable for WithHash<T, M>
where
    T: Packable<N = M>
```

```rust
pub fn pack(self) -> [Field; M + 1]
```

```rust
pub fn unpack(packed: [Field; M + 1]) -> Self
```
