def test_create_merkle_proof(self):
     empty_val = b'\x00' * 32
     dummy_val = b'\x01' * 32
     leaves = {0: dummy_val, 2: dummy_val, 3: dummy_val}
     tree = SparseMerkleTree(depth=3, leaves=leaves)
     mid_left_val = sha3(dummy_val + empty_val)
     mid_right_val = sha3(dummy_val + dummy_val)
     assert tree.create_merkle_proof(0) == empty_val + mid_right_val
     assert tree.create_merkle_proof(1) == dummy_val + mid_right_val
     assert tree.create_merkle_proof(2) == dummy_val + mid_left_val
     assert tree.create_merkle_proof(3) == dummy_val + mid_left_val
Example #2
0
 def merklize_transaction_set(self):
     hashed_transaction_dict = {
         tx.uid: tx.merkle_hash
         for tx in self.transaction_set
     }
     self.merkle = SparseMerkleTree(257, hashed_transaction_dict)
     return self.merkle.root
 def test_empty_right_leave(self):
     empty_val = b'\x00' * 32
     dummy_val = b'\x01' * 32
     leaves = {0: dummy_val, 2: dummy_val, 3: dummy_val}
     tree = SparseMerkleTree(depth=3, leaves=leaves)
     mid_left_val = sha3(dummy_val + empty_val)
     mid_right_val = sha3(dummy_val + dummy_val)
     assert tree.root == sha3(mid_left_val + mid_right_val)
Example #4
0
def userA_tries_to_double_spend_some_eth_to_userC(context, amount):
    invalid_tx = Transaction(DEPOSIT_TX_BLOCK, uid, 1, utils.normalize_address(userC))
    invalid_tx.sign(utils.normalize_key(userA_key))
    invalid_tx_merkle = SparseMerkleTree(257, {uid: invalid_tx.merkle_hash})

    root_chain = container.get_root_chain()
    root_chain.functions.submitBlock(invalid_tx_merkle.root, TRANSFER_TX_2_BLOCK).transact({
        'from': operator
    })
Example #5
0
def userC_starts_to_exit_some_eth_from_plasma_cash(context, amount):
    client = container.get_client()

    deposit_block = client.get_block(DEPOSIT_TX_BLOCK)
    deposit_tx = deposit_block.get_tx_by_uid(uid)
    deposit_block.merklize_transaction_set()
    deposit_tx_proof = deposit_block.merkle.create_merkle_proof(uid)

    # invalid tx doesn't exist in child chain
    invalid_tx = Transaction(DEPOSIT_TX_BLOCK, uid, 1,
                             utils.normalize_address(userC))
    invalid_tx.sign(utils.normalize_key(userA_key))
    invalid_tx_merkle = SparseMerkleTree(257, {uid: invalid_tx.merkle_hash})
    invalid_tx_proof = invalid_tx_merkle.create_merkle_proof(uid)

    root_chain = container.get_root_chain()
    root_chain.functions.startExit(
        rlp.encode(deposit_tx), deposit_tx_proof, DEPOSIT_TX_BLOCK,
        rlp.encode(invalid_tx), invalid_tx_proof,
        TRANSFER_TX_2_BLOCK).transact({'from': userC})
    time.sleep(5)
 def test_all_leaves_with_val(self):
     dummy_val = b'\x01' * 32
     leaves = {0: dummy_val, 1: dummy_val, 2: dummy_val, 3: dummy_val}
     tree = SparseMerkleTree(depth=3, leaves=leaves)
     mid_level_val = sha3(dummy_val + dummy_val)
     assert tree.root == sha3(mid_level_val + mid_level_val)
 def test_exceed_tree_size(self):
     with pytest.raises(SparseMerkleTree.TreeSizeExceededException):
         SparseMerkleTree(depth=1, leaves={0: '0', 1: '1'})
 def test_empty_leaves(self):
     tree = SparseMerkleTree(depth=3)
     empty_val = b'\x00' * 32
     mid_level_val = sha3(empty_val + empty_val)
     assert tree.root == sha3(mid_level_val + mid_level_val)