Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- from binascii import unhexlify
- from pure25519.basic import Zero, L, bytes_to_unknown_group_element
- import urllib2
- import json
- from retrying import retry
- ORDERS = {1: "1", 2: "2", 4: "4", 8: "8",
- 1*L: "1*L", 2*L: "2*L", 4*L: "4*L", 8*L: "8*L"}
- def get_order(e):
- for o in sorted(ORDERS):
- if e.scalarmult(o) == Zero:
- return o
- @retry(stop_max_attempt_number=20, wait_fixed=2000)
- def get_block_transactions(height):
- s = urllib2.urlopen("http://chainradar.com/api/v1/bcn/blocks/%s/full" % height)
- block = json.loads(s.read())
- transactions = block["transactions"]
- return transactions
- @retry(stop_max_attempt_number=20, wait_fixed=2000)
- def get_tx_inputs(tx_hash):
- s = urllib2.urlopen("http://chainradar.com/api/v1/bcn/transactions/%s/full" % tx_hash)
- tx = json.loads(s.read())
- inputs = tx["inputs"]
- return inputs
- #change block height range as necessary
- for blockHeight in range(1267197, 1269965):
- print "==== block height %s ====" % blockHeight
- #print json.dumps(block, indent=4)
- transactions = get_block_transactions(blockHeight)
- tx_hashes = [tx["hash"] for tx in transactions]
- for tx_hash in tx_hashes:
- print "tx:", tx_hash
- inputs = get_tx_inputs(tx_hash)
- #print inputs
- keyimages = [str(i.get("kImage")) for i in inputs if i.get("kImage")]
- print "key images: %s" % (keyimages,)
- for ki in keyimages:
- try:
- elem = bytes_to_unknown_group_element(unhexlify(ki))
- order = get_order(elem)
- if order != L:
- print "*** keyimage %s order %s" % (ki, ORDERS[order])
- with open("bad_keyimages", "a") as f:
- f.write("%s\n" % ki)
- except Exception, e:
- print e
- print "Bad keyimage", ki
- with open("bad_keyimages", "a") as f:
- f.write("%s\n" % ki)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement