Skip to content
This repository has been archived by the owner on Aug 22, 2019. It is now read-only.

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidKnott committed Jan 18, 2018
1 parent 60870f1 commit 35f5340
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 39 deletions.
5 changes: 3 additions & 2 deletions plasma/child_chain/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Block(rlp.Serializable):
('sig', binary),
]

def __init__(self, transaction_set = [], sig = b'\x00' * 65):
def __init__(self, transaction_set=[], sig=b'\x00' * 65):
self.transaction_set = transaction_set
self.sig = sig
self.merkle = None
Expand All @@ -32,7 +32,8 @@ def sender(self):
@property
def merkilize_transaction_set(self):
hashed_transaction_set = [transaction.hash for transaction in self.transaction_set]
self.merkle = FixedMerkle(16, hashed_utxo_set).root
self.merkle = FixedMerkle(16, hashed_transaction_set).root
return self.merkle


UnsignedBlock = Block.exclude(['sig'])
15 changes: 7 additions & 8 deletions plasma/child_chain/transaction.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import rlp
from rlp.sedes import big_endian_int, binary
from ethereum import utils
from plasma.config import plasma_config
from plasma.utils.utils import get_sender, sign


Expand All @@ -23,14 +22,13 @@ class Transaction(rlp.Serializable):
('sig2', binary),
]

# fields
def __init__(self, blknum1, txindex1, oindex1,
blknum2, txindex2, oindex2,
newowner1, amount1,
newowner2, amount2,
fee,
sig1 = b'\x00' * 65,
sig2 = b'\x00' * 65):
blknum2, txindex2, oindex2,
newowner1, amount1,
newowner2, amount2,
fee,
sig1=b'\x00' * 65,
sig2=b'\x00' * 65):
# Input 1
self.blknum1 = blknum1
self.txindex1 = txindex1
Expand Down Expand Up @@ -81,4 +79,5 @@ def sender1(self):
def sender2(self):
return get_sender(self.hash, self.sig2)


UnsignedTransaction = Transaction.exclude(['sig1', 'sig2'])
7 changes: 4 additions & 3 deletions plasma/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from ethereum.tools import tester as t


plasma_config = dict(
root_chain_address=None,
AUTHORITY = t.a0,
AUTHORITY_KEY = t.k0,
)
AUTHORITY=t.a0,
AUTHORITY_KEY=t.k0,
)
23 changes: 11 additions & 12 deletions plasma/root_chain/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
from web3.contract import ConciseContract
from web3 import Web3, HTTPProvider


OWN_DIR = os.path.dirname(os.path.realpath(__file__))


class Deployer(object):

def __init__(self, provider=HTTPProvider('http://localhost:8545')):
self.w3 = Web3(provider)

def get_dirs(self,path):
def get_dirs(self, path):
abs_contract_path = os.path.realpath(os.path.join(OWN_DIR, 'contracts'))
extra_args = [[file, [os.path.realpath(os.path.join(r,file))]] for r,d,f in os.walk(abs_contract_path) for file in f]
extra_args = [[file, [os.path.realpath(os.path.join(r, file))]] for r, d, f in os.walk(abs_contract_path) for file in f]
contracts = {}
for contract in extra_args:
contracts[contract[0]] = {'urls': contract[1]}
Expand All @@ -27,25 +29,22 @@ def compile_contract(self, path, args=()):
file_name = path.split('/')[1]
contract_name = file_name.split('.')[0]
path, contracts = self.get_dirs(path)

compiled_sol = compile_standard(
{'language': 'Solidity',
'sources': {**{path.split('/')[-1]: {'urls': [path]}}, **contracts},
},
allow_paths=OWN_DIR + "/contracts")
compiled_sol = compile_standard({'language': 'Solidity',
'sources': {**{path.split('/')[-1]: {'urls': [path]}}, **contracts}}, # Noqa E999
allow_paths=OWN_DIR + "/contracts")
abi = compiled_sol['contracts'][file_name][contract_name]['abi']
bytecode = compiled_sol['contracts'][file_name][contract_name]['evm']['bytecode']['object']
contract_file = open("contract_data/%s.json" % (file_name.split('.')[0]),"w+")
contract_file = open("contract_data/%s.json" % (file_name.split('.')[0]), "w+")
json.dump(abi, contract_file)
contract_file.close()
return abi, bytecode

