-
Notifications
You must be signed in to change notification settings - Fork 615
chore: cycle group cleanup #5 #17026
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
Changes from 6 commits
6b23fd2
4832bd6
bf3eacb
c6292e0
14c1400
fb17bdf
ce5e3da
dd1401e
3035add
984cb44
d1d440e
d9eb676
7c563b0
5da71f1
6001747
e690fd2
83be28b
1de5c17
50808c0
12c79de
1b5047e
739ad72
99c1cd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,28 +17,6 @@ cycle_scalar<Builder>::cycle_scalar(const field_t& _lo, const field_t& _hi) | |
| , hi(_hi) | ||
| {} | ||
|
|
||
| template <typename Builder> cycle_scalar<Builder>::cycle_scalar(const field_t& in) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. previously only used in the transcript |
||
| { | ||
| const uint256_t value(in.get_value()); | ||
| const uint256_t lo_v = value.slice(0, LO_BITS); | ||
| const uint256_t hi_v = value.slice(LO_BITS, HI_BITS); | ||
| constexpr uint256_t shift = uint256_t(1) << LO_BITS; | ||
| if (in.is_constant()) { | ||
| lo = lo_v; | ||
| hi = hi_v; | ||
| } else { | ||
| lo = witness_t<Builder>(in.get_context(), lo_v); | ||
| hi = witness_t<Builder>(in.get_context(), hi_v); | ||
| (lo + hi * shift).assert_equal(in); | ||
| // TODO(https://github.com/AztecProtocol/barretenberg/issues/1022): ensure lo and hi are in bb::fr modulus not | ||
| // bb::fq modulus otherwise we could have two representations for in | ||
| validate_scalar_is_in_field(); | ||
| } | ||
| // We need to manually propagate the origin tag | ||
| lo.set_origin_tag(in.get_origin_tag()); | ||
| hi.set_origin_tag(in.get_origin_tag()); | ||
| } | ||
|
|
||
| template <typename Builder> cycle_scalar<Builder>::cycle_scalar(const ScalarField& in) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was not used anywhere |
||
| { | ||
| const uint256_t value(in); | ||
|
|
@@ -79,44 +57,45 @@ cycle_scalar<Builder> cycle_scalar<Builder>::from_witness_bitstring(Builder* con | |
| BB_ASSERT_LT(bitstring.get_msb(), num_bits); | ||
| const uint256_t lo_v = bitstring.slice(0, LO_BITS); | ||
| const uint256_t hi_v = bitstring.slice(LO_BITS, HI_BITS); | ||
| field_t lo = witness_t<Builder>(context, lo_v); | ||
| field_t hi = witness_t<Builder>(context, hi_v); | ||
| lo.set_free_witness_tag(); | ||
| hi.set_free_witness_tag(); | ||
| cycle_scalar result{ lo, hi, num_bits, true, false }; | ||
| return result; | ||
| auto lo = field_t::from_witness(context, lo_v); | ||
| auto hi = field_t::from_witness(context, hi_v); | ||
| return cycle_scalar{ | ||
| lo, hi, num_bits, /*skip_primality_test=*/true, /*use_bn254_scalar_field_for_primality_test=*/false | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Use when we want to multiply a group element by a string of bits of known size. | ||
| * N.B. using this constructor method will make our scalar multiplication methods not perform primality tests. | ||
| * @brief Construct a cycle scalar (grumpkin scalar field element) from a bn254 scalar field element | ||
| * @details This method ensures that the input is constrained to be less than the bn254 scalar field modulus. | ||
| * | ||
| * @tparam Builder | ||
| * @param context | ||
| * @param value | ||
| * @param num_bits | ||
| * @return cycle_scalar<Builder> | ||
| */ | ||
| template <typename Builder> | ||
| cycle_scalar<Builder> cycle_scalar<Builder>::create_from_bn254_scalar(const field_t& in, const bool skip_primality_test) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this method should never skip the bn254 scalar field primality test (and indeed this path was never used) so I've removed |
||
| template <typename Builder> cycle_scalar<Builder> cycle_scalar<Builder>::create_from_bn254_scalar(const field_t& in) | ||
| { | ||
| const uint256_t value_u256(in.get_value()); | ||
| const uint256_t lo_v = value_u256.slice(0, LO_BITS); | ||
| const uint256_t hi_v = value_u256.slice(LO_BITS, HI_BITS); | ||
| const bool skip_primality_test = false; | ||
| const bool use_bn254_scalar_field_for_primality_test = true; | ||
| // WORKTODO: should be able to use field_t::split_at_unrestricted here | ||
| if (in.is_constant()) { | ||
| cycle_scalar result{ field_t(lo_v), field_t(hi_v), NUM_BITS, false, true }; | ||
| return result; | ||
| return cycle_scalar{ | ||
| field_t(lo_v), field_t(hi_v), NUM_BITS, skip_primality_test, use_bn254_scalar_field_for_primality_test | ||
| }; | ||
| } | ||
| field_t lo = witness_t<Builder>(in.get_context(), lo_v); | ||
| field_t hi = witness_t<Builder>(in.get_context(), hi_v); | ||
| auto lo = field_t::from_witness(in.get_context(), lo_v); | ||
| auto hi = field_t::from_witness(in.get_context(), hi_v); | ||
| lo.add_two(hi * (uint256_t(1) << LO_BITS), -in).assert_equal(0); | ||
|
|
||
| // We need to manually propagate the origin tag | ||
| lo.set_origin_tag(in.get_origin_tag()); | ||
| hi.set_origin_tag(in.get_origin_tag()); | ||
|
|
||
| cycle_scalar result{ lo, hi, NUM_BITS, skip_primality_test, true }; | ||
| return result; | ||
| return cycle_scalar{ lo, hi, NUM_BITS, skip_primality_test, use_bn254_scalar_field_for_primality_test }; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think eventually I can just get rid of |
||
| } | ||
| /** | ||
| * @brief Construct a new cycle scalar from a bigfield _value, over the same ScalarField Field. If _value is a witness, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cycle_scalar::from_witnessis not used anywhere in production so it seems better to test the main production use case instead which iscycle_scalars constructed from bigfield elements (i.e. in the ECCVM recursive verifier). I've updated all of the tests accordingly. Eventually I may expand them to usecycle_scalars constructed through all of the main production entrypoints