+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ cmd/manager/tmp
*.pem

dist/
result.zip
results.zip
*.spec
2 changes: 1 addition & 1 deletion cli/algorithms.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (cli *CLI) NewAlgorithmCmd() *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
algorithmFile := args[0]

log.Println("Uploading algorithm binary:", algorithmFile)
log.Println("Uploading algorithm file:", algorithmFile)

algorithm, err := os.ReadFile(algorithmFile)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cli/datasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import (
func (cli *CLI) NewDatasetsCmd() *cobra.Command {
return &cobra.Command{
Use: "data",
Short: "Upload a dataset CSV file",
Example: "data <dataset.csv> <private_key_file_path>",
Short: "Upload a dataset",
Example: "data <dataset_path> <private_key_file_path>",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
datasetFile := args[0]

log.Println("Uploading dataset CSV:", datasetFile)
log.Println("Uploading dataset:", datasetFile)

dataset, err := os.ReadFile(datasetFile)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cli/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra"
)

const resultFilePath = "result.zip"
const resultFilePath = "results.zip"

func (cli *CLI) NewResultsCmd() *cobra.Command {
return &cobra.Command{
Expand Down
58 changes: 36 additions & 22 deletions test/manual/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
## CLI

Throughout the tests, we assume that our current working directory is the root of the `cocos` repository, both on the host machine and in the VM.
First, we will build cli by running in the root directory of `cocos`:
```bash
make cli
```

### Algorithm requirements
The cli will be compiled to the build directory `./build/cocos-cli`.

Agent accepts the algorithm as a binary that take in two command line arguments.
```shell
algorithm-file <unix socket path> <dataset file paths>
```
### Algorithm requirements

The algorithm program should return the results to a socket and an example can be seen in this [file](./algo/lin_reg.py).
Agent accepts the algorithm as a binary or python or wasm file.
All assets/datasets the algorithm uses are stored in the `datasets` directory. The results from the algorithm run should be stored in the `results` directory. All these paths are relative to the algorithm working directory.

### Agent-CLI interaction

Expand All @@ -32,7 +34,7 @@ sev-snp-measure --mode snp --vcpus 4 --vcpu-type EPYC-v4 --ovmf $OVMF_CODE --ker

To speed up the verification process of attested TLS, download the ARK and ASK certificates using the CLI tool. The CLI tool will download the certificates under your home directory in the `.cocos` directory.
```bash
go run cmd/cli/main.go ca-bundle <path/to/platfrom_info.json>
./build/cocos-cli ca-bundle <path/to/platfrom_info.json>
```

In the following text, we can see an example of how the CLI tool is used.
Expand All @@ -52,55 +54,48 @@ cd ../..
# The CLI should also be aware of the VM measurement. To add the measurement
# to the .json file that contains the information about the platform, run CLI
# with the measurement in base64 format and the path of the backend_info.json file.:
go run cmd/cli/main.go backend measurement '<measurement>' '<backend_info.json>'
./build/cocos-cli backend measurement '<measurement>' '<backend_info.json>'

# If the VM is booted with the QEMU host data option, the CLI should also know
# the host data information. To add the host data to the .json file that contains
# the information about the platform, run CLI with the host data in base64 format
# and the path of the backend_info.json file.:
go run cmd/cli/main.go backend measurement '<host-data>' '<backend_info.json>'
./build/cocos-cli backend measurement '<host-data>' '<backend_info.json>'

# For attested TLS, also define the path to the backend_info.json that contains reference values for the fields of the attestation report
export AGENT_GRPC_MANIFEST=./scripts/backend_info/backend_info.json
export AGENT_GRPC_ATTESTED_TLS=true

# Retieve Attestation
go run cmd/cli/main.go attestation get '<report_data>'
./build/cocos-cli attestation get '<report_data>'

# Validate Attestation
# Product name must be Milan or Genoa
go run cmd/cli/main.go attestation validate '<attesation>' --report_data '<report_data>' --product <product_name>
./build/cocos-cli attestation validate '<attesation>' --report_data '<report_data>' --product <product_name>

# Run the CLI program with algorithm input
go run cmd/cli/main.go algo test/manual/algo/lin_reg.bin <private_key_file_path>
./build/cocos-cli algo test/manual/algo/lin_reg.py <private_key_file_path> -a python -r test/manual/algo/requirements.py
# 2023/09/21 10:43:53 Uploading algorithm binary: test/manual/algo/lin_reg.bin

# Run the CLI program with dataset input
go run cmd/cli/main.go data test/manual/data/iris.csv <private_key_file_path>
go run cmd/cli/main.go data test/manual/data/iris.csv <private_key_file_path>
./build/cocos-cli data test/manual/data/iris.csv <private_key_file_path>
# 2023/09/21 10:45:25 Uploading dataset CSV: test/manual/data/iris.csv

# Run the CLI program to fetch computation result
go run cmd/cli/main.go result <private_key_file_path>
./build/cocos-cli result <private_key_file_path>
# 2023/09/21 10:45:39 Retrieving computation result file
# 2023/09/21 10:45:40 Computation result retrieved and saved successfully!
```

Now there is a `result.bin` file in the current working directory. The file holds the trained logistic regression model. To test the model, run

```sh
python3 test/manual/algo/lin_reg_test.py test/manual/data/iris.csv result.bin
python ./test/manual/algo/lin_reg.py predict results.zip ./test/manual/data
```

You should get an output (truncated for the sake of brevity):

```sh
Id SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm Species
0 1 5.1 3.5 1.4 0.2 Iris-setosa
1 2 4.9 3.0 1.4 0.2 Iris-setosa
2 3 4.7 3.2 1.3 0.2 Iris-setosa
3 4 4.6 3.1 1.5 0.2 Iris-setosa
4 5 5.0 3.6 1.4 0.2 Iris-setosa
Precision, Recall, Confusion matrix, in training

precision recall f1-score support
Expand All @@ -112,4 +107,23 @@ Iris-versicolor 0.923 0.889 0.906 27
accuracy 0.933 75
macro avg 0.939 0.938 0.938 75
weighted avg 0.934 0.933 0.933 75

[[21 0 0]
[ 0 24 3]
[ 0 2 25]]
Precision, Recall, Confusion matrix, in testing

precision recall f1-score support

Iris-setosa 1.000 1.000 1.000 29
Iris-versicolor 1.000 1.000 1.000 23
Iris-virginica 1.000 1.000 1.000 23

accuracy 1.000 75
macro avg 1.000 1.000 1.000 75
weighted avg 1.000 1.000 1.000 75

[[29 0 0]
[ 0 23 0]
[ 0 0 23]]
```
10 changes: 5 additions & 5 deletions test/manual/algo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ python3 test/manual/algo/lin_reg.py
The linear regression example is a more complex algorithm that requires external dependencies.It returns a linear regression model trained on the iris dataset found [here](../data/) for demonstration purposes.

```bash
python3 test/manual/algo/lin_reg.py predict result.zip test/manual/data
python3 test/manual/algo/lin_reg.py predict results.zip test/manual/data
```

This will make inference on the results of the linear regression model.
Expand Down Expand Up @@ -71,29 +71,29 @@ Next we need to upload the dataset
After some time when the results are ready, you can run the following command to get the results:

```bash
./build/cocos-cli results ./private.pem
./build/cocos-cli result ./private.pem
```

This will return the results of the algorithm.

To make inference on the results, you can use the following command:

```bash
python3 test/manual/algo/lin_reg.py predict result.zip test/manual/data
python3 test/manual/algo/lin_reg.py predict results.zip test/manual/data
```

For addition example, you can use the following command:

```bash
go run ./test/computations/main.go ./test/manual/algo/addition.py public.pem false
./build/cocos-cli ./test/manual/algo/addition.py public.pem false
```

```bash
./build/cocos-cli algo ./test/manual/algo/addition.py ./private.pem -a python
```

```bash
./build/cocos-cli results ./private.pem
./build/cocos-cli result ./private.pem
```

## Wasm Example
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载