def create_contract(self, path, args=(), sender=t.k0):
def create_contract(self, path, args=(), gas=4410000, sender=t.k0):
abi, bytecode = self.compile_contract(path, args)
contract= self.w3.eth.contract(abi=abi, bytecode=bytecode)
contract = self.w3.eth.contract(abi=abi, bytecode=bytecode)

# Get transaction hash from deployed contract
tx_hash = contract.deploy(transaction={'from': self.w3.eth.accounts[0], 'gas': 4410000}, args=args)
tx_hash = contract.deploy(transaction={'from': self.w3.eth.accounts[0], 'gas': gas}, args=args)

# Get tx receipt to get contract address
tx_receipt = self.w3.eth.getTransactionReceipt(tx_hash)
Expand Down
13 changes: 6 additions & 7 deletions plasma/utils/merkle/fixed_merkle.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .node import Node
from ethereum.utils import sha3


class FixedMerkle(object):

def __init__(self, depth, leaves=[], hashed=False):
Expand All @@ -25,22 +26,21 @@ def create_tree(self, leaves):
next_level = len(leaves)
tree_level = []
for i in range(0, next_level, 2):
combined = sha3(leaves[i].data + leaves[i+1].data)
next_node = Node(combined, leaves[i], leaves[i+1])
combined = sha3(leaves[i].data + leaves[i + 1].data)
next_node = Node(combined, leaves[i], leaves[i + 1])
tree_level.append(next_node)
self.tree.append(tree_level)
self.create_tree(tree_level)


def check_membership(self, leaf, index, proof):
if not self.hashed:
leaf = sha3(leaf)
computed_hash = leaf
for i in range(0, self.depth*32, 32):
segment = proof[i:i+32]
for i in range(0, self.depth * 32, 32):
segment = proof[i:i + 32]
if index % 2 == 0:
computed_hash = sha3(computed_hash + segment)
else:
else:
computed_hash = sha3(segment + computed_hash)
index = index // 2
return computed_hash == self.root
Expand All @@ -60,7 +60,6 @@ def create_membership_proof(self, leaf):
proof += self.tree[i][sibling_index].data
return proof


def is_member(self, leaf):
return leaf in self.leaves

Expand Down
4 changes: 2 additions & 2 deletions plasma/utils/merkle/node.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Node(object):

def __init__(self, data, left=None, right=None):
self.data = data
self.left = left
self.right = right
self.right = right
13 changes: 8 additions & 5 deletions plasma/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
import rlp
from ethereum import utils as u
from ethereum import transactions, messages
from plasma.utils.merkle.fixed_merkle import FixedMerkle


def get_empty_merkle_tree_hash(depth):
zeroes_hash = b'\x00' * 32
for i in range(depth):
zeroes_hash = u.sha3(zeroes_hash + zeroes_hash)
return zeroes_hash


def get_merkle_of_leaves(depth, leaves):
return FixedMerkle(depth, leaves)


def bytes_fill_left(inp, length):
return bytes(length-len(inp)) + inp
return bytes(length - len(inp)) + inp


ZEROS_BYTES = [b'\x00' * 32]


def confirm_tx(tx, root, key):
return sign(u.sha3(tx.hash + tx.sig1 + tx.sig2 + root), key)


def sign(hash, key):
vrs = u.ecsign(hash, key)
rsv = vrs[1:] + vrs[:1]
vrs_bytes = [u.encode_int32(i) for i in rsv[:2]] + [u.int_to_bytes(rsv[2])]
return b''.join(vrs_bytes)


def get_sender(hash, sig):
v = sig[64]
if v < 27:
Expand All @@ -34,5 +39,3 @@ def get_sender(hash, sig):
s = u.bytes_to_int(sig[32:64])
pub = u.ecrecover_to_pub(hash, v, r, s)
return u.sha3(pub)[-20:]


0 comments on commit 35f5340

Please sign in to comment.