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

Add diagrams #18

Open
wants to merge 4 commits into
base: main
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
36 changes: 27 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
cmake_minimum_required(VERSION 3.13)
cmake_minimum_required(VERSION 3.27)

# Fix for check_source_compiles: C: needs to be enabled before use.
# set(CMAKE_USER_MAKE_RULES_OVERRIDE "cmake_cpp_rules.cmake")

project(mpc-lib LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_VERBOSE_MAKEFILE ON)

set(CMAKE_INCLUDE_CURRENT_DIR ON)## Always include the current directory

set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL REQUIRED)

if(NOT TARGET OpenSSL::Crypto)
set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL 1.1.1 EXACT REQUIRED)
set(CMAKE_VERBOSE_MAKEFILE ON)

if(WIN32)
message("https://cmake.org/cmake/help/latest/variable/WIN32.html?highlight=win32")
elseif(APPLE)
message("https://cmake.org/cmake/help/latest/variable/APPLE.html?highlight=apple")
elseif(UNIX)
message("https://cmake.org/cmake/help/latest/variable/UNIX.html?highlight=unix")
check_library_exists(snappy snappy_compress "" HAVE_SNAPPY)
endif()


# set fpic
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

add_subdirectory(src/common)
enable_testing()
add_subdirectory(test)

if(NOT MPC_LIB_SKIP_TESTS)
enable_testing()
add_subdirectory(test)
endif()
Binary file added diagrams/ecdsa-activity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
183 changes: 183 additions & 0 deletions diagrams/ecdsa-activity.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
@startuml
title ECDSA key setup for tests




package setup {

abstract class setup_key_persistency {
store_key()
store_key_metadata()
store_auxiliary_keys()
store_keyid_tenant_id()
store_setup_data()
load_setup_data()
store_setup_commitments()
setup_commitments()
delete_temporary_key_data()
}

setup_key_persistency --|> cmp_key_persistency

abstract class platform_service {
gen_random()
get_current_tenantid()
get_id_from_keyid()
derive_initial_share()
encrypt_for_player()
decrypt_message()
backup_key()
start_signing()
fill_signing_info_from_metadata()
is_client_id()
}

class cmp_setup_service {
generate_setup_commitments()
store_setup_commitments()
generate_setup_proofs()
verify_setup_proofs()
create_secret()

add_user_request()
add_user()
}

cmp_setup_service --> platform_service
cmp_setup_service --> setup_key_persistency
}

class cmp_ecdsa_signing_service {
create_mta_request()
ack_mta_request()
create_mta_response()
mta_verify()

calc_R()
derivation_key_delta()
make_sig_s_positive()
build_aad()
get_algebra()

platform_service _service
cmp_key_persistency _key_persistency
}


package offline {

class cmp_signature_preprocessed_data {
elliptic_curve_scalar k
elliptic_curve_scalar chi
elliptic_curve_point R
}

abstract class preprocessing_persistency {
store_preprocessing_metadata()
load_preprocessing_metadata()

store_preprocessing_data()
load_preprocessing_data()
delete_preprocessing_data()

create_preprocessed_data()
store_preprocessed_data()
load_preprocessed_data()
delete_preprocessed_data()
}

class cmp_ecdsa_offline_signing_service {
start_ecdsa_signature_preprocessing()
offline_mta_response()
offline_mta_verify()

store_presigning_data()
ecdsa_sign()
ecdsa_offline_signature()
cancel_preprocessing()
preprocessing_persistency _preprocessing_persistency
mutex _timing_map_lock
map<string, uint64_t> _timing_map
}
cmp_ecdsa_offline_signing_service --> preprocessing_persistency

cmp_ecdsa_offline_signing_service::start_ecdsa_signature_preprocessing .. cmp_signature_preprocessed_data
}

cmp_ecdsa_offline_signing_service --> cmp_ecdsa_signing_service

class offline_siging_info
{
offline_siging_info(uint64_t id, const cmp_key_persistency& key_persistency)\n: platform_service(id), signing_service(platform_service, key_persistency, persistency)
sign_platform platform_service
preprocessing_persistency persistency
cmp_ecdsa_offline_signing_service signing_service
}

offline_siging_info --> cmp_setup_service
offline_siging_info --> cmp_ecdsa_offline_signing_service

struct players_setup_info {
map<uint64_t, setup_persistency> players_setup_info
}

class create_secret {

// sets up a service for each player
map<uint64_t, unique_ptr<setup_info>> services

create_secret(players, ECDSA_SECP256K1, keyid, pubkey);
}


create_secret --> offline_siging_info :uses 1 per player
create_secret --> cmp_setup_service::generate_setup_commitments: calls
create_secret --> cmp_setup_service::store_setup_commitments: calls
create_secret --> cmp_setup_service::generate_setup_proofs: calls
create_secret --> cmp_setup_service::verify_setup_proofs: calls
create_secret --> cmp_setup_service::create_secret: calls


class add_user {
add_user(players, new_players, ECDSA_SECP256K1, keyid, new_keyid, pubkey)
}


