{"id":20433870,"url":"https://github.com/flashbots/andromeda-sirrah-contracts","last_synced_at":"2025-10-20T12:02:14.098Z","repository":{"id":219149897,"uuid":"718293833","full_name":"flashbots/andromeda-sirrah-contracts","owner":"flashbots","description":"forge development env for SUAVE key management","archived":false,"fork":false,"pushed_at":"2024-08-08T15:54:26.000Z","size":536,"stargazers_count":19,"open_issues_count":22,"forks_count":6,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-04-12T21:09:07.763Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flashbots.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-13T19:37:20.000Z","updated_at":"2025-01-10T21:02:44.000Z","dependencies_parsed_at":"2024-11-15T08:34:07.349Z","dependency_job_id":null,"html_url":"https://github.com/flashbots/andromeda-sirrah-contracts","commit_stats":null,"previous_names":["flashbots/andromeda-sirrah-contracts"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flashbots%2Fandromeda-sirrah-contracts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flashbots%2Fandromeda-sirrah-contracts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flashbots%2Fandromeda-sirrah-contracts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flashbots%2Fandromeda-sirrah-contracts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flashbots","download_url":"https://codeload.github.com/flashbots/andromeda-sirrah-contracts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631676,"owners_count":21136562,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T08:22:00.210Z","updated_at":"2025-10-20T12:02:09.071Z","avatar_url":"https://github.com/flashbots.png","language":"Solidity","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e [!WARNING]\n\u003e This repository is a work in progress, and for now only functions as a showcase. This code *is not intended to secure any valuable information*.\n\n# Andromeda Sirrah Contracts\n\nThis repository contains the smart contracts and development environment for SUAVE's intermediate programming layer, where Solidity contracts directly control SGX trusted hardware features like attestation and sealing. This also contains the code and examples that go along with the post \"Sirrah: Speedrunning a TEE Coprocessor.\"\n\n## Andromeda Precompiles\n\nThe Andromeda precompiles are a minimal way to add Trusted Hardware Enclaves to the Solidity environment.\nThe interface is defined in [./src/IAndromeda.sol](./src/IAndromeda.sol)). It basically adds four new things:\n\n- *Sampling random bytes*.\n\n```solidity\nfunction localRandom() view external returns(bytes32);\n```\n\nThis returns new random bytes each time it is called, sampled using the `RDRAND` x86 instruction.\n\n- *Process storage*\n\n```solidity\nfunction volatileSet(bytes32 tag, bytes32 value) external;\nfunction volatileGet(bytes32 tag) external returns(bytes32 value);\n```\n\nThis provides a key value storage. Each caller has its own isolated storage. If a message call reverts, it will *not* undo the side effects of `volatileSet`. All this storage is cleared each time the process restarts.\n\n- *Persistent storage*\n\n```solidity\nfunction sealingKey() view external;\n```\nThis provides a persistent key. For each caller, each MRENCLAVE on each CPU gets its own one of these. This is used so the enclave can store an encrypted file and retrieve it later if the process restarts.\n\n- *Remote attestation*\n\n ```solidity\nfunction attestSgx(bytes32 appData) external returns (bytes memory att);\nfunction verifySgx(address caller, bytes32 appData, bytes memory att) external view returns (bool);`\n```\n\nThis produces evidence that the `appData` was requested by the `caller`. The verification routine is pure Solidity, and does not require any special precompiles.\n\n- *External services*\n\nCurrently there are two external services defined: redis (persistent) key-value store and redis pubsub:\n```solidity\ninterface Redis {\n    function set(string memory key, bytes memory value) external;\n    function get(string memory key) external returns (bytes memory);\n}\ninterface RedisPubsub {\n    function publish(string memory topic, bytes memory msg) external;\n    function get_message(string memory topic) external returns (bytes memory);\n    function subscribe(string memory topic) external;\n    function unsubscribe(string memory topic) external;\n}\n```\n\nFor interacting with external services see [lib/revm-services/Interfaces.sol](lib/revm-services/Interfaces.sol) and the [RedisConfidentialStore example contract](src/examples/RedisConfidentialStore.sol).\n\n\n## Implementations\nWe provide three implementations of the Andromeda interface:\n\n1. A forge mockup environment. This is sufficient for logical testing of smart contracts. [./src/AndromedaForge.sol](./src/AndromedaForge.sol)\n2. A remote environment using actual remote attestations, computed via a remote service (dummy attester service) [./src/AndromedaRemote.sol](./src/AndromedaRemote.sol)\n3. Invoke the actual the precompiles recognized by the Andromeda EVM in separate repository, [suave-andromeda-revm](https://github.com/flashbots/suave-andromeda-revm/).\n\nTo reiterate, the forge development environment here (implementations 1 and 2) does NOT require any use of SGX, so you can develop on any machine (even on TEE-level components like a Key Manager and TCB recovery handling).\n\n## Speedrunning a Second Price auction\n\nHere's the motivating scenario to go along with the blogpost: Looking at [./src/examples/SpeedrunAuction.sol:LeakyAuction](./src/examples/SpeedrunAuction.sol), we can see a second price auction in plain ordinary Solidity. But, due to a lack of privacy, this is vulnerable to griefing through MEV.\n\nThe point of this demo is to solve this problem using the Andromeda precompiles. See: [./src/examples/Auction.sol:SealedAuction](./src/examples/Auction.sol)\n\n## Key Manager\n\nThe \"speedrun\" was a little unsatisfying because you have to bootstrap a new key each time you carry out an auction. Instead, we want to have a singletone Key Manager that encapsulates a single bootstrapping ceremony, and thereafter *many applications* as well as *many separate kettles* can provide confidential coprocessing service. The proposed key manager has the following features:\n\n- Verification of a raw SGX attestation (expensive in Solidity gas) only needs to occur once per Kettle. After initial registration, ordinary digital signatures can be used instead. Much cheaper.\n- Multiple Kettles can join. Newly registered Kettles receive a copy of the key from existing Kettles that already have it\n- A single instance of the Key Manager contract can be used by other contracts.\n\nThis is still a simplified strawman example, as it does not support upgrading the enclave, revoking keys, etc. This is meant as a starting point, and those ideas can be explored in Solidity.\n\n## Timelock encryption demo\n\nAs one demo, we include a sample application in the form of a timelock decryption service.\nThe code is at [./src/examples/Timelock.sol:Timelock](./src/examples/Timelock.sol)\nand the smart contract is found on the Rigil test network [https://explorer.rigil.suave.flashbots.net/address/0x6858162E579DFC66a623AE1bA357d67BF026dDD6](https://explorer.rigil.suave.flashbots.net/address/0x6858162E579DFC66a623AE1bA357d67BF026dDD6).\n\nThe application is very simple: messages are encrypted to the public key of the contract. A TEE kettle can only decrypt them only after the light client reports that a deadline has passed on the blockchain. \n\nThe frontend is hosted at https://timelock.sirrah.suave.flashbots.net/  \nYou'll need to point your web3 browser extension like Metamask to [point to a Rigil endpoint](https://github.com/flashbots/suave-specs/tree/main/specs/rigil). If you don't have Rigil testnet coins you can get some at [faucet.rigil.suave.flashbots.net](https://faucet.rigil.suave.flashbots.net).\n\n## Confidential bundle store demo\n\nIn another demo, [RedisConfidentialStore](./src/examples/RedisConfidentialStore.sol), we show how we can use redis's key-value store and pubsub to implement a replicated bundle database which preserves integrity and confidentiality.  \nThis specific demo aims to bring us closer to feature parity with Rigil by implementing the [confidential data store](https://suave.flashbots.net/technical/specs/rigil/confidential-data-store).  \n\nThis demo is also very simple, and allows inserting bundles, indexing them (by the block they target), and fetching them. The demo is built in a way that also allows replicating bundles across multiple kettles (as long as they are onboarded to the same key manager - not shown on the demo).  \nThe RedisConfidentialStore contract is deployed to the Rigil testnet, and can be found at [https://explorer.rigil.suave.flashbots.net/address/0xF1b9942f1DBf1dD9538FC2ee8e2FC533b7070366](https://explorer.rigil.suave.flashbots.net/address/0xF1b9942f1DBf1dD9538FC2ee8e2FC533b7070366).\n\n## Usage\n\nRelies on [Foundry](https://getfoundry.sh/) for contrats, [Python 3](https://www.python.org/downloads/) for various utilities, and [npm](https://nodejs.org/en) for automation and demo.  \n\nFor ease of use we provide the following `make` targets:\n* `make build` to build contracts\n* `make format` to format contracts\n* `make test` to test contracts\n* `make deploy` to deploy contracts\n* `make configure-all-tcbinfos` to configure `Andromeda` contracts with TCBInfo from Intel\n* `make bootstrap` to bootstrap a kettle for `KeyManager`\n* `make onboard` to onboard a kettle to `KeyManager` from one already bootstrapped\n* `make deploy-examples` to deploy `SealedAuction` and `Timelock` for use in the demo webapp\n* `make test-examples` to automatically deploy and test `SealedAuction` and `Timelock` on chain\n\nDeployed contracts are kept track of in the [deployment.json](deployment.json) file. If you want to re-deploy a contract, simply remove it from the `ADDR_OVERRIDES` section. The various deployment scripts write to the file on successful deployments.\n\n## Rigil\n\nIf you want to build and deploy only some of the contracts, here are ones predeployed to Rigil.\n\n1. Contracts\n\nIn [deployment.json] change the `ADDR_OVERRIDES` to include:\n\n```\n  \"ADDR_OVERRIDES\": {\n    \"out/SigVerifyLib.sol/SigVerifyLib.json\": \"0xed16804dB4D00A61e85569362ac10ef66126B13e\",\n    \"out/Andromeda.sol/Andromeda.json\": \"0x76832d4d9823eCD154598Ce2969D5C4e794E84c4\"\n  }\n```\n\n2. Demo apps\n\nIf you want to use predeployed `Timelock` demo, one is available on Rigil. Include the following in the `ADDR_OVERRIDES`:\n\n```\n  \"ADDR_OVERRIDES\": {\n    \"out/Timelock.sol/Timelock.json\": \"0x6858162E579DFC66a623AE1bA357d67BF026dDD6\",\n    \"out/RedisConfidentialStore.sol/BundleConfidentialStore.json\": \"0xF1b9942f1DBf1dD9538FC2ee8e2FC533b7070366\"\n  }\n```\n\n\u003e [!WARNING]\n\u003e The addresses will change, so don't depend on them too much. This is intended for quick prototyping rather than something that is highly available.\n\n\n### Rigil kettle\n\nIf you don't want to run a kettle yourself, you can always connect to the development TEE kettle at https://kettle.sirrah.suave.flashbots.net.\n\n## License\n\nThe code in this project is free software under the [MIT license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflashbots%2Fandromeda-sirrah-contracts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflashbots%2Fandromeda-sirrah-contracts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflashbots%2Fandromeda-sirrah-contracts/lists"}