-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support TEE logging and support running eliza in Intel SGX #1470
base: develop
Are you sure you want to change the base?
Conversation
This looks great! For testing quickly with one of my SGX machines, can I run the gramine docker image and clone this repo to deploy an agent? |
Steps I took to test on my sgx machine using gramine docker image :) I'm debugging more on this, but I'll try with install of gramine on the machine next.
|
@ShuochengWang Were you able to run the agent in SGX without any constraints? What specs was this tested on? I have an SGX1 chip & I hit the OOM error and crashes my machine. Typically, I've seen OOM errors for agents with up to 8GB of memory so this may be something to take into account with running Eliza in SGX. |
Running Eliza in SGX does not have any special restrictions. However, there are two points to note:
I will soon update a detailed step-by-step guide for running Eliza in SGX. |
Hi, I tested it in SGX using a clean project and have added a quick start guide for running it in SGX. During the following steps, the only issue I encountered was a build error caused by the missing plugin-tee dependency in plugin-tee-log. This error can be resolved by simply running the build command again. However, this is an issue that needs to be addressed later. Other than that, everything worked smoothly during the test. If you encounter any other issues while following these steps, please feel free to let me know. Note: Currently, I have set the SGX EPC size (memory size) to 64 GB in the Gramine manifest. In reality, Eliza itself does not require this much memory. However, some dependencies of Eliza rely on WebAssembly (WASM), and initializing WASM demands a significant amount of memory. If the memory is insufficient, you may encounter the following error:
To mitigate this issue, I configured the enclave size to 64 GB. This is a temporary workaround, and we need to optimize WASM memory usage in the future. Quick StartFirst, you need to prepare a SGX enabled machine. Then, you can use the following command to start a Gramine Docker container: sudo docker run -it --name eliza_sgx \
--mount type=bind,source={your_eliza_path},target=/root/eliza \
--device /dev/sgx/enclave \
--device /dev/sgx/provision \
gramineproject/gramine:stable-jammy After entering the docker, you can use the following command to prepare the Eliza environment: # Generate the private key for signing the SGX enclave
gramine-sgx-gen-private-key
cd /root/eliza/
# Install nodejs and pnpm
# Node.js will be installed at `/usr/bin/node`.
# Gramine will utilize this path as the default Node.js location to run Eliza.
# If you prefer to use nvm for installing Node.js, please ensure to specify the Node.js path in the Makefile, as the installation path for nvm is not `/usr/bin/node`.
apt update
apt install -y build-essential
apt install -y curl
curl -fsSL https://deb.nodesource.com/setup_23.x | bash -
apt install -y nodejs=23.3.0-1nodesource1
npm install -g pnpm
# Build Eliza
pnpm i
# The build may fail on the first attempt due to the missing `plugin-tee` dependency in `plugin-tee-log`. Simply run the build command again to resolve the issue.
# TODO: fix the build issue
pnpm build
# Copy the .env.example file to .env
cp .env.example .env
# Edit the .env file
# Start Eliza in SGX
SGX=1 make start -- --character "character/c3po.character.json" |
Switch branch to merge to develop |
Done, already switched to the develop branch. |
Done, the code has been updated with no conflicts, and all checks have passed successfully. @HashWarlock |
The previous build error has been fixed. The issue was related to the build order. Apart from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Due to updates in the develop branch, some conflicts have arisen, and I have just resolved all of them. Please review the changes again (no functional updates, only merging develop branch). I hope we can merge it as soon as possible to avoid new conflicts. Thanks a lot @HashWarlock |
@ShuochengWang great work! Thanks for updating. @odilitime how do we look here? |
Is there any update? I hope we can merge it as soon as possible. I’ve resolved conflicts several times before, and now new conflicts have emerged again... And resolving conflicts requires another round of review... |
Relates to:
Keywords: TEE, Intel SGX, Logging, Attestation, Verification, Gramine.
Risks
Low
Background
What does this PR do?
This PR introduces support for TEE (Trusted Execution Environment) logging and enables the Eliza application to run within Intel SGX (Software Guard Extensions).
As Eliza is a fully autonomous AI agent capable of running within a TEE, we need to demonstrate to the outside world that we are indeed operating within a TEE. This allows external parties to verify that our actions are protected by the TEE and that they are entirely executed by Eliza, without any third-party interference. Therefore, it is necessary to leverage TEE's remote attestation and establish a TEE logging mechanism to prove that these operations are entirely and autonomously performed by Eliza within the TEE.
Meanwhile, the existing plugin-tee only supports running Eliza in dstack TDX CVM. However, although TDX is more convenient to use, Intel SGX remains a highly popular TEE in production environments. With the help of Gramine LibOS, it is possible to support running Eliza in SGX, thereby enabling the deployment of Eliza in a broader range of TEE scenarios.
What kind of change is this?
Features
Details
TEE Logging Mechanism:
Key Pair Generation and Attestation:
Log Recording:
agentId
,roomId
,userId
,type
,content
, andtimestamp
. This information is concatenated and signed using the agent's corresponding private key to ensure verifiability. The verification process follows this trust chain:Data Storage:
Log Extraction for Verification:
Integrity Protection:
Documentation changes needed?
Need to add new documentation about TEE logging and how to run Eliza in SGX
Testing
Where should a reviewer start?
Detailed testing steps
Test SGX support
First, you need to prepare the SGX environment and install the Gramine dependencies according to https://gramine.readthedocs.io/en/stable/index.html
Then, start eliza in SGX:
Test TEE logging
To get started, prepare the TEE environment. Both dstack TDX and Gramine SGX are supported.
Next, enable TEE logging by configuring the .env file:
The logging isn't integrated for actions by default, you need to integrate the logging for the actions you want to log. For example, if you want to log the
Continue
action of plugin-bootstrap, you can do the following:First, add plugin-tee-log to the dependencies of plugin-bootstrap:
Then, add the following code to the
Continue
action: