コード例 #1
0
ファイル: enctest.py プロジェクト: nibau/zkay
from zkay.examples.scenario import ScenarioBuilder
a = 'a'
sb = ScenarioBuilder('RealEncrypt', 'code/EncTest.zkay').set_users(a)
sb.set_deployment_transaction(owner=a)
sb.add_balance_assertion(0)
sb.add_state_assertion('v', expected_value=0, should_decrypt=True)
sb.add_transaction('test', [42], user=a)
sb.add_state_assertion('v', expected_value=44, should_decrypt=True)
sb.add_balance_assertion(0)
sb.add_transaction('test', [7], user=a)
sb.add_state_assertion('v', expected_value=53, should_decrypt=True)
sb.add_balance_assertion(0)
SCENARIO = sb.build()
コード例 #2
0
from zkay.examples.scenario import ScenarioBuilder
from zkay.transaction.offchain import RequireException

raiser, backer1, backer2 = 'hospital', 'patient1', 'patient2'
sb = ScenarioBuilder('CrowdFundingSuccess', 'code/CrowdFunding.zkay').set_users(raiser, backer1, backer2)
# Set hospital as owner
sb.set_deployment_transaction(100, 3600, amount=20, owner=raiser)
sb.add_balance_assertion(20)
sb.add_state_assertion('pot_balance', user=raiser, should_decrypt=True, expected_value=20)
sb.add_state_assertion('pledged', raiser, user=raiser, should_decrypt=True, expected_value=20)

# Add some money to the contract
sb.add_transaction('fund', user=backer1, amount=300)
sb.add_transaction('fund', user=backer2, amount=2000)
sb.add_balance_assertion(2320)
sb.add_state_assertion('pot_balance', user=raiser, should_decrypt=True, expected_value=20)
sb.add_state_assertion('funds', backer1, user=backer1, should_decrypt=True, expected_value=300)
sb.add_state_assertion('funds', backer2, user=backer2, should_decrypt=True, expected_value=2000)

# Ooops, correct mistake
sb.add_transaction('retrieve_unpledged_funds', user=backer2)
sb.add_state_assertion('funds', backer2, user=backer2, should_decrypt=True, expected_value=0)
sb.add_balance_assertion(320)
sb.add_transaction('fund', user=backer2, amount=500)
sb.add_state_assertion('funds', backer2, user=backer2, should_decrypt=True, expected_value=500)
sb.add_balance_assertion(820)

# This should fail since nothing is pledged yet
sb.add_transaction('accept_pledge', user=raiser, expected_exception=RequireException)

# Pledge money 1
コード例 #3
0
ファイル: addition.py プロジェクト: nibau/zkay
from zkay.examples.scenario import ScenarioBuilder
a = 'a'
sb = ScenarioBuilder('SimpleAddition', 'code/Addition.zkay').set_users(a)
sb.set_deployment_transaction(owner=a)
sb.add_transaction('f', [1, 2], user=a)
sb.add_state_assertion('x', expected_value=3)
sb.add_balance_assertion(0)
SCENARIO = sb.build()
コード例 #4
0
from zkay.examples.scenario import ScenarioBuilder
from zkay.transaction.offchain import RequireException

ngo, lobbying, direct_aid, a, b = 'ngo', 'lobbying', 'direct_aid', 'a', 'b'
sb = ScenarioBuilder('NGO', 'code/Ngo.zkay').set_users(ngo, lobbying, direct_aid, a, b)
sb.set_deployment_transaction(lobbying, direct_aid, owner=ngo)

sb.add_transaction('contribute', amount=100, user=a)
sb.add_transaction('contribute', amount=200, user=b)

sb.add_balance_assertion(300)
sb.add_state_assertion('totalContributions', user=ngo, expected_value=300, should_decrypt=True)

# NGO now anonymously pays out money to lobbying / direct_aid, e.g. using the 'TokenHomomorphic' contract
# lobbying & direct_aid confirm having received the contributions

sb.add_transaction('reportReceivedContributions', [150], user=lobbying)
sb.add_transaction('proveMinContributions', user=ngo, expected_exception=RequireException)  # Not yet correct
sb.add_transaction('reportReceivedContributions', [90], user=direct_aid)
sb.add_transaction('proveMinContributions', user=ngo)  # Now it is

SCENARIO = sb.build()
コード例 #5
0
ファイル: voting_booth.py プロジェクト: eth-sri/zkay
from zkay.examples.scenario import ScenarioBuilder
from zkay.transaction.offchain import RequireException

owner, a, b, c = 'owner', 'a', 'b', 'c'
sb = ScenarioBuilder('VotingBooth',
                     'code/VotingBooth.zkay').set_users(owner, a, b, c)
sb.set_deployment_transaction(owner=owner)

sb.add_transaction('vote', [0], user=a)  # A votes for A
sb.add_transaction('vote', [1], user=b)  # B votes for B
sb.add_transaction('vote', [1], user=c)  # C votes for B
sb.add_transaction('vote', [0], user=a,
                   expected_exception=RequireException)  # No double-voting

sb.add_state_assertion('votesForA',
                       user=owner,
                       expected_value=1,
                       should_decrypt=True)
sb.add_state_assertion('votesForB',
                       user=owner,
                       expected_value=2,
                       should_decrypt=True)

sb.add_transaction(
    'declareWinner', user=a,
    expected_exception=RequireException)  # Only owner can call the vote
sb.add_transaction('declareWinner', user=owner)

sb.add_transaction(
    'vote', [0], user=a,
    expected_exception=RequireException)  # No voting after the vote was called
コード例 #6
0
from zkay.examples.scenario import ScenarioBuilder
a, b = 'a', 'b'
sb = ScenarioBuilder('SharedProd', 'code/SharedProd.zkay').set_users(a, b)
sb.set_deployment_transaction(owner=a)
sb.add_state_assertion('secret', expected_value=3, should_decrypt=True)
sb.add_transaction('foo', [4], user=b)
sb.add_transaction('foo', [5], user=a)
sb.add_state_assertion('secret', expected_value=60, should_decrypt=True)
sb.add_balance_assertion(0)
SCENARIO = sb.build()
コード例 #7
0
from zkay.examples.scenario import ScenarioBuilder
from zkay.transaction.offchain import RequireException

bank, a, b = 'bank', 'a', 'b'
sb = ScenarioBuilder('Interest', 'code/Interest.zkay').set_users(bank, a, b)
sb.set_deployment_transaction(owner=bank)

sb.add_transaction('register', user=a)
sb.add_transaction('buy', amount=125, user=a)
sb.add_transaction('register', user=b)
sb.add_transaction('buy', amount=225, user=b)
sb.add_balance_assertion(350)
sb.add_state_assertion('checkings',
                       a,
                       user=a,
                       expected_value=125,
                       should_decrypt=True)
sb.add_state_assertion('checkings',
                       b,
                       user=b,
                       expected_value=225,
                       should_decrypt=True)

sb.add_transaction('send_tokens', [25, b], user=a)
sb.add_state_assertion('checkings',
                       a,
                       user=a,
                       expected_value=100,
                       should_decrypt=True)
