Skip to content
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/contract-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pub mod types {
pub use attestation::{
AppCompose, Attestation, Collateral, DstackAttestation, EventLog, MockAttestation, TcbInfo,
VerifiedAttestation, VerifiedDstackAttestation,
};
pub use config::{Config, InitConfig};
pub use crypto::{
Expand Down
52 changes: 50 additions & 2 deletions crates/contract-interface/src/types/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,54 @@ pub enum Attestation {
Mock(MockAttestation),
}

#[derive(
Clone,
Debug,
Eq,
PartialEq,
Ord,
PartialOrd,
Hash,
Serialize,
Deserialize,
BorshSerialize,
BorshDeserialize,
)]
#[cfg_attr(
all(feature = "abi", not(target_arch = "wasm32")),
derive(schemars::JsonSchema)
)]
pub enum VerifiedAttestation {
Dtack(VerifiedDstackAttestation),
Mock(MockAttestation),
}

#[derive(
Clone,
Debug,
Eq,
PartialEq,
Ord,
PartialOrd,
Hash,
Serialize,
Deserialize,
BorshSerialize,
BorshDeserialize,
)]
#[cfg_attr(
all(feature = "abi", not(target_arch = "wasm32")),
derive(schemars::JsonSchema)
)]
pub struct VerifiedDstackAttestation {
/// The digest of the MPC image running.
pub mpc_image_hash: Sha256Digest,
/// The digest of the launcher compose file running.
pub launcher_compose_hash: Sha256Digest,
/// Unix time stamp for when this attestation will be expired.
pub expiry_timestamp_seconds: u64,
}

#[derive(
Clone,
Eq,
Expand Down Expand Up @@ -78,8 +126,8 @@ pub enum MockAttestation {
WithConstraints {
mpc_docker_image_hash: Option<Sha256Digest>,
launcher_docker_compose_hash: Option<Sha256Digest>,
/// Unix time stamp for when this attestation expires.
expiry_time_stamp_seconds: Option<u64>,
/// Unix time stamp for when this attestation will be expired.
expiry_timestamp_seconds: Option<u64>,
},
}

Expand Down
129 changes: 18 additions & 111 deletions crates/contract/src/dto_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use contract_interface::types as dtos;
use mpc_attestation::{
attestation::{Attestation, DstackAttestation, MockAttestation},
attestation::{Attestation, DstackAttestation, MockAttestation, VerifiedAttestation},
collateral::{Collateral, QuoteCollateralV3},
EventLog, TcbInfo,
};
Expand Down Expand Up @@ -70,11 +70,11 @@ impl IntoContractType<MockAttestation> for dtos::MockAttestation {
dtos::MockAttestation::WithConstraints {
mpc_docker_image_hash,
launcher_docker_compose_hash,
expiry_time_stamp_seconds,
expiry_timestamp_seconds,
} => MockAttestation::WithConstraints {
mpc_docker_image_hash: mpc_docker_image_hash.map(Into::into),
launcher_docker_compose_hash: launcher_docker_compose_hash.map(Into::into),
expiry_time_stamp_seconds,
expiry_timestamp_seconds,
},
}
}
Expand Down Expand Up @@ -179,14 +179,21 @@ impl IntoContractType<EventLog> for dtos::EventLog {
}
}

impl IntoInterfaceType<dtos::Attestation> for Attestation {
fn into_dto_type(self) -> dtos::Attestation {
impl IntoInterfaceType<dtos::VerifiedAttestation> for VerifiedAttestation {
fn into_dto_type(self) -> dtos::VerifiedAttestation {
match self {
Attestation::Dstack(dstack_attestation) => {
dtos::Attestation::Dstack(dstack_attestation.into_dto_type())
VerifiedAttestation::Mock(mock_attestation) => {
dtos::VerifiedAttestation::Mock(mock_attestation.into_dto_type())
}
Attestation::Mock(mock_attestation) => {
dtos::Attestation::Mock(mock_attestation.into_dto_type())
VerifiedAttestation::Dstack(validated_dstack_attestation) => {
dtos::VerifiedAttestation::Dtack(dtos::VerifiedDstackAttestation {
mpc_image_hash: validated_dstack_attestation.mpc_image_hash.into(),
launcher_compose_hash: validated_dstack_attestation
.launcher_compose_hash
.into(),
expiry_timestamp_seconds: validated_dstack_attestation
.expiration_timestamp_seconds,
})
}
}
}
Expand All @@ -200,116 +207,16 @@ impl IntoInterfaceType<dtos::MockAttestation> for MockAttestation {
MockAttestation::WithConstraints {
mpc_docker_image_hash,
launcher_docker_compose_hash,
expiry_time_stamp_seconds,
expiry_timestamp_seconds,
} => dtos::MockAttestation::WithConstraints {
mpc_docker_image_hash: mpc_docker_image_hash.map(Into::into),
launcher_docker_compose_hash: launcher_docker_compose_hash.map(Into::into),
expiry_time_stamp_seconds,
expiry_timestamp_seconds,
},
}
}
}

impl IntoInterfaceType<dtos::DstackAttestation> for DstackAttestation {
fn into_dto_type(self) -> dtos::DstackAttestation {
let DstackAttestation {
quote,
collateral,
tcb_info,
} = self;

dtos::DstackAttestation {
quote: quote.into(),
collateral: collateral.into_dto_type(),
tcb_info: tcb_info.into_dto_type(),
}
}
}

impl IntoInterfaceType<dtos::Collateral> for Collateral {
fn into_dto_type(self) -> dtos::Collateral {
// Collateral is a newtype wrapper around QuoteCollateralV3
let QuoteCollateralV3 {
pck_crl_issuer_chain,
root_ca_crl,
pck_crl,
tcb_info_issuer_chain,
tcb_info,
tcb_info_signature,
qe_identity_issuer_chain,
qe_identity,
qe_identity_signature,
} = self.into();

dtos::Collateral {
pck_crl_issuer_chain,
root_ca_crl,
pck_crl,
tcb_info_issuer_chain,
tcb_info,
tcb_info_signature,
qe_identity_issuer_chain,
qe_identity,
qe_identity_signature,
}
}
}

impl IntoInterfaceType<dtos::TcbInfo> for TcbInfo {
fn into_dto_type(self) -> dtos::TcbInfo {
let TcbInfo {
mrtd,
rtmr0,
rtmr1,
rtmr2,
rtmr3,
os_image_hash,
compose_hash,
device_id,
app_compose,
event_log,
} = self;

let event_log = event_log
.into_iter()
.map(IntoInterfaceType::into_dto_type)
.collect();

dtos::TcbInfo {
mrtd,
rtmr0,
rtmr1,
rtmr2,
rtmr3,
os_image_hash,
compose_hash,
device_id,
app_compose,
event_log,
}
}
}

impl IntoInterfaceType<dtos::EventLog> for EventLog {
fn into_dto_type(self) -> dtos::EventLog {
let EventLog {
imr,
event_type,
digest,
event,
event_payload,
} = self;

dtos::EventLog {
imr,
event_type,
digest,
event,
event_payload,
}
}
}

impl IntoInterfaceType<dtos::Secp256k1PublicKey> for &k256_types::PublicKey {
fn into_dto_type(self) -> dtos::Secp256k1PublicKey {
let mut bytes = [0u8; 64];
Expand Down
Loading
Loading