Skip to content

Commit

Permalink
upstream recent changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ekjnk authored and nadav-fireblocks committed Dec 2, 2024
1 parent ac6b6bc commit 1fb5d2a
Show file tree
Hide file tree
Showing 13 changed files with 1,974 additions and 414 deletions.
4 changes: 2 additions & 2 deletions include/cosigner/cmp_ecdsa_signing_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace cosigner

namespace mta
{
class response_verifier;
class base_response_verifier;
}

class cmp_key_persistency;
Expand Down Expand Up @@ -101,7 +101,7 @@ class COSIGNER_EXPORT cmp_ecdsa_signing_service
static cmp_mta_response create_mta_response(ecdsa_signing_data& data, const elliptic_curve256_algebra_ctx_t* algebra, uint64_t my_id, const std::vector<uint8_t>& aad, const cmp_key_metadata& metadata,
const std::map<uint64_t, std::vector<cmp_mta_request>>& requests, size_t index, const elliptic_curve_scalar& key, const auxiliary_keys& aux_keys);
static cmp_mta_deltas mta_verify(ecdsa_signing_data& data, const elliptic_curve256_algebra_ctx_t* algebra, uint64_t my_id, const std::string& uuid, const std::vector<uint8_t>& aad, const cmp_key_metadata& metadata,
const std::map<uint64_t, cmp_mta_responses>& mta_responses, size_t index, const auxiliary_keys& aux_keys, std::map<uint64_t, mta::response_verifier>& verifers);
const std::map<uint64_t, cmp_mta_responses>& mta_responses, size_t index, const auxiliary_keys& aux_keys, std::map<uint64_t, std::unique_ptr<mta::base_response_verifier>>& verifiers);
static void calc_R(ecdsa_signing_data& data, elliptic_curve_point& R, const elliptic_curve256_algebra_ctx_t* algebra, uint64_t my_id, const std::string& uuid, const cmp_key_metadata& metadata,
const std::map<uint64_t, std::vector<cmp_mta_deltas>>& deltas, size_t index);

Expand Down
9 changes: 4 additions & 5 deletions src/common/cosigner/cmp_ecdsa_offline_signing_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,24 +200,23 @@ uint64_t cmp_ecdsa_offline_signing_service::offline_mta_verify(const std::string
}

std::string uuid = metadata.key_id + request_id;
std::map<uint64_t, mta::response_verifier> verifers;
std::map<uint64_t, std::unique_ptr<mta::base_response_verifier>> verifiers;
for (auto it = mta_responses.begin(); it != mta_responses.end(); ++it)
{
if (it->first == my_id)
continue;
const auto& other = key_md.players_info.at(it->first);
auto aad = build_aad(uuid, it->first, key_md.seed);

mta::response_verifier verifer(it->first, algebra, aad, aux.paillier, other.paillier, aux.ring_pedersen);
verifers.emplace(it->first, std::move(verifer));
verifiers[it->first] = mta::new_response_verifier(metadata.count, it->first, algebra, aad, aux.paillier, other.paillier, aux.ring_pedersen);
}

