# Transaction filtering

***

The ZK Chain operators can filter both the transactions initiated from L1 and the ones submitted via API directly to L2.

### L1->L2 Transactions <a href="#l1-l2-transactions" id="l1-l2-transactions"></a>

To filter L1→L2 transactions coming through the Diamond proxy, operators shall:

1. Implement & deploy the `TransactionFilterer` contract which implement the [`ITransactionFilterer`](https://github.com/matter-labs/era-contracts/blob/dev/l1-contracts/contracts/state-transition/chain-interfaces/ITransactionFilterer.sol#L8)
2. Have the `TransactionFilterer` address set in the state transition [storage](https://github.com/matter-labs/era-contracts/blob/dev/l1-contracts/contracts/state-transition/chain-deps/ZkSyncHyperchainStorage.sol) (by using [this function](https://github.com/matter-labs/era-contracts/blob/dev/l1-contracts/contracts/state-transition/chain-deps/facets/Admin.sol#L95)).

If the filterer exists, it will be called by the [Mailbox facet](https://github.com/matter-labs/era-contracts/blob/994897b14eb1d8e77c809da2db3379e7b58125b5/l1-contracts/contracts/state-transition/chain-deps/facets/Mailbox.sol#L239) with the tx details, and will return whether the transaction can be executed. To disable L1→L2 filtering, the same function that registers the filtered to the storage can be used with `0x0` address.

### L2 Transactions <a href="#l2-transactions" id="l2-transactions"></a>

To filter the transactions sent via the API, operators shall include filtering logic before txs get to the mempool.

To do this, an alternative [`TxSinkLayer`](https://github.com/matter-labs/zksync-era/blob/main/core/node/node_framework/src/implementations/layers/web3_api/tx_sink.rs) must be implemented and used by the `node framework` by modifying the code [here](https://github.com/matter-labs/zksync-era/blob/main/core/bin/zksync_server/src/node_builder.rs#L230). For reference,

* See [Node Framework example](https://github.com/matter-labs/zksync-era/blob/main/core/node/node_framework/examples/main_node.rs#L416)
* See [example implementation](https://github.com/matter-labs/zksync-era/pull/1782)

**Note on Withdrawals**

Imagine a case where a user deposited funds and then was added to the denylist or removed from the allowlist. In that scenario, the user may have their funds locked on the L2 or potentially even in a contract on the L2. Please think about handling such cases and ensuring that the user can still withdraw their funds.

<br>
