Skip to content
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

More feature to betterpairing added and some refactoring performed #177

Merged
merged 1 commit into from
Feb 19, 2019
Merged

Conversation

nqyy
Copy link
Contributor

@nqyy nqyy commented Feb 11, 2019

  1. Added some new methods in classes from betterpairing: G1, G2.
  2. Added a new class to betterpairing: GT.
  3. On the rust side, new class PyFq6 is added to lib.rs
  4. New rust method vec_sum is added.
  5. Some refactoring is performed on betterpairing.py

Copy link
Contributor Author

@nqyy nqyy left a comment

Choose a reason for hiding this comment

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

Some comments by me.

if type(other) is ZR:
self.val.add_assign(other.val)
return self
elif type(other) is int:
if other < 0:
other *= 1
other *= -1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is a bug.

Copy link
Contributor

@amiller amiller Mar 2, 2019

Choose a reason for hiding this comment

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

other *= -1 can be different than other = other * -1.
The difference is *= applied to an object actually runs the __imul__ operator, which for the ZR G1 etc objects we have here, performs modifications in place. I suspect this is the cause of problems

That can't be it, as I can't find any examples where this is applied to anything except an int

if type(other) is ZR:
self.val.sub_assign(other.val)
return self
elif type(other) is int:
if other < 0:
other *= 1
other *= -1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above.

fq12 = PyFq12()
self.pyg1.py_pairing_with(other.pyg2, fq12)
return GT(fq12)

@staticmethod
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we need @staticmethod. Don't know why it was taken out.


# TODO: __truediv__ needs to be implemented

# TODO: __pow__ needs to be implemented
Copy link
Contributor Author

Choose a reason for hiding this comment

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

__truediv__ and __pow__ are not implemented. They are called below.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should narrow this interface abstraction a bit. G1 G2 and GT are both groups, but G1 and G2 are additive notation (you can add two points together, but not multiply them together).

Now the slightly confusing thing is that GT is actually defined as the finite field Fq12.... and in general finite fields support multiplication as well as addition. However, the GT class should probably not expose __add__ at all.

@amiller
Copy link
Contributor

amiller commented Feb 12, 2019

You have a few easy flake8 things to fix before you get the all greens :)

negone = PyFr(str(1))
negone.negate()
self.pyg1.mul_assign(negone)
self.pyg1.mul_assign(PyFr(str(1)).negate())
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe premature optimization - but this looks like an easy candidate for caching.

Separately - It always irks me to see serialization/deserialization to decimal numbers as the way of communicating with an FFI -- we're encountering this in bindings to the C++ NTL library too so I don't have a solution in mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see.

@@ -214,7 +235,8 @@ def __truediv__(self, other):
out.sub_assign(other.pyg2)
return G2(out)
else:
raise TypeError
raise TypeError(
'Invalid division param. Expected G1. Got ' + str(type(other)))
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks, much more helpful

}

#[pyfunction]
fn vec_sum(a: &PyList) -> PyResult<String>{
Copy link
Contributor

Choose a reason for hiding this comment

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

nice, useful sum tool to expose

@@ -474,6 +483,24 @@ impl PyFq2 {
}
}

#[pyclass]
struct PyFq6 {
Copy link
Contributor

Choose a reason for hiding this comment

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

what do we need Fq6 exposed in python for?

Copy link
Contributor

@amiller amiller left a comment

Choose a reason for hiding this comment

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

Changes requested:

  1. Clarify or justify why the exposed methods are appropriate, mainly I think addition in the GT group should be removed, and I don't see why Fq6 and Fq2 should be exposed
  2. There are several new functions added but no tests, can we add those?

@nqyy
Copy link
Contributor Author

nqyy commented Feb 18, 2019

Flake8 issues are fixed. Some implementation reasons or details can be answered by @tyurek . Currently there is no test for betterpairing, so I am trying to write some tests for it.

@amiller
Copy link
Contributor

amiller commented Feb 19, 2019

I'm OK to accept this and move on!

@smkuls
Copy link
Contributor

smkuls commented Feb 19, 2019

@chitianhao Can you squash all the commits?

@nqyy
Copy link
Contributor Author

nqyy commented Feb 19, 2019

Squashed and rebased. @smkuls

1. Added some new methods in classes from betterpairing: G1, G2.
2. Added a new class to betterpairing: GT.
3. On the rust side, new class PyFq6 is added to lib.rs
4. New rust method vec_sum is added.
5. Some refactoring is performed on betterpairing.py
@smkuls smkuls merged commit b65e7a4 into initc3:dev Feb 19, 2019
smkuls pushed a commit that referenced this pull request Feb 20, 2019
out = PyG1()
out.zero()
return G1(out)
return G1(PyG1().zero())
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the problem - PyG1.zero() zeroes out the element in place and returns None, rather than returning the PyG1 interest.

@amiller amiller mentioned this pull request Mar 2, 2019
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