Giter Club home page Giter Club logo

gotham-city's Introduction

Build Status

Gotham City

Gotham city is a fully functional client/server application for issuing two party ECDSA signatures.


Server

Gotham server is an ECDSA agnostic signing machine. List of supported Curve(s):

  • secp256k1

Client

You can see a full fledged example of a client which connects to gotham server under: integration-tests/test_ecdsa_key_signing

Project Description

Design Overview

ECDSA Keygen and Signing

ECDSA

Cryptographic libraries

For more information, see our white paper.

Benchmarks

In a local networking setup, with a MacBook Air M2, 8GB RAM and macOS 13.5:

  • cargo bench --bench keygen_bench reports 762ms
  • cargo bench --bench sign_bench reports 151ms

Disclaimer

USE AT YOUR OWN RISK, we are not responsible for software/hardware and/or any transactional issues that may occur while using Gotham city.The project is currently work in progress.

License

See LICENSE for more information.

Contact

For any questions, feel free to email us or join ZenGo X Telegram.

gotham-city's People

Contributors

boazarad88 avatar dependabot[bot] avatar elichai avatar gbenattar avatar github-actions[bot] avatar leontiadzen avatar max-zengo avatar oleiba avatar omershlo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gotham-city's Issues

[FEAT]: port to gotham-engine all the http endpoints and make gotham-city depend on gotham engine

Principles

  • Public Gotham must be functional and implement our most updated MPC crypto
  • Private Gotham should actually use public Gotham for MPC crypto (no code duplication)

Solution

Maybe if at trait default implementation we can parametrize to take another trait impl as input. Sth like dynamic dispatcher in c++. We would like the keygen and sign to decide at compile time which specific keygen and sign will execute. Can we?

//idea is to have all traits implement all default behavior and being generic over db and authenticator. Problem is the async nature of gotham functions which is not supported maturely enough by traits in current stable rust.
enum dbConnector {
    rocksDB,
    dynamoDB,
		...
}
enum authenticator {
    None,
    jwt,
		...
}

Struct PublicGotham{
dbType:   dbConnector;
auth: authenticator;
}

Struct PrivateGotham{
dbType:   dbConnector;
auth: authenticator;
}

pub trait Db {
type dbConnector;

	fn insert(&self,db:dbConnector,item) -> Result<>;
	fn delete(&self,db:dbConnector,item) -> Result<>;
	fn get(&self,db:dbConnector,item) -> Result<>;

}


impl Db for PublicGotham{
	fn insert(&self,db:dbConnector,item) -> Result<>{
...
}
	fn delete(&self,db:dbConnector,item) -> Result<>
{
...
}
	fn get(&self,db:dbConnector,item) -> Result<>
{
...
}
}


impl Db for PrivateGotham{
	fn insert(&self,db:dbConnector,item) -> Result<>{
...
}
	fn delete(&self,db:dbConnector,item) -> Result<>
{
...
}
	fn get(&self,db:dbConnector,item) -> Result<>
{
...
}
}

//async trait might be a blocker: https://rust-lang.github.io/async-book/07_workarounds/05_async_in_traits.html
//only in nightly and not mature enough: https://blog.rust-lang.org/inside-rust/2022/11/17/async-fn-in-trait-nightly.html
//not sure if the macros of rocket framework for http endpoints can be implemented at default trait functions
//might be impossible to connect trait functions as routes to rocket: https://github.com/ZenGo-X/zengo-gotham-city/blob/77cf354d8fcfd2865e2549110d0054d52bc96292/gotham-server/src/server.rs#L77
// trait functions are callable from their struct types. but here those functions are never explicitely called they are http async endpoints. Do not know how to call them. 

