0xMiden / 0xMiden/protocol

bug: BlockSignatures::Deserializable skips TooManySignatures validation in read_from

Abierto
#3,494 2 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Rust
Estrellas
132
Forks
167
Merge medio
1 d 23 h
PR fusionados (30 d)
110

Descripción

### Packages versions

miden-protocol: v0.16.0-rc.2 (main branch, commit bd52b31)

### Bug description

`BlockSignatures::read_from` constructs the struct directly without calling `new()`, so the `TooManySignatures` length check (`signatures.len() > ValidatorKeys::MAX`) is skipped during deserialization.

**`new()` validates:**

```rust
pub fn new(signatures: Vec) -> Result {
if signatures.len() > ValidatorKeys::MAX {
return Err(BlockSignaturesError::TooManySignatures { count: signatures.len() });
}
Ok(Self { signatures })
}
```

**`read_from` skips validation:**

```rust
impl Deserializable for BlockSignatures {
fn read_from(source: &mut R) -> Result {
let signatures = Vec::::read_from(source)?;
Ok(Self { signatures }) // ← no new(), no MAX check
}
}
```

`ValidatorKeys::read_from` in the same codebase does this correctly by routing through `Self::new().map_err(...)`:

```rust
impl Deserializable for ValidatorKeys {
fn read_from(source: &mut R) -> Result {
let keys = Vec::::read_from(source)?;
Self::new(keys).map_err(|err| DeserializationError::InvalidValue(err.to_string()))
}
}
```

**Suggested fix:** Route `read_from` through `new()`, matching the `ValidatorKeys` pattern:

```rust
impl Deserializable for BlockSignatures {
fn read_from(source: &mut R) -> Result {
let signatures = Vec::::read_from(source)?;
Self::new(signatures).map_err(|err| DeserializationError::InvalidValue(err.to_string()))
}
}
```

Happy to open a PR if this direction is agreed upon.

**Related:**
- #3185 same pattern in `ProposedBlock::read_from` (skips `new_at` validation)
- #3199 same pattern in `SignedBlock::read_from` (skips signature verification)

### How can this be reproduced?

1. Serialize a `BlockSignatures` with more than `ValidatorKeys::MAX` (5) signatures
2. Deserialize with `read_from_bytes()`
3. Deserialization succeeds `TooManySignatures` validation is bypassed
4. `BlockSignatures::new()` with the same data would return `Err(TooManySignatures { count: 6 })`

### Relevant log output

```shell
No logs structural code issue.
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.