Opened 8 months ago

Closed 8 months ago

Last modified 8 months ago

#21102 closed defect (fixed)

Shared Random Not Parsing Correctly

Reported by: tom Owned by: atagar
Priority: Medium Milestone:
Component: Core Tor/Stem Version:
Severity: Normal Keywords:
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

None of the shared random attributes are being parsed or populated on votes:

Latest stem version: 32ec5374c73b8c5f93d30723b629736a4070f314

>>> import stem
>>> from stem.descriptor import DocumentHandler
>>> from stem.descriptor.remote import DescriptorDownloader, get_authorities
>>>
>>> downloader = DescriptorDownloader()
>>> query = downloader.get_vote(get_authorities()['moria1'], document_handler = DocumentHandler.DOCUMENT, validate = False)
>>> r = query.run()[0]
>>> r.is_shared_randomness_participate
False
>>> r.shared_randomness_commitments
[]
>>> r.shared_randomness_previous_reveal_count
>>> r.shared_randomness_previous_value
>>> r.shared_randomness_current_reveal_count
>>> r.shared_randomness_current_value
>>> lines = r._raw_contents.split("\n")
>>> sharedlines = [bob for bob in lines if "shared" in bob]
>>> sharedlines
['shared-rand-participate', 'shared-rand-commit 1 sha3-256 0232AF901C31A04EE9848595AF9BB7620D4C5B2E AAAAAFhkUgDfD5O57GTaW03nOXG6NYzK5d4pbl5bvY0Gl+ltdeDWJw==', 'shared-rand-commit 1 sha3-256 14C131DFC5C6F93646BE72FA1401C02A8DF2E8B4 AAAAAFhkUgB1DTDby0B2+4wR/BT50pNinCALsi7dAfB7K6WcFBCXYg==', 'shared-rand-commit 1 sha3-256 23D15D965BC35114467363C165C4F724B64B4F66 AAAAAFhkUgAZDvoCYkpssoN4ths9bsf6JF+XoT3XpEaVbLwHTEoGFg==', 'shared-rand-commit 1 sha3-256 49015F787433103580E3B66A1707A00E60F2D15B AAAAAFhkUgDhiYVny8VXGIz/+swCKcuRTy25JaZpQYQqJ3aiFqTTxg==', 'shared-rand-commit 1 sha3-256 D586D18309DED4CD6D57C18FDB97EFA96D330566 AAAAAFhkUgDN/MbqvEG3IMLiAGv/MLp1arbCKGZFwLAptgYFY/N4qQ==', 'shared-rand-commit 1 sha3-256 E8A9C45EDE6D711294FADF8E7951F4DE6CA56B58 AAAAAFhkUgCcnmLxs4+uPPHJrTnOMH+ZgfJ289AjbI/+ZI62sIJRcQ==', 'shared-rand-commit 1 sha3-256 ED03BB616EB2F60BEC80151114BB25CEF515B226 AAAAAFhkUgD159ckYKLunWoreLKfCV/Rsmv5hel5TaX4SifHIC3/8g==', 'shared-rand-previous-value 7 1giXfU4CDR2aqxPprE2tx/Y/QXM8EmSJN+yyfs0UBhk=', 'shared-rand-current-value 6 oKd3173SXw2YYMgsWTDelUlpR5VlD/lFt264S2140R0=']

Child Tickets

Change History (10)

comment:1 Changed 8 months ago by atagar

Thanks Tom. This is probably because the addition's incorrect in the spec...

https://trac.torproject.org/projects/tor/ticket/21059

It's detailed as being part of the consensus header but is in the authority section instead.

comment:2 Changed 8 months ago by atagar

Resolution: fixed
Status: newclosed

Thanks for pointing this out! Fix pushed.

Shared randomness are properties of the DirectoryAuthority class rather than the header. Votes always have a single authority so here's how you fetch them...

for commitment in vote.directory_authorities[0].shared_randomness_commitments:
  print commitment

Possible I missed something. I'll be using these for #17434 so that should flush out any further issues. Figured better to push this out earlier than later though so you could take advantage of it.

comment:3 Changed 8 months ago by tom

Thanks this seems to be working now, although I think the properties are still present on the vote object itself also? is that intentional?

>>> import stem
>>> from stem.descriptor import DocumentHandler
>>> from stem.descriptor.remote import DescriptorDownloader, get_authorities
>>> downloader = DescriptorDownloader()
>>> query = downloader.get_vote(get_authorities()['moria1'], document_handler = DocumentHandler.DOCUMENT, validate = False)
>>> r = query.run()[0]
>>> r.is_shared_randomness_participate
False
>>> r.directory_authorities[0].is_shared_randomness_participate
True
>>> r.shared_randomness_previous_reveal_count
>>> r.directory_authorities[0].shared_randomness_previous_reveal_count
6
>>> r.unknown_properties_should_error_right
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "stem/descriptor/__init__.py", line 661, in __getattr__
    return super(Descriptor, self).__getattribute__(name)
AttributeError: 'NetworkStatusDocumentV3' object has no attribute 'unknown_properties_should_error_right'

comment:4 Changed 8 months ago by atagar

I can't outright remove the old attributes because they're documented as existing in the Stem 1.5 release. As such I've removed them from the documentation but left the broken attributes as they were...

https://gitweb.torproject.org/stem.git/tree/stem/descriptor/networkstatus.py#n907

comment:5 Changed 8 months ago by tom

Sorry, but I cannot find the shared random attributes on the consensus object...

comment:6 Changed 8 months ago by atagar

Which attributes do you mean? In taking a quick peek at a consensus the only shared randomness line I see is. Seems the rest are exclusive to votes.

comment:7 Changed 8 months ago by tom

There should be shared_randomness_current_reveal_coun, shared_randomness_current_value, shared_randomness_previous_reveal_count, and shared_randomness_previous_value but I don't get values from them.... (even from .directory_authorities[0]. like for the vote object)

>>> from stem.descriptor import DocumentHandler
>>> from stem.descriptor.remote import DescriptorDownloader
>>>
>>> downloader = DescriptorDownloader()
>>> consensus = downloader.get_consensus(document_handler = DocumentHandler.DOCUMENT).run()[0]
>>> consensus.shared_randomness_current_value
>>> consensus.directory_authorities[0].shared_randomness_current_value

comment:8 Changed 8 months ago by atagar

Ah, I see the issue. Current and previous values should be in the header for consensuses and authority section for votes. Fixed...

https://gitweb.torproject.org/stem.git/commit/?id=d713b29

To be clear those are the only two values that looks like they should be in the consensus. Unless I'm missing something the rest are exclusive to votes. Seems also that the previous value isn't always present...

% grep shared consensus
shared-rand-current-value 6 nwr/w2uC49g/ZxbGpshs0w2nqWWqCsrHWzQhkuelAgA=

comment:9 in reply to:  8 Changed 8 months ago by dgoulet

Replying to atagar:

To be clear those are the only two values that looks like they should be in the consensus. Unless I'm missing something the rest are exclusive to votes. Seems also that the previous value isn't always present...

Correct. Consensus _only_ have the shared-rand-current-value and shared-rand-previous-value. Vote have the commit line(s) and the shared values. Note that they can be absent from a vote or a consensus. Also, the vote has a shared-rand-participate field that indicate if the authority will participate in the computation of the share value. If that line is absent, ALL commit/srv should be ignored.

comment:10 Changed 8 months ago by tom

Thanks all, I got it working and was able to close out #20763

Note: See TracTickets for help on using tickets.