trait KeyGen<S: Db> {
#[post("/ecdsa/keygen/first", format = "json")]
    async fn first(&self, dbConn: S){
				S.insert()...// at this point trait does not know which gotham will be run time called thanks to dbConn abstraction. That is what we want. Not sure it compiles though.
				two_party_ecdsa...
				S.get()...
}
#[post("/ecdsa/keygen/<id>/second", format = "json", data = "<dlog_proof>")]
		async fn second(&self, dbConn: S){
				...
}
#[post(
    "/ecdsa/keygen/<id>/third",
    format = "json",
    data = "<party_2_pdl_first_message>"
)]
		async fn third(&self, dbConn: S){
				...
}
#[post(
    "/ecdsa/keygen/<id>/fourth",
    format = "json",
    data = "<party_two_pdl_second_message>"
)]
		async fn fourth(&self, dbConn: S){
				...
}
    
}

trait Sign<S: Db> {
    async fn sign_first(&self, dbConn: S){
				...
}
		async fn sign_second(&self, dbConn: S){
			  ...
}
    
}



impl<S: Db> KeyGen<S> for PublicGotham {}
impl<S: Db> KeyGen<S> for PrivateGotham {}


impl<S: Db> Sign<S> for PublicGotham {}
impl<S: Db> Sign<S> for PrivateGotham {}

let public = PublicGotham {
dbType:   dbConnector::rocksDB,
auth: authenticator::None,
};

let private = PrivateGotham {
dbType:   dbConnector::dynamoDB,
auth: authenticator::jwt,
};



//the question is can we put the trait default functions as routes to rocket:
rocket::Rocket::build()
        .mount(
            "/",
            routes![
                crate::routes::ecdsa::public::first,
                crate::routes::ecdsa::public::second,
                crate::routes::ecdsa::public::third,
                crate::routes::ecdsa::public::fourth,
                crate::routes::ecdsa::public::sign_first,
                crate::routes::ecdsa::public::sign_second,
            ],
        )

//and appropriately for PrivateGotham Struct:
rocket::Rocket::build()
        .mount(
            "/",
            routes![
                crate::routes::ecdsa::private::first,
                crate::routes::ecdsa::private::second,
                crate::routes::ecdsa::private::third,
                crate::routes::ecdsa::private::fourth,
                crate::routes::ecdsa::private::sign_first,
                crate::routes::ecdsa::private::sign_second,
            ],
        )`

Eliminate SerDes of PrivateShare and MasterKeys

right now we need serialize/ deserialize to support:

  1. client side:
    [A] save and load wallet
    [B] c API call to sign reads wallet from input json

  2. server side:
    [A] to save and load master key, and private share to the DB

1A is easy since I can just remove this save/load functionality. @gbenattar any ideas about 1B and 2A ?

feature has been removed

Compiling paillier v0.3.0 (https://github.com/KZen-networks/rust-paillier?tag=v0.3.0#735c95ec)
Compiling publicsuffix v1.5.4
error[E0557]: feature has been removed
--> /root/.cargo/git/checkouts/rust-paillier-5e0399ff4bbd1793/735c95e/src/lib.rs:1:12
|
1 | #![feature(custom_attribute)]
| ^^^^^^^^^^^^^^^^ feature has been removed
|
= note: removed in favor of #![register_tool] and #![register_attr]

error: aborting due to previous error

For more information about this error, try rustc --explain E0557.
error: could not compile paillier.

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed

[BUG]:build failed

Description

note: ld: library not found for -lgmp

Reproduce

cargo run --release

Environment

rustc 1.71.1 (eb26296b5 2023-08-03)

OS + Version:

Cargo Version:

HW type:

Additional context

Please provide any additional context that may be helpful in confirming and resolving this issue.

Cross Compile & Link Gotham Client and GMP for Android Architectures

Currently running into the following runtime error when loading .so after compiling GMP and Gotham City and linking in Android:

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "SSL_CTX_free" referenced by /lib/arm64/libclient_lib.so

Reproduce

  • Running macOS Mojave Kaby Lake
  • GMP 6.1.2 source code
  • Gotham City source code branch two-party-eddsa with eddsa folder and dependencies removed (with the dependencies Gotham cross compile fails with -lgmp error)
  • Added JNI wrapper for KeyGen ECDSA
  • Android prebuilt NDKs
  • Scripts are run from project root

Android Folder Structure
app
|_src
|__main
|___java
|___jniLibs
|____arm64-v8a
|_____libclient_lib.so
|_____libgmp.so

In android app build.gradle I have:
ndk { abiFilters "arm64-v8a" }

In MainActivity.kt I have:
companion object{
init {
System.loadLibrary("gmp")
System.loadLibrary("client_lib")
}
}

Project Folder Structure
project
|__rust
|___gmp-6.1.2 (source)
|___src (gotham-city/gotham-client source)
build_gmp.sh
build_gotham.sh

GMP Build Script
---------START SCRIPT---------
out_dir="out"
out_dir_temp="out_temp"
root=$PWD/rust/gmp-6.1.2/

rm -rf ${root}/${out_dir_temp}
mkdir ${root}/${out_dir_temp}
mv $PWD/rust/gmp-6.1.2/${out_dir}/* $PWD/rust/gmp-6.1.2/${out_dir_temp}/

export BASE_CFLAGS='-O2 -g -pedantic -fomit-frame-pointer -Wa,--noexecstack -ffunction-sections -funwind-tables -no-canonical-prefixes -fno-strict-aliasing'

cd ./rust/gmp-6.1.2/

export LDFLAGS='-Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now'
export CFLAGS="${BASE_CFLAGS} -fstack-protector-strong -finline-limit=300 -funswitch-loops"
export CC="aarch64-linux-android23-clang"
export CXX="aarch64-linux-android23-clang++"

./configure --prefix=/usr --disable-shared --enable-cxx --build=x86_64-pc-linux-gnu --host=aarch64-linux-android MPN_PATH="arm64 generic"
sed -i.bak '/HAVE_LOCALECONV 1/d' ./config.h
make -j8 V=1 2>&1 | tee arm64-v8a.log
mkdir ${out_dir}/aarch64-linux-android
make install DESTDIR=$PWD/${out_dir}/aarch64-linux-android
cd ${out_dir}/aarch64-linux-android && mv usr/lib/* ./ && mv usr/include/* ./ && rm -rf usr

---------END SCRIPT---------

Gotham Compilation
---------START SCRIPT---------

root=$PWD
cd ./rust
export SYSROOT="$toolchain_bin_dir/../sysroot"
CC=Library/Android/sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android23-clang
CXX=Library/Android/sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android23-clang++
LDFLAGS=""
CFLAGS=""
AR=Library/Android/sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-ar
cargo rustc --target "aarch64-linux-android" --release -- -L ${root}/rust/gmp-6.1.2/out/aarch64-linux-android

---------END SCRIPT---------

Cargo Config
[target.aarch64-linux-android]
ar = "$HOME/Library/Android/sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-ar"
linker = "$HOME/Library/Android/sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android23-clang"

Zeroize version issue

When trying to compile gotham-client on cyclic-dependency branch, getting the error below:

    Updating git repository `https://github.com/KZen-networks/rust-gmp`
    Updating crates.io index
    Updating git repository `https://github.com/KZen-networks/centipede`
    Updating git repository `https://github.com/KZen-networks/curv`
    Updating git repository `https://github.com/KZen-networks/rust-electrumx-client`
    Updating git repository `https://github.com/KZen-networks/kms-secp256k1`
    Updating git repository `https://github.com/KZen-networks/multi-party-ecdsa`
    Updating git repository `https://github.com/KZen-networks/multi-party-eddsa`
    Updating git repository `https://github.com/KZen-networks/multi-party-schnorr`
    Updating git repository `https://github.com/KZen-networks/zk-paillier`
    Updating git repository `https://github.com/KZen-networks/bulletproofs`
error: failed to select a version for the requirement `zeroize = "^0.10"`
  candidate versions found which didn't match: 1.5.0, 1.4.3, 1.4.2, ...
  location searched: crates.io index
required by package `curv v0.2.3 (https://github.com/KZen-networks/curv?tag=v0.2.3#d6c575b5)`
    ... which is depended on by `gotham-client v0.1.3 (/home/akurt/gotham-city/gotham-client)`

Ubuntu 16.04
rustc version: rustc 1.44.0-nightly (b2e36e6c2 2020-04-22)
rustup version: rustup 1.24.3 (ce5817a94 2021-05-31)

