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

ON HOLD: Double spending prevention using Secp256k1 keys on TrustChain #68

Closed
wants to merge 3 commits into from

Conversation

xoriole
Copy link
Contributor

@xoriole xoriole commented Mar 5, 2018

Double spending prevention using Secp256k1 signatures on transactions.

@tribler-ci
Copy link
Collaborator

Can one of the admins verify this patch?

@xoriole xoriole changed the title Double spending prevention using Secp256k1 keys on TrustChain WIP: Double spending prevention using Secp256k1 keys on TrustChain Mar 5, 2018
@xoriole xoriole requested a review from qstokkink March 5, 2018 15:15
Copy link
Collaborator

@qstokkink qstokkink left a comment

Choose a reason for hiding this comment

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

It doesn't pass the tests 🙍

@xoriole xoriole force-pushed the double_spending_prevention branch 8 times, most recently from b01940f to b30809a Compare March 6, 2018 09:40
@qstokkink
Copy link
Collaborator

retest this please

1 similar comment
@qstokkink
Copy link
Collaborator

retest this please

@@ -273,6 +290,14 @@ def err(reason):
linklinked = database.get_linked(link)
if linklinked is not None and linklinked.hash != self.hash:
err("Double countersign fraud")
if 'double_sig' in self.transaction and self.transaction['double_sig'] \
and 'double_sig' in linklinked.transaction and linklinked.transactino['double_sig']:
Copy link
Collaborator

Choose a reason for hiding this comment

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

transactino?

@xoriole xoriole force-pushed the double_spending_prevention branch from 9818aeb to 265fc07 Compare March 7, 2018 09:19
return self.point(x, y)

def sub(self, lhs, rhs):
return lhs + -rhs
Copy link
Collaborator

Choose a reason for hiding this comment

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

+ - is redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the way it should be. Point negation and addition.

test/util.py Outdated
@@ -166,4 +166,4 @@ def twisted_wrapper(arg):
"""
if isinstance(arg, (int, long)):
return lambda x: deferred(arg)(inlineCallbacks(x))
return deferred(timeout=1)(inlineCallbacks(arg))
return deferred(timeout=10)(inlineCallbacks(arg))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please change this per test, not globally.

@xoriole xoriole force-pushed the double_spending_prevention branch 9 times, most recently from 1d6dc0d to 3e3f2e5 Compare March 7, 2018 11:13
@xoriole
Copy link
Contributor Author

xoriole commented Mar 7, 2018

retest this please

@xoriole xoriole force-pushed the double_spending_prevention branch 2 times, most recently from 52790c6 to f9fbb01 Compare March 7, 2018 12:56
@xoriole
Copy link
Contributor Author

xoriole commented Mar 7, 2018

retest this please

@qstokkink
Copy link
Collaborator

test/keyvault/test_doublesign.py needs to be added to https://github.com/Tribler/py-ipv8/blob/master/test_classes_list.txt

xoriole added 2 commits March 7, 2018 14:08
Updated test timeouts to fit for signatures
Changed test timeout

Using gmpy2 integer for field operations
@xoriole xoriole force-pushed the double_spending_prevention branch from 1367765 to 040ced3 Compare March 7, 2018 13:09
test/base.py Outdated
@@ -95,7 +95,7 @@ def add_node_to_experiment(self, node):
self.nodes.append(node)

@inlineCallbacks
def deliver_messages(self, timeout=.1):
def deliver_messages(self, timeout=10):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please don't change the base timeouts.

@xoriole xoriole force-pushed the double_spending_prevention branch from 040ced3 to 05f9674 Compare March 7, 2018 13:18
@qstokkink
Copy link
Collaborator

retest this please

@xoriole xoriole changed the title WIP: Double spending prevention using Secp256k1 keys on TrustChain READY: Double spending prevention using Secp256k1 keys on TrustChain Mar 7, 2018
@qstokkink qstokkink requested a review from devos50 March 9, 2018 15:24
@devos50
Copy link
Contributor

devos50 commented Mar 12, 2018

retest this please

7 similar comments
@devos50
Copy link
Contributor

devos50 commented Mar 12, 2018

retest this please

@devos50
Copy link
Contributor

devos50 commented Mar 12, 2018

retest this please

@devos50
Copy link
Contributor

devos50 commented Mar 12, 2018

retest this please

@devos50
Copy link
Contributor

devos50 commented Mar 12, 2018

retest this please

@devos50
Copy link
Contributor

devos50 commented Mar 12, 2018

retest this please

@devos50
Copy link
Contributor

devos50 commented Mar 12, 2018

retest this please

@devos50
Copy link
Contributor

devos50 commented Mar 12, 2018

retest this please

Copy link
Contributor

@devos50 devos50 left a comment

Choose a reason for hiding this comment

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

It looks ok but I have some minor comments.

In general, I would like to know more about the performance. Can we get some numbers to quantify the overhead of the double spend detection (not for this PR)?

@@ -2,6 +2,7 @@

import time

from ipv8.keyvault import doublesign
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we use relative imports everywhere?

@@ -117,8 +118,9 @@ def pack(self, signature=True):
:param signature: False to pack EMPTY_SIG in the signature location, true to pack the signature field
:return: the buffer the data was packed into
"""
raw_transaction = {i:self.transaction[i] for i in self.transaction if i != 'double_sig'}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a space after the first : for clarity.

@@ -292,15 +317,22 @@ def err(reason):
err("Next hash is not equal to the hash id of the block")
# Again, this might not be fraud, but fixing it can only result in fraud.

return result[0], errors
return result[0], errors, result[1]
Copy link
Contributor

Choose a reason for hiding this comment

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

We're already returning a tuple with three results now. Maybe we should convert to a namedtuple?


def sign(self, key):
def sign(self, key, double_sign=False):
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a docstring about the double_sign parameter 👍

@staticmethod
def double_spend():
"""
The block violates at least one validation rule
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the docstring match with the method name?

@@ -51,11 +51,13 @@ class TrustChainCommunity(Community):
def __init__(self, *args, **kwargs):
working_directory = kwargs.pop('working_directory', '')
db_name = kwargs.pop('db_name', self.DB_NAME)
double_sign = kwargs.pop('double_sign', False)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rename this to check_for_double_sign or something similar 👍


def is_valid_double_signature(self, data, signature):
"""
Returns True if signature is valid
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor detail: please be consistent with ending docstrings with a period or not :)

@qstokkink qstokkink changed the title READY: Double spending prevention using Secp256k1 keys on TrustChain ON HOLD: Double spending prevention using Secp256k1 keys on TrustChain Apr 19, 2018
@qstokkink
Copy link
Collaborator

retest this please

@qstokkink
Copy link
Collaborator

Merged into the nuclear_backdoor branch.

@qstokkink qstokkink closed this Oct 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants