diff --git a/fhevm-engine/coprocessor/src/server.rs b/fhevm-engine/coprocessor/src/server.rs index 5a5532dd..bb7193a1 100644 --- a/fhevm-engine/coprocessor/src/server.rs +++ b/fhevm-engine/coprocessor/src/server.rs @@ -98,38 +98,40 @@ pub async fn run_server_iteration( // for EIP712 signature alloy::sol! { - struct CiphertextVerification { + struct CiphertextVerificationForCopro { address aclAddress; bytes32 hashOfCiphertext; uint256[] handlesList; + address userAddress; address contractAddress; - address callerAddress; } } -// copied from go coprocessor -// theData := signerApi.TypedData{ -// Types: signerApi.Types{ -// "EIP712Domain": domainType, -// "CiphertextVerification": []signerApi.Type{ -// {Name: "handlesList", Type: "uint256[]"}, -// {Name: "contractAddress", Type: "address"}, -// {Name: "callerAddress", Type: "address"}, -// }, -// }, -// Domain: signerApi.TypedDataDomain{ -// Name: "FHEVMCoprocessor", -// Version: "1", -// ChainId: chainId, -// VerifyingContract: verifyingContract.Hex(), -// }, -// PrimaryType: "CiphertextVerification", -// Message: signerApi.TypedDataMessage{ -// "handlesList": hexInputs, -// "contractAddress": contractAddress.Hex(), -// "callerAddress": callerAddress.Hex(), -// }, -// } +// copied from fhevm-go coprocessor +// const types = { +// CiphertextVerificationForCopro: [ +// { +// name: 'aclAddress', +// type: 'address', +// }, +// { +// name: 'hashOfCiphertext', +// type: 'bytes32', +// }, +// { +// name: 'handlesList', +// type: 'uint256[]', +// }, +// { +// name: 'userAddress', +// type: 'address', +// }, +// { +// name: 'contractAddress', +// type: 'address', +// }, +// ], +// }; #[tonic::async_trait] impl coprocessor::fhevm_coprocessor_server::FhevmCoprocessor for CoprocessorService { @@ -185,7 +187,7 @@ impl coprocessor::fhevm_coprocessor_server::FhevmCoprocessor for CoprocessorServ })?; let eip_712_domain = alloy::sol_types::eip712_domain! { - name: "FHEVMCoprocessor", + name: "InputVerifier", version: "1", chain_id: chain_id as u64, verifying_contract: verifying_contract_address, @@ -196,7 +198,7 @@ impl coprocessor::fhevm_coprocessor_server::FhevmCoprocessor for CoprocessorServ // server key is biiig, clone the pointer let server_key = std::sync::Arc::new(server_key); let mut contract_addresses = Vec::with_capacity(req.input_ciphertexts.len()); - let mut caller_addresses = Vec::with_capacity(req.input_ciphertexts.len()); + let mut user_addresses = Vec::with_capacity(req.input_ciphertexts.len()); for ci in &req.input_ciphertexts { // parse addresses contract_addresses.push( @@ -207,8 +209,8 @@ impl coprocessor::fhevm_coprocessor_server::FhevmCoprocessor for CoprocessorServ } })?, ); - caller_addresses.push( - alloy::primitives::Address::from_str(&ci.caller_address).map_err(|e| { + user_addresses.push( + alloy::primitives::Address::from_str(&ci.user_address).map_err(|e| { CoprocessorError::CannotParseEthereumAddress { bad_address: ci.contract_address.clone(), parsing_error: e.to_string(), @@ -300,11 +302,11 @@ impl coprocessor::fhevm_coprocessor_server::FhevmCoprocessor for CoprocessorServ let mut hash_of_ciphertext: [u8; 32] = [0; 32]; hash_of_ciphertext.copy_from_slice(&blob_hash); - let mut ct_verification = CiphertextVerification { + let mut ct_verification = CiphertextVerificationForCopro { hashOfCiphertext: alloy::primitives::FixedBytes(hash_of_ciphertext), aclAddress: acl_contract_address, contractAddress: contract_addresses[idx], - callerAddress: caller_addresses[idx], + userAddress: user_addresses[idx], handlesList: Vec::with_capacity(corresponding_unpacked.len()), }; @@ -313,9 +315,9 @@ impl coprocessor::fhevm_coprocessor_server::FhevmCoprocessor for CoprocessorServ hash_of_ciphertext: hash_of_ciphertext.to_vec(), input_handles: Vec::with_capacity(corresponding_unpacked.len()), eip712_signature: Vec::new(), - eip712_contract_address: contract_addresses[idx].to_string(), - eip712_caller_address: caller_addresses[idx].to_string(), - eip712_signer_address: self.signer.address().to_string(), + contract_address: contract_addresses[idx].to_string(), + user_address: user_addresses[idx].to_string(), + signer_address: self.signer.address().to_string(), }; for (ct_idx, the_ct) in corresponding_unpacked.iter().enumerate() { diff --git a/fhevm-engine/coprocessor/src/tests/errors.rs b/fhevm-engine/coprocessor/src/tests/errors.rs index 89e8a263..b193c331 100644 --- a/fhevm-engine/coprocessor/src/tests/errors.rs +++ b/fhevm-engine/coprocessor/src/tests/errors.rs @@ -11,7 +11,7 @@ use crate::{ }, }, tests::{ - inputs::{test_random_caller_address, test_random_contract_address}, + inputs::{test_random_user_address, test_random_contract_address}, utils::{default_api_key, default_tenant_id, setup_test_app}, }, }; @@ -55,7 +55,7 @@ async fn test_coprocessor_input_errors() -> Result<(), Box Result<(), Box Result<(), Box Result<(), Box String { +pub fn test_random_user_address() -> String { let _private_key = "bd2400c676871534a682ca1c5e4cd647ec9c3e122f188c6e3f54e6900d586c7b"; let public_key = "0x1BdA2a485c339C95a9AbfDe52E80ca38e34C199E"; public_key.to_string() @@ -40,6 +41,7 @@ async fn test_fhe_inputs() -> Result<(), Box> { })?; let keys = &keys[0]; + println!("Building list"); let mut builder = tfhe::ProvenCompactCiphertextList::builder(&keys.pks); let the_list = builder .push(false) @@ -57,13 +59,15 @@ async fn test_fhe_inputs() -> Result<(), Box> { .unwrap(); let serialized = safe_serialize(&the_list); + let input_bytes = keccak256(&serialized); + println!("input hash: 0x{}", hex::encode(input_bytes)); println!("Encrypting inputs..."); let mut input_request = tonic::Request::new(InputUploadBatch { input_ciphertexts: vec![InputToUpload { input_payload: serialized, signature: Vec::new(), - caller_address: test_random_caller_address(), + user_address: test_random_user_address(), contract_address: test_random_contract_address(), }], }); @@ -74,6 +78,25 @@ async fn test_fhe_inputs() -> Result<(), Box> { let resp = client.upload_inputs(input_request).await?; let resp = resp.get_ref(); assert_eq!(resp.upload_responses.len(), 1); + for resp in &resp.upload_responses { + println!(r#"response + acl address: {} + contract address: {} + hash: 0x{} + caller: {} + signer: {} + signature: 0x{} + handles: {:#?} + "#, + resp.acl_address, + resp.contract_address, + hex::encode(&resp.hash_of_ciphertext), + resp.user_address, + resp.signer_address, + hex::encode(&resp.eip712_signature), + resp.input_handles.iter().map(|i| hex::encode(&i.handle)).collect::>() + ); + } let first_resp = &resp.upload_responses[0]; @@ -134,6 +157,7 @@ async fn custom_insert_inputs() -> Result<(), Box> { })?; let keys = &keys[0]; + println!("Building list"); let mut builder = tfhe::ProvenCompactCiphertextList::builder(&keys.pks); let the_list = builder .push(false) @@ -146,13 +170,15 @@ async fn custom_insert_inputs() -> Result<(), Box> { .unwrap(); let serialized = safe_serialize(&the_list); + let input_bytes = keccak256(&serialized); + println!("input hash: 0x{}", hex::encode(input_bytes)); println!("Encrypting inputs..."); let mut input_request = tonic::Request::new(InputUploadBatch { input_ciphertexts: vec![InputToUpload { input_payload: serialized, signature: Vec::new(), - caller_address: test_random_caller_address(), + user_address: test_random_user_address(), contract_address: test_random_contract_address(), }], }); @@ -168,6 +194,7 @@ async fn custom_insert_inputs() -> Result<(), Box> { println!("request {idx}"); for (idx, h) in ur.input_handles.iter().enumerate() { println!(" ct {idx} 0x{}", hex::encode(&h.handle)); + println!(" response {:?}", ur); } } diff --git a/proto/coprocessor.proto b/proto/coprocessor.proto index 5b3c9759..30e6de88 100644 --- a/proto/coprocessor.proto +++ b/proto/coprocessor.proto @@ -62,7 +62,7 @@ message AsyncComputationInput { message InputToUpload { bytes input_payload = 1; string contract_address = 2; - string caller_address = 3; + string user_address = 3; bytes signature = 4; } @@ -75,9 +75,9 @@ message InputCiphertextResponse { string aclAddress = 1; bytes hashOfCiphertext = 2; repeated InputCiphertextResponseHandle input_handles = 3; - string eip712ContractAddress = 5; - string eip712CallerAddress = 6; - string eip712SignerAddress = 7; + string contractAddress = 5; + string userAddress = 6; + string signerAddress = 7; bytes eip712Signature = 8; }