# UNDF: UNDF-2026-000000392
## Classification

| Field       | Value |
|-------------|-------|
| CWE         | CWE-407 Inefficient Algorithmic Complexity |
| Severity    | HIGH |
| Component   | `net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.java` |
| Function    | `propagateSignal()` BFS |
| Hot path    | Called every redstone update tick |

## Defect

`ExperimentalRedstoneWireEvaluator` maintains `wiresToTurnOn` and
`wiresToTurnOff` as `Deque<BlockPos>`. During BFS propagation,
`deque.contains(pos)` is called for each candidate wire — O(N) scan per
call, inside the BFS loop: O(N²) total for N-wire networks.

```java
// BEFORE — O(N²): Deque.contains() inside BFS loop
private final Deque<BlockPos> wiresToTurnOff = new ArrayDeque<>();
private final Deque<BlockPos> wiresToTurnOn  = new ArrayDeque<>();

// In BFS loop:
if (!wiresToTurnOff.contains(pos)) wiresToTurnOff.add(pos);
if (!wiresToTurnOn.contains(pos))  wiresToTurnOn.add(pos);
```

Redstone wire networks of N=200 wires require 40,000 comparisons instead of 200.

## Fix

Add parallel `HashSet<BlockPos>` for O(1) duplicate detection.

```java
// AFTER — O(N): companion sets for O(1) membership
private final Deque<BlockPos> wiresToTurnOff    = new ArrayDeque<>();
private final Set<BlockPos>   wiresToTurnOffSet = new HashSet<>();
private final Deque<BlockPos> wiresToTurnOn     = new ArrayDeque<>();
private final Set<BlockPos>   wiresToTurnOnSet  = new HashSet<>();

// In BFS loop:
if (wiresToTurnOffSet.add(pos)) wiresToTurnOff.add(pos);
if (wiresToTurnOnSet.add(pos))  wiresToTurnOn.add(pos);
```

The `Deque` is retained for ordered BFS traversal. The `Set` is used only
for membership testing.