class ecdsa_preprocess{
ecdsa_preprocess\n(map<uint64_t, unique_ptr<offline_siging_info>> services, const string keyid, uint32_t start, uint32_t count, uint32_t total)

/'
create_preprocessed_data
create_mta_request

'/
}
ecdsa_preprocess --> cmp_ecdsa_offline_signing_service::start_ecdsa_signature_preprocessing
' offline_mta_response


class ecdsa_sign {
ecdsa_sign(players, ECDSA_SECP256K1, keyid, 1, pubkey, chaincode, {path})
map<uint64_t, std::vector<cmp_mta_request>> mta_requests


/'
(i->second->signing_service.start_signing(keyid, txid, type, data, "", players_str, players_ids, request))
(i->second->signing_service.mta_response(txid, mta_requests, MPC_CMP_ONLINE_VERSION, response))
(i->second->signing_service.mta_verify(txid, mta_responses, delta))
'/
}

ecdsa_sign --> start_signing

class test {
players_setup_info players
' map<uint64_t, setup_persistency> players_setup_info
}
test .. players_setup_info: uses
test --> create_secret: calls
test --> ecdsa_sign: calls
test --> add_user: calls
test --> ecdsa_preprocess: calls
@enduml
44 changes: 44 additions & 0 deletions diagrams/ecdsa-msc.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
@startuml

title ecdsa message sequence chart
hide footbox

participant test as t

participant ecdsa_offline_test as ot
participant cmp_ecdsa_offline_signing_service as ss

participant cmp_ecdsa_signing_service as core
participant persistency as p

t -> ot : ecdsa_preprocess()

ot -> ss : start_ecdsa_signature_preprocessing\n(mta_requests)
ss -> p: load_key_metadata()
p --> ss: metadata
ss -> p: create_preprocessed_data()
p --> ss
ss -> core : create_mta_request()
ss -> p: store_preprocessing_data()
p --> ss
core --> ot: mta_requests

ot -> ss: offline_mta_response(mta_requests)
ss --> ot

ot -> ss: offline_mta_verify(mta_responses)
ss --> ot

ot -> ss: store_presigning_data
ss --> ot



t -> ot: ecdsa_sign(partial_sigs)
ot -> ss: ecdsa_sign(partial_sigs)
ss -> p: load_key_meta_data()
p --> ss: metadata
ss --> ot: partial_sigs
ot -> ss: ecdsa_offline_signature\n(partial_sigs, sigs)
ss -> ss: add_scalar\n(&sig.s, sig.s, it->second[i].s)
@enduml
Binary file added diagrams/eddsa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions diagrams/eddsa.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
@startuml
title EDDSA

struct asymmetric_eddsa_signature_data {
elliptic_curve_scalar k
elliptic_curve_point R
vector<uint32_t> path
byte_vector_t message
uint32_t flags
}

struct asymmetric_eddsa_signing_metadata {
string key_id
HDChaincode chaincode
vector<asymmetric_eddsa_signature_data> sig_data
set<uint64_t> signers_ids
uint32_t version
uint32_t start_index
}

asymmetric_eddsa_signing_metadata --> asymmetric_eddsa_signature_data

struct eddsa_commitment

class signing_persistency {
create_preprocessed_data()
store_preprocessed_data()
load_preprocessed_data()
delete_preprocessed_data()

store_commitments()
load_commitments()
delete_commitments()

store_signing_data()
load_signing_data()
delete_signing_data()
}
signing_persistency --> asymmetric_eddsa_signing_metadata
signing_persistency --> eddsa_commitment

struct Rs_and_commitments {
vector<elliptic_curve_point> Rs
eddsa_commitment R_commitment
}

class asymmetric_eddsa_cosigner
{
derivation_key_delta()
commit_to_r()

verify_commit_to_r()
verify_commit_to_r()

platform_service _service
cmp_key_persistency _key_persistency
elliptic_curve256_algebra_ctx_t _ctx
}


asymmetric_eddsa_cosigner --> cmp_key_persistency
asymmetric_eddsa_cosigner --> platform_service


abstract class preprocessing_persistency {
create_preprocessed_data()
store_preprocessed_data()
load_preprocessed_data()
delete_preprocessed_data()
}

class asymmetric_eddsa_cosigner_client {
start_signature_preprocessing()
eddsa_sign_offline()

preprocessing_persistency _preprocessing_persistency
}
asymmetric_eddsa_cosigner_client --|> asymmetric_eddsa_cosigner
asymmetric_eddsa_cosigner_client --> preprocessing_persistency


class asymmetric_eddsa_cosigner_server {
store_presigning_data()

eddsa_sign_offline()
decommit_r()
broadcast_r()
broadcast_si()
get_eddsa_signature()

cancel_signing()

signing_persistency _signing_persistency
mutex _timing_map_lock
map<string, uint64_t> _timing_map
}


asymmetric_eddsa_cosigner_server --|> asymmetric_eddsa_cosigner
asymmetric_eddsa_cosigner_server --> signing_persistency
asymmetric_eddsa_cosigner_server --> eddsa_signature
asymmetric_eddsa_cosigner_server --> Rs_and_commitments


@enduml
Binary file added diagrams/mpc-lib.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading