Skip to content

Commit

Permalink
Bug fixes, Improvements, Features
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay111meher committed Dec 17, 2024
1 parent 296a069 commit 54eda10
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 183 deletions.
176 changes: 16 additions & 160 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,179 +7,35 @@ This repository implements a RiscZero based AWS Nitro Enclave attestation verifi
While it produces zero false positives, it does not aim to produce zero false negatives, i.e. it could reject _theoretically_ valid attestations. Instead, it asserts specific attestation formats that are _actually_ used in order to optimize proving time. It also does not verify any extensions in the certificates as it was deemed unnecessary.

## Build
Build the executables

Install the RiscZero tooling before proceeding further.

Note: Requires CUDA by default. It is possible to disable CUDA by disabling the relevant feature in `host/Cargo.toml`, but the proof generation process could take hours on a CPU.

```bash
cargo build --release
```

### Reproducible builds

Reproducible builds are enabled for the guest to produce a consistent GUEST_ID.

Expected GUEST_ID: 0x785ecdc7494dcdb0ee09574ad5554c79d8c6b99e8cb11dba5cf3c05a0e71d9ec

## Usage

```bash
$ ./target/release/host --help
GUEST: 0x785ecdc7494dcdb0ee09574ad5554c79d8c6b99e8cb11dba5cf3c05a0e71d9ec
Usage: host --url <URL>

Options:
-u, --url <URL>
-h, --help Print help
-V, --version Print version
```

It takes in a URL to an attestation server producing binary attestations. The attestation server should include a 64 byte public key in the attestation.

## Journal format

The journal contains bytes in the following order:
- 8 byte timestamp in milliseconds from the attestation
- 48 byte PCR0
- 48 byte PCR1
- 48 byte PCR2
- 48 byte public key from the root certificate
- 64 byte public key from the attestation
- 2 byte length of the user data
- N byte user data

## Directory Structure

```text
project_name
├── Cargo.toml
├── host
│ ├── Cargo.toml <-- [Disable CUDA here]
│ └── src
│ └── main.rs <-- [Host code goes here]
└── methods
├── Cargo.toml
├── build.rs <-- [Reproducible guest builds stuff here]
├── guest
│ ├── Cargo.toml
│ └── src
│ └── method_name.rs <-- [Guest code goes here]
└── src
└── lib.rs
```

## Kalypso Prover
#### Note: _To manage regular operation of kalypso-cli it is recommended to install [kalypso-cli](#kalypso-cli-documentation)_
Provers can generate proofs or attestation requests on kalypso and earn rewards.

```bash
touch .env
```
`.env` file should contain

```
GENERATOR_ADDRESS=<<generatorAddress>>
GAS_KEY=<<gas key>>
MARKET_ID=3
HTTP_RPC_URL=https://arb-sepolia.g.alchemy.com/v2/<<apikey>>
PROOF_MARKETPLACE_ADDRESS="0xfa2AAcA897C4AB956625B72ac678b3CB5450a154"
GENERATOR_REGISTRY_ADDRESS="0xdC33E074d2b055171e56887D79678136B4505Dec"
START_BLOCK=92423485
CHAIN_ID=421614
MAX_PARALLEL_PROOFS=1
IVS_URL=http://3.110.146.109:3030
PROVER_URL=http://localhost:3030/api/generateProof
```

#### Build the prover
```rust
cargo build --release
```

#### Benchmark the prover
This is should a proof for an attestation. It should take around 12-13 mins to generate the proof.
1.
```sh
./target/release/benchmark
```

#### Run the prover
The prover automatically detect the requests assigned to the your `generatorAddress` and submit proofs to kalypso and earns rewards.
```bash
./target/release/kalypso-attestation-prover
chmod +x bootstrap.sh
```

### Kalypso CLI Documentation

The `kalypso-cli` is an optional command-line interface (CLI) tool that provides an interactive way to perform various operations related to the Kalypso ecosystem. This guide explains how to build and run the `kalypso-cli` tool.

---

### Step 1: Download the Kalypso Monorepo

Open a terminal and clone the `kalypso-unified` repository:

2. Clean the build
```sh
git clone https://github.com/marlinprotocol/kalypso-unified
cd kalypso-unified
git checkout symbotic-bindings
./bootstrap.sh clean
```

---