Build Error due to conflicting versions of two_party_ecdsa crate

Description:
I encountered the above build error while working on the project. It seems to be caused by conflicting versions of the two_party_ecdsa crate. Specifically, the error suggests that there are two different versions of the crate being used, resulting in incompatible trait signatures for methods insert and get.

Error:

error[E0053]: method `insert` has an incompatible type for trait
  --> gotham-server/src/public_gotham.rs:56:1
   |
56 | #[async_trait]
   | ^^^^^^^^^^^^^^ expected trait `two_party_ecdsa::party_one::Value`, found a different trait `two_party_ecdsa::party_one::Value`
   |
   = note: expected signature `fn(&'life0 PublicGotham, &'life1 gotham_engine::types::DbIndex, &'life2 (dyn gotham_engine::traits::MPCStruct + 'life2), &'life3 (dyn two_party_ecdsa::party_one::Value + 'static)) -> Pin<_>`
              found signature `fn(&'life0 PublicGotham, &'life1 gotham_engine::types::DbIndex, &'life2 (dyn gotham_engine::traits::MPCStruct + 'life2), &'life3 (dyn two_party_ecdsa::party_one::Value + 'static)) -> Pin<_>`
   = note: perhaps two different versions of crate `two_party_ecdsa` are being used?

error[E0053]: method `get` has an incompatible type for trait
  --> gotham-server/src/public_gotham.rs:56:1
   |
56 | #[async_trait]
   | ^^^^^^^^^^^^^^ expected trait `two_party_ecdsa::party_one::Value`, found a different trait `two_party_ecdsa::party_one::Value`
   |
   = note: expected signature `fn(&'life0 PublicGotham, &'life1 gotham_engine::types::DbIndex, &'life2 (dyn gotham_engine::traits::MPCStruct + 'life2)) -> Pin<Box<(dyn std::future::Future<Output = Result<std::option::Option<Box<(dyn two_party_ecdsa::party_one::Value + 'static)>>, gotham_engine::types::DatabaseError>> + std::marker::Send + 'async_trait)>>`
              found signature `fn(&'life0 PublicGotham, &'life1 gotham_engine::types::DbIndex, &'life2 (dyn gotham_engine::traits::MPCStruct + 'life2)) -> Pin<Box<(dyn std::future::Future<Output = Result<std::option::Option<Box<(dyn two_party_ecdsa::party_one::Value + 'static)>>, gotham_engine::types::DatabaseError>> + std::marker::Send + 'async_trait)>>`
   = note: perhaps two different versions of crate `two_party_ecdsa` are being used?

Environment:
rustc 1.75.0

Runtime comparison

Dear KZen members,

We noticed that you compared the run times of your repository with our blockchain-crypto-mpc repository. In your code we see that you use multi-threading, so we updated our library to use multi-threading as well. This change should provide a more “apples-to-apples” comparison.

We also added a benchmarking tool for our algorithms that, we feel, provides a more accurate measurement of the run time.

We kindly suggest you run the tests again – we are interested in seeing the results.

Best Regards,

Dr. Samuel Ranellucci
Cryptographer, Unbound Tech

I use rust toolchain [rustc 1.72.0-nightly (8b35c0bb0 2023-06-08)] to compile the work space, but error appears

I use rust toolchain [rustc 1.72.0-nightly (8b35c0bb0 2023-06-08)] to compile the gotham-city/gotham-client, but error appears:

   Compiling tokio-io v0.1.13
   Compiling net2 v0.2.38
   Compiling lock_api v0.3.4
   Compiling openssl-sys v0.9.84
error[E0599]: no method named `includes` found for mutable reference `&mut Build` in the current scope
   --> /home/node/.cargo/registry/src/index.crates.io-6f17d22bba15001f/openssl-sys-0.9.84/build/run_bindgen.rs:192:10
    |
190 | /     cc::Build::new()
191 | |         .file(out_dir.join("boring_static_wrapper.c"))
192 | |         .includes(include_dirs)
    | |         -^^^^^^^^ help: there is a method with a similar name: `include`
    | |_________|
    |

