From fb2cfa5b66240a87347a491948bf137eaa870852 Mon Sep 17 00:00:00 2001 From: Louis Tremblay Thibault Date: Mon, 11 Dec 2023 20:44:54 +0100 Subject: [PATCH] fix(): use new protobuf API version --- fhevm/precompiles.go | 31 ++++-- kms/kms.pb.go | 250 +++++++++++++++++++++++++++++++------------ kms/kms_grpc.pb.go | 78 +++++++++++++- proto/kms.proto | 30 ++++-- 4 files changed, 303 insertions(+), 86 deletions(-) diff --git a/fhevm/precompiles.go b/fhevm/precompiles.go index daf36fe..e2f843e 100644 --- a/fhevm/precompiles.go +++ b/fhevm/precompiles.go @@ -1908,25 +1908,36 @@ func reencryptRun(environment EVMEnvironment, caller common.Address, addr common ct := getVerifiedCiphertext(environment, common.BytesToHash(input[0:32])) if ct != nil { // Make sure we don't decrypt before any optimistic requires are checked. - optReqResult, optReqErr := evaluateRemainingOptimisticRequires(environment) - if optReqErr != nil { - return nil, optReqErr - } else if !optReqResult { - return nil, ErrExecutionReverted + // optReqResult, optReqErr := evaluateRemainingOptimisticRequires(environment) + // if optReqErr != nil { + // return nil, optReqErr + // } else if !optReqResult { + // return nil, ErrExecutionReverted + // } + + var fheType kms.FheType + switch ct.ciphertext.fheUintType { + case FheUint8: + fheType = kms.FheType_Euint8 + case FheUint16: + fheType = kms.FheType_Euint16 + case FheUint32: + fheType = kms.FheType_Euint32 } - // TODO: generate merkle proof for some data (handle? ciphertext bytes?) + pubKey := input[32:64] + + // TODO: generate merkle proof for some data proof := &kms.Proof{ - Height: 5, + Height: 3, MerklePatriciaProof: []byte{}, } - pubKey := input[32:64] - reencryptionRequest := &kms.ReencryptionRequest{ + FheType: fheType, Ciphertext: ct.ciphertext.serialization, + Request: pubKey, // TODO: change according to the structure of `Request` Proof: proof, - PublicKey: pubKey, } conn, err := grpc.Dial(kms.KmsEndpointAddr, grpc.WithTransportCredentials(insecure.NewCredentials())) diff --git a/kms/kms.pb.go b/kms/kms.pb.go index 084e5fa..26318df 100644 --- a/kms/kms.pb.go +++ b/kms/kms.pb.go @@ -20,6 +20,58 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +type FheType int32 + +const ( + FheType_Bool FheType = 0 + FheType_Euint8 FheType = 1 + FheType_Euint16 FheType = 2 + FheType_Euint32 FheType = 3 +) + +// Enum value maps for FheType. +var ( + FheType_name = map[int32]string{ + 0: "Bool", + 1: "Euint8", + 2: "Euint16", + 3: "Euint32", + } + FheType_value = map[string]int32{ + "Bool": 0, + "Euint8": 1, + "Euint16": 2, + "Euint32": 3, + } +) + +func (x FheType) Enum() *FheType { + p := new(FheType) + *p = x + return p +} + +func (x FheType) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (FheType) Descriptor() protoreflect.EnumDescriptor { + return file_kms_proto_enumTypes[0].Descriptor() +} + +func (FheType) Type() protoreflect.EnumType { + return &file_kms_proto_enumTypes[0] +} + +func (x FheType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use FheType.Descriptor instead. +func (FheType) EnumDescriptor() ([]byte, []int) { + return file_kms_proto_rawDescGZIP(), []int{0} +} + type Proof struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -80,8 +132,10 @@ type DecryptionRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Ciphertext []byte `protobuf:"bytes,1,opt,name=ciphertext,proto3" json:"ciphertext,omitempty"` - Proof *Proof `protobuf:"bytes,2,opt,name=proof,proto3" json:"proof,omitempty"` + FheType FheType `protobuf:"varint,1,opt,name=fhe_type,json=fheType,proto3,enum=kms.FheType" json:"fhe_type,omitempty"` + Ciphertext []byte `protobuf:"bytes,2,opt,name=ciphertext,proto3" json:"ciphertext,omitempty"` + Request []byte `protobuf:"bytes,3,opt,name=request,proto3" json:"request,omitempty"` + Proof *Proof `protobuf:"bytes,4,opt,name=proof,proto3" json:"proof,omitempty"` } func (x *DecryptionRequest) Reset() { @@ -116,6 +170,13 @@ func (*DecryptionRequest) Descriptor() ([]byte, []int) { return file_kms_proto_rawDescGZIP(), []int{1} } +func (x *DecryptionRequest) GetFheType() FheType { + if x != nil { + return x.FheType + } + return FheType_Bool +} + func (x *DecryptionRequest) GetCiphertext() []byte { if x != nil { return x.Ciphertext @@ -123,6 +184,13 @@ func (x *DecryptionRequest) GetCiphertext() []byte { return nil } +func (x *DecryptionRequest) GetRequest() []byte { + if x != nil { + return x.Request + } + return nil +} + func (x *DecryptionRequest) GetProof() *Proof { if x != nil { return x.Proof @@ -135,8 +203,9 @@ type DecryptionResponse struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Plaintext uint32 `protobuf:"varint,1,opt,name=plaintext,proto3" json:"plaintext,omitempty"` - Signature []byte `protobuf:"bytes,2,opt,name=signature,proto3" json:"signature,omitempty"` + Signature []byte `protobuf:"bytes,1,opt,name=signature,proto3" json:"signature,omitempty"` + FheType FheType `protobuf:"varint,2,opt,name=fhe_type,json=fheType,proto3,enum=kms.FheType" json:"fhe_type,omitempty"` + Plaintext uint32 `protobuf:"varint,3,opt,name=plaintext,proto3" json:"plaintext,omitempty"` } func (x *DecryptionResponse) Reset() { @@ -171,18 +240,25 @@ func (*DecryptionResponse) Descriptor() ([]byte, []int) { return file_kms_proto_rawDescGZIP(), []int{2} } -func (x *DecryptionResponse) GetPlaintext() uint32 { +func (x *DecryptionResponse) GetSignature() []byte { if x != nil { - return x.Plaintext + return x.Signature } - return 0 + return nil } -func (x *DecryptionResponse) GetSignature() []byte { +func (x *DecryptionResponse) GetFheType() FheType { if x != nil { - return x.Signature + return x.FheType } - return nil + return FheType_Bool +} + +func (x *DecryptionResponse) GetPlaintext() uint32 { + if x != nil { + return x.Plaintext + } + return 0 } type ReencryptionRequest struct { @@ -190,9 +266,10 @@ type ReencryptionRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Ciphertext []byte `protobuf:"bytes,1,opt,name=ciphertext,proto3" json:"ciphertext,omitempty"` - Proof *Proof `protobuf:"bytes,2,opt,name=proof,proto3" json:"proof,omitempty"` - PublicKey []byte `protobuf:"bytes,3,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` + FheType FheType `protobuf:"varint,1,opt,name=fhe_type,json=fheType,proto3,enum=kms.FheType" json:"fhe_type,omitempty"` + Ciphertext []byte `protobuf:"bytes,2,opt,name=ciphertext,proto3" json:"ciphertext,omitempty"` + Request []byte `protobuf:"bytes,3,opt,name=request,proto3" json:"request,omitempty"` + Proof *Proof `protobuf:"bytes,4,opt,name=proof,proto3" json:"proof,omitempty"` } func (x *ReencryptionRequest) Reset() { @@ -227,6 +304,13 @@ func (*ReencryptionRequest) Descriptor() ([]byte, []int) { return file_kms_proto_rawDescGZIP(), []int{3} } +func (x *ReencryptionRequest) GetFheType() FheType { + if x != nil { + return x.FheType + } + return FheType_Bool +} + func (x *ReencryptionRequest) GetCiphertext() []byte { if x != nil { return x.Ciphertext @@ -234,16 +318,16 @@ func (x *ReencryptionRequest) GetCiphertext() []byte { return nil } -func (x *ReencryptionRequest) GetProof() *Proof { +func (x *ReencryptionRequest) GetRequest() []byte { if x != nil { - return x.Proof + return x.Request } return nil } -func (x *ReencryptionRequest) GetPublicKey() []byte { +func (x *ReencryptionRequest) GetProof() *Proof { if x != nil { - return x.PublicKey + return x.Proof } return nil } @@ -253,8 +337,8 @@ type ReencryptionResponse struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ReencryptedCiphertext []byte `protobuf:"bytes,1,opt,name=reencrypted_ciphertext,json=reencryptedCiphertext,proto3" json:"reencrypted_ciphertext,omitempty"` - Signature []byte `protobuf:"bytes,2,opt,name=signature,proto3" json:"signature,omitempty"` + ReencryptedCiphertext []byte `protobuf:"bytes,1,opt,name=reencrypted_ciphertext,json=reencryptedCiphertext,proto3" json:"reencrypted_ciphertext,omitempty"` + FheType FheType `protobuf:"varint,2,opt,name=fhe_type,json=fheType,proto3,enum=kms.FheType" json:"fhe_type,omitempty"` } func (x *ReencryptionResponse) Reset() { @@ -296,11 +380,11 @@ func (x *ReencryptionResponse) GetReencryptedCiphertext() []byte { return nil } -func (x *ReencryptionResponse) GetSignature() []byte { +func (x *ReencryptionResponse) GetFheType() FheType { if x != nil { - return x.Signature + return x.FheType } - return nil + return FheType_Bool } var File_kms_proto protoreflect.FileDescriptor @@ -312,33 +396,56 @@ var file_kms_proto_rawDesc = []byte{ 0x74, 0x12, 0x32, 0x0a, 0x15, 0x6d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x5f, 0x70, 0x61, 0x74, 0x72, 0x69, 0x63, 0x69, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x13, 0x6d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x50, 0x61, 0x74, 0x72, 0x69, 0x63, 0x69, 0x61, - 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0x55, 0x0a, 0x11, 0x44, 0x65, 0x63, 0x72, 0x79, 0x70, 0x74, - 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x69, - 0x70, 0x68, 0x65, 0x72, 0x74, 0x65, 0x78, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, - 0x63, 0x69, 0x70, 0x68, 0x65, 0x72, 0x74, 0x65, 0x78, 0x74, 0x12, 0x20, 0x0a, 0x05, 0x70, 0x72, - 0x6f, 0x6f, 0x66, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x6b, 0x6d, 0x73, 0x2e, - 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0x50, 0x0a, 0x12, - 0x44, 0x65, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x6c, 0x61, 0x69, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x70, 0x6c, 0x61, 0x69, 0x6e, 0x74, 0x65, 0x78, 0x74, - 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x22, 0x76, - 0x0a, 0x13, 0x52, 0x65, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x69, 0x70, 0x68, 0x65, 0x72, 0x74, - 0x65, 0x78, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x63, 0x69, 0x70, 0x68, 0x65, - 0x72, 0x74, 0x65, 0x78, 0x74, 0x12, 0x20, 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x6b, 0x6d, 0x73, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, - 0x52, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x75, 0x62, 0x6c, 0x69, - 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x70, 0x75, 0x62, - 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x22, 0x6b, 0x0a, 0x14, 0x52, 0x65, 0x65, 0x6e, 0x63, 0x72, - 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x35, - 0x0a, 0x16, 0x72, 0x65, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x65, 0x64, 0x5f, 0x63, 0x69, - 0x70, 0x68, 0x65, 0x72, 0x74, 0x65, 0x78, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x15, - 0x72, 0x65, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x65, 0x64, 0x43, 0x69, 0x70, 0x68, 0x65, - 0x72, 0x74, 0x65, 0x78, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, - 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, - 0x75, 0x72, 0x65, 0x32, 0x8b, 0x01, 0x0a, 0x0b, 0x4b, 0x6d, 0x73, 0x45, 0x6e, 0x64, 0x70, 0x6f, - 0x69, 0x6e, 0x74, 0x12, 0x3a, 0x0a, 0x07, 0x44, 0x65, 0x63, 0x72, 0x79, 0x70, 0x74, 0x12, 0x16, + 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0x98, 0x01, 0x0a, 0x11, 0x44, 0x65, 0x63, 0x72, 0x79, 0x70, + 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, 0x08, 0x66, + 0x68, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, + 0x6b, 0x6d, 0x73, 0x2e, 0x46, 0x68, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x07, 0x66, 0x68, 0x65, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x69, 0x70, 0x68, 0x65, 0x72, 0x74, 0x65, + 0x78, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x63, 0x69, 0x70, 0x68, 0x65, 0x72, + 0x74, 0x65, 0x78, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, + 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, + 0x6b, 0x6d, 0x73, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, + 0x22, 0x79, 0x0a, 0x12, 0x44, 0x65, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, + 0x75, 0x72, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, + 0x74, 0x75, 0x72, 0x65, 0x12, 0x27, 0x0a, 0x08, 0x66, 0x68, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x6b, 0x6d, 0x73, 0x2e, 0x46, 0x68, 0x65, + 0x54, 0x79, 0x70, 0x65, 0x52, 0x07, 0x66, 0x68, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1c, 0x0a, + 0x09, 0x70, 0x6c, 0x61, 0x69, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, + 0x52, 0x09, 0x70, 0x6c, 0x61, 0x69, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x22, 0x9a, 0x01, 0x0a, 0x13, + 0x52, 0x65, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, 0x08, 0x66, 0x68, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x6b, 0x6d, 0x73, 0x2e, 0x46, 0x68, 0x65, 0x54, + 0x79, 0x70, 0x65, 0x52, 0x07, 0x66, 0x68, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, + 0x63, 0x69, 0x70, 0x68, 0x65, 0x72, 0x74, 0x65, 0x78, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, + 0x52, 0x0a, 0x63, 0x69, 0x70, 0x68, 0x65, 0x72, 0x74, 0x65, 0x78, 0x74, 0x12, 0x18, 0x0a, 0x07, + 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x72, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x6b, 0x6d, 0x73, 0x2e, 0x50, 0x72, 0x6f, 0x6f, + 0x66, 0x52, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0x76, 0x0a, 0x14, 0x52, 0x65, 0x65, 0x6e, + 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x35, 0x0a, 0x16, 0x72, 0x65, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x65, 0x64, 0x5f, + 0x63, 0x69, 0x70, 0x68, 0x65, 0x72, 0x74, 0x65, 0x78, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, + 0x52, 0x15, 0x72, 0x65, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x65, 0x64, 0x43, 0x69, 0x70, + 0x68, 0x65, 0x72, 0x74, 0x65, 0x78, 0x74, 0x12, 0x27, 0x0a, 0x08, 0x66, 0x68, 0x65, 0x5f, 0x74, + 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x6b, 0x6d, 0x73, 0x2e, + 0x46, 0x68, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x07, 0x66, 0x68, 0x65, 0x54, 0x79, 0x70, 0x65, + 0x2a, 0x39, 0x0a, 0x07, 0x46, 0x68, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x08, 0x0a, 0x04, 0x42, + 0x6f, 0x6f, 0x6c, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x45, 0x75, 0x69, 0x6e, 0x74, 0x38, 0x10, + 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x45, 0x75, 0x69, 0x6e, 0x74, 0x31, 0x36, 0x10, 0x02, 0x12, 0x0b, + 0x0a, 0x07, 0x45, 0x75, 0x69, 0x6e, 0x74, 0x33, 0x32, 0x10, 0x03, 0x32, 0xa3, 0x02, 0x0a, 0x0b, + 0x4b, 0x6d, 0x73, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x47, 0x0a, 0x14, 0x56, + 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x61, 0x6e, 0x64, 0x5f, 0x64, 0x65, 0x63, 0x72, + 0x79, 0x70, 0x74, 0x12, 0x16, 0x2e, 0x6b, 0x6d, 0x73, 0x2e, 0x44, 0x65, 0x63, 0x72, 0x79, 0x70, + 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x6b, 0x6d, + 0x73, 0x2e, 0x44, 0x65, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4d, 0x0a, 0x16, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, + 0x5f, 0x61, 0x6e, 0x64, 0x5f, 0x72, 0x65, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x12, 0x18, + 0x2e, 0x6b, 0x6d, 0x73, 0x2e, 0x52, 0x65, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6f, + 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x6b, 0x6d, 0x73, 0x2e, 0x52, + 0x65, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x3a, 0x0a, 0x07, 0x44, 0x65, 0x63, 0x72, 0x79, 0x70, 0x74, 0x12, 0x16, 0x2e, 0x6b, 0x6d, 0x73, 0x2e, 0x44, 0x65, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x6b, 0x6d, 0x73, 0x2e, 0x44, 0x65, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, @@ -363,26 +470,36 @@ func file_kms_proto_rawDescGZIP() []byte { return file_kms_proto_rawDescData } +var file_kms_proto_enumTypes = make([]protoimpl.EnumInfo, 1) var file_kms_proto_msgTypes = make([]protoimpl.MessageInfo, 5) var file_kms_proto_goTypes = []interface{}{ - (*Proof)(nil), // 0: kms.Proof - (*DecryptionRequest)(nil), // 1: kms.DecryptionRequest - (*DecryptionResponse)(nil), // 2: kms.DecryptionResponse - (*ReencryptionRequest)(nil), // 3: kms.ReencryptionRequest - (*ReencryptionResponse)(nil), // 4: kms.ReencryptionResponse + (FheType)(0), // 0: kms.FheType + (*Proof)(nil), // 1: kms.Proof + (*DecryptionRequest)(nil), // 2: kms.DecryptionRequest + (*DecryptionResponse)(nil), // 3: kms.DecryptionResponse + (*ReencryptionRequest)(nil), // 4: kms.ReencryptionRequest + (*ReencryptionResponse)(nil), // 5: kms.ReencryptionResponse } var file_kms_proto_depIdxs = []int32{ - 0, // 0: kms.DecryptionRequest.proof:type_name -> kms.Proof - 0, // 1: kms.ReencryptionRequest.proof:type_name -> kms.Proof - 1, // 2: kms.KmsEndpoint.Decrypt:input_type -> kms.DecryptionRequest - 3, // 3: kms.KmsEndpoint.Reencrypt:input_type -> kms.ReencryptionRequest - 2, // 4: kms.KmsEndpoint.Decrypt:output_type -> kms.DecryptionResponse - 4, // 5: kms.KmsEndpoint.Reencrypt:output_type -> kms.ReencryptionResponse - 4, // [4:6] is the sub-list for method output_type - 2, // [2:4] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 0, // 0: kms.DecryptionRequest.fhe_type:type_name -> kms.FheType + 1, // 1: kms.DecryptionRequest.proof:type_name -> kms.Proof + 0, // 2: kms.DecryptionResponse.fhe_type:type_name -> kms.FheType + 0, // 3: kms.ReencryptionRequest.fhe_type:type_name -> kms.FheType + 1, // 4: kms.ReencryptionRequest.proof:type_name -> kms.Proof + 0, // 5: kms.ReencryptionResponse.fhe_type:type_name -> kms.FheType + 2, // 6: kms.KmsEndpoint.Validate_and_decrypt:input_type -> kms.DecryptionRequest + 4, // 7: kms.KmsEndpoint.Validate_and_reencrypt:input_type -> kms.ReencryptionRequest + 2, // 8: kms.KmsEndpoint.Decrypt:input_type -> kms.DecryptionRequest + 4, // 9: kms.KmsEndpoint.Reencrypt:input_type -> kms.ReencryptionRequest + 3, // 10: kms.KmsEndpoint.Validate_and_decrypt:output_type -> kms.DecryptionResponse + 5, // 11: kms.KmsEndpoint.Validate_and_reencrypt:output_type -> kms.ReencryptionResponse + 3, // 12: kms.KmsEndpoint.Decrypt:output_type -> kms.DecryptionResponse + 5, // 13: kms.KmsEndpoint.Reencrypt:output_type -> kms.ReencryptionResponse + 10, // [10:14] is the sub-list for method output_type + 6, // [6:10] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name } func init() { file_kms_proto_init() } @@ -457,13 +574,14 @@ func file_kms_proto_init() { File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_kms_proto_rawDesc, - NumEnums: 0, + NumEnums: 1, NumMessages: 5, NumExtensions: 0, NumServices: 1, }, GoTypes: file_kms_proto_goTypes, DependencyIndexes: file_kms_proto_depIdxs, + EnumInfos: file_kms_proto_enumTypes, MessageInfos: file_kms_proto_msgTypes, }.Build() File_kms_proto = out.File diff --git a/kms/kms_grpc.pb.go b/kms/kms_grpc.pb.go index 08eb831..f96d747 100644 --- a/kms/kms_grpc.pb.go +++ b/kms/kms_grpc.pb.go @@ -22,14 +22,18 @@ const _ = grpc.SupportPackageIsVersion7 const KmsEndpointAddr = "kms.zama.ai:50051" const ( - KmsEndpoint_Decrypt_FullMethodName = "/kms.KmsEndpoint/Decrypt" - KmsEndpoint_Reencrypt_FullMethodName = "/kms.KmsEndpoint/Reencrypt" + KmsEndpoint_ValidateAndDecrypt_FullMethodName = "/kms.KmsEndpoint/Validate_and_decrypt" + KmsEndpoint_ValidateAndReencrypt_FullMethodName = "/kms.KmsEndpoint/Validate_and_reencrypt" + KmsEndpoint_Decrypt_FullMethodName = "/kms.KmsEndpoint/Decrypt" + KmsEndpoint_Reencrypt_FullMethodName = "/kms.KmsEndpoint/Reencrypt" ) // KmsEndpointClient is the client API for KmsEndpoint service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type KmsEndpointClient interface { + ValidateAndDecrypt(ctx context.Context, in *DecryptionRequest, opts ...grpc.CallOption) (*DecryptionResponse, error) + ValidateAndReencrypt(ctx context.Context, in *ReencryptionRequest, opts ...grpc.CallOption) (*ReencryptionResponse, error) Decrypt(ctx context.Context, in *DecryptionRequest, opts ...grpc.CallOption) (*DecryptionResponse, error) Reencrypt(ctx context.Context, in *ReencryptionRequest, opts ...grpc.CallOption) (*ReencryptionResponse, error) } @@ -42,6 +46,24 @@ func NewKmsEndpointClient(cc grpc.ClientConnInterface) KmsEndpointClient { return &kmsEndpointClient{cc} } +func (c *kmsEndpointClient) ValidateAndDecrypt(ctx context.Context, in *DecryptionRequest, opts ...grpc.CallOption) (*DecryptionResponse, error) { + out := new(DecryptionResponse) + err := c.cc.Invoke(ctx, KmsEndpoint_ValidateAndDecrypt_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *kmsEndpointClient) ValidateAndReencrypt(ctx context.Context, in *ReencryptionRequest, opts ...grpc.CallOption) (*ReencryptionResponse, error) { + out := new(ReencryptionResponse) + err := c.cc.Invoke(ctx, KmsEndpoint_ValidateAndReencrypt_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *kmsEndpointClient) Decrypt(ctx context.Context, in *DecryptionRequest, opts ...grpc.CallOption) (*DecryptionResponse, error) { out := new(DecryptionResponse) err := c.cc.Invoke(ctx, KmsEndpoint_Decrypt_FullMethodName, in, out, opts...) @@ -64,6 +86,8 @@ func (c *kmsEndpointClient) Reencrypt(ctx context.Context, in *ReencryptionReque // All implementations must embed UnimplementedKmsEndpointServer // for forward compatibility type KmsEndpointServer interface { + ValidateAndDecrypt(context.Context, *DecryptionRequest) (*DecryptionResponse, error) + ValidateAndReencrypt(context.Context, *ReencryptionRequest) (*ReencryptionResponse, error) Decrypt(context.Context, *DecryptionRequest) (*DecryptionResponse, error) Reencrypt(context.Context, *ReencryptionRequest) (*ReencryptionResponse, error) mustEmbedUnimplementedKmsEndpointServer() @@ -73,6 +97,12 @@ type KmsEndpointServer interface { type UnimplementedKmsEndpointServer struct { } +func (UnimplementedKmsEndpointServer) ValidateAndDecrypt(context.Context, *DecryptionRequest) (*DecryptionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ValidateAndDecrypt not implemented") +} +func (UnimplementedKmsEndpointServer) ValidateAndReencrypt(context.Context, *ReencryptionRequest) (*ReencryptionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ValidateAndReencrypt not implemented") +} func (UnimplementedKmsEndpointServer) Decrypt(context.Context, *DecryptionRequest) (*DecryptionResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Decrypt not implemented") } @@ -92,6 +122,42 @@ func RegisterKmsEndpointServer(s grpc.ServiceRegistrar, srv KmsEndpointServer) { s.RegisterService(&KmsEndpoint_ServiceDesc, srv) } +func _KmsEndpoint_ValidateAndDecrypt_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DecryptionRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(KmsEndpointServer).ValidateAndDecrypt(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: KmsEndpoint_ValidateAndDecrypt_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(KmsEndpointServer).ValidateAndDecrypt(ctx, req.(*DecryptionRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _KmsEndpoint_ValidateAndReencrypt_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ReencryptionRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(KmsEndpointServer).ValidateAndReencrypt(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: KmsEndpoint_ValidateAndReencrypt_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(KmsEndpointServer).ValidateAndReencrypt(ctx, req.(*ReencryptionRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _KmsEndpoint_Decrypt_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(DecryptionRequest) if err := dec(in); err != nil { @@ -135,6 +201,14 @@ var KmsEndpoint_ServiceDesc = grpc.ServiceDesc{ ServiceName: "kms.KmsEndpoint", HandlerType: (*KmsEndpointServer)(nil), Methods: []grpc.MethodDesc{ + { + MethodName: "Validate_and_decrypt", + Handler: _KmsEndpoint_ValidateAndDecrypt_Handler, + }, + { + MethodName: "Validate_and_reencrypt", + Handler: _KmsEndpoint_ValidateAndReencrypt_Handler, + }, { MethodName: "Decrypt", Handler: _KmsEndpoint_Decrypt_Handler, diff --git a/proto/kms.proto b/proto/kms.proto index b5c4945..fe2cc7a 100644 --- a/proto/kms.proto +++ b/proto/kms.proto @@ -3,32 +3,46 @@ package kms; option go_package = "github.com/zama-ai/fhevm-go/kms"; service KmsEndpoint { + rpc Validate_and_decrypt(DecryptionRequest) returns (DecryptionResponse); + rpc Validate_and_reencrypt(ReencryptionRequest) + returns (ReencryptionResponse); rpc Decrypt(DecryptionRequest) returns (DecryptionResponse); rpc Reencrypt(ReencryptionRequest) returns (ReencryptionResponse); } +enum FheType { + Bool = 0; + Euint8 = 1; + Euint16 = 2; + Euint32 = 3; +} + message Proof { uint32 height = 1; bytes merkle_patricia_proof = 2; } message DecryptionRequest { - bytes ciphertext = 1; - Proof proof = 2; + FheType fhe_type = 1; + bytes ciphertext = 2; + bytes request = 3; + Proof proof = 4; } message DecryptionResponse { - uint32 plaintext = 1; - bytes signature = 2; + bytes signature = 1; + FheType fhe_type = 2; + uint32 plaintext = 3; } message ReencryptionRequest { - bytes ciphertext = 1; - Proof proof = 2; - bytes public_key = 3; + FheType fhe_type = 1; + bytes ciphertext = 2; + bytes request = 3; + Proof proof = 4; } message ReencryptionResponse { bytes reencrypted_ciphertext = 1; - bytes signature = 2; + FheType fhe_type = 2; } \ No newline at end of file