Skip to content
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

TSS attestation endpoint #1001

Merged
merged 14 commits into from
Aug 13, 2024
Merged

TSS attestation endpoint #1001

merged 14 commits into from
Aug 13, 2024

Conversation

ameba23
Copy link
Contributor

@ameba23 ameba23 commented Aug 12, 2024

This is part of #982

This adds a HTTP endpoint /attest to the TS server.

With the unsafe feature enabled, this will create a mock TDX quote for testing the attestation logic on non-TDX hardware.

Without the unsafe feature enabled, this will currently just respond with an error. Eventually though, it will create an actual TDX quote.

The idea is that once there is a pallet handling attestation, this endpoint will be called by an offchain worker. The endpoint will create the quote and submit it to the chain in an extrinsic. That does not yet happen, as we don't yet have a pallet to handle this.

@ameba23 ameba23 marked this pull request as draft August 12, 2024 09:58
@@ -99,3 +100,22 @@ pub enum HashingAlgorithm {

/// A compressed, serialized [synedrion::ecdsa::VerifyingKey<k256::Secp256k1>]
pub type EncodedVerifyingKey = [u8; VERIFICATION_KEY_LENGTH as usize];

/// Input data to be included in a TDX attestation
pub struct QuoteInputData(pub [u8; 64]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in entropy-shared because it will also be used by the chain when verifying quote input

@ameba23 ameba23 marked this pull request as ready for review August 12, 2024 14:30
@ameba23 ameba23 requested review from HCastano and JesseAbram and removed request for HCastano August 12, 2024 14:30
Copy link
Member

@JesseAbram JesseAbram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just the two things but looks good

crates/threshold-signature-server/src/lib.rs Outdated Show resolved Hide resolved
@@ -178,6 +178,7 @@ pub fn app(app_state: AppState) -> Router {
.route("/user/sign_tx", post(sign_tx))
.route("/signer/proactive_refresh", post(proactive_refresh))
.route("/validator/reshare", post(new_reshare))
.route("/attest", post(attest))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should go lower into the unsafe endpoints

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can put it there for now but the idea is this same endpoint will be the real thing when unsafe feature is not present

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk we can always change it when we remove the unsafe, it makes sense to me but your call

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I think it's fine as is

Copy link
Collaborator

@HCastano HCastano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice stuff 👍

assert_eq!(res.status(), 200);
let quote = res.bytes().await.unwrap();
// This verifies the signature in the quote
tdx_quote::Quote::from_bytes(&quote).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of unwrap-ing here we may want to check that the value we get back matches what we expect

crates/threshold-signature-server/src/validator/api.rs Outdated Show resolved Hide resolved
crates/threshold-signature-server/src/validator/api.rs Outdated Show resolved Hide resolved
input: Bytes,
) -> Result<(StatusCode, Bytes), ValidatorErr> {
// TODO #982 confirm with the chain that an attestation should be happenning
let nonce = input[..].try_into()?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let nonce = input[..].try_into()?;
let nonce = input.as_slice().try_into()?;

Copy link
Contributor Author

@ameba23 ameba23 Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i went for as_ref as as_slice doesn't seem to be available for Bytes

@@ -83,6 +84,7 @@ ethers-core ="2.0.14"
schnorrkel ={ version="0.11.4", default-features=false, features=["std"] }
schemars ={ version="0.8.21" }
subxt-signer="0.35.3"
tdx-quote ={ git="https://github.com/entropyxyz/tdx-quote", features=["mock"] }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to have this in both norm deps and dev deps?

Copy link
Contributor Author

@ameba23 ameba23 Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem is if we don't, it wont compile in test mode without the unsafe feature present, which is the case in CI. Ideally i don't want tdx-quote with the mock feature available in production. but i do want it in a release build if the unsafe feature is present, in order to be able to test a release build on non-tdx hardware.

let quote = tdx_quote::Quote::mock(signing_key.clone(), input_data.0);
// Here we would submit an attest extrinsic to the chain - but for now we just include it in the
// response
Ok((StatusCode::OK, Bytes::from(quote.as_bytes().to_vec())))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small thing for the future - would be nice to have a From/Into implementation for turning these quotes into Bytes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think thats only worth doing if we continue to include the quote in the http response. Initially i am proposing to only have on-chain quote verification, so the response body here will be empty and the quote will be included in an extrinsic instead. I want to keep the dependencies of tdx-quote as minimal as possible as its used in a pallet.

But if we decide to do quote verification by other TS servers, then we will want this.

@@ -178,6 +178,7 @@ pub fn app(app_state: AppState) -> Router {
.route("/user/sign_tx", post(sign_tx))
.route("/signer/proactive_refresh", post(proactive_refresh))
.route("/validator/reshare", post(new_reshare))
.route("/attest", post(attest))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I think it's fine as is

@ameba23 ameba23 merged commit fccd8a3 into master Aug 13, 2024
14 checks passed
@ameba23 ameba23 deleted the peg/attest-endpoint branch August 13, 2024 09:46
ameba23 added a commit that referenced this pull request Aug 13, 2024
* master:
  TSS attestation endpoint (#1001)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants