Skip to content

webb-tools/gadget

Repository files navigation

Gadget: A Powerful distributed MPC Framework

Gadget Logo

Validate PR License Rust Version

Gadget is a comprehensive framework for building multi-party computation (MPC) and restaking service gadgets. It provides a standardized and flexible approach to implementing services that interact with job management systems, such as blockchains with on-chain job management logic, and communicate with other service providers using peer-to-peer or alternative networking stacks.

Features

  • Modular and extensible architecture
  • Support for various MPC protocols and services:
  • Integration with Substrate blockchain logic and networking
  • Standardized job allocation, completion, and submission mechanisms
  • Protocol-specific blockchain connections, networking layers, and application logic
  • Comprehensive testing framework

Getting Started

Prerequisites

  • Rust 1.74.0 or higher
  • Substrate blockchain with compatible job management and submission infrastructure

Installation

  1. Clone the repository:
git clone https://github.com/webb-tools/gadget/
cd gadget
  1. Build the project:
cargo build --release

Running the Gadget Shell

The gadget shell is a standalone application that provides a command-line interface for interacting with the Gadget and the blockchain. To run the shell, use the following command:

./target/release/shell-manager --protocols-config ./global_protocols.toml --shell-config shell-configs/local-testnet-0.toml -vvv

Before running that command, make sure that a tangle node is running, otherwise, the shell will fail.

Creating a New Protocol

To create a new protocol using Gadget, follow these steps:

Create a new directory in the protocols folder with the name of your protocol (e.g., protocols/my-protocol). Copy the contents of the protocols/stub directory into your new protocol directory. Modify the Cargo.toml file in your protocol directory to include the necessary dependencies. Implement the protocol-specific logic in the src directory of your protocol. Update the tests in the tests directory to validate your protocol implementation. For more detailed instructions on creating a new protocol, refer to the README.md file in the protocols/stub directory.

Testing

This repository contains unit tests and integration tests to validate the functionality of the Gadget framework and its interaction with the blockchain.

Unit Testing

To run the tests, use the following command:

RUST_LOG=gadget=trace cargo nextest run

Integration testing

Integration testing involves a multi-step process that includes running a tangle node, running multiple gadget shells each with a separate config, and submitting jobs manually. To run the integration tests, make sure the aforementioned steps are followed for building the executables, then, follow these steps:

  1. Run a tangle node from the tangle repository
bash ./scripts/run-standalone-local.sh --clean 
  1. Run Gadgets
bash ./scripts/run-gadget-local.sh
  1. Once the shells are running, open a separate terminal, navigate to the tangle directory, and run:
cd types && yarn && ts-node playground.ts 
  1. View the progress by navigating in a web browser here

Troubleshooting

GMP Issues

If you encounter linking errors related to libgmp (e.g., "could not find library -lgmp") when building on a Mac M1, follow these steps:

  1. Install GMP using Homebrew:
brew install gmp
  1. Set the LIBRARY_PATH and INCLUDE_PATH environment variables:
export LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/lib
export INCLUDE_PATH=$INCLUDE_PATH:/opt/homebrew/include

Note: You need to set these environment variables each time you start a new shell session or append them to your .zshrc file.

Contributing

We welcome contributions to Gadget! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request.

License

Gadget is licensed under the MIT License

Acknowledgements

We would like to thank the following projects for their inspiration and contributions to this repository:

Contact

If you have any questions or need further information, please contact the developers here