Skip to content

Commit

Permalink
Merge pull request #2152 from AleoHQ/check_deserialized_poly_has_no_t…
Browse files Browse the repository at this point in the history
…railing_zero

[NCC 72V] Do not deserialize polys with trailing zero
  • Loading branch information
howardwu authored Nov 24, 2023
2 parents 9f956e1 + c7eff3f commit ce4103f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion algorithms/src/fft/polynomial/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,16 @@ impl<'a, F: Field> CanonicalSerialize for Polynomial<'a, F> {

impl<'a, F: Field> Valid for Polynomial<'a, F> {
fn check(&self) -> Result<(), SerializationError> {
Ok(())
// Check that the polynomial contains a trailing zero coefficient.
let has_trailing_zero = match self {
Sparse(p) => p.coeffs().last().map(|(_, c)| c.is_zero()),
Dense(p) => p.coeffs.last().map(|c| c.is_zero()),
};
// Fail if the trailing coefficient is zero.
match has_trailing_zero {
Some(true) => Err(SerializationError::InvalidData),
Some(false) | None => Ok(()),
}
}
}

Expand Down

1 comment on commit ce4103f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'snarkVM Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: ce4103f Previous: 9f956e1 Ratio
bls12_377: fq_repr_div2 13 ns/iter (± 0) 3 ns/iter (± 0) 4.33
bls12_377: fq_add_assign 25 ns/iter (± 0) 12 ns/iter (± 0) 2.08

This comment was automatically generated by workflow using github-action-benchmark.

CC: @raychu86

Please sign in to comment.