-
Notifications
You must be signed in to change notification settings - Fork 103
Refactor ElectionPolynomial to use PolynomialCoefficients dataclass #477
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
Refactor ElectionPolynomial to use PolynomialCoefficients dataclass #477
Conversation
|
This pull request introduces 1 alert when merging d74c8f9 into 82df51b - view on LGTM.com new alerts:
|
Removed unused PolynomialCoefficients import added in previous commit
|
|
||
| computed_value = ZERO_MOD_Q | ||
| for (i, coefficient) in enumerate(polynomial.coefficients): | ||
| for (i, coefficient) in enumerate(polynomial.coefficients.values): |
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.
polynomial.coefficients should return an List of PolynomialCoefficient here so you shouldn't be able to get the property of it like this.
I believe it would be
for (i, coefficient) in enumerate(polynomial.coefficients):
...
factor = mult_q(coefficient.value, exponent)
...
src/electionguard/key_ceremony.py
Outdated
| self.polynomial.coefficient_commitments, | ||
| self.polynomial.coefficient_proofs, | ||
| self.polynomial.coefficients.commitments, | ||
| self.polynomial.coefficients.proofs, |
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.
Similar to the previous comments. These lines shouldn't function as expected.
Originally this was
self.polynomial.coefficient_commitments: List[ElementModP]now it's
self.polynomial.coefficients: List[PolynomialCoefficient]This could be addressed by adding a convenience method to the polynomial class such as
def get_commitments(self) -> List[ElementModP]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.
Thanks for taking time to write this review. my initial solution was like this
self.polynomial.coefficients.commitments: PUBLIC_COMMITMENTThe issue is that it was not returning the expected list, but the constant directly?
I will add the suggested method. Shouldn't it access PUBLIC_COMMITMENT instead of ElementModP directly?
def get_commitments(self) -> List[PUBLIC_COMMITMENT]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.
Yes. It should access PUBLIC_COMMITMENT that would be ideal.
src/electionguard/key_ceremony.py
Outdated
| compute_polynomial_coordinate(backup.designated_sequence_order, polynomial), | ||
| polynomial.coefficient_commitments, | ||
| polynomial.coefficient_proofs, | ||
| polynomial.coefficients.commitments, |
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.
See above.
| def test_compute_polynomial_coordinate(self): | ||
| # Arrange | ||
| polynomial = ElectionPolynomial( | ||
| polynomial = ElectionPolynomial(PolynomialCoefficients( |
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.
This line actually changes pretty significantly. I tried to break it up for you to showcase what is happening. This could all be one line.
coefficient_1 = PolynomialCoefficient(ONE_MOD_Q, ONE_MOD_P, Proof_1)
coefficient_2 = PolynomialCoefficient(TWO_MOD_Q, TWO_MOD_P, Proof_2)
polynomial = ElectionPolynomial([coefficient_1, coefficient_2])| self.assertTrue( | ||
| verify_polynomial_coordinate( | ||
| value, TEST_EXPONENT_MODIFIER, polynomial.coefficient_commitments | ||
| value, TEST_EXPONENT_MODIFIER, polynomial.coefficients.commitments |
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.
See previous comments.
|
Really good first attempt. The helper methods I suggested on the class may make this easier for you. class ElectionPolynomial():
...
def get_commitments(self)-> List[ElementModP]:
return [coefficient.commitment for coefficient in self.coefficients]
... |
|
@Brites101 Following up, any progress? |
Brites101
left a comment
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.
@Brites101 Following up, any progress?
Yes! Just submitted some corrections. Thank you for the thorough review before. Please check if these fixes are properly implemented.
| [ONE_MOD_P, TWO_MOD_P], | ||
| [], | ||
| ) | ||
| Coefficient(ONE_MOD_Q, TWO_MOD_Q,), |
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.
@keithrfung , i left the proof blank, as it was the case in the previous iteration of this test, but i am unsure if this is correct.
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.
I think the typing will yell at you for this. Try constructing a proof instead.
proof = make_schnorr_proof(ElGamalKeyPair(coefficient, commitment), rand_q())
|
This pull request introduces 1 alert when merging b9969aa into 3a56cee - view on LGTM.com new alerts:
|
keithrfung
left a comment
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.
Moving in the right direction but still has a bit more work to do. This will likely fail the build and the linter.
I tried to be thorough on notes here to give you a hand. Don't get discouraged. You got this.
| [ONE_MOD_P, TWO_MOD_P], | ||
| [], | ||
| ) | ||
| Coefficient(ONE_MOD_Q, TWO_MOD_Q,), |
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.
I think the typing will yell at you for this. Try constructing a proof instead.
proof = make_schnorr_proof(ElGamalKeyPair(coefficient, commitment), rand_q())
|
This pull request introduces 2 alerts when merging e41fe1f into 3a56cee - view on LGTM.com new alerts:
|
|
This pull request introduces 2 alerts when merging 9b52466 into 3a56cee - view on LGTM.com new alerts:
|
|
This pull request introduces 1 alert when merging da02172 into 3a56cee - view on LGTM.com new alerts:
|
keithrfung
left a comment
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.
See the comments
|
As a helpful suggestion, before committing code, be sure to run:
|
Thank you for this. I tought this was for Linux/MAC, but now i see how to install it on windows. i will run it in future commits |
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.
There is a quick white space fix in the class, but the base code is now working, but the dependencies need some fixing. See the files called out by the linter.
Run make lint to continue to track these down.
************* Module electionguard.election_polynomial
src/electionguard/election_polynomial.py:27:59: C0303: Trailing whitespace (trailing-whitespace)
src/electionguard/election_polynomial.py:30:29: C0303: Trailing whitespace (trailing-whitespace)
src/electionguard/election_polynomial.py:32:0: C0303: Trailing whitespace (trailing-whitespace)
************* Module electionguard.key_ceremony
src/electionguard/key_ceremony.py:220:36: E1101: Instance of 'ElectionPolynomial' has no 'coefficient_commitments' member (no-member)
************* Module tests.unit.test_election_polynomial
tests/unit/test_election_polynomial.py:38:9: E0001: invalid syntax (<unknown>, line 38) (syntax-error)
************* Module tests.unit.test_key_ceremony
tests/unit/test_key_ceremony.py:54:16: E1101: Instance of 'ElectionPolynomial' has no 'coefficient_commitments' member (no-member)
tests/unit/test_key_ceremony.py:56:29: E1101: Instance of 'ElectionPolynomial' has no 'coefficient_proofs' member (no-member)
tests/unit/test_key_ceremony.py:57:21: E1101: Instance of 'ElectionPolynomial' has no 'coefficient_proofs' member (no-member)
Here's some quick help
src/electionguard/key_ceremony.py
https://github.com/microsoft/electionguard-python/blob/3a56cee6ba9cb722ab02d7bf885c87f8d788b0ee/src/electionguard/key_ceremony.py#L219-L221
This should be referencing the first coefficient like so:
key_pair = ElGamalKeyPair(
polynomial.coefficients[0].value, polynomial.coefficients[0].commitment
)tests/unit/test_key_ceremony.py
https://github.com/microsoft/electionguard-python/blob/3a56cee6ba9cb722ab02d7bf885c87f8d788b0ee/tests/unit/test_key_ceremony.py#L53-L59
The tests can change to be a bit more simple. The number of coefficients should equal the quorum and the proof line just needs to be adjusted.
self.assertEqual(len(election_key_pair.polynomial.coefficients), QUORUM)
for coefficient in election_key_pair.polynomial.coefficients:
self.assertTrue(coefficient.proof.is_valid())|
I've quite a few issues attempting to run the tests properly during the weekend. i was able to remove whitespaces and unused imports, but i am still trying to properly run all tests. |
keithrfung
left a comment
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.
See comment.
Issue
Fixes #473
Description
Refactored ElectionPolynomial to use a new PolynomialCoefficients dataclass.
Refactored references to ElectionPolynomial
Fixed a typo in the Build and Run guide.
Testing
Not sure if there was a better way to test these changes. I performed the test included in the Build and Run guide.