### Step 2: Build the CLI Tool

Ensure you are using a `stable` Rust toolchain to build the `kalypso-cli`. Run the following commands:

3 a. Build for GPU (recommended)
```sh
rm -rf .cargo
cargo build --release --bin kalypso-cli
chmod +x bootstrap.sh
./bootstrap.sh --gpu
```

This command builds the CLI tool in release mode.

---

### Step 3: Run the CLI Tool

Once the build is complete, you can run the `kalypso-cli` tool. It will prompt you to select an operation to perform. You can either input values interactively or use environment variables to predefine them.

#### Example:

3 b. Build for CPU (recommended)
You can still participate and challenge invalid attestation requests to earn rewards
```sh
./target/release/kalypso-cli
./bootstrap.sh --cpu
```

When executed, the CLI will display a list of operations:

4. Run prover
```sh
kalypso@kalypso:~/kalypso-unified$ ./target/release/kalypso-cli
? Select an operation ›
❯ Add IVS Key
Benchmark Prover
Claim Rewards
Compute PCRs
Create Marketplace
Create Proof Request (confidential market)
Create Proof Request (non confidential market)
Discard Request
Join Marketplace
Leave Marketplace
Load Generator Config
Native Stake
Non-Confidential Market PCRS
Read Attestation
Read Proof Bytes
Register
Request Symbiotic Stake
Request To Leave Marketplace
Start Enclave Program
Stop Enclave Program
Test Enclave Connection
Update Encryption Key
Whitelist IVS Image
Whitelist Prover Image
chmod +x start.sh
```

## License
This repository is licensed under the GNU AGPLv3 or any later version. See [LICENSE.txt](./LICENSE.txt).
```sh
./start.sh run-prover
```
10 changes: 10 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ clean_build_artifacts() {
echo "kalypso-cli binary does not exist. Skipping."
fi

# Remove the Cargo.lock
if [ -f "./Cargo.lock" ]; then
echo "Removing Cargo.lock ..."
rm -f ./Cargo.lock
else
echo "kalypso-cli binary does not exist. Skipping."
fi

# Remove application-specific binaries
BINARY_HOST="./test-connection"
BINARY_BENCHMARK="./benchmark"
Expand Down Expand Up @@ -301,6 +309,8 @@ build_application_binaries() {
BINARY_BENCHMARK="./benchmark"
BINARY_PROVER="./kalypso-attestation-prover"

rm ./Cargo.lock

if [ -f "$BINARY_HOST" ] && [ -f "$BINARY_BENCHMARK" ] && [ -f "$BINARY_PROVER" ]; then
echo "All application-specific binaries (test-connection, benchmark, kalypso-attestation-prover) are already built."
else
Expand Down
23 changes: 23 additions & 0 deletions generatormeta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"displayName": null,
"displayDescription": null,
"website": null,
"twitter": null,
"discord": null,
"logoUrl": null,
"bannerUrl": null,
"contactEmail": null,
"github": null,
"linkedin": null,
"medium": null,
"reddit": null,
"youtube": null,
"instagram": null,
"repoUrl": null,
"version": null,
"categories": [],
"tags": [],
"license": null,
"termsOfServiceUrl": null,
"privacyPolicyUrl": null
}
2 changes: 1 addition & 1 deletion host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ethers ={version = "2.0.10", features = ["abigen", "ws", "rustls"] }
dotenv = "0.15"
env_logger = "0.10"
tokio = { version = "1", features = ["full"] }
kalypso_listener = { git = "https://github.com/marlinprotocol/kalypso-unified.git", branch = "symbotic-bindings", package = "listener" }
kalypso_listener = { git = "https://github.com/marlinprotocol/kalypso-unified.git", branch = "symbotic-bindings", package = "listener", features = ["testnet"] }
kalypso_helper = { git = "https://github.com/marlinprotocol/kalypso-unified.git", branch = "symbotic-bindings", package = "helper" }
kalypso_generator_models = { git = "https://github.com/marlinprotocol/kalypso-unified.git", branch = "symbotic-bindings", package = "generator" }

Expand Down
105 changes: 83 additions & 22 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,22 @@ usage() {
echo "Usage: $0 {register-join|benchmark|test-connection|run-prover|symbiotic-stake|native-stake|claim-rewards|discard-request|read-stake|symbiotic-register}"
echo
echo "Options:"
echo " benchmark Run benchmark tests"
echo " claim-rewards Claim Rewards"
echo " discard-request Discard Request"
echo " native-stake Stake your own tokens"
echo " read-stake Read Stake data"
echo " register-join Register and join the network"
echo " run-prover Execute the prover service"
echo " symbiotic-register Register Operator with symbiotic"
echo " symbiotic-stake Request Symbiotic Stake"
echo " test-connection Test network connection"
echo " benchmark Run benchmark tests"
echo " claim-rewards Claim Rewards"
echo " discard-request Discard Request"
echo " native-stake Stake your own tokens"
echo " read-stake Read Stake data"
echo " register-join Register and join the network"
echo " run-prover Execute the prover service"
echo " symbiotic-register Register Operator with symbiotic"
echo " symbiotic-stake Request Symbiotic Stake"
echo " test-connection Test network connection"
echo " set-commission Set Operator commission"
echo " set-operator-meta Set Operator data"
echo " request-stake-withdrawal Request Stake Withdrawal"
echo " read-pending-withdrawals Read Pending Withdrawals"
echo " process-pending-withdrawals Process Pending Withdrawals"
echo " check-reward Check Available Rewards"
exit 1
}

Expand Down Expand Up @@ -83,6 +89,7 @@ export GENERATOR_REGISTRY_ADDRESS="0xdC33E074d2b055171e56887D79678136B4505Dec"
export ENTITY_KEY_REGISTRY_ADDRESS="0x457d42573096b339ba48be576e9db4fc5f186091"
export START_BLOCK="106483690"
export MARKET_ID="3"
export INDEXER_URL="https://kalypso-symbiotic-indexer.justfortesting.me"

# Execute based on the selected operation
case "$OPERATION" in
Expand Down Expand Up @@ -194,29 +201,83 @@ case "$OPERATION" in

read-stake)
echo "Read Operator Stake data"
export INDEXER_URL="https://kalypso-symbiotic-indexer.justfortesting.me"

