added sha proof on reveal

This commit is contained in:
Jarrad Hope 2015-07-26 18:54:56 +02:00
parent 585e1f57d8
commit 5e7186829e
3 changed files with 67 additions and 10 deletions

View File

@ -134,17 +134,20 @@ def add_sealed_offer(buy_ticket, hash):
return(key)
def reveal_offer(id, hash, buy_ticket, sell_ticket): # , preferences TODO
def reveal_offer(id, buy_ticket, sell_ticket, sha_proof:arr): # , preferences TODO
# TODO: maybe should be done over whisper?
# TODO: compare hash against hash of preferences
# TODO: ensure offer is valid
buyer = self.get_info(buy_ticket, outitems=1)[0]
seller = self.get_info(sell_ticket, outitems=1)[0]
if self.offers[id].owner == msg.sender:
# TODO: in reveal window?
hash = sha3(sha_proof:arr)
if hash == self.offers[id].hash:
buyer = self.get_info(buy_ticket, outitems=1)[0]
seller = self.get_info(sell_ticket, outitems=1)[0]
# TODO reveal for buyer/seller
log('reveal', buyer, buy_ticket, id)
log('reveal', seller, sell_ticket, id)
# check sha of offer
# TODO reveal for buyer/seller
log('reveal', buyer, buy_ticket, id)
log('reveal', seller, sell_ticket, id)
# def accept_offer(offer_id):
# # within accept blockchain number bounds

View File

@ -18,6 +18,9 @@ class Matchmaker:
current_block = -1
def debug(self, data):
print('debug', data)
def reveal_offers(self):
for offer in self.sealed_offers:
win_min = offer.epoch + self.SEALED_WINDOW
@ -26,19 +29,25 @@ class Matchmaker:
if can_reveal:
print(self.name, 'revealing offer', offer.id)
self.market.reveal_offer(offer.id, offer.hash, offer.buy_id, offer.sell_id) # TODO preferences
# can probably encode all information in the proof
sha_proof = [offer.epoch, offer.buy_id, offer.sell_id]
self.market.reveal_offer(offer.id, offer.buy_id, offer.sell_id, sha_proof) # TODO preferences
self.sealed_offers.remove(offer)
def make_match(self, buyer, seller):
if buyer.epoch < self.current_block + self.SEALED_WINDOW:
print(self.name, 'making sealed offer', buyer.id, seller.id)
# TODO: check hash for adding sealed offer, ie hash preferences?
shasum = utils.sha3([buyer.epoch, buyer.id, seller.id])
# TODO: rework this, see reveal
hash_arr = [buyer.epoch, buyer.id, seller.id]
shasum = utils.sha3(''.join(map(lambda x: utils.zpad(utils.encode_int(x), 32), hash_arr)))
# shasum = utils.sha3(hash_arr)
# TODO check epoch against SEALED_WINDOW
offer_id = self.market.add_sealed_offer(buyer.id, shasum)
print(self.name, 'shasum', shasum)
print(self.name, 'shasum', utils.decode_int(shasum))
# TODO, combine preferences
# TODO rework this, can probably just have buyer and seller instead of id's only
offer = Offer(offer_id, buyer.epoch, buyer.id, seller.id, shasum, buyer.preferences)
self.sealed_offers.append(offer)

45
testhash.py Normal file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import bitcoin
from ethereum import tester, utils
state = tester.state()
# 0 288
# 100 288
# ('zpadhash', 92268809646399479600174377094284069493881770942972924356240893702142402791897L)
# ('sha3int_zpad', 27004694829266425565490061128739172021375112860617960595218055460725948937951L)
# ('sha3int', 27004694829266425565490061128739172021375112860617960595218055460725948937951L)
# 0 270
# 200 270
# ('hash_arr', 8151782650644729368062958368917604144436969866772708851468873220389632519965L)
# ('hash_param', 7896341980786613614968953046582703950699541199067738665672778972695176727887L)
# ('hash_param_zpad', 7896341980786613614968953046582703950699541199067738665672778972695176727887L)
# ('hash_hardcode', 7896341980786613614968953046582703950699541199067738665672778972695176727887L)
# [Finished in 0.6s]
code = '''
def hash_arr(test:arr):
return(sha3(test:arr):uint256)
def hash_param(a, b, c):
return(sha3([a, b, c]:arr):uint256)
def foo():
return(sha3([0, 0, 1]:arr):uint256)
'''
# hash_arr also gives wildly different results depending on hash_param existence
hashtest = state.abi_contract(code)
tmp = [0, 0, 1]
print('hash_arr', hashtest.hash_arr(tmp))
print('hash_param', hashtest.hash_param(tmp[0], tmp[0], tmp[0]))
print(hashtest.foo())
a = utils.sha3(''.join(map(lambda x: utils.zpad(utils.encode_int(x), 32), tmp)))
print(utils.decode_int(a))