How does DeepWorm work?
The DeepWorm infrastructure leverages cutting-edge tools and techniques, from TEEs to Hyperliquid, for enabling interactions with the nervous system of a living organism onchain
Last updated
The DeepWorm infrastructure leverages cutting-edge tools and techniques, from TEEs to Hyperliquid, for enabling interactions with the nervous system of a living organism onchain
Last updated
DeepWorm subscribes to the compute offchain, verify onchain paradigm. As simulating the worm's neural network onchain would be prohibitively expensive, similar to L2 rollups, DeepWorm runs the simulation offchain in a Trusted Execution Environment (TEE) on the Marlin network and verifies the attestations provided by the TEE onchain.
Building and deploying the worm in a TEE
As a first step, the DeepWorm codebase (written in Go) wrapping the Nematoduino model (written in C) is packaged in an enclave and deployed on a Marlin node. A crucial component of the Marlin wrapper is an enclave key which is generated from within the enclave. Only the enclave is aware of its private key and can, thus, sign on to execution results to prove that the transactions originated from within the enclave. This step uses Nix to make the steps fully reproducible. Further information on how to build and deploy the worm simulation in a TEE is available under the Developer Guides.
Once the worm's enclave image file (EIF) is verifiably built, ensuring that the TEE is hosting the right enclave comes from requesting Remote Attestations. These attestations can be requested by anyone and can be verified locally as well as onchain. In order to further reduce gas consumption, DeepWorm verifies attestations offchain and produces a ZK proof of having correctly verified the attestation. This ZK proof is whats verified onchain before the enclave hosting the worm's simulation can register its enclave key.
These processes together make the worm fairly permissonless. It allows any untrusted party to host the worm enclave and attest to its enclave key (after a specified cooldown period) if the TEE hosting the worm becomes unavailable. Similarly, any one can fund the enclave key with gas tokens to enable it to keep sending signed state updates onchain.
What makes the worm move?
Further explained in the section describing the Nematoduino model, the worm requires environmental inputs in order for its muscles to react. These inputs trigger certain sensory neurons of the worm which in turn activate its nervous system. In the case of DeepWorm, what could be a better stimulus than its own price?
Here's where two unique features of TEEs stand out:
Secret data like private keys and API keys can be encumbered within a TEE such that applications running within the TEE can use them without revealing them to the public (including the host)
TLS connections and more broadly network calls can be made from a TEE allowing it to send transactions, read external API data and expose endpoints for others to read application state
The worm simulation uses these abilities to directly read the WORM token's price on the Solana blockchain using the Jupiter API. This would be a major bottleneck had the worm contracts on Hyperliquid directly tried fetching prices using cross-chain protocols. But with a TEE its just an usual API call!
Chemotaxis or NoseTouch are then called repeatedly over a loop with a 8:2 probability to trigger the worm's sensory neurons. Presently, the absolute value of the difference between the current price and last fetched price multiplied by a scaling factor is used to determine the number of times the loop runs.
How to interact with the worm?
The worm posts signed transactions on a state contract on the Hyperliquid EVM testnet. This includes the change in the worm's position, its muscles' latest state values and price input that made it react. These transactions carry signatures signed by the enclave key proving that the state updates are originating from an authorized enclave.
External smart contracts or dApps can read state information from the smart contract to build on top of the worm. Furthermore, the enclave exposes endpoints for web2 apps to directly query state data. A horizontally scalable gateway is introduced in front of the endpoints to prevent the enclave from being DoS'ed.
As an easter egg, the smart contract contains a function to allow users to invoke chemotaxis once per minute approximately. The worm simulation monitors the state contract on Hyperliquid for such events. When triggered, Chemotaxis or NoseTouch are called with a probability of 8:2 ten times.