Skip to content

Commit

Permalink
Merge pull request #1 from PhABC/patch-1
Browse files Browse the repository at this point in the history
Pre-proof comments
  • Loading branch information
PhABC committed Sep 7, 2018
2 parents b6746b2 + e9e7ef1 commit 5151b19
Showing 1 changed file with 36 additions and 15 deletions.
51 changes: 36 additions & 15 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
w3 = Web3(HTTPProvider("http://localhost:8545"));

if __name__ == "__main__":

pk_output = "../zksnark_element/pk.raw"
vk_output = "../zksnark_element/vk.json"
pk_output = "../zksnark_element/pk.raw" # Prover key
vk_output = "../zksnark_element/vk.json" # Verifier key

#genKeys(c.c_int(noTx), c.c_char_p(pk_output.encode()) , c.c_char_p(vk_output.encode()))

Expand All @@ -47,16 +47,22 @@
S = []
old_leaf = []
new_leaf = []
rhs_leaf = []
rhs_leaf = [] # Message
address = []
public_key = []
sk = []
fee = 0


# Generate random public key
sk.append(genSalt(64))

# Public key from private key
public_key.append(ed.publickey(sk[0]))


# Empty right handside of first leaf
rhs_leaf.append(hashPadded("0"*64 , "0"*64)[2:])

# Iterate over transactions
for j in range (1,noTx + 1):

leaves.append([])
Expand All @@ -67,40 +73,55 @@


# create a random new leaf
# This is just a filler message for test purpose (e.g. 11111111... , 22222211111...)
rhs_leaf.append(hashPadded(hex(j)[2]*64 , "1"*64)[2:])


# The old leaf is previous pubkey + previous message
old_leaf.append(createLeaf(public_key[j-1], rhs_leaf[j-1]))

# The new leaf is current pubkey with current message
new_leaf.append(createLeaf(public_key[j], rhs_leaf[j]))


# The message to sign is the previous leaf with the new leaf
message = hashPadded(old_leaf[j-1], new_leaf[j-1])

# Remove '0x' from byte
message = message[2:]


# Obtain Signature
r,s = getSignature(message, sk[j - 1], public_key[j-1])

# check the signauer is correct
ed.checkvalid(r, s, message, public_key[j-1])

# now we reverse teh buplic key by bit
# Now we reverse the puplic key by bit
# we have to reverse the bits so that the
# unpacker in libsnark will return us the
# correct field element
# correct field element
# To put into small endian?
pub_key_x = hex(int(''.join(str(e) for e in hexToBinary(hex(public_key[j-1][0]))[::-1]),2))
pub_key_y = hex(int(''.join(str(e) for e in hexToBinary(hex(public_key[j-1][1]))[::-1]),2))

r[0] = hex(int(''.join(str(e) for e in hexToBinary(hex(r[0]))[::-1]),2))
r[1] = hex(int(''.join(str(e) for e in hexToBinary(hex(r[1]))[::-1]),2))


# Two r on x and y axis of curve
R_x.append(r[0])
R_y.append(r[1])

# Store s
S.append(s)


# Store public key
pub_x.append(pub_key_x)
pub_y.append(pub_key_y)



leaves[j-1].append(old_leaf[j-1])

address.append(0)

# Get zk proof and merkle root
proof, root = genWitness(leaves, pub_x, pub_y, address, tree_depth,
rhs_leaf, new_leaf , R_x, R_y, S)

Expand Down

0 comments on commit 5151b19

Please sign in to comment.