argumentcomputer / bellpepper-gadgets

A library of gadgets compatible with bellpepper and bellperson (contact: @huitseeker)
Apache License 2.0
17 stars 13 forks source link

Enable optional value handling in emulated and bls12381 #48

Closed wwared closed 7 months ago

wwared commented 7 months ago

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:

The second commit updates bellpepper-bls12381 to use the new APIs above:

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.