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: add move entry function for verify attestation #20870

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

joyqvq
Copy link
Contributor

@joyqvq joyqvq commented Jan 13, 2025

Description

Describe the changes or additions included in this PR.

Test plan

───────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Transaction Effects                                                                               │
├───────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Digest: EKi3SxAAXzXUTn56MoKKDtXtYdbkcXY94LsWsEZ4o5ZN                                              │
│ Status: Success                                                                                   │
│ Executed Epoch: 6                                                                                 │
│ Mutated Objects:                                                                                  │
│  ┌──                                                                                              │
│  │ ID: 0x101c1e40e8f59302bc8673f3acf71066dcce5939b10c6accb3b4cd6036f46e04                         │
│  │ Owner: Account Address ( 0xfa469d15a399f7a000214f4630712c6e6207430499278e1c2e19a63d5dd821e5 )  │
│  │ Version: 4806                                                                                  │
│  │ Digest: HnMUEn3UmuLoL9Ph1kiNuec1XByvgmKFv6CuBKGi8Eez                                           │
│  └──                                                                                              │
│ Shared Objects:                                                                                   │
│  ┌──                                                                                              │
│  │ ID: 0x0000000000000000000000000000000000000000000000000000000000000006                         │
│  │ Version: 4805                                                                                  │
│  │ Digest: 3kSQomS162h2h3DWAqjhbmMeHjtokVA3kewaYV66zdiA                                           │
│  └──                                                                                              │
│ Gas Object:                                                                                       │
│  ┌──                                                                                              │
│  │ ID: 0x101c1e40e8f59302bc8673f3acf71066dcce5939b10c6accb3b4cd6036f46e04                         │
│  │ Owner: Account Address ( 0xfa469d15a399f7a000214f4630712c6e6207430499278e1c2e19a63d5dd821e5 )  │
│  │ Version: 4806                                                                                  │
│  │ Digest: HnMUEn3UmuLoL9Ph1kiNuec1XByvgmKFv6CuBKGi8Eez                                           │
│  └──                                                                                              │
│ Gas Cost Summary:                                                                                 │
│    Storage Cost: 988000 MIST                                                                      │
│    Computation Cost: 1000000 MIST                                                                 │
│    Storage Rebate: 978120 MIST                                                                    │
│    Non-refundable Storage Fee: 9880 MIST                                                          │
│                                                                                                   │
│ Transaction Dependencies:                                                                         │
│    ogFZK8yeyj8aW65KfjpydBxQza1DDEMaUorTVAk3FGT                                                    │
│    8HLYAqCnZ4FhfPcAFaWAXwjL6f8bzmkgqJDySoEotAsm                                                   │
│    E78irqocBhce6W6cqontHowPRRdAwCdNRak75tMPh4MK                                                   │
╰───────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────╮
│ No transaction block events │
╰─────────────────────────────╯

╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Object Changes                                                                                   │
├──────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Mutated Objects:                                                                                 │
│  ┌──                                                                                             │
│  │ ObjectID: 0x101c1e40e8f59302bc8673f3acf71066dcce5939b10c6accb3b4cd6036f46e04                  │
│  │ Sender: 0xfa469d15a399f7a000214f4630712c6e6207430499278e1c2e19a63d5dd821e5                    │
│  │ Owner: Account Address ( 0xfa469d15a399f7a000214f4630712c6e6207430499278e1c2e19a63d5dd821e5 ) │
│  │ ObjectType: 0x2::coin::Coin<0x2::sui::SUI>                                                    │
│  │ Version: 4806                                                                                 │
│  │ Digest: HnMUEn3UmuLoL9Ph1kiNuec1XByvgmKFv6CuBKGi8Eez                                          │
│  └──                                                                                             │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
╭───────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Balance Changes                                                                                   │
├───────────────────────────────────────────────────────────────────────────────────────────────────┤
│  ┌──                                                                                              │
│  │ Owner: Account Address ( 0xfa469d15a399f7a000214f4630712c6e6207430499278e1c2e19a63d5dd821e5 )  │
│  │ CoinType: 0x2::sui::SUI                                                                        │
│  │ Amount: -1009880                                                                               │
│  └──                                                                                              │
╰───────────────────────────────────────────────────────────────────────────────────────────────────╯

sui replay:

     Running `target/debug/sui-tool replay --cfg-path /Users/joy/.sui/sui_config/client.yaml --rpc 'http://127.0.0.1:9000' tx --tx-digest EKi3SxAAXzXUTn56MoKKDtXtYdbkcXY94LsWsEZ4o5ZN`