auto aad = build_aad(uuid, my_id, key_md.seed);
for (size_t i = 0; i < metadata.count; i++)
{
ecdsa_signing_data data;
_preprocessing_persistency.load_preprocessing_data(request_id, metadata.start_index + i, data);
cmp_mta_deltas delta = mta_verify(data, algebra, my_id, uuid, aad, key_md, mta_responses, i, aux, verifers);
cmp_mta_deltas delta = mta_verify(data, algebra, my_id, uuid, aad, key_md, mta_responses, i, aux, verifiers);
deltas.push_back(std::move(delta));
_preprocessing_persistency.store_preprocessing_data(request_id, metadata.start_index + i, data);
}
Expand All @@ -226,7 +225,7 @@ uint64_t cmp_ecdsa_offline_signing_service::offline_mta_verify(const std::string
{
if (it->first == my_id)
continue;
verifers.at(it->first).verify();
verifiers.at(it->first)->verify();
}

return my_id;
Expand Down
9 changes: 4 additions & 5 deletions src/common/cosigner/cmp_ecdsa_online_signing_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,31 +257,30 @@ uint64_t cmp_ecdsa_online_signing_service::mta_verify(const std::string& txid, c
}

std::string uuid = metadata.key_id + txid;
std::map<uint64_t, mta::response_verifier> verifers;
std::map<uint64_t, std::unique_ptr<mta::base_response_verifier>> verifiers;
for (auto it = mta_responses.begin(); it != mta_responses.end(); ++it)
{
if (it->first == my_id)
continue;
const auto& other = key_md.players_info.at(it->first);
auto aad = build_aad(uuid, it->first, key_md.seed);

mta::response_verifier verifer(it->first, algebra, aad, aux.paillier, other.paillier, aux.ring_pedersen);
verifers.emplace(it->first, std::move(verifer));
verifiers[it->first] = mta::new_response_verifier(metadata.sig_data.size(), it->first, algebra, aad, aux.paillier, other.paillier, aux.ring_pedersen);
}

auto aad = build_aad(uuid, my_id, key_md.seed);
for (size_t i = 0; i < metadata.sig_data.size(); i++)
{
cmp_signature_data& data = metadata.sig_data[i];
cmp_mta_deltas delta = cmp_ecdsa_signing_service::mta_verify(data, algebra, my_id, uuid, aad, key_md, mta_responses, i, aux, verifers);
cmp_mta_deltas delta = cmp_ecdsa_signing_service::mta_verify(data, algebra, my_id, uuid, aad, key_md, mta_responses, i, aux, verifiers);
deltas.push_back(std::move(delta));
}

for (auto it = mta_responses.begin(); it != mta_responses.end(); ++it)
{
if (it->first == my_id)
continue;
verifers.at(it->first).verify();
verifiers.at(it->first)->verify();
}

_signing_persistency.update_cmp_signing_data(txid, metadata);
Expand Down
18 changes: 14 additions & 4 deletions src/common/cosigner/cmp_ecdsa_signing_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,19 @@ cmp_mta_response cmp_ecdsa_signing_service::create_mta_response(ecdsa_signing_da
return resp;
}

cmp_mta_deltas cmp_ecdsa_signing_service::mta_verify(ecdsa_signing_data& data, const elliptic_curve256_algebra_ctx_t* algebra, uint64_t my_id, const std::string& uuid, const std::vector<uint8_t>& aad, const cmp_key_metadata& metadata,
const std::map<uint64_t, cmp_mta_responses>& mta_responses, size_t index, const auxiliary_keys& aux_keys, std::map<uint64_t, mta::response_verifier>& verifers)
cmp_mta_deltas cmp_ecdsa_signing_service::mta_verify(
ecdsa_signing_data& data, //this block singing data
const elliptic_curve256_algebra_ctx_t* algebra,
uint64_t my_id,
const std::string& uuid,
const std::vector<uint8_t>& aad, //this party's aad
const cmp_key_metadata& metadata, //all parties public metadata (public share, paillier, rind pedersen)
const std::map<uint64_t, cmp_mta_responses>& mta_responses, //all responses from all parties
size_t index, //this block (message) index
const auxiliary_keys& aux_keys,
std::map<uint64_t, std::unique_ptr<mta::base_response_verifier> >& verifiers)
{
//iterate over all responses from all signers
for (auto it = mta_responses.begin(); it != mta_responses.end(); ++it)
{
if (it->first == my_id)
Expand All @@ -138,11 +148,11 @@ cmp_mta_deltas cmp_ecdsa_signing_service::mta_verify(ecdsa_signing_data& data, c
}
pub.gamma_commitment.clear();
cmp_mta_message& gamma_mta = const_cast<cmp_mta_message&>(it->second.response[index].k_gamma_mta.at(my_id));
verifers.at(it->first).process(data.mta_request, gamma_mta, pub.GAMMA);
verifiers.at(it->first)->process(data.mta_request, gamma_mta, pub.GAMMA);
auto alpha = mta::decrypt_mta_response(it->first, algebra, std::move(gamma_mta.message), aux_keys.paillier);
throw_cosigner_exception(algebra->add_scalars(algebra, &data.delta.data, data.delta.data, sizeof(elliptic_curve256_scalar_t), alpha.data, sizeof(elliptic_curve256_scalar_t)));
cmp_mta_message& x_mta = const_cast<cmp_mta_message&>(it->second.response[index].k_x_mta.at(my_id));
verifers.at(it->first).process(data.mta_request, x_mta, other.public_share);
verifiers.at(it->first)->process(data.mta_request, x_mta, other.public_share);
alpha = mta::decrypt_mta_response(it->first, algebra, std::move(x_mta.message), aux_keys.paillier);
throw_cosigner_exception(algebra->add_scalars(algebra, &data.chi.data, data.chi.data, sizeof(elliptic_curve256_scalar_t), alpha.data, sizeof(elliptic_curve256_scalar_t)));
throw_cosigner_exception(algebra->add_points(algebra, &data.GAMMA.data, &data.GAMMA.data, &pub.GAMMA.data));
Expand Down
Loading

0 comments on commit 1fb5d2a

Please sign in to comment.