Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in f64 deserialization #145

Closed
maxgillett opened this issue Feb 17, 2023 · 1 comment · Fixed by #146
Closed

Bug in f64 deserialization #145

maxgillett opened this issue Feb 17, 2023 · 1 comment · Fixed by #146

Comments

@maxgillett
Copy link

maxgillett commented Feb 17, 2023

Unless I should be using another method for serialization, deserialization of zero values in this field does not work due to their canonical representation. The code below will panic with the error message: InvalidValue("invalid field element: value 18446744069414584321 is greater than or equal to the field modulus")'

use winter_math::{fields::f64::BaseElement, StarkField};
use winter_utils::Deserializable;
use winter_utils::SliceReader;

let bytes = BaseElement::from(0u8).as_int().to_le_bytes();
let mut reader = SliceReader::new(&bytes);
BaseElement::read_batch_from(&mut reader, 1).unwrap();

The issue is the following line, which should be changed to a greater than inequality:

if value >= M {

@Nashtare
Copy link
Contributor

Technically, the error message is correct: M should not be an obtainable value if we serialized a correct element to start with. I think it may be better to alter the as_int() method, to ensure that the output after Montgomery -> canonical conversion is indeed canonical, i.e in [0..M-1].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants