Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testnet #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
ENV=DEVNET
# rpc url address of the node
NODE_HTTPS_ADDRESS=https://devnet.coti.io/rpc
NODE_HTTPS_ADDRESS=https://testnet.coti.io/rpc
# websocket url address of the node
NODE_WSS_ADDRESS=wss://devnet.coti.io/ws
NODE_WSS_ADDRESS=wss://testnet.coti.coti.io/ws
# can be changed, the name of the directory where the contracts get deployed to
COMPILED_CONTRACTS_DIR=/compiled_contracts/
# usually should not be changed, points to the contracts directory fetched as git submodule
SOLIDITY_CONTRACTS_DIR=/confidentiality-contracts/contracts/
# ACCOUNT_PRIVATE_KEY created on runtime by any script
# ACCOUNT_ENCRYPTION_KEY created on runtime by onboard_account

2 changes: 1 addition & 1 deletion examples/data_onchain/data_on_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def main():
def make_sure_data_is_safe(eoa, web3, deployed_contract, tx_params):
some_other_contract_keeping_data = {
"contract_name": "DataOnChain",
"address": "0x349094471A746FaF7A211E7eE62Ea29C23Ada148",
"address": "0xbC39Df62e41F69300a413d4F3a262737A1109FC3",
"abi": [
{
"inputs": [],
Expand Down
103 changes: 57 additions & 46 deletions examples/onboard/onboard_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,54 @@
false = False
true = True

devnet_onboard_contract = {
"contract_name": "AccountOnboard",
"address": "0x413370ed41FB9EE3aea0B1B91FD336cC0be1Bad6",
"abi": [
{
"anonymous": false, "inputs": [
{
"indexed": true,
"internalType": "address",
"name": "_from",
"type": "address"
},
{
"indexed": false,
"internalType": "bytes",
"name": "userKey",
"type": "bytes"
}
],
"name": "AccountOnboarded",
"type": "event"
},
{
"inputs": [
{
"internalType": "bytes",
"name": "publicKey",
"type": "bytes"
},
{
"internalType": "bytes",
"name": "signedEK",
"type": "bytes"
}
],
"name": "onboardAccount",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b5061068c806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063afaea1bd14610030575b600080fd5b61004a6004803603810190610045919061031d565b61004c565b005b600061005a858585856100b1565b90503373ffffffffffffffffffffffffffffffffffffffff167fb67504ecfeef0230a06f661ea388c2947b4125a35e918ebff5889e3553c29c04826040516100a2919061042e565b60405180910390a25050505050565b6060600085859050848490506100c79190610489565b67ffffffffffffffff8111156100e0576100df6104bd565b5b6040519080825280601f01601f1916602001820160405280156101125781602001600182028036833780820191505090505b50905060005b8484905081101561018f57848482818110610136576101356104ec565b5b9050013560f81c60f81b828281518110610153576101526104ec565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080600101915050610118565b5060005b86869050811015610218578686828181106101b1576101b06104ec565b5b9050013560f81c60f81b8282878790506101cb9190610489565b815181106101dc576101db6104ec565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080600101915050610193565b50606473ffffffffffffffffffffffffffffffffffffffff1663a85f0ca2826040518263ffffffff1660e01b8152600401610253919061042e565b600060405180830381865afa158015610270573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f82011682018060405250810190610299919061060d565b915050949350505050565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b60008083601f8401126102dd576102dc6102b8565b5b8235905067ffffffffffffffff8111156102fa576102f96102bd565b5b602083019150836001820283011115610316576103156102c2565b5b9250929050565b60008060008060408587031215610337576103366102ae565b5b600085013567ffffffffffffffff811115610355576103546102b3565b5b610361878288016102c7565b9450945050602085013567ffffffffffffffff811115610384576103836102b3565b5b610390878288016102c7565b925092505092959194509250565b600081519050919050565b600082825260208201905092915050565b60005b838110156103d85780820151818401526020810190506103bd565b60008484015250505050565b6000601f19601f8301169050919050565b60006104008261039e565b61040a81856103a9565b935061041a8185602086016103ba565b610423816103e4565b840191505092915050565b6000602082019050818103600083015261044881846103f5565b905092915050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061049482610450565b915061049f83610450565b92508282019050808211156104b7576104b661045a565b5b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600080fd5b610529826103e4565b810181811067ffffffffffffffff82111715610548576105476104bd565b5b80604052505050565b600061055b6102a4565b90506105678282610520565b919050565b600067ffffffffffffffff821115610587576105866104bd565b5b610590826103e4565b9050602081019050919050565b60006105b06105ab8461056c565b610551565b9050828152602081018484840111156105cc576105cb61051b565b5b6105d78482856103ba565b509392505050565b600082601f8301126105f4576105f36102b8565b5b815161060484826020860161059d565b91505092915050565b600060208284031215610623576106226102ae565b5b600082015167ffffffffffffffff811115610641576106406102b3565b5b61064d848285016105df565b9150509291505056fea26469706673582212204b67a1dce8b9b54d0322869682b0e041a52e661d54dca735876040c6fe2cb03864736f6c63430008180033"
}
devnet_onboard_contract = {"contract_name": "AccountOnboard", "address": "0x60eA13A5f263f77f7a2832cfEeF1729B1688477c",
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "_from",
"type": "address"
},
{
"indexed": false,
"internalType": "bytes",
"name": "userKey1",
"type": "bytes"
},
{
"indexed": false,
"internalType": "bytes",
"name": "userKey2",
"type": "bytes"
}
],
"name": "AccountOnboarded",
"type": "event"
},
{
"inputs": [
{
"internalType": "bytes",
"name": "publicKey",
"type": "bytes"
},
{
"internalType": "bytes",
"name": "signedEK",
"type": "bytes"
}
],
"name": "onboardAccount",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b5061087f806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063afaea1bd14610030575b600080fd5b61004a600480360381019061004591906104d9565b61004c565b005b60008061005b868686866100b7565b915091503373ffffffffffffffffffffffffffffffffffffffff167ffc83efa19b7c2bc399a672494bb0af52f9bbd678357edf30e55b5ac4e65878ba83836040516100a79291906105ea565b60405180910390a2505050505050565b606080600086869050858590506100ce919061065a565b67ffffffffffffffff8111156100e7576100e661068e565b5b6040519080825280601f01601f1916602001820160405280156101195781602001600182028036833780820191505090505b50905060005b858590508110156101965785858281811061013d5761013c6106bd565b5b9050013560f81c60f81b82828151811061015a576101596106bd565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808060010191505061011f565b5060005b8787905081101561021f578787828181106101b8576101b76106bd565b5b9050013560f81c60f81b8282888890506101d2919061065a565b815181106101e3576101e26106bd565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808060010191505061019a565b506000606473ffffffffffffffffffffffffffffffffffffffff1663a85f0ca2836040518263ffffffff1660e01b815260040161025c91906106ec565b6000604051808303816000875af115801561027b573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f820116820180604052508101906102a49190610800565b9050600061010067ffffffffffffffff8111156102c4576102c361068e565b5b6040519080825280601f01601f1916602001820160405280156102f65781602001600182028036833780820191505090505b509050600061010067ffffffffffffffff8111156103175761031661068e565b5b6040519080825280601f01601f1916602001820160405280156103495781602001600182028036833780820191505090505b50905060005b82518110156103c55783818151811061036b5761036a6106bd565b5b602001015160f81c60f81b838281518110610389576103886106bd565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808060010191505061034f565b5060005b815181101561044c5783610100826103e1919061065a565b815181106103f2576103f16106bd565b5b602001015160f81c60f81b8282815181106104105761040f6106bd565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806001019150506103c9565b508181955095505050505094509492505050565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b60008083601f84011261049957610498610474565b5b8235905067ffffffffffffffff8111156104b6576104b5610479565b5b6020830191508360018202830111156104d2576104d161047e565b5b9250929050565b600080600080604085870312156104f3576104f261046a565b5b600085013567ffffffffffffffff8111156105115761051061046f565b5b61051d87828801610483565b9450945050602085013567ffffffffffffffff8111156105405761053f61046f565b5b61054c87828801610483565b925092505092959194509250565b600081519050919050565b600082825260208201905092915050565b60005b83811015610594578082015181840152602081019050610579565b60008484015250505050565b6000601f19601f8301169050919050565b60006105bc8261055a565b6105c68185610565565b93506105d6818560208601610576565b6105df816105a0565b840191505092915050565b6000604082019050818103600083015261060481856105b1565b9050818103602083015261061881846105b1565b90509392505050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061066582610621565b915061067083610621565b92508282019050808211156106885761068761062b565b5b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000602082019050818103600083015261070681846105b1565b905092915050565b600080fd5b61071c826105a0565b810181811067ffffffffffffffff8211171561073b5761073a61068e565b5b80604052505050565b600061074e610460565b905061075a8282610713565b919050565b600067ffffffffffffffff82111561077a5761077961068e565b5b610783826105a0565b9050602081019050919050565b60006107a361079e8461075f565b610744565b9050828152602081018484840111156107bf576107be61070e565b5b6107ca848285610576565b509392505050565b600082601f8301126107e7576107e6610474565b5b81516107f7848260208601610790565b91505092915050565b6000602082840312156108165761081561046a565b5b600082015167ffffffffffffffff8111156108345761083361046f565b5b610840848285016107d2565b9150509291505056fea2646970667358221220b9ef12093036f880e2c927bf49d4bc43abb14a9af8f661cd21085081a1fc69ee64736f6c63430008180033",
}


# Script onboards a EOA into the network, meaning, creates a AES key unique to that user,
Expand Down Expand Up @@ -88,9 +93,15 @@ def onboard_for_aes_key(deployed_contract, eoa_private_key, tx_params):
tx_receipt = onboard_user(deployed_contract, kwargs, tx_params)
print("tx receipt: ", tx_receipt)
make_sure_tx_didnt_fail(tx_receipt)
encrypted_user_aes_from_network = tx_receipt.logs[0].data[64:]
# only the private key could decrypt the account secret key
decrypted_aes_key = decrypt_rsa(private_key, encrypted_user_aes_from_network)

user_key_events = deployed_contract.events.AccountOnboarded().process_receipt(tx_receipt)
key_0_share = user_key_events[0].args.userKey1
key_1_share = user_key_events[0].args.userKey2

if key_0_share is None or key_1_share is None:
raise Exception("Failed to find the key shares of the account address in the transaction receipt.")

decrypted_aes_key = recover_user_key(private_key, key_0_share, key_1_share)
return decrypted_aes_key


Expand Down
57 changes: 31 additions & 26 deletions examples/precompiles/precompiles_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ def get_user_key(tx_params):
tx_receipt = exec_func_via_transaction(func, tx_params)
print(tx_receipt)
make_sure_tx_didnt_fail(tx_receipt)
encrypted_user_key = tx_receipt.logs[0].data[64:]
decrypted_aes_key = decrypt_rsa(private_key, encrypted_user_key)
result1, result2, result3, result4, result5, result6, result7, result8 \
= get_result(contract, "getUserKeyShares")
decrypted_aes_key = recover_user_key(private_key, result1, result2)
return decrypted_aes_key


Expand Down Expand Up @@ -108,7 +109,7 @@ def test(function_name, kwargs, expected_result1, get_result_function_name, tx_p
return
if function_name == "offboardToUserTest":
return result1, result2, result3, result4
if get_result_function_name == "getRandom":
if get_result_function_name == "getRandom" or get_result_function_name == "getRandomBounded":
assert result1 != expected_result1
last_random_value = result1
return
Expand Down Expand Up @@ -137,42 +138,46 @@ def get_result(contract, get_result_function_name):


def run_tests(a, b, shift, bit, numBits, bool_a, bool_b, tx_params):
test("addTest", {'a': a, 'b': b}, a + b, "getResult", tx_params)
test("subTest", {'a': a, 'b': b}, a - b, "getResult", tx_params)
test("mulTest", {'a': a, 'b': b}, a * b, "getResult16", tx_params)
test("divTest", {'a': a, 'b': b}, a / b, "getResult", tx_params)
test("remTest", {'a': a, 'b': b}, a % b, "getResult", tx_params)
test("andTest", {'a': a, 'b': b}, a & b, "getResult", tx_params)
test("orTest", {'a': a, 'b': b}, a | b, "getResult", tx_params)
test("xorTest", {'a': a, 'b': b}, a ^ b, "getResult", tx_params)
test("xorTest", {'a': a, 'b': b}, a ^ b, "getResult", tx_params)
test("shlTest", {'a': a, 'b': shift}, (a << shift) & 0xFF, "getAllShiftResults",
tx_params, (a << shift) & 0xFFFF, (a << shift) & 0xFFFFFFFF, (a << shift) & 0xFFFFFFFFFFFFFFFF)
test("shrTest", {'a': a, 'b': shift}, a >> shift, "getResult", tx_params)
test("minTest", {'a': a, 'b': b}, min(a, b), "getResult", tx_params)
test("maxTest", {'a': a, 'b': b}, max(a, b), "getResult", tx_params)
test("eqTest", {'a': a, 'b': b}, a == b, "getResult", tx_params)
test("neTest", {'a': a, 'b': b}, a != b, "getResult", tx_params)
test("geTest", {'a': a, 'b': b}, a >= b, "getResult", tx_params)
test("gtTest", {'a': a, 'b': b}, a > b, "getResult", tx_params)
test("leTest", {'a': a, 'b': b}, a <= b, "getResult", tx_params)
test("ltTest", {'a': a, 'b': b}, a < b, "getResult", tx_params)
test("muxTest", {'selectionBit': bit, 'a': a, 'b': b}, a if bit == 0 else b, "getResult", tx_params)
test("addTest", {'a': a, 'b': b}, a + b, "getAddResult", tx_params)
test("subTest", {'a': a, 'b': b}, a - b, "getSubResult", tx_params)
test("mulTest", {'a': a, 'b': b}, a * b, "getMulResult", tx_params)
test("divTest", {'a': a, 'b': b}, a / b, "getDivResult", tx_params)
test("remTest", {'a': a, 'b': b}, a % b, "getRemResult", tx_params)
test("andTest", {'a': a, 'b': b}, a & b, "getAndResult", tx_params)
test("orTest", {'a': a, 'b': b}, a | b, "getOrResult", tx_params)
test("xorTest", {'a': a, 'b': b}, a ^ b, "getXorResult", tx_params)
test("xorTest", {'a': a, 'b': b}, a ^ b, "getXorResult", tx_params)
test("minTest", {'a': a, 'b': b}, min(a, b), "getMinResult", tx_params)
test("maxTest", {'a': a, 'b': b}, max(a, b), "getMaxResult", tx_params)
test("eqTest", {'a': a, 'b': b}, a == b, "getEqResult", tx_params)
test("neTest", {'a': a, 'b': b}, a != b, "getNeResult", tx_params)
test("geTest", {'a': a, 'b': b}, a >= b, "getGeResult", tx_params)
test("gtTest", {'a': a, 'b': b}, a > b, "getGtResult", tx_params)
test("leTest", {'a': a, 'b': b}, a <= b, "getLeResult", tx_params)
test("ltTest", {'a': a, 'b': b}, a < b, "getLtResult", tx_params)
test("muxTest", {'selectionBit': bit, 'a': a, 'b': b}, a if bit == 0 else b, "getMuxResult", tx_params)
test("transferTest", {'amount': b, 'a': a, 'b': b}, a - b, "getResults", tx_params, b + b)
test("transferScalarTest", {'amount': b, 'a': a, 'b': b}, a - b, "getResults", tx_params, b + b)
test("offboardOnboardTest", {'a8': a, 'a16': a, 'a32': a, 'a64': a}, a, "getResult", tx_params)
test("offboardOnboardTest", {'a8': a, 'a16': a, 'a32': a, 'a64': a}, a, "getOnboardOffboardResult", tx_params)
test("notTest", {'a': bit}, not bit, "getBoolResult", tx_params)
test_user_key("offboardToUserTest", {'a': a, 'addr': tx_params['web3'].eth.default_account.address},
a, "getCTs", tx_params)
test_user_key_failure("offboardToUserTest", {'a': a, 'addr': tx_params['web3'].eth.default_account.address},
a, "getCTs", tx_params)
test("randomTest", {}, last_random_value, "getRandom", tx_params)
test("randomBoundedTest", {'numBits': numBits}, last_random_value, "getRandom", tx_params)
test("randomBoundedTest", {'numBits': numBits}, last_random_value, "getRandomBounded", tx_params)
test("booleanTest", {"a": bool_a, "b": bool_b, "bit": bit}, bool_a and bool_b,
"getBooleanResults", tx_params, bool_a or bool_b, bool_a ^ bool_b, not bool_a,
bool_a == bool_b, bool_a != bool_b, bool_b if bit else bool_a, bool_a)



# *** Not supported in testnet
# test("shlTest", {'a': a, 'b': shift}, (a << shift) & 0xFF, "getAllShiftResults",
# tx_params, (a << shift) & 0xFFFF, (a << shift) & 0xFFFFFFFF, (a << shift) & 0xFFFFFFFFFFFFFFFF)
# test("shrTest", {'a': a, 'b': shift}, a >> shift, "getResult", tx_params)


def main():
load_dotenv()
print("Running pre-compiles example testing...")
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ websockets==12.0
yarl==1.9.2
cryptography==3.4.8
python-dotenv==1.0.1
coti_sdk==0.1.16
coti_sdk==1.0.0