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

initial pepper service for keyless accounts #12158

Merged
merged 42 commits into from
Mar 1, 2024
Merged

initial pepper service for keyless accounts #12158

merged 42 commits into from
Mar 1, 2024

Conversation

zjma
Copy link
Contributor

@zjma zjma commented Feb 22, 2024

Description

TODOs

  • Rename oidb/pepper to oidb/pepper-service
  • Rename oidb/ to keyless/

Test Plan

Copy link

trunk-io bot commented Feb 22, 2024

⏱️ 24h 48m total CI duration on this PR
Job Cumulative Duration Recent Runs
windows-build 10h 46m 🟩🟩🟩🟩🟩 (+26 more)
rust-unit-tests 5h 55m 🟥🟥🟥🟥🟩 (+25 more)
run-tests-main-branch 3h 22m 🟥🟥🟥🟥🟥 (+26 more)
rust-lints 1h 32m 🟥🟥🟥🟥🟩 (+25 more)
check-dynamic-deps 1h 3m 🟩🟩🟩🟩🟩 (+26 more)
general-lints 1h 1m 🟩🟩🟩🟩🟩 (+25 more)
check 35m 🟩🟩🟩🟩🟩 (+26 more)
semgrep/ci 15m 🟩🟩🟩🟩🟩 (+26 more)
file_change_determinator 6m 🟩🟩🟩🟩🟩 (+26 more)
file_change_determinator 5m 🟩🟩🟩🟩🟩 (+26 more)
permission-check 4m 🟩🟩🟩🟩🟩 (+26 more)
permission-check 2m 🟩🟩🟩🟩🟩 (+26 more)
permission-check 1m 🟩🟩🟩🟩🟩 (+26 more)
permission-check 1m 🟩🟩🟩🟩🟩 (+26 more)

🚨 2 jobs on the last run were significantly faster/slower than expected

Job Duration vs 7d avg Delta
run-tests-main-branch 6m 4m +67%
windows-build 12m 20m -40%

settingsfeedbackdocs ⋅ learn more about trunk.io

@zjma zjma marked this pull request as ready for review February 22, 2024 03:21
@zjma zjma requested review from alinush and heliuchuan February 22, 2024 03:21
pub type KeyID = String;

