Skip to content
This repository has been archived by the owner on Jun 23, 2021. It is now read-only.

Latest commit

 

History

History
73 lines (58 loc) · 9.4 KB

M1_code_documentation.md

File metadata and controls

73 lines (58 loc) · 9.4 KB

Code Documentation for M1

This page describes the implemented functions of M1 with corresponding code references.

substraTEE-node

substraTEE-worker

Description of the functionality

The substraTEE-worker implements three main functions:

  1. Instruct the enclave to generate a RSA3072 key pair which is used for encrypting the payload sent from the substraTEE-client to the substraTEE-worker. This is done with the command getpublickey.

    • Important: only the public key leaves the enclave while the private key stays in the enclave.
  2. Instruct the enclave to generate a ED25519 key pair which is used for signing the extrinsic sent from the substraTEE-worker to the substraTEE-node. This is done with the command getsignkey.

    • Important: only the public key leaves the enclave while the private key stays in the enclave.
  3. Subscribe to substraTEE-proxy events, forward any received payload to the enclave and send the extrinsic (that is composed in the enclave) back to the substraTEE-node. This is done with the command worker.

Implementation

The functions are implemented at the following places:

Important: Only the functions defined in enclave/Enclave.edl are allowed to be called in the enclave. The return values also have to be defined here.

Funtion 1: RSA3072 key pair generation

Function 2: ED25519 key pair generation

Same principle as Function 1 but starting at line 107 in the worker/src/enclave_wrappers.rs

Function 3: Process encrypted payload from the substraTEE-node

substraTEE-client

The client is a sample implementation and only serves the purpose to demonstrate the functionalities of the substraTEE-node and –worker. It implements the following sequence:

  • client/src/main.rs:59: Get the free balance from //Alice
  • client/src/main.rs:62: Get the current account nonce of //Alice
  • client/src/main.rs:65: Fund //Alice with 1_000_000
  • client/src/main.rs:70: Transfer 1000 from //Alice to the account of the TEE (identified by the public ED25519 key of the enclave)
  • client/src/main.rs:73: Compose an extrinsic with an encrypted payload (using the public RSA3072 key of the enclave).
    • The payload contains the string Alice,42 which means that the account of Alice will be incremented by 42 in the enclave
  • client/src/main.rs:86: Send the extrinsic to the substraTEE-node to the function “call_worker” of the substratee-proxy module and wait for the confirmation that the transaction got finalized
  • client/src/main.rs:92: Use the substrate-api-client to subscribe to the event CallConfirmed of the substraTEE-node
  • client/src/main.rs:94: When the event was received, print out the calculated and the received hash of the (unencrypted) payload