2025-01-14T02:24:05.515413Z  INFO sui_replay: Executing tx: EKi3SxAAXzXUTn56MoKKDtXtYdbkcXY94LsWsEZ4o5ZN
2025-01-14T02:24:05.515867Z  INFO sui_replay::replay: Using RPC URL: http://127.0.0.1:9000
Execution finished successfully. Local and on-chain effects match.
image

Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol: Add a new native function to verify aws nitro enclave attestation in Devnet.
  • Nodes (Validators and Full nodes):
  • gRPC:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:

Copy link

vercel bot commented Jan 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 24, 2025 8:17pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Jan 24, 2025 8:17pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Jan 24, 2025 8:17pm

@joyqvq joyqvq force-pushed the joy/attestation branch 4 times, most recently from fe48069 to 0808288 Compare January 15, 2025 20:06
@joyqvq joyqvq force-pushed the joy/move-attestation branch from b723402 to dd15b47 Compare January 15, 2025 20:14
@joyqvq joyqvq temporarily deployed to sui-typescript-aws-kms-test-env January 15, 2025 20:14 — with GitHub Actions Inactive
@joyqvq joyqvq force-pushed the joy/move-attestation branch from dd15b47 to 844babe Compare January 15, 2025 20:32
@joyqvq joyqvq temporarily deployed to sui-typescript-aws-kms-test-env January 15, 2025 20:32 — with GitHub Actions Inactive
@joyqvq joyqvq temporarily deployed to sui-typescript-aws-kms-test-env January 16, 2025 15:25 — with GitHub Actions Inactive
@joyqvq joyqvq force-pushed the joy/attestation branch 2 times, most recently from ae78b72 to 4079db6 Compare January 16, 2025 16:46
Base automatically changed from joy/attestation to main January 16, 2025 17:16
@joyqvq joyqvq force-pushed the joy/move-attestation branch from 279ca0f to 958992f Compare January 16, 2025 17:44
@joyqvq joyqvq temporarily deployed to sui-typescript-aws-kms-test-env January 16, 2025 17:44 — with GitHub Actions Inactive
@joyqvq joyqvq force-pushed the joy/move-attestation branch from 3da6bd7 to d8e4a47 Compare January 17, 2025 21:34
@joyqvq joyqvq temporarily deployed to sui-typescript-aws-kms-test-env January 17, 2025 21:34 — with GitHub Actions Inactive
@joyqvq joyqvq marked this pull request as ready for review January 17, 2025 21:39
@joyqvq joyqvq requested a review from ronny-mysten as a code owner January 17, 2025 21:39
@joyqvq joyqvq temporarily deployed to sui-typescript-aws-kms-test-env January 17, 2025 21:39 — with GitHub Actions Inactive
@joyqvq joyqvq requested a review from tzakian January 17, 2025 21:40
@joyqvq joyqvq changed the title Joy/move attestation feat: add move entry function for verify attestation Jan 17, 2025
@joyqvq joyqvq force-pushed the joy/move-attestation branch from d8e4a47 to 3bcae14 Compare January 22, 2025 17:04
@joyqvq joyqvq temporarily deployed to sui-typescript-aws-kms-test-env January 22, 2025 17:04 — with GitHub Actions Inactive
@joyqvq joyqvq force-pushed the joy/move-attestation branch from 3bcae14 to 085d87e Compare January 22, 2025 17:06
@joyqvq joyqvq temporarily deployed to sui-typescript-aws-kms-test-env January 22, 2025 17:06 — with GitHub Actions Inactive
@joyqvq joyqvq requested a review from benr-ml January 22, 2025 17:06
@joyqvq joyqvq force-pushed the joy/move-attestation branch from 085d87e to 6922f31 Compare January 22, 2025 17:35
@joyqvq joyqvq temporarily deployed to sui-typescript-aws-kms-test-env January 22, 2025 17:35 — with GitHub Actions Inactive
@joyqvq joyqvq force-pushed the joy/move-attestation branch from 6922f31 to 4d77ed7 Compare January 22, 2025 18:33
@joyqvq joyqvq temporarily deployed to sui-typescript-aws-kms-test-env January 22, 2025 18:33 — with GitHub Actions Inactive
module_id: vector<u8>,
timestamp: u64,
digest: vector<u8>,
pcrs: vector<vector<u8>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