OPERATION_NAME="Read Stake Data" ./kalypso-cli &
S_ID=$!
# Wait for background processes to finish
wait $S_ID
;;

set-commission)
echo "Set Operator Commission"
set-commission)
echo "Set Operator Commission"

OPERATION_NAME="Set Operator Reward Commission" ./kalypso-cli &
S_ID=$!
# Wait for background processes to finish
wait $S_ID
;;
OPERATION_NAME="Set Operator Reward Commission" ./kalypso-cli &
S_ID=$!
# Wait for background processes to finish
wait $S_ID
;;

*)
set-operator-meta)
echo "Update Operator Metadata"

GENERATOR_META_JSON="./generatormeta.json"

if [ ! -f "$GENERATOR_META_JSON" ]; then
echo "$GENERATOR_META_JSON NOT FOUND"
exit 1
else
echo "Updating Operator Metadata from $GENERATOR_META_JSON"
fi

OPERATION_NAME="Update Generator Metadata" ./kalypso-cli &
S_ID=$!
# Wait for background processes to finish
wait $S_ID
;;

echo "Error: Invalid option '$OPERATION'."
usage
;;
request-stake-withdrawal)
echo "Request Stake Withdrawal"

OPERATION_NAME="Request Native Stake Withdrawal" ./kalypso-cli &
S_ID=$!
# Wait for background processes to finish
wait $S_ID
;;


read-pending-withdrawals)
echo "Read Pending Withdrawals"

OPERATION_NAME="Read Native Staking Pending Withdrawals" ./kalypso-cli &
S_ID=$!
# Wait for background processes to finish
wait $S_ID
;;

process-pending-withdrawals)
echo "Process Pending Withdrawals (if any)"

OPERATION_NAME="Process Withdrawal Requests" ./kalypso-cli &
S_ID=$!
# Wait for background processes to finish
wait $S_ID
;;

check-reward)
echo "Check Available Rewards"

OPERATION_NAME="Read Rewards Info" ./kalypso-cli &
S_ID=$!
# Wait for background processes to finish
wait $S_ID
;;

*)

echo "Error: Invalid option '$OPERATION'."

usage
;;
esac

echo "Bootstrap completed successfully."

0 comments on commit 54eda10

Please sign in to comment.