Esempio n. 1
0
                       separators=(', ', ': ')))
        print("---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----")

    # Generate Transaction intents and Dependency Graph
    tx_intents = TransactionIntents(op_intents,
                                    op_intents_json['dependencies'])
    for tx_intent in tx_intents._intents:
        print("---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----")
        print("Transaction Chain-ID:", tx_intent.chain_host)
        print(
            "Transaction information:",
            json.dumps(tx_intent.jsonize(),
                       sort_keys=True,
                       indent=4,
                       separators=(', ', ': ')))
        dappx = DApp(tx_intent.jsonize()['from'])
        print("---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----")

    with open('txintents.json', 'w') as tx_intents_file:
        tx_intents_file.write(tx_intents.jsonize())
'''Sample Output
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
{
    "amount": 1000, 
    "dst": {
        "domain": "Ethereum://chain2", 
        "user_name": "Y"
    }, 
    "name": "Op1", 
    "op_type": "Payment", 
    "src": {
Esempio n. 2
0
# python modules

# uip modules
from uiputils.ethtools import FileLoad, JsonRPC
from ves import VerifiableExecutionSystem
from dapp import DApp
from uiputils.transaction import StateType
import time


# config
from uiputils.config import HTTP_HEADER, alice, bob, tom

from uiputils.loggers import console_logger

from py_nsbcli.modules.admin import set_admin_singleton_mode
set_admin_singleton_mode(False)

if __name__ == '__main__':
    # 029a
    tot_time = time.perf_counter()
    # prepare
    ves = VerifiableExecutionSystem()
    dapp_x = DApp(info_x)
    dapp_y = DApp(info_y)
    ves.appenduserlink([dapp_x, dapp_y])

    console_logger.info('{0} built, info:{1}'.format(dapp_x, dapp_x.info))
    console_logger.info('{0} built, info:{1}'.format(dapp_y, dapp_y.info))
    console_logger.info('{0} built, info:{1}'.format(ves, ves.__dict__))
Esempio n. 3
0
}


def unlock_user(user):
    unlock = JsonRPC.personal_unlock_account(user['name'], user['passphrase'],
                                             20)
    response = JsonRPC.send(unlock, HTTP_HEADER, user['domain'])
    if not response['result']:
        raise ValueError("unlock failed. wrong password?")


if __name__ == '__main__':

    # prepare
    ves = VerifiableExecutionSystem()
    dapp_x = DApp(info_x)
    dapp_y = DApp(info_y)
    ves.appenduserlink([dapp_x, dapp_y])

    console_logger.info('{0} built, info:{1}'.format(dapp_x, dapp_x.info))
    console_logger.info('{0} built, info:{1}'.format(dapp_y, dapp_y.info))
    console_logger.info('{0} built, info:{1}'.format(ves, ves.__dict__))

    # load Sample.json
    op_intents_json = FileLoad.getopintents("./opintents2.json")

    for intent in op_intents_json['Op-intents']:
        intent['contract_domain'] = "Ethereum://" + intent['contract_domain']

    session_content, isc, session_signature, tx_intents = ves.session_setup_prepare(
        op_intents_json)
Esempio n. 4
0
        get_tx = JsonRPC.eth_get_transaction_receipt(resp)
        while True:
            response = JsonRPC.send(get_tx, HTTP_HEADER, host)
            print("result", response)
            break
            # if response['result'] is None:
            #     print("Exec...", resp)
            #     time.sleep(5)


if __name__ == '__main__':
    # 029a
    tot_time = time.perf_counter()
    # prepare
    ves = VerifiableExecutionSystem()
    dapp_x = DApp(info_x)
    dapp_y = DApp(info_y)
    ves.appenduserlink([dapp_x, dapp_y])

    console_logger.info('{0} built, info:{1}'.format(dapp_x, dapp_x.info))
    console_logger.info('{0} built, info:{1}'.format(dapp_y, dapp_y.info))
    console_logger.info('{0} built, info:{1}'.format(ves, ves.__dict__))

    # load Sample.json
    op_intents_json = FileLoad.getopintents("./opintents5.json")

    # for intent in op_intents_json['Op-intents']:
    #     intent['contract_domain'] = "Ethereum://" + intent['contract_domain']

    session_content, isc, session_signature, tx_intents = ves.session_setup_prepare(
        op_intents_json)
def e2e_execution():
    # prepare
    ves = VerifiableExecutionSystem()
    dapp_x = DApp(info_x)
    dapp_y = DApp(info_y)
    dapp_z = DApp(info_z)
    ves.appenduserlink([dapp_x, dapp_y, dapp_z])

    console_logger.info('{0} built, info:{1}'.format(dapp_x, dapp_x.info))
    console_logger.info('{0} built, info:{1}'.format(dapp_y, dapp_y.info))
    console_logger.info('{0} built, info:{1}'.format(dapp_z, dapp_z.info))
    console_logger.info('{0} built, info:{1}'.format(ves, ves.__dict__))

    # load Sample.json
    op_intents_json = FileLoad.getopintents("./test/opintents4.json")

    # for intent in op_intents_json['Op-intents']:
    #     intent['contract_domain'] = "Ethereum://" + intent['contract_domain']

    latency_profile = LatencyProfile()
    tot_time = time.perf_counter()
    session_content, isc, session_signature, tx_intents = ves.session_setup_prepare(
        op_intents_json)
    dapp_x.ackinit(ves,
                   isc,
                   session_content,
                   session_signature,
                   ves.nsb.host,
                   testing=False)
    dapp_y.ackinit(ves,
                   isc,
                   session_content,
                   session_signature,
                   ves.nsb.host,
                   testing=False)
    dapp_z.ackinit(ves,
                   isc,
                   session_content,
                   session_signature,
                   ves.nsb.host,
                   testing=False)
    latency_profile.isc_init = time.perf_counter() - tot_time

    # print("raw: ", ves.address)
    # print(isc.is_owner(ves.address))
    # print(isc.is_raw_sender(ves.address))
    # print(isc.is_owner(dapp_x.info[ves.nsb.host]['address']))
    # print(isc.is_owner(dapp_y.info[ves.nsb.host]['address']))
    # print(isc.tx_info_length())
    # print(isc.get_isc_state())
    # print(ves.nsb.is_active_isc(isc.address))

    user_table = [
        (dapp_x, ves),
        (dapp_y, ves),
        (dapp_x, ves),
        (ves, dapp_z),
        (dapp_z, ves),
    ]
    session_id = int(session_content[0])

    tag_time = None
    tag_time_end = None
    atte_computation = []
    action_staking = []
    proof_retriveal = []
    print("prepare end..", time.perf_counter() - tot_time)
    for idx, [u, v] in enumerate(user_table):
        # assert tx_intent is on ISC

        # Part_A # inited ##############################################################################################

        print("compute on_chain_tx")
        tag_time = time.perf_counter()
        # compute on_chain_tx
        tx = tx_intents.intents[idx].jsonize()
        console_logger.info(
            'on chain transaction computed index: {0}, content: {1}'.format(
                idx, tx))
        tag_time_end = time.perf_counter() - tag_time
        print("compute on_chain_tx", tag_time_end)

        print("attestation inited")
        # compute attestation
        tag_time = time.perf_counter()
        atte = u.init_attestation(tx, StateType.inited, session_id, idx,
                                  ves.nsb.host)
        tag_time_end = time.perf_counter() - tag_time
        print("Atte computation", tag_time_end)
        atte_computation.append(tag_time_end)

        # send inited attestaion
        tag_time = time.perf_counter()
        ret = u.send_attestation(session_id, atte, idx, StateType.inited,
                                 ves.nsb.host)
        tag_time_end = time.perf_counter() - tag_time
        action_staking.append(tag_time_end)
        print("Action staking", tag_time_end)

        # receive attestaion
        tag_time = time.perf_counter()
        atte_rec = v.receive(atte.encode(), int(session_content[0]), idx,
                             StateType.inited.value, ves.nsb.host)
        tag_time_end = time.perf_counter() - tag_time
        proof_retriveal.append(tag_time_end)
        print("attestation inited", tag_time_end)
        # laz_func = u.send_attestation(session_id, atte, idx, StateType.inited, ves.nsb.host)
        # u.unlockself(ves.nsb.host)
        # laz_func.transact()
        # console_logger.info('nsb received action, response: {}'.format(laz_func.loop_and_wait()))
        console_logger.info('nsb received action, response: {}'.format(ret))

        # Part_Z # open ################################################################################################

        print("attestation open")
        # compute attestation
        tag_time = time.perf_counter()
        rlped_data = v.sign_attestation(atte_rec)
        tag_time_end = time.perf_counter() - tag_time
        print("Atte computation", tag_time_end)
        atte_computation.append(tag_time_end)

        # send open-request attestion
        tag_time = time.perf_counter()
        ret = v.send_attestation(session_id, atte_rec, idx, StateType.open,
                                 ves.nsb.host)
        tag_time_end = time.perf_counter() - tag_time
        print("Action staking", tag_time_end)
        action_staking.append(tag_time_end)

        # no necessary to ack, just verify it
        tag_time = time.perf_counter()
        u.receive(rlped_data, int(session_content[0]), idx,
                  StateType.open.value, ves.nsb.host)
        tag_time_end = time.perf_counter() - tag_time
        proof_retriveal.append(tag_time_end)
        print("attestation open", tag_time_end)
        # laz_func = v.send_attestation(session_id, atte_rec, idx, StateType.open, ves.nsb.host)
        # v.unlockself(ves.nsb.host)
        # laz_func.transact()
        # console_logger.info('nsb received action, response: {}'.format(laz_func.loop_and_wait()))
        console_logger.info('nsb received action, response: {}'.format(ret))

        # Part_A # opened ##############################################################################################

        # open transaction
        print("transact")
        tag_time = time.perf_counter()
        # u.unlockself(tx_intents.intents[idx].chain_host)
        # temporary_transact(tx, tx_intents.intents[idx].chain_host, u)
        tag_time_end = time.perf_counter() - tag_time
        print("transact", tag_time_end)

        print("attestation opened")
        # compute opened attestaion
        tag_time = time.perf_counter()
        atte = u.init_attestation(tx, StateType.opened,
                                  int(session_content[0]), 0, ves.nsb.host)
        tag_time_end = time.perf_counter() - tag_time
        atte_computation.append(tag_time_end)

        # send opened attestion
        tag_time = time.perf_counter()
        ret = u.send_attestation(session_id, atte, idx, StateType.opened,
                                 ves.nsb.host)
        tag_time_end = time.perf_counter() - tag_time
        action_staking.append(tag_time_end)

        # no necessary to ack, just verify it
        tag_time = time.perf_counter()
        v.receive(atte.encode(), int(session_content[0]), idx,
                  StateType.opened.value, ves.nsb.host)
        tag_time_end = time.perf_counter() - tag_time
        proof_retriveal.append(tag_time_end)
        print("attestation opened", tag_time_end)

        # laz_func = u.send_attestation(session_id, atte, idx, StateType.opened, ves.nsb.host)
        # laz_func.transact()
        # console_logger.info('nsb received action, response: {}'.format(laz_func.loop_and_wait()))
        console_logger.info('nsb received action, response: {}'.format(ret))

        # Part_Z # closed ##############################################################################################

        # atte = v.init_attestation(tx, StateType.closed, int(session_content[0]), 0, ves.nsb.host)
        # laz_func = v.send_attestation(session_id, atte, idx, StateType.closed, ves.nsb.host)
        # laz_func.transact()
        # console_logger.info('nsb received action, response: {}'.format(laz_func.loop_and_wait()))

        # compute closed attestaion
        print("attestation closed")
        tag_time = time.perf_counter()
        atte = v.init_attestation(tx, StateType.closed,
                                  int(session_content[0]), 0, ves.nsb.host)
        tag_time_end = time.perf_counter() - tag_time
        atte_computation.append(tag_time_end)

        # send closed attestion
        tag_time = time.perf_counter()
        ret = v.send_attestation(session_id, atte, idx, StateType.closed,
                                 ves.nsb.host)
        tag_time_end = time.perf_counter() - tag_time
        action_staking.append(tag_time_end)

        # receive closed attestion
        tag_time = time.perf_counter()
        u.receive(atte.encode(), int(session_content[0]), idx,
                  StateType.closed.value, ves.nsb.host)
        tag_time_end = time.perf_counter() - tag_time
        proof_retriveal.append(tag_time_end)
        print("attestation closed", tag_time_end)
        console_logger.info('nsb received action, response: {}'.format(ret))

        # end ##########################################################################################################

        print("----------end transaction----------")
    # #
    # # # settle
    # #
    # # # close
    latency_profile.atte_computation = sum(atte_computation) / len(
        atte_computation)
    latency_profile.action_staking = sum(action_staking) / len(action_staking)
    latency_profile.proof_retrieval = sum(proof_retriveal) / len(
        proof_retriveal)
    print("tot_time", time.perf_counter() - tot_time)
    return latency_profile
Esempio n. 6
0
# python modules

# ethereum modules
from hexbytes import HexBytes
from web3 import Web3

# uip modules
from uiputils.ethtools import ServiceStart
from dapp import DApp
from nsb import EthNetStatusBlockchain
from uiputils.ethtools.loc_cal import slicelocation

baser = DApp({
    'domain': "Ethereum://chain1",
    'name': "nsb",
    'passphrase': "123456"
})
# beiyong 0x92a875bff412aea7fab74daa1cba3f7b94415ac9
# beiyong 0x211939ec400c7391d45e97f4b547e0dbfb8905ee
nsb_addr = Web3.toChecksumAddress("0x15055c5173c91957ea49552bdee55487e3c2ac43")
# ("0x076122c56613fc1e3ae97d715ca7cb6a35a934c6")

nsb_abi_dir = '../contract/solidity/nsb/nsb.abi'
nsb_bytecode_dir = '../contract/solidity/nsb/nsb.bin'
nsb_db_dir = "../nsb/actiondata"
tx = {
    "from":
    Web3.toChecksumAddress(baser.info['http://127.0.0.1:8545']['address']),
    "gas": hex(400000)
}
Esempio n. 7
0
    'passphrase': "123456"
}


def unlock_user(addr):
    unlock = JsonRPC.personal_unlock_account(addr, "123456", 20)
    response = JsonRPC.send(unlock, HTTP_HEADER, "http://127.0.0.1:8545")
    if not response['result']:
        raise ValueError("unlock failed. wrong password?")


if __name__ == '__main__':

    # prepare
    ves = VerifiableExecutionSystem()
    dapp_x = DApp(info_x)
    dapp_y = DApp(info_y)
    relay_x = DApp(info_relay_x)
    relay_y = DApp(info_relay_y)
    ves.appenduserlink([dapp_x, dapp_y])

    # load Sample.json
    op_intents_json = FileLoad.getopintents("./opintents.json")

    session_content, isc, session_signature, tx_intents = ves.session_setup_prepare(
        op_intents_json)
    # print('session_content:', session_content)
    # print('session_signature:', session_signature)

    dapp_x.ackinit(ves, isc, session_content, session_signature)
    dapp_y.ackinit(ves, isc, session_content, session_signature)