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

feat: shared quartz_common crate + enclave server macro #87

Closed
wants to merge 11 commits into from

Conversation

dangush
Copy link
Contributor

@dangush dangush commented Jul 10, 2024

Closes #81

Moved quartz-cw, quartz-enclave, and quartz-proto into:

quartz_common::{contract, enclave, proto}

Also created quartz_server! macro to cut down enclave/main.rs boilerplate down to 1 line:

// Passing a custom clap Cli is optional
quartz_server!(Cli, MtcsServer, |sk| MtcsServer::new(MtcsService::new(sk, EpidAttestor)));
// With default Cli:
// quartz_server!(MtcsServer, |sk| MtcsServer::new(MtcsService::new(sk, EpidAttestor)));

Acceptance Criteria

This PR is ready when:

  • proto related bugs are fixed
  • the MTCS server runs
  • handshake performs
    • requires merging with other branches but idt it's affected anyway, quartz macro can receive another look-over

TODO

We don't need quartz relayer here right?

@dangush dangush requested a review from hu55a1n1 July 10, 2024 00:48
@davekaj davekaj self-requested a review July 24, 2024 12:45
Copy link
Contributor

@davekaj davekaj left a comment

Choose a reason for hiding this comment

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

Left some comments. Also when I tried to run in MOCK_SGX mode for the transfer app, I got this error:

QUARTZ_PORT is set to: 11090
set trusted hash
... 09E63DFD91ECD4394ABF3D7222AAF60D49253549C19B650B31DCFF722C2B934F
MOCK_SGX is set. Running enclave without gramine...
Error: Os { code: 2, kind: NotFound, message: "No such file or directory" }

Did you also get this error? If you don't have it, then it must be my environment. But if you have it as well, it might be an error related to one of my comments below, or something else

core/quartz-common/src/quartz_macro.rs Show resolved Hide resolved
apps/transfers/enclave/src/main.rs Show resolved Hide resolved
apps/mtcs/enclave/src/types.rs Show resolved Hide resolved
core/quartz-common/src/cli.rs Show resolved Hide resolved
apps/mtcs/enclave/Cargo.toml Show resolved Hide resolved
Copy link
Member

@hu55a1n1 hu55a1n1 left a comment

Choose a reason for hiding this comment

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

Nice work! I did preliminary review and added some comments.
Nit: Cargo.tomls are not formatted and deps are not alphabetically ordered 😅. (feel free to ignore)
Haven't tested yet - just want to make sure mock-sgx is working correctly but will wait for the fix for using DefaultAttestor in the enclaves. Will try to test tonight otherwise will delegate to the team (because I'm off for the rest of the week). 🙏

core/quartz-common/Cargo.toml Show resolved Hide resolved
apps/mtcs/enclave/Cargo.toml Show resolved Hide resolved
apps/transfers/contracts/src/msg.rs Show resolved Hide resolved
apps/mtcs/enclave/src/main.rs Show resolved Hide resolved
@@ -0,0 +1,64 @@
#[cfg(feature = "macro")]
#[macro_export]
macro_rules! quartz_server {
Copy link
Member

@hu55a1n1 hu55a1n1 Jul 24, 2024

Choose a reason for hiding this comment

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

I think the macro is cool, but I am not convinced we need it for the following reasons -

  • The main reason to have this macro IMHO would be to make sure the user/dev didn't forget to add the quartz CoreService. But I think there are other ways to achieve that. e.g. ->
trait QuartzServerExt {
    fn quartz_builder(
        config: Config,
        sk: Arc<Mutex<Option<SigningKey>>>,
        attestor: DefaultAttestor,
    ) -> Router;
}

impl QuartzServerExt for Server {
    fn quartz_builder(
        config: Config,
        sk: Arc<Mutex<Option<SigningKey>>>,
        attestor: DefaultAttestor,
    ) -> Router {
        Server::builder().add_service(CoreServer::new(CoreService::new(
            config,
            sk.clone(),
            attestor.clone(),
        )))
    }
}
  • The macro does reduce the amount of code to be written but users might want the flexibility to specify their own config e.g. light client opts, etc.
  • Users may also want to add more services.
  • The macro is restricting users ability to use their libs of choice e.g. for CLI, tokio, etc. (I don't think we should make such decisions on their behalf)

@hu55a1n1
Copy link
Member

Superseded by #123 (which has been merged already).

@hu55a1n1 hu55a1n1 closed this Jul 31, 2024
@dangush dangush deleted the dangush/quartz-common branch August 21, 2024 00:25
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.

Create a separate crate for shared/common code that is imported by both contracts and enclaves
3 participants