Skip to content

Conversation

@MozirDmitriy
Copy link

GoldilocksField::from_str_radix constructed with Self(n) and could store values ≥ ORDER, violating the invariant that values are always canonical. This led to potential incorrect behavior in arithmetic and formatting. The function now rejects values ≥ ORDER and constructs via from_canonical_u64. Added tests to assert rejection of ORDER and acceptance of ORDER−1 to lock in the behavior.

Ok(Self::from_canonical_u64(n))
} else {
Err(format!("Number \"{s}\" too large for Goldilocks field."))
}
Copy link
Member

Choose a reason for hiding this comment

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

This changes the semantics of this function. Currently, the stored value is not greater than ORDER, as From<u64>calls wrap(n), so I assume that's the desired behavior for now. @chriseth wdyt?

Copy link
Member

@chriseth chriseth Jan 16, 2026

Choose a reason for hiding this comment

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

This function is completely undocumented, which is an fault on our part.
But I think the function is only used in tests, so this is probably a good change.

@leonardoalt leonardoalt reopened this Jan 16, 2026
@leonardoalt
Copy link
Member

Closed and re-opened to trigger CI.

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 this pull request may close these issues.

3 participants