/// The core processing logic of this pepper service.
pub async fn process(request: PepperRequest) -> anyhow::Result<String> {
Copy link
Contributor

@gedigi gedigi Feb 23, 2024

Choose a reason for hiding this comment

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

should there be any data validation (e.g. max/expected sizes) throughout this function? there's a lot of deserialization and parsing with user-controlled input which could potentially be expensive.

@@ -16,7 +17,7 @@ pub static VUF_SCHEME0_SK: Lazy<ark_bls12_381::Fr> = Lazy::new(|| {
let vuf_key_hex =
std::env::var("VRF_KEY_HEX").expect("VRF_KEY_HEX is required for pepper calculation");
let sk_bytes = hex::decode(vuf_key_hex).expect("vrf_key_hex should be a valid hex string");
ark_bls12_381::Fr::deserialize_compressed(sk_bytes.as_slice()).unwrap()
ark_bls12_381::Fr::from_be_bytes_mod_order(sk_bytes.as_slice())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@heliuchuan let's not use *_mod_order as it accepts any byte string, ircc.
Reverse the byte string and use deserialize_compressed instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nvm, what's from envvar will be a 256-bit seed and we need to derive sk from the seed.

oidb/pepper/common/src/lib.rs Outdated Show resolved Hide resolved
oidb/pepper/service/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@aluon aluon left a comment

Choose a reason for hiding this comment

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

The dev_setup.sh changes look good to me

@@ -892,6 +893,9 @@ while getopts "btoprvydaPJh:i:n" arg; do
n)
OPT_DIR="true"
;;
k)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you also update usage() to describe what the -k flag is used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current dev_setup change is actually a hack... (I'm surprised you didn't hate it lol, because below it's even trying to --break-system-packages)

I could not figure out how to use existing dockerfile templates for pepper service, and the current dockerfile for pepper service is quick and dirty.

I will figure out the right way to docker build and revert this part. But if you are ok with the hack, i guess i can keep using the hack until i figure out?

Copy link
Contributor

@aluon aluon Feb 27, 2024

Choose a reason for hiding this comment

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

I think it's fine if this is just a quick hack

How is this image going to be built? If we want to use the GitHub workflows to automate this we probably want to do something similar to the other Dockerfiles for caching

.map_err(|e| anyhow!("jwt decoding error: {}", e))
}

static DUMMY_DECODING_KEY: Lazy<DecodingKey> = Lazy::new(|| DecodingKey::from_secret(&[]));
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this? Can you add a comment? Is this the JWK? If so, why are you calling it a decoding key?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

they are required by the jsonwebtoken library to parse jwt without verifing sig (its default behavior is to parse and verify both in one call, but we don't want it).

It's JWK, but the library call it DecodingKey...

I found another library jwt with API that makes more sense, but yet to replace this.

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. No worries, just move the statics inside the function if that's the only place where they are used?

Plus, in the end we will need to unify the JWT logic so that we can use the same calls in both the prover service, pepper service and the Rust authenticator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}

#[derive(Debug, Default, Deserialize, Serialize)]
pub struct EncryptionPubKey {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this even used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, since we are not doing encryption at the moment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Will it be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now i remember this can be gone, given EphemeralPublicKey in main.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

CODEOWNERS Outdated
@@ -98,6 +98,11 @@
# Owners for the network and all its subdirectories.
/network/ @gregnazario @joshlind @brianolson

# Owners for the scripts
/scripts/ @aptos-labs/devinfra
Copy link
Contributor

@sionescu sionescu Feb 26, 2024

Choose a reason for hiding this comment

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

Let's make this @aptos-labs/prod-eng.

Copy link
Contributor

@alinush alinush Feb 26, 2024

Choose a reason for hiding this comment

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

@aluon said to use devinfra. Should I change it to prod-eng or add prod-eng next to it?

Copy link
Contributor

Choose a reason for hiding this comment

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

@aluon do we need a different team here ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also @aluon, there seems to be an error regarding the devinfra team not existing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's set this to aptos-labs/prod-eng for now. I was thinking we could create a devinfra team so we can add other folks but I'm not sure why it's erroring

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok.

Copy link
Contributor

Choose a reason for hiding this comment

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

@zjma this was not resolved. Can you change @aptos-labs/devinfra to @aptos-labs/prod-eng?

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 didn't add this diff... why is it even in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

anyway fixed

git_commit: String,
}

pub static ABOUT_JSON: Lazy<String> = Lazy::new(|| {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add comments? What is this?

Copy link
Contributor Author

@zjma zjma Feb 26, 2024

Choose a reason for hiding this comment

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

this is for showing some metadata at /about.
e.g. the commit SHA1

let (pepper, vuf_proof) = vuf::scheme0::Scheme0::eval(&VUF_SCHEME0_SK, &input_bytes)?;
ensure!(vuf_proof.is_empty(), "internal proof error");
let pepper_hexlified = hex::encode(pepper);
Ok(pepper_hexlified)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you not returning the proof here? @heliuchuan will want to verify the proof in the SDK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because the proof is empty?

Copy link
Contributor

Choose a reason for hiding this comment

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

For BLS, sure, but when you change the scheme, will you put the proof inside pepper_hexlified?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in that case, pepper should be bcs::to_bytes(some_struct_that_include_output_and_proof)?

Copy link
Contributor

@alinush alinush Feb 27, 2024

Choose a reason for hiding this comment

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

Sure, but the problem with this PR is that we do not have clean separation between structs and their serialization.

e.g., why is PepperResponse containing hex strings? It should have Vec<u8>'s and the serialization code (BCS, JSON) will decide the format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

use once_cell::sync::Lazy;
use ark_ff::PrimeField;

pub struct VufScheme0Sk {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not even used...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@alinush alinush changed the title initial oidb pepper service initial pepper service for keyless accounts Feb 26, 2024
}

/// The response to `PepperRequestV0`, which contains the calculated pepper (hexlified) or a processing error.
#[derive(Debug, Deserialize, Serialize)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add comments and explain these fields.

Not sure why there are two things here.

There is just one pepper.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

oidb/pepper/service/src/lib.rs Outdated Show resolved Hide resolved
@zjma zjma force-pushed the zjma/pepper-service branch from f119ad1 to f340408 Compare February 28, 2024 23:20
@@ -384,6 +385,8 @@ aptos-package-builder = { path = "aptos-move/package-builder" }
aptos-peer-monitoring-service-client = { path = "peer-monitoring-service/client" }
aptos-peer-monitoring-service-server = { path = "peer-monitoring-service/server" }
aptos-peer-monitoring-service-types = { path = "peer-monitoring-service/types" }
aptos-keyless-pepper-common = { path = "keyless/pepper/common" }
Copy link
Contributor

@alinush alinush Feb 29, 2024

Choose a reason for hiding this comment

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

We will likely move most of this into crates/aptos-crypto and types over time.

Copy link
Contributor

@alinush alinush left a comment

Choose a reason for hiding this comment

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

Stamping assuming you've addressed the request/response formatting issues. Don't have time to look right now.

Copy link
Contributor

@heliuchuan heliuchuan left a comment

Choose a reason for hiding this comment

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

stamp request response lgtm

v0 sennddddd

note eventually i think we should use axum over hyper

.header(ACCESS_CONTROL_ALLOW_ORIGIN, origin)
.header(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true")
.header(ACCESS_CONTROL_ALLOW_METHODS, "GET, POST, OPTIONS")
.header(ACCESS_CONTROL_ALLOW_HEADERS, "Content-Type, Authorization")
Copy link
Contributor

Choose a reason for hiding this comment

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

let's set this to "*" for now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@zjma zjma enabled auto-merge (squash) March 1, 2024 01:30

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

github-actions bot commented Mar 1, 2024

✅ Forge suite realistic_env_max_load success on 477f395cdbd35d3a7e4228bfcdf480a4082c9fe6

two traffics test: inner traffic : committed: 7979 txn/s, latency: 4918 ms, (p50: 4800 ms, p90: 5700 ms, p99: 10400 ms), latency samples: 3439100
two traffics test : committed: 100 txn/s, latency: 1880 ms, (p50: 1800 ms, p90: 2000 ms, p99: 6100 ms), latency samples: 1820
Latency breakdown for phase 0: ["QsBatchToPos: max: 0.230, avg: 0.203", "QsPosToProposal: max: 0.320, avg: 0.268", "ConsensusProposalToOrdered: max: 0.455, avg: 0.422", "ConsensusOrderedToCommit: max: 0.296, avg: 0.272", "ConsensusProposalToCommit: max: 0.738, avg: 0.694"]
Max round gap was 1 [limit 4] at version 1652910. Max no progress secs was 4.41434 [limit 15] at version 1652910.
Test Ok

Copy link
Contributor

github-actions bot commented Mar 1, 2024

✅ Forge suite compat success on aptos-node-v1.9.5 ==> 477f395cdbd35d3a7e4228bfcdf480a4082c9fe6

Compatibility test results for aptos-node-v1.9.5 ==> 477f395cdbd35d3a7e4228bfcdf480a4082c9fe6 (PR)
1. Check liveness of validators at old version: aptos-node-v1.9.5
compatibility::simple-validator-upgrade::liveness-check : committed: 6988 txn/s, latency: 4726 ms, (p50: 4800 ms, p90: 7300 ms, p99: 7800 ms), latency samples: 244600
2. Upgrading first Validator to new version: 477f395cdbd35d3a7e4228bfcdf480a4082c9fe6
compatibility::simple-validator-upgrade::single-validator-upgrade : committed: 689 txn/s, latency: 35500 ms, (p50: 38700 ms, p90: 53700 ms, p99: 56400 ms), latency samples: 56500
3. Upgrading rest of first batch to new version: 477f395cdbd35d3a7e4228bfcdf480a4082c9fe6
compatibility::simple-validator-upgrade::half-validator-upgrade : committed: 229 txn/s, submitted: 543 txn/s, expired: 313 txn/s, latency: 38004 ms, (p50: 41800 ms, p90: 56900 ms, p99: 61400 ms), latency samples: 19315
4. upgrading second batch to new version: 477f395cdbd35d3a7e4228bfcdf480a4082c9fe6
compatibility::simple-validator-upgrade::rest-validator-upgrade : committed: 2330 txn/s, latency: 12640 ms, (p50: 12300 ms, p90: 17800 ms, p99: 18400 ms), latency samples: 111880
5. check swarm health
Compatibility test for aptos-node-v1.9.5 ==> 477f395cdbd35d3a7e4228bfcdf480a4082c9fe6 passed
Test Ok

@zjma zjma merged commit c284f3b into main Mar 1, 2024
42 checks passed
@zjma zjma deleted the zjma/pepper-service branch March 1, 2024 10:18
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.

6 participants