sb.add_state_assertion('checkings',
                       b,
コード例 #8
0
from zkay.examples.scenario import ScenarioBuilder
admin, user, stock_a, stock_b = 'admin', 'user', 'stock_a', 'stock_b'
sb = ScenarioBuilder('IndexFund',
                     'code/IndexFund.zkay').set_users(admin, user, stock_a,
                                                      stock_b)
sb.set_deployment_transaction(owner=admin)
sb.add_transaction('add_stocks_to_fund', [stock_a, 1, 10], user=admin)
sb.add_transaction('add_stocks_to_fund', [stock_b, 3, 5], user=admin)
sb.add_state_assertion('current_fund_price', expected_value=25)

sb.add_transaction('pay_into', amount=250, user=user)
sb.add_state_assertion('balance',
                       user,
                       user=user,
                       expected_value=250,
                       should_decrypt=True)
sb.add_balance_assertion(250)

sb.add_transaction('buy_shares', [10], user=user)
sb.add_state_assertion('balance',
                       user,
                       user=user,
                       expected_value=0,
                       should_decrypt=True)
sb.add_state_assertion('shares',
                       user,
                       user=user,
                       expected_value=10,
                       should_decrypt=True)
sb.add_state_assertion('total_shares',
                       user=admin,
コード例 #9
0
from zkay.examples.scenario import ScenarioBuilder
a = 'a'
sb = ScenarioBuilder('FuncCalls', 'code/FuncCalls.zkay').set_users(a)
sb.set_deployment_transaction(owner=a)
sb.add_balance_assertion(0)
sb.add_transaction('compute', [42, 5], user=a)
sb.add_state_assertion('res', expected_value=326020380, should_decrypt=True)
sb.add_balance_assertion(0)
SCENARIO = sb.build()
コード例 #10
0
from zkay.examples.scenario import ScenarioBuilder
a = 'a'
sb = ScenarioBuilder('PrivateIfWithHom', 'code/PrivateIfWithHom.zkay').set_users(a)
sb.set_deployment_transaction(owner=a)
sb.add_transaction('f', [True, 1, 2], user=a)
sb.add_state_assertion('a', expected_value=1, should_decrypt=True)
sb.add_state_assertion('b', expected_value=1, should_decrypt=True)
sb.add_transaction('f', [False, 1, 2], user=a)
sb.add_state_assertion('a', expected_value=2, should_decrypt=True)
sb.add_state_assertion('b', expected_value=2, should_decrypt=True)
sb.add_balance_assertion(0)
SCENARIO = sb.build()
コード例 #11
0
ファイル: receipts_hom.py プロジェクト: eth-sri/zkay
from zkay.examples.scenario import ScenarioBuilder
from zkay.transaction.offchain import RequireException

business, a, b, c = 'business', 'a', 'b', 'c'
sb = ScenarioBuilder('ReceiptsHomomorphic',
                     'code/ReceiptsHomomorphic.zkay').set_users(
                         business, a, b, c)
sb.set_deployment_transaction(owner=business)

sb.add_transaction('give_receipt', [1, 123], user=business)
sb.add_transaction('receive_receipt', [1, 123], user=a)
sb.add_transaction('give_receipt', [2, 456], user=business)
sb.add_transaction('receive_receipt', [2, 456], user=b)
sb.add_transaction('give_receipt', [3, 789], user=business)
sb.add_transaction('receive_receipt', [3, 789], user=c)

sb.add_transaction('check', [1], user=business)
sb.add_transaction('check', [2], user=business)
sb.add_transaction('check', [3], user=business)

SCENARIO = sb.build()
コード例 #12
0
ファイル: multipleret.py プロジェクト: nibau/zkay
from zkay.examples.scenario import ScenarioBuilder
a = 'a'
sb = ScenarioBuilder('MultipleReturnValues', 'code/MultipleReturnValues.zkay').set_users(a)
sb.set_deployment_transaction(owner=a)

sb.add_balance_assertion(0)
for x in [0, 42, 123523]:
    sb.add_transaction('test', [x], user=a)
    sb.add_state_assertion('ret', expected_value=24*x + 134)
sb.add_balance_assertion(0)
SCENARIO = sb.build()
コード例 #13
0
ファイル: inheritance.py プロジェクト: eth-sri/zkay
from zkay.examples.scenario import ScenarioBuilder
from zkay.transaction.offchain import RequireException

owner, a, b, c, d = 'owner', 'a', 'b', 'c', 'd'
sb = ScenarioBuilder('Inheritance',
                     'code/Inheritance.zkay').set_users(owner, a, b, c, d)
sb.set_deployment_transaction(owner=owner)

sb.add_transaction('register', user=a)
sb.add_transaction('register', user=b)
sb.add_transaction('register', user=c)
sb.add_transaction('register', user=d)

sb.add_transaction('buy', amount=100, user=a)
sb.add_transaction('buy', amount=100, user=b)
sb.add_transaction('buy', amount=100, user=c)
sb.add_transaction('buy', amount=100, user=d)
sb.add_balance_assertion(400)

# A pledges 50 to B, 50 to C (after failing to give 100 to C due to missing funds)
sb.add_transaction('pledge_inheritance', [b, 50], user=a)
sb.add_transaction('pledge_inheritance', [c, 100],
                   user=a,
                   expected_exception=RequireException)
sb.add_transaction('pledge_inheritance', [c, 50], user=a)
sb.add_state_assertion('inheritance_pledged_send',
                       a,
                       b,
                       user=a,
                       expected_value=50,
                       should_decrypt=True)
コード例 #14
0
ファイル: hom_mul.py プロジェクト: eth-sri/zkay
from zkay.examples.scenario import ScenarioBuilder
a, b = 'a', 'b'
sb = ScenarioBuilder('HomomorphicMultiplication', 'code/HomomorphicMultiplication.zkay').set_users(a, b)
sb.set_deployment_transaction(3, 2, owner=a)
sb.add_state_assertion('a', expected_value=3, should_decrypt=True)
sb.add_state_assertion('b', expected_value=2)
sb.add_transaction('f', user=b)
sb.add_state_assertion('productPosPos', expected_value=6, should_decrypt=True)
sb.add_balance_assertion(0)
SCENARIO = sb.build()
コード例 #15
0
ファイル: medstats.py プロジェクト: nibau/zkay
# Initial state clean
sb.add_balance_assertion(0)
sb.add_state_assertion('risk',
                       patient1,
                       user=patient1,
                       should_decrypt=True,
                       expected_value=False)
sb.add_state_assertion('risk',
                       patient2,
                       user=patient2,
                       should_decrypt=True,
                       expected_value=False)

# Add record for patient 1
sb.add_transaction('record', [patient1, True], user=hospital)
sb.add_state_assertion('risk',
                       patient1,
                       user=patient1,
                       should_decrypt=True,
                       expected_value=True)
sb.add_state_assertion('risk',
                       patient2,
                       user=patient2,
                       should_decrypt=True,
                       expected_value=False)

# Add record for patient 2
sb.add_transaction('record', [patient2, False], user=hospital)
sb.add_state_assertion('risk',
                       patient1,
コード例 #16
0
ファイル: nested_if.py プロジェクト: nibau/zkay
from zkay.examples.scenario import ScenarioBuilder
a = 'a'
sb = ScenarioBuilder('NestedIfStatements', 'code/NestedIfCond.zkay').set_users(a)
sb.set_deployment_transaction(owner=a)
sb.add_balance_assertion(0)
sb.add_state_assertion('val', user=a, should_decrypt=True, expected_value=False)
sb.add_state_assertion('res', user=a, should_decrypt=True, expected_value=0)

sb.add_transaction('test_if', [51], user=a)
sb.add_state_assertion('val', user=a, should_decrypt=True, expected_value=True)
sb.add_state_assertion('res', user=a, should_decrypt=True, expected_value=2)
sb.add_state_assertion('res2', expected_value=10)

sb.add_transaction('test_if', [43], user=a)
sb.add_state_assertion('val', user=a, should_decrypt=True, expected_value=True)
sb.add_state_assertion('res', user=a, should_decrypt=True, expected_value=3)
sb.add_state_assertion('res2', user=a, expected_value=15)

sb.add_transaction('test_if', [42], user=a)
sb.add_state_assertion('val', user=a, should_decrypt=True, expected_value=False)
sb.add_state_assertion('res', user=a, should_decrypt=True, expected_value=3)
sb.add_state_assertion('res2', user=a, expected_value=15)

sb.add_transaction('test_if', [0], user=a)
sb.add_state_assertion('val', user=a, should_decrypt=True, expected_value=False)
sb.add_state_assertion('res', user=a, should_decrypt=True, expected_value=4)
sb.add_state_assertion('res2', user=a, expected_value=20)

sb.add_balance_assertion(0)
SCENARIO = sb.build()
コード例 #17
0
from zkay.examples.scenario import ScenarioBuilder
a = 'a'
sb = ScenarioBuilder('DivAndMod', 'code/DivAndMod.zkay').set_users(a)
sb.set_deployment_transaction(owner=a)
sb.add_transaction('testUintDiv', user=a)
sb.add_transaction('testIntDiv', user=a)
sb.add_transaction('testUintMod', user=a)
sb.add_transaction('testIntMod', user=a)
sb.add_balance_assertion(0)
SCENARIO = sb.build()
コード例 #18
0
ファイル: token_hom.py プロジェクト: eth-sri/zkay
from zkay.examples.scenario import ScenarioBuilder
from zkay.transaction.offchain import RequireException

a, b, c = 'a', 'b', 'c'
sb = ScenarioBuilder('TokenHomomorphic', 'code/TokenHomomorphic.zkay').set_users(a, b, c)
sb.set_deployment_transaction(owner=a)
sb.add_transaction('register', user=a)
sb.add_transaction('register', user=b)
sb.add_transaction('register', user=c)

sb.add_transaction('buy', [100], user=a)
sb.add_state_assertion('balance', a, user=a, expected_value=100, should_decrypt=True)
sb.add_transaction('buy', [50], user=b)
sb.add_state_assertion('balance', b, user=b, expected_value=50, should_decrypt=True)

sb.add_transaction('send_tokens', [40, c], user=a)
sb.add_state_assertion('balance', a, user=a, expected_value=60, should_decrypt=True)
sb.add_state_assertion('balance', c, user=c, expected_value=40, should_decrypt=True)

sb.add_transaction('send_tokens', [50, b], user=c, expected_exception=RequireException)
sb.add_state_assertion('balance', a, user=a, expected_value=60, should_decrypt=True)
sb.add_state_assertion('balance', b, user=b, expected_value=50, should_decrypt=True)
sb.add_state_assertion('balance', c, user=c, expected_value=40, should_decrypt=True)

SCENARIO = sb.build()
コード例 #19
0
from zkay.examples.scenario import ScenarioBuilder
a = 'a'
sb = ScenarioBuilder('Rehom', 'code/RehomArgs.zkay').set_users(a)
sb.set_deployment_transaction(owner=a)
sb.add_transaction('add_hom', [2], user=a)
sb.add_state_assertion('y', expected_value=2, should_decrypt=True)
sb.add_transaction('un_hom', [3], user=a)
sb.add_state_assertion('z', expected_value=3, should_decrypt=True)
sb.add_balance_assertion(0)
SCENARIO = sb.build()
コード例 #20
0
ファイル: exposure_warning.py プロジェクト: eth-sri/zkay
from zkay.examples.scenario import ScenarioBuilder
from zkay.transaction.offchain import RequireException

hospital, a, a_inf, b, b_inf, c = 'hospital', 'a', 'a_inf', 'b', 'b_inf', 'c'
sb = ScenarioBuilder('ExposureWarning', 'code/ExposureWarning.zkay').set_users(hospital, a, a_inf, b, b_inf, c)
sb.set_deployment_transaction(owner=hospital)

sb.add_transaction('setInfected', [a_inf], user=hospital)
sb.add_transaction('setInfected', [b_inf], user=hospital)
sb.add_transaction('setInfected', [c], user=b, expected_exception=RequireException)

sb.add_state_assertion('is_infected', a_inf, expected_value=True)
sb.add_state_assertion('is_infected', b_inf, expected_value=True)
sb.add_state_assertion('is_infected', c, expected_value=False)

# a had contact with b and c; b had contact with c
sb.add_transaction('notifyAboutExposure', [b], user=a_inf)
sb.add_transaction('notifyAboutExposure', [c], user=a_inf)
sb.add_transaction('notifyAboutExposure', [c], user=b_inf)
sb.add_transaction('notifyAboutExposure', [a], user=c, expected_exception=RequireException)

sb.add_state_assertion('exposures', a, user=a, expected_value=0, should_decrypt=True)
sb.add_state_assertion('exposures', b, user=b, expected_value=1, should_decrypt=True)
sb.add_state_assertion('exposures', c, user=c, expected_value=2, should_decrypt=True)

SCENARIO = sb.build()
コード例 #21
0
ファイル: casting.py プロジェクト: nibau/zkay
from zkay.examples.scenario import ScenarioBuilder
from zkay.transaction.types import AddressValue
from zkay.zkay_ast.ast import IntTypeName

a = 'a'
sb = ScenarioBuilder('Casting', 'code/Cast.zkay').set_users(a)
sb.set_deployment_transaction(owner=a)
sb.add_balance_assertion(0)

sb.add_transaction('test_signed_casts', user=a)
sb.add_state_assertion('negval',
                       should_decrypt=True,
                       expected_value=-1,
                       plain_type=IntTypeName('int248'))
sb.add_state_assertion('nv2', should_decrypt=True, expected_value=1)
sb.add_state_assertion('pv2', expected_value=-1)
sb.add_state_assertion('pv3', expected_value=(1 << 248) - 1)
sb.add_state_assertion('pv4', expected_value=(1 << 248) - 1)

sb.add_transaction(
    'f', [378], user=a
)  # b = false, p = 382, secint = 384, priv_addr = 426,sealed_enum = 1, res = 126
sb.add_state_assertion('p', should_decrypt=True, expected_value=382)
sb.add_state_assertion('priv_addr',
                       should_decrypt=True,
                       expected_value=AddressValue(426))
sb.add_state_assertion('sealed_enum', should_decrypt=True, expected_value=1)
sb.add_state_assertion('res', expected_value=126)

sb.add_transaction(
    'f', [379],