For more information about this error, try `rustc --explain E0599`.
error: could not compile `openssl-sys` (build script) due to previous error

which version of rust should I use? help!

How do I get the master address and master key right after create the wallet

Hello KZen people,

First, thank you very much for your cool product 👍 .

Really like multi-parties idea, I wish to try gotham-city as a wallet on testnet.
Currently, I was setup the server and was able to build your client.

After run "./cli create-wallet", got
(id: 0ce94885-fe95-4d11-b497-85d92f5aae74) Took: PT4.914320007S
Network: [testnet], Wallet saved to disk

When digging to wallet.data, I found that "master_key" is created.
Please help me that: at this step, how do I get the master address and master key (manually)?
Thank you.

Sincerely,
Quang, VU

Gotham goes real

The library has many points of improvements at the system/networking level:
Observations:

  • rocket facilitates code writing for web apps by abstracting low-level networking functionality at the level of Http server/client with routes points but seems too heavy for the needs of a two-party protocol.
  • Communication is blocking and synchronous per client.
  • json ser/de can be deprecated with a binary encoding format for MPC protocol specific messages.
  • There is no need to build the networking stack over http.

Possible directions:
[Gotham 2.0]

  • Keeping the same communication model: server/client over http; rocket can be deprecated with a lighter framework wrapped around tokio async runtime with hyper or tower (to investigate: https://crates.io/crates/ntex). As both hyper and tower act as wrappers of tokio that would allow better low level flexibility:
  1. binary encoding/decoding of messages
  2. framing the communicated bytestream to follow the application logic for better handling the message dispatcher
  3. 1-1 map to the underlying tokio runtime for taking advantage of concurrent execution at different levels: client is not blocked when expecting something from the server, server is not blocking when performing a task for a specific response.

[Gotham 3.0]

  • Once the Gotham 2.0 is stable by keeping the same communication model and deprecating rocket, a possible transition to an agnostic in the number of nodes protocol not relying to HTTP, just using sockets over a tcp stream will be easier since the new Gotham 2.0 codebase will be based on low-level tokio primitives for framing/sockets/bin serde/async IO. The required logic to handle multiple parties over sockets without requiring http endpoints will be minimal leading to a possibly faster Gotham 3.

Could not send, "Negative output"

Hello KZen people,
I've have a wallet with 2 derivative addresses. When I do the transaction within these 2 addresses, there are no error.
However when I try to transfer BTC to an outside address, I got this error:
thread 'main' panicked at 'called Result::unwrap() on an Err value: Error("missing field result", line: 1, column: 122)', src/libcore/result.rs:xxx:xx
The command is:
image

Tried to take the raw transaction out and send it manually through https://testnet.smartbit.com.au/txs/pushtx, I got this error
PUSH TRANSACTION ERROR: 16: BAD-TXNS-VOUT-NEGATIVE
After decode the transaction, I found this in the output
{
"addresses": null,
"script": "001429dd1071596903f049574e8e1f8529e14a4a4737",
"script_type": "pay-to-witness-pubkey-hash",
"value": -10000
}
The whole raw is
000000000001011c65b37fa305ef8b4c4ccb9731c2b14aa7dc933acbf08e0dc845c5148c7ea8180000000000ffffffff02e8030000000000001976a91452db02dda5c812097c67307ee63c23c22ea955e288acf0d8ffffffffffff16001429dd1071596903f049574e8e1f8529e14a4a473702473044022065ef7a2f120198f4acb7048edf90d070622583149eeb38c5fecb9f669e669b6202200532d8662932be31ae2586364f8fb7862ac93d0464eb07599e518eb468f0f0830121036b3a6ead2e7617c155f39f2f1b9a8ec963c0fb0b3c46154ea1074fe14d4221bb00000000

Hope to hear from you soon :)

Thank you

The security of client in gotham-city

I think there has a security problem according to the logic of gotham-city. The private key x2 of client and a common public share "master key" are saved on the client side. If the attacker gets the data of the client, can the private key of the wallet be calculated according to Q and x2?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.