예제 #1
0
    def __init__(self,
                 web3_addr,
                 contract_addr="",
                 contract_abi=None,
                 contract_bytecode=None,
                 timeout=30):

        web3 = ServiceStart.startweb3(web3_addr)
        contract_abi = FileLoad.getabi(contract_abi)
        contract_bytecode = FileLoad.getbytecode(contract_bytecode)

        if contract_addr != "":
            self.handle = web3.eth.contract(
                Web3.toChecksumAddress(contract_addr),
                abi=contract_abi,
                bytecode=contract_bytecode)
        else:
            self.handle = web3.eth.contract(abi=contract_abi,
                                            bytecode=contract_bytecode)

        self.timeout = timeout
        self.web3 = web3
        self.address = self.handle.address
        self.abi = self.handle.abi
        self.bytecode = self.handle.bytecode
        self.functions = self.handle.functions
예제 #2
0
파일: isc.py 프로젝트: KenHopkin/UIP
    def make_contract(owners, signature, rlped_txs, tx_count, ves, bytescode=None, bin_dir=isc_bin_dir):
        try:
            rlped_txs = HexBytes(rlped_txs)
            encoded_data = AbiEncoder.encodes(
                [
                    owners,
                    [0, 0, 0],
                    HexBytes(ETHSIGN_HEADER + bytes(str(len(rlped_txs)).encode(ENC)) + bytes(rlped_txs)).hex(),
                    signature,
                    keccak(ETHSIGN_HEADER + b'\x36\x35' + HexBytes(signature)),
                    tx_count
                ],
                ['address[]', 'uint256[]', 'bytes', 'bytes', 'bytes32', 'uint256']
            )
            if bytescode is None:
                bytescode = FileLoad.getbytecode(bin_dir)

            ves.unlockself()
            tx_json = JsonRPC.eth_send_transaction({
                'from': ves.address,
                'data': bytescode.decode(ENC) + encoded_data,
                'gas': hex(8000000)
            })
            # print(tx_json)
            response = JsonRPC.send(tx_json, rpc_host=ves.chain_host)
            rp_json = JsonRPC.eth_get_transaction_receipt(response['result'])
        except Exception as e:
            isc_log.debug('ISCBulidError: {}'.format(str(e)))
            raise e
        while True:
            try:

                response = JsonRPC.send(rp_json, rpc_host=ves.chain_host)
                if response['result'] is None:
                    console_logger.info("Contract is deploying, please stand by")
                    time.sleep(2)
                    continue
                console_logger.info("got Transaction_result {}".format(response['result']))

                block_number = response['result']['blockNumber']
                contract_addr = response['result']['contractAddress']

                cd_json = JsonRPC.eth_get_code(contract_addr, block_number)
                response = JsonRPC.send(cd_json, rpc_host=ves.chain_host)
                if response['result'] == '0x':
                    raise IndexError("Contract deployment failed")

                return contract_addr
            except Exception as e:
                isc_log.debug('ISCBulidError: {exec}'.format(exec=str(e)), extra={"addr": ""})
                raise e
예제 #3
0
파일: json_test.py 프로젝트: KenHopkin/UIP
# python modules
import json

# uip modules
from dapp import DApp
from uiputils.op_intents import OpIntent
from uiputils.transaction_intents import TransactionIntents

# eth modules
from uiputils.ethtools import FileLoad

if __name__ == '__main__':
    # load Sample.json
    op_intents_json = FileLoad.getopintents("opintents.json")

    # build eligible Op intents
    op_intents = OpIntent.createopintents(op_intents_json['Op-intents'])
    for op_intent in op_intents:
        print("---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----")
        print(
            json.dumps(op_intent.__dict__,
                       sort_keys=True,
                       indent=4,
                       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("---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----")
예제 #4
0

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)

    dapp_x.ackinit(ves,
                   isc,
                   session_content,
                   session_signature,
                   ves.chain_host,
                   testing=False)
    dapp_y.ackinit(ves,
                   isc,
예제 #5
0
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