Esempio n. 1
0
def say_hi():
    patient_addresses = repo.web3.eth.accounts[1:10]
    anonymous_diabetics = list(
        zip(patient_addresses, anonymous_diabetes_users[0],
            anonymous_diabetes_users[1]))
    cure_diabetes_inc = repo.web3.eth.accounts[1]
    pubkey, prikey = KeyPair().generate(n_length=1024)
    diabetes_classifier = LinearClassifier(desc="DiabetesClassifier",
                                           n_inputs=10,
                                           n_labels=1)
    initial_error = diabetes_classifier.evaluate(validation[0], validation[1])
    diabetes_classifier.encrypt(pubkey)

    diabetes_model = Model(owner=cure_diabetes_inc,
                           syft_obj=diabetes_classifier,
                           bounty=1,
                           initial_error=initial_error,
                           target_error=10000)
    model_id = repo.submit_model(diabetes_model)
    model = repo[model_id]
    diabetic_address, input_data, target_data = anonymous_diabetics[0]
    repo[model_id].submit_gradient(diabetic_address, input_data, target_data)
    print(repo[model_id])
    old_balance = get_balance(diabetic_address)
    print(old_balance)
    new_error = repo[model_id].evaluate_gradient(cure_diabetes_inc,
                                                 repo[model_id][0], prikey,
                                                 pubkey, validation[0],
                                                 validation[1])
    print(new_error)
    new_balance = get_balance(diabetic_address)
    incentive = new_balance - old_balance
    print(incentive)
    return jsonify({
        'initial_error': initial_error,
        'old_balance': old_balance,
        'new_balance': new_balance,
        'new_error': new_error,
        'incentive': incentive
    })
Esempio n. 2
0
import json
import copy
from web3 import Web3, KeepAliveRPCProvider

from sonar.ipfs import IPFS
from syft.he.paillier.keys import KeyPair

publickey, privatekey = KeyPair().generate(n_length=1024)


class Gradient():
    def __init__(self,
                 owner,
                 grad_values,
                 gradient_id,
                 new_model_error=None,
                 new_weights=None):
        self.owner = owner
        self.grad_values = grad_values
        self.id = gradient_id

        self.new_model_error = new_model_error
        self.new_weights = new_weights


class Model():
    def __init__(self,
                 owner,
                 syft_obj,
                 bounty,
                 initial_error,
Esempio n. 3
0
def get_keys(id):
    pk_bin = conn.get(id+'_public')
    sk_bin = conn.get(id+'_private')
    pk,sk = KeyPair().deserialize(pk_bin,sk_bin)
    return (pk,sk)
repo = ModelRepository('0xCe4a53D71C6D7E1BB83296B4AEcd6CEd67C44536'
                       )  # blockchain hosted model repository

# we're going to set aside 10 accounts for our 42 patients
# Let's go ahead and pair each data point with each patient's
# address so that we know we don't get them confused
patient_addresses = repo.web3.eth.accounts[1:10]
anonymous_diabetics = list(
    zip(patient_addresses, anonymous_diabetes_users[0],
        anonymous_diabetes_users[1]))

# we're going to set aside 1 account for Cure Diabetes Inc
cure_diabetes_inc = repo.web3.eth.accounts[1]
agg_addr = repo.web3.eth.accounts[2]

pubkey, prikey = KeyPair().generate(n_length=1024)
#pubkey,prikey=paillier.paillier.generate_paillier_keypair()
diabetes_classifier = LinearClassifier(desc="DiabetesClassifier",
                                       n_inputs=30,
                                       n_labels=2)
initial_error = diabetes_classifier.evaluate(validation[0], validation[1])
start_modelencryption = time.time()
diabetes_classifier.encrypt(pubkey)
end_modelencryption = time.time()
print('modelencryption time', end_modelencryption - start_modelencryption)
start_prikeyshare_gen = time.time()
s1, s2 = paillier.paillier.genKeyShares(prikey.sk, pubkey.pk)
st = SecretKey(s1)
sab = SecretKey(s2)
s3, s4 = paillier.paillier.genKeyShares(s2, pubkey.pk)
sa = SecretKey(s3)
Esempio n. 5
0
# ATTENTION: copy paste the correct address (NOT THE DEFAULT SEEN HERE) from truffle migrate output.
repo = ModelRepository('0xEc40aA837dB3cf71DFa2a153A151d0425439900A'
                       )  # blockchain hosted model repository

# we're going to set aside 10 accounts for our 42 patients
# Let's go ahead and pair each data point with each patient's
# address so that we know we don't get them confused
patient_addresses = repo.web3.eth.accounts[2:11]
anonymous_patients = list(
    zip(patient_addresses, anonymous_users[0], anonymous_users[1]))

# we're going to set aside 1 account for Cure Cancer Inc
cure_cancer_inc = repo.web3.eth.accounts[0]
agg_addr = repo.web3.eth.accounts[1]

pubkey, prikey = KeyPair().generate(n_length=2048)
#pubkey,prikey=paillier.paillier.generate_paillier_keypair()
cancer_classifier = LinearClassifier(desc="CancerClassifier",
                                     n_inputs=30,
                                     n_labels=1)
initial_error = cancer_classifier.evaluate(validation[0], validation[1])
start_modelencryption = time.time()
cancer_classifier.encrypt(pubkey)
end_modelencryption = time.time()
print('modelencryption time', end_modelencryption - start_modelencryption)
start_prikeyshare_gen = time.time()
s1, s2 = paillier.paillier.genKeyShares(prikey.sk, pubkey.pk)
st = SecretKey(s1)
sab = SecretKey(s2)
s3, s4 = paillier.paillier.genKeyShares(s2, pubkey.pk)
sa = SecretKey(s3)