Skip to content

Commit 6d0352a

Browse files
authored
Merge branch 'main' into tore/feat/2489/api-endpoints
2 parents 64e3a1c + 5618c3d commit 6d0352a

File tree

20 files changed

+197
-103
lines changed

20 files changed

+197
-103
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ authors = ["Zama"]
2525
publish = true
2626
edition = "2021"
2727
license = "BSD-3-Clause-Clear"
28-
version = "0.11.0-24"
28+
version = "0.11.0-26"
2929

3030
[workspace.dependencies]
3131
aes = "=0.8.4"

backward-compatibility/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backward-compatibility/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "backward-compatibility"
3-
version = "0.11.0-24"
3+
version = "0.11.0-26"
44
publish = false
55
authors = ["Zama"]
66
edition = "2021"
@@ -9,7 +9,6 @@ license = "BSD-3-Clause-Clear"
99
[dependencies]
1010
# This is a list of kms-core versions we will generate data for. This list will grow over time.
1111
# They are only activated when generating data, with the binary target and the "generate" feature.
12-
# TODO update to public repo, once we have a public release
1312
kms_0_11 = { git = "https://github.com/zama-ai/kms.git", package = "kms", rev = "v0.11.0-22", optional = true }
1413
kms_grpc_0_11 = { git = "https://github.com/zama-ai/kms.git", package = "kms-grpc", rev = "v0.11.0-22", optional = true }
1514
threshold_fhe_0_11 = { git = "https://github.com/zama-ai/kms.git", package = "threshold-fhe", rev = "v0.11.0-22", optional = true, features = [

core-client/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@ fn check_ext_pt_signature(
901901
external_handles: Vec<Vec<u8>>,
902902
domain: Eip712Domain,
903903
kms_addrs: &[alloy_primitives::Address],
904+
extra_data: Vec<u8>,
904905
) -> anyhow::Result<()> {
905906
// convert received data into proper format for EIP-712 verification
906907
if external_sig.len() != 65 {
@@ -918,7 +919,7 @@ fn check_ext_pt_signature(
918919
tracing::debug!("PTs: {:?}", plaintexts);
919920
tracing::debug!("ext. handles: {:?}", external_handles);
920921

921-
let hash = compute_pt_message_hash(external_handles, plaintexts, domain);
922+
let hash = compute_pt_message_hash(external_handles, plaintexts, domain, extra_data);
922923

923924
let addr = sig.recover_address_from_prehash(&hash)?;
924925
tracing::info!("recovered address: {}", addr);
@@ -942,11 +943,12 @@ fn check_external_decryption_signature(
942943
for response in responses {
943944
let payload = response.payload.as_ref().unwrap();
944945
check_ext_pt_signature(
945-
payload.external_signature(),
946+
response.external_signature(),
946947
&payload.plaintexts,
947948
external_handles.to_owned(),
948949
domain.clone(),
949950
kms_addrs,
951+
vec![],
950952
)?;
951953

952954
for (idx, pt) in payload.plaintexts.iter().enumerate() {

core/grpc/proto/kms.v1.proto

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ message PublicDecryptionRequest {
223223

224224
// The EIP712 domain used for signing the response.
225225
Eip712DomainMsg domain = 4;
226+
227+
// Extra data from the gateway.
228+
bytes extra_data = 5;
226229
}
227230

228231
// KMS-internal Public Decryption Response Payload, containing meta data, plaintexts
@@ -234,27 +237,29 @@ message PublicDecryptionResponsePayload {
234237
// trusted keys.
235238
// TODO should be renamed to make it clear it is the server's key
236239
bytes verification_key = 1;
237-
// Digest of the request validated.
238-
// Needed to ensure that the response is for the expected request.
239-
// THIS IS DEPRECATED AND KMS WILL LEAVE THIS FIELD EMPTY,
240-
// instead, we will use request_id to specify the link.
241-
bytes digest = 2 [deprecated=true];
240+
242241
// A list of plaintexts, as little endian byte arrays. One for each
243242
// ciphertext.
244-
repeated TypedPlaintext plaintexts = 3;
245-
// the signature on external_decryption_result for the external recipient
246-
// (e.g. using EIP712 for fhevm)
247-
optional bytes external_signature = 4;
243+
repeated TypedPlaintext plaintexts = 2;
244+
248245
// Request ID of the request that this response corresponds to.
249-
RequestId request_id = 5;
246+
RequestId request_id = 3;
250247
}
251248

252249
// KMS-internal Public Decryption Response
253250
message PublicDecryptionResponse {
254251
// Signature of the serialization of [PublicDecryptionResponsePayload].
255252
bytes signature = 1;
253+
254+
// the signature on external_decryption_result for the external recipient
255+
// (e.g. using EIP712 for fhevm)
256+
optional bytes external_signature = 2;
257+
256258
// The payload that is signed
257-
PublicDecryptionResponsePayload payload = 2;
259+
PublicDecryptionResponsePayload payload = 3;
260+
261+
// Extra data used in the EIP712 signature - external_signature.
262+
bytes extra_data = 4;
258263
}
259264

260265
// Eip712 domain information.
@@ -289,38 +294,51 @@ message UserDecryptionRequest {
289294

290295
// The user's EIP712 domain. This MUST be present. Furthermore, the `verifying_contract` MUST be set and be distinct from `client_address`.
291296
Eip712DomainMsg domain = 6;
297+
298+
// Extra data from the gateway.
299+
bytes extra_data = 7;
292300
}
293301

294302
message UserDecryptionResponse {
295303
bytes signature = 1;
304+
296305
// This is the external signature created from the Eip712 domain
297306
// on the structure, where userDecryptedShare is bc2wrap::serialize(&payload)
298307
// struct UserDecryptResponseVerification {
299308
// bytes publicKey;
300309
// uint256[] ctHandles;
301-
// bytes userDecryptedShare;
310+
// bytes userDecryptedShare; // serialization of payload
311+
// bytes extraData;
302312
// }
303313
bytes external_signature = 2;
314+
304315
// The actual [UserDecryptionResponsePayload].
305316
UserDecryptionResponsePayload payload = 3;
317+
318+
// Extra data used in the EIP712 signature - external_signature.
319+
bytes extra_data = 4;
306320
}
307321

308322
message UserDecryptionResponsePayload {
309323
// The server's signature verification key, Encoded using SEC1.
310324
// Needed to validate the response, but MUST also be linked to a list of
311325
// trusted keys.
312326
bytes verification_key = 1;
327+
313328
// This is needed to ensure the response corresponds to the request.
314329
// It is the digest of UserDecryptionLinker hashed using EIP712
315330
// under the given domain in the request.
316331
bytes digest = 2;
332+
317333
// The resulting signcrypted ciphertexts, each ciphertext
318334
// must be decrypted and then reconstructed with the other shares
319335
// to produce the final plaintext.
320336
repeated TypedSigncryptedCiphertext signcrypted_ciphertexts = 3;
337+
321338
// The ID of the MPC party doing the user decryption. Used for polynomial
322339
// reconstruction.
323340
uint32 party_id = 4;
341+
324342
// The degree of the sharing scheme used.
325343
uint32 degree = 5;
326344
}

core/grpc/src/rpc_types.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ alloy_sol_types::sol! {
4242
bytes publicKey;
4343
bytes32[] ctHandles;
4444
bytes userDecryptedShare;
45+
bytes extraData;
4546
}
4647
}
4748

@@ -62,6 +63,7 @@ alloy_sol_types::sol! {
6263
struct PublicDecryptVerification {
6364
bytes32[] ctHandles;
6465
bytes decryptedResult;
66+
bytes extraData;
6567
}
6668
}
6769

@@ -1129,6 +1131,7 @@ mod tests {
11291131
client_address: client_address.to_checksum(None),
11301132
enc_key: vec![],
11311133
domain: None,
1134+
extra_data: vec![],
11321135
};
11331136
assert!(req
11341137
.compute_link_checked()
@@ -1146,6 +1149,7 @@ mod tests {
11461149
client_address: client_address.to_checksum(None),
11471150
enc_key: vec![],
11481151
domain: Some(domain.clone()),
1152+
extra_data: vec![],
11491153
};
11501154
assert!(req
11511155
.compute_link_checked()
@@ -1166,6 +1170,7 @@ mod tests {
11661170
client_address: client_address.to_checksum(None),
11671171
enc_key: vec![],
11681172
domain: Some(bad_domain),
1173+
extra_data: vec![],
11691174
};
11701175

11711176
assert!(req
@@ -1184,6 +1189,7 @@ mod tests {
11841189
client_address: client_address.to_checksum(None),
11851190
enc_key: vec![],
11861191
domain: Some(domain.clone()),
1192+
extra_data: vec![],
11871193
};
11881194
assert!(req.compute_link_checked().is_ok());
11891195
}

core/service/rust-toolchain.toml

Lines changed: 0 additions & 2 deletions
This file was deleted.

core/service/src/client/js_api.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ struct UserDecryptionResponseHex {
380380
// NOTE: this is the external signature
381381
signature: String,
382382
payload: Option<String>,
383+
extra_data: Option<String>,
383384
}
384385

385386
#[cfg(feature = "wasm_tests")]
@@ -392,6 +393,7 @@ fn resp_to_js(agg_resp: Vec<UserDecryptionResponse>) -> JsValue {
392393
Some(inner) => Some(hex::encode(serialize(&inner).unwrap())),
393394
None => None,
394395
},
396+
extra_data: Some(hex::encode(&resp.extra_data)),
395397
};
396398
out.push(r);
397399
}
@@ -421,6 +423,10 @@ fn js_to_resp(json: JsValue) -> anyhow::Result<Vec<UserDecryptionResponse>> {
421423
}
422424
None => None,
423425
},
426+
extra_data: match hex_resp.extra_data {
427+
Some(inner) => hex::decode(&inner)?,
428+
None => vec![],
429+
},
424430
});
425431
}
426432
Ok(out)
@@ -473,7 +479,8 @@ fn js_to_resp(json: JsValue) -> anyhow::Result<Vec<UserDecryptionResponse>> {
473479
/// [
474480
/// {
475481
/// signature: '69e7e040cab157aa819015b321c012dccb1545ffefd325b359b492653f0347517e28e66c572cdc299e259024329859ff9fcb0096e1ce072af0b6e1ca1fe25ec6',
476-
/// payload: '0100000029...'
482+
/// payload: '0100000029...',
483+
/// extra_data: '01234...',
477484
/// }
478485
/// ]
479486
/// ```

core/service/src/client/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ impl Client {
767767
key_id: Some((*key_id).into()),
768768
domain: Some(domain_msg),
769769
request_id: Some((*request_id).into()),
770+
extra_data: vec![],
770771
};
771772
Ok(req)
772773
}
@@ -824,6 +825,7 @@ impl Client {
824825
typed_ciphertexts,
825826
key_id: Some((*key_id).into()),
826827
domain: Some(domain_msg),
828+
extra_data: vec![],
827829
},
828830
UnifiedPublicEncKey::MlKem512(enc_pk),
829831
UnifiedPrivateEncKey::MlKem512(enc_sk),
@@ -872,6 +874,7 @@ impl Client {
872874
typed_ciphertexts,
873875
key_id: Some((*key_id).into()),
874876
domain: Some(domain_msg),
877+
extra_data: vec![],
875878
},
876879
UnifiedPublicEncKey::MlKem1024(enc_pk),
877880
UnifiedPrivateEncKey::MlKem1024(enc_sk),

0 commit comments

Comments
 (0)