there is some meaning to the order, no? if simple, let's document it, else let's define this type explicitly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

Copy link
Contributor

Choose a reason for hiding this comment

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

are we sure that PCR6 for example won't be added in the future? if not, should we store a vector of PCR { index: u8, data: vector}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

        let pcrs = match document_map
            .iter()
            .find(|(k, _)| matches!(k, ciborium::value::Value::Text(s) if s == "pcrs"))
        {
            Some((_, ciborium::value::Value::Map(pcr_map))) => {
                let mut pcr_vec = Vec::new();
                // Valid PCR indices are 0, 1, 2, 3, 4, 8 for AWS.
                for i in [0, 1, 2, 3, 4, 8] {
                    if let Some((_, ciborium::value::Value::Bytes(val))) = pcr_map.iter().find(
                        |(k, _)| matches!(k, ciborium::value::Value::Integer(n) if *n == i.into()),
                    ) {
                        pcr_vec.push(val.clone());
                    } else {
                        return Err(NitroAttestationVerifyError::InvalidAttestationDoc(
                            "invalid PCR format".to_string(),
                        ));
                    }
                }
                pcr_vec
            }
            _ => {
                return Err(NitroAttestationVerifyError::InvalidAttestationDoc(
                    "cannot parse PCRs".to_string(),
                ))
            }
        };

we currently hardcode the index for 0, 1, 2, 3, 4, 8. there are all zero values in other indices and there are 26 of them. while we can parse all of them and return, this will be a quadratic lookup to look at all pcr values, my worry is that there is no limit on the number of pcr values.

/// @param clock: the clock object.
///
/// Returns parsed NitroAttestationDocument after verifying the attestation.
public fun verify_nitro_attestation(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public fun verify_nitro_attestation(
entry fun load_nitro_attestation(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

iiuc this forbids other move module to call this? i would think its useful to expose it?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, other modules cannot call it, but in which use case do we need that? it's a user provided data.

as an entry function we have the flexibility to change the interface later if we like

Copy link
Contributor Author

Choose a reason for hiding this comment

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

its user provided data, but the output are consumed by the caller module which should check the rest like verifying the public key == user data and the signature verifies, and all pcrs match the registry?

https://github.com/MystenLabs/enclave-twitter/blob/main/move/sources/twitter.move#L25

Copy link
Contributor

Choose a reason for hiding this comment

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

that function could receive NitroAttestationDocument as an output a previous PTB command

/// @param attestation: attesttaion documents bytes data.
/// @param clock: the clock object.
///
/// Returns parsed NitroAttestationDocument after verifying the attestation.
Copy link
Contributor

Choose a reason for hiding this comment

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

also document the errors in case of expired cert, etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all verify error is currently casted to a generic VerifyError. any reason this should be more specific?

Copy link
Contributor

@benr-ml benr-ml Jan 26, 2025

Choose a reason for hiding this comment

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

sounds ok, let's have that error documented here

use sui::test_scenario;

#[test]
fun test_nitro_attestation() {
Copy link
Contributor

Choose a reason for hiding this comment

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

once we stabilize the move interface, let's test also:

  • old cert
  • invalid structs
  • invalid cert sig

Copy link
Contributor Author

Choose a reason for hiding this comment

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

a related question, do you think the tests should exist twice in both move and sui-type? or we should port all sui-types tests here? agreed to add more tests. it will be quite involved (i need a mock signer in cert) so good to do it in a separate pr

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, if we cover those cases in the Rust tests then indeed it's enough. Let's only test here the flows of the native call, i.e.,:

  • parsing fails (with a hardcoded string)
  • parsing succeeds, verification fails
  • everything is good

// Encapsulate as a lambda and call to allow us to capture any `Err` returns.
// Could do this with `and_then` as well if desired.
let result = || {
Ok(Value::struct_(Struct::pack(vec![
Copy link
Contributor

Choose a reason for hiding this comment

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

@tzakian please review the conversions here

module_id: vector<u8>,
timestamp: u64,
digest: vector<u8>,
pcrs: vector<vector<u8>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

are we sure that PCR6 for example won't be added in the future? if not, should we store a vector of PCR { index: u8, data: vector}

verify_nitro_attestation_internal(attestation, clock::timestamp_ms(clock))
}

public fun module_id(attestation: &NitroAttestationDocument): vector<u8> {
Copy link
Contributor

Choose a reason for hiding this comment

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

should this (and below) be ref?

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