Code Monkey home page Code Monkey logo

secretnetwork's Introduction

Secret Network

Secret Network offers scalable permissionless smart contracts with a private by default design— bringing novel use cases to blockchain not feasible on public systems. Secret Network enables users to take back ownership over their private (financial) information and for them to share this information with whom they trust. Secret Network was the first protocol to provide private smart contracts on mainnet, live since September 2020. Secret Network is Built with the Cosmos Software Development Kit (SDK) bringing Interoperable privacy to the entire Cosmos ecosystem. Secret Network uses a combination of the Intel SGX (Software Guard Extension) Trusted Execution Environment technology, several encryption schemes and key management to bring privacy by default to blockchain users. Secret Contracts are an implementation of the Rust based smart contract compiling toolkit CosmWasm, adding private metadata possibilities. Secret Network is powered by the Native public coin SCRT which is used for fees, Proof Of Stake security and Governance. With more than 20+ Dapps, 100+ full time builders and a strong grassroots community Secret Network aims to bring privacy to the masses.

Setting up Environment

Prebuilt Environment

Gitpod

Click the button below to start a new development environment:

Open in Gitpod

VSCode Docker Environment

  1. Install extension

  2. Clone this repository into a new dev container

Docker Dev Environments

  1. From Docker Desktop, create a new Dev Environment from the prebuilt image - ghcr.io/scrtlabs/secretnetwork-dev:latest
  2. Connect with VSCode, or use the container directly
  3. Make sure the code is updated by using get fetch and git pull

Manual Set up

You can find everything below in a handy script that you can copy and run from here

Install prerequisite packages

apt-get install -y --no-install-recommends g++ libtool automake autoconf clang

Ubuntu 22+

The build depends on libssl1.1. Install using:

wget https://debian.mirror.ac.za/debian/pool/main/o/openssl/libssl1.1_1.1.1w-0%2Bdeb11u1_amd64.deb
dpkg -i libssl1.1_1.1.1w-0%2Bdeb11u1_amd64.deb

Clone Repo

Clone this repo to your favorite working directory

Install Rust

Install rust from https://rustup.rs/.

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Then, add the rust-src component. This will also install the version of rust that is defined by the workspace (in rust-toolchain) -

rustup component add rust-src

To run tests you'll need to add the wasm32 target -

rustup target add wasm32-unknown-unknown

Install Go (v1.18+)

Install go from https://go.dev/doc/install

Install gobindata

sudo apt install go-bindata

Install SGX

To compile the code and run tests, you'll need to install the SGX SDK and PSW. To run in simulation (or software) modes of SGX you do not need to install the SGX driver. For a simple install, run the install-sgx.sh script in the following way:

chmod +x ./scripts/install-sgx.sh
sudo ./scripts/install-sgx.sh true true true false

Note: If you are using WSL you'll need to use the 5.15 kernel which you can find how to do here, otherwise you'll have to run anything SGX related only in docker

Install Xargo

We need a very specific version of xargo for everything to compile happily together

cargo install xargo --version 0.3.25

Install submodules

We use incubator-teaclave-sgx-sdk as a submodule. To compile the code, you must first sync this submodule

git submodule init
git submodule update --remote

Build from Source

Use make build-linux to build the entire codebase. This will build both the Rust (enclave & contract engine) and the Go (blockchain) code.

To build just the rust code, you can use make build-linux, while to build just the Go code, there is the aptly named make build_local_no_rust.

Tip: For a production build the enclave must be copied from the most recent release. This is due to non-reproducible builds, and the fact that enclaves must be signed with a specific key to be accepted on mainnet. Still, the non-enclave code can be modified and ran on mainnet as long as there are no consensus-breaking changes

Running Something

Run tests

To build run all tests, use make go-tests

Start local network

Run ./scripts/start-node.sh

Documentation

For the latest documentation, check out https://docs.scrt.network

Community

secretnetwork's People

Contributors

aronvanammers avatar assafmo avatar cankisagun avatar cashmaney avatar darwinzer0 avatar daviddemeij avatar dbriggsie avatar dependabot[bot] avatar dylanschultzie avatar eshelb avatar faddat avatar fishmanl avatar guyz avatar ikapitonau avatar itshaseebsaeed avatar jlwaugh avatar kent-3 avatar lacabra avatar levackt avatar liorbond avatar luca992 avatar luiseel avatar mohammedpatla avatar privatepixels avatar reuvenpo avatar sbellem avatar secretchaingirl avatar the-dusky avatar toml01 avatar valdok 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  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

secretnetwork's Issues

Compile CosmWasm to SGX

  • Review compilation process of helloworld rust program to SGX
  • Compile a helloworld rust program/static library to SGX
  • find and work around all uses of the filesystem in go-cosmwasm
  • Apply to CosmWasm
  • Add to Makefile
  • Test a simple stateless contract deployment+execution
  • Test a simple stateful contract deployment+execution

Compile to Mac & Windows

  1. Compile the current mainnet release to Mac & Window.
  2. Also add this to Makefile
  3. Add docs on how to use enigmacli from any host by connecting to a full node

Deploy a public testnet with a faucet

  • Deploy faucet service
  • Register domain names for faucet and bootstrap nodes (with help of @lacabra )
  • Set up SSL certs
  • Create a new reCaptcha keys
  • Change to test keyring backend Change password to faucet account
  • Update all in .env and .env.local
  • Fix README and clean comments etc.
  • Update dependencies to fix security vulnerabilities
  • Upgrade to v0.1.0
  • Write blog post

Dockerfile for enigmad

Cc @moonstash

  • Write docs on using the docker image
  • Build v0.0.2 and push to hub.docker.com

Fix docs for RPC laddr not working behind NAT

Fix docs to support running a full node behind NAT with port forwarding.
Also check about UPnP support.

Correctly setting laddr in enigmad config doesn't work for this use case.

Cc @moonstash

[BUG] LCD SSL cert causing errors

Hi there,

I am running a seperate fullnode for RPC & LCD purposes

I have added in my SSL .crt & .key and even put them in the /config/ DIR & specified them in the config.toml
(My cert is from a CA - Comodo)

However it seems when there is a value in the cert & key options in the config I get no response on LCD from the https... and on http side i get this error.

http error:
{"error":"Status: error unmarshalling: invalid character 'C' looking for beginning of value"}

you can see on these two links it being reproduced.
https://172.105.11.162/node_info
http://172.105.11.162/node_info

Any info on this would be good. The reason i need SSL working is for swagger to connect over https. As its giving errors because it doesnt want to go from https -> http (lcd)

The SSL works fine for RPC, just not LCD..

Application idea - Salad, transactional privacy

Below is the user flow for Salad, Enigma's tool for transactional privacy.

  1. Alice sends SCRT to be mixed - denomination amounts to be finalized but we can work with the assumption 100 SCRT, 1,000 SCRT, 10,000 SCRT and her locally encrypted recipient address to Salad secret contract
  2. Bob and others follow steps 1)

On the Salad secret contract side, the following will happen:
3) check whether a quorum is reached after X blocks (currently 2 hours or ~12,000 block) and secret contract has the right amount of SCRT
4) If 3) is satisfactory, privately decrypt and shuffle all inputs (recipient addresses)
5) Return shuffled plaintext recipient addresses to the deposit contract for distribution of SCRT to new addresses

More details can be found in this post

Installing inside ubuntu container fails

When trying to install inside a docker container (ubuntu:18.04) (RUN dpkg -i enigmachain_0.0.2_amd64.deb) a few errors are encountered:

  • logname: no login name
  • /var/lib/dpkg/info/enigmachain.postinst: line 23: sudo: command not found

Stateless contract execution in SGX (no encryption)

The idea is to first develop an encryption free, state-free simple toy contract that runs inside of SGX.

In this task, we don't have to worry about an API of going in/out of the enclave - just to pull the WASM interpreter into the enclave and properly integrate a single in/out point from/to the enclave in CosmWasm.

On-chain bootstrap skeleton

This task sets the outline/interface of the bootstrap module. It should achieve the following:

  • Have a registered validators key-value store. It should allow validators to be in one of (pending, registered) states
  • Have a register_validator() tx handler to deal with new validators who join in
  • Have a share_seed() tx handler to deal with the sharing of the encrypted seed value for a new validator
  • Have a confirm_validator() tx handler to change a new validator from 'pending' state to confirmed state

On-chain report verification

Verify report signature on-chain (similar to how this worked in the Enigma Contract in Discovery/Ethereum). Needed as part of register_validator().

How to remove a validator

While there is documentation on how to join a network as a validator, I have not been able to find information on how to properly stop being a validator. I would like to request adding the proper documentation for it.

enigmacli query on slashing for validator is returning "null"

Using the following command is supposed to display slashing info for a validator:

enigmacli q distribution slashes [validator-operator-address] [start-height] [end-height]

I tried with an enigmavaloper1... address that had a slashing event, but the command is returning:

null

encrypted get_state and set_state

This should overlay the existing implementation of CosmWasm as much as possible. The complexity lies with actually navigating between doing this inside of the enclave, and actually storing/fetching data that lives outside of the enclave (in the untrusted part of the validator).
We can make the following simplifying assumptions for encrypted state:

  • keys are unencrypted - this allows searching in plaintext outside of the enclave. If someone wants to fully encrypt the state, they can have a single key that maps to a single encrypted dictionary
  • Decrypting the existing state value with the previous tx_hash. Note: the unencrypted latest tx_hash (or whatever nonce we decide on) needs to be serialized and included with the stored value.

