Skip to content

Implement new range check technique#1349

Merged
divergentdave merged 5 commits intomainfrom
david/range-check-changes
Mar 4, 2026
Merged

Implement new range check technique#1349
divergentdave merged 5 commits intomainfrom
david/range-check-changes

Conversation

@divergentdave
Copy link
Copy Markdown
Collaborator

This implements the technique from cfrg/draft-irtf-cfrg-vdaf#549 in Prio3Sum, Prio3SumVec, and Prio3MultihotCountVec. See spec PRs cfrg/draft-irtf-cfrg-vdaf#576 and cfrg/draft-irtf-cfrg-vdaf#581.

I updated the test vectors with files from those PRs, and this implementation matches (though I had to unwind some field name changes that haven't been adopted here yet). I implemented the common encoding/decoding step in a helper function, and used that in the implementation of each FLP type.

Note that I had to add some new trait bounds from the subtle crate to our Integer associated type, in order to make encoding constant time. I added them here instead of on the related Integer trait because they each imply a Copy bound. We previously left the Copy bound on this associated type, and not the Integer trait, because we reuse the trait in tests where we implement it for a non-Copy arbitrary precision integer type, to help with GF(2^255-19) tests.

I'm opening this as a draft for now until we arrive at a decision on the spec changes.

Copy link
Copy Markdown
Contributor

@tgeoghegan tgeoghegan left a comment

Choose a reason for hiding this comment

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

This change LGTM compared to the spec changes in cfrg/draft-irtf-cfrg-vdaf#576 and cfrg/draft-irtf-cfrg-vdaf#581.

The awkward thing is that the test vectors don't correspond to draft-irtf-cfrg-vdaf-18, but those vectors also account for the Rhizomes work to evaluate polynomials in the Lagrange basis, which we don't have yet. So I think we should merge this as-is, and we'll sync up with the VDAF test vectors in the next change we take.

It's also unfortunate to have to disable the Mastic test vector tests, but we'd need that specification to update before we can do anything about it, and I don't want to hold up shipping draft-irtf-cfrg-vdaf-18's Prio3 on that.

@divergentdave divergentdave marked this pull request as ready for review March 3, 2026 23:33
@divergentdave divergentdave requested a review from a team as a code owner March 3, 2026 23:33
Comment thread src/flp/types.rs Outdated
Comment thread src/flp/types.rs Outdated
Comment thread src/flp/types.rs Outdated
Comment thread src/flp/types.rs
Comment thread src/flp/types.rs
)));
}
flattened.extend(F::encode_as_bitvector(*summand, self.bits)?);
encode_range_checked_int(*summand, self.bits, self.last_weight, &mut flattened)?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: kind of a shame to trade the real clear "summand exceeds maximum of 2^{}-1" for a FieldError::InputSizeMismatch.

We could put back in an explicit bounds check, similar to how Sum::encode_measurement checks at line 245.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'm going to add a new error variant for this. InputSizeMismatch isn't appropriate, that's intended for trying to add two vectors of field elements with different lengths.

@divergentdave divergentdave force-pushed the david/range-check-changes branch from b08e007 to 6d95937 Compare March 4, 2026 22:17
@divergentdave divergentdave requested a review from jcjones March 4, 2026 22:19
Copy link
Copy Markdown
Contributor

@jcjones jcjones left a comment

Choose a reason for hiding this comment

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

These are some great improvements on top of my comments -- looks great to me now!

Copy link
Copy Markdown
Collaborator Author

@divergentdave divergentdave left a comment

Choose a reason for hiding this comment

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

Oops, forgot to submit my pending comment

Comment thread src/flp/types.rs
)));
}
flattened.extend(F::encode_as_bitvector(*summand, self.bits)?);
encode_range_checked_int(*summand, self.bits, self.last_weight, &mut flattened)?;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'm going to add a new error variant for this. InputSizeMismatch isn't appropriate, that's intended for trying to add two vectors of field elements with different lengths.

@divergentdave divergentdave merged commit 96ad045 into main Mar 4, 2026
6 checks passed
@divergentdave divergentdave deleted the david/range-check-changes branch March 4, 2026 22:52
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