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

# Struct SpongeBlob

Module: `protocol_types::blob_data`

```rust
pub struct SpongeBlob {
    pub sponge: Poseidon2Sponge,
    pub num_absorbed_fields: u32,
}
```

A Poseidon2 sponge used to accumulate data that will be added to blob(s). (More accurately called BlobSponge, but that's not as fun).

The journey of a SpongeBlob:

Tx base: each tx absorbs its effects into the given "start" SpongeBlob and outputs it as the "end" SpongeBlob.

Tx merge or block root checks that the start SpongeBlob of a tx matches the end SpongeBlob of the previous tx.

Block root: the end SpongeBlob of the last tx absorbs a special block end marker indicating the number of txs in the block, along with the end state of the block. The block header commits to the value squeezed from this SpongeBlob. This updated SpongeBlob is then output as the end SpongeBlob of the block root.

In block merge or checkpoint root, the start SpongeBlob is checked against the end SpongeBlob of the previous block.

Checkpoint root: receives all fields as private inputs and checks that hashing them matches the final hash squeezed from the end SpongeBlob of the last block, after absorbing a checkpoint end marker indicating the number of fields absorbed. It also checks that the start SpongeBlob of the first tx in the block does not have any fields absorbed.

The final hash is used as part of the blob challenge, proving that all fields of the blob(s) are included.

Note: The hash squeezed from the SpongeBlob is NOT a standard poseidon2 hash.

## Fields

```rust
sponge: Poseidon2Sponge
```

```rust
num_absorbed_fields: u32
```

## Implementations

```rust
impl SpongeBlob
```

```rust
pub fn init() -> Self
```

Initialize the sponge with the maximum number of fields allowed in a checkpoint. This allows proposers to start creating blocks and signing block headers (which contain the hash squeezed from the this sponge) before receiving all txs in a checkpoint slot.

```rust
pub fn absorb_tx_blob_data(
    &mut self,
    tx_effect: TxEffect,
    array_lengths: TxEffectArrayLengths,
)
```

\|----------|--------------------------------|-------------------------------------| | Field 0 | TX_START_PREFIX | 64 bits | | | num_note_hashes | 16 bits | | | num_nullifiers | 16 bits | | | num_l1_to_l2_msgs | 16 bits | | | num_public_data_writes | 16 bits | | | num_private_logs | 16 bits | | | private_logs_length | 16 bits | | | public_logs_length | 32 bits | | | contract_class_log_length | 16 bits | | | revert_code | 8 bits |

|            | num_blob_fields                | 32 bits                               |
| ---------- | -------------------------------- | ------------------------------------- |
| Field 1    | tx_effect.tx_hash              | A field                               |
| ---------- | -------------------------------- | ------------------------------------- |
| Field 2    | tx_effect.transaction_fee      | A field                               |
| ---------- | -------------------------------- | ------------------------------------- |
|            | tx_effect.note_hashes          | `num_note_hashes` fields              |
| ---------- | -------------------------------- | ------------------------------------- |
|            | tx_effect.nullifiers            | `num_nullifiers` fields               |
| ---------- | -------------------------------- | ------------------------------------- |
|            | tx_effect.l2_to_l1_msgs      | `num_l1_to_l2_msgs` fields            |
| ---------- | -------------------------------- | ------------------------------------- |
|            | tx_effect.public_data_writes  | `num_public_data_writes * 2` fields   |
| ---------- | -------------------------------- | ------------------------------------- |
|            | (tx_effect.private_logs):      | (private_logs_length)               |
|            | Where, for each log:             |                                       |
|            | log.length                       | A field                               |
|            | log.fields                       | `log.length` fields                   |
| ---------- | -------------------------------- | ------------------------------------- |
|            | tx_effect.public_logs.payload  | `public_logs.length` fields           |
| ---------- | -------------------------------- | ------------------------------------- |
|            | tx_effect.contract_class_logs | (contract_class_log_length)        |
|            | Where, for each log:             |                                       |
|            | log.contract_address            | A field                               |
|            | log.fields                       | `log.length` fields                   |
| ---------- | -------------------------------- | ------------------------------------- |

```rust
pub fn absorb_tx_blob_data_sections(
    &mut self,
    tx_effect: TxEffect,
    array_lengths: TxEffectArrayLengths,
    sections: TxBlobDataSections,
)
```

```rust
pub fn absorb_block_end_data(
    &mut self,
    global_variables: GlobalVariables,
    last_archive: AppendOnlyTreeSnapshot,
    state: StateReference,
    num_txs: u16,
    total_mana_used: Field,
)
```

\|----------|---------------------------------------------|---------| | Field 0 | BLOCK_END_PREFIX | 72 bits | | | timestamp | 64 bits | | | block_number | 32 bits |

|            | num_txs                                          | 16 bits   |
| ---------- | ------------------------------------------------- | --------- |
| Field 1    | l1_to_l2_message_next_available_leaf_index | 36 bits   |
|            | note_hash_next_available_leaf_index          | 42 bits   |
|            | nullifier_next_available_leaf_index           | 42 bits   |
|            | public_data_next_available_leaf_index        | 40 bits   |
|            | total_mana_used                                 | 48 bits   |
| ---------- | ---------------------------------------------     | --------- |
| Field 2    | last_archive.root                                | A field   |
| ---------- | ---------------------------------------------     | --------- |
| Field 3    | note_hash_tree.root                             | A field   |
| ---------- | ---------------------------------------------     | --------- |
| Field 4    | nullifier_tree.root                              | A field   |
| ---------- | ---------------------------------------------     | --------- |
| Field 5    | public_data_tree.root                           | A field   |
| ---------- | ---------------------------------------------     | --------- |
| Field 6    | l1_to_l2_message_tree.root                    | A field   |
| ---------- | ---------------------------------------------     | --------- |

```rust
pub fn absorb_checkpoint_end_marker(&mut self)
```

\|----------|---------------------------------------------|---------| | Field 0 | CHECKPOINT_END_PREFIX | 112 bits|

|   | num_blob_fields | 32 bits |
| - | ----------------- | ------- |

```rust
pub fn absorb<let N: u32>(&mut self, input: [Field; N], in_len: u32)
```

Absorb the first `in_len` fields of the `input` to the sponge. Fields beyond `in_len` are ignored.

```rust
pub fn squeeze(&mut self) -> Field
```

Finalize the sponge and output the non-standard poseidon2 hash of all fields absorbed.

## Trait implementations

```rust
impl Deserialize for SpongeBlob
```

```rust
pub fn deserialize(fields: [Field; 10]) -> Self
```

```rust
pub fn stream_deserialize<let K: u32>(reader: &mut Reader<K>) -> Self
```

```rust
impl Empty for SpongeBlob
```

```rust
pub fn empty() -> Self
```

```rust
pub fn is_empty(self: Self) -> bool
where
    Self: Eq
```

```rust
pub fn assert_empty<let S: u32>(self: Self, msg: str<S>)
where
    Self: Eq
```

```rust
impl Eq for SpongeBlob
```

```rust
pub fn eq(_self: Self, _other: Self) -> bool
```

```rust
impl Serialize for SpongeBlob
```

```rust
pub fn serialize(self) -> [Field; 10]
```

```rust
pub fn stream_serialize<let K: u32>(self, writer: &mut Writer<K>)
```