In set_state, need to do the opposite:

  • Derive a new state encryption key using the master key and current tx_hash.
  • Encrypt the data and serialize it, alongside the tx_hash
  • Pass the unencrypted key in the key value store, alongside the encrypted bytes outside of the enclave for CosmWasm to store natively.

Client library to deploy WASM contracts

Experiment with CosmWasm client library. Integrate into our own tools. NOTE: this is subject to have breaking changes, so we should not spend too much time here right now.

Write docs on using gov

Write docs on using the governance module:

  1. How to create proposals
  2. How to deposit
  3. Deposits burn risk
  4. How to vote, modify a vote and validator/delegator dynamic

Application idea - Deadman switch / access control

“Dead-Man’s Switch” is a trigger for an event that occurs when an operator becomes incapacitated. Originally, the term described a physical switch that when released, caused a machine to stop running. Now the term also refers to software that asks a user to periodically “check-in”, and releases some information if the user fails to perform this check-in within a certain amount of time.

Below is the user flow for a deadman switch built on Enigma blockchain.

  1. Alice initiates the secret contract that will act as the decentralized deadman switch by:
  • storing encrypted secret (input) to the secret contract
  • defining the recipient address of the secret (input)to receive the secret when the triggering event takes place
  • defining triggering event - i.e. desired check-in interval (1 TX per month, year etc.) defined in number of blocks
  • funding a bounty for the deadman switch to be called if desired check-ins don't take place
  1. Alice "checks-in" - sends a transaction to the DMS secret contract Enigma network. Alice must repeat this within the specified interval.

  2. Bob is able to submit a transaction to the secret contract. If Alice ceases to "check-in" within the specified interval, Bob would submit a transaction to the secret contract to reveal the secret and collect the bounty. Secret contract compares block numbers of Bob's transactions and Alice's last "check-in" transaction to the desired check-in interval.

  3. If elapsed time is greater than the interval specified by the user, Bob receives the bounty and secret contract encrypts the secret with the recipient address Alice defined in step 1. (encrypted outputs).

Hello world local node to enclave

The idea for this task is to prepare a skeleton for the implementation of (register_validator and share_seed) functionalities, as well as any other API we need between a node and its enclave

Launch a public testnet

A public ground for:

  • Testing out new features
  • Allowing different stakeholders to get a look and feel of what's going on (e.g., node runners can test their system; developers can test their contracts, etc..)

Manage the lifecycle of new nodes

New nodes should not be able to start syncing blocks UNTIL they are confirmed as a registered node. We should look into InitChainer and EndBlocker.

New node

  • register node
    • generate report for enclave
      Get quote - SafeTrace ref
    • using enigmad generate key pair inside of the enclave
    • seal + backup private key
    • handle loading of private key on node init
    • using IAS (proxy node) get report for public key (signed quote)
    • enigmacli send tx with public key as a param + report
    • bootstrap node handling (only happens for the first node)
      Initialization logic for the enclave. See the logic described here in Phase 1 (register_node()): https://forum.enigma.co/t/network-key-management-agreement/1324
      Check whether this can happen automatically inside the global InitChainer (also whether this can listen to new blocks and block execution until the new node is confirmed).

Existing nodes

New node again

  • register_node()
    • decrypt seed with pk_io and my private key (using derive_key https://forum.enigma.co/t/input-output-state-encryption-decryption-protocol/1325). With the single shared 256-bit seed generated above, we can run the CSPRNG several times to get other 256-bit pseudo-random keys:
    • First 256 bits: used to generate (sk_io, pk_io) --> a key pair whose pubkey can be used by users to derive new symmetric encryption keys for encrypting input/outputs. The protocol above needs to be changed so that the first validator also broadcasts pk_io to the network.
    • Next 256 bits: used to generate master_state_key --> a symmetric key used to encrypt contract state. In practice, this is a seed we can use to derive further keys.
    • Next 256 bits: used to generate master_iv --> this is a seed that can be used to generate fresh IVs for encrypting outputs. That’s how the network can avoid non-determinism and still maintain the security of symmetric ciphers.
    • Next 256 bits: used to generate master_rand_seed --> this is a seed that can be used to generate randomness.
    • check how to pass this to my InitChainer to be able to sync blocks

gen_keys() function (in the Enclave)

Used to generate the following initial keys once the seed is shared:

  • (sk_io, pk_io) --> shared key for deriving input/output keys. pk_io is available on-chain, and sk_io is shared across all validators’ enclaves.
  • master_state_key --> a symmetric master key used to derive other state keys.
  • master_iv --> an IV seed used to generate fresh pseudo-random IVs for both encrypted outputs and state encryption.

https://forum.enigma.co/t/network-key-management-agreement/1324

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.