The goal of this PR is to make bellpepper-emulated and bellpepper-bls12381 play nicer with MetricCS and when values of AllocatedNums are not assigned (i.e. .get_value() returns None). Closes #45 and is related to https://github.com/lurk-lab/bellpepper/pull/88. This PR is easier to review by looking at the commits individually.
The first commit refactors bellpepper-emulated to be more mindful of optional values:
All get_value().unwrap_or_default() and bare .get_value().unwrap() calls replaced, and now usually just return SynthesisError::AssignmentMissing instead
The From impl was turned into a TryFrom impl due to the above (going from EmulatedFieldElement to BigInt)
Update hint functions in field_hints.rs to pass through optional values to the allocation functions
To support the above, a few additional helper functions to allocate optional values: allocate_optional_field_element_unchecked, allocate_optional_limbs, allocate_empty_limbs.
The second commit updates bellpepper-bls12381 to use the new APIs above:
Refactor alloc_element to take an Option instead (a lot of churn adding Somes to the tests)
Change From impl to TryFrom
Refactor division/inversion functions to passthrough missing values
Add a test that instantiates the pairing circuit with MetricCS
https://github.com/lurk-lab/bellpepper/pull/88 is not a pre-requisite for this PR (it works with or without it), but I found that issue when working on this: the sub_op method of bellpepepper-emulated will not error with an EmulatedFieldElement that is missing its limbs, and subtracting two missing elements will end up returning a new element with all-zero limbs (more precisely, the limbs are a multiple of the field modulus, see sub_padding), instead of another element missing its limbs. After the PR above, this issue no longer happens.
Adding @adr1anh as a reviewer since he opened #45.
The goal of this PR is to make
bellpepper-emulated
andbellpepper-bls12381
play nicer withMetricCS
and when values ofAllocatedNum
s are not assigned (i.e..get_value()
returnsNone
). Closes #45 and is related to https://github.com/lurk-lab/bellpepper/pull/88. This PR is easier to review by looking at the commits individually.The first commit refactors
bellpepper-emulated
to be more mindful of optional values:get_value().unwrap_or_default()
and bare.get_value().unwrap()
calls replaced, and now usually just returnSynthesisError::AssignmentMissing
insteadFrom
impl was turned into aTryFrom
impl due to the above (going fromEmulatedFieldElement
toBigInt
)field_hints.rs
to pass through optional values to the allocation functionsallocate_optional_field_element_unchecked
,allocate_optional_limbs
,allocate_empty_limbs
.The second commit updates
bellpepper-bls12381
to use the new APIs above:alloc_element
to take anOption
instead (a lot of churn addingSome
s to the tests)From
impl toTryFrom
MetricCS
https://github.com/lurk-lab/bellpepper/pull/88 is not a pre-requisite for this PR (it works with or without it), but I found that issue when working on this: the
sub_op
method ofbellpepepper-emulated
will not error with anEmulatedFieldElement
that is missing its limbs, and subtracting two missing elements will end up returning a new element with all-zero limbs (more precisely, the limbs are a multiple of the field modulus, seesub_padding
), instead of another element missing its limbs. After the PR above, this issue no longer happens.Adding @adr1anh as a reviewer since he opened #45.