2024-09-29 04:52:44 +00:00
2024-10-02 03:57:13 +00:00
# Quartz CosmWasm (quartz-contract-core)
2024-09-29 04:52:44 +00:00
2024-10-02 03:57:13 +00:00
Quartz CosmWasm (quartz-contract-core) is a high-level framework for building attestation-aware smart contracts on CosmWasm. It provides a robust foundation for developing secure, Intel SGX-based contracts with built-in remote attestation support.
2024-09-29 04:52:44 +00:00
## Features
2024-10-02 03:57:13 +00:00
- `Attested<M, A>` wrapper for a message and its attestation
- MockAttestation type for development ease
- Session management for secure communication between contract and enclave
- Verify DCAP attestations (by calling `dcap-verifier` and `tcbinfo` contracts)
2024-09-29 04:52:44 +00:00
- Mock SGX support for testing environments
2024-10-02 03:57:13 +00:00
See also the [spec.md ](./SPEC.md )
2024-09-29 04:52:44 +00:00
## Installation
2024-10-02 03:57:13 +00:00
Add `quartz-contract-core` to your `Cargo.toml` :
2024-09-29 04:52:44 +00:00
```toml
[dependencies]
2024-10-02 03:57:13 +00:00
quartz-contract-core = { path = "../packages/quartz-contract-core" }
2024-09-29 04:52:44 +00:00
```
## Usage
2024-10-02 03:57:13 +00:00
Here's a basic example of how to use `quartz-contract-core` in your CosmWasm contract:
2024-09-29 04:52:44 +00:00
```rust
use quartz_cw::prelude::*;
use cosmwasm_std::{DepsMut, Env, MessageInfo, Response};
pub fn execute(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: QuartzExecuteMsg,
) -> Result< Response , ContractError > {
match msg {
QuartzExecuteMsg::Attested(attested_msg) => {
// Handle attested message
// Verification of the attestation is done automatically
let result = attested_msg.handle(deps, env, info)?;
Ok(result)
},
// Other message handlers...
}
}
```
## Key Components
1. `Attested<M, A>` : A wrapper struct for holding a message and its attestation.
2024-10-02 03:57:13 +00:00
2. `Attestation` : A trait for attestation types (DCAP, Mock).
2024-09-29 04:52:44 +00:00
3. `HasUserData` : A trait for extracting user data from attestations.
4. `RawHandler` : A trait for handling raw messages.
## Configuration
You can enable mock SGX support for testing by adding the `mock-sgx` feature to your `Cargo.toml` :
```toml
[dependencies]
2024-10-02 03:57:13 +00:00
quartz-contract-core = { path = "../packages/quartz-contract-core", features = ["mock-sgx"] }
2024-09-29 04:52:44 +00:00
```
## Testing
To run the tests:
```sh
cargo test
```