Skip to content

TEE Verifier Contracts #1374

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,22 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/automata-network-on-chain-pccs"]
path = lib/automata-network-on-chain-pccs
url = https://github.com/automata-network/automata-on-chain-pccs
[submodule "lib/automata-network-dcap-attestation"]
path = lib/automata-network-dcap-attestation
url = https://github.com/automata-network/automata-dcap-attestation
[submodule "lib/solady"]
path = lib/solady
url = https://github.com/Vectorized/solady
[submodule "lib/openzeppelin-contracts-v5"]
path = lib/openzeppelin-contracts-v5
url = https://github.com/OpenZeppelin/openzeppelin-contracts
branch = release-v5.3
[submodule "lib/sp1-contracts"]
path = lib/sp1-contracts
url = https://github.com/succinctlabs/sp1-contracts
[submodule "lib/risc0-ethereum"]
path = lib/risc0-ethereum
url = https://github.com/risc0/risc0-ethereum
1 change: 1 addition & 0 deletions lib/automata-network-dcap-attestation
1 change: 1 addition & 0 deletions lib/automata-network-on-chain-pccs
1 change: 1 addition & 0 deletions lib/openzeppelin-contracts-v5
1 change: 1 addition & 0 deletions lib/risc0-ethereum
Submodule risc0-ethereum added at b96551
1 change: 1 addition & 0 deletions lib/solady
Submodule solady added at 995904
1 change: 1 addition & 0 deletions lib/sp1-contracts
Submodule sp1-contracts added at 41282f
14 changes: 14 additions & 0 deletions tee-contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Compiler files
cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/

# Docs
docs/

# Dotenv file
.env
240 changes: 240 additions & 0 deletions tee-contracts/DeployTeeDCAP.s.sol

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions tee-contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## Foundry

**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**

Foundry consists of:

- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.

## Documentation

https://book.getfoundry.sh/

## Usage

### Build

```shell
$ forge build
```

### Test

```shell
$ forge test
```

### Format

```shell
$ forge fmt
```

### Gas Snapshots

```shell
$ forge snapshot
```

### Anvil

```shell
$ anvil
```

### Deploy

```shell
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
```

### Cast

```shell
$ cast <subcommand>
```

### Help

```shell
$ forge --help
$ anvil --help
$ cast --help
```
107 changes: 107 additions & 0 deletions tee-contracts/contracts/HashValidator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
import {Ownable} from "solady/auth/Ownable.sol";
import "./interfaces/IHashValidator.sol";

/**
* @title HashValidator
* @dev Manages a set of valid hashes with batch operations for efficiency.
*/
contract HashValidator is Ownable, IHashValidator {
mapping(bytes32 => bool) private validEnclaveHashes;
mapping(bytes32 => bool) private validTD10ReportBodyMrHashes;

event EnclaveHashesUpdated(bytes32[] hashes, bool status);
event TD10ReportBodyMrHashesUpdated(bytes32[] hashes, bool status);

constructor(address owner) {
_initializeOwner(owner);
}

/**
* @notice Adds multiple enclave hashes to the valid list.
* @param hashes The array of hashes to be marked as valid.
*/
function addValidEnclaveHashes(bytes32[] calldata hashes) external onlyOwner {
uint256 length = hashes.length;
require(length > 0, EmptyArray());

for (uint256 i = 0; i < length; ++i) {
bytes32 hash = hashes[i];
if (!validEnclaveHashes[hash]) {
validEnclaveHashes[hash] = true;
}
}
emit EnclaveHashesUpdated(hashes, true);
}

/**
* @notice Removes multiple enclave hashes from the valid list.
* @param hashes The array of hashes to be removed.
*/
function removeValidEnclaveHashes(bytes32[] calldata hashes) external onlyOwner {
uint256 length = hashes.length;
require(length > 0, EmptyArray());

for (uint256 i = 0; i < length; ++i) {
bytes32 hash = hashes[i];
if (validEnclaveHashes[hash]) {
validEnclaveHashes[hash] = false;
}
}
emit EnclaveHashesUpdated(hashes, false);
}

/**
* @notice Checks if a given enclave hash is in the valid list.
* @param hash The hash to check.
* @return isValid True if the hash is in the valid list, false otherwise.
*/
function isValidEnclaveHash(bytes32 hash) external view returns (bool isValid) {
return validEnclaveHashes[hash];
}

/**
* @notice Adds multiple TD10ReportBody Mr hashes to the valid list.
* @dev hash = keccak256();
* @param hashes The array of hashes to be marked as valid.
*/
function addValidTD10ReportBodyMrHashes(bytes32[] calldata hashes) external onlyOwner {
uint256 length = hashes.length;
require(length > 0, EmptyArray());

for (uint256 i = 0; i < length; ++i) {
bytes32 hash = hashes[i];
if (!validTD10ReportBodyMrHashes[hash]) {
validTD10ReportBodyMrHashes[hash] = true;
}
}
emit TD10ReportBodyMrHashesUpdated(hashes, true);
}

/**
* @notice Removes multiple TD10ReportBody Mr hashes from the valid list.
* @param hashes The array of hashes to be removed.
*/
function removeValidTD10ReportBodyMrHashes(bytes32[] calldata hashes) external onlyOwner {
uint256 length = hashes.length;
require(length > 0, EmptyArray());

for (uint256 i = 0; i < length; ++i) {
bytes32 hash = hashes[i];
if (validTD10ReportBodyMrHashes[hash]) {
validTD10ReportBodyMrHashes[hash] = false;
}
}
emit TD10ReportBodyMrHashesUpdated(hashes, false);
}

/**
* @notice Checks if a given TD10ReportBody Mr hash is in the valid list.
* @param hash The hash to check.
* @return isValid True if the hash is in the valid list, false otherwise.
*/
function isValidTD10ReportBodyMrHash(bytes32 hash) external view returns (bool isValid) {
return validTD10ReportBodyMrHashes[hash];
}
}
Loading